forked from OSchip/llvm-project
[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:
parent
a9831cce1e
commit
d7593ebaee
|
@ -652,6 +652,14 @@ public:
|
|||
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;
|
||||
|
|
|
@ -699,8 +699,7 @@ public:
|
|||
/// 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);
|
||||
|
|
|
@ -1760,7 +1760,7 @@ public:
|
|||
|
||||
/// 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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue