[cfe-commits] r63108 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp

Chris Lattner sabre at nondot.org
Tue Jan 27 10:08:34 PST 2009


Author: lattner
Date: Tue Jan 27 12:08:34 2009
New Revision: 63108

URL: http://llvm.org/viewvc/llvm-project?rev=63108&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=63108&r1=63107&r2=63108&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Jan 27 12:08:34 2009
@@ -394,8 +394,8 @@
     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 @@
     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.

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=63108&r1=63107&r2=63108&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jan 27 12:08:34 2009
@@ -453,6 +453,22 @@
   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,





More information about the cfe-commits mailing list