Re: [Mesa-dev] [PATCH] gallivm: Fix build after removal of deprecated attribute API v2
On Mon, Nov 7, 2016 at 11:04 PM, Jan Vesely wrote: > On Mon, 2016-11-07 at 21:06 +, 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; >> + } 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? An enum would be better. Then lp_add_function_attr can translate the enum to a string. The enums can be defined by gallivm. Marek ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] gallivm: Fix build after removal of deprecated attribute API v2
On 07.11.2016 23:04, Jan Vesely wrote: On Mon, 2016-11-07 at 21:06 +, 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 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] gallivm: Fix build after removal of deprecated attribute API v2
On Mon, 2016-11-07 at 21:06 +, 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; > + } 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: -LLVMAddAttribute(LLVMGetParam(function, i), LLVMNoAliasAttribute); + +lp_add_function_attr(function, i + 1, "noalias", 7); Jan > + } > +#else > + LLVMContextRef context = > LLVMGetModuleContext(LLVMGetGlobalParent(function)); > + unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, attr_len); > + LLVMAttributeRef attr = LLVMCreateEnumAttribute(context, kind_id, 0); > + LLVMAddAttributeAtIndex(function, attr_idx, attr); > +#endif > +} > + > LLVMValueRef > lp_build_intrinsic(LLVMBuilderRef builder, > const char *name, > LLVMTypeRef ret_type, > LLVMValueRef *args, > unsigned num_args, > - LLVMAttribute attr) > + const char *attr_str) > { > LLVMModuleRef module = > LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); > LLVMValueRef function; > @@ -145,10 +189,14 @@ lp_build_intrinsic(LLVMBuilderRef builder, > >function = lp_declare_intrinsic(module, name, ret_type, arg_types, > num_args); > > + if (attr_str) { > + lp_add_function_attr(function, -1, attr_str, sizeof(attr_str)); > + } > + >/* NoUnwind indicates that the intrinsic never raises a C+
[Mesa-dev] [PATCH] gallivm: Fix build after removal of deprecated attribute API v2
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; + } 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) +{ + +#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); + } +#else + LLVMContextRef context = LLVMGetModuleContext(LLVMGetGlobalParent(function)); + unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, attr_len); + LLVMAttributeRef attr = LLVMCreateEnumAttribute(context, kind_id, 0); + LLVMAddAttributeAtIndex(function, attr_idx, attr); +#endif +} + LLVMValueRef lp_build_intrinsic(LLVMBuilderRef builder, const char *name, LLVMTypeRef ret_type, LLVMValueRef *args, unsigned num_args, - LLVMAttribute attr) + const char *attr_str) { LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); LLVMValueRef function; @@ -145,10 +189,14 @@ lp_build_intrinsic(LLVMBuilderRef builder, function = lp_declare_intrinsic(module, name, ret_type, arg_types, num_args); + if (attr_str) { + lp_add_function_attr(function, -1, attr_str, sizeof(attr_str)); + } + /* NoUnwind indicates that the intrinsic never raises a C++ exception. * Set it for all intrinsics. */ - LLVMAddFunctionAttr(function, attr | LLVMNoUnwindAttribute); + lp_add_function_attr(function, -1, "nounwind", 8); 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 7d80ac2..a058de4 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h @@ -60,13 +60,24 @@ lp_declare_intrinsic(LLVMModuleRef module, LLVMTypeRef *arg_types,