]> granicus.if.org Git - clang/commitdiff
Cleanups. Move GenerateRtti to CodeGenModule.
authorMike Stump <mrs@apple.com>
Tue, 18 Aug 2009 21:49:00 +0000 (21:49 +0000)
committerMike Stump <mrs@apple.com>
Tue, 18 Aug 2009 21:49:00 +0000 (21:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79372 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/CodeGenModule.h

index 0f70ca99c4d511fe03aa2cfb5075db209b3b7b6a..7355846f6abc42d6d681a27b100345b0910560eb 100644 (file)
@@ -670,7 +670,7 @@ const char *CodeGenModule::getMangledCXXDtorName(const CXXDestructorDecl *D,
   return UniqueMangledName(Name.begin(), Name.end());
 }
 
-llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) {
+llvm::Constant *CodeGenModule::GenerateRtti(const CXXRecordDecl *RD) {
   llvm::Type *Ptr8Ty;
   Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
   llvm::Constant *Rtti = llvm::Constant::getNullValue(Ptr8Ty);
@@ -697,7 +697,7 @@ llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) {
   llvm::Constant *C;
   llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, info.size());
   C = llvm::ConstantArray::get(type, info);
-  Rtti = new llvm::GlobalVariable(CGM.getModule(), type, true, linktype, C,
+  Rtti = new llvm::GlobalVariable(getModule(), type, true, linktype, C,
                                   Name);
   Rtti = llvm::ConstantExpr::getBitCast(Rtti, Ptr8Ty);
   return Rtti;
@@ -706,14 +706,19 @@ llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) {
 class ABIBuilder {
   std::vector<llvm::Constant *> &methods;
   llvm::Type *Ptr8Ty;
+  const CXXRecordDecl *Class;
+  llvm::Constant *rtti;
   llvm::LLVMContext &VMContext;
   CodeGenModule &CGM;  // Per-module state.
 public:
   ABIBuilder(std::vector<llvm::Constant *> &meth,
+             const CXXRecordDecl *c,
              CodeGenModule &cgm)
-    : methods(meth), VMContext(cgm.getModule().getContext()), CGM(cgm) {
+    : methods(meth), Class(c), rtti(cgm.GenerateRtti(c)),
+      VMContext(cgm.getModule().getContext()), CGM(cgm) {
     Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
   }
+
   void GenerateVcalls(const CXXRecordDecl *RD) {
     typedef CXXRecordDecl::method_iterator meth_iter;
     llvm::Constant *m;
@@ -747,7 +752,6 @@ public:
                              bool forPrimary,
                              int64_t Offset,
                              const CXXRecordDecl *Class,
-                             llvm::Constant *rtti,
                              bool ForVirtualBase,
                    llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary) {
     llvm::Constant *m = llvm::Constant::getNullValue(Ptr8Ty);
@@ -782,7 +786,7 @@ public:
       if (PrimaryBaseWasVirtual)
         IndirectPrimary.insert(PrimaryBase);
       Top = false;
-      GenerateVtableForBase(PrimaryBase, true, Offset, Class, rtti,
+      GenerateVtableForBase(PrimaryBase, true, Offset, Class,
                             PrimaryBaseWasVirtual, IndirectPrimary);
     }
 
@@ -812,15 +816,13 @@ public:
         cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
       if (Base != PrimaryBase || PrimaryBaseWasVirtual) {
         uint64_t o = Offset + Layout.getBaseClassOffset(Base);
-        GenerateVtableForBase(Base, true, o, Class, rtti, false,
-                              IndirectPrimary);
+        GenerateVtableForBase(Base, true, o, Class, false, IndirectPrimary);
       }
     }
   }
 
   void GenerateVtableForVBases(const CXXRecordDecl *RD,
                                const CXXRecordDecl *Class,
-                               llvm::Constant *rtti,
                    llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary) {
     for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
            e = RD->bases_end(); i != e; ++i) {
@@ -829,10 +831,10 @@ public:
       if (i->isVirtual() && !IndirectPrimary.count(Base)) {
         // Mark it so we don't output it twice.
         IndirectPrimary.insert(Base);
-        GenerateVtableForBase(Base, true, 0, Class, rtti, true, IndirectPrimary);
+        GenerateVtableForBase(Base, true, 0, Class, true, IndirectPrimary);
       }
       if (Base->getNumVBases())
-        GenerateVtableForVBases(Base, Class, rtti, IndirectPrimary);
+        GenerateVtableForVBases(Base, Class, IndirectPrimary);
     }
   }
 
@@ -869,20 +871,19 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
   std::vector<llvm::Constant *> methods;
   llvm::Type *Ptr8Ty=llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext),0);
   int64_t Offset = 0;
-  llvm::Constant *rtti = GenerateRtti(RD);
 
   Offset += LLVMPointerWidth;
   Offset += LLVMPointerWidth;
 
   llvm::SmallSet<const CXXRecordDecl *, 32> IndirectPrimary;
 
-  ABIBuilder b(methods, CGM);
+  ABIBuilder b(methods, RD, CGM);
 
   // First comes the vtables for all the non-virtual bases...
-  b.GenerateVtableForBase(RD, true, 0, RD, rtti, false, IndirectPrimary);
+  b.GenerateVtableForBase(RD, true, 0, RD, false, IndirectPrimary);
 
   // then the vtables for all the virtual bases.
-  b.GenerateVtableForVBases(RD, RD, rtti, IndirectPrimary);
+  b.GenerateVtableForVBases(RD, RD, IndirectPrimary);
 
   llvm::Constant *C;
   llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size());
index 41c886a656a9394d76d747517c856f602c5e5cf7..8cee4a649cc162ff6c9f4b57e3087b0796b2cb77 100644 (file)
@@ -361,7 +361,6 @@ public:
   /// legal to call this function even if there is no current insertion point.
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
-  llvm::Constant *GenerateRtti(const CXXRecordDecl *RD);
   llvm::Value *GenerateVtable(const CXXRecordDecl *RD);
 
   void EmitCtorPrologue(const CXXConstructorDecl *CD);
index cb3f0ba6873657d4429874709a9d6e770f1065c9..98e3bf307d792c1c7deeb1973a1d110e9da5162a 100644 (file)
@@ -232,6 +232,9 @@ public:
   llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
                                     const llvm::Type *Ty = 0);
 
+  /// GenerateRtti - Generate the rtti information for the given type.
+  llvm::Constant *GenerateRtti(const CXXRecordDecl *RD);
+
   /// GetStringForStringLiteral - Return the appropriate bytes for a string
   /// literal, properly padded to match the literal type. If only the address of
   /// a constant is needed consider using GetAddrOfConstantStringLiteral.