ac/radeonsi: refactor out pass manager init to common code.
authorDave Airlie <airlied@redhat.com>
Tue, 26 Jun 2018 22:52:20 +0000 (08:52 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 3 Jul 2018 19:18:01 +0000 (05:18 +1000)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_llvm_util.c
src/amd/common/ac_llvm_util.h
src/gallium/drivers/radeonsi/si_pipe.c

index 25ff4a8c22ad020f447e3ed88b4fef67e14337a8..b25f9e3e6ddd0d1de2509f2a50b307cda5ead3de 100644 (file)
 #include "util/bitscan.h"
 #include <llvm-c/Core.h>
 #include <llvm-c/Support.h>
+#include <llvm-c/Transforms/IPO.h>
+#include <llvm-c/Transforms/Scalar.h>
+#if HAVE_LLVM >= 0x0700
+#include <llvm-c/Transforms/Utils.h>
+#endif
 #include "c11/threads.h"
 #include "util/u_math.h"
 
@@ -160,6 +165,31 @@ LLVMTargetMachineRef ac_create_target_machine(enum radeon_family family,
        return tm;
 }
 
+LLVMPassManagerRef ac_create_passmgr(LLVMTargetLibraryInfoRef target_library_info,
+                                    bool check_ir)
+{
+       LLVMPassManagerRef passmgr = LLVMCreatePassManager();
+       if (!passmgr)
+               return NULL;
+
+       LLVMAddTargetLibraryInfo(target_library_info,
+                                passmgr);
+
+       if (check_ir)
+               LLVMAddVerifierPass(passmgr);
+       LLVMAddAlwaysInlinerPass(passmgr);
+       /* This pass should eliminate all the load and store instructions. */
+       LLVMAddPromoteMemoryToRegisterPass(passmgr);
+       LLVMAddScalarReplAggregatesPass(passmgr);
+       LLVMAddLICMPass(passmgr);
+       LLVMAddAggressiveDCEPass(passmgr);
+       LLVMAddCFGSimplificationPass(passmgr);
+       /* This is recommended by the instruction combining pass. */
+       LLVMAddEarlyCSEMemSSAPass(passmgr);
+       LLVMAddInstructionCombiningPass(passmgr);
+       return passmgr;
+}
+
 static const char *attr_to_str(enum ac_func_attr attr)
 {
    switch (attr) {
index 4311c5ea8a4c52c5029784fc16d77e04c7bd41c6..8d4f7d83150daf37bcf0726c4b7018da52af73e5 100644 (file)
@@ -111,6 +111,8 @@ ac_get_store_intr_attribs(bool writeonly_memory)
 unsigned
 ac_count_scratch_private_memory(LLVMValueRef function);
 
+LLVMPassManagerRef ac_create_passmgr(LLVMTargetLibraryInfoRef target_library_info,
+                                    bool check_ir);
 void ac_init_llvm_once(void);
 
 #ifdef __cplusplus
index 0d6d93a73586ecfb08652a34ccba4f63b6fdf43f..0f58286fed126b2fc3dd0f0917bfa2ed4b445b12 100644 (file)
 #include "vl/vl_decoder.h"
 #include "driver_ddebug/dd_util.h"
 
-#include <llvm-c/Transforms/IPO.h>
-#include <llvm-c/Transforms/Scalar.h>
-#if HAVE_LLVM >= 0x0700
-#include <llvm-c/Transforms/Utils.h>
-#endif
-
 static const struct debug_named_value debug_options[] = {
        /* Shader logging options: */
        { "vs", DBG(VS), "Print vertex shaders" },
@@ -131,27 +125,10 @@ static void si_init_compiler(struct si_screen *sscreen,
        if (!compiler->target_library_info)
                return;
 
-       compiler->passmgr = LLVMCreatePassManager();
+       compiler->passmgr = ac_create_passmgr(compiler->target_library_info,
+                                             (sscreen->debug_flags & DBG(CHECK_IR)));
        if (!compiler->passmgr)
                return;
-
-       LLVMAddTargetLibraryInfo(compiler->target_library_info,
-                                compiler->passmgr);
-
-       /* Add LLVM passes into the pass manager. */
-       if (sscreen->debug_flags & DBG(CHECK_IR))
-               LLVMAddVerifierPass(compiler->passmgr);
-
-       LLVMAddAlwaysInlinerPass(compiler->passmgr);
-       /* This pass should eliminate all the load and store instructions. */
-       LLVMAddPromoteMemoryToRegisterPass(compiler->passmgr);
-       LLVMAddScalarReplAggregatesPass(compiler->passmgr);
-       LLVMAddLICMPass(compiler->passmgr);
-       LLVMAddAggressiveDCEPass(compiler->passmgr);
-       LLVMAddCFGSimplificationPass(compiler->passmgr);
-       /* This is recommended by the instruction combining pass. */
-       LLVMAddEarlyCSEMemSSAPass(compiler->passmgr);
-       LLVMAddInstructionCombiningPass(compiler->passmgr);
 }
 
 static void si_destroy_compiler(struct si_compiler *compiler)