X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fopt%2FAnalysisWrappers.cpp;h=b94902692b0d901255dba445d8b1cd5f45062582;hb=ccbfd5b18a79a07229f11af478843eae16ac9b26;hp=a13695daef442c673e9c82444e1c0d00df86fe56;hpb=794fd75c67a2cdc128d67342c6d88a504d186896;p=oota-llvm.git diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp index a13695daef4..b94902692b0 100644 --- a/tools/opt/AnalysisWrappers.cpp +++ b/tools/opt/AnalysisWrappers.cpp @@ -2,8 +2,8 @@ // // 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. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -17,11 +17,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Module.h" +#include "llvm/Analysis/CallGraph.h" +#include "llvm/IR/Module.h" #include "llvm/Pass.h" #include "llvm/Support/CallSite.h" -#include "llvm/Analysis/CallGraph.h" -#include +#include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { @@ -30,30 +30,34 @@ namespace { /// useful when looking for standard library functions we should constant fold /// or handle in alias analyses. struct ExternalFunctionsPassedConstants : public ModulePass { - static const int ID; // Pass ID, replacement for typeid - ExternalFunctionsPassedConstants() : ModulePass((intptr_t)&ID) {} + static char ID; // Pass ID, replacement for typeid + ExternalFunctionsPassedConstants() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (I->isDeclaration()) { - bool PrintedFn = false; - for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); - UI != E; ++UI) - if (Instruction *User = dyn_cast(*UI)) { - CallSite CS = CallSite::get(User); - if (CS.getInstruction()) { - for (CallSite::arg_iterator AI = CS.arg_begin(), - E = CS.arg_end(); AI != E; ++AI) - if (isa(*AI)) { - if (!PrintedFn) { - std::cerr << "Function '" << I->getName() << "':\n"; - PrintedFn = true; - } - std::cerr << *User; - break; - } - } + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + if (!I->isDeclaration()) continue; + + bool PrintedFn = false; + for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); + UI != E; ++UI) { + Instruction *User = dyn_cast(*UI); + if (!User) continue; + + CallSite CS(cast(User)); + if (!CS) continue; + + for (CallSite::arg_iterator AI = CS.arg_begin(), + E = CS.arg_end(); AI != E; ++AI) { + if (!isa(*AI)) continue; + + if (!PrintedFn) { + errs() << "Function '" << I->getName() << "':\n"; + PrintedFn = true; } + errs() << *User; + break; + } } + } return false; } @@ -62,27 +66,29 @@ namespace { AU.setPreservesAll(); } }; +} - const int ExternalFunctionsPassedConstants::ID = 0; - RegisterPass - P1("externalfnconstants", "Print external fn callsites passed constants"); - +char ExternalFunctionsPassedConstants::ID = 0; +static RegisterPass + P1("print-externalfnconstants", + "Print external fn callsites passed constants"); + +namespace { struct CallGraphPrinter : public ModulePass { - static const int ID; // Pass ID, replacement for typeid - CallGraphPrinter() : ModulePass((intptr_t)&ID) {} + static char ID; // Pass ID, replacement for typeid + CallGraphPrinter() : ModulePass(ID) {} virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); - AU.addRequiredTransitive(); + AU.addRequiredTransitive(); } - virtual bool runOnModule(Module &M) { return false; } - - virtual void print(std::ostream &OS, const Module *M) const { - getAnalysis().print(OS, M); + virtual bool runOnModule(Module &M) { + getAnalysis().print(errs(), &M); + return false; } }; - - const int CallGraphPrinter::ID = 0; - RegisterPass - P2("callgraph", "Print a call graph"); } + +char CallGraphPrinter::ID = 0; +static RegisterPass + P2("print-callgraph", "Print a call graph");