[llvm] 7557d6c - [NFC] Cleanup calls to CallBase::getAttribute()

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 18 09:39:54 PDT 2021


Author: Arthur Eubanks
Date: 2021-08-18T09:39:33-07:00
New Revision: 7557d6c896d3418216e82c0d0cf3b0708f2145bb

URL: https://github.com/llvm/llvm-project/commit/7557d6c896d3418216e82c0d0cf3b0708f2145bb
DIFF: https://github.com/llvm/llvm-project/commit/7557d6c896d3418216e82c0d0cf3b0708f2145bb.diff

LOG: [NFC] Cleanup calls to CallBase::getAttribute()

Added: 
    

Modified: 
    llvm/include/llvm/IR/InstrTypes.h
    llvm/lib/Analysis/VectorUtils.cpp
    llvm/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/unittests/Transforms/Utils/VFABIUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 60e8c090fb83e..55ab5bce20c72 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -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");

diff  --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index ce91e16fdfb46..543f3790fee0a 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -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;
 

diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 7fa819ec08ad3..1ffba572ff35f 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -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 =

diff  --git a/llvm/unittests/Transforms/Utils/VFABIUtils.cpp b/llvm/unittests/Transforms/Utils/VFABIUtils.cpp
index 689e1280deab9..4ac9b45a403c5 100644
--- a/llvm/unittests/Transforms/Utils/VFABIUtils.cpp
+++ b/llvm/unittests/Transforms/Utils/VFABIUtils.cpp
@@ -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)");
 }


        


More information about the llvm-commits mailing list