X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fopt%2FAnalysisWrappers.cpp;h=4bdc268f8d7594d54bb0b6e5ba9b1c23e38556b8;hb=a37512049cdc8adc0e6fa034095c8afe514ef24d;hp=94cca50d63d1f310c10b6ae95ad9c4ac2299bbd0;hpb=3ee8fc964952a65bcb3668b85938c46f90631e42;p=oota-llvm.git diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp index 94cca50d63d..4bdc268f8d7 100644 --- a/tools/opt/AnalysisWrappers.cpp +++ b/tools/opt/AnalysisWrappers.cpp @@ -17,11 +17,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Module.h" -#include "llvm/Pass.h" -#include "llvm/Support/CallSite.h" #include "llvm/Analysis/CallGraph.h" -#include +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Module.h" +#include "llvm/Pass.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { @@ -31,58 +31,63 @@ namespace { /// or handle in alias analyses. struct ExternalFunctionsPassedConstants : public ModulePass { static char ID; // Pass ID, replacement for typeid - ExternalFunctionsPassedConstants() : ModulePass((intptr_t)&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; - } - } + ExternalFunctionsPassedConstants() : ModulePass(ID) {} + bool runOnModule(Module &M) override { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + if (!I->isDeclaration()) continue; + + bool PrintedFn = false; + for (User *U : I->users()) { + Instruction *UI = dyn_cast(U); + if (!UI) continue; + + CallSite CS(cast(UI)); + 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() << *UI; + break; + } } + } return false; } - virtual void getAnalysisUsage(AnalysisUsage &AU) const { + void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); } }; +} - char ExternalFunctionsPassedConstants::ID = 0; - RegisterPass +char ExternalFunctionsPassedConstants::ID = 0; +static RegisterPass P1("print-externalfnconstants", "Print external fn callsites passed constants"); +namespace { struct CallGraphPrinter : public ModulePass { static char ID; // Pass ID, replacement for typeid - CallGraphPrinter() : ModulePass((intptr_t)&ID) {} + CallGraphPrinter() : ModulePass(ID) {} - virtual void getAnalysisUsage(AnalysisUsage &AU) const { + void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); - AU.addRequiredTransitive(); + AU.addRequiredTransitive(); } - virtual bool runOnModule(Module &M) { - getAnalysis().print(std::cerr, &M); + bool runOnModule(Module &M) override { + getAnalysis().print(errs(), &M); return false; } }; - - char CallGraphPrinter::ID = 0; - RegisterPass - P2("print-callgraph", "Print a call graph"); } + +char CallGraphPrinter::ID = 0; +static RegisterPass + P2("print-callgraph", "Print a call graph");