gallivm: Use standard LLVMSetAlignment from LLVM 3.4 onwards.
authorJose Fonseca <jfonseca@vmware.com>
Sat, 2 Apr 2016 13:31:16 +0000 (14:31 +0100)
committerJose Fonseca <jfonseca@vmware.com>
Sun, 3 Apr 2016 08:51:27 +0000 (09:51 +0100)
Only provide a fallback for LLVM 3.3.

One less dependency on LLVM C++ interface.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/gallivm/lp_bld.h
src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c
src/gallium/auxiliary/gallivm/lp_bld_gather.c
src/gallium/auxiliary/gallivm/lp_bld_init.h
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
src/gallium/auxiliary/gallivm/lp_bld_struct.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index b48bdcc779ea2c707b3692cacacb71609411b886..9c68d4fbf78e964d5cc236a6f182b7ff51ebefbb 100644 (file)
@@ -817,7 +817,7 @@ store_aos(struct gallivm_state *gallivm,
 #endif
 
    /* Unaligned store due to the vertex header */
-   lp_set_store_alignment(LLVMBuildStore(builder, value, data_ptr), sizeof(float));
+   LLVMSetAlignment(LLVMBuildStore(builder, value, data_ptr), sizeof(float));
 }
 
 /**
@@ -1069,7 +1069,7 @@ store_clip(struct gallivm_state *gallivm,
       clip_ptr = LLVMBuildPointerCast(builder, clip_ptr, clip_ptr_type, "");
 
       /* Unaligned store */
-      lp_set_store_alignment(LLVMBuildStore(builder, aos[j], clip_ptr), sizeof(float));
+      LLVMSetAlignment(LLVMBuildStore(builder, aos[j], clip_ptr), sizeof(float));
    }
 }
 
index 7ba925c480350d15b4aaa607149618fb2c3459f9..239c27e3c255dc8ab51dc2557947c56fdac81d9a 100644 (file)
@@ -95,4 +95,18 @@ typedef void *LLVMMCJITMemoryManagerRef;
 #define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION
 #define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
 
+
+/*
+ * Before LLVM 3.4 LLVMSetAlignment only supported GlobalValue, not
+ * LoadInst/StoreInst as we need.
+ */
+#if HAVE_LLVM < 0x0304
+#  ifdef __cplusplus
+      extern "C"
+#  endif
+   void LLVMSetAlignmentBackport(LLVMValueRef V, unsigned Bytes);
+#  define LLVMSetAlignment LLVMSetAlignmentBackport
+#endif
+
+
 #endif /* LP_BLD_H */
index ee3ca86c000adbb9a19f3dc2d635636feb469e19..8cad3a6fc651f37cae99798b803b87d05e57a83a 100644 (file)
@@ -74,7 +74,7 @@ lp_build_fetch_rgba_aos_array(struct gallivm_state *gallivm,
    ptr = LLVMBuildGEP(builder, base_ptr, &offset, 1, "");
    ptr = LLVMBuildPointerCast(builder, ptr, LLVMPointerType(src_vec_type, 0), "");
    res = LLVMBuildLoad(builder, ptr, "");
-   lp_set_load_alignment(res, src_type.width / 8);
+   LLVMSetAlignment(res, src_type.width / 8);
 
    /* Truncate doubles to float */
    if (src_type.floating && src_type.width == 64) {
index d02602041ce13c9722e9be2b7721d879ffe0fc57..c641c8bafc120fc81216e3a3b52e4cd2b30d6b2d 100644 (file)
@@ -112,7 +112,7 @@ lp_build_gather_elem(struct gallivm_state *gallivm,
     * gallium could not do anything else except 16 no matter what...
     */
   if (!aligned) {
-      lp_set_load_alignment(res, 1);
+      LLVMSetAlignment(res, 1);
    }
 
    assert(src_width <= dst_width);
index ab44661a271d013ab55438d8a25ed453e32812ab..f0155b3a2ef9398bfc0b4a1a07b9f30e7af90656 100644 (file)
@@ -77,14 +77,6 @@ func_pointer
 gallivm_jit_function(struct gallivm_state *gallivm,
                      LLVMValueRef func);
 
-void
-lp_set_load_alignment(LLVMValueRef Inst,
-                       unsigned Align);
-
-void
-lp_set_store_alignment(LLVMValueRef Inst,
-                      unsigned Align);
-
 #ifdef __cplusplus
 }
 #endif
index 30ef37c9d224dd54da650d60c71fb04405734ca7..61a50fa3b2e95f6dde8f36ca6e80fed24c837773 100644 (file)
@@ -187,22 +187,28 @@ lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
 }
 
 
-extern "C"
-void
-lp_set_load_alignment(LLVMValueRef Inst,
-                       unsigned Align)
-{
-   llvm::unwrap<llvm::LoadInst>(Inst)->setAlignment(Align);
-}
+#if HAVE_LLVM < 0x0304
 
 extern "C"
 void
-lp_set_store_alignment(LLVMValueRef Inst,
-                       unsigned Align)
+LLVMSetAlignmentBackport(LLVMValueRef V,
+                         unsigned Bytes)
 {
-   llvm::unwrap<llvm::StoreInst>(Inst)->setAlignment(Align);
+   switch (LLVMGetInstructionOpcode(V)) {
+   case LLVMLoad:
+      llvm::unwrap<llvm::LoadInst>(V)->setAlignment(Bytes);
+      break;
+   case LLVMStore:
+      llvm::unwrap<llvm::StoreInst>(V)->setAlignment(Bytes);
+      break;
+   default:
+      assert(0);
+      break;
+   }
 }
 
+#endif
+
 
 #if HAVE_LLVM < 0x0306
 typedef llvm::JITMemoryManager BaseMemoryManager;
index e21933ffc851cc44dfc8481a86396fa720ca6dd6..937948bbb02e62a16ce8877ef05bf863dcf25e1d 100644 (file)
@@ -1939,7 +1939,7 @@ lp_build_clamp_border_color(struct lp_build_sample_context *bld,
                                        LLVMPointerType(vec4_bld.vec_type, 0), "");
    border_color = LLVMBuildLoad(builder, border_color_ptr, "");
    /* we don't have aligned type in the dynamic state unfortunately */
-   lp_set_load_alignment(border_color, 4);
+   LLVMSetAlignment(border_color, 4);
 
    /*
     * Instead of having some incredibly complex logic which will try to figure out
index cc248d15e97f362d50adbf1166bf226c062efd99..0df44164d80c16464c5292fe85284b7561e4f2c1 100644 (file)
@@ -157,7 +157,7 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder,
    assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
    element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
    res = LLVMBuildLoad(builder, element_ptr, "");
-   lp_set_load_alignment(res, alignment);
+   LLVMSetAlignment(res, alignment);
 #ifdef DEBUG
    lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
 #endif
@@ -188,5 +188,5 @@ lp_build_pointer_set_unaligned(LLVMBuilderRef builder,
    LLVMValueRef instr;
    element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
    instr = LLVMBuildStore(builder, value, element_ptr);
-   lp_set_store_alignment(instr, alignment);
+   LLVMSetAlignment(instr, alignment);
 }
index 83ff97659fbcdf7d86a0aeda09482c7ff5fd7ce0..ca0533b4a0f1999fe731db616c1efe552f6abd99 100644 (file)
@@ -786,7 +786,7 @@ load_unswizzled_block(struct gallivm_state *gallivm,
 
       dst[i] = LLVMBuildLoad(builder, dst_ptr, "");
 
-      lp_set_load_alignment(dst[i], dst_alignment);
+      LLVMSetAlignment(dst[i], dst_alignment);
    }
 }
 
@@ -830,7 +830,7 @@ store_unswizzled_block(struct gallivm_state *gallivm,
 
       src_ptr = LLVMBuildStore(builder, src[i], src_ptr);
 
-      lp_set_store_alignment(src_ptr, src_alignment);
+      LLVMSetAlignment(src_ptr, src_alignment);
    }
 }