Skip to content

Commit b1db3e5

Browse files
committed
Wrap attribute at index methods
Fix after https://reviews.llvm.org/D108614.
1 parent b66c5bb commit b1db3e5

File tree

5 files changed

+113
-32
lines changed

5 files changed

+113
-32
lines changed

GenXIntrinsics/include/llvmVCWrapper/IR/Attributes.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,45 @@ inline bool hasFnAttr(const llvm::AttributeList &AttrList,
3333
#endif
3434
}
3535

36+
inline bool hasAttributeAtIndex(const llvm::AttributeList &AttrList,
37+
unsigned Index,
38+
llvm::Attribute::AttrKind Kind) {
39+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
40+
return AttrList.hasAttributeAtIndex(Index, Kind);
41+
#else
42+
return AttrList.hasAttribute(Index, Kind);
43+
#endif
44+
}
45+
46+
inline bool hasAttributeAtIndex(const llvm::AttributeList &AttrList,
47+
unsigned Index, llvm::StringRef Kind) {
48+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
49+
return AttrList.hasAttributeAtIndex(Index, Kind);
50+
#else
51+
return AttrList.hasAttribute(Index, Kind);
52+
#endif
53+
}
54+
55+
inline llvm::Attribute getAttributeAtIndex(const llvm::AttributeList &AttrList,
56+
unsigned Index,
57+
llvm::Attribute::AttrKind Kind) {
58+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
59+
return AttrList.getAttributeAtIndex(Index, Kind);
60+
#else
61+
return AttrList.getAttribute(Index, Kind);
62+
#endif
63+
}
64+
65+
inline llvm::Attribute getAttributeAtIndex(const llvm::AttributeList &AttrList,
66+
unsigned Index,
67+
llvm::StringRef Kind) {
68+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
69+
return AttrList.getAttributeAtIndex(Index, Kind);
70+
#else
71+
return AttrList.getAttribute(Index, Kind);
72+
#endif
73+
}
74+
3675
} // namespace AttributeList
3776

3877
} // namespace VCINTR

GenXIntrinsics/include/llvmVCWrapper/IR/Function.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ inline llvm::Function *Create(llvm::FunctionType *FTy,
2828
#endif
2929
}
3030

31+
inline void addAttributeAtIndex(llvm::Function &F, unsigned Index,
32+
llvm::Attribute Attr) {
33+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
34+
F.addAttributeAtIndex(Index, Attr);
35+
#else
36+
F.addAttribute(Index, Attr);
37+
#endif
38+
}
39+
40+
inline void removeAttributeAtIndex(llvm::Function &F, unsigned Index,
41+
llvm::Attribute::AttrKind Kind) {
42+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
43+
F.removeAttributeAtIndex(Index, Kind);
44+
#else
45+
F.removeAttribute(Index, Kind);
46+
#endif
47+
}
48+
49+
inline void removeAttributeAtIndex(llvm::Function &F, unsigned Index,
50+
llvm::StringRef Kind) {
51+
#if VC_INTR_LLVM_VERSION_MAJOR >= 14
52+
F.removeAttributeAtIndex(Index, Kind);
53+
#else
54+
F.removeAttribute(Index, Kind);
55+
#endif
56+
}
57+
3158
} // namespace Function
3259

3360
} // namespace VCINTR

GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -433,25 +433,25 @@ bool GenXSPIRVReaderAdaptor::runOnFunction(Function &F) {
433433

434434
if (VCINTR::AttributeList::hasFnAttr(Attrs, VCFunctionMD::VCSIMTCall)) {
435435
auto SIMTMode = StringRef();
436-
SIMTMode = Attrs
437-
.getAttribute(AttributeList::FunctionIndex,
438-
VCFunctionMD::VCSIMTCall)
439-
.getValueAsString();
436+
SIMTMode =
437+
VCINTR::AttributeList::getAttributeAtIndex(
438+
Attrs, AttributeList::FunctionIndex, VCFunctionMD::VCSIMTCall)
439+
.getValueAsString();
440440
F.addFnAttr(FunctionMD::CMGenxSIMT, SIMTMode);
441441
}
442442

443443
auto &&Context = F.getContext();
444444
if (VCINTR::AttributeList::hasFnAttr(Attrs, VCFunctionMD::VCFloatControl)) {
445445
auto FloatControl = unsigned(0);
446-
Attrs
447-
.getAttribute(AttributeList::FunctionIndex,
448-
VCFunctionMD::VCFloatControl)
446+
VCINTR::AttributeList::getAttributeAtIndex(
447+
Attrs, AttributeList::FunctionIndex, VCFunctionMD::VCFloatControl)
449448
.getValueAsString()
450449
.getAsInteger(0, FloatControl);
451450

452451
auto Attr = Attribute::get(Context, FunctionMD::CMFloatControl,
453452
std::to_string(FloatControl));
454-
F.addAttribute(AttributeList::FunctionIndex, Attr);
453+
VCINTR::Function::addAttributeAtIndex(F, AttributeList::FunctionIndex,
454+
Attr);
455455
}
456456

457457
if (auto *ReqdSubgroupSize =
@@ -461,7 +461,8 @@ bool GenXSPIRVReaderAdaptor::runOnFunction(Function &F) {
461461
->getZExtValue();
462462
Attribute Attr = Attribute::get(Context, FunctionMD::OCLRuntime,
463463
std::to_string(SIMDSize));
464-
F.addAttribute(AttributeList::FunctionIndex, Attr);
464+
VCINTR::Function::addAttributeAtIndex(F, AttributeList::FunctionIndex,
465+
Attr);
465466
}
466467

467468
if (!(F.getCallingConv() == CallingConv::SPIR_KERNEL))
@@ -480,7 +481,8 @@ bool GenXSPIRVReaderAdaptor::runOnFunction(Function &F) {
480481
llvm::Type *I32Ty = llvm::Type::getInt32Ty(Context);
481482

482483
if (VCINTR::AttributeList::hasFnAttr(Attrs, VCFunctionMD::VCSLMSize)) {
483-
Attrs.getAttribute(AttributeList::FunctionIndex, VCFunctionMD::VCSLMSize)
484+
VCINTR::AttributeList::getAttributeAtIndex(
485+
Attrs, AttributeList::FunctionIndex, VCFunctionMD::VCSLMSize)
484486
.getValueAsString()
485487
.getAsInteger(0, SLMSize);
486488
}
@@ -490,18 +492,24 @@ bool GenXSPIRVReaderAdaptor::runOnFunction(Function &F) {
490492
auto ArgKind = unsigned(0);
491493
auto ArgIOKind = unsigned(0);
492494
auto ArgDesc = std::string();
493-
if (Attrs.hasAttribute(ArgNo + 1, VCFunctionMD::VCArgumentKind)) {
494-
Attrs.getAttribute(ArgNo + 1, VCFunctionMD::VCArgumentKind)
495+
if (VCINTR::AttributeList::hasAttributeAtIndex(
496+
Attrs, ArgNo + 1, VCFunctionMD::VCArgumentKind)) {
497+
VCINTR::AttributeList::getAttributeAtIndex(Attrs, ArgNo + 1,
498+
VCFunctionMD::VCArgumentKind)
495499
.getValueAsString()
496500
.getAsInteger(0, ArgKind);
497501
}
498-
if (Attrs.hasAttribute(ArgNo + 1, VCFunctionMD::VCArgumentIOKind)) {
499-
Attrs.getAttribute(ArgNo + 1, VCFunctionMD::VCArgumentIOKind)
502+
if (VCINTR::AttributeList::hasAttributeAtIndex(
503+
Attrs, ArgNo + 1, VCFunctionMD::VCArgumentIOKind)) {
504+
VCINTR::AttributeList::getAttributeAtIndex(Attrs, ArgNo + 1,
505+
VCFunctionMD::VCArgumentIOKind)
500506
.getValueAsString()
501507
.getAsInteger(0, ArgIOKind);
502508
}
503-
if (Attrs.hasAttribute(ArgNo + 1, VCFunctionMD::VCArgumentDesc)) {
504-
ArgDesc = Attrs.getAttribute(ArgNo + 1, VCFunctionMD::VCArgumentDesc)
509+
if (VCINTR::AttributeList::hasAttributeAtIndex(
510+
Attrs, ArgNo + 1, VCFunctionMD::VCArgumentDesc)) {
511+
ArgDesc = VCINTR::AttributeList::getAttributeAtIndex(
512+
Attrs, ArgNo + 1, VCFunctionMD::VCArgumentDesc)
505513
.getValueAsString()
506514
.str();
507515
}

GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVWriterAdaptor.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,24 @@ bool GenXSPIRVWriterAdaptorImpl::runOnFunction(Function &F) {
483483

484484
if (VCINTR::AttributeList::hasFnAttr(Attrs, FunctionMD::CMGenxSIMT)) {
485485
auto SIMTMode = StringRef();
486-
SIMTMode =
487-
Attrs.getAttribute(AttributeList::FunctionIndex, FunctionMD::CMGenxSIMT)
488-
.getValueAsString();
486+
SIMTMode = VCINTR::AttributeList::getAttributeAtIndex(
487+
Attrs, AttributeList::FunctionIndex, FunctionMD::CMGenxSIMT)
488+
.getValueAsString();
489489
F.addFnAttr(VCFunctionMD::VCSIMTCall, SIMTMode);
490490
}
491491

492492
auto &&Context = F.getContext();
493493
if (VCINTR::AttributeList::hasFnAttr(Attrs, FunctionMD::CMFloatControl)) {
494494
auto FloatControl = unsigned(0);
495-
Attrs.getAttribute(AttributeList::FunctionIndex, FunctionMD::CMFloatControl)
495+
VCINTR::AttributeList::getAttributeAtIndex(
496+
Attrs, AttributeList::FunctionIndex, FunctionMD::CMFloatControl)
496497
.getValueAsString()
497498
.getAsInteger(0, FloatControl);
498499

499500
auto Attr = Attribute::get(Context, VCFunctionMD::VCFloatControl,
500501
std::to_string(FloatControl));
501-
F.addAttribute(AttributeList::FunctionIndex, Attr);
502+
VCINTR::Function::addAttributeAtIndex(F, AttributeList::FunctionIndex,
503+
Attr);
502504
}
503505

504506
auto *KernelMDs = F.getParent()->getNamedMetadata(FunctionMD::GenXKernels);
@@ -507,7 +509,8 @@ bool GenXSPIRVWriterAdaptorImpl::runOnFunction(Function &F) {
507509

508510
if (VCINTR::AttributeList::hasFnAttr(Attrs, FunctionMD::OCLRuntime)) {
509511
auto SIMDSize = unsigned(0);
510-
Attrs.getAttribute(AttributeList::FunctionIndex, FunctionMD::OCLRuntime)
512+
VCINTR::AttributeList::getAttributeAtIndex(
513+
Attrs, AttributeList::FunctionIndex, FunctionMD::OCLRuntime)
511514
.getValueAsString()
512515
.getAsInteger(0, SIMDSize);
513516
auto SizeMD = ConstantAsMetadata::get(
@@ -537,7 +540,7 @@ bool GenXSPIRVWriterAdaptorImpl::runOnFunction(Function &F) {
537540
auto ArgKind = V->getZExtValue();
538541
auto Attr = Attribute::get(Context, VCFunctionMD::VCArgumentKind,
539542
std::to_string(ArgKind));
540-
F.addAttribute(ArgNo + 1, Attr);
543+
VCINTR::Function::addAttributeAtIndex(F, ArgNo + 1, Attr);
541544
}
542545
}
543546
}
@@ -550,7 +553,8 @@ bool GenXSPIRVWriterAdaptorImpl::runOnFunction(Function &F) {
550553
auto SLMSize = V->getZExtValue();
551554
auto Attr = Attribute::get(Context, VCFunctionMD::VCSLMSize,
552555
std::to_string(SLMSize));
553-
F.addAttribute(AttributeList::FunctionIndex, Attr);
556+
VCINTR::Function::addAttributeAtIndex(F, AttributeList::FunctionIndex,
557+
Attr);
554558
}
555559
}
556560

@@ -564,7 +568,7 @@ bool GenXSPIRVWriterAdaptorImpl::runOnFunction(Function &F) {
564568
auto ArgKind = V->getZExtValue();
565569
auto Attr = Attribute::get(Context, VCFunctionMD::VCArgumentIOKind,
566570
std::to_string(ArgKind));
567-
F.addAttribute(ArgNo + 1, Attr);
571+
VCINTR::Function::addAttributeAtIndex(F, ArgNo + 1, Attr);
568572
}
569573
}
570574
}
@@ -579,7 +583,7 @@ bool GenXSPIRVWriterAdaptorImpl::runOnFunction(Function &F) {
579583
auto &&Desc = MS->getString();
580584
auto Attr =
581585
Attribute::get(Context, VCFunctionMD::VCArgumentDesc, Desc);
582-
F.addAttribute(ArgNo + 1, Attr);
586+
VCINTR::Function::addAttributeAtIndex(F, ArgNo + 1, Attr);
583587
}
584588
}
585589
}

GenXIntrinsics/lib/GenXIntrinsics/GenXSingleElementVectorUtil.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SPDX-License-Identifier: MIT
2222
#include "llvm/IR/Module.h"
2323
#include "llvm/Pass.h"
2424

25+
#include "llvmVCWrapper/IR/Attributes.h"
2526
#include "llvmVCWrapper/IR/DerivedTypes.h"
2627
#include "llvmVCWrapper/IR/Function.h"
2728
#include "llvmVCWrapper/IR/GlobalValue.h"
@@ -460,10 +461,11 @@ static void manageSingleElementVectorAttribute(Function &NewF, Type *OldT,
460461
auto InnerPtrs = std::to_string(getInnerPointerVectorNesting(OldT));
461462
auto Attr = Attribute::get(NewF.getContext(),
462463
VCModuleMD::VCSingleElementVector, InnerPtrs);
463-
NewF.addAttribute(AttrNo, Attr);
464+
VCINTR::Function::addAttributeAtIndex(NewF, AttrNo, Attr);
464465
} else if (hasSingleElementVector(NewT)) {
465466
assert(!hasSingleElementVector(OldT));
466-
NewF.removeAttribute(AttrNo, VCModuleMD::VCSingleElementVector);
467+
VCINTR::Function::removeAttributeAtIndex(NewF, AttrNo,
468+
VCModuleMD::VCSingleElementVector);
467469
}
468470
}
469471

@@ -492,11 +494,12 @@ static Type *getOriginalType(Function &F, size_t AttrNo) {
492494
auto *T =
493495
AttrNo == 0 ? FuncT->getReturnType() : FuncT->getParamType(AttrNo - 1);
494496
auto Attrs = F.getAttributes();
495-
if (!Attrs.hasAttribute(AttrNo, VCModuleMD::VCSingleElementVector))
497+
if (!VCINTR::AttributeList::hasAttributeAtIndex(
498+
Attrs, AttrNo, VCModuleMD::VCSingleElementVector))
496499
return T;
497-
auto InnerPtrsStr =
498-
Attrs.getAttribute(AttrNo, VCModuleMD::VCSingleElementVector)
499-
.getValueAsString();
500+
auto InnerPtrsStr = VCINTR::AttributeList::getAttributeAtIndex(
501+
Attrs, AttrNo, VCModuleMD::VCSingleElementVector)
502+
.getValueAsString();
500503
auto InnerPtrs = InnerPtrsStr.empty() ? 0 : std::stoull(InnerPtrsStr.str());
501504
return getTypeWithSingleElementVector(T, InnerPtrs);
502505
}

0 commit comments

Comments
 (0)