* Rename MethodPass class to FunctionPass

- Rename runOnMethod to runOnFunction
* Transform getAnalysisUsageInfo into getAnalysisUsage
  - Method is now const
  - It now takes one AnalysisUsage object to fill in instead of 3 vectors
    to fill in
  - Pass's now specify which other passes they _preserve_ not which ones
    they modify (be conservative!)
  - A pass can specify that it preserves all analyses (because it never
    modifies the underlying program)
* s/Method/Function/g in other random places as well


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2333 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-04-27 06:56:12 +00:00
parent f2361c5e5c
commit f57b845547
62 changed files with 608 additions and 649 deletions

View File

@ -118,11 +118,10 @@ public:
// run - Compute the call graph for the specified module.
virtual bool run(Module *TheModule);
// getAnalysisUsageInfo - This obviously provides a call graph
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
Provided.push_back(ID);
// getAnalysisUsage - This obviously provides a call graph
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
// releaseMemory - Data structures can be large, so free memory agressively.

View File

@ -485,11 +485,10 @@ public:
// If the pass pipeline is done with this pass, we can release our memory...
virtual void releaseMemory();
// getAnalysisUsageInfo - This obviously provides a call graph
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
Provided.push_back(ID);
// getAnalysisUsage - This obviously provides a call graph
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
};

View File

@ -485,11 +485,10 @@ public:
// If the pass pipeline is done with this pass, we can release our memory...
virtual void releaseMemory();
// getAnalysisUsageInfo - This obviously provides a call graph
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
Provided.push_back(ID);
// getAnalysisUsage - This obviously provides a call graph
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
};

View File

@ -1,13 +1,13 @@
//===- llvm/Analysis/Dominators.h - Dominator Info Calculation ---*- C++ -*--=//
//
// This file defines the following classes:
// 1. DominatorSet: Calculates the [reverse] dominator set for a method
// 1. DominatorSet: Calculates the [reverse] dominator set for a function
// 2. ImmediateDominators: Calculates and holds a mapping between BasicBlocks
// and their immediate dominator.
// 3. DominatorTree: Represent the ImmediateDominator as an explicit tree
// structure.
// 4. DominanceFrontier: Calculate and hold the dominance frontier for a
// method.
// function.
//
// These data structures are listed in increasing order of complexity. It
// takes longer to calculate the dominator frontier, for example, than the
@ -28,7 +28,7 @@ namespace cfg {
// DominatorBase - Base class that other, more interesting dominator analyses
// inherit from.
//
class DominatorBase : public MethodPass {
class DominatorBase : public FunctionPass {
protected:
BasicBlock *Root;
const bool IsPostDominators;
@ -45,7 +45,7 @@ public:
//===----------------------------------------------------------------------===//
//
// DominatorSet - Maintain a set<const BasicBlock*> for every basic block in a
// method, that represents the blocks that dominate the block.
// function, that represents the blocks that dominate the block.
//
class DominatorSet : public DominatorBase {
public:
@ -59,14 +59,14 @@ private:
void calcPostDominatorSet(Function *F);
public:
// DominatorSet ctor - Build either the dominator set or the post-dominator
// set for a method...
// set for a function...
//
static AnalysisID ID; // Build dominator set
static AnalysisID PostDomID; // Build postdominator set
DominatorSet(AnalysisID id) : DominatorBase(id == PostDomID) {}
virtual bool runOnMethod(Function *F);
virtual bool runOnFunction(Function *F);
// Accessor interface:
typedef DomSetMapType::const_iterator const_iterator;
@ -83,7 +83,7 @@ public:
//
inline const DomSetType &getDominators(const BasicBlock *BB) const {
const_iterator I = find(BB);
assert(I != end() && "BB not in method!");
assert(I != end() && "BB not in function!");
return I->second;
}
@ -93,19 +93,17 @@ public:
return getDominators(B).count(A) != 0;
}
// getAnalysisUsageInfo - This obviously provides a dominator set, but it also
// uses the UnifyMethodExitNode pass if building post-dominators
// getAnalysisUsage - This obviously provides a dominator set, but it also
// uses the UnifyFunctionExitNode pass if building post-dominators
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
};
//===----------------------------------------------------------------------===//
//
// ImmediateDominators - Calculate the immediate dominator for each node in a
// method.
// function.
//
class ImmediateDominators : public DominatorBase {
std::map<const BasicBlock*, const BasicBlock*> IDoms;
@ -113,14 +111,14 @@ class ImmediateDominators : public DominatorBase {
public:
// ImmediateDominators ctor - Calculate the idom or post-idom mapping,
// for a method...
// for a function...
//
static AnalysisID ID; // Build immediate dominators
static AnalysisID PostDomID; // Build immediate postdominators
ImmediateDominators(AnalysisID id) : DominatorBase(id == PostDomID) {}
virtual bool runOnMethod(Function *F) {
virtual bool runOnFunction(Function *F) {
IDoms.clear(); // Reset from the last time we were run...
DominatorSet *DS;
if (isPostDominator())
@ -149,18 +147,17 @@ public:
return I != IDoms.end() ? I->second : 0;
}
// getAnalysisUsageInfo - This obviously provides a dominator tree, but it
// getAnalysisUsage - This obviously provides a dominator tree, but it
// can only do so with the input of dominator sets
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
if (isPostDominator()) {
Requires.push_back(DominatorSet::PostDomID);
Provided.push_back(PostDomID);
AU.addRequired(DominatorSet::PostDomID);
AU.addProvided(PostDomID);
} else {
Requires.push_back(DominatorSet::ID);
Provided.push_back(ID);
AU.addRequired(DominatorSet::ID);
AU.addProvided(ID);
}
}
};
@ -168,7 +165,7 @@ public:
//===----------------------------------------------------------------------===//
//
// DominatorTree - Calculate the immediate dominator tree for a method.
// DominatorTree - Calculate the immediate dominator tree for a function.
//
class DominatorTree : public DominatorBase {
class Node2;
@ -213,7 +210,7 @@ public:
DominatorTree(AnalysisID id) : DominatorBase(id == PostDomID) {}
~DominatorTree() { reset(); }
virtual bool runOnMethod(Function *F) {
virtual bool runOnFunction(Function *F) {
reset();
DominatorSet *DS;
if (isPostDominator())
@ -230,18 +227,17 @@ public:
return (i != Nodes.end()) ? i->second : 0;
}
// getAnalysisUsageInfo - This obviously provides a dominator tree, but it
// getAnalysisUsage - This obviously provides a dominator tree, but it
// uses dominator sets
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
if (isPostDominator()) {
Requires.push_back(DominatorSet::PostDomID);
Provided.push_back(PostDomID);
AU.addRequired(DominatorSet::PostDomID);
AU.addProvided(PostDomID);
} else {
Requires.push_back(DominatorSet::ID);
Provided.push_back(ID);
AU.addRequired(DominatorSet::ID);
AU.addProvided(ID);
}
}
};
@ -249,7 +245,7 @@ public:
//===----------------------------------------------------------------------===//
//
// DominanceFrontier - Calculate the dominance frontiers for a method.
// DominanceFrontier - Calculate the dominance frontiers for a function.
//
class DominanceFrontier : public DominatorBase {
public:
@ -263,14 +259,14 @@ private:
const DominatorTree::Node *Node);
public:
// DominatorFrontier ctor - Compute dominator frontiers for a method
// DominatorFrontier ctor - Compute dominator frontiers for a function
//
static AnalysisID ID; // Build dominator frontier
static AnalysisID PostDomID; // Build postdominator frontier
DominanceFrontier(AnalysisID id) : DominatorBase(id == PostDomID) {}
virtual bool runOnMethod(Function *) {
virtual bool runOnFunction(Function *) {
Frontiers.clear();
DominatorTree *DT;
if (isPostDominator())
@ -292,18 +288,17 @@ public:
inline const_iterator end() const { return Frontiers.end(); }
inline const_iterator find(const BasicBlock* B) const { return Frontiers.find(B); }
// getAnalysisUsageInfo - This obviously provides a dominator tree, but it
// getAnalysisUsage - This obviously provides the dominance frontier, but it
// uses dominator sets
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
if (isPostDominator()) {
Requires.push_back(DominatorTree::PostDomID);
Provided.push_back(PostDomID);
AU.addRequired(DominatorTree::PostDomID);
AU.addProvided(PostDomID);
} else {
Requires.push_back(DominatorTree::ID);
Provided.push_back(ID);
AU.addRequired(DominatorTree::ID);
AU.addProvided(ID);
}
}
};

View File

@ -1,4 +1,4 @@
//===- llvm/Analysis/SafePointerAccess.h - Check pointer safety ---*- C++ -*-=//
//===- llvm/Analysis/FindUnsafePointerTypes.h - Unsafe pointers ---*- C++ -*-=//
//
// This file defines a pass that can be used to determine, interprocedurally,
// which pointer types are accessed unsafely in a program. If there is an
@ -10,12 +10,12 @@
//
// Additionally, this analysis exports a hidden command line argument that (when
// enabled) prints out the reasons a type was determined to be unsafe. Just add
// -unsafeptrinst to the command line of the tool you want to get it.
// -printunsafeptrinst to the command line of the tool you want to get it.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_SAFEPOINTERACCESS_H
#define LLVM_ANALYSIS_SAFEPOINTERACCESS_H
#ifndef LLVM_ANALYSIS_UNSAFEPOINTERTYPES_H
#define LLVM_ANALYSIS_UNSAFEPOINTERTYPES_H
#include "llvm/Pass.h"
#include <set>
@ -46,11 +46,12 @@ public:
//
void printResults(const Module *Mod, std::ostream &o) const;
// getAnalysisUsageInfo - This function needs FindUsedTypes to do its job...
// getAnalysisUsage - Of course, we provide ourself...
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
};
#endif

View File

@ -52,11 +52,12 @@ public:
//
bool run(Module *M);
// getAnalysisUsageInfo - This function needs FindUsedTypes to do its job...
// getAnalysisUsage - Of course, we provide ourself...
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
};
#endif

View File

@ -1,7 +1,7 @@
//===- IntervalPartition.h - Interval partition Calculation ------*- C++ -*--=//
//
// This file contains the declaration of the cfg::IntervalPartition class, which
// calculates and represents the interval partition of a method, or a
// calculates and represents the interval partition of a function, or a
// preexisting interval partition.
//
// In this way, the interval partition may be used to reduce a flow graph down
@ -24,12 +24,12 @@ namespace cfg {
//===----------------------------------------------------------------------===//
//
// IntervalPartition - This class builds and holds an "interval partition" for
// a method. This partition divides the control flow graph into a set of
// a function. This partition divides the control flow graph into a set of
// maximal intervals, as defined with the properties above. Intuitively, a
// BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
// nodes following it.
//
class IntervalPartition : public MethodPass, public std::vector<Interval*> {
class IntervalPartition : public FunctionPass, public std::vector<Interval*> {
typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
IntervalMapTy IntervalMap;
@ -41,8 +41,8 @@ public:
IntervalPartition(AnalysisID AID) : RootInterval(0) { assert(AID == ID); }
// run - Calculate the interval partition for this method
virtual bool runOnMethod(Function *F);
// run - Calculate the interval partition for this function
virtual bool runOnFunction(Function *F);
// IntervalPartition ctor - Build a reduced interval partition from an
// existing interval graph. This takes an additional boolean parameter to
@ -54,7 +54,7 @@ public:
~IntervalPartition() { destroy(); }
// getRootInterval() - Return the root interval that contains the starting
// block of the method.
// block of the function.
inline Interval *getRootInterval() { return RootInterval; }
// isDegeneratePartition() - Returns true if the interval partition contains
@ -69,15 +69,14 @@ public:
return I != IntervalMap.end() ? I->second : 0;
}
// getAnalysisUsageInfo - Implement the Pass API
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
Provided.push_back(ID);
// getAnalysisUsage - Implement the Pass API
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
private:
// destroy - Reset state back to before method was analyzed
// destroy - Reset state back to before function was analyzed
void destroy();
// addIntervalToPartition - Add an interval to the internal list of intervals,

View File

@ -1,15 +1,15 @@
/* Title: MethodLiveVarInfo.h -*- C++ -*-
/* Title: FunctionLiveVarInfo.h -*- C++ -*-
Author: Ruchira Sasanka
Date: Jun 30, 01
Purpose:
This is the interface for live variable info of a method that is required
This is the interface for live variable info of a function that is required
by any other part of the compiler
It must be called like:
MethodLiveVarInfo MLVI(Function *); // initializes data structures
MLVI.analyze(); // do the actural live variable anal
FunctionLiveVarInfo FLVI(Function *); // initializes data structures
FLVI.analyze(); // do the actural live variable anal
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
live var info of a BB.
@ -79,7 +79,7 @@ enum LiveVarDebugLevel_t {
extern cl::Enum<LiveVarDebugLevel_t> DEBUG_LV;
class MethodLiveVarInfo : public MethodPass {
class MethodLiveVarInfo : public FunctionPass {
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI;
@ -105,19 +105,18 @@ public:
MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); }
// --------- Implement the MethodPass interface ----------------------
// --------- Implement the FunctionPass interface ----------------------
// runOnMethod - Perform analysis, update internal data structures.
virtual bool runOnMethod(Function *F);
// runOnFunction - Perform analysis, update internal data structures.
virtual bool runOnFunction(Function *F);
// releaseMemory - After LiveVariable analysis has been used, forget!
virtual void releaseMemory();
// getAnalysisUsageInfo - Provide self!
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
Provided.push_back(ID);
// getAnalysisUsage - Provide self!
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
// --------- Functions to access analysis results -------------------

View File

@ -62,9 +62,9 @@ private:
//===----------------------------------------------------------------------===//
// LoopInfo - This class builds and contains all of the top level loop
// structures in the specified method.
// structures in the specified function.
//
class LoopInfo : public MethodPass {
class LoopInfo : public FunctionPass {
// BBMap - Mapping of basic blocks to the inner most loop they occur in
std::map<const BasicBlock *, Loop*> BBMap;
std::vector<Loop*> TopLevelLoops;
@ -105,16 +105,15 @@ public:
bool isLoopExit(const BasicBlock *BB) const;
#endif
// runOnMethod - Pass framework implementation
virtual bool runOnMethod(Function *F);
// runOnFunction - Pass framework implementation
virtual bool runOnFunction(Function *F);
virtual void releaseMemory();
// getAnalysisUsageInfo - Provide loop info, require dominator set
// getAnalysisUsage - Provide loop info, require dominator set
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
private:
void Calculate(const DominatorSet &DS);
Loop *ConsiderForLoop(const BasicBlock *BB, const DominatorSet &DS);

View File

@ -1,9 +1,10 @@
//===- llvm/Assembly/PrintModulePass.h - Printing Pass -----------*- C++ -*--=//
//
// This file defines two passes to print out a module. The PrintModulePass
// pass simply prints out the entire module when it is executed. The
// PrintMethodPass class is designed to be pipelined with other MethodPass's,
// and prints out the methods of the class as they are processed.
// This file defines two passes to print out a module. The PrintModulePass pass
// simply prints out the entire module when it is executed. The
// PrintFunctionPass class is designed to be pipelined with other
// FunctionPass's, and prints out the functions of the class as they are
// processed.
//
//===----------------------------------------------------------------------===//
@ -32,8 +33,8 @@ public:
}
};
class PrintFunctionPass : public MethodPass {
std::string Banner; // String to print before each method
class PrintFunctionPass : public FunctionPass {
std::string Banner; // String to print before each function
std::ostream *Out; // ostream to print on
bool DeleteStream; // Delete the ostream in our dtor?
public:
@ -46,10 +47,10 @@ public:
if (DeleteStream) delete Out;
}
// runOnMethod - This pass just prints a banner followed by the method as
// runOnFunction - This pass just prints a banner followed by the function as
// it's processed.
//
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
(*Out) << Banner << (Value*)F;
return false;
}

View File

@ -1,15 +1,15 @@
/* Title: MethodLiveVarInfo.h -*- C++ -*-
/* Title: FunctionLiveVarInfo.h -*- C++ -*-
Author: Ruchira Sasanka
Date: Jun 30, 01
Purpose:
This is the interface for live variable info of a method that is required
This is the interface for live variable info of a function that is required
by any other part of the compiler
It must be called like:
MethodLiveVarInfo MLVI(Function *); // initializes data structures
MLVI.analyze(); // do the actural live variable anal
FunctionLiveVarInfo FLVI(Function *); // initializes data structures
FLVI.analyze(); // do the actural live variable anal
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
live var info of a BB.
@ -79,7 +79,7 @@ enum LiveVarDebugLevel_t {
extern cl::Enum<LiveVarDebugLevel_t> DEBUG_LV;
class MethodLiveVarInfo : public MethodPass {
class MethodLiveVarInfo : public FunctionPass {
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI;
@ -105,19 +105,18 @@ public:
MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); }
// --------- Implement the MethodPass interface ----------------------
// --------- Implement the FunctionPass interface ----------------------
// runOnMethod - Perform analysis, update internal data structures.
virtual bool runOnMethod(Function *F);
// runOnFunction - Perform analysis, update internal data structures.
virtual bool runOnFunction(Function *F);
// releaseMemory - After LiveVariable analysis has been used, forget!
virtual void releaseMemory();
// getAnalysisUsageInfo - Provide self!
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
Provided.push_back(ID);
// getAnalysisUsage - Provide self!
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addProvided(ID);
}
// --------- Functions to access analysis results -------------------

View File

@ -8,7 +8,7 @@
#ifndef LLVM_CODEGEN_INSTR_SCHEDULING_H
#define LLVM_CODEGEN_INSTR_SCHEDULING_H
class MethodPass;
class Pass;
class TargetMachine;
//---------------------------------------------------------------------------
@ -21,7 +21,7 @@ class TargetMachine;
// are still in SSA form.
//---------------------------------------------------------------------------
MethodPass *createInstructionSchedulingWithSSAPass(const TargetMachine &Target);
Pass *createInstructionSchedulingWithSSAPass(const TargetMachine &Target);
//---------------------------------------------------------------------------

View File

@ -9,12 +9,11 @@
#include "llvm/Pass.h"
class TargetMachine;
class MethodPass;
//----------------------------------------------------------------------------
// Entry point for register allocation for a module
//----------------------------------------------------------------------------
MethodPass *getRegisterAllocator(TargetMachine &T);
Pass *getRegisterAllocator(TargetMachine &T);
#endif

View File

@ -10,8 +10,8 @@
//
// Passes should extend one of the classes below, depending on the guarantees
// that it can make about what will be modified as it is run. For example, most
// global optimizations should derive from MethodPass, because they do not add
// or delete methods, they operate on the internals of the method.
// global optimizations should derive from FunctionPass, because they do not add
// or delete functionss, they operate on the internals of the function.
//
//===----------------------------------------------------------------------===//
@ -24,6 +24,7 @@ class Value;
class BasicBlock;
class Function;
class Module;
class AnalysisUsage;
class AnalysisID;
class Pass;
template<class UnitType> class PassManagerT;
@ -33,7 +34,6 @@ struct AnalysisResolver;
// Implemented in PassManager.h
typedef PassManagerT<Module> PassManager;
//===----------------------------------------------------------------------===//
// Pass interface - Implemented by all 'passes'. Subclass this if you are an
// interprocedural optimization or you do not fit into any of the more
@ -43,8 +43,6 @@ class Pass {
friend class AnalysisResolver;
AnalysisResolver *Resolver; // AnalysisResolver this pass is owned by...
public:
typedef std::vector<AnalysisID> AnalysisSet;
inline Pass(AnalysisResolver *AR = 0) : Resolver(AR) {}
inline virtual ~Pass() {} // Destructor is virtual so we can be subclassed
@ -54,24 +52,13 @@ public:
//
virtual bool run(Module *M) = 0;
// getAnalysisUsageInfo - This function should be overriden by passes that
// need analysis information to do their job. If a pass specifies that it
// uses a particular analysis result to this function, it can then use the
// getAnalysisUsage - This function should be overriden by passes that need
// analysis information to do their job. If a pass specifies that it uses a
// particular analysis result to this function, it can then use the
// getAnalysis<AnalysisType>() function, below.
//
// The Destroyed vector is used to communicate what analyses are invalidated
// by this pass. This is critical to specify so that the PassManager knows
// which analysis must be rerun after this pass has proceeded. Analysis are
// only invalidated if run() returns true.
//
// The Provided vector is used for passes that provide analysis information,
// these are the analysis passes themselves. All analysis passes should
// override this method to return themselves in the provided set.
//
virtual void getAnalysisUsageInfo(AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
// By default, no analysis results are used or destroyed.
virtual void getAnalysisUsage(AnalysisUsage &Info) const {
// By default, no analysis results are used, all are invalidated.
}
// releaseMemory() - This member can be implemented by a pass if it wants to
@ -93,7 +80,7 @@ public:
protected:
// getAnalysis<AnalysisType>() - This function is used by subclasses to get to
// the analysis information that they claim to use by overriding the
// getAnalysisUsageInfo function.
// getAnalysisUsage function.
//
template<typename AnalysisType>
AnalysisType &getAnalysis(AnalysisID AID = AnalysisType::ID) {
@ -118,52 +105,50 @@ private:
friend class PassManagerT<Module>;
friend class PassManagerT<Function>;
friend class PassManagerT<BasicBlock>;
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisSet &Req,
AnalysisSet &Destroyed, AnalysisSet &Provided);
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU);
};
//===----------------------------------------------------------------------===//
// MethodPass class - This class is used to implement most global optimizations.
// Optimizations should subclass this class if they meet the following
// constraints:
// 1. Optimizations are organized globally, ie a method at a time
// 2. Optimizing a method does not cause the addition or removal of any methods
// in the module
// FunctionPass class - This class is used to implement most global
// optimizations. Optimizations should subclass this class if they meet the
// following constraints:
//
struct MethodPass : public Pass {
// 1. Optimizations are organized globally, ie a function at a time
// 2. Optimizing a function does not cause the addition or removal of any
// functions in the module
//
struct FunctionPass : public Pass {
// doInitialization - Virtual method overridden by subclasses to do
// any neccesary per-module initialization.
//
virtual bool doInitialization(Module *M) { return false; }
// runOnMethod - Virtual method overriden by subclasses to do the per-method
// processing of the pass.
// runOnFunction - Virtual method overriden by subclasses to do the
// per-function processing of the pass.
//
virtual bool runOnMethod(Function *M) = 0;
virtual bool runOnFunction(Function *F) = 0;
// doFinalization - Virtual method overriden by subclasses to do any post
// processing needed after all passes have run.
//
virtual bool doFinalization(Module *M) { return false; }
// run - On a module, we run this pass by initializing, ronOnMethod'ing once
// for every method in the module, then by finalizing.
// run - On a module, we run this pass by initializing, ronOnFunction'ing once
// for every function in the module, then by finalizing.
//
virtual bool run(Module *M);
// run - On a method, we simply initialize, run the method, then finalize.
// run - On a function, we simply initialize, run the function, then finalize.
//
bool run(Function *M);
bool run(Function *F);
private:
friend class PassManagerT<Module>;
friend class PassManagerT<Function>;
friend class PassManagerT<BasicBlock>;
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisSet &Req,
AnalysisSet &Dest, AnalysisSet &Prov);
virtual void addToPassManager(PassManagerT<Function> *PM,AnalysisSet &Req,
AnalysisSet &Dest, AnalysisSet &Prov);
virtual void addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU);
virtual void addToPassManager(PassManagerT<Function> *PM, AnalysisUsage &AU);
};
@ -174,20 +159,20 @@ private:
// meet the following constraints:
// 1. Optimizations are local, operating on either a basic block or
// instruction at a time.
// 2. Optimizations do not modify the CFG of the contained method, or any
// other basic block in the method.
// 3. Optimizations conform to all of the contstraints of MethodPass's.
// 2. Optimizations do not modify the CFG of the contained function, or any
// other basic block in the function.
// 3. Optimizations conform to all of the contstraints of FunctionPass's.
//
struct BasicBlockPass : public MethodPass {
struct BasicBlockPass : public FunctionPass {
// runOnBasicBlock - Virtual method overriden by subclasses to do the
// per-basicblock processing of the pass.
//
virtual bool runOnBasicBlock(BasicBlock *M) = 0;
// To run this pass on a method, we simply call runOnBasicBlock once for each
// method.
// To run this pass on a function, we simply call runOnBasicBlock once for
// each function.
//
virtual bool runOnMethod(Function *F);
virtual bool runOnFunction(Function *F);
// To run directly on the basic block, we initialize, runOnBasicBlock, then
// finalize.
@ -197,10 +182,8 @@ struct BasicBlockPass : public MethodPass {
private:
friend class PassManagerT<Function>;
friend class PassManagerT<BasicBlock>;
virtual void addToPassManager(PassManagerT<Function> *PM, AnalysisSet &,
AnalysisSet &, AnalysisSet &);
virtual void addToPassManager(PassManagerT<BasicBlock> *PM, AnalysisSet &,
AnalysisSet &, AnalysisSet &);
virtual void addToPassManager(PassManagerT<Function> *PM, AnalysisUsage &AU);
virtual void addToPassManager(PassManagerT<BasicBlock> *PM,AnalysisUsage &AU);
};
@ -249,6 +232,50 @@ public:
}
};
//===----------------------------------------------------------------------===//
// AnalysisUsage - Represent the analysis usage information of a pass. This
// tracks analyses that the pass REQUIRES (must available when the pass runs),
// and analyses that the pass PRESERVES (the pass does not invalidate the
// results of these analyses). This information is provided by a pass to the
// Pass infrastructure through the getAnalysisUsage virtual function.
//
class AnalysisUsage {
// Sets of analyses required and preserved by a pass
std::vector<AnalysisID> Required, Preserved, Provided;
bool PreservesAll;
public:
AnalysisUsage() : PreservesAll(false) {}
// addRequires - Add the specified ID to the required set of the usage info
// for a pass.
//
AnalysisUsage &addRequired(AnalysisID ID) {
Required.push_back(ID);
return *this;
}
// addPreserves - Add the specified ID to the set of analyses preserved by
// this pass
//
AnalysisUsage &addPreserved(AnalysisID ID) {
Preserved.push_back(ID);
return *this;
}
void addProvided(AnalysisID ID) {
Provided.push_back(ID);
}
// PreservesAll - Set by analyses that do not transform their input at all
void setPreservesAll() { PreservesAll = true; }
bool preservesAll() const { return PreservesAll; }
const std::vector<AnalysisID> &getRequiredSet() const { return Required; }
const std::vector<AnalysisID> &getPreservedSet() const { return Preserved; }
const std::vector<AnalysisID> &getProvidedSet() const { return Provided; }
};
//===----------------------------------------------------------------------===//
// AnalysisResolver - Simple interface implemented by PassManagers objects that

View File

@ -1,19 +1,19 @@
//===-- MethodInlining.h - Functions that perform Inlining -------*- C++ -*--=//
//===-- FunctionInlining.h - Functions that perform Inlining -----*- C++ -*--=//
//
// This family of functions is useful for performing method inlining.
// This family of functions is useful for performing function inlining.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_METHOD_INLINING_H
#define LLVM_TRANSFORMS_METHOD_INLINING_H
#ifndef LLVM_TRANSFORMS_FUNCTION_INLINING_H
#define LLVM_TRANSFORMS_FUNCTION_INLINING_H
#include "llvm/BasicBlock.h"
class CallInst;
class Pass;
Pass *createMethodInliningPass();
Pass *createFunctionInliningPass();
// InlineMethod - This function forcibly inlines the called method into the
// InlineFunction - This function forcibly inlines the called function into the
// basic block of the caller. This returns true if it is not possible to inline
// this call. The program is still in a well defined state if this occurs
// though.
@ -21,9 +21,9 @@ Pass *createMethodInliningPass();
// Note that this only does one level of inlining. For example, if the
// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
// exists in the instruction stream. Similiarly this will inline a recursive
// method by one level.
// function by one level.
//
bool InlineMethod(CallInst *C);
bool InlineMethod(BasicBlock::iterator CI); // *CI must be CallInst
bool InlineFunction(CallInst *C);
bool InlineFunction(BasicBlock::iterator CI); // *CI must be CallInst
#endif

View File

@ -1,6 +1,6 @@
//===- llvm/Transforms/Instrumentation/TraceValues.h - Tracing ---*- C++ -*--=//
//
// Support for inserting LLVM code to print values at basic block and method
// Support for inserting LLVM code to print values at basic block and function
// exits.
//
//===----------------------------------------------------------------------===//
@ -9,7 +9,7 @@
#define LLVM_TRANSFORMS_INSTRUMENTATION_TRACEVALUES_H
class Pass;
Pass *createTraceValuesPassForMethod(); // Just trace methods
Pass *createTraceValuesPassForFunction(); // Just trace function entry/exit
Pass *createTraceValuesPassForBasicBlocks(); // Trace BB's and methods
#endif

View File

@ -41,7 +41,7 @@ class MutateStructTypes : public Pass {
// Mapping from global value of old type, to a global value of the new type...
std::map<const GlobalValue*, GlobalValue*> GlobalMap;
// Mapping from intra method value to intra method value
// Mapping from intra function value to intra function value
std::map<const Value*, Value*> LocalValueMap;
public:
@ -60,13 +60,6 @@ public:
// run - do the transformation
virtual bool run(Module *M);
// getAnalysisUsageInfo - This function needs the results of the
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided);
protected:
// Alternatively, it is valid to subclass this class and provide transforms
@ -80,17 +73,17 @@ private:
// processGlobals - This loops over global constants defined in the
// module, converting them to their new type. Also this creates placeholder
// methods for methods than need to be copied because they have a new
// functions for functions than need to be copied because they have a new
// signature type.
//
void processGlobals(Module *M);
// transformMethod - This transforms the instructions of the method to use the
// new types.
// transformFunction - This transforms the instructions of the function to use
// the new types.
//
void transformMethod(Function *F);
void transformFunction(Function *F);
// removeDeadGlobals - This removes the old versions of methods that are no
// removeDeadGlobals - This removes the old versions of functions that are no
// longer needed.
//
void removeDeadGlobals(Module *M);

View File

@ -11,17 +11,15 @@
#include "llvm/Pass.h"
namespace cfg { class IntervalPartition; }
struct InductionVariableCannonicalize : public MethodPass {
struct InductionVariableCannonicalize : public FunctionPass {
// doInductionVariableCannonicalize - Simplify induction variables in loops
//
static bool doIt(Function *M, cfg::IntervalPartition &IP);
static bool doIt(Function *F, cfg::IntervalPartition &IP);
virtual bool runOnMethod(Function *M);
virtual bool runOnFunction(Function *F);
// getAnalysisUsageInfo - Declare that we need IntervalPartitions
void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided);
// getAnalysisUsage - Declare that we need IntervalPartitions
void getAnalysisUsage(AnalysisUsage &AU) const;
};
#endif

View File

@ -1,17 +1,17 @@
//===-- UnifyMethodExitNodes.h - Ensure methods have one return --*- C++ -*--=//
//===-- UnifyFunctionExitNodes.h - Ensure fn's have one return ---*- C++ -*--=//
//
// This pass is used to ensure that methods have at most one return instruction
// in them. It also holds onto the return instruction of the last unified
// method.
// This pass is used to ensure that functions have at most one return
// instruction in them. It also holds onto the return instruction of the last
// unified function.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
#define LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
#ifndef LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
#define LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
#include "llvm/Pass.h"
struct UnifyMethodExitNodes : public MethodPass {
struct UnifyMethodExitNodes : public FunctionPass {
BasicBlock *ExitNode;
public:
static AnalysisID ID; // Pass ID
@ -21,22 +21,19 @@ public:
// BasicBlock, and converting all returns to unconditional branches to this
// new basic block. The singular exit node is returned in ExitNode.
//
// If there are no return stmts in the Method, a null pointer is returned.
// If there are no return stmts in the function, a null pointer is returned.
//
static bool doit(Function *F, BasicBlock *&ExitNode);
virtual bool runOnMethod(Function *F) {
virtual bool runOnFunction(Function *F) {
return doit(F, ExitNode);
}
BasicBlock *getExitNode() const { return ExitNode; }
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
// FIXME: Should invalidate CFG
Provided.push_back(ID); // Provide self!
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addProvided(ID); // Provide self!
}
};

View File

@ -95,11 +95,3 @@ void FindUnsafePointerTypes::printResults(const Module *M,
CW << " #" << Counter << ". " << (Value*)*I << "\n";
}
}
// getAnalysisUsageInfo - Of course, we provide ourself...
//
void FindUnsafePointerTypes::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Provided.push_back(FindUnsafePointerTypes::ID);
}

View File

@ -93,11 +93,3 @@ void FindUsedTypes::printTypes(std::ostream &o, const Module *M = 0) const {
E = UsedTypes.end(); I != E; ++I)
o << " " << *I << "\n";
}
// getAnalysisUsageInfo - Of course, we provide ourself...
//
void FindUsedTypes::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Provided.push_back(FindUsedTypes::ID);
}

View File

@ -52,19 +52,19 @@ void IntervalPartition::updatePredecessors(cfg::Interval *Int) {
// IntervalPartition ctor - Build the first level interval partition for the
// specified function...
//
bool IntervalPartition::runOnMethod(Function *M) {
assert(M->front() && "Cannot operate on prototypes!");
bool IntervalPartition::runOnFunction(Function *F) {
assert(F->front() && "Cannot operate on prototypes!");
// Pass false to intervals_begin because we take ownership of it's memory
function_interval_iterator I = intervals_begin(M, false);
assert(I != intervals_end(M) && "No intervals in function!?!?!");
function_interval_iterator I = intervals_begin(F, false);
assert(I != intervals_end(F) && "No intervals in function!?!?!");
addIntervalToPartition(RootInterval = *I);
++I; // After the first one...
// Add the rest of the intervals to the partition...
for_each(I, intervals_end(M),
for_each(I, intervals_end(F),
bind_obj(this, &IntervalPartition::addIntervalToPartition));
// Now that we know all of the successor information, propogate this to the

View File

@ -1,6 +1,6 @@
//===-- MethodLiveVarInfo.cpp - Live Variable Analysis for a Function -----===//
//===-- FunctionLiveVarInfo.cpp - Live Variable Analysis for a Function ---===//
//
// This is the interface to method level live variable information that is
// This is the interface to function level live variable information that is
// provided by live variable analysis.
//
//===----------------------------------------------------------------------===//
@ -39,10 +39,10 @@ const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
//-----------------------------------------------------------------------------
// Performs live var analysis for a method
// Performs live var analysis for a function
//-----------------------------------------------------------------------------
bool MethodLiveVarInfo::runOnMethod(Function *Meth) {
bool MethodLiveVarInfo::runOnFunction(Function *Meth) {
M = Meth;
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
@ -149,12 +149,12 @@ void MethodLiveVarInfo::releaseMemory() {
//-----------------------------------------------------------------------------
// Following functions will give the LiveVar info for any machine instr in
// a method. It should be called after a call to analyze().
// a function. It should be called after a call to analyze().
//
// Thsese functions calucluates live var info for all the machine instrs in a
// BB when LVInfo for one inst is requested. Hence, this function is useful
// when live var info is required for many (or all) instructions in a basic
// block. Also, the arguments to this method does not require specific
// block. Also, the arguments to this function does not require specific
// iterators.
//-----------------------------------------------------------------------------

View File

@ -35,7 +35,7 @@ void cfg::LoopInfo::releaseMemory() {
//===----------------------------------------------------------------------===//
// cfg::LoopInfo implementation
//
bool cfg::LoopInfo::runOnMethod(Function *F) {
bool cfg::LoopInfo::runOnFunction(Function *F) {
releaseMemory();
Calculate(getAnalysis<DominatorSet>()); // Update
return false;
@ -53,11 +53,10 @@ void cfg::LoopInfo::Calculate(const DominatorSet &DS) {
TopLevelLoops[i]->setLoopDepth(1);
}
void cfg::LoopInfo::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(DominatorSet::ID);
Provided.push_back(ID);
void cfg::LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired(DominatorSet::ID);
AU.addProvided(ID);
}

View File

@ -22,7 +22,7 @@ using std::set;
AnalysisID cfg::DominatorSet::ID(AnalysisID::create<cfg::DominatorSet>());
AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create<cfg::DominatorSet>());
bool cfg::DominatorSet::runOnMethod(Function *F) {
bool cfg::DominatorSet::runOnFunction(Function *F) {
Doms.clear(); // Reset from the last time we were run...
if (isPostDominator())
@ -129,17 +129,16 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
} while (Changed);
}
// getAnalysisUsageInfo - This obviously provides a dominator set, but it also
// uses the UnifyMethodExitNodes pass if building post-dominators
// getAnalysisUsage - This obviously provides a dominator set, but it also
// uses the UnifyFunctionExitNodes pass if building post-dominators
//
void cfg::DominatorSet::getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
if (isPostDominator()) {
Provided.push_back(PostDomID);
Requires.push_back(UnifyMethodExitNodes::ID);
AU.addProvided(PostDomID);
AU.addRequired(UnifyMethodExitNodes::ID);
} else {
Provided.push_back(ID);
AU.addProvided(ID);
}
}

View File

@ -1480,26 +1480,23 @@ instrIsFeasible(const SchedulingManager& S,
//---------------------------------------------------------------------------
namespace {
class InstructionSchedulingWithSSA : public MethodPass {
class InstructionSchedulingWithSSA : public FunctionPass {
const TargetMachine &target;
public:
inline InstructionSchedulingWithSSA(const TargetMachine &T) : target(T) {}
// getAnalysisUsageInfo - We use LiveVarInfo...
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(MethodLiveVarInfo::ID);
Destroyed.push_back(MethodLiveVarInfo::ID);
// getAnalysisUsage - We use LiveVarInfo...
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(MethodLiveVarInfo::ID);
}
bool runOnMethod(Function *F);
bool runOnFunction(Function *F);
};
} // end anonymous namespace
bool
InstructionSchedulingWithSSA::runOnMethod(Function *M)
InstructionSchedulingWithSSA::runOnFunction(Function *M)
{
if (SchedDebugLevel == Sched_Disable)
return false;
@ -1544,8 +1541,6 @@ InstructionSchedulingWithSSA::runOnMethod(Function *M)
}
MethodPass*
createInstructionSchedulingWithSSAPass(const TargetMachine &tgt)
{
Pass *createInstructionSchedulingWithSSAPass(const TargetMachine &tgt) {
return new InstructionSchedulingWithSSA(tgt);
}

View File

@ -40,14 +40,14 @@ cl::Enum<RegAllocDebugLevel_t> DEBUG_RA("dregalloc", cl::NoFlags,
// RegisterAllocation pass front end...
//----------------------------------------------------------------------------
namespace {
class RegisterAllocator : public MethodPass {
class RegisterAllocator : public FunctionPass {
TargetMachine &Target;
public:
inline RegisterAllocator(TargetMachine &T) : Target(T) {}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
if (DEBUG_RA)
cerr << "\n******************** Method "<< F->getName()
cerr << "\n******************** Function "<< F->getName()
<< " ********************\n";
PhyRegAlloc PRA(F, Target, &getAnalysis<MethodLiveVarInfo>(),
@ -58,17 +58,14 @@ namespace {
return false;
}
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(cfg::LoopInfo::ID);
Requires.push_back(MethodLiveVarInfo::ID);
Destroyed.push_back(MethodLiveVarInfo::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID);
AU.addRequired(MethodLiveVarInfo::ID);
}
};
}
MethodPass *getRegisterAllocator(TargetMachine &T) {
Pass *getRegisterAllocator(TargetMachine &T) {
return new RegisterAllocator(T);
}

View File

@ -1480,26 +1480,23 @@ instrIsFeasible(const SchedulingManager& S,
//---------------------------------------------------------------------------
namespace {
class InstructionSchedulingWithSSA : public MethodPass {
class InstructionSchedulingWithSSA : public FunctionPass {
const TargetMachine &target;
public:
inline InstructionSchedulingWithSSA(const TargetMachine &T) : target(T) {}
// getAnalysisUsageInfo - We use LiveVarInfo...
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(MethodLiveVarInfo::ID);
Destroyed.push_back(MethodLiveVarInfo::ID);
// getAnalysisUsage - We use LiveVarInfo...
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(MethodLiveVarInfo::ID);
}
bool runOnMethod(Function *F);
bool runOnFunction(Function *F);
};
} // end anonymous namespace
bool
InstructionSchedulingWithSSA::runOnMethod(Function *M)
InstructionSchedulingWithSSA::runOnFunction(Function *M)
{
if (SchedDebugLevel == Sched_Disable)
return false;
@ -1544,8 +1541,6 @@ InstructionSchedulingWithSSA::runOnMethod(Function *M)
}
MethodPass*
createInstructionSchedulingWithSSAPass(const TargetMachine &tgt)
{
Pass *createInstructionSchedulingWithSSAPass(const TargetMachine &tgt) {
return new InstructionSchedulingWithSSA(tgt);
}

View File

@ -1,6 +1,6 @@
//===-- MethodLiveVarInfo.cpp - Live Variable Analysis for a Function -----===//
//===-- FunctionLiveVarInfo.cpp - Live Variable Analysis for a Function ---===//
//
// This is the interface to method level live variable information that is
// This is the interface to function level live variable information that is
// provided by live variable analysis.
//
//===----------------------------------------------------------------------===//
@ -39,10 +39,10 @@ const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
//-----------------------------------------------------------------------------
// Performs live var analysis for a method
// Performs live var analysis for a function
//-----------------------------------------------------------------------------
bool MethodLiveVarInfo::runOnMethod(Function *Meth) {
bool MethodLiveVarInfo::runOnFunction(Function *Meth) {
M = Meth;
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
@ -149,12 +149,12 @@ void MethodLiveVarInfo::releaseMemory() {
//-----------------------------------------------------------------------------
// Following functions will give the LiveVar info for any machine instr in
// a method. It should be called after a call to analyze().
// a function. It should be called after a call to analyze().
//
// Thsese functions calucluates live var info for all the machine instrs in a
// BB when LVInfo for one inst is requested. Hence, this function is useful
// when live var info is required for many (or all) instructions in a basic
// block. Also, the arguments to this method does not require specific
// block. Also, the arguments to this function does not require specific
// iterators.
//-----------------------------------------------------------------------------

View File

@ -40,14 +40,14 @@ cl::Enum<RegAllocDebugLevel_t> DEBUG_RA("dregalloc", cl::NoFlags,
// RegisterAllocation pass front end...
//----------------------------------------------------------------------------
namespace {
class RegisterAllocator : public MethodPass {
class RegisterAllocator : public FunctionPass {
TargetMachine &Target;
public:
inline RegisterAllocator(TargetMachine &T) : Target(T) {}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
if (DEBUG_RA)
cerr << "\n******************** Method "<< F->getName()
cerr << "\n******************** Function "<< F->getName()
<< " ********************\n";
PhyRegAlloc PRA(F, Target, &getAnalysis<MethodLiveVarInfo>(),
@ -58,17 +58,14 @@ namespace {
return false;
}
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(cfg::LoopInfo::ID);
Requires.push_back(MethodLiveVarInfo::ID);
Destroyed.push_back(MethodLiveVarInfo::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID);
AU.addRequired(MethodLiveVarInfo::ID);
}
};
}
MethodPass *getRegisterAllocator(TargetMachine &T) {
Pass *getRegisterAllocator(TargetMachine &T) {
return new RegisterAllocator(T);
}

View File

@ -4,10 +4,10 @@
// LLVM. The code in this file assumes that the specified module has already
// been compiled into the internal data structures of the Module.
//
// This code largely consists of two LLVM Pass's: a MethodPass and a Pass. The
// MethodPass is pipelined together with all of the rest of the code generation
// stages, and the Pass runs at the end to emit code for global variables and
// such.
// This code largely consists of two LLVM Pass's: a FunctionPass and a Pass.
// The FunctionPass is pipelined together with all of the rest of the code
// generation stages, and the Pass runs at the end to emit code for global
// variables and such.
//
//===----------------------------------------------------------------------===//
@ -197,7 +197,7 @@ public:
// SparcFunctionAsmPrinter Code
//===----------------------------------------------------------------------===//
struct SparcFunctionAsmPrinter : public MethodPass, public AsmPrinter {
struct SparcFunctionAsmPrinter : public FunctionPass, public AsmPrinter {
inline SparcFunctionAsmPrinter(std::ostream &os, const TargetMachine &t)
: AsmPrinter(os, t) {}
@ -206,7 +206,7 @@ struct SparcFunctionAsmPrinter : public MethodPass, public AsmPrinter {
return false;
}
virtual bool runOnMethod(Function *F) {
virtual bool runOnFunction(Function *F) {
startFunction(F);
emitFunction(F);
endFunction(F);
@ -410,7 +410,7 @@ SparcFunctionAsmPrinter::emitFunction(const Function *M)
} // End anonymous namespace
Pass *UltraSparc::getMethodAsmPrinterPass(PassManager &PM, std::ostream &Out) {
Pass *UltraSparc::getFunctionAsmPrinterPass(PassManager &PM, std::ostream &Out){
return new SparcFunctionAsmPrinter(Out, *this);
}

View File

@ -128,7 +128,7 @@ public:
// returned in `minstrVec'. Any temporary registers (TmpInstruction)
// created are returned in `tempVec'.
//
virtual void CreateCodeToLoadConst(Function* method,
virtual void CreateCodeToLoadConst(Function *F,
Value* val,
Instruction* dest,
std::vector<MachineInstr*>& minstrVec,
@ -141,7 +141,7 @@ public:
// The generated instructions are returned in `minstrVec'.
// Any temp. registers (TmpInstruction) created are returned in `tempVec'.
//
virtual void CreateCodeToCopyIntToFloat(Function* method,
virtual void CreateCodeToCopyIntToFloat(Function* F,
Value* val,
Instruction* dest,
std::vector<MachineInstr*>& minstr,
@ -152,7 +152,7 @@ public:
// `val' to an integer value `dest' by copying to memory and back.
// See the previous function for information about return values.
//
virtual void CreateCodeToCopyFloatToInt(Function* method,
virtual void CreateCodeToCopyFloatToInt(Function* F,
Value* val,
Instruction* dest,
std::vector<MachineInstr*>& minstr,
@ -161,7 +161,7 @@ public:
// create copy instruction(s)
virtual void CreateCopyInstructionsByType(const TargetMachine& target,
Function* method,
Function* F,
Value* src,
Instruction* dest,
std::vector<MachineInstr*>& minstr) const;
@ -224,7 +224,7 @@ class UltraSparcRegInfo : public MachineRegInfo {
// ======================== Private Methods =============================
// The following methods are used to color special live ranges (e.g.
// method args and return values etc.) with specific hardware registers
// function args and return values etc.) with specific hardware registers
// as required. See SparcRegInfo.cpp for the implementation.
//
void setCallOrRetArgCol(LiveRange *LR, unsigned RegNo,
@ -251,7 +251,7 @@ class UltraSparcRegInfo : public MachineRegInfo {
unsigned getCallInstNumArgs(const MachineInstr *CallMI) const;
// The following 3 methods are used to find the RegType (see enum above)
// The following 3 methods are used to find the RegType (see enum above)
// of a LiveRange, Value and using the unified RegClassID
int getRegType(const LiveRange *LR) const;
int getRegType(const Value *Val) const;
@ -272,7 +272,7 @@ class UltraSparcRegInfo : public MachineRegInfo {
// The following 2 methods are used to order the instructions addeed by
// the register allocator in association with method calling. See
// the register allocator in association with function calling. See
// SparcRegInfo.cpp for more details
//
void moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec,
@ -344,7 +344,7 @@ public:
virtual int getZeroRegNum() const;
// getCallAddressReg - returns the reg used for pushing the address when a
// method is called. This can be used for other purposes between calls
// function is called. This can be used for other purposes between calls
//
unsigned getCallAddressReg() const;
@ -357,7 +357,7 @@ public:
// The following methods are used to color special live ranges (e.g.
// method args and return values etc.) with specific hardware registers
// function args and return values etc.) with specific hardware registers
// as required. See SparcRegInfo.cpp for the implementation for Sparc.
//
void suggestRegs4MethodArgs(const Function *Meth,
@ -499,16 +499,16 @@ public:
UltraSparcFrameInfo(const TargetMachine &tgt) : MachineFrameInfo(tgt) {}
public:
int getStackFrameSizeAlignment () const { return StackFrameSizeAlignment;}
int getMinStackFrameSize () const { return MinStackFrameSize; }
int getNumFixedOutgoingArgs () const { return NumFixedOutgoingArgs; }
int getSizeOfEachArgOnStack () const { return SizeOfEachArgOnStack; }
bool argsOnStackHaveFixedSize () const { return true; }
int getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;}
int getMinStackFrameSize() const { return MinStackFrameSize; }
int getNumFixedOutgoingArgs() const { return NumFixedOutgoingArgs; }
int getSizeOfEachArgOnStack() const { return SizeOfEachArgOnStack; }
bool argsOnStackHaveFixedSize() const { return true; }
//
// These methods compute offsets using the frame contents for a
// particular method. The frame contents are obtained from the
// MachineCodeInfoForMethod object for the given method.
// particular function. The frame contents are obtained from the
// MachineCodeInfoForMethod object for the given function.
//
int getFirstIncomingArgOffset (MachineCodeForMethod& mcInfo,
bool& growUp) const
@ -623,7 +623,7 @@ public:
virtual void addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
private:
Pass *getMethodAsmPrinterPass(PassManager &PM, std::ostream &Out);
Pass *getFunctionAsmPrinterPass(PassManager &PM, std::ostream &Out);
Pass *getModuleAsmPrinterPass(PassManager &PM, std::ostream &Out);
Pass *getEmitBytecodeToAsmPass(std::ostream &Out);
};

View File

@ -21,11 +21,11 @@
namespace {
class InsertPrologEpilogCode : public MethodPass {
class InsertPrologEpilogCode : public FunctionPass {
TargetMachine &Target;
public:
InsertPrologEpilogCode(TargetMachine &T) : Target(T) {}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
MachineCodeForMethod &mcodeInfo = MachineCodeForMethod::get(F);
if (!mcodeInfo.isCompiledAsLeafMethod()) {
InsertPrologCode(F);

View File

@ -126,21 +126,21 @@ UltraSparc::UltraSparc()
// Native code generation for a specified target.
//===---------------------------------------------------------------------===//
class ConstructMachineCodeForFunction : public MethodPass {
class ConstructMachineCodeForFunction : public FunctionPass {
TargetMachine &Target;
public:
inline ConstructMachineCodeForFunction(TargetMachine &T) : Target(T) {}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
MachineCodeForMethod::construct(F, Target);
return false;
}
};
class InstructionSelection : public MethodPass {
class InstructionSelection : public FunctionPass {
TargetMachine &Target;
public:
inline InstructionSelection(TargetMachine &T) : Target(T) {}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
if (SelectInstructionsForMethod(F, Target)) {
cerr << "Instr selection failed for function " << F->getName() << "\n";
abort();
@ -149,12 +149,12 @@ public:
}
};
struct FreeMachineCodeForFunction : public MethodPass {
struct FreeMachineCodeForFunction : public FunctionPass {
static void freeMachineCode(Instruction *I) {
MachineCodeForInstruction::destroy(I);
}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
for (BasicBlock::iterator I = (*FI)->begin(), E = (*FI)->end();
I != E; ++I)
@ -197,7 +197,7 @@ void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
// allowing machine code representations for functions to be free'd after the
// function has been emitted.
//
PM.add(getMethodAsmPrinterPass(PM, Out));
PM.add(getFunctionAsmPrinterPass(PM, Out));
PM.add(new FreeMachineCodeForFunction()); // Free stuff no longer needed
// Emit Module level assembly after all of the functions have been processed.

View File

@ -74,8 +74,8 @@ static bool doHoistPHIConstants(Function *M) {
}
namespace {
struct HoistPHIConstants : public MethodPass {
virtual bool runOnMethod(Function *F) { return doHoistPHIConstants(F); }
struct HoistPHIConstants : public FunctionPass {
virtual bool runOnFunction(Function *F) { return doHoistPHIConstants(F); }
};
}

View File

@ -58,8 +58,8 @@ bool mergeDuplicateConstants(Module *M, unsigned &ConstantNo,
}
namespace {
// FIXME: ConstantMerge should not be a methodPass!!!
class ConstantMerge : public MethodPass {
// FIXME: ConstantMerge should not be a FunctionPass!!!
class ConstantMerge : public FunctionPass {
protected:
std::map<Constant*, GlobalVariable*> Constants;
unsigned LastConstantSeen;
@ -73,7 +73,7 @@ namespace {
return ::mergeDuplicateConstants(M, LastConstantSeen, Constants);
}
bool runOnMethod(Function *) { return false; }
bool runOnFunction(Function *) { return false; }
// doFinalization - Clean up internal state for this module
//
@ -85,10 +85,10 @@ namespace {
};
struct DynamicConstantMerge : public ConstantMerge {
// runOnMethod - Check to see if any globals have been added to the
// runOnFunction - Check to see if any globals have been added to the
// global list for the module. If so, eliminate them.
//
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
return ::mergeDuplicateConstants(F->getParent(), LastConstantSeen,
Constants);
}

View File

@ -35,7 +35,7 @@ using std::cerr;
static const Type *PtrSByte = 0; // 'sbyte*' type
namespace {
struct CleanupGCCOutput : public MethodPass {
struct CleanupGCCOutput : public FunctionPass {
// doPassInitialization - For this pass, it removes global symbol table
// entries for primitive types. These are never used for linking in GCC and
// they make the output uglier to look at, so we nuke them.
@ -46,18 +46,15 @@ namespace {
// runOnFunction - This method simplifies the specified function hopefully.
//
bool runOnMethod(Function *F);
bool runOnFunction(Function *F);
// doPassFinalization - Strip out type names that are unused by the program
bool doFinalization(Module *M);
// getAnalysisUsageInfo - This function needs FindUsedTypes to do its job...
// getAnalysisUsage - This function needs FindUsedTypes to do its job...
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
// FIXME: Invalidates the CFG
Required.push_back(FindUsedTypes::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(FindUsedTypes::ID);
}
};
}
@ -246,7 +243,7 @@ static inline void RefactorPredecessor(BasicBlock *BB, BasicBlock *Pred) {
}
// runOnMethod - Loop through the function and fix problems with the PHI nodes
// runOnFunction - Loop through the function and fix problems with the PHI nodes
// in the current function. The problem is that PHI nodes might exist with
// multiple entries for the same predecessor. GCC sometimes generates code that
// looks like this:
@ -262,7 +259,7 @@ static inline void RefactorPredecessor(BasicBlock *BB, BasicBlock *Pred) {
// bb8: %reg119 = phi uint [ 0, %bbX ], [ 1, %bb7 ]
//
//
bool CleanupGCCOutput::runOnMethod(Function *M) {
bool CleanupGCCOutput::runOnFunction(Function *M) {
bool Changed = false;
// Don't use iterators because invalidation gets messy...
for (unsigned MI = 0; MI < M->size(); ++MI) {

View File

@ -1,6 +1,7 @@
//===-- GlobalDCE.cpp - DCE unreachable internal functions ----------------===//
//
// This transform is designed to eliminate unreachable internal globals
// FIXME: GlobalDCE should update the callgraph, not destroy it!
//
//===----------------------------------------------------------------------===//
@ -55,16 +56,12 @@ namespace {
return RemoveUnreachableFunctions(M, getAnalysis<CallGraph>());
}
// getAnalysisUsageInfo - This function works on the call graph of a module.
// getAnalysisUsage - This function works on the call graph of a module.
// It is capable of updating the call graph to reflect the new state of the
// module.
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(CallGraph::ID);
// FIXME: This should update the callgraph, not destroy it!
Destroyed.push_back(CallGraph::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(CallGraph::ID);
}
};
}

View File

@ -53,7 +53,7 @@ static inline void RemapInstruction(Instruction *I,
}
}
// InlineMethod - This function forcibly inlines the called function into the
// InlineFunction - This function forcibly inlines the called function into the
// basic block of the caller. This returns false if it is not possible to
// inline this call. The program is still in a well defined state if this
// occurs though.
@ -63,8 +63,8 @@ static inline void RemapInstruction(Instruction *I,
// exists in the instruction stream. Similiarly this will inline a recursive
// function by one level.
//
bool InlineMethod(BasicBlock::iterator CIIt) {
assert(isa<CallInst>(*CIIt) && "InlineMethod only works on CallInst nodes!");
bool InlineFunction(BasicBlock::iterator CIIt) {
assert(isa<CallInst>(*CIIt) && "InlineFunction only works on CallInst nodes");
assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
assert((*CIIt)->getParent()->getParent() && "Instruction not in function!");
@ -209,7 +209,7 @@ bool InlineMethod(BasicBlock::iterator CIIt) {
return true;
}
bool InlineMethod(CallInst *CI) {
bool InlineFunction(CallInst *CI) {
assert(CI->getParent() && "CallInst not embeded in BasicBlock!");
BasicBlock *PBB = CI->getParent();
@ -217,12 +217,12 @@ bool InlineMethod(CallInst *CI) {
assert(CallIt != PBB->end() &&
"CallInst has parent that doesn't contain CallInst?!?");
return InlineMethod(CallIt);
return InlineFunction(CallIt);
}
static inline bool ShouldInlineFunction(const CallInst *CI, const Function *F) {
assert(CI->getParent() && CI->getParent()->getParent() &&
"Call not embedded into a method!");
"Call not embedded into a function!");
// Don't inline a recursive call.
if (CI->getParent()->getParent() == F) return false;
@ -244,7 +244,7 @@ static inline bool DoFunctionInlining(BasicBlock *BB) {
// Check to see if we should inline this function
Function *F = CI->getCalledFunction();
if (F && ShouldInlineFunction(CI, F))
return InlineMethod(I);
return InlineFunction(I);
}
}
return false;
@ -270,11 +270,11 @@ static bool doFunctionInlining(Function *F) {
}
namespace {
struct FunctionInlining : public MethodPass {
virtual bool runOnMethod(Function *F) {
struct FunctionInlining : public FunctionPass {
virtual bool runOnFunction(Function *F) {
return doFunctionInlining(F);
}
};
}
Pass *createMethodInliningPass() { return new FunctionInlining(); }
Pass *createFunctionInliningPass() { return new FunctionInlining(); }

View File

@ -28,12 +28,6 @@
using std::map;
using std::vector;
//FIXME: These headers are only included because the analyses are killed!!!
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/FindUsedTypes.h"
#include "llvm/Analysis/FindUnsafePointerTypes.h"
//FIXME end
// To enable debugging, uncomment this...
//#define DEBUG_MST(x) x
@ -273,7 +267,7 @@ void MutateStructTypes::processGlobals(Module *M) {
if (Meth->hasName())
Meth->setName("OLD."+Meth->getName());
// Insert the new function into the method list... to be filled in later..
// Insert the new function into the function list... to be filled in later
M->getFunctionList().push_back(NewMeth);
// Keep track of the association...
@ -325,10 +319,10 @@ void MutateStructTypes::removeDeadGlobals(Module *M) {
// transformMethod - This transforms the instructions of the function to use the
// new types.
// transformFunction - This transforms the instructions of the function to use
// the new types.
//
void MutateStructTypes::transformMethod(Function *m) {
void MutateStructTypes::transformFunction(Function *m) {
const Function *M = m;
map<const GlobalValue*, GlobalValue*>::iterator GMI = GlobalMap.find(M);
if (GMI == GlobalMap.end())
@ -518,19 +512,9 @@ bool MutateStructTypes::run(Module *M) {
processGlobals(M);
for_each(M->begin(), M->end(),
bind_obj(this, &MutateStructTypes::transformMethod));
bind_obj(this, &MutateStructTypes::transformFunction));
removeDeadGlobals(M);
return true;
}
// getAnalysisUsageInfo - This function needs the results of the
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
//
void MutateStructTypes::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Destroyed.push_back(FindUsedTypes::ID);
Destroyed.push_back(FindUnsafePointerTypes::ID);
Destroyed.push_back(CallGraph::ID);
}

View File

@ -234,12 +234,11 @@ namespace {
bool run(Module *M);
// getAnalysisUsageInfo - This function requires data structure information
// getAnalysisUsage - This function requires data structure information
// to be able to see what is pool allocatable.
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &,Pass::AnalysisSet &) {
Required.push_back(DataStructure::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(DataStructure::ID);
}
public:

View File

@ -1,4 +1,4 @@
//===- SimpleStructMutation.cpp - Swap structure elements around ---*- C++ -*--=//
//===- SimpleStructMutation.cpp - Swap structure elements around -*- C++ -*--=//
//
// This pass does a simple transformation that swaps all of the elements of the
// struct types in the program around.
@ -31,15 +31,13 @@ namespace {
return Changed;
}
// getAnalysisUsageInfo - This function needs the results of the
// getAnalysisUsage - This function needs the results of the
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(FindUsedTypes::ID);
Required.push_back(FindUnsafePointerTypes::ID);
MutateStructTypes::getAnalysisUsageInfo(Required, Destroyed, Provided);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(FindUsedTypes::ID);
AU.addRequired(FindUnsafePointerTypes::ID);
MutateStructTypes::getAnalysisUsage(AU);
}
private:

View File

@ -37,17 +37,15 @@
using std::vector;
class ProfilePaths: public MethodPass {
class ProfilePaths: public FunctionPass {
public:
bool runOnMethod(Function *M);
bool runOnFunction(Function *F);
// Before this pass, make sure that there is only one
// entry and only one exit node for the function in the CFG of the function
//
void ProfilePaths::getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(UnifyMethodExitNodes::ID);
void ProfilePaths::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(UnifyMethodExitNodes::ID);
}
};
@ -68,7 +66,7 @@ static Node *findBB(std::set<Node *> &st, BasicBlock *BB){
}
//Per function pass for inserting counters and trigger code
bool ProfilePaths::runOnMethod(Function *M){
bool ProfilePaths::runOnFunction(Function *M){
//Transform the cfg s.t. we have just one exit node
BasicBlock *ExitNode =
getAnalysis<UnifyMethodExitNodes>().getExitNode();

View File

@ -23,7 +23,7 @@ using std::vector;
using std::string;
namespace {
class InsertTraceCode : public MethodPass {
class InsertTraceCode : public FunctionPass {
bool TraceBasicBlockExits, TraceFunctionExits;
Function *PrintfFunc;
public:
@ -46,14 +46,14 @@ namespace {
// runOnFunction - This method does the work.
//
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
return doit(F, TraceBasicBlockExits, TraceFunctionExits, PrintfFunc);
}
};
} // end anonymous namespace
Pass *createTraceValuesPassForMethod() { // Just trace functions
Pass *createTraceValuesPassForFunction() { // Just trace functions
return new InsertTraceCode(false, true);
}

View File

@ -440,7 +440,7 @@ static bool DoRaisePass(Function *F) {
}
// RaisePointerReferences::doit - Raise a method representation to a higher
// RaisePointerReferences::doit - Raise a function representation to a higher
// level.
//
static bool doRPR(Function *F) {
@ -458,7 +458,7 @@ static bool doRPR(Function *F) {
cerr << "Looping: \n" << F;
#endif
// Iterate over the method, refining it, until it converges on a stable
// Iterate over the function, refining it, until it converges on a stable
// state
LocalChange = false;
while (DoRaisePass(F)) LocalChange = true;
@ -470,8 +470,8 @@ static bool doRPR(Function *F) {
}
namespace {
struct RaisePointerReferences : public MethodPass {
virtual bool runOnMethod(Function *F) { return doRPR(F); }
struct RaisePointerReferences : public FunctionPass {
virtual bool runOnFunction(Function *F) { return doRPR(F); }
};
}

View File

@ -29,7 +29,7 @@ using std::cerr;
// It's public interface consists of a constructor and a doADCE() method.
//
class ADCE {
Function *M; // The method that we are working on...
Function *M; // The function that we are working on
std::vector<Instruction*> WorkList; // Instructions that just became live
std::set<Instruction*> LiveSet; // The set of live instructions
bool MadeChanges;
@ -38,11 +38,11 @@ class ADCE {
// The public interface for this class
//
public:
// ADCE Ctor - Save the method to operate on...
inline ADCE(Function *m) : M(m), MadeChanges(false) {}
// ADCE Ctor - Save the function to operate on...
inline ADCE(Function *f) : M(f), MadeChanges(false) {}
// doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
// true if the method was modified.
// true if the function was modified.
bool doADCE(cfg::DominanceFrontier &CDG);
//===--------------------------------------------------------------------===//
@ -75,14 +75,14 @@ private:
// doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
// true if the method was modified.
// true if the function was modified.
//
bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
#ifdef DEBUG_ADCE
cerr << "Function: " << M;
#endif
// Iterate over all of the instructions in the method, eliminating trivially
// Iterate over all of the instructions in the function, eliminating trivially
// dead instructions, and marking instructions live that are known to be
// needed. Perform the walk in depth first order so that we avoid marking any
// instructions live in basic blocks that are unreachable. These blocks will
@ -173,7 +173,7 @@ bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
if (EntryBlock && EntryBlock != M->front()) {
if (isa<PHINode>(EntryBlock->front())) {
// Cannot make the first block be a block with a PHI node in it! Instead,
// strip the first basic block of the method to contain no instructions,
// strip the first basic block of the function to contain no instructions,
// then add a simple branch to the "real" entry node...
//
BasicBlock *E = M->front();
@ -191,9 +191,9 @@ bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
} else {
// We need to move the new entry block to be the first bb of the method.
// We need to move the new entry block to be the first bb of the function
Function::iterator EBI = find(M->begin(), M->end(), EntryBlock);
std::swap(*EBI, *M->begin());// Exchange old location with start of method
std::swap(*EBI, *M->begin()); // Exchange old location with start of fn
MadeChanges = true;
}
}
@ -289,19 +289,17 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks,
}
namespace {
struct AgressiveDCE : public MethodPass {
struct AgressiveDCE : public FunctionPass {
// doADCE - Execute the Agressive Dead Code Elimination Algorithm
//
virtual bool runOnMethod(Function *M) {
return ADCE(M).doADCE(
virtual bool runOnFunction(Function *F) {
return ADCE(F).doADCE(
getAnalysis<cfg::DominanceFrontier>(cfg::DominanceFrontier::PostDomID));
}
// getAnalysisUsageInfo - We require post dominance frontiers (aka Control
// getAnalysisUsage - We require post dominance frontiers (aka Control
// Dependence Graph)
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(cfg::DominanceFrontier::PostDomID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::DominanceFrontier::PostDomID);
}
};
}

View File

@ -211,8 +211,8 @@ static bool DoConstPropPass(Function *F) {
}
namespace {
struct ConstantPropogation : public MethodPass {
inline bool runOnMethod(Function *F) {
struct ConstantPropogation : public FunctionPass {
inline bool runOnFunction(Function *F) {
bool Modified = false;
// Fold constants until we make no progress...

View File

@ -9,7 +9,7 @@
// predecessor only has one successor.
// * Eliminates PHI nodes for basic blocks with a single predecessor
// * Eliminates a basic block that only contains an unconditional branch
// * Eliminates method prototypes that are not referenced
// * Eliminates function prototypes that are not referenced
//
// TODO: This should REALLY be worklist driven instead of iterative. Right now,
// we scan linearly through values, removing unused ones as we go. The problem
@ -163,13 +163,13 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
// iterator that designates the first element remaining after the block that
// was deleted.
//
// WARNING: The entry node of a method may not be simplified.
// WARNING: The entry node of a function may not be simplified.
//
bool SimplifyCFG(Function::iterator &BBIt) {
BasicBlock *BB = *BBIt;
Function *M = BB->getParent();
assert(BB && BB->getParent() && "Block not embedded in method!");
assert(BB && BB->getParent() && "Block not embedded in function!");
assert(BB->getTerminator() && "Degenerate basic block encountered!");
assert(BB->getParent()->front() != BB && "Can't Simplify entry block!");
@ -258,7 +258,7 @@ bool SimplifyCFG(Function::iterator &BBIt) {
Pred->getInstList().push_back(Def); // Add to end...
}
// Remove basic block from the method... and advance iterator to the
// Remove basic block from the function... and advance iterator to the
// next valid block...
BB = M->getBasicBlocks().remove(BBIt);
@ -303,7 +303,7 @@ static bool DoDCEPass(Function *F) {
}
// Remove unused global values - This removes unused global values of no
// possible value. This currently includes unused method prototypes and
// possible value. This currently includes unused function prototypes and
// unitialized global variables.
//
static bool RemoveUnusedGlobalValues(Module *Mod) {
@ -313,7 +313,7 @@ static bool RemoveUnusedGlobalValues(Module *Mod) {
Function *Meth = *MI;
if (Meth->isExternal() && Meth->use_size() == 0) {
// No references to prototype?
//cerr << "Removing method proto: " << Meth->getName() << endl;
//cerr << "Removing function proto: " << Meth->getName() << endl;
delete Mod->getFunctionList().remove(MI); // Remove prototype
// Remove moves iterator to point to the next one automatically
Changed = true;
@ -339,7 +339,7 @@ static bool RemoveUnusedGlobalValues(Module *Mod) {
}
namespace {
struct DeadCodeElimination : public MethodPass {
struct DeadCodeElimination : public FunctionPass {
// Pass Interface...
virtual bool doInitialization(Module *M) {
@ -349,7 +349,7 @@ namespace {
// It is possible that we may require multiple passes over the code to fully
// eliminate dead code. Iterate until we are done.
//
virtual bool runOnMethod(Function *F) {
virtual bool runOnFunction(Function *F) {
bool Changed = false;
while (DoDCEPass(F)) Changed = true;
return Changed;

View File

@ -1,4 +1,4 @@
//===- llvm/Transforms/DecomposeMultiDimRefs.cpp - Lower array refs to 1D -----=//
//===- llvm/Transforms/DecomposeMultiDimRefs.cpp - Lower array refs to 1D ---=//
//
// DecomposeMultiDimRefs -
// Convert multi-dimensional references consisting of any combination
@ -7,7 +7,7 @@
// has at most one index (except structure references,
// which need an extra leading index of [0]).
//
//===---------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar/DecomposeMultiDimRefs.h"
#include "llvm/ConstantVals.h"
@ -171,9 +171,13 @@ doDecomposeMultiDimRefs(Function *F)
namespace {
struct DecomposeMultiDimRefsPass : public MethodPass {
virtual bool runOnMethod(Function *F) { return doDecomposeMultiDimRefs(F); }
struct DecomposeMultiDimRefsPass : public FunctionPass {
virtual bool runOnFunction(Function *F) {
return doDecomposeMultiDimRefs(F);
}
};
}
Pass *createDecomposeMultiDimRefsPass() { return new DecomposeMultiDimRefsPass(); }
Pass *createDecomposeMultiDimRefsPass() {
return new DecomposeMultiDimRefsPass();
}

View File

@ -188,7 +188,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
}
static bool doit(Function *M, cfg::LoopInfo &Loops) {
// Induction Variables live in the header nodes of the loops of the method...
// Induction Variables live in the header nodes of the loops of the function
return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
Loops.getTopLevelLoops().end(),
std::bind1st(std::ptr_fun(TransformLoop), &Loops));
@ -196,15 +196,13 @@ static bool doit(Function *M, cfg::LoopInfo &Loops) {
namespace {
struct InductionVariableSimplify : public MethodPass {
virtual bool runOnMethod(Function *F) {
struct InductionVariableSimplify : public FunctionPass {
virtual bool runOnFunction(Function *F) {
return doit(F, getAnalysis<cfg::LoopInfo>());
}
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(cfg::LoopInfo::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID);
}
};
}

View File

@ -183,7 +183,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
Function *M = Header->getParent();
if (M->hasSymbolTable()) {
// Only name the induction variable if the method isn't stripped.
// Only name the induction variable if the function isn't stripped.
PHIName = "ind_var";
AddName = "ind_var_next";
}
@ -353,7 +353,7 @@ static bool ProcessInterval(cfg::Interval *Int) {
//
static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) {
// This currently just prints out information about the interval structure
// of the method...
// of the function...
#if 0
static unsigned N = 0;
cerr << "\n***********Interval Partition #" << (++N) << "************\n\n";
@ -398,17 +398,14 @@ bool InductionVariableCannonicalize::doIt(Function *M,
}
bool InductionVariableCannonicalize::runOnMethod(Function *F) {
bool InductionVariableCannonicalize::runOnFunction(Function *F) {
return doIt(F, getAnalysis<cfg::IntervalPartition>());
}
// getAnalysisUsageInfo - This function works on the call graph of a module.
// getAnalysisUsage - This function works on the call graph of a module.
// It is capable of updating the call graph to reflect the new state of the
// module.
//
void InductionVariableCannonicalize::getAnalysisUsageInfo(
Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(cfg::IntervalPartition::ID);
void InductionVariableCannonicalize::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::IntervalPartition::ID);
}

View File

@ -27,7 +27,7 @@
namespace {
class InstCombiner : public MethodPass,
class InstCombiner : public FunctionPass,
public InstVisitor<InstCombiner, Instruction*> {
// Worklist of all of the instructions that need to be simplified.
std::vector<Instruction*> WorkList;
@ -44,7 +44,7 @@ namespace {
public:
virtual bool runOnMethod(Function *F);
virtual bool runOnFunction(Function *F);
// Visitation implementation - Implement instruction combining for different
// instruction types. The semantics are as follows:
@ -205,7 +205,7 @@ Instruction *InstCombiner::visitMemAccessInst(MemAccessInst *MAI) {
}
bool InstCombiner::runOnMethod(Function *F) {
bool InstCombiner::runOnFunction(Function *F) {
bool Changed = false;
WorkList.insert(WorkList.end(), inst_begin(F), inst_end(F));

View File

@ -34,9 +34,7 @@
using std::cerr;
// InstVal class - This class represents the different lattice values that an
// instruction may occupy. It is a simple class with value semantics. The
// potential constant value that is pointed to is owned by the constant pool
// for the method being optimized.
// instruction may occupy. It is a simple class with value semantics.
//
class InstVal {
enum {
@ -83,7 +81,7 @@ public:
// SCCP Class
//
// This class does all of the work of Sparse Conditional Constant Propogation.
// It's public interface consists of a constructor and a doSCCP() method.
// It's public interface consists of a constructor and a doSCCP() function.
//
class SCCP : public InstVisitor<SCCP> {
Function *M; // The function that we are working on
@ -99,11 +97,11 @@ class SCCP : public InstVisitor<SCCP> {
//
public:
// SCCP Ctor - Save the method to operate on...
// SCCP Ctor - Save the function to operate on...
inline SCCP(Function *f) : M(f) {}
// doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
// return true if the method was modified.
// return true if the function was modified.
bool doSCCP();
//===--------------------------------------------------------------------===//
@ -212,10 +210,10 @@ private:
// doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
// return true if the method was modified.
// return true if the function was modified.
//
bool SCCP::doSCCP() {
// Mark the first block of the method as being executable...
// Mark the first block of the function as being executable...
markExecutable(M->front());
// Process the work lists until their are empty!
@ -264,7 +262,7 @@ bool SCCP::doSCCP() {
#endif
// Iterate over all of the instructions in a method, replacing them with
// Iterate over all of the instructions in a function, replacing them with
// constants if we have found them to be of constant values.
//
bool MadeChanges = false;
@ -467,8 +465,8 @@ namespace {
// SCCPPass - Use Sparse Conditional Constant Propogation
// to prove whether a value is constant and whether blocks are used.
//
struct SCCPPass : public MethodPass {
inline bool runOnMethod(Function *F) {
struct SCCPPass : public FunctionPass {
inline bool runOnFunction(Function *F) {
SCCP S(F);
return S.doSCCP();
}

View File

@ -60,8 +60,8 @@ static bool doStripGlobalSymbols(Module *M) {
}
namespace {
struct SymbolStripping : public MethodPass {
virtual bool runOnMethod(Function *F) {
struct SymbolStripping : public FunctionPass {
virtual bool runOnFunction(Function *F) {
return doSymbolStripping(F);
}
};

View File

@ -309,22 +309,20 @@ bool PromoteInstance::queuePhiNode(BasicBlock *bb, int i /*the alloca*/)
namespace {
struct PromotePass : public MethodPass {
struct PromotePass : public FunctionPass {
// runOnMethod - To run this pass, first we calculate the alloca
// runOnFunction - To run this pass, first we calculate the alloca
// instructions that are safe for promotion, then we promote each one.
//
virtual bool runOnMethod(Function *F) {
virtual bool runOnFunction(Function *F) {
return (bool)PromoteInstance(F, getAnalysis<DominanceFrontier>());
}
// getAnalysisUsageInfo - We need dominance frontiers
// getAnalysisUsage - We need dominance frontiers
//
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Requires.push_back(DominanceFrontier::ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(DominanceFrontier::ID);
}
};
}

View File

@ -22,7 +22,7 @@ using std::set;
AnalysisID cfg::DominatorSet::ID(AnalysisID::create<cfg::DominatorSet>());
AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create<cfg::DominatorSet>());
bool cfg::DominatorSet::runOnMethod(Function *F) {
bool cfg::DominatorSet::runOnFunction(Function *F) {
Doms.clear(); // Reset from the last time we were run...
if (isPostDominator())
@ -129,17 +129,16 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
} while (Changed);
}
// getAnalysisUsageInfo - This obviously provides a dominator set, but it also
// uses the UnifyMethodExitNodes pass if building post-dominators
// getAnalysisUsage - This obviously provides a dominator set, but it also
// uses the UnifyFunctionExitNodes pass if building post-dominators
//
void cfg::DominatorSet::getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
if (isPostDominator()) {
Provided.push_back(PostDomID);
Requires.push_back(UnifyMethodExitNodes::ID);
AU.addProvided(PostDomID);
AU.addRequired(UnifyMethodExitNodes::ID);
} else {
Provided.push_back(ID);
AU.addProvided(ID);
}
}

View File

@ -71,10 +71,10 @@ void PMDebug::PrintPassInformation(unsigned Depth, const char *Action,
}
void PMDebug::PrintAnalysisSetInfo(unsigned Depth, const char *Msg,
Pass *P, const Pass::AnalysisSet &Set) {
Pass *P, const std::vector<AnalysisID> &Set){
if (PassDebugging >= PassDetails && !Set.empty()) {
std::cerr << (void*)P << std::string(Depth*2+3, ' ') << Msg << " Analyses:";
for (unsigned i = 0; i < Set.size(); ++i) {
for (unsigned i = 0; i != Set.size(); ++i) {
Pass *P = Set[i].createPass(); // Good thing this is just debug code...
std::cerr << " " << typeid(*P).name();
delete P;
@ -93,57 +93,54 @@ void Pass::dumpPassStructure(unsigned Offset = 0) {
// Pass Implementation
//
void Pass::addToPassManager(PassManagerT<Module> *PM, AnalysisSet &Required,
AnalysisSet &Destroyed, AnalysisSet &Provided) {
PM->addPass(this, Required, Destroyed, Provided);
void Pass::addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU) {
PM->addPass(this, AU);
}
//===----------------------------------------------------------------------===//
// MethodPass Implementation
// FunctionPass Implementation
//
// run - On a module, we run this pass by initializing, ronOnMethod'ing once
// for every method in the module, then by finalizing.
// run - On a module, we run this pass by initializing, runOnFunction'ing once
// for every function in the module, then by finalizing.
//
bool MethodPass::run(Module *M) {
bool FunctionPass::run(Module *M) {
bool Changed = doInitialization(M);
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (!(*I)->isExternal()) // Passes are not run on external methods!
Changed |= runOnMethod(*I);
if (!(*I)->isExternal()) // Passes are not run on external functions!
Changed |= runOnFunction(*I);
return Changed | doFinalization(M);
}
// run - On a method, we simply initialize, run the method, then finalize.
// run - On a function, we simply initialize, run the function, then finalize.
//
bool MethodPass::run(Function *F) {
if (F->isExternal()) return false; // Passes are not run on external methods!
bool FunctionPass::run(Function *F) {
if (F->isExternal()) return false;// Passes are not run on external functions!
return doInitialization(F->getParent()) | runOnMethod(F)
return doInitialization(F->getParent()) | runOnFunction(F)
| doFinalization(F->getParent());
}
void MethodPass::addToPassManager(PassManagerT<Module> *PM,
AnalysisSet &Required, AnalysisSet &Destroyed,
AnalysisSet &Provided) {
PM->addPass(this, Required, Destroyed, Provided);
void FunctionPass::addToPassManager(PassManagerT<Module> *PM,
AnalysisUsage &AU) {
PM->addPass(this, AU);
}
void MethodPass::addToPassManager(PassManagerT<Function> *PM,
AnalysisSet &Required, AnalysisSet &Destroyed,
AnalysisSet &Provided) {
PM->addPass(this, Required, Destroyed, Provided);
void FunctionPass::addToPassManager(PassManagerT<Function> *PM,
AnalysisUsage &AU) {
PM->addPass(this, AU);
}
//===----------------------------------------------------------------------===//
// BasicBlockPass Implementation
//
// To run this pass on a method, we simply call runOnBasicBlock once for each
// method.
// To run this pass on a function, we simply call runOnBasicBlock once for each
// function.
//
bool BasicBlockPass::runOnMethod(Function *F) {
bool BasicBlockPass::runOnFunction(Function *F) {
bool Changed = false;
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
Changed |= runOnBasicBlock(*I);
@ -159,16 +156,12 @@ bool BasicBlockPass::run(BasicBlock *BB) {
}
void BasicBlockPass::addToPassManager(PassManagerT<Function> *PM,
AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
PM->addPass(this, Required, Destroyed, Provided);
AnalysisUsage &AU) {
PM->addPass(this, AU);
}
void BasicBlockPass::addToPassManager(PassManagerT<BasicBlock> *PM,
AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {
PM->addPass(this, Required, Destroyed, Provided);
AnalysisUsage &AU) {
PM->addPass(this, AU);
}

View File

@ -14,6 +14,7 @@
#include "llvm/Pass.h"
#include <string>
#include <algorithm>
//===----------------------------------------------------------------------===//
// PMDebug class - a set of debugging functions, that are not to be
@ -26,7 +27,7 @@ struct PMDebug {
static void PrintPassStructure(Pass *P);
static void PrintPassInformation(unsigned,const char*,Pass *, Value *);
static void PrintAnalysisSetInfo(unsigned,const char*,Pass *P,
const Pass::AnalysisSet&);
const std::vector<AnalysisID> &);
};
@ -107,15 +108,16 @@ public:
PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P, (Value*)M);
// Get information about what analyses the pass uses...
std::vector<AnalysisID> Required, Destroyed, Provided;
P->getAnalysisUsageInfo(Required, Destroyed, Provided);
PMDebug::PrintAnalysisSetInfo(getDepth(), "Required", P, Required);
AnalysisUsage AnUsage;
P->getAnalysisUsage(AnUsage);
PMDebug::PrintAnalysisSetInfo(getDepth(), "Required", P,
AnUsage.getRequiredSet());
#ifndef NDEBUG
// All Required analyses should be available to the pass as it runs!
for (Pass::AnalysisSet::iterator I = Required.begin(),
E = Required.end(); I != E; ++I) {
for (vector<AnalysisID>::const_iterator
I = AnUsage.getRequiredSet().begin(),
E = AnUsage.getRequiredSet().end(); I != E; ++I) {
assert(getAnalysisOrNullUp(*I) && "Analysis used but not available!");
}
#endif
@ -127,17 +129,35 @@ public:
if (Changed)
PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P,
(Value*)M);
PMDebug::PrintAnalysisSetInfo(getDepth(), "Destroyed", P, Destroyed);
PMDebug::PrintAnalysisSetInfo(getDepth(), "Provided", P, Provided);
PMDebug::PrintAnalysisSetInfo(getDepth(), "Preserved", P,
AnUsage.getPreservedSet());
PMDebug::PrintAnalysisSetInfo(getDepth(), "Provided", P,
AnUsage.getProvidedSet());
// Erase all analyses not in the preserved set...
if (!AnUsage.preservesAll()) {
const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
E = CurrentAnalyses.end(); I != E; )
if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
PreservedSet.end())
++I; // This analysis is preserved, leave it in the available set...
else {
#if MAP_DOESNT_HAVE_BROKEN_ERASE_MEMBER
I = CurrentAnalyses.erase(I); // Analysis not preserved!
#else
// GCC 2.95.3 STL doesn't have correct erase member!
CurrentAnalyses.erase(I);
I = CurrentAnalyses.begin();
#endif
}
}
// Erase all analyses in the destroyed set...
for (Pass::AnalysisSet::iterator I = Destroyed.begin(),
E = Destroyed.end(); I != E; ++I)
CurrentAnalyses.erase(*I);
// Add all analyses in the provided set...
for (Pass::AnalysisSet::iterator I = Provided.begin(),
E = Provided.end(); I != E; ++I)
for (std::vector<AnalysisID>::const_iterator
I = AnUsage.getProvidedSet().begin(),
E = AnUsage.getProvidedSet().end(); I != E; ++I)
CurrentAnalyses[*I] = P;
// Free memory for any passes that we are the last use of...
@ -226,12 +246,13 @@ public:
//
void add(PassClass *P) {
// Get information about what analyses the pass uses...
std::vector<AnalysisID> Required, Destroyed, Provided;
P->getAnalysisUsageInfo(Required, Destroyed, Provided);
AnalysisUsage AnUsage;
P->getAnalysisUsage(AnUsage);
const std::vector<AnalysisID> &Required = AnUsage.getRequiredSet();
// Loop over all of the analyses used by this pass,
for (std::vector<AnalysisID>::iterator I = Required.begin(),
E = Required.end(); I != E; ++I) {
for (std::vector<AnalysisID>::const_iterator I = Required.begin(),
E = Required.end(); I != E; ++I) {
if (getAnalysisOrNullDown(*I) == 0)
add((PassClass*)I->createPass());
}
@ -240,7 +261,7 @@ public:
// depends on the class of the pass, and is critical to laying out passes in
// an optimal order..
//
P->addToPassManager(this, Required, Destroyed, Provided);
P->addToPassManager(this, AnUsage);
}
private:
@ -253,15 +274,17 @@ private:
//
// For generic Pass subclasses (which are interprocedural passes), we simply
// add the pass to the end of the pass list and terminate any accumulation of
// MethodPasses that are present.
// FunctionPass's that are present.
//
void addPass(PassClass *P, Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed, Pass::AnalysisSet &Provided) {
void addPass(PassClass *P, AnalysisUsage &AnUsage) {
const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
const std::vector<AnalysisID> &ProvidedSet = AnUsage.getProvidedSet();
// Providers are analysis classes which are forbidden to modify the module
// they are operating on, so they are allowed to be reordered to before the
// batcher...
//
if (Batcher && Provided.empty())
if (Batcher && ProvidedSet.empty())
closeBatcher(); // This pass cannot be batched!
// Set the Resolver instance variable in the Pass so that it knows where to
@ -274,34 +297,46 @@ private:
// being used by this pass. This is used to make sure that analyses are not
// free'd before we have to use them...
//
for (std::vector<AnalysisID>::iterator I = Required.begin(),
E = Required.end(); I != E; ++I)
for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
E = RequiredSet.end(); I != E; ++I)
markPassUsed(*I, P); // Mark *I as used by P
// Erase all analyses in the destroyed set...
for (std::vector<AnalysisID>::iterator I = Destroyed.begin(),
E = Destroyed.end(); I != E; ++I)
CurrentAnalyses.erase(*I);
// Erase all analyses not in the preserved set...
if (!AnUsage.preservesAll()) {
const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
E = CurrentAnalyses.end(); I != E; )
if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
PreservedSet.end())
++I; // This analysis is preserved, leave it in the available set...
else {
#if MAP_DOESNT_HAVE_BROKEN_ERASE_MEMBER
I = CurrentAnalyses.erase(I); // Analysis not preserved!
#else
CurrentAnalyses.erase(I);// GCC 2.95.3 STL doesn't have correct erase!
I = CurrentAnalyses.begin();
#endif
}
}
// Add all analyses in the provided set...
for (std::vector<AnalysisID>::iterator I = Provided.begin(),
E = Provided.end(); I != E; ++I)
for (std::vector<AnalysisID>::const_iterator I = ProvidedSet.begin(),
E = ProvidedSet.end(); I != E; ++I)
CurrentAnalyses[*I] = P;
// For now assume that our results are never used...
LastUseOf[P] = P;
}
// For MethodPass subclasses, we must be sure to batch the MethodPasses
// together in a MethodPassBatcher object so that all of the analyses are run
// together a method at a time.
// For FunctionPass subclasses, we must be sure to batch the FunctionPass's
// together in a BatcherClass object so that all of the analyses are run
// together a function at a time.
//
void addPass(SubPassClass *MP, Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed, Pass::AnalysisSet &Provided) {
void addPass(SubPassClass *MP, AnalysisUsage &AnUsage) {
if (Batcher == 0) // If we don't have a batcher yet, make one now.
Batcher = new BatcherClass(this);
// The Batcher will queue them passes up
MP->addToPassManager(Batcher, Required, Destroyed, Provided);
MP->addToPassManager(Batcher, AnUsage);
}
// closeBatcher - Terminate the batcher that is being worked on.
@ -364,12 +399,12 @@ template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
//===----------------------------------------------------------------------===//
// PassManagerTraits<Function> Specialization
//
// This pass manager is used to group together all of the MethodPass's
// This pass manager is used to group together all of the FunctionPass's
// into a single unit.
//
template<> struct PassManagerTraits<Function> : public MethodPass {
template<> struct PassManagerTraits<Function> : public FunctionPass {
// PassClass - The type of passes tracked by this PassManager
typedef MethodPass PassClass;
typedef FunctionPass PassClass;
// SubPassClass - The types of classes that should be collated together
typedef BasicBlockPass SubPassClass;
@ -384,17 +419,17 @@ template<> struct PassManagerTraits<Function> : public MethodPass {
typedef PassManagerT<Function> PMType;
// runPass - Specify how the pass should be run on the UnitType
static bool runPass(PassClass *P, Function *M) {
return P->runOnMethod(M);
static bool runPass(PassClass *P, Function *F) {
return P->runOnFunction(F);
}
// getPMName() - Return the name of the unit the PassManager operates on for
// debugging.
const char *getPMName() const { return "Function"; }
// Implement the MethodPass interface...
// Implement the FunctionPass interface...
virtual bool doInitialization(Module *M);
virtual bool runOnMethod(Function *M);
virtual bool runOnFunction(Function *F);
virtual bool doFinalization(Module *M);
};
@ -410,7 +445,7 @@ template<> struct PassManagerTraits<Module> : public Pass {
typedef Pass PassClass;
// SubPassClass - The types of classes that should be collated together
typedef MethodPass SubPassClass;
typedef FunctionPass SubPassClass;
// BatcherClass - The type to use for collation of subtypes...
typedef PassManagerT<Function> BatcherClass;
@ -467,8 +502,8 @@ inline bool PassManagerTraits<Function>::doInitialization(Module *M) {
return Changed;
}
inline bool PassManagerTraits<Function>::runOnMethod(Function *M) {
return ((PMType*)this)->runOnUnit(M);
inline bool PassManagerTraits<Function>::runOnFunction(Function *F) {
return ((PMType*)this)->runOnUnit(F);
}
inline bool PassManagerTraits<Function>::doFinalization(Module *M) {

View File

@ -53,7 +53,7 @@
namespace { // Anonymous namespace for class
struct Verifier : public MethodPass, InstVisitor<Verifier> {
struct Verifier : public FunctionPass, InstVisitor<Verifier> {
bool Broken;
Verifier() : Broken(false) {}
@ -63,7 +63,7 @@ namespace { // Anonymous namespace for class
return false;
}
bool runOnMethod(Function *F) {
bool runOnFunction(Function *F) {
visit(F);
return false;
}

View File

@ -90,30 +90,26 @@ public:
return false;
}
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(ID);
}
};
template <class PassName>
class PassPrinter<MethodPass, PassName> : public MethodPass {
class PassPrinter<FunctionPass, PassName> : public FunctionPass {
const string Message;
const AnalysisID ID;
public:
PassPrinter(const string &M, AnalysisID id) : Message(M), ID(id) {}
virtual bool runOnMethod(Function *F) {
std::cout << Message << " on method '" << F->getName() << "'\n";
virtual bool runOnFunction(Function *F) {
std::cout << Message << " on function '" << F->getName() << "'\n";
printPass(getAnalysis<PassName>(ID), std::cout, F);
return false;
}
virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
Pass::AnalysisSet &Destroyed,
Pass::AnalysisSet &Provided) {
Required.push_back(ID);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(ID);
}
};
@ -137,13 +133,13 @@ Pass *NewPrintModule(const string &Message) {
return new PrintModulePass(&std::cout);
}
struct InstForest : public MethodPass {
struct InstForest : public FunctionPass {
void doit(Function *F) {
std::cout << analysis::InstForest<char>(F);
}
};
struct IndVars : public MethodPass {
struct IndVars : public FunctionPass {
void doit(Function *F) {
cfg::LoopInfo &LI = getAnalysis<cfg::LoopInfo>();
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
@ -154,13 +150,12 @@ struct IndVars : public MethodPass {
}
}
void getAnalysisUsageInfo(Pass::AnalysisSet &Req,
Pass::AnalysisSet &, Pass::AnalysisSet &) {
Req.push_back(cfg::LoopInfo::ID);
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID);
}
};
struct Exprs : public MethodPass {
struct Exprs : public FunctionPass {
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) {
@ -197,8 +192,8 @@ class PrinterPass : public TraitClass {
public:
PrinterPass(const string &M) : Message(M) {}
virtual bool runOnMethod(Function *F) {
std::cout << Message << " on method '" << F->getName() << "'\n";
virtual bool runOnFunction(Function *F) {
std::cout << Message << " on function '" << F->getName() << "'\n";
TraitClass::doit(F);
return false;
@ -259,8 +254,8 @@ struct {
} AnTable[] = {
// Global analyses
{ print , NewPrintFunction },
{ intervals , New<MethodPass, cfg::IntervalPartition> },
{ loops , New<MethodPass, cfg::LoopInfo> },
{ intervals , New<FunctionPass, cfg::IntervalPartition> },
{ loops , New<FunctionPass, cfg::LoopInfo> },
{ instforest , Create<PrinterPass<InstForest> > },
{ indvars , Create<PrinterPass<IndVars> > },
{ exprs , Create<PrinterPass<Exprs> > },
@ -273,15 +268,15 @@ struct {
{ unsafepointertypes, New<Pass, FindUnsafePointerTypes> },
// Dominator analyses
{ domset , New<MethodPass, cfg::DominatorSet> },
{ idom , New<MethodPass, cfg::ImmediateDominators> },
{ domtree , New<MethodPass, cfg::DominatorTree> },
{ domfrontier , New<MethodPass, cfg::DominanceFrontier> },
{ domset , New<FunctionPass, cfg::DominatorSet> },
{ idom , New<FunctionPass, cfg::ImmediateDominators> },
{ domtree , New<FunctionPass, cfg::DominatorTree> },
{ domfrontier , New<FunctionPass, cfg::DominanceFrontier> },
{ postdomset , New<MethodPass, cfg::DominatorSet, cfg::DominatorSet::PostDomID> },
{ postidom , New<MethodPass, cfg::ImmediateDominators, cfg::ImmediateDominators::PostDomID> },
{ postdomtree , New<MethodPass, cfg::DominatorTree, cfg::DominatorTree::PostDomID> },
{ postdomfrontier , New<MethodPass, cfg::DominanceFrontier, cfg::DominanceFrontier::PostDomID> },
{ postdomset , New<FunctionPass, cfg::DominatorSet, cfg::DominatorSet::PostDomID> },
{ postidom , New<FunctionPass, cfg::ImmediateDominators, cfg::ImmediateDominators::PostDomID> },
{ postdomtree , New<FunctionPass, cfg::DominatorTree, cfg::DominatorTree::PostDomID> },
{ postdomfrontier , New<FunctionPass, cfg::DominanceFrontier, cfg::DominanceFrontier::PostDomID> },
};
int main(int argc, char **argv) {

View File

@ -88,7 +88,7 @@ int main(int argc, char **argv) {
if (TraceValues == TraceBasicBlocks)
Passes.add(createTraceValuesPassForBasicBlocks());
else if (TraceValues == TraceFunctions)
Passes.add(createTraceValuesPassForMethod());
Passes.add(createTraceValuesPassForFunction());
else
assert(0 && "Bad value for TraceValues!");

View File

@ -70,35 +70,35 @@ struct {
enum Opts OptID;
Pass * (*PassCtor)();
} OptTable[] = {
{ dce , createDeadCodeEliminationPass },
{ die , createDeadInstEliminationPass },
{ constprop , createConstantPropogationPass },
{ inlining , createMethodInliningPass },
{ constmerge , createConstantMergePass },
{ strip , createSymbolStrippingPass },
{ mstrip , createFullSymbolStrippingPass },
{ dce , createDeadCodeEliminationPass },
{ die , createDeadInstEliminationPass },
{ constprop , createConstantPropogationPass },
{ inlining , createFunctionInliningPass },
{ constmerge , createConstantMergePass },
{ strip , createSymbolStrippingPass },
{ mstrip , createFullSymbolStrippingPass },
{ mergereturn, createUnifyMethodExitNodesPass },
{ indvars , createIndVarSimplifyPass },
{ instcombine, createInstructionCombiningPass },
{ sccp , createSCCPPass },
{ adce , createAgressiveDCEPass },
{ indvars , createIndVarSimplifyPass },
{ instcombine, createInstructionCombiningPass },
{ sccp , createSCCPPass },
{ adce , createAgressiveDCEPass },
{ raise , createRaisePointerReferencesPass },
{ mem2reg , createPromoteMemoryToRegister },
{ lowerrefs, createDecomposeMultiDimRefsPass },
{ mem2reg , createPromoteMemoryToRegister },
{ lowerrefs, createDecomposeMultiDimRefsPass },
{ trace , createTraceValuesPassForBasicBlocks },
{ tracem , createTraceValuesPassForMethod },
{ paths , createProfilePathsPass },
{ tracem , createTraceValuesPassForFunction },
{ paths , createProfilePathsPass },
{ print , createPrintFunctionPass },
{ printm , createPrintModulePass },
{ verify , createVerifierPass },
{ printm , createPrintModulePass },
{ verify , createVerifierPass },
{ raiseallocs, createRaiseAllocationsPass },
{ cleangcc , createCleanupGCCOutputPass },
{ raiseallocs, createRaiseAllocationsPass },
{ cleangcc , createCleanupGCCOutputPass },
{ funcresolve, createFunctionResolvingPass },
{ globaldce , createGlobalDCEPass },
{ globaldce , createGlobalDCEPass },
{ swapstructs, createSwapElementsPass },
{ sortstructs, createSortElementsPass },
{ poolalloc , createPoolAllocatePass },