Module: Mesa
Branch: master
Commit: 9b82d128c96ec73eaef6b167a4651ae9716a0424
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9b82d128c96ec73eaef6b167a4651ae9716a0424

Author: Marek Olšák <[email protected]>
Date:   Thu Jul  5 02:27:45 2018 -0400

ac: run LLVM optimization passes only on the final function after inlining

---

 src/amd/common/ac_llvm_helper.cpp | 6 ++++++
 src/amd/common/ac_llvm_util.c     | 7 +++++++
 src/amd/common/ac_llvm_util.h     | 1 +
 3 files changed, 14 insertions(+)

diff --git a/src/amd/common/ac_llvm_helper.cpp 
b/src/amd/common/ac_llvm_helper.cpp
index 4348ebd36e..e0943135fa 100644
--- a/src/amd/common/ac_llvm_helper.cpp
+++ b/src/amd/common/ac_llvm_helper.cpp
@@ -36,6 +36,7 @@
 #include <llvm/Target/TargetMachine.h>
 #include <llvm/IR/IRBuilder.h>
 #include <llvm/Analysis/TargetLibraryInfo.h>
+#include <llvm/Transforms/IPO.h>
 
 #include <llvm/IR/LegacyPassManager.h>
 #if HAVE_LLVM < 0x0700
@@ -165,3 +166,8 @@ bool ac_compile_module_to_binary(struct ac_compiler_passes 
*p, LLVMModuleRef mod
                fprintf(stderr, "amd: cannot read an ELF shader binary\n");
        return success;
 }
+
+void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr)
+{
+       llvm::unwrap(passmgr)->add(llvm::createBarrierNoopPass());
+}
diff --git a/src/amd/common/ac_llvm_util.c b/src/amd/common/ac_llvm_util.c
index 8d73df4e31..0c8dbf1ec5 100644
--- a/src/amd/common/ac_llvm_util.c
+++ b/src/amd/common/ac_llvm_util.c
@@ -181,6 +181,13 @@ static LLVMPassManagerRef 
ac_create_passmgr(LLVMTargetLibraryInfoRef target_libr
        if (check_ir)
                LLVMAddVerifierPass(passmgr);
        LLVMAddAlwaysInlinerPass(passmgr);
+       /* Normally, the pass manager runs all passes on one function before
+        * moving onto another. Adding a barrier no-op pass forces the pass
+        * manager to run the inliner on all functions first, which makes sure
+        * that the following passes are only run on the remaining non-inline
+        * function, so it removes useless work done on dead inline functions.
+        */
+       ac_llvm_add_barrier_noop_pass(passmgr);
        /* This pass should eliminate all the load and store instructions. */
        LLVMAddPromoteMemoryToRegisterPass(passmgr);
        LLVMAddScalarReplAggregatesPass(passmgr);
diff --git a/src/amd/common/ac_llvm_util.h b/src/amd/common/ac_llvm_util.h
index 373fd8d28d..e5b93037d2 100644
--- a/src/amd/common/ac_llvm_util.h
+++ b/src/amd/common/ac_llvm_util.h
@@ -133,6 +133,7 @@ struct ac_compiler_passes 
*ac_create_llvm_passes(LLVMTargetMachineRef tm);
 void ac_destroy_llvm_passes(struct ac_compiler_passes *p);
 bool ac_compile_module_to_binary(struct ac_compiler_passes *p, LLVMModuleRef 
module,
                                 struct ac_shader_binary *binary);
+void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr);
 
 #ifdef __cplusplus
 }

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to