]> granicus.if.org Git - clang/commitdiff
Introduce CodeGenModule::GetTargetTypeStoreSize() to calculate the store size
authorKen Dyck <ken.dyck@onsemi.com>
Tue, 26 Jan 2010 13:48:07 +0000 (13:48 +0000)
committerKen Dyck <ken.dyck@onsemi.com>
Tue, 26 Jan 2010 13:48:07 +0000 (13:48 +0000)
of LLVM types in character units.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94542 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h

index 72da7d32eb1d1708e48890d3c268e313f4dae8f2..15347a488fa741d3dd88a6feada6ec4f46d29b31 100644 (file)
@@ -593,8 +593,8 @@ BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) {
 
   // Block literal size. For global blocks we just use the size of the generic
   // block literal struct.
-  CharUnits BlockLiteralSize = CharUnits::fromQuantity(
-    TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType()) / 8);
+  CharUnits BlockLiteralSize = 
+    CGM.GetTargetTypeStoreSize(getGenericBlockLiteralType());
   DescriptorFields[1] =
     llvm::ConstantInt::get(UnsignedLongTy,BlockLiteralSize.getQuantity());
 
@@ -698,9 +698,8 @@ CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr,
       LocalDeclMap[VD] = i->second;
   }
 
-  BlockOffset = CharUnits::fromQuantity(
-      CGM.getTargetData()
-        .getTypeStoreSizeInBits(CGM.getGenericBlockLiteralType()) / 8);
+  BlockOffset = 
+      CGM.GetTargetTypeStoreSize(CGM.getGenericBlockLiteralType());
   BlockAlign = getContext().getTypeAlign(getContext().VoidPtrTy) / 8;
 
   const FunctionType *BlockFunctionType = BExpr->getFunctionType();
index 23b4ff26a2e18f13bb4f0902dc507ae5d476c06a..56feee4097217940ad586698ff7dcc6c6dce1f9c 100644 (file)
@@ -559,8 +559,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
     const llvm::Type *V1;
     V1 = cast<llvm::PointerType>(DeclPtr->getType())->getElementType();
     V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
-                               (CGM.getTargetData().getTypeStoreSizeInBits(V1)
-                                / 8));
+                               CGM.GetTargetTypeStoreSize(V1).getQuantity());
     Builder.CreateStore(V, size_field);
 
     if (flags & BLOCK_HAS_COPY_DISPOSE) {
index 65b29313c60fc38a613513d94bfeb84541374d33..4eb8bd8d9ffff69f3de319910ba6fba3f828628c 100644 (file)
@@ -20,6 +20,7 @@
 #include "TargetInfo.h"
 #include "clang/CodeGen/CodeGenOptions.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/CharUnits.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecordLayout.h"
@@ -968,6 +969,11 @@ GetLinkageForVariable(ASTContext &Context, const VarDecl *VD) {
   return CodeGenModule::GVA_StrongExternal;
 }
 
+CharUnits CodeGenModule::GetTargetTypeStoreSize(const llvm::Type *Ty) const {
+    return CharUnits::fromQuantity(
+      TheTargetData.getTypeStoreSizeInBits(Ty) / Context.getCharWidth());
+}
+
 void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
   llvm::Constant *Init = 0;
   QualType ASTTy = D->getType();
index 81f39791fcd0649b71874d3e9a4cc2672280b366..6267a10ec4a7dc269fd0ca7a892266df9ac63924 100644 (file)
@@ -53,6 +53,7 @@ namespace clang {
   class ObjCProtocolDecl;
   class ObjCEncodeExpr;
   class BlockExpr;
+  class CharUnits;
   class Decl;
   class Expr;
   class Stmt;
@@ -417,6 +418,10 @@ public:
   /// and type information of the given class.
   static llvm::GlobalVariable::LinkageTypes 
   getVtableLinkage(const CXXRecordDecl *RD);
+
+  /// GetTargetTypeStoreSize - Return the store size, in character units, of
+  /// the given LLVM type.
+  CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const;
   
 private:
   /// UniqueMangledName - Unique a name by (if necessary) inserting it into the