forked from OSchip/llvm-project
simplify some code, ensure that packed structures get abi alignment of 1.
llvm-svn: 34352
This commit is contained in:
parent
8091f28d1a
commit
f9122c4512
|
|
@ -442,8 +442,7 @@ uint64_t TargetData::getTypeSizeInBits(const Type *Ty) const {
|
||||||
Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
|
Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
|
||||||
== false) for the requested type \a Ty.
|
== false) for the requested type \a Ty.
|
||||||
*/
|
*/
|
||||||
unsigned char TargetData::getAlignment(const Type *Ty, bool abi_or_pref) const
|
unsigned char TargetData::getAlignment(const Type *Ty, bool abi_or_pref) const {
|
||||||
{
|
|
||||||
int AlignType = -1;
|
int AlignType = -1;
|
||||||
|
|
||||||
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
|
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
|
||||||
|
|
@ -454,27 +453,21 @@ unsigned char TargetData::getAlignment(const Type *Ty, bool abi_or_pref) const
|
||||||
return (abi_or_pref
|
return (abi_or_pref
|
||||||
? getPointerABIAlignment()
|
? getPointerABIAlignment()
|
||||||
: getPointerPrefAlignment());
|
: getPointerPrefAlignment());
|
||||||
case Type::ArrayTyID: {
|
case Type::ArrayTyID:
|
||||||
const ArrayType *ATy = cast<ArrayType>(Ty);
|
return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
|
||||||
return (abi_or_pref
|
|
||||||
? getABITypeAlignment(ATy->getElementType())
|
|
||||||
: getPrefTypeAlignment(ATy->getElementType()));
|
|
||||||
}
|
|
||||||
case Type::StructTyID: {
|
case Type::StructTyID: {
|
||||||
// Get the layout annotation... which is lazily created on demand.
|
// Packed structure types always have an ABI alignment of one.
|
||||||
|
if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// Get the layout annotation... which is lazily created on demand.
|
||||||
const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
|
const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
|
||||||
const TargetAlignElem &elem = getAlignment(AGGREGATE_ALIGN, 0);
|
const TargetAlignElem &elem = getAlignment(AGGREGATE_ALIGN, 0);
|
||||||
assert(validAlignment(elem)
|
assert(validAlignment(elem)
|
||||||
&& "Aggregate alignment return invalid in getAlignment");
|
&& "Aggregate alignment return invalid in getAlignment");
|
||||||
if (abi_or_pref) {
|
unsigned Align = abi_or_pref ? elem.ABIAlign : elem.PrefAlign;
|
||||||
return (elem.ABIAlign < Layout->getAlignment()
|
return Align < Layout->getAlignment() ? Layout->StructAlignment : Align;
|
||||||
? Layout->StructAlignment
|
|
||||||
: elem.ABIAlign);
|
|
||||||
} else {
|
|
||||||
return (elem.PrefAlign < Layout->getAlignment()
|
|
||||||
? Layout->StructAlignment
|
|
||||||
: elem.PrefAlign);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case Type::IntegerTyID:
|
case Type::IntegerTyID:
|
||||||
case Type::VoidTyID:
|
case Type::VoidTyID:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue