forked from OSchip/llvm-project
[CallLowering] Support opaque pointers
Always use the byval/inalloca/preallocated type (which is required nowadays), don't fall back on the pointer element type. This requires adding Function::getParamPreallocatedType() to mirror the CallBase API, so that the templated code can work with both.
This commit is contained in:
parent
d34d2bbe5d
commit
14afbe9448
|
@ -478,6 +478,11 @@ public:
|
|||
return AttributeSets.getParamByRefType(ArgNo);
|
||||
}
|
||||
|
||||
/// Extract the preallocated type for a parameter.
|
||||
Type *getParamPreallocatedType(unsigned ArgNo) const {
|
||||
return AttributeSets.getParamPreallocatedType(ArgNo);
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable bytes for a parameter.
|
||||
/// @param ArgNo Index of an argument, with 0 being the first function arg.
|
||||
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
|
||||
|
|
|
@ -166,19 +166,21 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
|
|||
Align MemAlign = DL.getABITypeAlign(Arg.Ty);
|
||||
if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated()) {
|
||||
assert(OpIdx >= AttributeList::FirstArgIndex);
|
||||
Type *ElementTy = PtrTy->getElementType();
|
||||
unsigned ParamIdx = OpIdx - AttributeList::FirstArgIndex;
|
||||
|
||||
auto Ty =
|
||||
Attrs.getAttributeAtIndex(OpIdx, Attribute::ByVal).getValueAsType();
|
||||
Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : ElementTy));
|
||||
Type *ElementTy = FuncInfo.getParamByValType(ParamIdx);
|
||||
if (!ElementTy)
|
||||
ElementTy = FuncInfo.getParamInAllocaType(ParamIdx);
|
||||
if (!ElementTy)
|
||||
ElementTy = FuncInfo.getParamPreallocatedType(ParamIdx);
|
||||
assert(ElementTy && "Must have byval, inalloca or preallocated type");
|
||||
Flags.setByValSize(DL.getTypeAllocSize(ElementTy));
|
||||
|
||||
// For ByVal, alignment should be passed from FE. BE will guess if
|
||||
// this info is not there but there are cases it cannot get right.
|
||||
if (auto ParamAlign =
|
||||
FuncInfo.getParamStackAlign(OpIdx - AttributeList::FirstArgIndex))
|
||||
if (auto ParamAlign = FuncInfo.getParamStackAlign(ParamIdx))
|
||||
MemAlign = *ParamAlign;
|
||||
else if ((ParamAlign =
|
||||
FuncInfo.getParamAlign(OpIdx - AttributeList::FirstArgIndex)))
|
||||
else if ((ParamAlign = FuncInfo.getParamAlign(ParamIdx)))
|
||||
MemAlign = *ParamAlign;
|
||||
else
|
||||
MemAlign = Align(getTLI()->getByValTypeAlignment(ElementTy, DL));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: llc -global-isel -mtriple=aarch64-unknown-unknown -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s
|
||||
; RUN: llc -global-isel -mtriple=aarch64-unknown-unknown -stop-after=irtranslator -verify-machineinstrs -opaque-pointers %s -o - | FileCheck %s
|
||||
|
||||
; The byval object should not be immutable, but the non-byval stack
|
||||
; passed argument should be.
|
||||
|
|
Loading…
Reference in New Issue