Implement aliases. This fixes PR1017 and it's dependent bugs. CFE part

will follow.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36435 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov
2007-04-25 14:27:10 +00:00
parent 24a3cc4c83
commit 8b0a8c84da
22 changed files with 552 additions and 52 deletions
+12 -1
View File
@@ -62,7 +62,8 @@ bool GlobalDCE::runOnModule(Module &M) {
GlobalIsNeeded(I);
}
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
Changed |= RemoveUnusedGlobalValue(*I);
// Externally visible & appending globals are needed, if they have an
// initializer.
@@ -72,6 +73,13 @@ bool GlobalDCE::runOnModule(Module &M) {
}
for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I) {
Changed |= RemoveUnusedGlobalValue(*I);
// Aliases are always needed even if they are not used.
GlobalIsNeeded(I);
}
// Now that all globals which are needed are in the AliveGlobals set, we loop
// through the program, deleting those which are not alive.
//
@@ -135,6 +143,9 @@ void GlobalDCE::GlobalIsNeeded(GlobalValue *G) {
// referenced by the initializer to the alive set.
if (GV->hasInitializer())
MarkUsedGlobalsAsNeeded(GV->getInitializer());
} else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(G)) {
// If this is a global alias we also need it's aliasee
GlobalIsNeeded(const_cast<GlobalValue*>(GA->getAliasee()));
} else {
// Otherwise this must be a function object. We have to scan the body of
// the function looking for constants and global values which are used as