diff options
author | Anders Carlsson <andersca@mac.com> | 2009-10-03 14:56:57 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-10-03 14:56:57 +0000 |
commit | 2b3583573ba6b26b605aacaad9a50492fb3d6fe6 (patch) | |
tree | 3c646b8e2903a50ce22032e9b5e76171056b8928 /lib/CodeGen | |
parent | ee383163a656a7e8d99efa4e5ee98c705c7fdf89 (diff) |
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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 20 | ||||
-rw-r--r-- | lib/CodeGen/CGCXXClass.cpp | 9 | ||||
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 5 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.h | 8 |
5 files changed, 26 insertions, 18 deletions
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<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"); 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. |