[PATCH] D72884: [NFC] Factor out function to detect if an attribute has an argument.
Tyker via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 15:27:50 PST 2020
Tyker updated this revision to Diff 239443.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72884/new/
https://reviews.llvm.org/D72884
Files:
llvm/include/llvm/IR/Attributes.h
llvm/lib/IR/AttributeImpl.h
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Utils/KnowledgeRetention.cpp
Index: llvm/lib/Transforms/Utils/KnowledgeRetention.cpp
===================================================================
--- llvm/lib/Transforms/Utils/KnowledgeRetention.cpp
+++ llvm/lib/Transforms/Utils/KnowledgeRetention.cpp
@@ -124,6 +124,11 @@
SmallVector<OperandBundleDef, 8> OpBundle;
for (const AssumedKnowledge &Elem : AssumedKnowledgeSet) {
SmallVector<Value *, 2> Args;
+ assert(Attribute::getAttrKindFromName(Elem.Name) ==
+ Attribute::AttrKind::None ||
+ static_cast<bool>(Elem.Argument) ==
+ Attribute::doesAttrKindHaveArgument(
+ Attribute::getAttrKindFromName(Elem.Name)));
if (Elem.WasOn.getPointer())
Args.push_back(Elem.WasOn.getPointer());
if (Elem.Argument)
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1565,6 +1565,13 @@
if (A.isStringAttribute())
continue;
+ if (A.isIntAttribute() !=
+ Attribute::doesAttrKindHaveArgument(A.getKindAsEnum())) {
+ CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument",
+ V);
+ return;
+ }
+
if (isFuncOnlyAttr(A.getKindAsEnum())) {
if (!IsFunction) {
CheckFailed("Attribute '" + A.getAsString() +
Index: llvm/lib/IR/Attributes.cpp
===================================================================
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -199,6 +199,14 @@
}
}
+bool Attribute::doesAttrKindHaveArgument(Attribute::AttrKind AttrKind) {
+ return AttrKind == Attribute::Alignment ||
+ AttrKind == Attribute::StackAlignment ||
+ AttrKind == Attribute::Dereferenceable ||
+ AttrKind == Attribute::AllocSize ||
+ AttrKind == Attribute::DereferenceableOrNull;
+}
+
//===----------------------------------------------------------------------===//
// Attribute Accessor Methods
//===----------------------------------------------------------------------===//
@@ -1472,8 +1480,7 @@
AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) {
assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
- assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
- Val != Attribute::Dereferenceable && Val != Attribute::AllocSize &&
+ assert(!Attribute::doesAttrKindHaveArgument(Val) &&
"Adding integer attribute without adding a value!");
Attrs[Val] = true;
return *this;
Index: llvm/lib/IR/AttributeImpl.h
===================================================================
--- llvm/lib/IR/AttributeImpl.h
+++ llvm/lib/IR/AttributeImpl.h
@@ -134,10 +134,7 @@
public:
IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
: EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
- assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment ||
- Kind == Attribute::Dereferenceable ||
- Kind == Attribute::DereferenceableOrNull ||
- Kind == Attribute::AllocSize) &&
+ assert(Attribute::doesAttrKindHaveArgument(Kind) &&
"Wrong kind for int attribute!");
}
Index: llvm/include/llvm/IR/Attributes.h
===================================================================
--- llvm/include/llvm/IR/Attributes.h
+++ llvm/include/llvm/IR/Attributes.h
@@ -111,6 +111,9 @@
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind);
+ /// Return true if and only if the attribute has an Argument.
+ static bool doesAttrKindHaveArgument(Attribute::AttrKind AttrKind);
+
//===--------------------------------------------------------------------===//
// Attribute Accessors
//===--------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72884.239443.patch
Type: text/x-patch
Size: 3850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200121/1ac576f1/attachment.bin>
More information about the llvm-commits
mailing list