diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-25 03:23:25 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-25 03:23:25 +0000 |
commit | 17600e29fa8d154f7c1e36d797f21422eebcf249 (patch) | |
tree | ac90d094e00bb84d873bc47142414980803c6f58 /llvm/lib/Transforms/IPO/GlobalOpt.cpp | |
parent | c7d3fc5547159b8d8cd40dcd50d2de879991180c (diff) | |
download | bcm5719-llvm-17600e29fa8d154f7c1e36d797f21422eebcf249.tar.gz bcm5719-llvm-17600e29fa8d154f7c1e36d797f21422eebcf249.zip |
Respect llvm.used in Internalize.
The language reference says that:
"If a symbol appears in the @llvm.used list, then the compiler,
assembler, and linker are required to treat the symbol as if there is
a reference to the symbol that it cannot see"
Since even the linker cannot see the reference, we must assume that
the reference can be using the symbol table. For example, a user can add
__attribute__((used)) to a debug helper function like dump and use it from
a debugger.
llvm-svn: 187103
Diffstat (limited to 'llvm/lib/Transforms/IPO/GlobalOpt.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 20af15ed008..64cd515f673 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -38,6 +38,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetLibraryInfo.h" +#include "llvm/Transforms/Utils/ModuleUtils.h" #include <algorithm> using namespace llvm; @@ -3040,24 +3041,6 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) { return true; } -/// \brief Given "llvm.used" or "llvm.compiler.used" as a global name, collect -/// the initializer elements of that global in Set and return the global itself. -static GlobalVariable * -collectUsedGlobalVariables(Module &M, const char *Name, - SmallPtrSet<GlobalValue *, 8> &Set) { - GlobalVariable *GV = M.getGlobalVariable(Name); - if (!GV || !GV->hasInitializer()) - return GV; - - const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); - for (unsigned I = 0, E = Init->getNumOperands(); I != E; ++I) { - Value *Op = Init->getOperand(I); - GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases()); - Set.insert(G); - } - return GV; -} - static int compareNames(const void *A, const void *B) { const GlobalValue *VA = *reinterpret_cast<GlobalValue* const*>(A); const GlobalValue *VB = *reinterpret_cast<GlobalValue* const*>(B); @@ -3107,9 +3090,8 @@ class LLVMUsed { public: LLVMUsed(Module &M) { - UsedV = collectUsedGlobalVariables(M, "llvm.used", Used); - CompilerUsedV = - collectUsedGlobalVariables(M, "llvm.compiler.used", CompilerUsed); + UsedV = collectUsedGlobalVariables(M, Used, false); + CompilerUsedV = collectUsedGlobalVariables(M, CompilerUsed, true); } typedef SmallPtrSet<GlobalValue *, 8>::iterator iterator; iterator usedBegin() { return Used.begin(); } |