Skip to content

Commit a699d6c

Browse files
committed
[LLVM][PM] Start making LateLowerGC NewPM compatible
1 parent dc02b48 commit a699d6c

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/llvm-late-gc-lowering.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ namespace llvm {
305305
void initializeLateLowerGCFramePass(PassRegistry &Registry);
306306
}
307307

308-
struct LateLowerGCFrame: public FunctionPass, private JuliaPassContext {
308+
struct LateLowerGCFrameLegacy: public FunctionPass {
309309
static char ID;
310-
LateLowerGCFrame() : FunctionPass(ID)
310+
LateLowerGCFrameLegacy() : FunctionPass(ID)
311311
{
312312
llvm::initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
313313
}
@@ -320,6 +320,17 @@ struct LateLowerGCFrame: public FunctionPass, private JuliaPassContext {
320320
AU.setPreservesCFG();
321321
}
322322

323+
private:
324+
bool runOnFunction(Function &F) override;
325+
};
326+
327+
struct LateLowerGCFrame: private JuliaPassContext {
328+
function_ref<DominatorTree &()> GetDT;
329+
LateLowerGCFrame(function_ref<DominatorTree &()> GetDT) : GetDT(GetDT) {}
330+
331+
public:
332+
bool runOnFunction(Function &F);
333+
323334
private:
324335
CallInst *pgcstack;
325336

@@ -350,8 +361,6 @@ struct LateLowerGCFrame: public FunctionPass, private JuliaPassContext {
350361
void PlaceGCFrameStore(State &S, unsigned R, unsigned MinColorRoot, const std::vector<int> &Colors, Value *GCFrame, Instruction *InsertBefore);
351362
void PlaceGCFrameStores(State &S, unsigned MinColorRoot, const std::vector<int> &Colors, Value *GCFrame);
352363
void PlaceRootsAndUpdateCalls(std::vector<int> &Colors, State &S, std::map<Value *, std::pair<int, int>>);
353-
bool doInitialization(Module &M) override;
354-
bool runOnFunction(Function &F) override;
355364
bool CleanupIR(Function &F, State *S=nullptr);
356365
void NoteUseChain(State &S, BBState &BBS, User *TheUser);
357366
SmallVector<int, 1> GetPHIRefinements(PHINode *phi, State &S);
@@ -1388,7 +1397,7 @@ void LateLowerGCFrame::FixUpRefinements(ArrayRef<int> PHINumbers, State &S)
13881397
j++;
13891398
if (auto inst = dyn_cast<Instruction>(S.ReversePtrNumbering[refine])) {
13901399
if (!S.DT)
1391-
S.DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1400+
S.DT = &GetDT();
13921401
if (S.DT->dominates(inst, Phi))
13931402
continue;
13941403
// Decrement `j` so we'll overwrite/ignore it.
@@ -2000,7 +2009,7 @@ void LateLowerGCFrame::ComputeLiveSets(State &S) {
20002009
// add in any extra live values.
20012010
if (!S.GCPreserves.empty()) {
20022011
if (!S.DT) {
2003-
S.DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
2012+
S.DT = &GetDT();
20042013
}
20052014
for (auto it2 : S.GCPreserves) {
20062015
if (!S.DT->dominates(it2.first, Safepoint))
@@ -2658,16 +2667,9 @@ void LateLowerGCFrame::PlaceRootsAndUpdateCalls(std::vector<int> &Colors, State
26582667
}
26592668
}
26602669

2661-
bool LateLowerGCFrame::doInitialization(Module &M) {
2662-
// Initialize platform-agnostic references.
2663-
initAll(M);
2664-
return true;
2665-
}
2666-
26672670
bool LateLowerGCFrame::runOnFunction(Function &F) {
2671+
initAll(*F.getParent());
26682672
LLVM_DEBUG(dbgs() << "GC ROOT PLACEMENT: Processing function " << F.getName() << "\n");
2669-
// Check availability of functions again since they might have been deleted.
2670-
initFunctions(*F.getParent());
26712673
if (!pgcstack_getter)
26722674
return CleanupIR(F);
26732675

@@ -2684,11 +2686,19 @@ bool LateLowerGCFrame::runOnFunction(Function &F) {
26842686
return true;
26852687
}
26862688

2687-
char LateLowerGCFrame::ID = 0;
2688-
static RegisterPass<LateLowerGCFrame> X("LateLowerGCFrame", "Late Lower GCFrame Pass", false, false);
2689+
bool LateLowerGCFrameLegacy::runOnFunction(Function &F) {
2690+
auto GetDT = [this]() -> DominatorTree & {
2691+
return getAnalysis<DominatorTreeWrapperPass>().getDomTree();
2692+
};
2693+
auto lateLowerGCFrame = LateLowerGCFrame(GetDT);
2694+
return lateLowerGCFrame.runOnFunction(F);
2695+
}
2696+
2697+
char LateLowerGCFrameLegacy::ID = 0;
2698+
static RegisterPass<LateLowerGCFrameLegacy> X("LateLowerGCFrame", "Late Lower GCFrame Pass", false, false);
26892699

26902700
Pass *createLateLowerGCFramePass() {
2691-
return new LateLowerGCFrame();
2701+
return new LateLowerGCFrameLegacy();
26922702
}
26932703

26942704
extern "C" JL_DLLEXPORT void LLVMExtraAddLateLowerGCFramePass(LLVMPassManagerRef PM)

0 commit comments

Comments
 (0)