Skip to content

Commit d1cf777

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd7593ebaeeec' from llvm.org/main into next
2 parents fd42264 + d7593eb commit d1cf777

File tree

16 files changed

+46
-48
lines changed

16 files changed

+46
-48
lines changed

llvm/include/llvm/IR/Attributes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,14 @@ class AttributeList {
652652
return hasAttributes(ArgNo + FirstArgIndex);
653653
}
654654

655+
/// Return true if the attribute exists for the return value.
656+
bool hasRetAttr(Attribute::AttrKind Kind) const {
657+
return hasAttribute(ReturnIndex, Kind);
658+
}
659+
660+
/// Return true if attributes exists for the return value.
661+
bool hasRetAttrs() const { return hasAttributes(ReturnIndex); }
662+
655663
/// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
656664
/// may be faster.
657665
bool hasFnAttr(Attribute::AttrKind Kind) const;

llvm/include/llvm/IR/Function.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ class Function : public GlobalObject, public ilist_node<Function> {
699699
/// Determine if the parameter or return value is marked with NoAlias
700700
/// attribute.
701701
bool returnDoesNotAlias() const {
702-
return AttributeSets.hasAttribute(AttributeList::ReturnIndex,
703-
Attribute::NoAlias);
702+
return AttributeSets.hasRetAttr(Attribute::NoAlias);
704703
}
705704
void setReturnDoesNotAlias() {
706705
addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ class CallBase : public Instruction {
17601760

17611761
/// Determine if the return value is marked with NoAlias attribute.
17621762
bool returnDoesNotAlias() const {
1763-
return Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
1763+
return Attrs.hasRetAttr(Attribute::NoAlias);
17641764
}
17651765

17661766
/// If one of the arguments has the 'returned' attribute, returns its

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5581,7 +5581,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
55815581
AttributeList::get(Context, AttributeSet::get(Context, FuncAttrs),
55825582
AttributeSet::get(Context, RetAttrs), Attrs);
55835583

5584-
if (PAL.hasAttribute(1, Attribute::StructRet) && !RetType->isVoidTy())
5584+
if (PAL.hasParamAttr(0, Attribute::StructRet) && !RetType->isVoidTy())
55855585
return error(RetTypeLoc, "functions with 'sret' argument must return void");
55865586

55875587
FunctionType *FT = FunctionType::get(RetType, ParamTypeList, IsVarArg);

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ static bool isLibCallInTailPosition(MachineInstr &MI,
497497
return false;
498498

499499
// It's not safe to eliminate the sign / zero extension of the return value.
500-
if (CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt) ||
501-
CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
500+
if (CallerAttrs.hasRetAttr(Attribute::ZExt) ||
501+
CallerAttrs.hasRetAttr(Attribute::SExt))
502502
return false;
503503

504504
// Only tail call if the following instruction is a standard return or if we

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ bool MachinePipeliner::runOnMachineFunction(MachineFunction &mf) {
200200
if (!EnableSWP)
201201
return false;
202202

203-
if (mf.getFunction().getAttributes().hasAttribute(
204-
AttributeList::FunctionIndex, Attribute::OptimizeForSize) &&
203+
if (mf.getFunction().getAttributes().hasFnAttr(Attribute::OptimizeForSize) &&
205204
!EnableSWPOptSize.getPosition())
206205
return false;
207206

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,16 +1967,13 @@ void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
19671967
/*IsVarArg*/ false, DL);
19681968

19691969
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
1970-
if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
1971-
Attribute::SExt))
1970+
if (F->getAttributes().hasRetAttr(Attribute::SExt))
19721971
ExtendKind = ISD::SIGN_EXTEND;
1973-
else if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
1974-
Attribute::ZExt))
1972+
else if (F->getAttributes().hasRetAttr(Attribute::ZExt))
19751973
ExtendKind = ISD::ZERO_EXTEND;
19761974

19771975
LLVMContext &Context = F->getContext();
1978-
bool RetInReg = F->getAttributes().hasAttribute(
1979-
AttributeList::ReturnIndex, Attribute::InReg);
1976+
bool RetInReg = F->getAttributes().hasRetAttr(Attribute::InReg);
19801977

19811978
for (unsigned j = 0; j != NumValues; ++j) {
19821979
EVT VT = ValueVTs[j];

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,9 +1657,9 @@ void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
16571657
EVT VT = ValueVTs[j];
16581658
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
16591659

1660-
if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
1660+
if (attr.hasRetAttr(Attribute::SExt))
16611661
ExtendKind = ISD::SIGN_EXTEND;
1662-
else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
1662+
else if (attr.hasRetAttr(Attribute::ZExt))
16631663
ExtendKind = ISD::ZERO_EXTEND;
16641664

16651665
// FIXME: C calling convention requires the return type to be promoted to
@@ -1679,13 +1679,13 @@ void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
16791679

16801680
// 'inreg' on function refers to return value
16811681
ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
1682-
if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::InReg))
1682+
if (attr.hasRetAttr(Attribute::InReg))
16831683
Flags.setInReg();
16841684

16851685
// Propagate extension type if any
1686-
if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
1686+
if (attr.hasRetAttr(Attribute::SExt))
16871687
Flags.setSExt();
1688-
else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
1688+
else if (attr.hasRetAttr(Attribute::ZExt))
16891689
Flags.setZExt();
16901690

16911691
for (unsigned i = 0; i < NumParts; ++i)

llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,9 @@ bool AArch64CallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
387387
MVT NewVT = TLI.getRegisterTypeForCallingConv(Ctx, CC, SplitEVTs[i]);
388388
if (EVT(NewVT) != SplitEVTs[i]) {
389389
unsigned ExtendOp = TargetOpcode::G_ANYEXT;
390-
if (F.getAttributes().hasAttribute(AttributeList::ReturnIndex,
391-
Attribute::SExt))
390+
if (F.getAttributes().hasRetAttr(Attribute::SExt))
392391
ExtendOp = TargetOpcode::G_SEXT;
393-
else if (F.getAttributes().hasAttribute(AttributeList::ReturnIndex,
394-
Attribute::ZExt))
392+
else if (F.getAttributes().hasRetAttr(Attribute::ZExt))
395393
ExtendOp = TargetOpcode::G_ZEXT;
396394

397395
LLT NewLLT(NewVT);

llvm/lib/Target/AVR/AVRISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,8 +1488,7 @@ AVRTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
14881488

14891489
// Don't emit the ret/reti instruction when the naked attribute is present in
14901490
// the function being compiled.
1491-
if (MF.getFunction().getAttributes().hasAttribute(
1492-
AttributeList::FunctionIndex, Attribute::Naked)) {
1491+
if (MF.getFunction().getAttributes().hasFnAttr(Attribute::Naked)) {
14931492
return Chain;
14941493
}
14951494

llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ bool HexagonOptimizeSZextends::runOnFunction(Function &F) {
6767
if (skipFunction(F))
6868
return false;
6969

70-
unsigned Idx = 1;
70+
unsigned Idx = 0;
7171
// Try to optimize sign extends in formal parameters. It's relying on
7272
// callee already sign extending the values. I'm not sure if our ABI
7373
// requires callee to sign extend though.
7474
for (auto &Arg : F.args()) {
75-
if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
75+
if (F.getAttributes().hasParamAttr(Idx, Attribute::SExt)) {
7676
if (!isa<PointerType>(Arg.getType())) {
7777
for (auto UI = Arg.use_begin(); UI != Arg.use_end();) {
7878
if (isa<SExtInst>(*UI)) {

llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,9 @@ bool WebAssemblyFastISel::selectRet(const Instruction *I) {
13701370
}
13711371

13721372
unsigned Reg;
1373-
if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::SExt))
1373+
if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::SExt))
13741374
Reg = getRegForSignedValue(RV);
1375-
else if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::ZExt))
1375+
else if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::ZExt))
13761376
Reg = getRegForUnsignedValue(RV);
13771377
else
13781378
Reg = getRegForValue(RV);

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27235,11 +27235,11 @@ SDValue X86TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
2723527235

2723627236
if (!Attrs.isEmpty() && !Func->isVarArg()) {
2723727237
unsigned InRegCount = 0;
27238-
unsigned Idx = 1;
27238+
unsigned Idx = 0;
2723927239

2724027240
for (FunctionType::param_iterator I = FTy->param_begin(),
2724127241
E = FTy->param_end(); I != E; ++I, ++Idx)
27242-
if (Attrs.hasAttribute(Idx, Attribute::InReg)) {
27242+
if (Attrs.hasParamAttr(Idx, Attribute::InReg)) {
2724327243
const DataLayout &DL = DAG.getDataLayout();
2724427244
// FIXME: should only count parameters that are lowered to integers.
2724527245
InRegCount += (DL.getTypeSizeInBits(*I) + 31) / 32;

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
10551055
// pointers.
10561056
for (Function *F : SCCNodes) {
10571057
// Already nonnull.
1058-
if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
1059-
Attribute::NonNull))
1058+
if (F->getAttributes().hasRetAttr(Attribute::NonNull))
10601059
continue;
10611060

10621061
// We can infer and propagate function attributes only when we know that the
@@ -1090,8 +1089,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
10901089

10911090
if (SCCReturnsNonNull) {
10921091
for (Function *F : SCCNodes) {
1093-
if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
1094-
Attribute::NonNull) ||
1092+
if (F->getAttributes().hasRetAttr(Attribute::NonNull) ||
10951093
!F->getReturnType()->isPointerTy())
10961094
continue;
10971095

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ static StringRef getDeoptLowering(CallBase *Call) {
15331533
// FIXME: Calls have a *really* confusing interface around attributes
15341534
// with values.
15351535
const AttributeList &CSAS = Call->getAttributes();
1536-
if (CSAS.hasAttribute(AttributeList::FunctionIndex, DeoptLowering))
1536+
if (CSAS.hasFnAttr(DeoptLowering))
15371537
return CSAS.getAttribute(AttributeList::FunctionIndex, DeoptLowering)
15381538
.getValueAsString();
15391539
Function *F = Call->getCalledFunction();

llvm/unittests/IR/AttributesTest.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ TEST(Attributes, AddAttributes) {
6868
B.clear();
6969
B.addAttribute(Attribute::SExt);
7070
AL = AL.addAttributes(C, AttributeList::ReturnIndex, B);
71-
EXPECT_TRUE(AL.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt));
71+
EXPECT_TRUE(AL.hasRetAttr(Attribute::SExt));
7272
EXPECT_TRUE(AL.hasFnAttr(Attribute::NoReturn));
7373
}
7474

@@ -102,9 +102,9 @@ TEST(Attributes, RemoveAlign) {
102102
AttributeList AL;
103103
AL = AL.addParamAttributes(C, 0, B_align_readonly);
104104
AL = AL.addAttributes(C, 0, B_stackalign_optnone);
105-
EXPECT_TRUE(AL.hasAttributes(0));
106-
EXPECT_TRUE(AL.hasAttribute(0, Attribute::StackAlignment));
107-
EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone));
105+
EXPECT_TRUE(AL.hasRetAttrs());
106+
EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
107+
EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
108108
EXPECT_TRUE(AL.getStackAlignment(0) == 32);
109109
EXPECT_TRUE(AL.hasParamAttrs(0));
110110
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::Alignment));
@@ -114,15 +114,15 @@ TEST(Attributes, RemoveAlign) {
114114
AL = AL.removeParamAttribute(C, 0, Attribute::Alignment);
115115
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
116116
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
117-
EXPECT_TRUE(AL.hasAttribute(0, Attribute::StackAlignment));
118-
EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone));
117+
EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
118+
EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
119119
EXPECT_TRUE(AL.getStackAlignment(0) == 32);
120120

121121
AL = AL.removeAttribute(C, 0, Attribute::StackAlignment);
122122
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
123123
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
124-
EXPECT_FALSE(AL.hasAttribute(0, Attribute::StackAlignment));
125-
EXPECT_TRUE(AL.hasAttribute(0, Attribute::OptimizeNone));
124+
EXPECT_FALSE(AL.hasRetAttr(Attribute::StackAlignment));
125+
EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
126126

127127
AttributeList AL2;
128128
AL2 = AL2.addParamAttributes(C, 0, B_align_readonly);
@@ -131,15 +131,15 @@ TEST(Attributes, RemoveAlign) {
131131
AL2 = AL2.removeParamAttributes(C, 0, B_align);
132132
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
133133
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
134-
EXPECT_TRUE(AL2.hasAttribute(0, Attribute::StackAlignment));
135-
EXPECT_TRUE(AL2.hasAttribute(0, Attribute::OptimizeNone));
134+
EXPECT_TRUE(AL2.hasRetAttr(Attribute::StackAlignment));
135+
EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
136136
EXPECT_TRUE(AL2.getStackAlignment(0) == 32);
137137

138138
AL2 = AL2.removeAttributes(C, 0, B_stackalign);
139139
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
140140
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
141-
EXPECT_FALSE(AL2.hasAttribute(0, Attribute::StackAlignment));
142-
EXPECT_TRUE(AL2.hasAttribute(0, Attribute::OptimizeNone));
141+
EXPECT_FALSE(AL2.hasRetAttr(Attribute::StackAlignment));
142+
EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
143143
}
144144

145145
TEST(Attributes, AddMatchingAlignAttr) {

0 commit comments

Comments
 (0)