From a699d6ca806e73e75c9db6e04321a849da4a441e Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Sat, 2 Oct 2021 18:19:33 -0400 Subject: [PATCH] [LLVM][PM] Start making LateLowerGC NewPM compatible --- src/llvm-late-gc-lowering.cpp | 44 +++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index d178778b7054e..f8399bbae11b1 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -305,9 +305,9 @@ namespace llvm { void initializeLateLowerGCFramePass(PassRegistry &Registry); } -struct LateLowerGCFrame: public FunctionPass, private JuliaPassContext { +struct LateLowerGCFrameLegacy: public FunctionPass { static char ID; - LateLowerGCFrame() : FunctionPass(ID) + LateLowerGCFrameLegacy() : FunctionPass(ID) { llvm::initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry()); } @@ -320,6 +320,17 @@ struct LateLowerGCFrame: public FunctionPass, private JuliaPassContext { AU.setPreservesCFG(); } +private: + bool runOnFunction(Function &F) override; +}; + +struct LateLowerGCFrame: private JuliaPassContext { + function_ref GetDT; + LateLowerGCFrame(function_ref GetDT) : GetDT(GetDT) {} + +public: + bool runOnFunction(Function &F); + private: CallInst *pgcstack; @@ -350,8 +361,6 @@ struct LateLowerGCFrame: public FunctionPass, private JuliaPassContext { void PlaceGCFrameStore(State &S, unsigned R, unsigned MinColorRoot, const std::vector &Colors, Value *GCFrame, Instruction *InsertBefore); void PlaceGCFrameStores(State &S, unsigned MinColorRoot, const std::vector &Colors, Value *GCFrame); void PlaceRootsAndUpdateCalls(std::vector &Colors, State &S, std::map>); - bool doInitialization(Module &M) override; - bool runOnFunction(Function &F) override; bool CleanupIR(Function &F, State *S=nullptr); void NoteUseChain(State &S, BBState &BBS, User *TheUser); SmallVector GetPHIRefinements(PHINode *phi, State &S); @@ -1388,7 +1397,7 @@ void LateLowerGCFrame::FixUpRefinements(ArrayRef PHINumbers, State &S) j++; if (auto inst = dyn_cast(S.ReversePtrNumbering[refine])) { if (!S.DT) - S.DT = &getAnalysis().getDomTree(); + S.DT = &GetDT(); if (S.DT->dominates(inst, Phi)) continue; // Decrement `j` so we'll overwrite/ignore it. @@ -2000,7 +2009,7 @@ void LateLowerGCFrame::ComputeLiveSets(State &S) { // add in any extra live values. if (!S.GCPreserves.empty()) { if (!S.DT) { - S.DT = &getAnalysis().getDomTree(); + S.DT = &GetDT(); } for (auto it2 : S.GCPreserves) { if (!S.DT->dominates(it2.first, Safepoint)) @@ -2658,16 +2667,9 @@ void LateLowerGCFrame::PlaceRootsAndUpdateCalls(std::vector &Colors, State } } -bool LateLowerGCFrame::doInitialization(Module &M) { - // Initialize platform-agnostic references. - initAll(M); - return true; -} - bool LateLowerGCFrame::runOnFunction(Function &F) { + initAll(*F.getParent()); LLVM_DEBUG(dbgs() << "GC ROOT PLACEMENT: Processing function " << F.getName() << "\n"); - // Check availability of functions again since they might have been deleted. - initFunctions(*F.getParent()); if (!pgcstack_getter) return CleanupIR(F); @@ -2684,11 +2686,19 @@ bool LateLowerGCFrame::runOnFunction(Function &F) { return true; } -char LateLowerGCFrame::ID = 0; -static RegisterPass X("LateLowerGCFrame", "Late Lower GCFrame Pass", false, false); +bool LateLowerGCFrameLegacy::runOnFunction(Function &F) { + auto GetDT = [this]() -> DominatorTree & { + return getAnalysis().getDomTree(); + }; + auto lateLowerGCFrame = LateLowerGCFrame(GetDT); + return lateLowerGCFrame.runOnFunction(F); +} + +char LateLowerGCFrameLegacy::ID = 0; +static RegisterPass X("LateLowerGCFrame", "Late Lower GCFrame Pass", false, false); Pass *createLateLowerGCFramePass() { - return new LateLowerGCFrame(); + return new LateLowerGCFrameLegacy(); } extern "C" JL_DLLEXPORT void LLVMExtraAddLateLowerGCFramePass(LLVMPassManagerRef PM)