X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fopt%2FAnalysisWrappers.cpp;h=55f544ff5e5c1ff8ae42798db431d3cc151006e2;hb=b8e48a636e7ee6c13140382eb93d9695a65b0624;hp=f48d5afe297db2ef8528d210527f78c915aae21f;hpb=86f42bdad93677fa0ca33b27afb0f493028376cb;p=oota-llvm.git diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp index f48d5afe297..55f544ff5e5 100644 --- a/tools/opt/AnalysisWrappers.cpp +++ b/tools/opt/AnalysisWrappers.cpp @@ -1,10 +1,10 @@ //===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===// -// +// // 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. +// //===----------------------------------------------------------------------===// // // This file defines pass wrappers around LLVM analyses that don't make sense to @@ -17,70 +17,78 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Module.h" +#include "llvm/Analysis/CallGraph.h" +#include "llvm/IR/Module.h" #include "llvm/Pass.h" -#include "llvm/Analysis/InstForest.h" #include "llvm/Support/CallSite.h" -#include - +#include "llvm/Support/raw_ostream.h" using namespace llvm; -namespace { - struct InstForestHelper : public FunctionPass { - Function *F; - virtual bool runOnFunction(Function &Func) { F = &Func; return false; } - - void print(std::ostream &OS) const { - std::cout << InstForest(F); - } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - } - }; - - RegisterAnalysis P1("instforest", "InstForest Printer"); -} - namespace { /// ExternalFunctionsPassedConstants - This pass prints out call sites to /// external functions that are called with constant arguments. This can be /// useful when looking for standard library functions we should constant fold /// or handle in alias analyses. - struct ExternalFunctionsPassedConstants : public Pass { - virtual bool run(Module &M) { - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (I->isExternal()) { - 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) || isa(*AI)) { - if (!PrintedFn) { - std::cerr << "Function '" << I->getName() << "':\n"; - PrintedFn = true; - } - std::cerr << *User; - break; - } - } + struct ExternalFunctionsPassedConstants : public ModulePass { + 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()) 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; } - void print(std::ostream &OS) const {} - virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); } }; +} + +char ExternalFunctionsPassedConstants::ID = 0; +static RegisterPass + P1("print-externalfnconstants", + "Print external fn callsites passed constants"); - RegisterAnalysis - P2("externalfnconstants", "Print external fn callsites passed constants"); +namespace { + struct CallGraphPrinter : public ModulePass { + static char ID; // Pass ID, replacement for typeid + CallGraphPrinter() : ModulePass(ID) {} + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + AU.addRequiredTransitive(); + } + virtual bool runOnModule(Module &M) { + getAnalysis().print(errs(), &M); + return false; + } + }; } + +char CallGraphPrinter::ID = 0; +static RegisterPass + P2("print-callgraph", "Print a call graph");