aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/FunctionResolution.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-11-10 03:36:55 +0000
committerChris Lattner <sabre@nondot.org>2002-11-10 03:36:55 +0000
commita2b8d7bff28bcee2b375ca74dca53f12218ff2b6 (patch)
tree6f0ca2be3824ae0fb7efc90619f666bcdd272125 /lib/Transforms/IPO/FunctionResolution.cpp
parent48e989e9021f04af6d7ca5f12bf372778ba7e9eb (diff)
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
Diffstat (limited to 'lib/Transforms/IPO/FunctionResolution.cpp')
-rw-r--r--lib/Transforms/IPO/FunctionResolution.cpp56
1 files changed, 37 insertions, 19 deletions
diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp
index 8ff786ecef..cbcfa2aba8 100644
--- a/lib/Transforms/IPO/FunctionResolution.cpp
+++ b/lib/Transforms/IPO/FunctionResolution.cpp
@@ -130,8 +130,8 @@ static bool ResolveFunctions(Module &M, vector<GlobalValue*> &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<Function>(Globals[i]));
- ++NumResolved;
- } else {
- M.getGlobalList().erase(cast<GlobalVariable>(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<Function>(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<Function>(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;
}