diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/ASTContext.h | 10 | ||||
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 16 | 
2 files changed, 24 insertions, 2 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 684feb24025..a01199d4b2a 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -394,8 +394,8 @@ public:      return getTypeInfo(T).first;    } -  /// getTypeAlign - Return the alignment of the specified type, in bits.  This -  /// method does not work on incomplete types. +  /// getTypeAlign - Return the ABI-specified alignment of a type, in bits. +  /// This method does not work on incomplete types.    unsigned getTypeAlign(QualType T) {      return getTypeInfo(T).second;    } @@ -403,6 +403,12 @@ public:      return getTypeInfo(T).second;    } +  /// 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 getPreferredTypeAlign(const Type *T); +      /// getDeclAlign - Return the alignment of the specified decl that should be    /// returned by __alignof().  Note that bitfields do not have a valid    /// alignment, so this method will assert on them. 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,  | 

