1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[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.
This commit is contained in:
Nikita Popov 2021-07-12 21:25:46 +02:00
parent 436c202090
commit 2812298c44
6 changed files with 8 additions and 20 deletions

View File

@ -138,9 +138,6 @@ public:
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 @@ public:
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;

View File

@ -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())

View File

@ -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!");
}

View File

@ -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

View File

@ -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");

View File

@ -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();