Skip to content

Commit ea3d788

Browse files
committed
[LLVM][PM] Make FinalLowerGC NewPM compatible
1 parent 7600bfd commit ea3d788

File tree

8 files changed

+71
-11
lines changed

8 files changed

+71
-11
lines changed

src/aotcompile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,10 @@ static void registerCallbacks(PassBuilder &PB) {
909909
PM.addPass(LowerSIMDLoop());
910910
return true;
911911
}
912+
if (Name == "FinalLowerGC") {
913+
PM.addPass(FinalLowerGCPass());
914+
return true;
915+
}
912916
return false;
913917
});
914918

src/llvm-final-gc-lowering.cpp

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
#include "llvm-version.h"
4+
#include "passes.h"
45

56
#include <llvm/IR/LegacyPassManager.h>
67
#include <llvm/IR/Function.h>
@@ -28,21 +29,18 @@ using namespace llvm;
2829
// This pass targets typical back-ends for which the standard Julia
2930
// runtime library is available. Atypical back-ends should supply
3031
// their own lowering pass.
31-
struct FinalLowerGC: public FunctionPass, private JuliaPassContext {
32-
static char ID;
33-
FinalLowerGC() : FunctionPass(ID)
34-
{ }
32+
33+
struct FinalLowerGC: private JuliaPassContext {
34+
bool runOnFunction(Function &F);
35+
bool doInitialization(Module &M);
36+
bool doFinalization(Module &M);
3537

3638
private:
3739
Function *queueRootFunc;
3840
Function *poolAllocFunc;
3941
Function *bigAllocFunc;
4042
Instruction *pgcstack;
4143

42-
bool doInitialization(Module &M) override;
43-
bool doFinalization(Module &M) override;
44-
bool runOnFunction(Function &F) override;
45-
4644
// Lowers a `julia.new_gc_frame` intrinsic.
4745
Value *lowerNewGCFrame(CallInst *target, Function &F);
4846

@@ -325,12 +323,55 @@ bool FinalLowerGC::runOnFunction(Function &F)
325323
return true;
326324
}
327325

328-
char FinalLowerGC::ID = 0;
329-
static RegisterPass<FinalLowerGC> X("FinalLowerGC", "Final GC intrinsic lowering pass", false, false);
326+
struct FinalLowerGCLegacy: public FunctionPass {
327+
static char ID;
328+
FinalLowerGCLegacy() : FunctionPass(ID), finalLowerGC(FinalLowerGC()) {}
329+
330+
protected:
331+
void getAnalysisUsage(AnalysisUsage &AU) const override {
332+
FunctionPass::getAnalysisUsage(AU);
333+
}
334+
335+
private:
336+
bool runOnFunction(Function &F) override;
337+
bool doInitialization(Module &M) override;
338+
bool doFinalization(Module &M) override;
339+
340+
FinalLowerGC finalLowerGC;
341+
};
342+
343+
bool FinalLowerGCLegacy::runOnFunction(Function &F) {
344+
return finalLowerGC.runOnFunction(F);
345+
}
346+
347+
bool FinalLowerGCLegacy::doInitialization(Module &M) {
348+
return finalLowerGC.doInitialization(M);
349+
}
350+
351+
bool FinalLowerGCLegacy::doFinalization(Module &M) {
352+
return finalLowerGC.doFinalization(M);
353+
}
354+
355+
356+
PreservedAnalyses FinalLowerGCPass::run(Module &M, ModuleAnalysisManager &AM)
357+
{
358+
auto finalLowerGC = FinalLowerGC();
359+
finalLowerGC.doInitialization(M);
360+
for (auto &F : M.functions()) {
361+
if (F.isDeclaration())
362+
continue;
363+
finalLowerGC.runOnFunction(F);
364+
}
365+
finalLowerGC.doFinalization(M);
366+
return PreservedAnalyses::all();
367+
}
368+
369+
char FinalLowerGCLegacy::ID = 0;
370+
static RegisterPass<FinalLowerGCLegacy> X("FinalLowerGC", "Final GC intrinsic lowering pass", false, false);
330371

331372
Pass *createFinalLowerGCPass()
332373
{
333-
return new FinalLowerGC();
374+
return new FinalLowerGCLegacy();
334375
}
335376

336377
extern "C" JL_DLLEXPORT void LLVMExtraAddFinalLowerGCPass_impl(LLVMPassManagerRef PM)

src/passes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using namespace llvm;
1111
// Function Passes
1212
struct DemoteFloat16 : PassInfoMixin<DemoteFloat16> {
1313
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
14+
static bool isRequired() { return true; }
1415
};
1516

1617
struct CombineMulAdd : PassInfoMixin<CombineMulAdd> {
@@ -19,11 +20,13 @@ struct CombineMulAdd : PassInfoMixin<CombineMulAdd> {
1920

2021
struct LateLowerGC : PassInfoMixin<LateLowerGC> {
2122
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
23+
static bool isRequired() { return true; }
2224
};
2325

2426
// Module Passes
2527
struct CPUFeatures : PassInfoMixin<CPUFeatures> {
2628
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
29+
static bool isRequired() { return true; }
2730
};
2831

2932
struct RemoveNI : PassInfoMixin<RemoveNI> {
@@ -34,6 +37,11 @@ struct LowerSIMDLoop : PassInfoMixin<LowerSIMDLoop> {
3437
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
3538
};
3639

40+
struct FinalLowerGCPass : PassInfoMixin<LateLowerGC> {
41+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
42+
static bool isRequired() { return true; }
43+
};
44+
3745
// Loop Passes
3846
struct JuliaLICMPass : PassInfoMixin<JuliaLICMPass> {
3947
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,

test/llvmpasses/final-lower-gc.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -FinalLowerGC -S %s | FileCheck %s
2+
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='FinalLowerGC' -S %s | FileCheck %s
3+
24

35
@tag = external addrspace(10) global {}
46

test/llvmpasses/gcroots.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -LateLowerGCFrame -FinalLowerGC -S %s | FileCheck %s
2+
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(LateLowerGCFrame),FinalLowerGC' -S %s | FileCheck %s
23

34

45
declare void @boxed_simple({} addrspace(10)*, {} addrspace(10)*)

test/llvmpasses/refinements.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -LateLowerGCFrame -FinalLowerGC -S %s | FileCheck %s
2+
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(LateLowerGCFrame),FinalLowerGC' -S %s | FileCheck %s
23

34

45
declare {}*** @julia.ptls_states()

test/llvmpasses/returnstwicegc.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -LateLowerGCFrame -FinalLowerGC -S %s | FileCheck %s
2+
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(LateLowerGCFrame),FinalLowerGC' -S %s | FileCheck %s
23

34

45
declare void @boxed_simple({} addrspace(10)*, {} addrspace(10)*)

test/llvmpasses/safepoint_stress.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
# RUN: julia --startup-file=no %s | opt -enable-new-pm=0 -load libjulia-codegen%shlibext -LateLowerGCFrame -FinalLowerGC -S - | FileCheck %s
4+
# RUN: julia --startup-file=no %s | opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(LateLowerGCFrame),FinalLowerGC' -S - | FileCheck %s
5+
46

57
println("""
68
declare {} addrspace(10)* @alloc()

0 commit comments

Comments
 (0)