diff options
author | Duncan Sands <baldrick@free.fr> | 2009-03-06 10:21:56 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2009-03-06 10:21:56 +0000 |
commit | fc5940d2a09a795e683ae86b237d6f55fb3551d4 (patch) | |
tree | 6821f5daf4f09326efad2f6baaab28e155212077 /lib/Transforms | |
parent | 49155ffababdc2102852fd3cd3988d800d12a5c6 (diff) |
While thinking about the one-definition-rule and trying
to find a tiny mouse hole to squeeze through, it struck
me that globals without a name can be considered internal
since they can't be referenced from outside the current
module. This patch makes GlobalOpt give them internal
linkage. Also done for aliases even though they always
have names, since in my opinion anonymous aliases should
be allowed for consistency with global variables and
functions. So if that happens one day, this code is ready!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66267 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/GlobalOpt.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 0a35fa93e4..b93eb6b6d4 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -67,7 +67,7 @@ namespace { GlobalVariable *FindGlobalCtors(Module &M); bool OptimizeFunctions(Module &M); bool OptimizeGlobalVars(Module &M); - bool ResolveAliases(Module &M); + bool OptimizeGlobalAliases(Module &M); bool OptimizeGlobalCtorsList(GlobalVariable *&GCL); bool ProcessInternalGlobal(GlobalVariable *GV,Module::global_iterator &GVI); }; @@ -1808,6 +1808,9 @@ bool GlobalOpt::OptimizeFunctions(Module &M) { // Optimize functions. for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) { Function *F = FI++; + // Functions without names cannot be referenced outside this module. + if (!F->hasName() && !F->isDeclaration()) + F->setLinkage(GlobalValue::InternalLinkage); F->removeDeadConstantUsers(); if (F->use_empty() && (F->hasLocalLinkage() || F->hasLinkOnceLinkage())) { @@ -1844,6 +1847,9 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) { for (Module::global_iterator GVI = M.global_begin(), E = M.global_end(); GVI != E; ) { GlobalVariable *GV = GVI++; + // Global variables without names cannot be referenced outside this module. + if (!GV->hasName() && !GV->isDeclaration()) + GV->setLinkage(GlobalValue::InternalLinkage); if (!GV->isConstant() && GV->hasLocalLinkage() && GV->hasInitializer()) Changed |= ProcessInternalGlobal(GV, GVI); @@ -2371,12 +2377,15 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) { return true; } -bool GlobalOpt::ResolveAliases(Module &M) { +bool GlobalOpt::OptimizeGlobalAliases(Module &M) { bool Changed = false; for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) { Module::alias_iterator J = I++; + // Aliases without names cannot be referenced outside this module. + if (!J->hasName() && !J->isDeclaration()) + J->setLinkage(GlobalValue::InternalLinkage); // If the aliasee may change at link time, nothing can be done - bail out. if (J->mayBeOverridden()) continue; @@ -2447,7 +2456,7 @@ bool GlobalOpt::runOnModule(Module &M) { LocalChange |= OptimizeGlobalVars(M); // Resolve aliases, when possible. - LocalChange |= ResolveAliases(M); + LocalChange |= OptimizeGlobalAliases(M); Changed |= LocalChange; } |