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/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index bf9af9c..1ea60ef 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -1206,23 +1206,27 @@
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 @@
"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 5d7b8a0..9c8174b 100644
--- a/lib/CodeGen/CGCXXClass.cpp
+++ b/lib/CodeGen/CGCXXClass.cpp
@@ -70,8 +70,8 @@
}
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 @@
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 @@
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 017efd3..5307d14 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -239,7 +239,7 @@
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 faad45a..09a20e2 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -588,11 +588,6 @@
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 ff8ffb3..b46b4ef 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -252,6 +252,14 @@
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.