aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-01-29 18:25:07 +0000
committerAnders Carlsson <andersca@mac.com>2011-01-29 18:25:07 +0000
commit96eaf2992b5955d1470fc9cce7a96e7e1e3b4ea7 (patch)
treec24f4ee8894fee79acb1c26d66f12f7dff4c6586 /lib/CodeGen
parent3bd6202ea2d5b5f7c8229cd280a846ae3dcf2355 (diff)
Use CGM.CreateOrReplaceCXXRuntimeVariable in CGVTables.cpp
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124538 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGVTables.cpp51
-rw-r--r--lib/CodeGen/CodeGenModule.cpp2
2 files changed, 5 insertions, 48 deletions
diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp
index 6d8812a3aa..0ff41bb354 100644
--- a/lib/CodeGen/CGVTables.cpp
+++ b/lib/CodeGen/CGVTables.cpp
@@ -2932,49 +2932,6 @@ CodeGenVTables::CreateVTableInitializer(const CXXRecordDecl *RD,
return llvm::ConstantArray::get(ArrayType, Inits.data(), Inits.size());
}
-/// GetGlobalVariable - Will return a global variable of the given type.
-/// If a variable with a different type already exists then a new variable
-/// with the right type will be created.
-/// FIXME: We should move this to CodeGenModule and rename it to something
-/// better and then use it in CGVTT and CGRTTI.
-static llvm::GlobalVariable *
-GetGlobalVariable(llvm::Module &Module, llvm::StringRef Name,
- const llvm::Type *Ty,
- llvm::GlobalValue::LinkageTypes Linkage) {
-
- llvm::GlobalVariable *GV = Module.getNamedGlobal(Name);
- llvm::GlobalVariable *OldGV = 0;
-
- if (GV) {
- // Check if the variable has the right type.
- if (GV->getType()->getElementType() == Ty)
- return GV;
-
- assert(GV->isDeclaration() && "Declaration has wrong type!");
-
- OldGV = GV;
- }
-
- // Create a new variable.
- GV = new llvm::GlobalVariable(Module, Ty, /*isConstant=*/true,
- Linkage, 0, Name);
-
- if (OldGV) {
- // Replace occurrences of the old variable if needed.
- GV->takeName(OldGV);
-
- if (!OldGV->use_empty()) {
- llvm::Constant *NewPtrForOldDecl =
- llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
- OldGV->replaceAllUsesWith(NewPtrForOldDecl);
- }
-
- OldGV->eraseFromParent();
- }
-
- return GV;
-}
-
llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTable(const CXXRecordDecl *RD) {
llvm::SmallString<256> OutName;
CGM.getCXXABI().getMangleContext().mangleCXXVTable(RD, OutName);
@@ -2987,8 +2944,8 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTable(const CXXRecordDecl *RD) {
llvm::ArrayType::get(Int8PtrTy, getNumVTableComponents(RD));
llvm::GlobalVariable *GV =
- GetGlobalVariable(CGM.getModule(), Name, ArrayType,
- llvm::GlobalValue::ExternalLinkage);
+ CGM.CreateOrReplaceCXXRuntimeVariable(Name, ArrayType,
+ llvm::GlobalValue::ExternalLinkage);
GV->setUnnamedAddr(true);
return GV;
}
@@ -3050,8 +3007,8 @@ CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD,
// Create the variable that will hold the construction vtable.
llvm::GlobalVariable *VTable =
- GetGlobalVariable(CGM.getModule(), Name, ArrayType,
- llvm::GlobalValue::InternalLinkage);
+ CGM.CreateOrReplaceCXXRuntimeVariable(Name, ArrayType,
+ llvm::GlobalValue::InternalLinkage);
// Add the thunks.
VTableThunksTy VTableThunks;
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index c261ccae2e..3162559e47 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1000,7 +1000,7 @@ CodeGenModule::CreateOrReplaceCXXRuntimeVariable(llvm::StringRef Name,
// Because C++ name mangling, the only way we can end up with an already
// existing global with the same name is if it has been declared extern "C".
- assert(GV->isDeclaration() && "Declaration has wrong type!");
+ assert(GV->isDeclaration() && "Declaration has wrong type!");
OldGV = GV;
}