From a2b8d7bff28bcee2b375ca74dca53f12218ff2b6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 10 Nov 2002 03:36:55 +0000 Subject: [PATCH] Fix testcase: FunctionResolve/2002-11-09-ExternFn.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4668 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/FunctionResolution.cpp | 56 +++++++++++++++-------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp index 8ff786ecef2..cbcfa2aba85 100644 --- a/lib/Transforms/IPO/FunctionResolution.cpp +++ b/lib/Transforms/IPO/FunctionResolution.cpp @@ -130,8 +130,8 @@ static bool ResolveFunctions(Module &M, vector &Globals, // for (unsigned i = 0; i < OldMT->getParamTypes().size(); ++i) if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) { - cerr << "Parameter types conflict for" << OldMT - << " and " << ConcreteMT; + cerr << "Parameter types conflict for: '" << OldMT + << "' and '" << ConcreteMT << "'\n"; return Changed; } @@ -231,31 +231,24 @@ static bool ProcessGlobalsWithSameName(Module &M, return false; // Don't know how to handle this, bail out! } - // Ignore globals that are never used so they don't cause spurious - // warnings... here we will actually DCE the function so that it isn't used - // later. - // - if (Globals[i]->isExternal() && Globals[i]->use_empty()) { - if (isFunction) { - M.getFunctionList().erase(cast(Globals[i])); - ++NumResolved; - } else { - M.getGlobalList().erase(cast(Globals[i])); - ++NumGlobals; - } - - Globals.erase(Globals.begin()+i); - Changed = true; - } else if (isFunction) { + if (isFunction) { // For functions, we look to merge functions definitions of "int (...)" // to 'int (int)' or 'int ()' or whatever else is not completely generic. // Function *F = cast(Globals[i]); if (!F->isExternal()) { - if (Concrete) + if (Concrete && !Concrete->isExternal()) return false; // Found two different functions types. Can't choose! Concrete = Globals[i]; + } else if (Concrete) { + if (Concrete->isExternal()) // If we have multiple external symbols...x + if (F->getFunctionType()->getNumParams() > + cast(Concrete)->getFunctionType()->getNumParams()) + Concrete = F; // We are more concrete than "Concrete"! + + } else { + Concrete = F; } ++i; } else { @@ -342,5 +335,30 @@ bool FunctionResolvingPass::run(Module &M) { E = Globals.end(); I != E; ++I) Changed |= ProcessGlobalsWithSameName(M, I->second); + // Now loop over all of the globals, checking to see if any are trivially + // dead. If so, remove them now. + + for (Module::iterator I = M.begin(), E = M.end(); I != E; ) + if (I->isExternal() && I->use_empty()) { + Function *F = I; + ++I; + M.getFunctionList().erase(F); + ++NumResolved; + Changed = true; + } else { + ++I; + } + + for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ) + if (I->isExternal() && I->use_empty()) { + GlobalVariable *GV = I; + ++I; + M.getGlobalList().erase(GV); + ++NumGlobals; + Changed = true; + } else { + ++I; + } + return Changed; }