[Mesa-dev] [PATCH 1/2] gallivm: add wrappers for missing functions in LLVM <= 3.8

Jose Fonseca jfonseca at vmware.com
Tue Nov 8 22:07:03 UTC 2016


On 19/10/16 23:14, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> radeonsi needs these.
> ---
>  src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 21 +++++++++++++++++++++
>  src/gallium/auxiliary/gallivm/lp_bld_misc.h   |  6 ++++++
>  2 files changed, 27 insertions(+)
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
> index 791a470..f4045ad 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
> @@ -70,20 +70,21 @@
>  #include <llvm/ExecutionEngine/JITMemoryManager.h>
>  #else
>  #include <llvm/ExecutionEngine/SectionMemoryManager.h>
>  #endif
>  #include <llvm/Support/CommandLine.h>
>  #include <llvm/Support/Host.h>
>  #include <llvm/Support/PrettyStackTrace.h>
>
>  #include <llvm/Support/TargetSelect.h>
>
> +#include <llvm/IR/CallSite.h>
>  #include <llvm/IR/IRBuilder.h>
>  #include <llvm/IR/Module.h>
>  #include <llvm/Support/CBindingWrapping.h>
>
>  #include <llvm/Config/llvm-config.h>
>  #if LLVM_USE_INTEL_JITEVENTS
>  #include <llvm/ExecutionEngine/JITEventListener.h>
>  #endif
>
>  // Workaround http://llvm.org/PR23628
> @@ -701,10 +702,30 @@ lp_free_memory_manager(LLVMMCJITMemoryManagerRef 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
>  }
> +
> +extern "C" LLVMValueRef
> +lp_get_called_value(LLVMValueRef call)
> +{
> +#if HAVE_LLVM >= 0x0309
> +	return LLVMGetCalledValue(call);
> +#else
> +	return llvm::wrap(llvm::CallSite(llvm::unwrap<llvm::Instruction>(call)).getCalledValue());
> +#endif
> +}

In these circumstances, rather introducing a wrapper,  I find it more 
appealing to "backport" the future defintion, as:

#if HAVE_LLVM < 0x0309
extern "C" LLVMValueRef
LLVMGetCalledValue(LLVMValueRef call)
{
	return 
llvm::wrap(llvm::CallSite(llvm::unwrap<llvm::Instruction>(call)).getCalledValue());
  }
#endif


This way it's one less wrapper to learn.  And when the required LLVM 
version reaches 3.9, we can just remove the function.

Jose


> +
> +extern "C" bool
> +lp_is_function(LLVMValueRef v)
> +{
> +#if HAVE_LLVM >= 0x0309
> +	return LLVMGetValueKind(v) == LLVMFunctionValueKind;
> +#else
> +	return llvm::isa<llvm::Function>(llvm::unwrap(v));
> +#endif
> +}
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
> index c127c48..a55c6bd 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
> @@ -69,16 +69,22 @@ lp_free_generated_code(struct lp_generated_code *code);
>
>  extern LLVMMCJITMemoryManagerRef
>  lp_get_default_memory_manager();
>
>  extern void
>  lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr);
>
>  extern void
>  lp_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);
>
> +extern LLVMValueRef
> +lp_get_called_value(LLVMValueRef call);
> +
> +extern bool
> +lp_is_function(LLVMValueRef v);
> +
>  #ifdef __cplusplus
>  }
>  #endif
>
>
>  #endif /* !LP_BLD_MISC_H */
>



More information about the mesa-dev mailing list