diff options
author | Tom Stellard <[email protected]> | 2016-11-07 18:35:09 +0000 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2016-11-09 20:13:27 +0000 |
commit | 8bdd52c8f3595128cbc1da4f23cdb10ff861a6ef (patch) | |
tree | 559ecc6a07fac37950cbb95c95860d28162cb784 /src/gallium/auxiliary | |
parent | fb50245ac1e1eb60b2451d9d6dd05388cb89634a (diff) |
gallivm: Fix build after removal of deprecated attribute API v3
v2:
Fix adding parameter attributes with LLVM < 4.0.
v3:
Fix typo.
Fix parameter index.
Add a gallivm enum for function attributes.
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/draw/draw_llvm.c | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_intr.c | 70 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_intr.h | 17 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 4 |
4 files changed, 89 insertions, 8 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 5b4e2a14aef..ba86b11b178 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -1568,8 +1568,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, LLVMSetFunctionCallConv(variant_func, LLVMCCallConv); for (i = 0; i < num_arg_types; ++i) if (LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) - LLVMAddAttribute(LLVMGetParam(variant_func, i), - LLVMNoAliasAttribute); + lp_add_function_attr(variant_func, i + 1, LP_FUNC_ATTR_NOALIAS); context_ptr = LLVMGetParam(variant_func, 0); io_ptr = LLVMGetParam(variant_func, 1); @@ -2193,8 +2192,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, for (i = 0; i < ARRAY_SIZE(arg_types); ++i) if (LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) - LLVMAddAttribute(LLVMGetParam(variant_func, i), - LLVMNoAliasAttribute); + lp_add_function_attr(variant_func, i + 1, LP_FUNC_ATTR_NOALIAS); context_ptr = LLVMGetParam(variant_func, 0); input_array = LLVMGetParam(variant_func, 1); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c index f12e735b5ee..049671a09f2 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c @@ -46,6 +46,7 @@ #include "util/u_debug.h" #include "util/u_string.h" +#include "util/bitscan.h" #include "lp_bld_const.h" #include "lp_bld_intr.h" @@ -120,13 +121,73 @@ lp_declare_intrinsic(LLVMModuleRef module, } +#if HAVE_LLVM < 0x0400 +static LLVMAttribute lp_attr_to_llvm_attr(enum lp_func_attr attr) +{ + switch (attr) { + case LP_FUNC_ATTR_ALWAYSINLINE: return LLVMAlwaysInlineAttribute; + case LP_FUNC_ATTR_BYVAL: return LLVMByValAttribute; + case LP_FUNC_ATTR_INREG: return LLVMInRegAttribute; + case LP_FUNC_ATTR_NOALIAS: return LLVMNoAliasAttribute; + case LP_FUNC_ATTR_NOUNWIND: return LLVMNoUnwindAttribute; + case LP_FUNC_ATTR_READNONE: return LLVMReadNoneAttribute; + case LP_FUNC_ATTR_READONLY: return LLVMReadOnlyAttribute; + default: + _debug_printf("Unhandled function attribute: %x\n", attr); + return 0; + } +} + +#else + +static const char *attr_to_str(enum lp_func_attr attr) +{ + switch (attr) { + case LP_FUNC_ATTR_ALWAYSINLINE: return "alwaysinline"; + case LP_FUNC_ATTR_BYVAL: return "byval"; + case LP_FUNC_ATTR_INREG: return "inreg"; + case LP_FUNC_ATTR_NOALIAS: return "noalias"; + case LP_FUNC_ATTR_NOUNWIND: return "nounwind"; + case LP_FUNC_ATTR_READNONE: return "readnone"; + case LP_FUNC_ATTR_READONLY: return "readonly"; + default: + _debug_printf("Unhandled function attribute: %x\n", attr); + return 0; + } +} + +#endif + +void +lp_add_function_attr(LLVMValueRef function, + int attr_idx, + enum lp_func_attr attr) +{ + +#if HAVE_LLVM < 0x0400 + LLVMAttribute llvm_attr = lp_attr_to_llvm_attr(attr); + if (attr_idx == -1) { + LLVMAddFunctionAttr(function, llvm_attr); + } else { + LLVMAddAttribute(LLVMGetParam(function, attr_idx - 1), llvm_attr); + } +#else + LLVMContextRef context = LLVMGetModuleContext(LLVMGetGlobalParent(function)); + const char *attr_name = attr_to_str(attr); + unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, + strlen(attr_name)); + LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(context, kind_id, 0); + LLVMAddAttributeAtIndex(function, attr_idx, llvm_attr); +#endif +} + LLVMValueRef lp_build_intrinsic(LLVMBuilderRef builder, const char *name, LLVMTypeRef ret_type, LLVMValueRef *args, unsigned num_args, - LLVMAttribute attr) + unsigned attr_mask) { LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); LLVMValueRef function; @@ -148,7 +209,12 @@ lp_build_intrinsic(LLVMBuilderRef builder, /* NoUnwind indicates that the intrinsic never raises a C++ exception. * Set it for all intrinsics. */ - LLVMAddFunctionAttr(function, attr | LLVMNoUnwindAttribute); + attr_mask |= LP_FUNC_ATTR_NOUNWIND; + + while (attr_mask) { + enum lp_func_attr attr = 1 << u_bit_scan(&attr_mask); + lp_add_function_attr(function, -1, attr); + } if (gallivm_debug & GALLIVM_DEBUG_IR) { lp_debug_dump_value(function); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h index 7d80ac28f70..f1e075a9b9b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h @@ -46,6 +46,16 @@ */ #define LP_MAX_FUNC_ARGS 32 +enum lp_func_attr { + LP_FUNC_ATTR_ALWAYSINLINE = (1 << 0), + LP_FUNC_ATTR_BYVAL = (1 << 1), + LP_FUNC_ATTR_INREG = (1 << 2), + LP_FUNC_ATTR_NOALIAS = (1 << 3), + LP_FUNC_ATTR_NOUNWIND = (1 << 4), + LP_FUNC_ATTR_READNONE = (1 << 5), + LP_FUNC_ATTR_READONLY = (1 << 6), + LP_FUNC_ATTR_LAST = (1 << 7) +}; void lp_format_intrinsic(char *name, @@ -60,13 +70,18 @@ lp_declare_intrinsic(LLVMModuleRef module, LLVMTypeRef *arg_types, unsigned num_args); +void +lp_add_function_attr(LLVMValueRef function, + int attr_idx, + enum lp_func_attr attr); + LLVMValueRef lp_build_intrinsic(LLVMBuilderRef builder, const char *name, LLVMTypeRef ret_type, LLVMValueRef *args, unsigned num_args, - LLVMAttribute attr); + unsigned attr_mask); LLVMValueRef diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index 1477a72d601..939cd43ac48 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -60,6 +60,7 @@ #include "lp_bld_struct.h" #include "lp_bld_quad.h" #include "lp_bld_pack.h" +#include "lp_bld_intr.h" /** @@ -3316,7 +3317,8 @@ lp_build_sample_soa_func(struct gallivm_state *gallivm, for (i = 0; i < num_param; ++i) { if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) { - LLVMAddAttribute(LLVMGetParam(function, i), LLVMNoAliasAttribute); + + lp_add_function_attr(function, i + 1, LP_FUNC_ATTR_NOALIAS); } } |