[NFC] Cleanup calls to CallBase::getAttribute()
authorArthur Eubanks <aeubanks@google.com>
Wed, 18 Aug 2021 16:37:01 +0000 (09:37 -0700)
committerArthur Eubanks <aeubanks@google.com>
Wed, 18 Aug 2021 16:39:33 +0000 (09:39 -0700)
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/Analysis/VectorUtils.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/unittests/Transforms/Utils/VFABIUtils.cpp

index 60e8c09..55ab5bc 100644 (file)
@@ -1635,6 +1635,16 @@ public:
     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");
index ce91e16..543f379 100644 (file)
@@ -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;
 
index 7fa819e..1ffba57 100644 (file)
@@ -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 =
index 689e128..4ac9b45 100644 (file)
@@ -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)");
 }