From 781e6f5f894175a48e21c7b9d443616a7428f1f7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 29 Jul 2002 21:24:10 +0000 Subject: Seperate analysis wrapper stuff to AnalysisWrappers.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3127 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/analyze/AnalysisWrappers.cpp | 101 +++++++++++++++++++++++++++++++ tools/analyze/analyze.cpp | 120 ------------------------------------- tools/opt/AnalysisWrappers.cpp | 101 +++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 120 deletions(-) create mode 100644 tools/analyze/AnalysisWrappers.cpp create mode 100644 tools/opt/AnalysisWrappers.cpp (limited to 'tools') diff --git a/tools/analyze/AnalysisWrappers.cpp b/tools/analyze/AnalysisWrappers.cpp new file mode 100644 index 0000000000..db69517fab --- /dev/null +++ b/tools/analyze/AnalysisWrappers.cpp @@ -0,0 +1,101 @@ +//===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===// +// +// This file defines pass wrappers around LLVM analyses that don't make sense to +// be passes. It provides a nice standard pass interface to these classes so +// that they can be printed out by analyze. +// +// These classes are seperated out of analyze.cpp so that it is more clear which +// code is the integral part of the analyze tool, and which part of the code is +// just making it so more passes are available. +// +//===----------------------------------------------------------------------===// + +#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" + +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"); + + struct IndVars : public FunctionPass { + Function *F; + LoopInfo *LI; + virtual bool runOnFunction(Function &Func) { + F = &Func; LI = &getAnalysis(); + return false; + } + + 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); + } + } + + void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(LoopInfo::ID); + AU.setPreservesAll(); + } + }; + + RegisterAnalysis P6("indvars", "Induction Variable Analysis"); + + + struct Exprs : public FunctionPass { + Function *F; + virtual bool runOnFunction(Function &Func) { F = &Func; return false; } + + 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; + analysis::ExprType R = analysis::ClassifyExpression(*I); + if (R.Var == *I) continue; // Doesn't tell us anything + + OS << "\t\tExpr ="; + switch (R.ExprTy) { + case analysis::ExprType::ScaledLinear: + WriteAsOperand(OS << "(", (Value*)R.Scale) << " ) *"; + // fall through + case analysis::ExprType::Linear: + WriteAsOperand(OS << "(", R.Var) << " )"; + if (R.Offset == 0) break; + else OS << " +"; + // fall through + case analysis::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(); + } + }; + + RegisterAnalysis P7("exprs", "Expression Printer"); +} diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp index d9423e4c65..cc3a478082 100644 --- a/tools/analyze/analyze.cpp +++ b/tools/analyze/analyze.cpp @@ -11,132 +11,12 @@ //===----------------------------------------------------------------------===// #include "llvm/Module.h" -#include "llvm/iPHINode.h" -#include "llvm/Type.h" #include "llvm/PassManager.h" #include "llvm/Bytecode/Reader.h" #include "llvm/Assembly/Parser.h" -#include "llvm/Assembly/PrintModulePass.h" -#include "llvm/Assembly/Writer.h" -#include "llvm/Analysis/InstForest.h" -#include "llvm/Analysis/Expressions.h" -#include "llvm/Analysis/InductionVariable.h" -#include "llvm/Support/InstIterator.h" #include "llvm/Support/PassNameParser.h" #include -using std::ostream; - -#if 0 - -template -class PassPrinter; // Do not implement - -template -class PassPrinter : public Pass { - const AnalysisID ID; -public: - PassPrinter(AnalysisID id) : ID(id) {} - - const char *getPassName() const { return "IP Pass Printer"; } - - virtual bool run(Module &M) { - printPass(getAnalysis(ID), std::cout, M); - return false; - } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(ID); - } -}; - -template -class PassPrinter : public FunctionPass { - const AnalysisID ID; -public: - PassPrinter(AnalysisID id) : ID(id) {} - - const char *getPassName() const { return "Function Pass Printer"; } - - virtual bool runOnFunction(Function &F) { - std::cout << "Running on function '" << F.getName() << "'\n"; - printPass(getAnalysis(ID), std::cout, F); - return false; - } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(ID); - AU.setPreservesAll(); - } -}; - - -struct InstForestHelper : public FunctionPass { - const char *getPassName() const { return "InstForest Printer"; } - - void doit(Function &F) { - std::cout << InstForest(&F); - } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - } -}; - -struct IndVars : public FunctionPass { - const char *getPassName() const { return "IndVars Printer"; } - - void doit(Function &F) { - LoopInfo &LI = getAnalysis(); - 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(std::cout); - } - } - - void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(LoopInfo::ID); - AU.setPreservesAll(); - } -}; - -struct Exprs : public FunctionPass { - const char *getPassName() const { return "Expression Printer"; } - - static void doit(Function &F) { - std::cout << "Classified expressions for: " << F.getName() << "\n"; - for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { - std::cout << *I; - - if ((*I)->getType() == Type::VoidTy) continue; - analysis::ExprType R = analysis::ClassifyExpression(*I); - if (R.Var == *I) continue; // Doesn't tell us anything - - std::cout << "\t\tExpr ="; - switch (R.ExprTy) { - case analysis::ExprType::ScaledLinear: - WriteAsOperand(std::cout << "(", (Value*)R.Scale) << " ) *"; - // fall through - case analysis::ExprType::Linear: - WriteAsOperand(std::cout << "(", R.Var) << " )"; - if (R.Offset == 0) break; - else std::cout << " +"; - // fall through - case analysis::ExprType::Constant: - if (R.Offset) WriteAsOperand(std::cout, (Value*)R.Offset); - else std::cout << " 0"; - break; - } - std::cout << "\n\n"; - } - } - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - } -}; -#endif struct ModulePassPrinter : public Pass { Pass *PassToPrint; diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp new file mode 100644 index 0000000000..db69517fab --- /dev/null +++ b/tools/opt/AnalysisWrappers.cpp @@ -0,0 +1,101 @@ +//===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===// +// +// This file defines pass wrappers around LLVM analyses that don't make sense to +// be passes. It provides a nice standard pass interface to these classes so +// that they can be printed out by analyze. +// +// These classes are seperated out of analyze.cpp so that it is more clear which +// code is the integral part of the analyze tool, and which part of the code is +// just making it so more passes are available. +// +//===----------------------------------------------------------------------===// + +#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" + +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"); + + struct IndVars : public FunctionPass { + Function *F; + LoopInfo *LI; + virtual bool runOnFunction(Function &Func) { + F = &Func; LI = &getAnalysis(); + return false; + } + + 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); + } + } + + void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(LoopInfo::ID); + AU.setPreservesAll(); + } + }; + + RegisterAnalysis P6("indvars", "Induction Variable Analysis"); + + + struct Exprs : public FunctionPass { + Function *F; + virtual bool runOnFunction(Function &Func) { F = &Func; return false; } + + 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; + analysis::ExprType R = analysis::ClassifyExpression(*I); + if (R.Var == *I) continue; // Doesn't tell us anything + + OS << "\t\tExpr ="; + switch (R.ExprTy) { + case analysis::ExprType::ScaledLinear: + WriteAsOperand(OS << "(", (Value*)R.Scale) << " ) *"; + // fall through + case analysis::ExprType::Linear: + WriteAsOperand(OS << "(", R.Var) << " )"; + if (R.Offset == 0) break; + else OS << " +"; + // fall through + case analysis::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(); + } + }; + + RegisterAnalysis P7("exprs", "Expression Printer"); +} -- cgit v1.2.3