gallivm: add helper lp_add_attr_dereferenceable
authorMarek Olšák <marek.olsak@amd.com>
Tue, 12 Jul 2016 16:49:57 +0000 (18:49 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 13 Jul 2016 17:46:16 +0000 (19:46 +0200)
Not sure if this is the right way to do it, but it seems to work.

v2: make it a no-op on LLVM <= 3.5

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/gallivm/lp_bld_misc.h

index 23ef3edeae7d1001d0675df28e390e24f1cb4b93..791a4702556dbfd3471b83515a704c6faaf9382e 100644 (file)
@@ -697,3 +697,14 @@ lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr)
 {
    delete reinterpret_cast<BaseMemoryManager*>(memorymgr);
 }
+
+extern "C" void
+lp_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes)
+{
+#if HAVE_LLVM >= 0x0306
+   llvm::Argument *A = llvm::unwrap<llvm::Argument>(val);
+   llvm::AttrBuilder B;
+   B.addDereferenceableAttr(bytes);
+   A->addAttr(llvm::AttributeSet::get(A->getContext(), A->getArgNo() + 1,  B));
+#endif
+}
index d038e3bee009310c06f9e8d8f69e152b3965d743..c127c480d52d6cdf196f246164cfd9feac9f0055 100644 (file)
@@ -73,6 +73,9 @@ lp_get_default_memory_manager();
 extern void
 lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr);
 
+extern void
+lp_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);
+
 #ifdef __cplusplus
 }
 #endif