Skip to content

Commit 582c53d

Browse files
Teach the internalize pass to also internalize
global aliases. llvm-svn: 61754
1 parent 8d65f36 commit 582c53d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/lib/Transforms/IPO/Internalize.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <set>
2727
using namespace llvm;
2828

29+
STATISTIC(NumAliases , "Number of aliases internalized");
2930
STATISTIC(NumFunctions, "Number of functions internalized");
3031
STATISTIC(NumGlobals , "Number of global vars internalized");
3132

@@ -158,6 +159,17 @@ bool InternalizePass::runOnModule(Module &M) {
158159
DOUT << "Internalized gvar " << I->getName() << "\n";
159160
}
160161

162+
// Mark all aliases that are not in the api as internal as well.
163+
for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
164+
I != E; ++I)
165+
if (!I->isDeclaration() && !I->hasInternalLinkage() &&
166+
!ExternalNames.count(I->getName())) {
167+
I->setLinkage(GlobalValue::InternalLinkage);
168+
Changed = true;
169+
++NumAliases;
170+
DOUT << "Internalized alias " << I->getName() << "\n";
171+
}
172+
161173
return Changed;
162174
}
163175

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llvm-as < %s | opt -internalize | llvm-dis | grep internal | count 3
2+
3+
@A = global i32 0
4+
@B = alias i32* @A
5+
@C = alias i32* @B
6+
7+
define i32 @main() {
8+
%tmp = load i32* @C
9+
ret i32 %tmp
10+
}

0 commit comments

Comments
 (0)