[Mesa-dev] [PATCH] gallivm: Fix build after removal of deprecated attribute API v2
Nicolai Hähnle
nhaehnle at gmail.com
Tue Nov 8 08:57:51 UTC 2016
On 07.11.2016 23:04, Jan Vesely wrote:
> On Mon, 2016-11-07 at 21:06 +0000, Tom Stellard wrote:
>> v2:
>> Fix adding parameter attributes with LLVM < 4.0.
>> ---
>> src/gallium/auxiliary/draw/draw_llvm.c | 6 +-
>> src/gallium/auxiliary/gallivm/lp_bld_intr.c | 52 ++++++++++++++++-
>> src/gallium/auxiliary/gallivm/lp_bld_intr.h | 13 ++++-
>> src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 4 +-
>> src/gallium/drivers/radeonsi/si_shader.c | 69 ++++++++++++-----------
>> src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c | 24 ++++----
>> 6 files changed, 116 insertions(+), 52 deletions(-)
>>
>> diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
>> index 5b4e2a1..5d87318 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, "noalias", 7);
>>
>> 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, "noalias", 7);
>>
>> 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 f12e735..401e9a2 100644
>> --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c
>> +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
>> @@ -120,13 +120,57 @@ lp_declare_intrinsic(LLVMModuleRef module,
>> }
>>
>>
>> +#if HAVE_LLVM < 0x0400
>> +static LLVMAttribute str_to_attr(const char *attr_name, unsigned attr_len)
>> +{
>> + if (!strncmp("alwaysinline", attr_name, attr_len)) {
>> + return LLVMAlwaysInlineAttribute;
>> + } else if (!strncmp("byval", attr_name, attr_len)) {
>> + return LLVMByValAttribute;
>> + } else if (!strncmp("inreg", attr_name, attr_len)) {
>> + return LLVMInRegAttribute;
>> + } else if (!strncmp("noalias", attr_name, attr_len)) {
>> + return LLVMNoAlliasAttribute;
LLVMNoAliasAttribute
>> + } else if (!strncmp("readnone", attr_name, attr_len)) {
>> + return LLVMReadNoneAttribute;
>> + } else if (!strncmp("readonly", attr_name, attr_len)) {
>> + return LLVMReadOnlyAttribute;
>> + } else {
>> + _debug_printf("Unhandled function attribute: %s\n", attr_name);
>> + return 0;
>> + }
>> +}
>> +#endif
>> +
>> +void
>> +lp_add_function_attr(LLVMValueRef function,
>> + int attr_idx,
>> + const char *attr_name,
>> + unsigned attr_len)
>
> Any reason to pass string length by hand rather than local strlen?
>
>> +{
>> +
>> +#if HAVE_LLVM < 0x0400
>> + LLVMAttribute attr = str_to_attr(attr_name, attr_len);
>> + if (attr_idx == -1) {
>> + LLVMAddFunctionAttr(function, attr);
>> + } else {
>> + LLVMAddAttribute(LLVMGetParam(function, attr_idx), attr);
>
> I think this needs to be attr_idx - 1. LLVM 4.0 counts parameter
> attributes from 1 (0 is the ret value). in the changes below:
Agreed.
Cheers,
Nicolai
More information about the mesa-dev
mailing list