diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-01-27 18:08:34 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-01-27 18:08:34 +0000 |
| commit | a3402cd52403e07013edf952ce9e70685bcc4ead (patch) | |
| tree | 4838d94c92d34b2468966e4e6c83632a6529c979 /clang/lib/AST | |
| parent | ec39eb851984f5ddcabfcde7cb8e28bf4f442261 (diff) | |
| download | bcm5719-llvm-a3402cd52403e07013edf952ce9e70685bcc4ead.tar.gz bcm5719-llvm-a3402cd52403e07013edf952ce9e70685bcc4ead.zip | |
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.
llvm-svn: 63108
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2662860af2f..e7c08e2da39 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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, |

