aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/TargetData.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-16 22:25:34 +0000
committerChris Lattner <sabre@nondot.org>2007-02-16 22:25:34 +0000
commitae6f1fa36b020c89b0f44c4b4222d0f5fd9b6326 (patch)
tree726158e0825536254618e1f35ea20b7294e821f0 /lib/Target/TargetData.cpp
parent3dd074afcb820bbb677967bdd116aee219e07920 (diff)
simplify some code, ensure that packed structures get abi alignment of 1.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r--lib/Target/TargetData.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index 3f9da2bc09..3be2f11e19 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -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
== 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;
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
? getPointerABIAlignment()
: getPointerPrefAlignment());
- case Type::ArrayTyID: {
- const ArrayType *ATy = cast<ArrayType>(Ty);
- return (abi_or_pref
- ? getABITypeAlignment(ATy->getElementType())
- : getPrefTypeAlignment(ATy->getElementType()));
- }
+ case Type::ArrayTyID:
+ return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
+
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 TargetAlignElem &elem = getAlignment(AGGREGATE_ALIGN, 0);
assert(validAlignment(elem)
&& "Aggregate alignment return invalid in getAlignment");
- if (abi_or_pref) {
- return (elem.ABIAlign < Layout->getAlignment()
- ? Layout->StructAlignment
- : elem.ABIAlign);
- } else {
- return (elem.PrefAlign < Layout->getAlignment()
- ? Layout->StructAlignment
- : elem.PrefAlign);
- }
+ unsigned Align = abi_or_pref ? elem.ABIAlign : elem.PrefAlign;
+ return Align < Layout->getAlignment() ? Layout->StructAlignment : Align;
}
case Type::IntegerTyID:
case Type::VoidTyID: