[Mesa-dev] [PATCH 1/2] gallivm: Fix build after removal of deprecated attribute API v3

Roland Scheidegger sroland at vmware.com
Thu Nov 10 16:20:06 UTC 2016


Am 10.11.2016 um 17:14 schrieb Tom Stellard:
> On Wed, Nov 09, 2016 at 11:45:38PM +0100, Roland Scheidegger wrote:
>> Am 09.11.2016 um 16:22 schrieb Tom Stellard:
>>> v2:
>>>   Fix adding parameter attributes with LLVM < 4.0.
>>>
>>> v3:
>>>   Fix typo.
>>>   Fix parameter index.
>>>   Add a gallivm enum for function attributes.
>>> ---
>>>  src/gallium/auxiliary/draw/draw_llvm.c            |  6 +-
>>>  src/gallium/auxiliary/gallivm/lp_bld_intr.c       | 70 ++++++++++++++++++++++-
>>>  src/gallium/auxiliary/gallivm/lp_bld_intr.h       | 22 ++++++-
>>>  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, 143 insertions(+), 52 deletions(-)
>>>
>>> diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
>>> index 5b4e2a1..ba86b11 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 f12e735..049671a 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 7d80ac2..85a86c2 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)
>>> +};
>> Not sure if there's any value in using bit flags? Or is it supposed to
>> handle multiple attributes simultaneously at some point?
>> Not that it would really matter much, though...
>>
> 
> I used a bitfield, so that lp_build_intrinsic could handle multiple
> flags at once.  I thought it would be more convenient to be able to
> do this.
> 

Ahh right I somehow thought that wouldn't work anyway. But clearly it does.

Roland




More information about the mesa-dev mailing list