|
27 | 27 |
|
28 | 28 | using namespace llvm; |
29 | 29 |
|
| 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 | + |
30 | 39 | namespace { |
31 | 40 |
|
32 | 41 | /// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or |
33 | 42 | /// llvm.gcwrite intrinsics, replacing them with simple loads and stores as |
34 | 43 | /// directed by the GCStrategy. It also performs automatic root initialization |
35 | 44 | /// and custom intrinsic lowering. |
36 | 45 | class LowerIntrinsics : public FunctionPass { |
37 | | - bool DoLowering(Function &F, GCStrategy &S); |
38 | | - |
39 | 46 | public: |
40 | 47 | static char ID; |
41 | 48 |
|
@@ -72,6 +79,19 @@ class GCMachineCodeAnalysis : public MachineFunctionPass { |
72 | 79 | }; |
73 | 80 | } |
74 | 81 |
|
| 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 | + |
75 | 95 | // ----------------------------------------------------------------------------- |
76 | 96 |
|
77 | 97 | INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering", false, |
@@ -178,14 +198,7 @@ bool LowerIntrinsics::runOnFunction(Function &F) { |
178 | 198 | return DoLowering(F, S); |
179 | 199 | } |
180 | 200 |
|
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) { |
189 | 202 | SmallVector<AllocaInst *, 32> Roots; |
190 | 203 |
|
191 | 204 | bool MadeChange = false; |
|
0 commit comments