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);
|
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.
|
/// Extract the number of dereferenceable bytes for a parameter.
|
||||||
/// @param ArgNo Index of an argument, with 0 being the first function arg.
|
/// @param ArgNo Index of an argument, with 0 being the first function arg.
|
||||||
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
|
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
|
||||||
|
|
|
@ -166,19 +166,21 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
|
||||||
Align MemAlign = DL.getABITypeAlign(Arg.Ty);
|
Align MemAlign = DL.getABITypeAlign(Arg.Ty);
|
||||||
if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated()) {
|
if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated()) {
|
||||||
assert(OpIdx >= AttributeList::FirstArgIndex);
|
assert(OpIdx >= AttributeList::FirstArgIndex);
|
||||||
Type *ElementTy = PtrTy->getElementType();
|
unsigned ParamIdx = OpIdx - AttributeList::FirstArgIndex;
|
||||||
|
|
||||||
auto Ty =
|
Type *ElementTy = FuncInfo.getParamByValType(ParamIdx);
|
||||||
Attrs.getAttributeAtIndex(OpIdx, Attribute::ByVal).getValueAsType();
|
if (!ElementTy)
|
||||||
Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : 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
|
// 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.
|
// this info is not there but there are cases it cannot get right.
|
||||||
if (auto ParamAlign =
|
if (auto ParamAlign = FuncInfo.getParamStackAlign(ParamIdx))
|
||||||
FuncInfo.getParamStackAlign(OpIdx - AttributeList::FirstArgIndex))
|
|
||||||
MemAlign = *ParamAlign;
|
MemAlign = *ParamAlign;
|
||||||
else if ((ParamAlign =
|
else if ((ParamAlign = FuncInfo.getParamAlign(ParamIdx)))
|
||||||
FuncInfo.getParamAlign(OpIdx - AttributeList::FirstArgIndex)))
|
|
||||||
MemAlign = *ParamAlign;
|
MemAlign = *ParamAlign;
|
||||||
else
|
else
|
||||||
MemAlign = Align(getTLI()->getByValTypeAlignment(ElementTy, DL));
|
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 %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
|
; The byval object should not be immutable, but the non-byval stack
|
||||||
; passed argument should be.
|
; passed argument should be.
|
||||||
|
|
Loading…
Reference in New Issue