[llvm] r189886 - Add r159136 back now that pr13124 has been fixed.
Rafael Espindola
rafael.espindola at gmail.com
Tue Sep 3 16:34:36 PDT 2013
Author: rafael
Date: Tue Sep 3 18:34:36 2013
New Revision: 189886
URL: http://llvm.org/viewvc/llvm-project?rev=189886&view=rev
Log:
Add r159136 back now that pr13124 has been fixed.
Original message:
If a constant or a function has linkonce_odr linkage and unnamed_addr, mark
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.
Added:
llvm/trunk/test/Transforms/GlobalOpt/hidden.ll
Modified:
llvm/trunk/include/llvm/IR/GlobalValue.h
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=189886&r1=189885&r2=189886&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Tue Sep 3 18:34:36 2013
@@ -122,6 +122,9 @@ public:
static bool isAvailableExternallyLinkage(LinkageTypes Linkage) {
return Linkage == AvailableExternallyLinkage;
}
+ static bool isLinkOnceODRLinkage(LinkageTypes Linkage) {
+ return Linkage == LinkOnceODRLinkage;
+ }
static bool isLinkOnceLinkage(LinkageTypes Linkage) {
return Linkage == LinkOnceAnyLinkage ||
Linkage == LinkOnceODRLinkage ||
@@ -202,6 +205,9 @@ public:
bool hasAvailableExternallyLinkage() const {
return isAvailableExternallyLinkage(Linkage);
}
+ bool hasLinkOnceODRLinkage() const {
+ return isLinkOnceODRLinkage(Linkage);
+ }
bool hasLinkOnceLinkage() const {
return isLinkOnceLinkage(Linkage);
}
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=189886&r1=189885&r2=189886&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Sep 3 18:34:36 2013
@@ -1914,6 +1914,12 @@ bool GlobalOpt::ProcessGlobal(GlobalVari
return true;
}
+ if (GV->hasLinkOnceODRLinkage() && GV->hasUnnamedAddr() && GV->isConstant() &&
+ GV->getVisibility() != GlobalValue::HiddenVisibility) {
+ GV->setVisibility(GlobalValue::HiddenVisibility);
+ return true;
+ }
+
if (!GV->hasLocalLinkage())
return false;
@@ -1926,6 +1932,7 @@ bool GlobalOpt::ProcessGlobal(GlobalVari
if (!GS.isCompared && !GV->hasUnnamedAddr()) {
GV->setUnnamedAddr(true);
NumUnnamed++;
+ return true;
}
if (GV->isConstant() || !GV->hasInitializer())
@@ -2105,6 +2112,10 @@ bool GlobalOpt::OptimizeFunctions(Module
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()) {
Added: llvm/trunk/test/Transforms/GlobalOpt/hidden.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/hidden.ll?rev=189886&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/hidden.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/hidden.ll Tue Sep 3 18:34:36 2013
@@ -0,0 +1,14 @@
+; RUN: opt %s -globalopt -S | FileCheck %s
+
+ at foo = linkonce_odr unnamed_addr constant i32 42
+; CHECK: @foo = linkonce_odr hidden unnamed_addr constant i32 42
+
+define linkonce_odr void @bar() unnamed_addr {
+; CHECK: define linkonce_odr hidden void @bar() unnamed_addr {
+ ret void
+}
+
+define i32* @zed() {
+ call void @bar()
+ ret i32* @foo
+}
More information about the llvm-commits
mailing list