From: Anders Carlsson Date: Sat, 3 Oct 2009 14:56:57 +0000 (+0000) Subject: Move some functions from CodeGenFunctions to CodeGenModule so they can be used by... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b3583573ba6b26b605aacaad9a50492fb3d6fe6;p=clang Move some functions from CodeGenFunctions to CodeGenModule so they can be used by CGExprConstant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83263 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index de2392fd10..1093592b83 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -365,7 +365,7 @@ 1A4C41BE105B4C0B0047B5E7 /* CGCXXClass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGCXXClass.cpp; path = lib/CodeGen/CGCXXClass.cpp; sourceTree = ""; tabWidth = 2; }; 1A5D5E570E5E81010023C059 /* CGCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGCXX.cpp; path = lib/CodeGen/CGCXX.cpp; sourceTree = ""; tabWidth = 2; }; 1A649E1D0F9599D9005B965E /* CGBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGBlocks.h; path = lib/CodeGen/CGBlocks.h; sourceTree = ""; }; - 1A649E1E0F9599DA005B965E /* CGCXX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGCXX.h; path = lib/CodeGen/CGCXX.h; sourceTree = ""; }; + 1A649E1E0F9599DA005B965E /* CGCXX.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = CGCXX.h; path = lib/CodeGen/CGCXX.h; sourceTree = ""; tabWidth = 2; }; 1A6B6CD110693FC900BB4A8F /* CodeCompleteConsumer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CodeCompleteConsumer.cpp; path = lib/Sema/CodeCompleteConsumer.cpp; sourceTree = ""; tabWidth = 2; }; 1A6B6CD210693FC900BB4A8F /* SemaCodeComplete.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaCodeComplete.cpp; path = lib/Sema/SemaCodeComplete.cpp; sourceTree = ""; tabWidth = 2; }; 1A6B6CD310693FC900BB4A8F /* SemaTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = SemaTemplate.h; path = lib/Sema/SemaTemplate.h; sourceTree = ""; tabWidth = 2; }; diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index bf9af9c64d..1ea60eff56 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -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"); diff --git a/lib/CodeGen/CGCXXClass.cpp b/lib/CodeGen/CGCXXClass.cpp index 5d7b8a022c..9c8174bc22 100644 --- a/lib/CodeGen/CGCXXClass.cpp +++ b/lib/CodeGen/CGCXXClass.cpp @@ -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( diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 017efd3c88..5307d14753 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -239,7 +239,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { cast(E->getType()->getAs()-> getClass()->getAs()->getDecl()); - llvm::Constant *Adj = CGF.GetCXXBaseClassOffset(DstDecl, SrcDecl); + llvm::Constant *Adj = CGF.CGM.GetCXXBaseClassOffset(DstDecl, SrcDecl); if (Adj) SrcAdj = Builder.CreateAdd(SrcAdj, Adj, "adj"); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index faad45ad96..09a20e2227 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -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, diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index ff8ffb305d..b46b4ef860 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -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.