If a constant or a function has linkonce_odr linkage and unnamed_addr, mark it

hidden. Being linkonce_odr guarantees that it is available in every dso that
needs it. Being a constant/function with unnamed_addr guarantees that the
copies don't have to be merged.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159136 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2012-06-25 14:30:31 +00:00
parent ccaddf4708
commit a0706a9ff4
3 changed files with 31 additions and 0 deletions

View File

@@ -1731,6 +1731,12 @@ bool GlobalOpt::ProcessGlobal(GlobalVariable *GV,
return true;
}
if (GV->hasLinkOnceODRLinkage() && GV->hasUnnamedAddr() && GV->isConstant() &&
GV->getVisibility() != GlobalValue::HiddenVisibility) {
GV->setVisibility(GlobalValue::HiddenVisibility);
return true;
}
if (!GV->hasLocalLinkage())
return false;
@@ -1743,6 +1749,7 @@ bool GlobalOpt::ProcessGlobal(GlobalVariable *GV,
if (!GS.isCompared && !GV->hasUnnamedAddr()) {
GV->setUnnamedAddr(true);
NumUnnamed++;
return true;
}
if (GV->isConstant() || !GV->hasInitializer())
@@ -1917,6 +1924,10 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
F->eraseFromParent();
Changed = true;
++NumFnDeleted;
} else if (F->hasLinkOnceODRLinkage() && F->hasUnnamedAddr() &&
F->getVisibility() != GlobalValue::HiddenVisibility) {
F->setVisibility(GlobalValue::HiddenVisibility);
Changed = true;
} else if (F->hasLocalLinkage()) {
if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
!F->hasAddressTaken()) {