|
1 | 1 | // This file is a part of Julia. License is MIT: https://julialang.org/license
|
2 | 2 |
|
3 | 3 | #include "llvm-version.h"
|
| 4 | +#include "passes.h" |
4 | 5 |
|
5 | 6 | #include <llvm/IR/LegacyPassManager.h>
|
6 | 7 | #include <llvm/IR/Function.h>
|
@@ -28,21 +29,18 @@ using namespace llvm;
|
28 | 29 | // This pass targets typical back-ends for which the standard Julia
|
29 | 30 | // runtime library is available. Atypical back-ends should supply
|
30 | 31 | // 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); |
35 | 37 |
|
36 | 38 | private:
|
37 | 39 | Function *queueRootFunc;
|
38 | 40 | Function *poolAllocFunc;
|
39 | 41 | Function *bigAllocFunc;
|
40 | 42 | Instruction *pgcstack;
|
41 | 43 |
|
42 |
| - bool doInitialization(Module &M) override; |
43 |
| - bool doFinalization(Module &M) override; |
44 |
| - bool runOnFunction(Function &F) override; |
45 |
| - |
46 | 44 | // Lowers a `julia.new_gc_frame` intrinsic.
|
47 | 45 | Value *lowerNewGCFrame(CallInst *target, Function &F);
|
48 | 46 |
|
@@ -325,12 +323,55 @@ bool FinalLowerGC::runOnFunction(Function &F)
|
325 | 323 | return true;
|
326 | 324 | }
|
327 | 325 |
|
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); |
330 | 371 |
|
331 | 372 | Pass *createFinalLowerGCPass()
|
332 | 373 | {
|
333 |
| - return new FinalLowerGC(); |
| 374 | + return new FinalLowerGCLegacy(); |
334 | 375 | }
|
335 | 376 |
|
336 | 377 | extern "C" JL_DLLEXPORT void LLVMExtraAddFinalLowerGCPass_impl(LLVMPassManagerRef PM)
|
|
0 commit comments