aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-27 18:08:34 +0000
committerChris Lattner <sabre@nondot.org>2009-01-27 18:08:34 +0000
commit34ebde404dc17d89487b07e6daaf1b47d5dfee39 (patch)
tree22d6ba8575374c17d600a151846a5cc6ada81551 /lib
parent12444a24419fe88b42a16b46106db3c11ac5cd35 (diff)
add a new "getPreferredTypeAlign" method to return the preferred alignment
of a type. The implementation is currently something of a hack, but is sufficient for now and allows clients to be built on it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 2662860af2..e7c08e2da3 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -453,6 +453,22 @@ ASTContext::getTypeInfo(const Type *T) {
return std::make_pair(Width, Align);
}
+/// getPreferredTypeAlign - Return the "preferred" alignment of the specified
+/// type for the current target in bits. This can be different than the ABI
+/// alignment in cases where it is beneficial for performance to overalign
+/// a data type.
+unsigned ASTContext::getPreferredTypeAlign(const Type *T) {
+ unsigned ABIAlign = getTypeAlign(T);
+
+ // Doubles should be naturally aligned if possible.
+ if (const BuiltinType *BT = dyn_cast<BuiltinType>(getCanonicalType(T)))
+ if (BT->getKind() == BuiltinType::Double)
+ return std::max(ABIAlign, 8U);
+
+ return ABIAlign;
+}
+
+
/// LayoutField - Field layout.
void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo,
bool IsUnion, unsigned StructPacking,