summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/GlobalMerge.cpp
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2015-08-11 15:48:04 +0000
committerJohn Brawn <john.brawn@arm.com>2015-08-11 15:48:04 +0000
commit863bfdbfb446adaef767ff514d1f2ffb5d489562 (patch)
treeb602a64933ad983b6fedca8691aa0a4bdb36b29c /llvm/lib/CodeGen/GlobalMerge.cpp
parentb10555cc618b4bfda5bd08bb76ebdfdbf817d68d (diff)
downloadbcm5719-llvm-863bfdbfb446adaef767ff514d1f2ffb5d489562.tar.gz
bcm5719-llvm-863bfdbfb446adaef767ff514d1f2ffb5d489562.zip
[GlobalMerge] Use private linkage for MergedGlobals variables
Other objects can never reference the MergedGlobals symbol so external linkage is never needed. Using private instead of internal linkage means the object is more similar to what it looks like when global merging is not enabled, with the only difference being that the merged variables are addressed indirectly relative to the start of the section they are in. Also add aliases for merged variables with internal linkage, as this also makes the object be more like what it is when they are not merged. Differential Revision: http://reviews.llvm.org/D11942 llvm-svn: 244615
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r--llvm/lib/CodeGen/GlobalMerge.cpp30
1 files changed, 5 insertions, 25 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index d477143d62d..3a7e2f47686 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -429,8 +429,6 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
std::vector<Type*> Tys;
std::vector<Constant*> Inits;
- bool HasExternal = false;
- GlobalVariable *TheFirstExternal = 0;
for (j = i; j != -1; j = GlobalSet.find_next(j)) {
Type *Ty = Globals[j]->getType()->getElementType();
MergedSize += DL.getTypeAllocSize(Ty);
@@ -439,30 +437,14 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
}
Tys.push_back(Ty);
Inits.push_back(Globals[j]->getInitializer());
-
- if (Globals[j]->hasExternalLinkage() && !HasExternal) {
- HasExternal = true;
- TheFirstExternal = Globals[j];
- }
}
- // If merged variables doesn't have external linkage, we needn't to expose
- // the symbol after merging.
- GlobalValue::LinkageTypes Linkage = HasExternal
- ? GlobalValue::ExternalLinkage
- : GlobalValue::InternalLinkage;
-
StructType *MergedTy = StructType::get(M.getContext(), Tys);
Constant *MergedInit = ConstantStruct::get(MergedTy, Inits);
- // If merged variables have external linkage, we use symbol name of the
- // first variable merged as the suffix of global symbol name. This would
- // be able to avoid the link-time naming conflict for globalm symbols.
GlobalVariable *MergedGV = new GlobalVariable(
- M, MergedTy, isConst, Linkage, MergedInit,
- HasExternal ? "_MergedGlobals_" + TheFirstExternal->getName()
- : "_MergedGlobals",
- nullptr, GlobalVariable::NotThreadLocal, AddrSpace);
+ M, MergedTy, isConst, GlobalValue::PrivateLinkage, MergedInit,
+ "_MergedGlobals", nullptr, GlobalVariable::NotThreadLocal, AddrSpace);
for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k)) {
GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
@@ -477,11 +459,9 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
Globals[k]->replaceAllUsesWith(GEP);
Globals[k]->eraseFromParent();
- if (Linkage != GlobalValue::InternalLinkage) {
- // Generate a new alias...
- auto *PTy = cast<PointerType>(GEP->getType());
- GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
- }
+ // Generate a new alias...
+ auto *PTy = cast<PointerType>(GEP->getType());
+ GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
NumMerged++;
}
OpenPOWER on IntegriCloud