Skip to content

Commit 6eb3848

Browse files
authored
Replace add-, get-, has-, removeAttribute by related methods. (#1197)
1 parent 6cef1d1 commit 6eb3848

File tree

6 files changed

+28
-36
lines changed

6 files changed

+28
-36
lines changed

lib/SPIRV/PreprocessMetadata.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,7 @@ void PreprocessMetadataBase::preprocessVectorComputeMetadata(Module *M,
321321
auto Attrs = F.getAttributes();
322322
if (Attrs.hasFnAttr(kVCMetadata::VCFloatControl)) {
323323
SPIRVWord Mode = 0;
324-
Attrs
325-
.getAttribute(AttributeList::FunctionIndex,
326-
kVCMetadata::VCFloatControl)
324+
Attrs.getFnAttr(kVCMetadata::VCFloatControl)
327325
.getValueAsString()
328326
.getAsInteger(0, Mode);
329327
spv::ExecutionMode ExecRoundMode =
@@ -344,7 +342,7 @@ void PreprocessMetadataBase::preprocessVectorComputeMetadata(Module *M,
344342
}
345343
if (Attrs.hasFnAttr(kVCMetadata::VCSLMSize)) {
346344
SPIRVWord SLMSize = 0;
347-
Attrs.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCSLMSize)
345+
Attrs.getFnAttr(kVCMetadata::VCSLMSize)
348346
.getValueAsString()
349347
.getAsInteger(0, SLMSize);
350348
EM.addOp()

lib/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,7 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
38783878

38793879
auto SEVAttr = Attribute::get(*Context, kVCMetadata::VCSingleElementVector);
38803880
if (BF->hasDecorate(DecorationSingleElementVectorINTEL))
3881-
F->addAttribute(AttributeList::ReturnIndex, SEVAttr);
3881+
F->addAttributeAtIndex(AttributeList::ReturnIndex, SEVAttr);
38823882

38833883
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
38843884
++I) {
@@ -3888,10 +3888,10 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
38883888
if (BA->hasDecorate(DecorationFuncParamIOKindINTEL, 0, &Kind)) {
38893889
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCArgumentIOKind,
38903890
std::to_string(Kind));
3891-
F->addAttribute(ArgNo + 1, Attr);
3891+
F->addParamAttr(ArgNo, Attr);
38923892
}
38933893
if (BA->hasDecorate(DecorationSingleElementVectorINTEL))
3894-
F->addAttribute(ArgNo + 1, SEVAttr);
3894+
F->addParamAttr(ArgNo, SEVAttr);
38953895
}
38963896

38973897
// Do not add float control if there is no any
@@ -3991,14 +3991,14 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
39913991
if (IsVCFloatControl) {
39923992
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCFloatControl,
39933993
std::to_string(FloatControl));
3994-
F->addAttribute(AttributeList::FunctionIndex, Attr);
3994+
F->addFnAttr(Attr);
39953995
}
39963996

39973997
if (auto EM = BF->getExecutionMode(ExecutionModeSharedLocalMemorySizeINTEL)) {
39983998
unsigned int SLMSize = EM->getLiterals()[0];
39993999
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCSLMSize,
40004000
std::to_string(SLMSize));
4001-
F->addAttribute(AttributeList::FunctionIndex, Attr);
4001+
F->addFnAttr(Attr);
40024002
}
40034003

40044004
return true;

lib/SPIRV/SPIRVToOCL12.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ void SPIRVToOCL12Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {
8989

9090
void SPIRVToOCL12Base::visitCallSPIRVControlBarrier(CallInst *CI) {
9191
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
92-
Attrs = Attrs.addAttribute(CI->getContext(), AttributeList::FunctionIndex,
93-
Attribute::Convergent);
92+
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
9493
mutateCallInstOCL(
9594
M, CI,
9695
[=](CallInst *, std::vector<Value *> &Args) {

lib/SPIRV/SPIRVToOCL20.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ void SPIRVToOCL20Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {
9797

9898
void SPIRVToOCL20Base::visitCallSPIRVControlBarrier(CallInst *CI) {
9999
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
100-
Attrs = Attrs.addAttribute(CI->getContext(), AttributeList::FunctionIndex,
101-
Attribute::Convergent);
100+
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
102101
mutateCallInstOCL(
103102
M, CI,
104103
[=](CallInst *, std::vector<Value *> &Args) {

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ cl::opt<bool, true> EnableDbgOutput("spirv-debug",
8282
bool isSupportedTriple(Triple T) { return T.isSPIR(); }
8383

8484
void addFnAttr(CallInst *Call, Attribute::AttrKind Attr) {
85-
Call->addAttribute(AttributeList::FunctionIndex, Attr);
85+
Call->addFnAttr(Attr);
8686
}
8787

8888
void removeFnAttr(CallInst *Call, Attribute::AttrKind Attr) {
89-
Call->removeAttribute(AttributeList::FunctionIndex, Attr);
89+
Call->removeFnAttr(Attr);
9090
}
9191

9292
Value *removeCast(Value *V) {

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -652,22 +652,21 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
652652
BA->addAttr(FunctionParameterAttributeSret);
653653
if (I->onlyReadsMemory())
654654
BA->addAttr(FunctionParameterAttributeNoWrite);
655-
if (Attrs.hasAttribute(ArgNo + 1, Attribute::ZExt))
655+
if (Attrs.hasParamAttr(ArgNo, Attribute::ZExt))
656656
BA->addAttr(FunctionParameterAttributeZext);
657-
if (Attrs.hasAttribute(ArgNo + 1, Attribute::SExt))
657+
if (Attrs.hasParamAttr(ArgNo, Attribute::SExt))
658658
BA->addAttr(FunctionParameterAttributeSext);
659-
if (Attrs.hasAttribute(ArgNo + 1, Attribute::Alignment)) {
660-
SPIRVWord AlignmentBytes =
661-
Attrs.getAttribute(ArgNo + 1, Attribute::Alignment)
662-
.getAlignment()
663-
.valueOrOne()
664-
.value();
659+
if (Attrs.hasParamAttr(ArgNo, Attribute::Alignment)) {
660+
SPIRVWord AlignmentBytes = Attrs.getParamAttr(ArgNo, Attribute::Alignment)
661+
.getAlignment()
662+
.valueOrOne()
663+
.value();
665664
BA->setAlignment(AlignmentBytes);
666665
}
667666
if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_1) &&
668-
Attrs.hasAttribute(ArgNo + 1, Attribute::Dereferenceable))
667+
Attrs.hasParamAttr(ArgNo, Attribute::Dereferenceable))
669668
BA->addDecorate(DecorationMaxByteOffset,
670-
Attrs.getAttribute(ArgNo + 1, Attribute::Dereferenceable)
669+
Attrs.getParamAttr(ArgNo, Attribute::Dereferenceable)
671670
.getDereferenceableBytes());
672671
if (BufferLocation && I->getType()->isPointerTy()) {
673672
// Order of integer numbers in MD node follows the order of function
@@ -692,9 +691,9 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
692691
BA->addDecorate(internal::DecorationRuntimeAlignedINTEL, LocID);
693692
}
694693
}
695-
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
694+
if (Attrs.hasRetAttr(Attribute::ZExt))
696695
BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeZext);
697-
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
696+
if (Attrs.hasRetAttr(Attribute::SExt))
698697
BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeSext);
699698
if (Attrs.hasFnAttr("referenced-indirectly")) {
700699
assert(!isKernel(F) &&
@@ -734,14 +733,13 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {
734733

735734
if (Attrs.hasFnAttr(kVCMetadata::VCSIMTCall)) {
736735
SPIRVWord SIMTMode = 0;
737-
Attrs.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCSIMTCall)
736+
Attrs.getFnAttr(kVCMetadata::VCSIMTCall)
738737
.getValueAsString()
739738
.getAsInteger(0, SIMTMode);
740739
BF->addDecorate(DecorationSIMTCallINTEL, SIMTMode);
741740
}
742741

743-
if (Attrs.hasAttribute(AttributeList::ReturnIndex,
744-
kVCMetadata::VCSingleElementVector)) {
742+
if (Attrs.hasRetAttr(kVCMetadata::VCSingleElementVector)) {
745743
auto *RT = BF->getType();
746744
(void)RT;
747745
assert((RT->isTypeBool() || RT->isTypeFloat() || RT->isTypeInt() ||
@@ -754,14 +752,14 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {
754752
++I) {
755753
auto ArgNo = I->getArgNo();
756754
SPIRVFunctionParameter *BA = BF->getArgument(ArgNo);
757-
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentIOKind)) {
755+
if (Attrs.hasParamAttr(ArgNo, kVCMetadata::VCArgumentIOKind)) {
758756
SPIRVWord Kind = {};
759-
Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentIOKind)
757+
Attrs.getParamAttr(ArgNo, kVCMetadata::VCArgumentIOKind)
760758
.getValueAsString()
761759
.getAsInteger(0, Kind);
762760
BA->addDecorate(DecorationFuncParamIOKindINTEL, Kind);
763761
}
764-
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCSingleElementVector)) {
762+
if (Attrs.hasParamAttr(ArgNo, kVCMetadata::VCSingleElementVector)) {
765763
auto *AT = BA->getType();
766764
(void)AT;
767765
assert((AT->isTypeBool() || AT->isTypeFloat() || AT->isTypeInt() ||
@@ -775,8 +773,7 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {
775773
Attrs.hasFnAttr(kVCMetadata::VCFloatControl)) {
776774

777775
SPIRVWord Mode = 0;
778-
Attrs
779-
.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCFloatControl)
776+
Attrs.getFnAttr(kVCMetadata::VCFloatControl)
780777
.getValueAsString()
781778
.getAsInteger(0, Mode);
782779
VCFloatTypeSizeMap::foreach (
@@ -1399,7 +1396,6 @@ SPIRVEntry *addMemAliasingINTELInstructions(SPIRVModule *M,
13991396
return M->getOrAddAliasScopeListDeclINTELInst(ListId, AliasingListMD);
14001397
}
14011398

1402-
14031399
// Translate alias.scope/noalias metadata attached to store and load
14041400
// instructions.
14051401
void transAliasingMemAccess(SPIRVModule *BM, MDNode *AliasingListMD,

0 commit comments

Comments
 (0)