|
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-c/Core.h>
|
6 | 7 | #include <llvm-c/Types.h>
|
@@ -70,23 +71,8 @@ using namespace llvm;
|
70 | 71 | * handler structures to tell LLVM that it is free to re-use the stack slot
|
71 | 72 | * while the handler is not being used.
|
72 | 73 | */
|
73 |
| -struct LowerExcHandlers : public FunctionPass { |
74 |
| - static char ID; |
75 |
| - LowerExcHandlers() : FunctionPass(ID) |
76 |
| - {} |
77 |
| - |
78 |
| -private: |
79 |
| - Function *except_enter_func; |
80 |
| - Function *leave_func; |
81 |
| - Function *jlenter_func; |
82 |
| - Function *setjmp_func; |
83 |
| - Function *lifetime_start; |
84 |
| - Function *lifetime_end; |
85 |
| - |
86 |
| - bool doInitialization(Module &M) override; |
87 |
| - bool runOnFunction(Function &F) override; |
88 |
| -}; |
89 | 74 |
|
| 75 | +namespace { |
90 | 76 | /*
|
91 | 77 | * If the module doesn't have declarations for the jl_enter_handler and setjmp
|
92 | 78 | * functions, insert them.
|
@@ -115,24 +101,19 @@ static void ensure_enter_function(Module &M)
|
115 | 101 | }
|
116 | 102 | }
|
117 | 103 |
|
118 |
| -bool LowerExcHandlers::doInitialization(Module &M) { |
119 |
| - except_enter_func = M.getFunction("julia.except_enter"); |
| 104 | +static bool lowerExcHandlers(Function &F) { |
| 105 | + Module &M = *F.getParent(); |
| 106 | + Function *except_enter_func = M.getFunction("julia.except_enter"); |
120 | 107 | if (!except_enter_func)
|
121 |
| - return false; |
| 108 | + return false; // No EH frames in this module |
122 | 109 | ensure_enter_function(M);
|
123 |
| - leave_func = M.getFunction(XSTR(jl_pop_handler)); |
124 |
| - jlenter_func = M.getFunction(XSTR(jl_enter_handler)); |
125 |
| - setjmp_func = M.getFunction(jl_setjmp_name); |
| 110 | + Function *leave_func = M.getFunction(XSTR(jl_pop_handler)); |
| 111 | + Function *jlenter_func = M.getFunction(XSTR(jl_enter_handler)); |
| 112 | + Function *setjmp_func = M.getFunction(jl_setjmp_name); |
126 | 113 |
|
127 | 114 | auto T_pint8 = Type::getInt8PtrTy(M.getContext(), 0);
|
128 |
| - lifetime_start = Intrinsic::getDeclaration(&M, Intrinsic::lifetime_start, { T_pint8 }); |
129 |
| - lifetime_end = Intrinsic::getDeclaration(&M, Intrinsic::lifetime_end, { T_pint8 }); |
130 |
| - return true; |
131 |
| -} |
132 |
| - |
133 |
| -bool LowerExcHandlers::runOnFunction(Function &F) { |
134 |
| - if (!except_enter_func) |
135 |
| - return false; // No EH frames in this module |
| 115 | + Function *lifetime_start = Intrinsic::getDeclaration(&M, Intrinsic::lifetime_start, { T_pint8 }); |
| 116 | + Function *lifetime_end = Intrinsic::getDeclaration(&M, Intrinsic::lifetime_end, { T_pint8 }); |
136 | 117 |
|
137 | 118 | /* Step 1: EH Depth Numbering */
|
138 | 119 | std::map<llvm::CallInst *, int> EnterDepth;
|
@@ -237,14 +218,32 @@ bool LowerExcHandlers::runOnFunction(Function &F) {
|
237 | 218 | return true;
|
238 | 219 | }
|
239 | 220 |
|
240 |
| -char LowerExcHandlers::ID = 0; |
241 |
| -static RegisterPass<LowerExcHandlers> X("LowerExcHandlers", "Lower Julia Exception Handlers", |
| 221 | +} // anonymous namespace |
| 222 | + |
| 223 | +PreservedAnalyses LowerExcHandlers::run(Function &F, FunctionAnalysisManager &AM) |
| 224 | +{ |
| 225 | + lowerExcHandlers(F); |
| 226 | + return PreservedAnalyses::all(); |
| 227 | +} |
| 228 | + |
| 229 | + |
| 230 | +struct LowerExcHandlersLegacy : public FunctionPass { |
| 231 | + static char ID; |
| 232 | + LowerExcHandlersLegacy() : FunctionPass(ID) |
| 233 | + {} |
| 234 | + bool runOnFunction(Function &F) { |
| 235 | + return lowerExcHandlers(F); |
| 236 | + } |
| 237 | +}; |
| 238 | + |
| 239 | +char LowerExcHandlersLegacy::ID = 0; |
| 240 | +static RegisterPass<LowerExcHandlersLegacy> X("LowerExcHandlers", "Lower Julia Exception Handlers", |
242 | 241 | false /* Only looks at CFG */,
|
243 | 242 | false /* Analysis Pass */);
|
244 | 243 |
|
245 | 244 | Pass *createLowerExcHandlersPass()
|
246 | 245 | {
|
247 |
| - return new LowerExcHandlers(); |
| 246 | + return new LowerExcHandlersLegacy(); |
248 | 247 | }
|
249 | 248 |
|
250 | 249 | extern "C" JL_DLLEXPORT void LLVMExtraAddLowerExcHandlersPass_impl(LLVMPassManagerRef PM)
|
|
0 commit comments