[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.
This commit is contained in:
Arthur Eubanks 2021-08-13 11:59:18 -07:00
parent a9831cce1e
commit d7593ebaee
16 changed files with 46 additions and 48 deletions

View File

@ -652,6 +652,14 @@ public:
return hasAttributes(ArgNo + FirstArgIndex); 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 /// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
/// may be faster. /// may be faster.
bool hasFnAttr(Attribute::AttrKind Kind) const; bool hasFnAttr(Attribute::AttrKind Kind) const;

View File

@ -699,8 +699,7 @@ public:
/// Determine if the parameter or return value is marked with NoAlias /// Determine if the parameter or return value is marked with NoAlias
/// attribute. /// attribute.
bool returnDoesNotAlias() const { bool returnDoesNotAlias() const {
return AttributeSets.hasAttribute(AttributeList::ReturnIndex, return AttributeSets.hasRetAttr(Attribute::NoAlias);
Attribute::NoAlias);
} }
void setReturnDoesNotAlias() { void setReturnDoesNotAlias() {
addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);

View File

@ -1760,7 +1760,7 @@ public:
/// Determine if the return value is marked with NoAlias attribute. /// Determine if the return value is marked with NoAlias attribute.
bool returnDoesNotAlias() const { 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 /// If one of the arguments has the 'returned' attribute, returns its

View File

@ -5571,7 +5571,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
AttributeList::get(Context, AttributeSet::get(Context, FuncAttrs), AttributeList::get(Context, AttributeSet::get(Context, FuncAttrs),
AttributeSet::get(Context, RetAttrs), Attrs); 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"); return error(RetTypeLoc, "functions with 'sret' argument must return void");
FunctionType *FT = FunctionType::get(RetType, ParamTypeList, IsVarArg); FunctionType *FT = FunctionType::get(RetType, ParamTypeList, IsVarArg);

View File

@ -497,8 +497,8 @@ static bool isLibCallInTailPosition(MachineInstr &MI,
return false; return false;
// It's not safe to eliminate the sign / zero extension of the return value. // It's not safe to eliminate the sign / zero extension of the return value.
if (CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt) || if (CallerAttrs.hasRetAttr(Attribute::ZExt) ||
CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt)) CallerAttrs.hasRetAttr(Attribute::SExt))
return false; return false;
// Only tail call if the following instruction is a standard return or if we // Only tail call if the following instruction is a standard return or if we

View File

@ -200,8 +200,7 @@ bool MachinePipeliner::runOnMachineFunction(MachineFunction &mf) {
if (!EnableSWP) if (!EnableSWP)
return false; return false;
if (mf.getFunction().getAttributes().hasAttribute( if (mf.getFunction().getAttributes().hasFnAttr(Attribute::OptimizeForSize) &&
AttributeList::FunctionIndex, Attribute::OptimizeForSize) &&
!EnableSWPOptSize.getPosition()) !EnableSWPOptSize.getPosition())
return false; return false;

View File

@ -1953,16 +1953,13 @@ void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
/*IsVarArg*/ false, DL); /*IsVarArg*/ false, DL);
ISD::NodeType ExtendKind = ISD::ANY_EXTEND; ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex, if (F->getAttributes().hasRetAttr(Attribute::SExt))
Attribute::SExt))
ExtendKind = ISD::SIGN_EXTEND; ExtendKind = ISD::SIGN_EXTEND;
else if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex, else if (F->getAttributes().hasRetAttr(Attribute::ZExt))
Attribute::ZExt))
ExtendKind = ISD::ZERO_EXTEND; ExtendKind = ISD::ZERO_EXTEND;
LLVMContext &Context = F->getContext(); LLVMContext &Context = F->getContext();
bool RetInReg = F->getAttributes().hasAttribute( bool RetInReg = F->getAttributes().hasRetAttr(Attribute::InReg);
AttributeList::ReturnIndex, Attribute::InReg);
for (unsigned j = 0; j != NumValues; ++j) { for (unsigned j = 0; j != NumValues; ++j) {
EVT VT = ValueVTs[j]; EVT VT = ValueVTs[j];

View File

@ -1657,9 +1657,9 @@ void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
EVT VT = ValueVTs[j]; EVT VT = ValueVTs[j];
ISD::NodeType ExtendKind = ISD::ANY_EXTEND; ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt)) if (attr.hasRetAttr(Attribute::SExt))
ExtendKind = ISD::SIGN_EXTEND; ExtendKind = ISD::SIGN_EXTEND;
else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt)) else if (attr.hasRetAttr(Attribute::ZExt))
ExtendKind = ISD::ZERO_EXTEND; ExtendKind = ISD::ZERO_EXTEND;
// FIXME: C calling convention requires the return type to be promoted to // 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 // 'inreg' on function refers to return value
ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy(); ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::InReg)) if (attr.hasRetAttr(Attribute::InReg))
Flags.setInReg(); Flags.setInReg();
// Propagate extension type if any // Propagate extension type if any
if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt)) if (attr.hasRetAttr(Attribute::SExt))
Flags.setSExt(); Flags.setSExt();
else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt)) else if (attr.hasRetAttr(Attribute::ZExt))
Flags.setZExt(); Flags.setZExt();
for (unsigned i = 0; i < NumParts; ++i) for (unsigned i = 0; i < NumParts; ++i)

View File

@ -387,11 +387,9 @@ bool AArch64CallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
MVT NewVT = TLI.getRegisterTypeForCallingConv(Ctx, CC, SplitEVTs[i]); MVT NewVT = TLI.getRegisterTypeForCallingConv(Ctx, CC, SplitEVTs[i]);
if (EVT(NewVT) != SplitEVTs[i]) { if (EVT(NewVT) != SplitEVTs[i]) {
unsigned ExtendOp = TargetOpcode::G_ANYEXT; unsigned ExtendOp = TargetOpcode::G_ANYEXT;
if (F.getAttributes().hasAttribute(AttributeList::ReturnIndex, if (F.getAttributes().hasRetAttr(Attribute::SExt))
Attribute::SExt))
ExtendOp = TargetOpcode::G_SEXT; ExtendOp = TargetOpcode::G_SEXT;
else if (F.getAttributes().hasAttribute(AttributeList::ReturnIndex, else if (F.getAttributes().hasRetAttr(Attribute::ZExt))
Attribute::ZExt))
ExtendOp = TargetOpcode::G_ZEXT; ExtendOp = TargetOpcode::G_ZEXT;
LLT NewLLT(NewVT); LLT NewLLT(NewVT);

View File

@ -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 // Don't emit the ret/reti instruction when the naked attribute is present in
// the function being compiled. // the function being compiled.
if (MF.getFunction().getAttributes().hasAttribute( if (MF.getFunction().getAttributes().hasFnAttr(Attribute::Naked)) {
AttributeList::FunctionIndex, Attribute::Naked)) {
return Chain; return Chain;
} }

View File

@ -67,12 +67,12 @@ bool HexagonOptimizeSZextends::runOnFunction(Function &F) {
if (skipFunction(F)) if (skipFunction(F))
return false; return false;
unsigned Idx = 1; unsigned Idx = 0;
// Try to optimize sign extends in formal parameters. It's relying on // 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 // callee already sign extending the values. I'm not sure if our ABI
// requires callee to sign extend though. // requires callee to sign extend though.
for (auto &Arg : F.args()) { for (auto &Arg : F.args()) {
if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) { if (F.getAttributes().hasParamAttr(Idx, Attribute::SExt)) {
if (!isa<PointerType>(Arg.getType())) { if (!isa<PointerType>(Arg.getType())) {
for (auto UI = Arg.use_begin(); UI != Arg.use_end();) { for (auto UI = Arg.use_begin(); UI != Arg.use_end();) {
if (isa<SExtInst>(*UI)) { if (isa<SExtInst>(*UI)) {

View File

@ -1370,9 +1370,9 @@ bool WebAssemblyFastISel::selectRet(const Instruction *I) {
} }
unsigned Reg; unsigned Reg;
if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::SExt)) if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::SExt))
Reg = getRegForSignedValue(RV); Reg = getRegForSignedValue(RV);
else if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::ZExt)) else if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::ZExt))
Reg = getRegForUnsignedValue(RV); Reg = getRegForUnsignedValue(RV);
else else
Reg = getRegForValue(RV); Reg = getRegForValue(RV);

View File

@ -27235,11 +27235,11 @@ SDValue X86TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
if (!Attrs.isEmpty() && !Func->isVarArg()) { if (!Attrs.isEmpty() && !Func->isVarArg()) {
unsigned InRegCount = 0; unsigned InRegCount = 0;
unsigned Idx = 1; unsigned Idx = 0;
for (FunctionType::param_iterator I = FTy->param_begin(), for (FunctionType::param_iterator I = FTy->param_begin(),
E = FTy->param_end(); I != E; ++I, ++Idx) 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(); const DataLayout &DL = DAG.getDataLayout();
// FIXME: should only count parameters that are lowered to integers. // FIXME: should only count parameters that are lowered to integers.
InRegCount += (DL.getTypeSizeInBits(*I) + 31) / 32; InRegCount += (DL.getTypeSizeInBits(*I) + 31) / 32;

View File

@ -1055,8 +1055,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
// pointers. // pointers.
for (Function *F : SCCNodes) { for (Function *F : SCCNodes) {
// Already nonnull. // Already nonnull.
if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex, if (F->getAttributes().hasRetAttr(Attribute::NonNull))
Attribute::NonNull))
continue; continue;
// We can infer and propagate function attributes only when we know that the // 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) { if (SCCReturnsNonNull) {
for (Function *F : SCCNodes) { for (Function *F : SCCNodes) {
if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex, if (F->getAttributes().hasRetAttr(Attribute::NonNull) ||
Attribute::NonNull) ||
!F->getReturnType()->isPointerTy()) !F->getReturnType()->isPointerTy())
continue; continue;

View File

@ -1533,7 +1533,7 @@ static StringRef getDeoptLowering(CallBase *Call) {
// FIXME: Calls have a *really* confusing interface around attributes // FIXME: Calls have a *really* confusing interface around attributes
// with values. // with values.
const AttributeList &CSAS = Call->getAttributes(); const AttributeList &CSAS = Call->getAttributes();
if (CSAS.hasAttribute(AttributeList::FunctionIndex, DeoptLowering)) if (CSAS.hasFnAttr(DeoptLowering))
return CSAS.getAttribute(AttributeList::FunctionIndex, DeoptLowering) return CSAS.getAttribute(AttributeList::FunctionIndex, DeoptLowering)
.getValueAsString(); .getValueAsString();
Function *F = Call->getCalledFunction(); Function *F = Call->getCalledFunction();

View File

@ -68,7 +68,7 @@ TEST(Attributes, AddAttributes) {
B.clear(); B.clear();
B.addAttribute(Attribute::SExt); B.addAttribute(Attribute::SExt);
AL = AL.addAttributes(C, AttributeList::ReturnIndex, B); 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)); EXPECT_TRUE(AL.hasFnAttr(Attribute::NoReturn));
} }
@ -102,9 +102,9 @@ TEST(Attributes, RemoveAlign) {
AttributeList AL; AttributeList AL;
AL = AL.addParamAttributes(C, 0, B_align_readonly); AL = AL.addParamAttributes(C, 0, B_align_readonly);
AL = AL.addAttributes(C, 0, B_stackalign_optnone); AL = AL.addAttributes(C, 0, B_stackalign_optnone);
EXPECT_TRUE(AL.hasAttributes(0)); EXPECT_TRUE(AL.hasRetAttrs());
EXPECT_TRUE(AL.hasAttribute(0, Attribute::StackAlignment)); EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone)); EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL.getStackAlignment(0) == 32); EXPECT_TRUE(AL.getStackAlignment(0) == 32);
EXPECT_TRUE(AL.hasParamAttrs(0)); EXPECT_TRUE(AL.hasParamAttrs(0));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::Alignment)); EXPECT_TRUE(AL.hasParamAttr(0, Attribute::Alignment));
@ -114,15 +114,15 @@ TEST(Attributes, RemoveAlign) {
AL = AL.removeParamAttribute(C, 0, Attribute::Alignment); AL = AL.removeParamAttribute(C, 0, Attribute::Alignment);
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment)); EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly)); EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
EXPECT_TRUE(AL.hasAttribute(0, Attribute::StackAlignment)); EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone)); EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL.getStackAlignment(0) == 32); EXPECT_TRUE(AL.getStackAlignment(0) == 32);
AL = AL.removeAttribute(C, 0, Attribute::StackAlignment); AL = AL.removeAttribute(C, 0, Attribute::StackAlignment);
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment)); EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly)); EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
EXPECT_FALSE(AL.hasAttribute(0, Attribute::StackAlignment)); EXPECT_FALSE(AL.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone)); EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
AttributeList AL2; AttributeList AL2;
AL2 = AL2.addParamAttributes(C, 0, B_align_readonly); AL2 = AL2.addParamAttributes(C, 0, B_align_readonly);
@ -131,15 +131,15 @@ TEST(Attributes, RemoveAlign) {
AL2 = AL2.removeParamAttributes(C, 0, B_align); AL2 = AL2.removeParamAttributes(C, 0, B_align);
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment)); EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly)); EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
EXPECT_TRUE(AL2.hasAttribute(0, Attribute::StackAlignment)); EXPECT_TRUE(AL2.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL2.hasAttribute(0, Attribute::OptimizeNone)); EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL2.getStackAlignment(0) == 32); EXPECT_TRUE(AL2.getStackAlignment(0) == 32);
AL2 = AL2.removeAttributes(C, 0, B_stackalign); AL2 = AL2.removeAttributes(C, 0, B_stackalign);
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment)); EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly)); EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
EXPECT_FALSE(AL2.hasAttribute(0, Attribute::StackAlignment)); EXPECT_FALSE(AL2.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL2.hasAttribute(0, Attribute::OptimizeNone)); EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
} }
TEST(Attributes, AddMatchingAlignAttr) { TEST(Attributes, AddMatchingAlignAttr) {