Skip to content

Commit 3e1ebd7

Browse files
authored
[GlobalISel] Add support for lowering byref attribute
Reviewers: nikic, spaits, arsenm Reviewed By: arsenm Pull Request: #96733
1 parent 5861145 commit 3e1ebd7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

llvm/lib/CodeGen/GlobalISel/CallLowering.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ addFlagsUsingAttrFn(ISD::ArgFlagsTy &Flags,
4949
Flags.setNest();
5050
if (AttrFn(Attribute::ByVal))
5151
Flags.setByVal();
52+
if (AttrFn(Attribute::ByRef))
53+
Flags.setByRef();
5254
if (AttrFn(Attribute::Preallocated))
5355
Flags.setPreallocated();
5456
if (AttrFn(Attribute::InAlloca))
@@ -221,17 +223,26 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
221223
}
222224

223225
Align MemAlign = DL.getABITypeAlign(Arg.Ty);
224-
if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated()) {
226+
if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated() ||
227+
Flags.isByRef()) {
225228
assert(OpIdx >= AttributeList::FirstArgIndex);
226229
unsigned ParamIdx = OpIdx - AttributeList::FirstArgIndex;
227230

228231
Type *ElementTy = FuncInfo.getParamByValType(ParamIdx);
232+
if (!ElementTy)
233+
ElementTy = FuncInfo.getParamByRefType(ParamIdx);
229234
if (!ElementTy)
230235
ElementTy = FuncInfo.getParamInAllocaType(ParamIdx);
231236
if (!ElementTy)
232237
ElementTy = FuncInfo.getParamPreallocatedType(ParamIdx);
238+
233239
assert(ElementTy && "Must have byval, inalloca or preallocated type");
234-
Flags.setByValSize(DL.getTypeAllocSize(ElementTy));
240+
241+
uint64_t MemSize = DL.getTypeAllocSize(ElementTy);
242+
if (Flags.isByRef())
243+
Flags.setByRefSize(MemSize);
244+
else
245+
Flags.setByValSize(MemSize);
235246

236247
// For ByVal, alignment should be passed from FE. BE will guess if
237248
// this info is not there but there are cases it cannot get right.

0 commit comments

Comments
 (0)