[llvm] 7c8206c - [NFC] Cleanup AttributeList::getStackAlignment()

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 19 14:21:53 PDT 2021


Author: Arthur Eubanks
Date: 2021-08-19T14:21:40-07:00
New Revision: 7c8206cd2ad62cd65a1267e974fd9d49d5ff01a6

URL: https://github.com/llvm/llvm-project/commit/7c8206cd2ad62cd65a1267e974fd9d49d5ff01a6
DIFF: https://github.com/llvm/llvm-project/commit/7c8206cd2ad62cd65a1267e974fd9d49d5ff01a6.diff

LOG: [NFC] Cleanup AttributeList::getStackAlignment()

So that we don't use a confusing index.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 97f0985839d7d..68ea881b8e41c 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -821,8 +821,11 @@ class AttributeList {
   /// 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.

diff  --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index 98dff3c684e63..bffc93b629847 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -425,7 +425,7 @@ class Function : public GlobalObject, public ilist_node<Function> {
 
   /// 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.

diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index d8765ccbd6b76..3eca9a0c09286 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -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 {

diff  --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp
index 3e8bcf16594b9..188d4e342e857 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -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));


        


More information about the llvm-commits mailing list