Mesa (master): gallivm: Run passes per module, not per function.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed May 14 10:06:05 UTC 2014


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

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon May 12 14:29:04 2014 +0100

gallivm: Run passes per module, not per function.

This is how it is meant to be done nowadays.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

---

 src/gallium/auxiliary/gallivm/lp_bld_init.c |   47 +++++++++++----------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 2d854e9..a3549c1 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -499,32 +499,6 @@ gallivm_destroy(struct gallivm_state *gallivm)
 
 
 /**
- * Validate and optimze a function.
- */
-static void
-gallivm_optimize_function(struct gallivm_state *gallivm,
-                          LLVMValueRef func)
-{
-   if (0) {
-      debug_printf("optimizing %s...\n", LLVMGetValueName(func));
-   }
-
-   assert(gallivm->passmgr);
-
-   /* Apply optimizations to LLVM IR */
-   LLVMRunFunctionPassManager(gallivm->passmgr, func);
-
-   if (0) {
-      if (gallivm_debug & GALLIVM_DEBUG_IR) {
-         /* Print the LLVM IR to stderr */
-         lp_debug_dump_value(func);
-         debug_printf("\n");
-      }
-   }
-}
-
-
-/**
  * Validate a function.
  */
 void
@@ -540,8 +514,6 @@ gallivm_verify_function(struct gallivm_state *gallivm,
    }
 #endif
 
-   gallivm_optimize_function(gallivm, func);
-
    if (gallivm_debug & GALLIVM_DEBUG_IR) {
       /* Print the LLVM IR to stderr */
       lp_debug_dump_value(func);
@@ -553,8 +525,27 @@ gallivm_verify_function(struct gallivm_state *gallivm,
 void
 gallivm_compile_module(struct gallivm_state *gallivm)
 {
+   LLVMValueRef func;
+
    assert(!gallivm->compiled);
 
+   if (gallivm->builder) {
+      LLVMDisposeBuilder(gallivm->builder);
+      gallivm->builder = NULL;
+   }
+
+   /* Run optimization passes */
+   LLVMInitializeFunctionPassManager(gallivm->passmgr);
+   func = LLVMGetFirstFunction(gallivm->module);
+   while (func) {
+      if (0) {
+	 debug_printf("optimizing %s...\n", LLVMGetValueName(func));
+      }
+      LLVMRunFunctionPassManager(gallivm->passmgr, func);
+      func = LLVMGetNextFunction(func);
+   }
+   LLVMFinalizeFunctionPassManager(gallivm->passmgr);
+
    /* Dump byte code to a file */
    if (0) {
       LLVMWriteBitcodeToFile(gallivm->module, "llvmpipe.bc");




More information about the mesa-commit mailing list