[Mlir-commits] [mlir] 6ac3287 - [Attributes] Replace doesAttrKindHaveArgument() (NFC)

Nikita Popov llvmlistbot at llvm.org
Mon Jul 12 12:57:43 PDT 2021


Author: Nikita Popov
Date: 2021-07-12T21:57:26+02:00
New Revision: 6ac32872ee2fa02bdce54b25641d9a21cfbcfa9a

URL: https://github.com/llvm/llvm-project/commit/6ac32872ee2fa02bdce54b25641d9a21cfbcfa9a
DIFF: https://github.com/llvm/llvm-project/commit/6ac32872ee2fa02bdce54b25641d9a21cfbcfa9a.diff

LOG: [Attributes] Replace doesAttrKindHaveArgument() (NFC)

This is now the same as isIntAttrKind(), so use that instead, as
it does not require manual maintenance. The naming is also more
accurate in that both int and type attributes have an argument,
but this method was only targeting int attributes.

I initially wanted to tighten the AttrBuilder assertion, but we
have some in-tree uses that would violate it.

Added: 
    

Modified: 
    llvm/include/llvm/IR/Attributes.h
    llvm/lib/Analysis/AssumeBundleQueries.cpp
    llvm/lib/IR/AttributeImpl.h
    llvm/lib/IR/Attributes.cpp
    llvm/lib/IR/Verifier.cpp
    llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 2f04c02e4b760..c75b950853ebc 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -138,9 +138,6 @@ class Attribute {
 
   static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind);
 
-  /// Return true if and only if the attribute has an Argument.
-  static bool doesAttrKindHaveArgument(Attribute::AttrKind AttrKind);
-
   /// Return true if the provided string matches the IR name of an attribute.
   /// example: "noalias" return true but not "NoAlias"
   static bool isExistingAttribute(StringRef Name);
@@ -841,7 +838,8 @@ class AttrBuilder {
   AttrBuilder &addAttribute(Attribute::AttrKind Val) {
     assert((unsigned)Val < Attribute::EndAttrKinds &&
            "Attribute out of range!");
-    assert(!Attribute::doesAttrKindHaveArgument(Val) &&
+    // TODO: This should really assert isEnumAttrKind().
+    assert(!Attribute::isIntAttrKind(Val) &&
            "Adding integer attribute without adding a value!");
     Attrs[Val] = true;
     return *this;

diff  --git a/llvm/lib/Analysis/AssumeBundleQueries.cpp b/llvm/lib/Analysis/AssumeBundleQueries.cpp
index 519d27aa3fb7a..dee044346f025 100644
--- a/llvm/lib/Analysis/AssumeBundleQueries.cpp
+++ b/llvm/lib/Analysis/AssumeBundleQueries.cpp
@@ -44,7 +44,7 @@ bool llvm::hasAttributeInAssume(AssumeInst &Assume, Value *IsOn,
                                 StringRef AttrName, uint64_t *ArgVal) {
   assert(Attribute::isExistingAttribute(AttrName) &&
          "this attribute doesn't exist");
-  assert((ArgVal == nullptr || Attribute::doesAttrKindHaveArgument(
+  assert((ArgVal == nullptr || Attribute::isIntAttrKind(
                                    Attribute::getAttrKindFromName(AttrName))) &&
          "requested value for an attribute that has no argument");
   if (Assume.bundle_op_infos().empty())

diff  --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h
index 3b297a9e39084..6669238602bfa 100644
--- a/llvm/lib/IR/AttributeImpl.h
+++ b/llvm/lib/IR/AttributeImpl.h
@@ -136,7 +136,7 @@ class IntAttributeImpl : public EnumAttributeImpl {
 public:
   IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
       : EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
-    assert(Attribute::doesAttrKindHaveArgument(Kind) &&
+    assert(Attribute::isIntAttrKind(Kind) &&
            "Wrong kind for int attribute!");
   }
 

diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 916aa8648000d..06042b221b8fb 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -242,15 +242,6 @@ StringRef Attribute::getNameFromAttrKind(Attribute::AttrKind AttrKind) {
   }
 }
 
-bool Attribute::doesAttrKindHaveArgument(Attribute::AttrKind AttrKind) {
-  return AttrKind == Attribute::Alignment ||
-         AttrKind == Attribute::StackAlignment ||
-         AttrKind == Attribute::Dereferenceable ||
-         AttrKind == Attribute::AllocSize ||
-         AttrKind == Attribute::DereferenceableOrNull ||
-         AttrKind == Attribute::VScaleRange;
-}
-
 bool Attribute::isExistingAttribute(StringRef Name) {
   return StringSwitch<bool>(Name)
 #define GET_ATTR_NAMES

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 6039d1cf2dc02..6ee9ea4421d93 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1741,8 +1741,7 @@ void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction,
       continue;
     }
 
-    if (A.isIntAttribute() !=
-        Attribute::doesAttrKindHaveArgument(A.getKindAsEnum())) {
+    if (A.isIntAttribute() != Attribute::isIntAttrKind(A.getKindAsEnum())) {
       CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument",
                   V);
       return;
@@ -4702,7 +4701,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
       Assert(ArgCount <= 2, "to many arguments");
       if (Kind == Attribute::None)
         break;
-      if (Attribute::doesAttrKindHaveArgument(Kind)) {
+      if (Attribute::isIntAttrKind(Kind)) {
         Assert(ArgCount == 2, "this attribute should have 2 arguments");
         Assert(isa<ConstantInt>(Call.getOperand(Elem.Begin + 1)),
                "the second argument should be a constant integral value");

diff  --git a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
index f8c66035c65bf..d689e04da36f9 100644
--- a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
+++ b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
@@ -152,7 +152,7 @@ struct AssumeBuilderState {
     }
     if (auto *Arg = dyn_cast<Argument>(RK.WasOn)) {
       if (Arg->hasAttribute(RK.AttrKind) &&
-          (!Attribute::doesAttrKindHaveArgument(RK.AttrKind) ||
+          (!Attribute::isIntAttrKind(RK.AttrKind) ||
            Arg->getAttribute(RK.AttrKind).getValueAsInt() >= RK.ArgValue))
         return false;
       return true;
@@ -422,7 +422,7 @@ struct AssumeSimplify {
           if (auto *Arg = dyn_cast_or_null<Argument>(RK.WasOn)) {
             bool HasSameKindAttr = Arg->hasAttribute(RK.AttrKind);
             if (HasSameKindAttr)
-              if (!Attribute::doesAttrKindHaveArgument(RK.AttrKind) ||
+              if (!Attribute::isIntAttrKind(RK.AttrKind) ||
                   Arg->getAttribute(RK.AttrKind).getValueAsInt() >=
                       RK.ArgValue) {
                 RemoveFromAssume();

diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 5f39d52e03fc4..f078ded04ec7f 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -522,7 +522,7 @@ static LogicalResult checkedAddLLVMFnAttribute(Location loc,
     return success();
   }
 
-  if (llvm::Attribute::doesAttrKindHaveArgument(kind)) {
+  if (llvm::Attribute::isIntAttrKind(kind)) {
     if (value.empty())
       return emitError(loc) << "LLVM attribute '" << key << "' expects a value";
 


        


More information about the Mlir-commits mailing list