llvm.org GIT mirror llvm / 4cb766a
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 Chris Lattner 16 years ago
1 changed file(s) with 18 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1919
2020 #include "llvm/Transforms/IPO.h"
2121 #include "llvm/Module.h"
22 #include "llvm/SymbolTable.h"
2322 #include "llvm/DerivedTypes.h"
2423 #include "llvm/Pass.h"
2524 #include "llvm/iOther.h"
136135 bool isFunction = isa(Globals[0]); // Is this group all functions?
137136 GlobalValue *Concrete = 0; // The most concrete implementation to resolve to
138137
139 assert((isFunction ^ isa(Globals[0])) &&
140 "Should either be function or gvar!");
141
142138 for (unsigned i = 0; i != Globals.size(); ) {
143139 if (isa(Globals[i]) != isFunction) {
144140 std::cerr << "WARNING: Found function and global variable with the "
242238 }
243239
244240 bool FunctionResolvingPass::run(Module &M) {
245 SymbolTable &ST = M.getSymbolTable();
246
247241 std::map > Globals;
248242
249 // Loop over the entries in the symbol table. If an entry is a func pointer,
250 // then add it to the Functions map. We do a two pass algorithm here to avoid
251 // problems with iterators getting invalidated if we did a one pass scheme.
243 // Loop over the globals, adding them to the Globals map. We use a two pass
244 // algorithm here to avoid problems with iterators getting invalidated if we
245 // did a one pass scheme.
252246 //
253 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I)
254 if (const PointerType *PT = dyn_cast(I->first)) {
255 SymbolTable::VarMap &Plane = I->second;
256 for (SymbolTable::type_iterator PI = Plane.begin(), PE = Plane.end();
257 PI != PE; ++PI) {
258 GlobalValue *GV = cast(PI->second);
259 assert(PI->first == GV->getName() &&
260 "Global name and symbol table do not agree!");
261 if (!GV->hasInternalLinkage())
262 Globals[PI->first].push_back(GV);
263 }
264 }
247 for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
248 Function *F = I++;
249 if (F->use_empty() && F->isExternal())
250 M.getFunctionList().erase(F);
251 else if (!F->hasInternalLinkage() && !F->getName().empty())
252 Globals[F->getName()].push_back(F);
253 }
254
255 for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ) {
256 GlobalVariable *GV = I++;
257 if (GV->use_empty() && GV->isExternal())
258 M.getGlobalList().erase(GV);
259 else if (!GV->hasInternalLinkage() && !GV->getName().empty())
260 Globals[GV->getName()].push_back(GV);
261 }
265262
266263 bool Changed = false;
267264