From 4cb766af4a3ca51dd798608f8efb19c19ed5d2b5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 22 Oct 2003 04:42:20 +0000 Subject: [PATCH] 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 --- lib/Transforms/IPO/FunctionResolution.cpp | 39 +++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp index 5030e26dc5e..844bc0027d1 100644 --- a/lib/Transforms/IPO/FunctionResolution.cpp +++ b/lib/Transforms/IPO/FunctionResolution.cpp @@ -20,7 +20,6 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Module.h" -#include "llvm/SymbolTable.h" #include "llvm/DerivedTypes.h" #include "llvm/Pass.h" #include "llvm/iOther.h" @@ -137,9 +136,6 @@ static bool ProcessGlobalsWithSameName(Module &M, TargetData &TD, bool isFunction = isa(Globals[0]); // Is this group all functions? GlobalValue *Concrete = 0; // The most concrete implementation to resolve to - assert((isFunction ^ isa(Globals[0])) && - "Should either be function or gvar!"); - for (unsigned i = 0; i != Globals.size(); ) { if (isa(Globals[i]) != isFunction) { 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) { - SymbolTable &ST = M.getSymbolTable(); - std::map > Globals; - // Loop over the entries in the symbol table. If an entry is a func pointer, - // then add it to the Functions map. We do a two pass algorithm here to avoid - // problems with iterators getting invalidated if we did a one pass scheme. + // Loop over the globals, adding them to the Globals map. We use a two pass + // algorithm here to avoid problems with iterators getting invalidated if we + // did a one pass scheme. // - for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) - if (const PointerType *PT = dyn_cast(I->first)) { - SymbolTable::VarMap &Plane = I->second; - for (SymbolTable::type_iterator PI = Plane.begin(), PE = Plane.end(); - PI != PE; ++PI) { - GlobalValue *GV = cast(PI->second); - assert(PI->first == GV->getName() && - "Global name and symbol table do not agree!"); - if (!GV->hasInternalLinkage()) - Globals[PI->first].push_back(GV); - } - } + for (Module::iterator I = M.begin(), E = M.end(); I != E; ) { + Function *F = I++; + if (F->use_empty() && F->isExternal()) + M.getFunctionList().erase(F); + else if (!F->hasInternalLinkage() && !F->getName().empty()) + Globals[F->getName()].push_back(F); + } + + for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ) { + 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; -- 2.34.1