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/IR/Module.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/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 64528d2815a..10110367841 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -14,6 +14,7 @@ #include "llvm/IR/Module.h" #include "SymbolTableListTraitsImpl.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" @@ -515,3 +516,18 @@ void Module::setProfileSummary(Metadata *M) { Metadata *Module::getProfileSummary() { return getModuleFlag("ProfileSummary"); } + +GlobalVariable *llvm::collectUsedGlobalVariables( + const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) { + const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used"; + GlobalVariable *GV = M.getGlobalVariable(Name); + if (!GV || !GV->hasInitializer()) + return GV; + + const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); + for (Value *Op : Init->operands()) { + GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases()); + Set.insert(G); + } + return GV; +} |