X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fopt%2FAnalysisWrappers.cpp;h=b94902692b0d901255dba445d8b1cd5f45062582;hb=ccbfd5b18a79a07229f11af478843eae16ac9b26;hp=89945f76ed353d55b3b4422bb1089a1a27d878bc;hpb=ac1ccae982d9e718ef1234baa4f0255d5d3a64f3;p=oota-llvm.git diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp index 89945f76ed3..b94902692b0 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,94 +17,78 @@ // //===----------------------------------------------------------------------===// -#include "llvm/iPHINode.h" -#include "llvm/Type.h" -#include "llvm/Assembly/Writer.h" -#include "llvm/Analysis/InstForest.h" -#include "llvm/Analysis/Expressions.h" -#include "llvm/Analysis/InductionVariable.h" -#include "llvm/Analysis/LoopInfo.h" -#include "llvm/Support/InstIterator.h" - +#include "llvm/Analysis/CallGraph.h" +#include "llvm/IR/Module.h" +#include "llvm/Pass.h" +#include "llvm/Support/CallSite.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) {} + virtual bool runOnModule(Module &M) { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + if (!I->isDeclaration()) continue; - void print(std::ostream &OS) const { - std::cout << InstForest(F); - } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - } - }; + 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; - RegisterAnalysis P1("instforest", "InstForest Printer"); + CallSite CS(cast(User)); + if (!CS) continue; - struct IndVars : public FunctionPass { - Function *F; - LoopInfo *LI; - virtual bool runOnFunction(Function &Func) { - F = &Func; LI = &getAnalysis(); - return false; - } + for (CallSite::arg_iterator AI = CS.arg_begin(), + E = CS.arg_end(); AI != E; ++AI) { + if (!isa(*AI)) continue; - void print(std::ostream &OS) const { - for (inst_iterator I = inst_begin(*F), E = inst_end(*F); I != E; ++I) - if (PHINode *PN = dyn_cast(*I)) { - InductionVariable IV(PN, LI); - if (IV.InductionType != InductionVariable::Unknown) - IV.print(OS); + if (!PrintedFn) { + errs() << "Function '" << I->getName() << "':\n"; + PrintedFn = true; + } + errs() << *User; + break; + } } + } + + return false; } - - void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(); + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); } }; +} - RegisterAnalysis P6("indvars", "Induction Variable Analysis"); - +char ExternalFunctionsPassedConstants::ID = 0; +static RegisterPass + P1("print-externalfnconstants", + "Print external fn callsites passed constants"); - struct Exprs : public FunctionPass { - Function *F; - virtual bool runOnFunction(Function &Func) { F = &Func; return false; } +namespace { + struct CallGraphPrinter : public ModulePass { + static char ID; // Pass ID, replacement for typeid + CallGraphPrinter() : ModulePass(ID) {} - void print(std::ostream &OS) const { - OS << "Classified expressions for: " << F->getName() << "\n"; - for (inst_iterator I = inst_begin(*F), E = inst_end(*F); I != E; ++I) { - OS << *I; - - if ((*I)->getType() == Type::VoidTy) continue; - ExprType R = ClassifyExpr(*I); - if (R.Var == *I) continue; // Doesn't tell us anything - - OS << "\t\tExpr ="; - switch (R.ExprTy) { - case ExprType::ScaledLinear: - WriteAsOperand(OS << "(", (Value*)R.Scale) << " ) *"; - // fall through - case ExprType::Linear: - WriteAsOperand(OS << "(", R.Var) << " )"; - if (R.Offset == 0) break; - else OS << " +"; - // fall through - case ExprType::Constant: - if (R.Offset) WriteAsOperand(OS, (Value*)R.Offset); - else OS << " 0"; - break; - } - OS << "\n\n"; - } - } virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); + AU.addRequiredTransitive(); + } + virtual bool runOnModule(Module &M) { + getAnalysis().print(errs(), &M); + return false; } }; - - RegisterAnalysis P7("exprs", "Expression Printer"); } + +char CallGraphPrinter::ID = 0; +static RegisterPass + P2("print-callgraph", "Print a call graph");