[NFC] Cleanup AttributeList::getStackAlignment()
authorArthur Eubanks <aeubanks@google.com>
Thu, 19 Aug 2021 21:20:59 +0000 (14:20 -0700)
committerArthur Eubanks <aeubanks@google.com>
Thu, 19 Aug 2021 21:21:40 +0000 (14:21 -0700)
So that we don't use a confusing index.

llvm/include/llvm/IR/Attributes.h
llvm/include/llvm/IR/Function.h
llvm/lib/IR/Attributes.cpp
llvm/unittests/IR/AttributesTest.cpp

index 97f0985..68ea881 100644 (file)
@@ -821,8 +821,11 @@ public:
   /// Return the elementtype type for the specified function parameter.
   Type *getParamElementType(unsigned ArgNo) const;
 
-  /// Get the stack alignment.
-  MaybeAlign getStackAlignment(unsigned Index) const;
+  /// Get the stack alignment of the function.
+  MaybeAlign getFnStackAlignment() const;
+
+  /// Get the stack alignment of the return value.
+  MaybeAlign getRetStackAlignment() const;
 
   /// Get the number of dereferenceable bytes (or zero if unknown) of the return
   /// value.
index 98dff3c..bffc93b 100644 (file)
@@ -425,7 +425,7 @@ public:
 
   /// Return the stack alignment for the function.
   MaybeAlign getFnStackAlign() const {
-    return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
+    return AttributeSets.getFnStackAlignment();
   }
 
   /// Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
index d8765cc..3eca9a0 100644 (file)
@@ -1462,8 +1462,12 @@ Type *AttributeList::getParamElementType(unsigned Index) const {
   return getAttributes(Index + FirstArgIndex).getElementType();
 }
 
-MaybeAlign AttributeList::getStackAlignment(unsigned Index) const {
-  return getAttributes(Index).getStackAlignment();
+MaybeAlign AttributeList::getFnStackAlignment() const {
+  return getFnAttrs().getStackAlignment();
+}
+
+MaybeAlign AttributeList::getRetStackAlignment() const {
+  return getRetAttrs().getStackAlignment();
 }
 
 uint64_t AttributeList::getRetDereferenceableBytes() const {
index 3e8bcf1..188d4e3 100644 (file)
@@ -106,7 +106,7 @@ TEST(Attributes, RemoveAlign) {
   EXPECT_TRUE(AL.hasRetAttrs());
   EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
   EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
-  EXPECT_TRUE(AL.getStackAlignment(0) == 32);
+  EXPECT_TRUE(AL.getRetStackAlignment() == 32);
   EXPECT_TRUE(AL.hasParamAttrs(0));
   EXPECT_TRUE(AL.hasParamAttr(0, Attribute::Alignment));
   EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
@@ -117,7 +117,7 @@ TEST(Attributes, RemoveAlign) {
   EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
   EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
   EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
-  EXPECT_TRUE(AL.getStackAlignment(0) == 32);
+  EXPECT_TRUE(AL.getRetStackAlignment() == 32);
 
   AL = AL.removeRetAttribute(C, Attribute::StackAlignment);
   EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
@@ -134,7 +134,7 @@ TEST(Attributes, RemoveAlign) {
   EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
   EXPECT_TRUE(AL2.hasRetAttr(Attribute::StackAlignment));
   EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
-  EXPECT_TRUE(AL2.getStackAlignment(0) == 32);
+  EXPECT_TRUE(AL2.getRetStackAlignment() == 32);
 
   AL2 = AL2.removeRetAttributes(C, B_stackalign);
   EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));