From: Dave Airlie <airl...@redhat.com>

---
 src/amd/common/ac_llvm_util.c          | 30 ++++++++++++++++++++++++++
 src/amd/common/ac_llvm_util.h          |  2 ++
 src/gallium/drivers/radeonsi/si_pipe.c | 27 ++---------------------
 3 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/src/amd/common/ac_llvm_util.c b/src/amd/common/ac_llvm_util.c
index f33691dcc92..06b79a3d1cb 100644
--- a/src/amd/common/ac_llvm_util.c
+++ b/src/amd/common/ac_llvm_util.c
@@ -28,6 +28,11 @@
 #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"
 
@@ -157,6 +162,31 @@ LLVMTargetMachineRef ac_create_target_machine(enum 
radeon_family family,
        return tm;
 }
 
+LLVMPassManagerRef ac_init_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) {
diff --git a/src/amd/common/ac_llvm_util.h b/src/amd/common/ac_llvm_util.h
index 4a894d0cc8f..b32257a52f3 100644
--- a/src/amd/common/ac_llvm_util.h
+++ b/src/amd/common/ac_llvm_util.h
@@ -110,6 +110,8 @@ ac_get_store_intr_attribs(bool writeonly_memory)
 unsigned
 ac_count_scratch_private_memory(LLVMValueRef function);
 
+LLVMPassManagerRef ac_init_passmgr(LLVMTargetLibraryInfoRef 
target_library_info,
+                                  bool check_ir);
 void ac_init_llvm_once(void);
 
 #ifdef __cplusplus
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c 
b/src/gallium/drivers/radeonsi/si_pipe.c
index e1db4cccdde..aca61670765 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -41,12 +41,6 @@
 #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" },
@@ -130,28 +124,11 @@ static void si_init_compiler(struct si_screen *sscreen,
        if (!compiler->target_library_info)
                return;
 
-       compiler->passmgr = LLVMCreatePassManager();
+       compiler->passmgr = ac_init_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);
-
        /* Get the data layout. */
        LLVMTargetDataRef data_layout = 
LLVMCreateTargetDataLayout(compiler->tm);
        if (!data_layout)
-- 
2.17.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to