summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-01-14 18:52:17 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-01-14 18:52:17 +0000
commit3e4542b2ca3426e5f5b812e008f6c71cf9ad295b (patch)
treeaabc4dfbe82b7dfb4c91a4390d86e7f136cba13d /lib/Transforms/IPO
parentcba390a29ed0839aae92e010229b07a5ebb82438 (diff)
downloadllvm-3e4542b2ca3426e5f5b812e008f6c71cf9ad295b.tar.gz
llvm-3e4542b2ca3426e5f5b812e008f6c71cf9ad295b.tar.bz2
llvm-3e4542b2ca3426e5f5b812e008f6c71cf9ad295b.tar.xz
Reapply "LTO: add API to set strategy for -internalize"
Reapply r199191, reverted in r199197 because it carelessly broke Other/link-opts.ll. The problem was that calling createInternalizePass("main") would select createInternalizePass(bool("main")) instead of createInternalizePass(ArrayRef<const char *>("main")). This commit fixes the bug. The original commit message follows. Add API to LTOCodeGenerator to specify a strategy for the -internalize pass. This is a new attempt at Bill's change in r185882, which he reverted in r188029 due to problems with the gold linker. This puts the onus on the linker to decide whether (and what) to internalize. In particular, running internalize before outputting an object file may change a 'weak' symbol into an internal one, even though that symbol could be needed by an external object file --- e.g., with arclite. This patch enables three strategies: - LTO_INTERNALIZE_FULL: the default (and the old behaviour). - LTO_INTERNALIZE_NONE: skip -internalize. - LTO_INTERNALIZE_HIDDEN: only -internalize symbols with hidden visibility. LTO_INTERNALIZE_FULL should be used when linking an executable. Outputting an object file (e.g., via ld -r) is more complicated, and depends on whether hidden symbols should be internalized. E.g., for ld -r, LTO_INTERNALIZE_NONE can be used when -keep_private_externs, and LTO_INTERNALIZE_HIDDEN can be used otherwise. However, LTO_INTERNALIZE_FULL is inappropriate, since the output object file will eventually need to link with others. lto_codegen_set_internalize_strategy() sets the strategy for subsequent calls to lto_codegen_write_merged_modules() and lto_codegen_compile*(). <rdar://problem/14334895> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199244 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r--lib/Transforms/IPO/Internalize.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp
index 0307714177..59ef4e192f 100644
--- a/lib/Transforms/IPO/Internalize.cpp
+++ b/lib/Transforms/IPO/Internalize.cpp
@@ -54,10 +54,11 @@ APIList("internalize-public-api-list", cl::value_desc("list"),
namespace {
class InternalizePass : public ModulePass {
std::set<std::string> ExternalNames;
+ bool OnlyHidden;
public:
static char ID; // Pass identification, replacement for typeid
- explicit InternalizePass();
- explicit InternalizePass(ArrayRef<const char *> ExportList);
+ explicit InternalizePass(bool OnlyHidden = false);
+ explicit InternalizePass(ArrayRef<const char *> ExportList, bool OnlyHidden);
void LoadFile(const char *Filename);
virtual bool runOnModule(Module &M);
@@ -72,16 +73,17 @@ char InternalizePass::ID = 0;
INITIALIZE_PASS(InternalizePass, "internalize",
"Internalize Global Symbols", false, false)
-InternalizePass::InternalizePass()
- : ModulePass(ID) {
+InternalizePass::InternalizePass(bool OnlyHidden)
+ : ModulePass(ID), OnlyHidden(OnlyHidden) {
initializeInternalizePassPass(*PassRegistry::getPassRegistry());
if (!APIFile.empty()) // If a filename is specified, use it.
LoadFile(APIFile.c_str());
ExternalNames.insert(APIList.begin(), APIList.end());
}
-InternalizePass::InternalizePass(ArrayRef<const char *> ExportList)
- : ModulePass(ID){
+InternalizePass::InternalizePass(ArrayRef<const char *> ExportList,
+ bool OnlyHidden)
+ : ModulePass(ID), OnlyHidden(OnlyHidden) {
initializeInternalizePassPass(*PassRegistry::getPassRegistry());
for(ArrayRef<const char *>::const_iterator itr = ExportList.begin();
itr != ExportList.end(); itr++) {
@@ -106,7 +108,11 @@ void InternalizePass::LoadFile(const char *Filename) {
}
static bool shouldInternalize(const GlobalValue &GV,
- const std::set<std::string> &ExternalNames) {
+ const std::set<std::string> &ExternalNames,
+ bool OnlyHidden) {
+ if (OnlyHidden && !GV.hasHiddenVisibility())
+ return false;
+
// Function must be defined here
if (GV.isDeclaration())
return false;
@@ -155,9 +161,8 @@ bool InternalizePass::runOnModule(Module &M) {
}
// Mark all functions not in the api as internal.
- // FIXME: maybe use private linkage?
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
- if (!shouldInternalize(*I, ExternalNames))
+ if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
continue;
I->setLinkage(GlobalValue::InternalLinkage);
@@ -191,10 +196,9 @@ bool InternalizePass::runOnModule(Module &M) {
// Mark all global variables with initializers that are not in the api as
// internal as well.
- // FIXME: maybe use private linkage?
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
- if (!shouldInternalize(*I, ExternalNames))
+ if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
continue;
I->setLinkage(GlobalValue::InternalLinkage);
@@ -206,7 +210,7 @@ bool InternalizePass::runOnModule(Module &M) {
// Mark all aliases that are not in the api as internal as well.
for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I) {
- if (!shouldInternalize(*I, ExternalNames))
+ if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
continue;
I->setLinkage(GlobalValue::InternalLinkage);
@@ -218,10 +222,15 @@ bool InternalizePass::runOnModule(Module &M) {
return Changed;
}
-ModulePass *llvm::createInternalizePass() {
- return new InternalizePass();
+ModulePass *llvm::createInternalizePass(bool OnlyHidden) {
+ return new InternalizePass(OnlyHidden);
+}
+
+ModulePass *llvm::createInternalizePass(ArrayRef<const char *> ExportList,
+ bool OnlyHidden) {
+ return new InternalizePass(ExportList, OnlyHidden);
}
-ModulePass *llvm::createInternalizePass(ArrayRef<const char *> ExportList) {
- return new InternalizePass(ExportList);
+ModulePass *llvm::createInternalizePass(const char *SingleExport) {
+ return createInternalizePass(ArrayRef<const char *>(SingleExport));
}