|
18 | 18 | #include <llvm-c/BitWriter.h>
|
19 | 19 | #include <llvm-c/Core.h>
|
20 | 20 | #include <llvm-c/ExecutionEngine.h>
|
| 21 | +#if LLVM_VERSION_MAJOR > 16 |
| 22 | +#include <llvm-c/Transforms/PassBuilder.h> |
| 23 | +#endif |
21 | 24 | #if LLVM_VERSION_MAJOR > 11
|
22 | 25 | #include <llvm-c/Orc.h>
|
23 | 26 | #include <llvm-c/OrcEE.h>
|
|
27 | 30 | #endif
|
28 | 31 | #include <llvm-c/Support.h>
|
29 | 32 | #include <llvm-c/Target.h>
|
| 33 | +#if LLVM_VERSION_MAJOR < 17 |
30 | 34 | #include <llvm-c/Transforms/IPO.h>
|
31 | 35 | #include <llvm-c/Transforms/PassManagerBuilder.h>
|
32 | 36 | #include <llvm-c/Transforms/Scalar.h>
|
33 | 37 | #if LLVM_VERSION_MAJOR > 6
|
34 | 38 | #include <llvm-c/Transforms/Utils.h>
|
35 | 39 | #endif
|
| 40 | +#endif |
36 | 41 |
|
37 | 42 | #include "jit/llvmjit.h"
|
38 | 43 | #include "jit/llvmjit_emit.h"
|
@@ -630,6 +635,7 @@ llvm_function_reference(LLVMJitContext *context,
|
630 | 635 | static void
|
631 | 636 | llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
|
632 | 637 | {
|
| 638 | +#if LLVM_VERSION_MAJOR < 17 |
633 | 639 | LLVMPassManagerBuilderRef llvm_pmb;
|
634 | 640 | LLVMPassManagerRef llvm_mpm;
|
635 | 641 | LLVMPassManagerRef llvm_fpm;
|
@@ -693,6 +699,31 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
|
693 | 699 | LLVMDisposePassManager(llvm_mpm);
|
694 | 700 |
|
695 | 701 | LLVMPassManagerBuilderDispose(llvm_pmb);
|
| 702 | +#else |
| 703 | + LLVMPassBuilderOptionsRef options; |
| 704 | + LLVMErrorRef err; |
| 705 | + const char *passes; |
| 706 | + |
| 707 | + if (context->base.flags & PGJIT_OPT3) |
| 708 | + passes = "default<O3>"; |
| 709 | + else |
| 710 | + passes = "default<O0>,mem2reg"; |
| 711 | + |
| 712 | + options = LLVMCreatePassBuilderOptions(); |
| 713 | + |
| 714 | +#ifdef LLVM_PASS_DEBUG |
| 715 | + LLVMPassBuilderOptionsSetDebugLogging(options, 1); |
| 716 | +#endif |
| 717 | + |
| 718 | + LLVMPassBuilderOptionsSetInlinerThreshold(options, 512); |
| 719 | + |
| 720 | + err = LLVMRunPasses(module, passes, NULL, options); |
| 721 | + |
| 722 | + if (err) |
| 723 | + elog(ERROR, "failed to JIT module: %s", llvm_error_message(err)); |
| 724 | + |
| 725 | + LLVMDisposePassBuilderOptions(options); |
| 726 | +#endif |
696 | 727 | }
|
697 | 728 |
|
698 | 729 | /*
|
|
0 commit comments