mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-31 08:16:47 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -130,8 +130,8 @@ static bool ResolveFunctions(Module &M, vector<GlobalValue*> &Globals, | |||||||
|       // |       // | ||||||
|       for (unsigned i = 0; i < OldMT->getParamTypes().size(); ++i) |       for (unsigned i = 0; i < OldMT->getParamTypes().size(); ++i) | ||||||
|         if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) { |         if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) { | ||||||
|           cerr << "Parameter types conflict for" << OldMT |           cerr << "Parameter types conflict for: '" << OldMT | ||||||
|                << " and " << ConcreteMT; |                << "' and '" << ConcreteMT << "'\n"; | ||||||
|           return Changed; |           return Changed; | ||||||
|         } |         } | ||||||
|        |        | ||||||
| @@ -231,31 +231,24 @@ static bool ProcessGlobalsWithSameName(Module &M, | |||||||
|       return false;                 // Don't know how to handle this, bail out! |       return false;                 // Don't know how to handle this, bail out! | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Ignore globals that are never used so they don't cause spurious |     if (isFunction) { | ||||||
|     // 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) { |  | ||||||
|       // For functions, we look to merge functions definitions of "int (...)" |       // For functions, we look to merge functions definitions of "int (...)" | ||||||
|       // to 'int (int)' or 'int ()' or whatever else is not completely generic. |       // to 'int (int)' or 'int ()' or whatever else is not completely generic. | ||||||
|       // |       // | ||||||
|       Function *F = cast<Function>(Globals[i]); |       Function *F = cast<Function>(Globals[i]); | ||||||
|       if (!F->isExternal()) { |       if (!F->isExternal()) { | ||||||
|         if (Concrete) |         if (Concrete && !Concrete->isExternal()) | ||||||
|           return false;   // Found two different functions types.  Can't choose! |           return false;   // Found two different functions types.  Can't choose! | ||||||
|          |          | ||||||
|         Concrete = Globals[i]; |         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; |       ++i; | ||||||
|     } else { |     } else { | ||||||
| @@ -342,5 +335,30 @@ bool FunctionResolvingPass::run(Module &M) { | |||||||
|          E = Globals.end(); I != E; ++I) |          E = Globals.end(); I != E; ++I) | ||||||
|     Changed |= ProcessGlobalsWithSameName(M, I->second); |     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; |   return Changed; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user