|
9 | 9 | #include "llvm/IR/PassManager.h" |
10 | 10 | #include "llvm/IR/Instruction.h" |
11 | 11 | #include "llvm/IR/Instructions.h" |
12 | | -#include "llvm/Support/Casting.h" |
13 | 12 | #include "llvm/IR/DerivedTypes.h" |
14 | 13 |
|
15 | 14 | #include "llvm/Passes/PassPlugin.h" |
16 | 15 | #include "llvm/Passes/PassBuilder.h" |
17 | 16 |
|
18 | 17 | #include "llvm/Transforms/Utils/ModuleUtils.h" |
19 | 18 |
|
| 19 | +#if LLVM_VERSION_MAJOR < 17 |
| 20 | + #include "llvm/InitializePasses.h" |
| 21 | +#endif |
| 22 | + |
20 | 23 | namespace { |
21 | 24 | using namespace llvm; |
22 | 25 |
|
@@ -71,13 +74,14 @@ namespace { |
71 | 74 | IRBuilder<> builder(llvm_context); |
72 | 75 |
|
73 | 76 | Type *llvm_void_t = Type::getVoidTy(llvm_context); |
74 | | - Type *llvm_str_t = Type::getInt8PtrTy(llvm_context); |
75 | | - |
76 | | - FunctionType *log_init_function_t = FunctionType::get(llvm_void_t, false); |
77 | | - FunctionCallee log_init_function = module.getOrInsertFunction(log_init_function_name, log_init_function_t); |
| 77 | +#if LLVM_VERSION_MAJOR < 16 |
| 78 | + Type *llvm_str_t = Type::getInt8PtrTy(llvm_context); |
| 79 | +#else |
| 80 | + Type *llvm_str_t = builder.getPtrTy(); |
| 81 | +#endif |
78 | 82 |
|
79 | | - FunctionType *log_call_function_t = FunctionType::get(llvm_void_t, {llvm_str_t}, false); |
80 | | - FunctionCallee log_call_function = module.getOrInsertFunction(log_call_function_name, log_call_function_t); |
| 83 | + FunctionCallee log_init_function = module.getOrInsertFunction(log_init_function_name, llvm_void_t); |
| 84 | + FunctionCallee log_call_function = module.getOrInsertFunction(log_call_function_name, llvm_void_t, llvm_str_t); |
81 | 85 |
|
82 | 86 | FunctionType *log_deinit_function_t = FunctionType::get(llvm_void_t, false); |
83 | 87 | Function *log_deinit_function = |
@@ -116,9 +120,11 @@ namespace { |
116 | 120 | }; |
117 | 121 | } // end of anonymous namespace |
118 | 122 |
|
119 | | -extern "C" PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { |
| 123 | +extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { |
120 | 124 | return { |
121 | | - LLVM_PLUGIN_API_VERSION, "Log-Pass", "v1.0", [](PassBuilder &PB) { |
| 125 | + LLVM_PLUGIN_API_VERSION, "LogPass", "v0.3", |
| 126 | + /* lambda to insert our pass into the pass pipeline. */ |
| 127 | + [](PassBuilder &PB) { |
122 | 128 | PB.registerOptimizerLastEPCallback([](ModulePassManager &MPM, OptimizationLevel OL) { MPM.addPass(LogPass()); }); |
123 | 129 | }}; |
124 | 130 | } |
0 commit comments