@@ -30,34 +30,51 @@ using namespace llvm;
30
30
31
31
void CallLowering::anchor () {}
32
32
33
- ISD::ArgFlagsTy CallLowering::getAttributesForArgIdx (const CallBase &Call,
34
- unsigned ArgIdx) const {
35
- ISD::ArgFlagsTy Flags;
36
- if (Call.paramHasAttr (ArgIdx, Attribute::SExt))
33
+ // / Helper function which updates \p Flags when \p AttrFn returns true.
34
+ static void
35
+ addFlagsUsingAttrFn (ISD::ArgFlagsTy &Flags,
36
+ const std::function<bool (Attribute::AttrKind)> &AttrFn) {
37
+ if (AttrFn (Attribute::SExt))
37
38
Flags.setSExt ();
38
- if (Call. paramHasAttr (ArgIdx, Attribute::ZExt))
39
+ if (AttrFn ( Attribute::ZExt))
39
40
Flags.setZExt ();
40
- if (Call. paramHasAttr (ArgIdx, Attribute::InReg))
41
+ if (AttrFn ( Attribute::InReg))
41
42
Flags.setInReg ();
42
- if (Call. paramHasAttr (ArgIdx, Attribute::StructRet))
43
+ if (AttrFn ( Attribute::StructRet))
43
44
Flags.setSRet ();
44
- if (Call. paramHasAttr (ArgIdx, Attribute::Nest))
45
+ if (AttrFn ( Attribute::Nest))
45
46
Flags.setNest ();
46
- if (Call. paramHasAttr (ArgIdx, Attribute::ByVal))
47
+ if (AttrFn ( Attribute::ByVal))
47
48
Flags.setByVal ();
48
- if (Call. paramHasAttr (ArgIdx, Attribute::Preallocated))
49
+ if (AttrFn ( Attribute::Preallocated))
49
50
Flags.setPreallocated ();
50
- if (Call. paramHasAttr (ArgIdx, Attribute::InAlloca))
51
+ if (AttrFn ( Attribute::InAlloca))
51
52
Flags.setInAlloca ();
52
- if (Call. paramHasAttr (ArgIdx, Attribute::Returned))
53
+ if (AttrFn ( Attribute::Returned))
53
54
Flags.setReturned ();
54
- if (Call. paramHasAttr (ArgIdx, Attribute::SwiftSelf))
55
+ if (AttrFn ( Attribute::SwiftSelf))
55
56
Flags.setSwiftSelf ();
56
- if (Call. paramHasAttr (ArgIdx, Attribute::SwiftError))
57
+ if (AttrFn ( Attribute::SwiftError))
57
58
Flags.setSwiftError ();
59
+ }
60
+
61
+ ISD::ArgFlagsTy CallLowering::getAttributesForArgIdx (const CallBase &Call,
62
+ unsigned ArgIdx) const {
63
+ ISD::ArgFlagsTy Flags;
64
+ addFlagsUsingAttrFn (Flags, [&Call, &ArgIdx](Attribute::AttrKind Attr) {
65
+ return Call.paramHasAttr (ArgIdx, Attr);
66
+ });
58
67
return Flags;
59
68
}
60
69
70
+ void CallLowering::addArgFlagsFromAttributes (ISD::ArgFlagsTy &Flags,
71
+ const AttributeList &Attrs,
72
+ unsigned OpIdx) const {
73
+ addFlagsUsingAttrFn (Flags, [&Attrs, &OpIdx](Attribute::AttrKind Attr) {
74
+ return Attrs.hasAttribute (OpIdx, Attr);
75
+ });
76
+ }
77
+
61
78
bool CallLowering::lowerCall (MachineIRBuilder &MIRBuilder, const CallBase &CB,
62
79
ArrayRef<Register> ResRegs,
63
80
ArrayRef<ArrayRef<Register>> ArgRegs,
@@ -118,24 +135,7 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
118
135
const FuncInfoTy &FuncInfo) const {
119
136
auto &Flags = Arg.Flags [0 ];
120
137
const AttributeList &Attrs = FuncInfo.getAttributes ();
121
- if (Attrs.hasAttribute (OpIdx, Attribute::ZExt))
122
- Flags.setZExt ();
123
- if (Attrs.hasAttribute (OpIdx, Attribute::SExt))
124
- Flags.setSExt ();
125
- if (Attrs.hasAttribute (OpIdx, Attribute::InReg))
126
- Flags.setInReg ();
127
- if (Attrs.hasAttribute (OpIdx, Attribute::StructRet))
128
- Flags.setSRet ();
129
- if (Attrs.hasAttribute (OpIdx, Attribute::SwiftSelf))
130
- Flags.setSwiftSelf ();
131
- if (Attrs.hasAttribute (OpIdx, Attribute::SwiftError))
132
- Flags.setSwiftError ();
133
- if (Attrs.hasAttribute (OpIdx, Attribute::ByVal))
134
- Flags.setByVal ();
135
- if (Attrs.hasAttribute (OpIdx, Attribute::Preallocated))
136
- Flags.setPreallocated ();
137
- if (Attrs.hasAttribute (OpIdx, Attribute::InAlloca))
138
- Flags.setInAlloca ();
138
+ addArgFlagsFromAttributes (Flags, Attrs, OpIdx);
139
139
140
140
if (Flags.isByVal () || Flags.isInAlloca () || Flags.isPreallocated ()) {
141
141
Type *ElementTy = cast<PointerType>(Arg.Ty )->getElementType ();
@@ -152,8 +152,6 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
152
152
FrameAlign = Align (getTLI ()->getByValTypeAlignment (ElementTy, DL));
153
153
Flags.setByValAlign (FrameAlign);
154
154
}
155
- if (Attrs.hasAttribute (OpIdx, Attribute::Nest))
156
- Flags.setNest ();
157
155
Flags.setOrigAlign (DL.getABITypeAlign (Arg.Ty ));
158
156
}
159
157
0 commit comments