Skip to content

Commit 7557d6c

Browse files
committed
[NFC] Cleanup calls to CallBase::getAttribute()
1 parent 164e09d commit 7557d6c

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,16 @@ class CallBase : public Instruction {
16351635
return getAttributes().getAttribute(i, Kind);
16361636
}
16371637

1638+
/// Get the attribute of a given kind for the function.
1639+
Attribute getFnAttr(StringRef Kind) const {
1640+
return getAttributes().getFnAttr(Kind);
1641+
}
1642+
1643+
/// Get the attribute of a given kind for the function.
1644+
Attribute getFnAttr(Attribute::AttrKind Kind) const {
1645+
return getAttributes().getFnAttr(Kind);
1646+
}
1647+
16381648
/// Get the attribute of a given kind from a given arg
16391649
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
16401650
assert(ArgNo < getNumArgOperands() && "Out of bounds");

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,7 @@ std::string VFABI::mangleTLIVectorName(StringRef VectorName,
13521352

13531353
void VFABI::getVectorVariantNames(
13541354
const CallInst &CI, SmallVectorImpl<std::string> &VariantMappings) {
1355-
const StringRef S =
1356-
CI.getAttribute(AttributeList::FunctionIndex, VFABI::MappingsAttrName)
1357-
.getValueAsString();
1355+
const StringRef S = CI.getFnAttr(VFABI::MappingsAttrName).getValueAsString();
13581356
if (S.empty())
13591357
return;
13601358

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,10 +1915,8 @@ static void RemovePreallocated(Function *F) {
19151915
Value *AllocaReplacement = ArgAllocas[AllocArgIndex];
19161916
if (!AllocaReplacement) {
19171917
auto AddressSpace = UseCall->getType()->getPointerAddressSpace();
1918-
auto *ArgType = UseCall
1919-
->getAttribute(AttributeList::FunctionIndex,
1920-
Attribute::Preallocated)
1921-
.getValueAsType();
1918+
auto *ArgType =
1919+
UseCall->getFnAttr(Attribute::Preallocated).getValueAsType();
19221920
auto *InsertBefore = PreallocatedSetup->getNextNonDebugInstruction();
19231921
Builder.SetInsertPoint(InsertBefore);
19241922
auto *Alloca =

llvm/unittests/Transforms/Utils/VFABIUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ TEST_F(VFABIAttrTest, Write) {
4646
Mappings.push_back("_ZGVnN8v_g");
4747
Mappings.push_back("_ZGVnN2v_g(custom_vg)");
4848
VFABI::setVectorVariantNames(CI, Mappings);
49-
const StringRef S = CI->getAttribute(AttributeList::FunctionIndex,
50-
"vector-function-abi-variant")
51-
.getValueAsString();
49+
const StringRef S =
50+
CI->getFnAttr("vector-function-abi-variant").getValueAsString();
5251
EXPECT_EQ(S, "_ZGVnN8v_g,_ZGVnN2v_g(custom_vg)");
5352
}

0 commit comments

Comments
 (0)