|
29 | 29 | #include <llvm-c/BitWriter.h>
|
30 | 30 | #include <llvm-c/Core.h>
|
31 | 31 | #include <llvm-c/ExecutionEngine.h>
|
| 32 | +#if LLVM_VERSION_MAJOR > 16 |
| 33 | +#include <llvm-c/Transforms/PassBuilder.h> |
| 34 | +#endif |
32 | 35 | #if LLVM_VERSION_MAJOR > 11
|
33 | 36 | #include <llvm-c/Orc.h>
|
34 | 37 | #include <llvm-c/OrcEE.h>
|
|
38 | 41 | #endif
|
39 | 42 | #include <llvm-c/Support.h>
|
40 | 43 | #include <llvm-c/Target.h>
|
| 44 | +#if LLVM_VERSION_MAJOR < 17 |
41 | 45 | #include <llvm-c/Transforms/IPO.h>
|
42 | 46 | #include <llvm-c/Transforms/PassManagerBuilder.h>
|
43 | 47 | #include <llvm-c/Transforms/Scalar.h>
|
44 | 48 | #if LLVM_VERSION_MAJOR > 6
|
45 | 49 | #include <llvm-c/Transforms/Utils.h>
|
46 | 50 | #endif
|
| 51 | +#endif |
47 | 52 |
|
48 | 53 |
|
49 | 54 | /* Handle of a module emitted via ORC JIT */
|
@@ -564,6 +569,7 @@ llvm_function_reference(LLVMJitContext *context,
|
564 | 569 | static void
|
565 | 570 | llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
|
566 | 571 | {
|
| 572 | +#if LLVM_VERSION_MAJOR < 17 |
567 | 573 | LLVMPassManagerBuilderRef llvm_pmb;
|
568 | 574 | LLVMPassManagerRef llvm_mpm;
|
569 | 575 | LLVMPassManagerRef llvm_fpm;
|
@@ -627,6 +633,31 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
|
627 | 633 | LLVMDisposePassManager(llvm_mpm);
|
628 | 634 |
|
629 | 635 | LLVMPassManagerBuilderDispose(llvm_pmb);
|
| 636 | +#else |
| 637 | + LLVMPassBuilderOptionsRef options; |
| 638 | + LLVMErrorRef err; |
| 639 | + const char *passes; |
| 640 | + |
| 641 | + if (context->base.flags & PGJIT_OPT3) |
| 642 | + passes = "default<O3>"; |
| 643 | + else |
| 644 | + passes = "default<O0>,mem2reg"; |
| 645 | + |
| 646 | + options = LLVMCreatePassBuilderOptions(); |
| 647 | + |
| 648 | +#ifdef LLVM_PASS_DEBUG |
| 649 | + LLVMPassBuilderOptionsSetDebugLogging(options, 1); |
| 650 | +#endif |
| 651 | + |
| 652 | + LLVMPassBuilderOptionsSetInlinerThreshold(options, 512); |
| 653 | + |
| 654 | + err = LLVMRunPasses(module, passes, NULL, options); |
| 655 | + |
| 656 | + if (err) |
| 657 | + elog(ERROR, "failed to JIT module: %s", llvm_error_message(err)); |
| 658 | + |
| 659 | + LLVMDisposePassBuilderOptions(options); |
| 660 | +#endif |
630 | 661 | }
|
631 | 662 |
|
632 | 663 | /*
|
|
0 commit comments