Blame SOURCES/0001-gallivm-Make-sure-module-has-the-correct-data-layout.patch

f06792
From 9aca538a8ae017222aded41bc530fef150db351c Mon Sep 17 00:00:00 2001
f06792
From: Tom Stellard <tstellar@redhat.com>
f06792
Date: Fri, 5 May 2017 01:07:00 +0000
f06792
Subject: [PATCH] gallivm: Make sure module has the correct data layout when
f06792
 pass manager runs
f06792
f06792
The datalayout for modules was purposely not being set in order to work around
f06792
the fact that the ExecutionEngine requires that the module's datalayout
f06792
matches the datalayout of the TargetMachine that the ExecutionEngine is
f06792
using.
f06792
f06792
When the pass manager runs on a module with no datalayout, it uses
f06792
the default datalayout which is little-endian.  This causes problems
f06792
on big-endian targets, because some optimizations that are legal on
f06792
little-endian or illegal on big-endian.
f06792
f06792
To resolve this, we set the datalayout prior to running the pass
f06792
manager, and then clear it before creating the ExectionEngine.
f06792
f06792
This patch fixes a lot of piglit tests on big-endian ppc64.
f06792
f06792
Cc: mesa-stable@lists.freedesktop.org
f06792
---
f06792
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 34 +++++++++++++++--------------
f06792
 1 file changed, 18 insertions(+), 16 deletions(-)
f06792
f06792
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
f06792
index ef2580e..9f1ade6 100644
f06792
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
f06792
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
f06792
@@ -125,19 +125,6 @@ create_pass_manager(struct gallivm_state *gallivm)
f06792
    LLVMAddTargetData(gallivm->target, gallivm->passmgr);
f06792
 #endif
f06792
 
f06792
-   /* Setting the module's DataLayout to an empty string will cause the
f06792
-    * ExecutionEngine to copy to the DataLayout string from its target
f06792
-    * machine to the module.  As of LLVM 3.8 the module and the execution
f06792
-    * engine are required to have the same DataLayout.
f06792
-    *
f06792
-    * TODO: This is just a temporary work-around.  The correct solution is
f06792
-    * for gallivm_init_state() to create a TargetMachine and pull the
f06792
-    * DataLayout from there.  Currently, the TargetMachine used by llvmpipe
f06792
-    * is being implicitly created by the EngineBuilder in
f06792
-    * lp_build_create_jit_compiler_for_module()
f06792
-    */
f06792
-
f06792
-#if HAVE_LLVM < 0x0308
f06792
    {
f06792
       char *td_str;
f06792
       // New ones from the Module.
f06792
@@ -145,9 +132,6 @@ create_pass_manager(struct gallivm_state *gallivm)
f06792
       LLVMSetDataLayout(gallivm->module, td_str);
f06792
       free(td_str);
f06792
    }
f06792
-#else
f06792
-   LLVMSetDataLayout(gallivm->module, "");
f06792
-#endif
f06792
 
f06792
    if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
f06792
       /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
f06792
@@ -628,6 +612,24 @@ gallivm_compile_module(struct gallivm_state *gallivm)
f06792
    }
f06792
 
f06792
    if (use_mcjit) {
f06792
+      /* Setting the module's DataLayout to an empty string will cause the
f06792
+       * ExecutionEngine to copy to the DataLayout string from its target
f06792
+       * machine to the module.  As of LLVM 3.8 the module and the execution
f06792
+       * engine are required to have the same DataLayout.
f06792
+       *
f06792
+       * We must make sure we do this after running the optimization passes,
f06792
+       * because those passes need a correct datalayout string.  For example,
f06792
+       * if those optimization passes see an empty datalayout, they will assume
f06792
+       * this is a little endian target and will do optimizations that break big
f06792
+       * endian machines.
f06792
+       *
f06792
+       * TODO: This is just a temporary work-around.  The correct solution is
f06792
+       * for gallivm_init_state() to create a TargetMachine and pull the
f06792
+       * DataLayout from there.  Currently, the TargetMachine used by llvmpipe
f06792
+       * is being implicitly created by the EngineBuilder in
f06792
+       * lp_build_create_jit_compiler_for_module()
f06792
+       */
f06792
+      LLVMSetDataLayout(gallivm->module, "");
f06792
       assert(!gallivm->engine);
f06792
       if (!init_gallivm_engine(gallivm)) {
f06792
          assert(0);
f06792
-- 
f06792
2.9.3
f06792