]> granicus.if.org Git - clang/commitdiff
Change the key of CGRecordLayouts from being an llvm type* to being a decl*. LLVM
authorChris Lattner <sabre@nondot.org>
Tue, 5 Feb 2008 06:55:31 +0000 (06:55 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 5 Feb 2008 06:55:31 +0000 (06:55 +0000)
Type*'s can change as types are refined, so we can't use them as a stable key in
the map.  Decls don't change, so use them instead.

This patch was written by Anders, but he's too shy to commit it himself :)

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

CodeGen/CGExprConstant.cpp
CodeGen/CodeGenFunction.cpp
CodeGen/CodeGenTypes.cpp
CodeGen/CodeGenTypes.h

index fbf65aa59b9c6731776f341d3f441e1ef8957ad6..f72994d5089e68ed7c23d8205c553223fab0579c 100644 (file)
@@ -104,8 +104,9 @@ public:
   llvm::Constant *EmitStructInitialization(InitListExpr *ILE,
                                            const llvm::StructType *SType) {
 
+    TagDecl *TD = ILE->getType()->getAsRecordType()->getDecl();
     std::vector<llvm::Constant*> Elts;
-    const CGRecordLayout *CGR = CGM.getTypes().getCGRecordLayout(SType);
+    const CGRecordLayout *CGR = CGM.getTypes().getCGRecordLayout(TD);
     unsigned NumInitElements = ILE->getNumInits();
     unsigned NumElements = SType->getNumElements();
       
index 98d0b01ad5a19cab57944031ec78e14a6297daa1..dc31a27945b57e905d2819ca2d41309c02eafe85 100644 (file)
@@ -139,14 +139,11 @@ void CodeGenFunction::StartBlock(const char *N) {
 
 /// getCGRecordLayout - Return record layout info.
 const CGRecordLayout *CodeGenFunction::getCGRecordLayout(CodeGenTypes &CGT,
-                                                         QualType RTy) {
-  assert (isa<RecordType>(RTy) 
-          && "Unexpected type. RecordType expected here.");
+                                                         QualType Ty) {
+  const RecordType *RTy = Ty->getAsRecordType();
+  assert (RTy && "Unexpected type. RecordType expected here.");
 
-  const llvm::Type *Ty = ConvertType(RTy);
-  assert (Ty && "Unable to find llvm::Type");
-  
-  return CGT.getCGRecordLayout(Ty);
+  return CGT.getCGRecordLayout(RTy->getDecl());
 }
 
 /// WarnUnsupported - Print out a warning that codegen doesn't support the
index 06ec4679bc342ec188609e1a37bb37e5841db77a..97fc61d4ac10805c876200035a76ecc68c79a5ed 100644 (file)
@@ -84,7 +84,7 @@ CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M,
 }
 
 CodeGenTypes::~CodeGenTypes() {
-  for(llvm::DenseMap<const llvm::Type *, CGRecordLayout *>::iterator
+  for(llvm::DenseMap<const TagDecl *, CGRecordLayout *>::iterator
         I = CGRecordLayouts.begin(), E = CGRecordLayouts.end();
       I != E; ++I)
     delete I->second;
@@ -332,7 +332,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
       CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType(), 
                                                RO.getPaddingFields());
       ResultType = TagDeclTypes[TD] = RLI->getLLVMType();
-      CGRecordLayouts[ResultType] = RLI;
+      CGRecordLayouts[TD] = RLI;
 
       // Refine any OpaqueType associated with this RecordDecl.
       OpaqueTy->refineAbstractTypeTo(ResultType);
@@ -356,7 +356,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
         CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType(),
                                                  RO.getPaddingFields());
         ResultType = TagDeclTypes[TD] = RLI->getLLVMType();
-        CGRecordLayouts[ResultType] = RLI;
+        CGRecordLayouts[TD] = RLI;
       } else {       
         std::vector<const llvm::Type*> Fields;
         ResultType = TagDeclTypes[TD] = llvm::StructType::get(Fields);
@@ -436,9 +436,9 @@ void CodeGenTypes::addBitFieldInfo(const FieldDecl *FD, unsigned Begin,
 
 /// getCGRecordLayout - Return record layout info for the given llvm::Type.
 const CGRecordLayout *
-CodeGenTypes::getCGRecordLayout(const llvm::Type* Ty) const {
-  llvm::DenseMap<const llvm::Type*, CGRecordLayout *>::iterator I
-    = CGRecordLayouts.find(Ty);
+CodeGenTypes::getCGRecordLayout(const TagDecl *TD) const {
+  llvm::DenseMap<const TagDecl*, CGRecordLayout *>::iterator I
+    = CGRecordLayouts.find(TD);
   assert (I != CGRecordLayouts.end() 
           && "Unable to find record layout information for type");
   return I->second;
index 2ca3d3478cc6bd3fa59641f0479253f75e33e282..0da71ca029d2ce5cfac2dcd3a75bb93545a0f5de 100644 (file)
@@ -81,7 +81,7 @@ class CodeGenTypes {
   /// record layout info. 
   /// FIXME : If CGRecordLayout is less than 16 bytes then use 
   /// inline it in the map.
-  llvm::DenseMap<const llvm::Type*, CGRecordLayout *> CGRecordLayouts;
+  llvm::DenseMap<const TagDecl*, CGRecordLayout *> CGRecordLayouts;
 
   /// FieldInfo - This maps struct field with corresponding llvm struct type
   /// field no. This info is populated by record organizer.
@@ -136,7 +136,7 @@ public:
   const llvm::Type *ConvertTypeForMem(QualType T);
   
   
-  const CGRecordLayout *getCGRecordLayout(const llvm::Type*) const;
+  const CGRecordLayout *getCGRecordLayout(const TagDecl*) const;
   
   /// getLLVMFieldNo - Return llvm::StructType element number
   /// that corresponds to the field FD.