|
29 | 29 | #define __STDC_CONSTANT_MACROS |
30 | 30 | #endif |
31 | 31 |
|
| 32 | +#include "llvm-c/Core.h" |
32 | 33 | #include "llvm-c/BitWriter.h" |
33 | 34 | #include "llvm-c/Analysis.h" |
| 35 | +#include "llvm-c/Transforms/InstCombine.h" |
| 36 | +#include "llvm-c/Transforms/Scalar.h" |
| 37 | +#include "llvm-c/Transforms/IPO.h" |
34 | 38 |
|
35 | 39 | #include "mini-llvm-cpp.h" |
36 | 40 | #include "llvm-jit.h" |
@@ -138,6 +142,7 @@ typedef struct { |
138 | 142 | GHashTable *no_method_table_lmethods; |
139 | 143 | GHashTable *intrins_id_to_intrins; |
140 | 144 | GHashTable *intrins_id_to_type; |
| 145 | + LLVMPassManagerRef func_pass_manager; |
141 | 146 | } MonoLLVMModule; |
142 | 147 |
|
143 | 148 | /* |
@@ -13337,6 +13342,11 @@ emit_method_inner (EmitContext *ctx) |
13337 | 13342 | #endif |
13338 | 13343 | } else { |
13339 | 13344 | //LLVMVerifyFunction (method, 0); |
| 13345 | + if (ctx->module->func_pass_manager) { |
| 13346 | + LLVMInitializeFunctionPassManager (ctx->module->func_pass_manager); |
| 13347 | + LLVMRunFunctionPassManager(ctx->module->func_pass_manager, ctx->lmethod); |
| 13348 | + LLVMFinalizeFunctionPassManager (ctx->module->func_pass_manager); |
| 13349 | + } |
13340 | 13350 | llvm_jit_finalize_method (ctx); |
13341 | 13351 | } |
13342 | 13352 |
|
@@ -13856,13 +13866,22 @@ mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, |
13856 | 13866 | LLVMSetLinkage (module->sentinel_exception, LLVMExternalLinkage); |
13857 | 13867 | mono_llvm_set_is_constant (module->sentinel_exception); |
13858 | 13868 | } |
| 13869 | + |
| 13870 | + module->func_pass_manager = LLVMCreateFunctionPassManagerForModule (module->lmodule); |
| 13871 | + if (module->func_pass_manager) { |
| 13872 | + LLVMAddCFGSimplificationPass (module->func_pass_manager); |
| 13873 | + LLVMAddInstructionCombiningPass (module->func_pass_manager); |
| 13874 | + } |
13859 | 13875 | } |
13860 | 13876 |
|
13861 | 13877 | void |
13862 | 13878 | mono_llvm_free_aot_module (void) |
13863 | 13879 | { |
13864 | 13880 | MonoLLVMModule *module = &aot_module; |
13865 | 13881 |
|
| 13882 | + if (module->func_pass_manager) |
| 13883 | + LLVMDisposePassManager (module->func_pass_manager); |
| 13884 | + |
13866 | 13885 | if (module->lmodule) |
13867 | 13886 | LLVMDisposeModule (module->lmodule); |
13868 | 13887 |
|
|
0 commit comments