Loop over the module, not the symbol table. This makes the code handle

unused external functions again


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9365 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-10-22 04:42:20 +00:00
parent 20678b96ea
commit 4cb766af4a

View File

@@ -20,7 +20,6 @@
#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/SymbolTable.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/iOther.h" #include "llvm/iOther.h"
@@ -137,9 +136,6 @@ static bool ProcessGlobalsWithSameName(Module &M, TargetData &TD,
bool isFunction = isa<Function>(Globals[0]); // Is this group all functions? bool isFunction = isa<Function>(Globals[0]); // Is this group all functions?
GlobalValue *Concrete = 0; // The most concrete implementation to resolve to GlobalValue *Concrete = 0; // The most concrete implementation to resolve to
assert((isFunction ^ isa<GlobalVariable>(Globals[0])) &&
"Should either be function or gvar!");
for (unsigned i = 0; i != Globals.size(); ) { for (unsigned i = 0; i != Globals.size(); ) {
if (isa<Function>(Globals[i]) != isFunction) { if (isa<Function>(Globals[i]) != isFunction) {
std::cerr << "WARNING: Found function and global variable with the " std::cerr << "WARNING: Found function and global variable with the "
@@ -243,26 +239,27 @@ static bool ProcessGlobalsWithSameName(Module &M, TargetData &TD,
} }
bool FunctionResolvingPass::run(Module &M) { bool FunctionResolvingPass::run(Module &M) {
SymbolTable &ST = M.getSymbolTable();
std::map<std::string, std::vector<GlobalValue*> > Globals; std::map<std::string, std::vector<GlobalValue*> > Globals;
// Loop over the entries in the symbol table. If an entry is a func pointer, // Loop over the globals, adding them to the Globals map. We use a two pass
// then add it to the Functions map. We do a two pass algorithm here to avoid // algorithm here to avoid problems with iterators getting invalidated if we
// problems with iterators getting invalidated if we did a one pass scheme. // did a one pass scheme.
// //
for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
if (const PointerType *PT = dyn_cast<PointerType>(I->first)) { Function *F = I++;
SymbolTable::VarMap &Plane = I->second; if (F->use_empty() && F->isExternal())
for (SymbolTable::type_iterator PI = Plane.begin(), PE = Plane.end(); M.getFunctionList().erase(F);
PI != PE; ++PI) { else if (!F->hasInternalLinkage() && !F->getName().empty())
GlobalValue *GV = cast<GlobalValue>(PI->second); Globals[F->getName()].push_back(F);
assert(PI->first == GV->getName() && }
"Global name and symbol table do not agree!");
if (!GV->hasInternalLinkage()) for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ) {
Globals[PI->first].push_back(GV); GlobalVariable *GV = I++;
} if (GV->use_empty() && GV->isExternal())
} M.getGlobalList().erase(GV);
else if (!GV->hasInternalLinkage() && !GV->getName().empty())
Globals[GV->getName()].push_back(GV);
}
bool Changed = false; bool Changed = false;