diff options
author | Teresa Johnson <tejohnson@google.com> | 2016-04-20 14:39:45 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2016-04-20 14:39:45 +0000 |
commit | b35cc691ea93d9408f76736170359fd7ce604b53 (patch) | |
tree | 61d2c9ebba7b2a675bdc47ff212be9e44ef4df89 /llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | |
parent | 6eda85ac1fd9aed299eceed5a014c38a8d89da07 (diff) | |
download | bcm5719-llvm-b35cc691ea93d9408f76736170359fd7ce604b53.tar.gz bcm5719-llvm-b35cc691ea93d9408f76736170359fd7ce604b53.zip |
[ThinLTO] Prevent importing of "llvm.used" values
Summary:
This patch prevents importing from (and therefore exporting from) any
module with a "llvm.used" local value. Local values need to be promoted
and renamed when importing, and their presense on the llvm.used variable
indicates that there are opaque uses that won't see the rename. One such
example is a use in inline assembly.
See also the discussion at:
http://lists.llvm.org/pipermail/llvm-dev/2016-April/098047.html
As part of this, move collectUsedGlobalVariables out of Transforms/Utils
and into IR/Module so that it can be used more widely. There are several
other places in LLVM that used copies of this code that can be cleaned
up as a follow on NFC patch.
Reviewers: joker.eph
Subscribers: pcc, llvm-commits, joker.eph
Differential Revision: http://reviews.llvm.org/D18986
llvm-svn: 266877
Diffstat (limited to 'llvm/lib/Analysis/ModuleSummaryAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index 5c8b0aab193..ebc17214e2a 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -120,6 +120,31 @@ ModuleSummaryIndexBuilder::ModuleSummaryIndexBuilder( const Module *M, std::function<BlockFrequencyInfo *(const Function &F)> Ftor) : Index(llvm::make_unique<ModuleSummaryIndex>()), M(M) { + // We cannot currently promote or rename anything that is in llvm.used, + // since any such value may have a use that won't see the new name. + // Specifically, any uses within inline assembly are not visible to the + // compiler. Prevent importing of any modules containing these uses by + // suppressing generation of the index. This also prevents importing + // into this module, which is also necessary to avoid needing to rename + // in case of a name clash between a local in this module and an imported + // global. + // FIXME: If we find we need a finer-grained approach of preventing promotion + // and renaming of just the functions using inline assembly we will need to: + // - Add flag in the function summaries to identify those with inline asm. + // - Prevent importing of any functions with flag set. + // - Prevent importing of any global function with the same name as a + // function in current module that has the flag set. + // - For any llvm.used value that is exported and promoted, add a private + // alias to the original name in the current module (even if we don't + // export the function using those values in inline asm, another function + // with a reference could be exported). + SmallPtrSet<GlobalValue *, 8> Used; + collectUsedGlobalVariables(*M, Used, /*CompilerUsed*/ false); + for (GlobalValue *V : Used) { + if (V->hasLocalLinkage()) + return; + } + // Compute summaries for all functions defined in module, and save in the // index. for (auto &F : *M) { |