diff options
author | Owen Anderson <resistor@mac.com> | 2015-03-08 21:53:59 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2015-03-08 21:53:59 +0000 |
commit | 7e621e9d5e011a50b4e0917ef0b6367c44567a90 (patch) | |
tree | 7dee93d2fe8729ff2c5f2f7c388305e87fa0be43 /llvm/lib/IR/DataLayout.cpp | |
parent | f4af99bc6a1d15664d5412b90d4ebc6f2ff032af (diff) | |
download | bcm5719-llvm-7e621e9d5e011a50b4e0917ef0b6367c44567a90.tar.gz bcm5719-llvm-7e621e9d5e011a50b4e0917ef0b6367c44567a90.zip |
Teach DataLayout to infer a plausible alignment for things even when nothing is specified by the user.
llvm-svn: 231613
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index c70d7c68a91..5dcb5fbf490 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -479,9 +479,7 @@ unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType, // If we didn't find an integer alignment, fall back on most conservative. if (AlignType == INTEGER_ALIGN) { BestMatchIdx = LargestInt; - } else { - assert(AlignType == VECTOR_ALIGN && "Unknown alignment type!"); - + } else if (AlignType == VECTOR_ALIGN) { // By default, use natural alignment for vector types. This is consistent // with what clang and llvm-gcc do. unsigned Align = getTypeAllocSize(cast<VectorType>(Ty)->getElementType()); @@ -494,6 +492,19 @@ unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType, } } + // If we still couldn't find a reasonable default alignment, fall back + // to a simple heuristic that the alignment is the first power of two + // greater-or-equal to the store size of the type. This is a reasonable + // approximation of reality, and if the user wanted something less + // less conservative, they should have specified it explicitly in the data + // layout. + if (BestMatchIdx == -1) { + unsigned Align = getTypeStoreSize(Ty); + if (Align & (Align-1)) + Align = NextPowerOf2(Align); + return Align; + } + // Since we got a "best match" index, just return it. return ABIInfo ? Alignments[BestMatchIdx].ABIAlign : Alignments[BestMatchIdx].PrefAlign; |