diff --git a/lib/SPIRV/PreprocessMetadata.cpp b/lib/SPIRV/PreprocessMetadata.cpp index b833114dd9..bafb1dddcd 100644 --- a/lib/SPIRV/PreprocessMetadata.cpp +++ b/lib/SPIRV/PreprocessMetadata.cpp @@ -321,9 +321,7 @@ void PreprocessMetadataBase::preprocessVectorComputeMetadata(Module *M, auto Attrs = F.getAttributes(); if (Attrs.hasFnAttr(kVCMetadata::VCFloatControl)) { SPIRVWord Mode = 0; - Attrs - .getAttribute(AttributeList::FunctionIndex, - kVCMetadata::VCFloatControl) + Attrs.getFnAttr(kVCMetadata::VCFloatControl) .getValueAsString() .getAsInteger(0, Mode); spv::ExecutionMode ExecRoundMode = @@ -344,7 +342,7 @@ void PreprocessMetadataBase::preprocessVectorComputeMetadata(Module *M, } if (Attrs.hasFnAttr(kVCMetadata::VCSLMSize)) { SPIRVWord SLMSize = 0; - Attrs.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCSLMSize) + Attrs.getFnAttr(kVCMetadata::VCSLMSize) .getValueAsString() .getAsInteger(0, SLMSize); EM.addOp() diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index d357b15809..fd39b65d7d 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -3878,7 +3878,7 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) { auto SEVAttr = Attribute::get(*Context, kVCMetadata::VCSingleElementVector); if (BF->hasDecorate(DecorationSingleElementVectorINTEL)) - F->addAttribute(AttributeList::ReturnIndex, SEVAttr); + F->addAttributeAtIndex(AttributeList::ReturnIndex, SEVAttr); for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) { @@ -3888,10 +3888,10 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) { if (BA->hasDecorate(DecorationFuncParamIOKindINTEL, 0, &Kind)) { Attribute Attr = Attribute::get(*Context, kVCMetadata::VCArgumentIOKind, std::to_string(Kind)); - F->addAttribute(ArgNo + 1, Attr); + F->addParamAttr(ArgNo, Attr); } if (BA->hasDecorate(DecorationSingleElementVectorINTEL)) - F->addAttribute(ArgNo + 1, SEVAttr); + F->addParamAttr(ArgNo, SEVAttr); } // Do not add float control if there is no any @@ -3991,14 +3991,14 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) { if (IsVCFloatControl) { Attribute Attr = Attribute::get(*Context, kVCMetadata::VCFloatControl, std::to_string(FloatControl)); - F->addAttribute(AttributeList::FunctionIndex, Attr); + F->addFnAttr(Attr); } if (auto EM = BF->getExecutionMode(ExecutionModeSharedLocalMemorySizeINTEL)) { unsigned int SLMSize = EM->getLiterals()[0]; Attribute Attr = Attribute::get(*Context, kVCMetadata::VCSLMSize, std::to_string(SLMSize)); - F->addAttribute(AttributeList::FunctionIndex, Attr); + F->addFnAttr(Attr); } return true; diff --git a/lib/SPIRV/SPIRVToOCL12.cpp b/lib/SPIRV/SPIRVToOCL12.cpp index 4e78c5ccbd..34ffca6a5d 100644 --- a/lib/SPIRV/SPIRVToOCL12.cpp +++ b/lib/SPIRV/SPIRVToOCL12.cpp @@ -89,8 +89,7 @@ void SPIRVToOCL12Base::visitCallSPIRVMemoryBarrier(CallInst *CI) { void SPIRVToOCL12Base::visitCallSPIRVControlBarrier(CallInst *CI) { AttributeList Attrs = CI->getCalledFunction()->getAttributes(); - Attrs = Attrs.addAttribute(CI->getContext(), AttributeList::FunctionIndex, - Attribute::Convergent); + Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent); mutateCallInstOCL( M, CI, [=](CallInst *, std::vector &Args) { diff --git a/lib/SPIRV/SPIRVToOCL20.cpp b/lib/SPIRV/SPIRVToOCL20.cpp index 1b546cc131..7cfb444ba5 100644 --- a/lib/SPIRV/SPIRVToOCL20.cpp +++ b/lib/SPIRV/SPIRVToOCL20.cpp @@ -97,8 +97,7 @@ void SPIRVToOCL20Base::visitCallSPIRVMemoryBarrier(CallInst *CI) { void SPIRVToOCL20Base::visitCallSPIRVControlBarrier(CallInst *CI) { AttributeList Attrs = CI->getCalledFunction()->getAttributes(); - Attrs = Attrs.addAttribute(CI->getContext(), AttributeList::FunctionIndex, - Attribute::Convergent); + Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent); mutateCallInstOCL( M, CI, [=](CallInst *, std::vector &Args) { diff --git a/lib/SPIRV/SPIRVUtil.cpp b/lib/SPIRV/SPIRVUtil.cpp index 8e157fb4d2..a347a7a597 100644 --- a/lib/SPIRV/SPIRVUtil.cpp +++ b/lib/SPIRV/SPIRVUtil.cpp @@ -82,11 +82,11 @@ cl::opt EnableDbgOutput("spirv-debug", bool isSupportedTriple(Triple T) { return T.isSPIR(); } void addFnAttr(CallInst *Call, Attribute::AttrKind Attr) { - Call->addAttribute(AttributeList::FunctionIndex, Attr); + Call->addFnAttr(Attr); } void removeFnAttr(CallInst *Call, Attribute::AttrKind Attr) { - Call->removeAttribute(AttributeList::FunctionIndex, Attr); + Call->removeFnAttr(Attr); } Value *removeCast(Value *V) { diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index a23d354274..5e2a40fe22 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -652,22 +652,21 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) { BA->addAttr(FunctionParameterAttributeSret); if (I->onlyReadsMemory()) BA->addAttr(FunctionParameterAttributeNoWrite); - if (Attrs.hasAttribute(ArgNo + 1, Attribute::ZExt)) + if (Attrs.hasParamAttr(ArgNo, Attribute::ZExt)) BA->addAttr(FunctionParameterAttributeZext); - if (Attrs.hasAttribute(ArgNo + 1, Attribute::SExt)) + if (Attrs.hasParamAttr(ArgNo, Attribute::SExt)) BA->addAttr(FunctionParameterAttributeSext); - if (Attrs.hasAttribute(ArgNo + 1, Attribute::Alignment)) { - SPIRVWord AlignmentBytes = - Attrs.getAttribute(ArgNo + 1, Attribute::Alignment) - .getAlignment() - .valueOrOne() - .value(); + if (Attrs.hasParamAttr(ArgNo, Attribute::Alignment)) { + SPIRVWord AlignmentBytes = Attrs.getParamAttr(ArgNo, Attribute::Alignment) + .getAlignment() + .valueOrOne() + .value(); BA->setAlignment(AlignmentBytes); } if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_1) && - Attrs.hasAttribute(ArgNo + 1, Attribute::Dereferenceable)) + Attrs.hasParamAttr(ArgNo, Attribute::Dereferenceable)) BA->addDecorate(DecorationMaxByteOffset, - Attrs.getAttribute(ArgNo + 1, Attribute::Dereferenceable) + Attrs.getParamAttr(ArgNo, Attribute::Dereferenceable) .getDereferenceableBytes()); if (BufferLocation && I->getType()->isPointerTy()) { // Order of integer numbers in MD node follows the order of function @@ -692,9 +691,9 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) { BA->addDecorate(internal::DecorationRuntimeAlignedINTEL, LocID); } } - if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt)) + if (Attrs.hasRetAttr(Attribute::ZExt)) BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeZext); - if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt)) + if (Attrs.hasRetAttr(Attribute::SExt)) BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeSext); if (Attrs.hasFnAttr("referenced-indirectly")) { assert(!isKernel(F) && @@ -734,14 +733,13 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) { if (Attrs.hasFnAttr(kVCMetadata::VCSIMTCall)) { SPIRVWord SIMTMode = 0; - Attrs.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCSIMTCall) + Attrs.getFnAttr(kVCMetadata::VCSIMTCall) .getValueAsString() .getAsInteger(0, SIMTMode); BF->addDecorate(DecorationSIMTCallINTEL, SIMTMode); } - if (Attrs.hasAttribute(AttributeList::ReturnIndex, - kVCMetadata::VCSingleElementVector)) { + if (Attrs.hasRetAttr(kVCMetadata::VCSingleElementVector)) { auto *RT = BF->getType(); (void)RT; assert((RT->isTypeBool() || RT->isTypeFloat() || RT->isTypeInt() || @@ -754,14 +752,14 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) { ++I) { auto ArgNo = I->getArgNo(); SPIRVFunctionParameter *BA = BF->getArgument(ArgNo); - if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentIOKind)) { + if (Attrs.hasParamAttr(ArgNo, kVCMetadata::VCArgumentIOKind)) { SPIRVWord Kind = {}; - Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentIOKind) + Attrs.getParamAttr(ArgNo, kVCMetadata::VCArgumentIOKind) .getValueAsString() .getAsInteger(0, Kind); BA->addDecorate(DecorationFuncParamIOKindINTEL, Kind); } - if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCSingleElementVector)) { + if (Attrs.hasParamAttr(ArgNo, kVCMetadata::VCSingleElementVector)) { auto *AT = BA->getType(); (void)AT; assert((AT->isTypeBool() || AT->isTypeFloat() || AT->isTypeInt() || @@ -775,8 +773,7 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) { Attrs.hasFnAttr(kVCMetadata::VCFloatControl)) { SPIRVWord Mode = 0; - Attrs - .getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCFloatControl) + Attrs.getFnAttr(kVCMetadata::VCFloatControl) .getValueAsString() .getAsInteger(0, Mode); VCFloatTypeSizeMap::foreach ( @@ -1399,7 +1396,6 @@ SPIRVEntry *addMemAliasingINTELInstructions(SPIRVModule *M, return M->getOrAddAliasScopeListDeclINTELInst(ListId, AliasingListMD); } - // Translate alias.scope/noalias metadata attached to store and load // instructions. void transAliasingMemAccess(SPIRVModule *BM, MDNode *AliasingListMD,