Skip to content

Commit 25e0dc9

Browse files
authored
[CodeGen] Port GCLowering to new pass manager (#75305)
1 parent 414ea3a commit 25e0dc9

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

llvm/include/llvm/CodeGen/CodeGenPassBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ Error CodeGenPassBuilder<Derived>::buildPipeline(
488488
AddIRPass addIRPass(MPM, Opt.DebugPM);
489489
// `ProfileSummaryInfo` is always valid.
490490
addIRPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
491+
addIRPass(RequireAnalysisPass<CollectorMetadataAnalysis, Module>());
491492
addISelPasses(addIRPass);
492493

493494
AddMachinePass addPass(MFPM);

llvm/include/llvm/CodeGen/GCMetadata.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ class GCFunctionAnalysis : public AnalysisInfoMixin<GCFunctionAnalysis> {
186186
Result run(Function &F, FunctionAnalysisManager &FAM);
187187
};
188188

189+
/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
190+
/// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
191+
/// directed by the GCStrategy. It also performs automatic root initialization
192+
/// and custom intrinsic lowering.
193+
///
194+
/// This pass requires `CollectorMetadataAnalysis`.
195+
class GCLoweringPass : public PassInfoMixin<GCLoweringPass> {
196+
public:
197+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
198+
};
199+
189200
/// An analysis pass which caches information about the entire Module.
190201
/// Records both the function level information used by GCRoots and a
191202
/// cache of the 'active' gc strategy objects for the current Module.

llvm/include/llvm/CodeGen/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass, (TM))
5151
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass, (TM))
5252
FUNCTION_PASS("expand-reductions", ExpandReductionsPass, ())
5353
FUNCTION_PASS("expandvp", ExpandVectorPredicationPass, ())
54+
FUNCTION_PASS("gc-lowering", GCLoweringPass, ())
5455
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, (TM))
5556
FUNCTION_PASS("interleaved-access", InterleavedAccessPass, (TM))
5657
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass, (TM))
@@ -133,7 +134,6 @@ MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis,
133134
#endif
134135
DUMMY_FUNCTION_PASS("atomic-expand", AtomicExpandPass, ())
135136
DUMMY_FUNCTION_PASS("codegenprepare", CodeGenPreparePass, ())
136-
DUMMY_FUNCTION_PASS("gc-lowering", GCLoweringPass, ())
137137
DUMMY_FUNCTION_PASS("stack-protector", StackProtectorPass, ())
138138
#undef DUMMY_FUNCTION_PASS
139139

llvm/lib/CodeGen/GCRootLowering.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@
2727

2828
using namespace llvm;
2929

30+
/// Lower barriers out of existence (if the associated GCStrategy hasn't
31+
/// already done so...), and insert initializing stores to roots as a defensive
32+
/// measure. Given we're going to report all roots live at all safepoints, we
33+
/// need to be able to ensure each root has been initialized by the point the
34+
/// first safepoint is reached. This really should have been done by the
35+
/// frontend, but the old API made this non-obvious, so we do a potentially
36+
/// redundant store just in case.
37+
static bool DoLowering(Function &F, GCStrategy &S);
38+
3039
namespace {
3140

3241
/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
3342
/// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
3443
/// directed by the GCStrategy. It also performs automatic root initialization
3544
/// and custom intrinsic lowering.
3645
class LowerIntrinsics : public FunctionPass {
37-
bool DoLowering(Function &F, GCStrategy &S);
38-
3946
public:
4047
static char ID;
4148

@@ -72,6 +79,19 @@ class GCMachineCodeAnalysis : public MachineFunctionPass {
7279
};
7380
}
7481

82+
PreservedAnalyses GCLoweringPass::run(Function &F,
83+
FunctionAnalysisManager &FAM) {
84+
auto &Info = FAM.getResult<GCFunctionAnalysis>(F);
85+
86+
bool Changed = DoLowering(F, Info.getStrategy());
87+
88+
if (!Changed)
89+
return PreservedAnalyses::all();
90+
PreservedAnalyses PA;
91+
PA.preserve<DominatorTreeAnalysis>();
92+
return PA;
93+
}
94+
7595
// -----------------------------------------------------------------------------
7696

7797
INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering", false,
@@ -178,14 +198,7 @@ bool LowerIntrinsics::runOnFunction(Function &F) {
178198
return DoLowering(F, S);
179199
}
180200

181-
/// Lower barriers out of existance (if the associated GCStrategy hasn't
182-
/// already done so...), and insert initializing stores to roots as a defensive
183-
/// measure. Given we're going to report all roots live at all safepoints, we
184-
/// need to be able to ensure each root has been initialized by the point the
185-
/// first safepoint is reached. This really should have been done by the
186-
/// frontend, but the old API made this non-obvious, so we do a potentially
187-
/// redundant store just in case.
188-
bool LowerIntrinsics::DoLowering(Function &F, GCStrategy &S) {
201+
bool DoLowering(Function &F, GCStrategy &S) {
189202
SmallVector<AllocaInst *, 32> Roots;
190203

191204
bool MadeChange = false;

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM))
316316
FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
317317
FUNCTION_PASS("flattencfg", FlattenCFGPass())
318318
FUNCTION_PASS("float2int", Float2IntPass())
319+
FUNCTION_PASS("gc-lowering", GCLoweringPass())
319320
FUNCTION_PASS("guard-widening", GuardWideningPass())
320321
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
321322
FUNCTION_PASS("gvn-sink", GVNSinkPass())

0 commit comments

Comments
 (0)