[llvm] d7593eb - [NFC] Clean up users of AttributeList::hasAttribute()
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 13 12:02:15 PDT 2021
Author: Arthur Eubanks
Date: 2021-08-13T11:59:18-07:00
New Revision: d7593ebaeeec2072abed73db0299a0e71f5c7a2c
URL: https://github.com/llvm/llvm-project/commit/d7593ebaeeec2072abed73db0299a0e71f5c7a2c
DIFF: https://github.com/llvm/llvm-project/commit/d7593ebaeeec2072abed73db0299a0e71f5c7a2c.diff
LOG: [NFC] Clean up users of AttributeList::hasAttribute()
AttributeList::hasAttribute() is confusing, use clearer methods like
hasParamAttr()/hasRetAttr().
Add hasRetAttr() since it was missing from AttributeList.
Added:
Modified:
llvm/include/llvm/IR/Attributes.h
llvm/include/llvm/IR/Function.h
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/CodeGen/MachinePipeliner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
llvm/lib/Target/AVR/AVRISelLowering.cpp
llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp
llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/unittests/IR/AttributesTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 3b1cead212c85..dacab3938f557 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -652,6 +652,14 @@ class AttributeList {
return hasAttributes(ArgNo + FirstArgIndex);
}
+ /// Return true if the attribute exists for the return value.
+ bool hasRetAttr(Attribute::AttrKind Kind) const {
+ return hasAttribute(ReturnIndex, Kind);
+ }
+
+ /// Return true if attributes exists for the return value.
+ bool hasRetAttrs() const { return hasAttributes(ReturnIndex); }
+
/// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
/// may be faster.
bool hasFnAttr(Attribute::AttrKind Kind) const;
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index d1c8a231d45aa..ce0bbb54d846f 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -699,8 +699,7 @@ class Function : public GlobalObject, public ilist_node<Function> {
/// Determine if the parameter or return value is marked with NoAlias
/// attribute.
bool returnDoesNotAlias() const {
- return AttributeSets.hasAttribute(AttributeList::ReturnIndex,
- Attribute::NoAlias);
+ return AttributeSets.hasRetAttr(Attribute::NoAlias);
}
void setReturnDoesNotAlias() {
addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index aab51f113fe38..65cada3d735de 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1760,7 +1760,7 @@ class CallBase : public Instruction {
/// Determine if the return value is marked with NoAlias attribute.
bool returnDoesNotAlias() const {
- return Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
+ return Attrs.hasRetAttr(Attribute::NoAlias);
}
/// If one of the arguments has the 'returned' attribute, returns its
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 156b46cc94534..9ae10d76692a1 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -5571,7 +5571,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
AttributeList::get(Context, AttributeSet::get(Context, FuncAttrs),
AttributeSet::get(Context, RetAttrs), Attrs);
- if (PAL.hasAttribute(1, Attribute::StructRet) && !RetType->isVoidTy())
+ if (PAL.hasParamAttr(0, Attribute::StructRet) && !RetType->isVoidTy())
return error(RetTypeLoc, "functions with 'sret' argument must return void");
FunctionType *FT = FunctionType::get(RetType, ParamTypeList, IsVarArg);
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index e12b3ed2b70ca..2ce32748453d2 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -497,8 +497,8 @@ static bool isLibCallInTailPosition(MachineInstr &MI,
return false;
// It's not safe to eliminate the sign / zero extension of the return value.
- if (CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt) ||
- CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
+ if (CallerAttrs.hasRetAttr(Attribute::ZExt) ||
+ CallerAttrs.hasRetAttr(Attribute::SExt))
return false;
// Only tail call if the following instruction is a standard return or if we
diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp
index caa3f8049aebd..f32c8a2978fe3 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -200,8 +200,7 @@ bool MachinePipeliner::runOnMachineFunction(MachineFunction &mf) {
if (!EnableSWP)
return false;
- if (mf.getFunction().getAttributes().hasAttribute(
- AttributeList::FunctionIndex, Attribute::OptimizeForSize) &&
+ if (mf.getFunction().getAttributes().hasFnAttr(Attribute::OptimizeForSize) &&
!EnableSWPOptSize.getPosition())
return false;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 0786dc395b409..9e21a213a77aa 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1953,16 +1953,13 @@ void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
/*IsVarArg*/ false, DL);
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
- if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
- Attribute::SExt))
+ if (F->getAttributes().hasRetAttr(Attribute::SExt))
ExtendKind = ISD::SIGN_EXTEND;
- else if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
- Attribute::ZExt))
+ else if (F->getAttributes().hasRetAttr(Attribute::ZExt))
ExtendKind = ISD::ZERO_EXTEND;
LLVMContext &Context = F->getContext();
- bool RetInReg = F->getAttributes().hasAttribute(
- AttributeList::ReturnIndex, Attribute::InReg);
+ bool RetInReg = F->getAttributes().hasRetAttr(Attribute::InReg);
for (unsigned j = 0; j != NumValues; ++j) {
EVT VT = ValueVTs[j];
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index d11c6b05aad7c..0b817c99d20a5 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -1657,9 +1657,9 @@ void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
EVT VT = ValueVTs[j];
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
- if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
+ if (attr.hasRetAttr(Attribute::SExt))
ExtendKind = ISD::SIGN_EXTEND;
- else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
+ else if (attr.hasRetAttr(Attribute::ZExt))
ExtendKind = ISD::ZERO_EXTEND;
// FIXME: C calling convention requires the return type to be promoted to
@@ -1679,13 +1679,13 @@ void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
// 'inreg' on function refers to return value
ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
- if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::InReg))
+ if (attr.hasRetAttr(Attribute::InReg))
Flags.setInReg();
// Propagate extension type if any
- if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
+ if (attr.hasRetAttr(Attribute::SExt))
Flags.setSExt();
- else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
+ else if (attr.hasRetAttr(Attribute::ZExt))
Flags.setZExt();
for (unsigned i = 0; i < NumParts; ++i)
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
index df5dd59df190b..5ad2c6e6e7a08 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
@@ -387,11 +387,9 @@ bool AArch64CallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
MVT NewVT = TLI.getRegisterTypeForCallingConv(Ctx, CC, SplitEVTs[i]);
if (EVT(NewVT) != SplitEVTs[i]) {
unsigned ExtendOp = TargetOpcode::G_ANYEXT;
- if (F.getAttributes().hasAttribute(AttributeList::ReturnIndex,
- Attribute::SExt))
+ if (F.getAttributes().hasRetAttr(Attribute::SExt))
ExtendOp = TargetOpcode::G_SEXT;
- else if (F.getAttributes().hasAttribute(AttributeList::ReturnIndex,
- Attribute::ZExt))
+ else if (F.getAttributes().hasRetAttr(Attribute::ZExt))
ExtendOp = TargetOpcode::G_ZEXT;
LLT NewLLT(NewVT);
diff --git a/llvm/lib/Target/AVR/AVRISelLowering.cpp b/llvm/lib/Target/AVR/AVRISelLowering.cpp
index 58a7aed91cdf3..ce50ed0bcfd74 100644
--- a/llvm/lib/Target/AVR/AVRISelLowering.cpp
+++ b/llvm/lib/Target/AVR/AVRISelLowering.cpp
@@ -1488,8 +1488,7 @@ AVRTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
// Don't emit the ret/reti instruction when the naked attribute is present in
// the function being compiled.
- if (MF.getFunction().getAttributes().hasAttribute(
- AttributeList::FunctionIndex, Attribute::Naked)) {
+ if (MF.getFunction().getAttributes().hasFnAttr(Attribute::Naked)) {
return Chain;
}
diff --git a/llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp b/llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp
index e026bb6d601d0..1941c0f35e5b4 100644
--- a/llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp
@@ -67,12 +67,12 @@ bool HexagonOptimizeSZextends::runOnFunction(Function &F) {
if (skipFunction(F))
return false;
- unsigned Idx = 1;
+ unsigned Idx = 0;
// Try to optimize sign extends in formal parameters. It's relying on
// callee already sign extending the values. I'm not sure if our ABI
// requires callee to sign extend though.
for (auto &Arg : F.args()) {
- if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
+ if (F.getAttributes().hasParamAttr(Idx, Attribute::SExt)) {
if (!isa<PointerType>(Arg.getType())) {
for (auto UI = Arg.use_begin(); UI != Arg.use_end();) {
if (isa<SExtInst>(*UI)) {
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index c40e4f903df58..4495d624e09d1 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -1370,9 +1370,9 @@ bool WebAssemblyFastISel::selectRet(const Instruction *I) {
}
unsigned Reg;
- if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::SExt))
+ if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::SExt))
Reg = getRegForSignedValue(RV);
- else if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::ZExt))
+ else if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::ZExt))
Reg = getRegForUnsignedValue(RV);
else
Reg = getRegForValue(RV);
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 72e9a2b4b29a7..6614978b25d1a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -27235,11 +27235,11 @@ SDValue X86TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
if (!Attrs.isEmpty() && !Func->isVarArg()) {
unsigned InRegCount = 0;
- unsigned Idx = 1;
+ unsigned Idx = 0;
for (FunctionType::param_iterator I = FTy->param_begin(),
E = FTy->param_end(); I != E; ++I, ++Idx)
- if (Attrs.hasAttribute(Idx, Attribute::InReg)) {
+ if (Attrs.hasParamAttr(Idx, Attribute::InReg)) {
const DataLayout &DL = DAG.getDataLayout();
// FIXME: should only count parameters that are lowered to integers.
InRegCount += (DL.getTypeSizeInBits(*I) + 31) / 32;
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index ca8660a98ded8..eae971dd32af7 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1055,8 +1055,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
// pointers.
for (Function *F : SCCNodes) {
// Already nonnull.
- if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
- Attribute::NonNull))
+ if (F->getAttributes().hasRetAttr(Attribute::NonNull))
continue;
// We can infer and propagate function attributes only when we know that the
@@ -1090,8 +1089,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
if (SCCReturnsNonNull) {
for (Function *F : SCCNodes) {
- if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
- Attribute::NonNull) ||
+ if (F->getAttributes().hasRetAttr(Attribute::NonNull) ||
!F->getReturnType()->isPointerTy())
continue;
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 4be07558d42df..77701bf1d0c65 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1533,7 +1533,7 @@ static StringRef getDeoptLowering(CallBase *Call) {
// FIXME: Calls have a *really* confusing interface around attributes
// with values.
const AttributeList &CSAS = Call->getAttributes();
- if (CSAS.hasAttribute(AttributeList::FunctionIndex, DeoptLowering))
+ if (CSAS.hasFnAttr(DeoptLowering))
return CSAS.getAttribute(AttributeList::FunctionIndex, DeoptLowering)
.getValueAsString();
Function *F = Call->getCalledFunction();
diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp
index 30664b1d6fedb..86e7389877266 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -68,7 +68,7 @@ TEST(Attributes, AddAttributes) {
B.clear();
B.addAttribute(Attribute::SExt);
AL = AL.addAttributes(C, AttributeList::ReturnIndex, B);
- EXPECT_TRUE(AL.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt));
+ EXPECT_TRUE(AL.hasRetAttr(Attribute::SExt));
EXPECT_TRUE(AL.hasFnAttr(Attribute::NoReturn));
}
@@ -102,9 +102,9 @@ TEST(Attributes, RemoveAlign) {
AttributeList AL;
AL = AL.addParamAttributes(C, 0, B_align_readonly);
AL = AL.addAttributes(C, 0, B_stackalign_optnone);
- EXPECT_TRUE(AL.hasAttributes(0));
- EXPECT_TRUE(AL.hasAttribute(0, Attribute::StackAlignment));
- EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone));
+ 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.hasParamAttrs(0));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::Alignment));
@@ -114,15 +114,15 @@ TEST(Attributes, RemoveAlign) {
AL = AL.removeParamAttribute(C, 0, Attribute::Alignment);
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
- EXPECT_TRUE(AL.hasAttribute(0, Attribute::StackAlignment));
- EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone));
+ EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
+ EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL.getStackAlignment(0) == 32);
AL = AL.removeAttribute(C, 0, Attribute::StackAlignment);
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
- EXPECT_FALSE(AL.hasAttribute(0, Attribute::StackAlignment));
- EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone));
+ EXPECT_FALSE(AL.hasRetAttr(Attribute::StackAlignment));
+ EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
AttributeList AL2;
AL2 = AL2.addParamAttributes(C, 0, B_align_readonly);
@@ -131,15 +131,15 @@ TEST(Attributes, RemoveAlign) {
AL2 = AL2.removeParamAttributes(C, 0, B_align);
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
- EXPECT_TRUE(AL2.hasAttribute(0, Attribute::StackAlignment));
- EXPECT_TRUE(AL2.hasAttribute(0, Attribute::OptimizeNone));
+ EXPECT_TRUE(AL2.hasRetAttr(Attribute::StackAlignment));
+ EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL2.getStackAlignment(0) == 32);
AL2 = AL2.removeAttributes(C, 0, B_stackalign);
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
- EXPECT_FALSE(AL2.hasAttribute(0, Attribute::StackAlignment));
- EXPECT_TRUE(AL2.hasAttribute(0, Attribute::OptimizeNone));
+ EXPECT_FALSE(AL2.hasRetAttr(Attribute::StackAlignment));
+ EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
}
TEST(Attributes, AddMatchingAlignAttr) {
More information about the llvm-commits
mailing list