//===- FunctionResolution.cpp - Resolve declarations to implementations ---===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// Loop over the functions that are in the module and look for functions that
using namespace llvm;
namespace {
- Statistic<>NumResolved("funcresolve", "Number of varargs functions resolved");
- Statistic<> NumGlobals("funcresolve", "Number of global variables resolved");
+ Statistic NumResolved("funcresolve", "Number of varargs functions resolved");
+ Statistic NumGlobals("funcresolve", "Number of global variables resolved");
- struct FunctionResolvingPass : public Pass {
+ struct FunctionResolvingPass : public ModulePass {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>();
}
- bool run(Module &M);
+ bool runOnModule(Module &M);
};
- RegisterOpt<FunctionResolvingPass> X("funcresolve", "Resolve Functions");
+ RegisterPass<FunctionResolvingPass> X("funcresolve", "Resolve Functions");
}
-Pass *llvm::createFunctionResolvingPass() {
+ModulePass *llvm::createFunctionResolvingPass() {
return new FunctionResolvingPass();
}
for (unsigned i = 0; i != Globals.size(); ++i)
if (Globals[i] != Concrete) {
Function *Old = cast<Function>(Globals[i]);
- const FunctionType *OldMT = Old->getFunctionType();
- const FunctionType *ConcreteMT = Concrete->getFunctionType();
-
- if (OldMT->getNumParams() > ConcreteMT->getNumParams() &&
- !ConcreteMT->isVarArg())
+ const FunctionType *OldFT = Old->getFunctionType();
+ const FunctionType *ConcreteFT = Concrete->getFunctionType();
+
+ if (OldFT->getNumParams() > ConcreteFT->getNumParams() &&
+ !ConcreteFT->isVarArg())
if (!Old->use_empty()) {
- std::cerr << "WARNING: Linking function '" << Old->getName()
- << "' is causing arguments to be dropped.\n";
- std::cerr << "WARNING: Prototype: ";
- WriteAsOperand(std::cerr, Old);
- std::cerr << " resolved to ";
- WriteAsOperand(std::cerr, Concrete);
- std::cerr << "\n";
+ cerr << "WARNING: Linking function '" << Old->getName()
+ << "' is causing arguments to be dropped.\n";
+ cerr << "WARNING: Prototype: ";
+ WriteAsOperand(*cerr.stream(), Old);
+ cerr << " resolved to ";
+ WriteAsOperand(*cerr.stream(), Concrete);
+ cerr << "\n";
}
-
+
// Check to make sure that if there are specified types, that they
// match...
//
- unsigned NumArguments = std::min(OldMT->getNumParams(),
- ConcreteMT->getNumParams());
+ unsigned NumArguments = std::min(OldFT->getNumParams(),
+ ConcreteFT->getNumParams());
if (!Old->use_empty() && !Concrete->use_empty())
for (unsigned i = 0; i < NumArguments; ++i)
- if (OldMT->getParamType(i) != ConcreteMT->getParamType(i))
- if (OldMT->getParamType(i)->getTypeID() !=
- ConcreteMT->getParamType(i)->getTypeID()) {
- std::cerr << "WARNING: Function [" << Old->getName()
- << "]: Parameter types conflict for: '";
- WriteTypeSymbolic(std::cerr, OldMT, &M);
- std::cerr << "' and '";
- WriteTypeSymbolic(std::cerr, ConcreteMT, &M);
- std::cerr << "'\n";
+ if (OldFT->getParamType(i) != ConcreteFT->getParamType(i))
+ if (OldFT->getParamType(i)->getTypeID() !=
+ ConcreteFT->getParamType(i)->getTypeID()) {
+ cerr << "WARNING: Function [" << Old->getName()
+ << "]: Parameter types conflict for: '";
+ WriteTypeSymbolic(*cerr.stream(), OldFT, &M);
+ cerr << "' (in "
+ << Old->getParent()->getModuleIdentifier() << ") and '";
+ WriteTypeSymbolic(*cerr.stream(), ConcreteFT, &M);
+ cerr << "'(in "
+ << Concrete->getParent()->getModuleIdentifier() << ")\n";
return Changed;
}
-
+
// Attempt to convert all of the uses of the old function to the concrete
// form of the function. If there is a use of the fn that we don't
// understand here we punt to avoid making a bad transformation.
// functions and that the Old function has no varargs fns specified. In
// otherwords it's just <retty> (...)
//
- if (!Old->use_empty()) { // Avoid making the CPR unless we really need it
+ if (!Old->use_empty()) {
Value *Replacement = Concrete;
if (Concrete->getType() != Old->getType())
- Replacement = ConstantExpr::getCast(Concrete,Old->getType());
- NumResolved += Old->use_size();
+ Replacement = ConstantExpr::getCast(Concrete, Old->getType());
+ NumResolved += Old->getNumUses();
Old->replaceAllUsesWith(Replacement);
}
for (unsigned i = 0; i != Globals.size(); ) {
if (isa<Function>(Globals[i]) != isFunction) {
- std::cerr << "WARNING: Found function and global variable with the "
- << "same name: '" << Globals[i]->getName() << "'.\n";
+ cerr << "WARNING: Found function and global variable with the "
+ << "same name: '" << Globals[i]->getName() << "'.\n";
return false; // Don't know how to handle this, bail out!
}
if (!F->isExternal()) {
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...
- if (F->getFunctionType()->getNumParams() >
+ if (F->getFunctionType()->getNumParams() >
cast<Function>(Concrete)->getFunctionType()->getNumParams())
Concrete = F; // We are more concrete than "Concrete"!
GlobalVariable *GV = cast<GlobalVariable>(Globals[i]);
if (!GV->isExternal()) {
if (Concrete) {
- std::cerr << "WARNING: Two global variables with external linkage"
- << " exist with the same name: '" << GV->getName()
- << "'!\n";
+ cerr << "WARNING: Two global variables with external linkage"
+ << " exist with the same name: '" << GV->getName()
+ << "'!\n";
return false;
}
Concrete = GV;
else if (!Globals[i]->hasInternalLinkage())
NumInstancesWithExternalLinkage++;
}
-
+
if (!HasExternal && NumInstancesWithExternalLinkage <= 1)
return false; // Nothing to do? Must have multiple internal definitions.
OtherF->getFunctionType()->isVarArg() &&
OtherF->getFunctionType()->getNumParams() == 0)
DontPrintWarning = true;
-
+
// Otherwise, if the non-concrete global is a global array variable with a
// size of 0, and the concrete global is an array with a real size, don't
// warn. This occurs due to declaring 'extern int A[];'.
}
}
- if (!DontPrintWarning) {
- std::cerr << "WARNING: Found global types that are not compatible:\n";
+ if (0 && !DontPrintWarning) {
+ cerr << "WARNING: Found global types that are not compatible:\n";
for (unsigned i = 0; i < Globals.size(); ++i) {
- std::cerr << "\t";
- WriteTypeSymbolic(std::cerr, Globals[i]->getType(), &M);
- std::cerr << " %" << Globals[i]->getName() << "\n";
+ cerr << "\t";
+ WriteTypeSymbolic(*cerr.stream(), Globals[i]->getType(), &M);
+ cerr << " %" << Globals[i]->getName() << "\n";
}
}
return false;
}
-bool FunctionResolvingPass::run(Module &M) {
+bool FunctionResolvingPass::runOnModule(Module &M) {
std::map<std::string, std::vector<GlobalValue*> > Globals;
// Loop over the globals, adding them to the Globals map. We use a two pass
Globals[F->getName()].push_back(F);
}
- for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ) {
+ for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+ I != E; ) {
GlobalVariable *GV = I++;
if (GV->use_empty() && GV->isExternal()) {
M.getGlobalList().erase(GV);
++I;
}
- for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; )
+ for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+ I != E; )
if (I->isExternal() && I->use_empty()) {
GlobalVariable *GV = I;
++I;