X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fopt%2FAnalysisWrappers.cpp;h=4bdc268f8d7594d54bb0b6e5ba9b1c23e38556b8;hb=80c55f265d1a68b7f03845a3e9356447f7d258c8;hp=aa9f03d88388202c77712dd17013af93afef9045;hpb=04eaef28a8bc1e530a55c18dab0785f7d1dff640;p=oota-llvm.git diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp index aa9f03d8838..4bdc268f8d7 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,24 +17,77 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/CallGraph.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Module.h" #include "llvm/Pass.h" -#include "llvm/Analysis/InstForest.h" - +#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; } + /// 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 ModulePass { + static char ID; // Pass ID, replacement for typeid + 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; - void print(std::ostream &OS) const { - std::cout << InstForest(F); + 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(); } }; +} - RegisterAnalysis P1("instforest", "InstForest Printer"); +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(ID) {} + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesAll(); + AU.addRequiredTransitive(); + } + bool runOnModule(Module &M) override { + getAnalysis().print(errs(), &M); + return false; + } + }; } + +char CallGraphPrinter::ID = 0; +static RegisterPass + P2("print-callgraph", "Print a call graph");