Skip to content

Commit

Permalink
[NFC] Cleanup calls to CallBase::getAttribute()
Browse files Browse the repository at this point in the history
  • Loading branch information
aeubanks committed Aug 18, 2021
1 parent 164e09d commit 7557d6c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/InstrTypes.h
Expand Up @@ -1635,6 +1635,16 @@ class CallBase : public Instruction {
return getAttributes().getAttribute(i, Kind);
}

/// Get the attribute of a given kind for the function.
Attribute getFnAttr(StringRef Kind) const {
return getAttributes().getFnAttr(Kind);
}

/// Get the attribute of a given kind for the function.
Attribute getFnAttr(Attribute::AttrKind Kind) const {
return getAttributes().getFnAttr(Kind);
}

/// Get the attribute of a given kind from a given arg
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
assert(ArgNo < getNumArgOperands() && "Out of bounds");
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Analysis/VectorUtils.cpp
Expand Up @@ -1352,9 +1352,7 @@ std::string VFABI::mangleTLIVectorName(StringRef VectorName,

void VFABI::getVectorVariantNames(
const CallInst &CI, SmallVectorImpl<std::string> &VariantMappings) {
const StringRef S =
CI.getAttribute(AttributeList::FunctionIndex, VFABI::MappingsAttrName)
.getValueAsString();
const StringRef S = CI.getFnAttr(VFABI::MappingsAttrName).getValueAsString();
if (S.empty())
return;

Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/IPO/GlobalOpt.cpp
Expand Up @@ -1915,10 +1915,8 @@ static void RemovePreallocated(Function *F) {
Value *AllocaReplacement = ArgAllocas[AllocArgIndex];
if (!AllocaReplacement) {
auto AddressSpace = UseCall->getType()->getPointerAddressSpace();
auto *ArgType = UseCall
->getAttribute(AttributeList::FunctionIndex,
Attribute::Preallocated)
.getValueAsType();
auto *ArgType =
UseCall->getFnAttr(Attribute::Preallocated).getValueAsType();
auto *InsertBefore = PreallocatedSetup->getNextNonDebugInstruction();
Builder.SetInsertPoint(InsertBefore);
auto *Alloca =
Expand Down
5 changes: 2 additions & 3 deletions llvm/unittests/Transforms/Utils/VFABIUtils.cpp
Expand Up @@ -46,8 +46,7 @@ TEST_F(VFABIAttrTest, Write) {
Mappings.push_back("_ZGVnN8v_g");
Mappings.push_back("_ZGVnN2v_g(custom_vg)");
VFABI::setVectorVariantNames(CI, Mappings);
const StringRef S = CI->getAttribute(AttributeList::FunctionIndex,
"vector-function-abi-variant")
.getValueAsString();
const StringRef S =
CI->getFnAttr("vector-function-abi-variant").getValueAsString();
EXPECT_EQ(S, "_ZGVnN8v_g,_ZGVnN2v_g(custom_vg)");
}

0 comments on commit 7557d6c

Please sign in to comment.