summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/Internalize.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-10-21 17:14:55 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-10-21 17:14:55 +0000
commit3d7fc25c7c08d25b97c56ab99aee1a8551c2155d (patch)
tree004ba3e61bf61d3fd7e7ade3ba671b98f0a4f5e5 /llvm/lib/Transforms/IPO/Internalize.cpp
parent63bb3e1182f79f52d15cbf658545515f6bcece7b (diff)
downloadbcm5719-llvm-3d7fc25c7c08d25b97c56ab99aee1a8551c2155d.tar.gz
bcm5719-llvm-3d7fc25c7c08d25b97c56ab99aee1a8551c2155d.zip
Optimize more linkonce_odr values during LTO.
When a linkonce_odr value that is on the dso list is not unnamed_addr we can still look to see if anything is actually using its address. If not, it is safe to hide it. This patch implements that by moving GlobalStatus to Transforms/Utils and using it in Internalize. llvm-svn: 193090
Diffstat (limited to 'llvm/lib/Transforms/IPO/Internalize.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/Internalize.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/Internalize.cpp b/llvm/lib/Transforms/IPO/Internalize.cpp
index f20a7bd92f4..e61591870bc 100644
--- a/llvm/lib/Transforms/IPO/Internalize.cpp
+++ b/llvm/lib/Transforms/IPO/Internalize.cpp
@@ -11,6 +11,19 @@
// If the function or variable is not in the list of external names given to
// the pass it is marked as internal.
//
+// This transformation would not be legal or profitable in a regular
+// compilation, but it gets extra information from the linker about what is safe
+// or profitable.
+//
+// As an example of a normally illegal transformation: Internalizing a function
+// with external linkage. Only if we are told it is only used from within this
+// module, it is safe to do it.
+//
+// On the profitability side: It is always legal to internalize a linkonce_odr
+// whose address is not used. Doing so normally would introduce code bloat, but
+// if we are told by the linker that the only use of this would be for a
+// DSO symbol table, it is profitable to hide it.
+//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "internalize"
@@ -23,6 +36,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/Utils/GlobalStatus.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <fstream>
#include <set>
@@ -142,8 +156,11 @@ static bool shouldInternalize(const GlobalValue &GV,
if (GV.hasUnnamedAddr())
return true;
- // FIXME: Check if the address is used.
- return false;
+ GlobalStatus GS;
+ if (GlobalStatus::analyzeGlobal(&GV, GS))
+ return false;
+
+ return !GS.IsCompared;
}
bool InternalizePass::runOnModule(Module &M) {
OpenPOWER on IntegriCloud