|
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"
|
@@ -561,6 +566,7 @@ llvm_function_reference(LLVMJitContext *context,
|
561 | 566 | static void
|
562 | 567 | llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
|
563 | 568 | {
|
| 569 | +#if LLVM_VERSION_MAJOR < 17 |
564 | 570 | LLVMPassManagerBuilderRef llvm_pmb;
|
565 | 571 | LLVMPassManagerRef llvm_mpm;
|
566 | 572 | LLVMPassManagerRef llvm_fpm;
|
@@ -624,6 +630,31 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
|
624 | 630 | LLVMDisposePassManager(llvm_mpm);
|
625 | 631 |
|
626 | 632 | LLVMPassManagerBuilderDispose(llvm_pmb);
|
| 633 | +#else |
| 634 | + LLVMPassBuilderOptionsRef options; |
| 635 | + LLVMErrorRef err; |
| 636 | + const char *passes; |
| 637 | + |
| 638 | + if (context->base.flags & PGJIT_OPT3) |
| 639 | + passes = "default<O3>"; |
| 640 | + else |
| 641 | + passes = "default<O0>,mem2reg"; |
| 642 | + |
| 643 | + options = LLVMCreatePassBuilderOptions(); |
| 644 | + |
| 645 | +#ifdef LLVM_PASS_DEBUG |
| 646 | + LLVMPassBuilderOptionsSetDebugLogging(options, 1); |
| 647 | +#endif |
| 648 | + |
| 649 | + LLVMPassBuilderOptionsSetInlinerThreshold(options, 512); |
| 650 | + |
| 651 | + err = LLVMRunPasses(module, passes, NULL, options); |
| 652 | + |
| 653 | + if (err) |
| 654 | + elog(ERROR, "failed to JIT module: %s", llvm_error_message(err)); |
| 655 | + |
| 656 | + LLVMDisposePassBuilderOptions(options); |
| 657 | +#endif |
627 | 658 | }
|
628 | 659 |
|
629 | 660 | /*
|
|
0 commit comments