diff options
author | paperchalice <liujunchang97@outlook.com> | 2024-01-09 17:42:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 17:42:09 +0800 |
commit | 25e0dc92a1df906d6e42c66a32f1fa764f1acabd (patch) | |
tree | 2603cf1f062e089901200eafc4d5748e6ae9f318 | |
parent | 414ea3a77181ef01d2cc2ad34950fc1c03ce0d41 (diff) | |
download | llvm-25e0dc92a1df906d6e42c66a32f1fa764f1acabd.zip llvm-25e0dc92a1df906d6e42c66a32f1fa764f1acabd.tar.gz llvm-25e0dc92a1df906d6e42c66a32f1fa764f1acabd.tar.bz2 |
[CodeGen] Port `GCLowering` to new pass manager (#75305)
-rw-r--r-- | llvm/include/llvm/CodeGen/CodeGenPassBuilder.h | 1 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/GCMetadata.h | 11 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/MachinePassRegistry.def | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GCRootLowering.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/Passes/PassRegistry.def | 1 |
5 files changed, 37 insertions, 11 deletions
diff --git a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h index 2100c30..c52bd41 100644 --- a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h +++ b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h @@ -488,6 +488,7 @@ Error CodeGenPassBuilder<Derived>::buildPipeline( AddIRPass addIRPass(MPM, Opt.DebugPM); // `ProfileSummaryInfo` is always valid. addIRPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); + addIRPass(RequireAnalysisPass<CollectorMetadataAnalysis, Module>()); addISelPasses(addIRPass); AddMachinePass addPass(MFPM); diff --git a/llvm/include/llvm/CodeGen/GCMetadata.h b/llvm/include/llvm/CodeGen/GCMetadata.h index 9e4e834..ca6a511 100644 --- a/llvm/include/llvm/CodeGen/GCMetadata.h +++ b/llvm/include/llvm/CodeGen/GCMetadata.h @@ -186,6 +186,17 @@ public: Result run(Function &F, FunctionAnalysisManager &FAM); }; +/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or +/// llvm.gcwrite intrinsics, replacing them with simple loads and stores as +/// directed by the GCStrategy. It also performs automatic root initialization +/// and custom intrinsic lowering. +/// +/// This pass requires `CollectorMetadataAnalysis`. +class GCLoweringPass : public PassInfoMixin<GCLoweringPass> { +public: + PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); +}; + /// An analysis pass which caches information about the entire Module. /// Records both the function level information used by GCRoots and a /// cache of the 'active' gc strategy objects for the current Module. diff --git a/llvm/include/llvm/CodeGen/MachinePassRegistry.def b/llvm/include/llvm/CodeGen/MachinePassRegistry.def index b1b8ee8..4ddbb24 100644 --- a/llvm/include/llvm/CodeGen/MachinePassRegistry.def +++ b/llvm/include/llvm/CodeGen/MachinePassRegistry.def @@ -51,6 +51,7 @@ FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass, (TM)) FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass, (TM)) FUNCTION_PASS("expand-reductions", ExpandReductionsPass, ()) FUNCTION_PASS("expandvp", ExpandVectorPredicationPass, ()) +FUNCTION_PASS("gc-lowering", GCLoweringPass, ()) FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, (TM)) FUNCTION_PASS("interleaved-access", InterleavedAccessPass, (TM)) FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass, (TM)) @@ -133,7 +134,6 @@ MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis, #endif DUMMY_FUNCTION_PASS("atomic-expand", AtomicExpandPass, ()) DUMMY_FUNCTION_PASS("codegenprepare", CodeGenPreparePass, ()) -DUMMY_FUNCTION_PASS("gc-lowering", GCLoweringPass, ()) DUMMY_FUNCTION_PASS("stack-protector", StackProtectorPass, ()) #undef DUMMY_FUNCTION_PASS diff --git a/llvm/lib/CodeGen/GCRootLowering.cpp b/llvm/lib/CodeGen/GCRootLowering.cpp index c0ce370..894ab9a 100644 --- a/llvm/lib/CodeGen/GCRootLowering.cpp +++ b/llvm/lib/CodeGen/GCRootLowering.cpp @@ -27,6 +27,15 @@ using namespace llvm; +/// Lower barriers out of existence (if the associated GCStrategy hasn't +/// already done so...), and insert initializing stores to roots as a defensive +/// measure. Given we're going to report all roots live at all safepoints, we +/// need to be able to ensure each root has been initialized by the point the +/// first safepoint is reached. This really should have been done by the +/// frontend, but the old API made this non-obvious, so we do a potentially +/// redundant store just in case. +static bool DoLowering(Function &F, GCStrategy &S); + namespace { /// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or @@ -34,8 +43,6 @@ namespace { /// directed by the GCStrategy. It also performs automatic root initialization /// and custom intrinsic lowering. class LowerIntrinsics : public FunctionPass { - bool DoLowering(Function &F, GCStrategy &S); - public: static char ID; @@ -72,6 +79,19 @@ public: }; } +PreservedAnalyses GCLoweringPass::run(Function &F, + FunctionAnalysisManager &FAM) { + auto &Info = FAM.getResult<GCFunctionAnalysis>(F); + + bool Changed = DoLowering(F, Info.getStrategy()); + + if (!Changed) + return PreservedAnalyses::all(); + PreservedAnalyses PA; + PA.preserve<DominatorTreeAnalysis>(); + return PA; +} + // ----------------------------------------------------------------------------- INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering", false, @@ -178,14 +198,7 @@ bool LowerIntrinsics::runOnFunction(Function &F) { return DoLowering(F, S); } -/// Lower barriers out of existance (if the associated GCStrategy hasn't -/// already done so...), and insert initializing stores to roots as a defensive -/// measure. Given we're going to report all roots live at all safepoints, we -/// need to be able to ensure each root has been initialized by the point the -/// first safepoint is reached. This really should have been done by the -/// frontend, but the old API made this non-obvious, so we do a potentially -/// redundant store just in case. -bool LowerIntrinsics::DoLowering(Function &F, GCStrategy &S) { +bool DoLowering(Function &F, GCStrategy &S) { SmallVector<AllocaInst *, 32> Roots; bool MadeChange = false; diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 1b6c0e4..bceac83 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -316,6 +316,7 @@ FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM)) FUNCTION_PASS("fix-irreducible", FixIrreduciblePass()) FUNCTION_PASS("flattencfg", FlattenCFGPass()) FUNCTION_PASS("float2int", Float2IntPass()) +FUNCTION_PASS("gc-lowering", GCLoweringPass()) FUNCTION_PASS("guard-widening", GuardWideningPass()) FUNCTION_PASS("gvn-hoist", GVNHoistPass()) FUNCTION_PASS("gvn-sink", GVNSinkPass()) |