#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION
#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
-#if LLVM_VERSION_MAJOR >= 8
+#if LLVM_VERSION_MAJOR >= 15
+#define GALLIVM_HAVE_CORO 0
+#define GALLIVM_USE_NEW_PASS 1
+#elif LLVM_VERSION_MAJOR >= 8
#define GALLIVM_HAVE_CORO 1
+#define GALLIVM_USE_NEW_PASS 0
#else
#define GALLIVM_HAVE_CORO 0
+#define GALLIVM_USE_NEW_PASS 0
#endif
+#define GALLIVM_COROUTINES (GALLIVM_HAVE_CORO || GALLIVM_USE_NEW_PASS)
+
/* LLVM is transitioning to "opaque pointers", and as such deprecates
* LLVMBuildGEP, LLVMBuildCall, LLVMBuildLoad, replacing them with
* LLVMBuildGEP2, LLVMBuildCall2, LLVMBuildLoad2 respectivelly.
#include <llvm-c/Transforms/Utils.h>
#endif
#include <llvm-c/BitWriter.h>
-#if GALLIVM_HAVE_CORO
+#if GALLIVM_USE_NEW_PASS == 1
+#include <llvm-c/Transforms/PassBuilder.h>
+#elif GALLIVM_HAVE_CORO == 1
#if LLVM_VERSION_MAJOR <= 8 && (defined(PIPE_ARCH_AARCH64) || defined (PIPE_ARCH_ARM) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_MIPS64))
#include <llvm-c/Transforms/IPO.h>
#endif
static boolean
create_pass_manager(struct gallivm_state *gallivm)
{
+#if GALLIVM_USE_NEW_PASS == 0
assert(!gallivm->passmgr);
assert(gallivm->target);
if (!gallivm->passmgr)
return FALSE;
-#if GALLIVM_HAVE_CORO
+#if GALLIVM_HAVE_CORO == 1
gallivm->cgpassmgr = LLVMCreatePassManager();
#endif
/*
free(td_str);
}
-#if GALLIVM_HAVE_CORO
+#if GALLIVM_HAVE_CORO == 1
#if LLVM_VERSION_MAJOR <= 8 && (defined(PIPE_ARCH_AARCH64) || defined (PIPE_ARCH_ARM) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_MIPS64))
LLVMAddArgumentPromotionPass(gallivm->cgpassmgr);
LLVMAddFunctionAttrsPass(gallivm->cgpassmgr);
*/
LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
}
-#if GALLIVM_HAVE_CORO
+#if GALLIVM_HAVE_CORO == 1
LLVMAddCoroCleanupPass(gallivm->passmgr);
#endif
-
+#endif
return TRUE;
}
-
/**
* Free gallivm object's LLVM allocations, but not any generated code
* nor the gallivm object itself.
void
gallivm_free_ir(struct gallivm_state *gallivm)
{
+#if GALLIVM_USE_NEW_PASS == 0
if (gallivm->passmgr) {
LLVMDisposePassManager(gallivm->passmgr);
}
-#if GALLIVM_HAVE_CORO
+#if GALLIVM_HAVE_CORO == 1
if (gallivm->cgpassmgr) {
LLVMDisposePassManager(gallivm->cgpassmgr);
}
#endif
+#endif
if (gallivm->engine) {
/* This will already destroy any associated module */
gallivm->target = NULL;
gallivm->module = NULL;
gallivm->module_name = NULL;
+#if GALLIVM_USE_NEW_PASS == 0
+#if GALLIVM_HAVE_CORO == 1
gallivm->cgpassmgr = NULL;
+#endif
gallivm->passmgr = NULL;
+#endif
gallivm->context = NULL;
gallivm->builder = NULL;
gallivm->cache = NULL;
void
gallivm_compile_module(struct gallivm_state *gallivm)
{
- LLVMValueRef func;
int64_t time_begin = 0;
assert(!gallivm->compiled);
gallivm->builder = NULL;
}
+ LLVMSetDataLayout(gallivm->module, "");
+ assert(!gallivm->engine);
+ if (!init_gallivm_engine(gallivm)) {
+ assert(0);
+ }
+ assert(gallivm->engine);
+
if (gallivm->cache && gallivm->cache->data_size) {
goto skip_cached;
}
if (gallivm_debug & GALLIVM_DEBUG_PERF)
time_begin = os_time_get();
-#if GALLIVM_HAVE_CORO
+#if GALLIVM_USE_NEW_PASS == 1
+ char passes[1024];
+ passes[0] = 0;
+
+ /*
+ * there should be some way to combine these two pass runs but I'm not seeing it,
+ * at the time of writing.
+ */
+ strcpy(passes, "default<O0>");
+
+ LLVMPassBuilderOptionsRef opts = LLVMCreatePassBuilderOptions();
+ LLVMRunPasses(gallivm->module, passes, LLVMGetExecutionEngineTargetMachine(gallivm->engine), opts);
+
+ if (!(gallivm_perf & GALLIVM_PERF_NO_OPT))
+ strcpy(passes, "sroa,early-cse,simplifycfg,reassociate,mem2reg,constprop,instcombine,");
+ else
+ strcpy(passes, "mem2reg");
+
+ LLVMRunPasses(gallivm->module, passes, LLVMGetExecutionEngineTargetMachine(gallivm->engine), opts);
+ LLVMDisposePassBuilderOptions(opts);
+#else
+#if GALLIVM_HAVE_CORO == 1
LLVMRunPassManager(gallivm->cgpassmgr, gallivm->module);
#endif
/* Run optimization passes */
LLVMInitializeFunctionPassManager(gallivm->passmgr);
+ LLVMValueRef func;
func = LLVMGetFirstFunction(gallivm->module);
while (func) {
if (0) {
func = LLVMGetNextFunction(func);
}
LLVMFinalizeFunctionPassManager(gallivm->passmgr);
-
+#endif
if (gallivm_debug & GALLIVM_DEBUG_PERF) {
int64_t time_end = os_time_get();
int time_msec = (int)((time_end - time_begin) / 1000);
* lp_build_create_jit_compiler_for_module()
*/
skip_cached:
- LLVMSetDataLayout(gallivm->module, "");
- assert(!gallivm->engine);
- if (!init_gallivm_engine(gallivm)) {
- assert(0);
- }
- assert(gallivm->engine);
++gallivm->compiled;