]> granicus.if.org Git - clang/commitdiff
Move some functions from CodeGenFunctions to CodeGenModule so they can be used by...
authorAnders Carlsson <andersca@mac.com>
Sat, 3 Oct 2009 14:56:57 +0000 (14:56 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 3 Oct 2009 14:56:57 +0000 (14:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83263 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
lib/CodeGen/CGCXX.cpp
lib/CodeGen/CGCXXClass.cpp
lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/CodeGenModule.h

index de2392fd1097ed6631fae485b0ad5af1be15daa9..1093592b834a054e274db5d689b0d5533c01d156 100644 (file)
                1A4C41BE105B4C0B0047B5E7 /* CGCXXClass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGCXXClass.cpp; path = lib/CodeGen/CGCXXClass.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1A5D5E570E5E81010023C059 /* CGCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGCXX.cpp; path = lib/CodeGen/CGCXX.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1A649E1D0F9599D9005B965E /* CGBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGBlocks.h; path = lib/CodeGen/CGBlocks.h; sourceTree = "<group>"; };
-               1A649E1E0F9599DA005B965E /* CGCXX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGCXX.h; path = lib/CodeGen/CGCXX.h; sourceTree = "<group>"; };
+               1A649E1E0F9599DA005B965E /* CGCXX.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = CGCXX.h; path = lib/CodeGen/CGCXX.h; sourceTree = "<group>"; tabWidth = 2; };
                1A6B6CD110693FC900BB4A8F /* CodeCompleteConsumer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CodeCompleteConsumer.cpp; path = lib/Sema/CodeCompleteConsumer.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1A6B6CD210693FC900BB4A8F /* SemaCodeComplete.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaCodeComplete.cpp; path = lib/Sema/SemaCodeComplete.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1A6B6CD310693FC900BB4A8F /* SemaTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = SemaTemplate.h; path = lib/Sema/SemaTemplate.h; sourceTree = "<group>"; tabWidth = 2; };
index bf9af9c64da1b12fb2b5da17da31b2480d453f1b..1ea60eff56d0d00274dc810c8bb34c57b2fb9a5d 100644 (file)
@@ -1206,23 +1206,27 @@ CodeGenFunction::BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *&This,
                                   const llvm::Type *Ty) {
   // FIXME: If we know the dynamic type, we don't have to do a virtual dispatch.
 
-  // FIXME: move to Context
-  if (vtableinfo == 0)
-    vtableinfo = new VtableInfo(CGM);
-
-  VtableInfo::Index_t Idx = vtableinfo->lookup(MD);
-
+  uint64_t Index = CGM.GetVtableIndex(MD);
+  
   Ty = llvm::PointerType::get(Ty, 0);
   Ty = llvm::PointerType::get(Ty, 0);
   Ty = llvm::PointerType::get(Ty, 0);
   llvm::Value *vtbl = Builder.CreateBitCast(This, Ty);
   vtbl = Builder.CreateLoad(vtbl);
   llvm::Value *vfn = Builder.CreateConstInBoundsGEP1_64(vtbl,
-                                                        Idx, "vfn");
+                                                        Index, "vfn");
   vfn = Builder.CreateLoad(vfn);
   return vfn;
 }
 
+uint64_t CodeGenModule::GetVtableIndex(const CXXMethodDecl *MD) {
+  // FIXME: move to CodeGenModule.
+  if (vtableinfo == 0)
+    vtableinfo = new VtableInfo(*this);
+  
+  return vtableinfo->lookup(MD);
+}
+
 /// EmitClassAggrMemberwiseCopy - This routine generates code to copy a class
 /// array of objects from SrcValue to DestValue. Copying can be either a bitwise
 /// copy or via a copy constructor call.
@@ -1241,7 +1245,7 @@ void CodeGenFunction::EmitClassAggrMemberwiseCopy(llvm::Value *Dest,
                                            "loop.index");
   llvm::Value* zeroConstant =
     llvm::Constant::getNullValue(llvm::Type::getInt64Ty(VMContext));
-    Builder.CreateStore(zeroConstant, IndexPtr, false);
+  Builder.CreateStore(zeroConstant, IndexPtr, false);
   // Start the loop with a block that tests the condition.
   llvm::BasicBlock *CondBlock = createBasicBlock("for.cond");
   llvm::BasicBlock *AfterFor = createBasicBlock("for.end");
index 5d7b8a022c71636f3a111fd39155a8b5df2b43d5..9c8174bc22f71e1ccad46ae646ef2500b6ec256f 100644 (file)
@@ -70,8 +70,8 @@ static uint64_t ComputeBaseClassOffset(ASTContext &Context,
 }
 
 llvm::Constant *
-CodeGenFunction::GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl,
-                                       const CXXRecordDecl *BaseClassDecl) {
+CodeGenModule::GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl,
+                                     const CXXRecordDecl *BaseClassDecl) {
   if (ClassDecl == BaseClassDecl)
     return 0;
 
@@ -84,7 +84,8 @@ CodeGenFunction::GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl,
   if (!Offset)
     return 0;
 
-  const llvm::Type *PtrDiffTy = ConvertType(getContext().getPointerDiffType());
+  const llvm::Type *PtrDiffTy = 
+    Types.ConvertType(getContext().getPointerDiffType());
 
   return llvm::ConstantInt::get(PtrDiffTy, Offset);
 }
@@ -94,7 +95,7 @@ CodeGenFunction::GetAddressCXXOfBaseClass(llvm::Value *BaseValue,
                                           const CXXRecordDecl *ClassDecl,
                                           const CXXRecordDecl *BaseClassDecl,
                                           bool NullCheckValue) {
-  llvm::Constant *Offset = GetCXXBaseClassOffset(ClassDecl, BaseClassDecl);
+  llvm::Constant *Offset = CGM.GetCXXBaseClassOffset(ClassDecl, BaseClassDecl);
   
   QualType BTy =
     getContext().getCanonicalType(
index 017efd3c8811d09e95ecc8faaec5a035261d22e2..5307d147538c0da8cbb7651404d16b7bccf40d12 100644 (file)
@@ -239,7 +239,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
       cast<CXXRecordDecl>(E->getType()->getAs<MemberPointerType>()->
                           getClass()->getAs<RecordType>()->getDecl());
     
-    llvm::Constant *Adj = CGF.GetCXXBaseClassOffset(DstDecl, SrcDecl);
+    llvm::Constant *Adj = CGF.CGM.GetCXXBaseClassOffset(DstDecl, SrcDecl);
     if (Adj)
       SrcAdj = Builder.CreateAdd(SrcAdj, Adj, "adj");
     
index faad45ad96eb017ec34d4e90c8c3434610cf6f05..09a20e22279beb68cdd0f2fe4e498e08839cabfa 100644 (file)
@@ -588,11 +588,6 @@ public:
                                         const CXXRecordDecl *ClassDecl,
                                         const CXXRecordDecl *BaseClassDecl,
                                         bool NullCheckValue);
-
-  /// GetCXXBaseClassOffset - Returns the offset from a derived class to its
-  /// base class. Returns null if the offset is 0.
-  llvm::Constant *GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl,
-                                        const CXXRecordDecl *BaseClassDecl);
   
   void EmitClassAggrMemberwiseCopy(llvm::Value *DestValue,
                                    llvm::Value *SrcValue,
index ff8ffb305df0b17a660692006b063fd92cdd88f4..b46b4ef860751830eeefa1e168940b60a5b60564 100644 (file)
@@ -252,6 +252,14 @@ public:
                                       int64_t nv_t, int64_t v_t,
                                       int64_t nv_r, int64_t v_r);
 
+  /// GetVtableIndex - Return the vtable index for a virtual member function.
+  uint64_t GetVtableIndex(const CXXMethodDecl *MD);
+
+  /// GetCXXBaseClassOffset - Returns the offset from a derived class to its
+  /// base class. Returns null if the offset is 0.
+  llvm::Constant *GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl,
+                                        const CXXRecordDecl *BaseClassDecl);
+
   /// 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.