forked from OSchip/llvm-project
Insert padding before unaligned long double arguments.
llvm-svn: 147791
This commit is contained in:
parent
01a82d1918
commit
1632af603d
|
@ -3042,6 +3042,7 @@ class MipsABIInfo : public ABIInfo {
|
|||
unsigned MinABIStackAlignInBytes;
|
||||
llvm::Type* HandleStructTy(QualType Ty) const;
|
||||
llvm::Type* returnAggregateInRegs(QualType RetTy, uint64_t Size) const;
|
||||
llvm::Type* getPaddingType(uint64_t Align, uint64_t Offset) const;
|
||||
public:
|
||||
MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) :
|
||||
ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8) {}
|
||||
|
@ -3132,18 +3133,34 @@ llvm::Type* MipsABIInfo::HandleStructTy(QualType Ty) const {
|
|||
return llvm::StructType::get(getVMContext(), ArgList);
|
||||
}
|
||||
|
||||
llvm::Type *MipsABIInfo::getPaddingType(uint64_t Align, uint64_t Offset) const {
|
||||
// Padding is inserted only for N32/64.
|
||||
if (IsO32)
|
||||
return 0;
|
||||
|
||||
assert(Align <= 16 && "Alignment larger than 16 not handled.");
|
||||
return (Align == 16 && Offset & 0xf) ?
|
||||
llvm::IntegerType::get(getVMContext(), 64) : 0;
|
||||
}
|
||||
|
||||
ABIArgInfo
|
||||
MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {
|
||||
uint64_t OrigOffset = Offset;
|
||||
uint64_t TySize =
|
||||
llvm::RoundUpToAlignment(getContext().getTypeSize(Ty), 64) / 8;
|
||||
uint64_t Align = getContext().getTypeAlign(Ty) / 8;
|
||||
Offset = llvm::RoundUpToAlignment(Offset, std::max(Align, (uint64_t)8));
|
||||
Offset += TySize;
|
||||
|
||||
if (isAggregateTypeForABI(Ty)) {
|
||||
// Ignore empty aggregates.
|
||||
uint64_t TySize = getContext().getTypeSize(Ty);
|
||||
if (TySize == 0)
|
||||
return ABIArgInfo::getIgnore();
|
||||
|
||||
// Records with non trivial destructors/constructors should not be passed
|
||||
// by value.
|
||||
if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) {
|
||||
Offset += 8;
|
||||
Offset = OrigOffset + 8;
|
||||
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
||||
}
|
||||
|
||||
|
@ -3152,23 +3169,21 @@ MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {
|
|||
// latter case, padding is inserted if the offset of the aggregate is
|
||||
// unaligned.
|
||||
llvm::Type *ResType = HandleStructTy(Ty);
|
||||
uint64_t Align = getContext().getTypeAlign(Ty) / 8;
|
||||
assert(Align <= 16 && "Alignment larger than 16 not handled.");
|
||||
llvm::Type *PaddingTy = (ResType && Align == 16 && Offset & 0xf) ?
|
||||
llvm::IntegerType::get(getVMContext(), 64) : 0;
|
||||
Offset = llvm::RoundUpToAlignment(Offset, std::max(Align, (uint64_t)8));
|
||||
Offset += llvm::RoundUpToAlignment(TySize, 8);
|
||||
return ResType ? ABIArgInfo::getDirect(ResType, 0, PaddingTy) :
|
||||
ABIArgInfo::getIndirect(0);
|
||||
|
||||
if (!ResType)
|
||||
return ABIArgInfo::getIndirect(0);
|
||||
|
||||
return ABIArgInfo::getDirect(ResType, 0, getPaddingType(Align, OrigOffset));
|
||||
}
|
||||
|
||||
// Treat an enum type as its underlying type.
|
||||
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
||||
Ty = EnumTy->getDecl()->getIntegerType();
|
||||
|
||||
Offset += 8;
|
||||
return (Ty->isPromotableIntegerType() ?
|
||||
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
||||
if (Ty->isPromotableIntegerType())
|
||||
return ABIArgInfo::getExtend();
|
||||
|
||||
return ABIArgInfo::getDirect(0, 0, getPaddingType(Align, OrigOffset));
|
||||
}
|
||||
|
||||
llvm::Type*
|
||||
|
|
|
@ -5,7 +5,7 @@ typedef struct {
|
|||
long double ld;
|
||||
} S0;
|
||||
|
||||
// Insert padding to ensure arugments of type S0 are aligned to 16-byte boundaries.
|
||||
// Insert padding to ensure arguments of type S0 are aligned to 16-byte boundaries.
|
||||
|
||||
// CHECK: define void @foo1(i32 %a0, i64, double %a1.coerce0, i64 %a1.coerce1, i64 %a1.coerce2, i64 %a1.coerce3, double %a2.coerce0, i64 %a2.coerce1, i64 %a2.coerce2, i64 %a2.coerce3, i32 %b, i64, double %a3.coerce0, i64 %a3.coerce1, i64 %a3.coerce2, i64 %a3.coerce3)
|
||||
// CHECK: tail call void @foo2(i32 1, i32 2, i32 %a0, i64 undef, double %a1.coerce0, i64 %a1.coerce1, i64 %a1.coerce2, i64 %a1.coerce3, double %a2.coerce0, i64 %a2.coerce1, i64 %a2.coerce2, i64 %a2.coerce3, i32 3, i64 undef, double %a3.coerce0, i64 %a3.coerce1, i64 %a3.coerce2, i64 %a3.coerce3)
|
||||
|
@ -17,3 +17,15 @@ void foo1(int a0, S0 a1, S0 a2, int b, S0 a3) {
|
|||
foo2(1, 2, a0, a1, a2, 3, a3);
|
||||
}
|
||||
|
||||
// Insert padding before long double argument.
|
||||
//
|
||||
// CHECK: define void @foo3(i32 %a0, i64, fp128 %a1)
|
||||
// CHECK: tail call void @foo4(i32 1, i32 2, i32 %a0, i64 undef, fp128 %a1)
|
||||
// CHECK: declare void @foo4(i32, i32, i32, i64, fp128)
|
||||
|
||||
extern void foo4(int, int, int, long double);
|
||||
|
||||
void foo3(int a0, long double a1) {
|
||||
foo4(1, 2, a0, a1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue