X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FAnalysis%2FSparsePropagation.h;h=76c8ccf59c2b553630f2b276fe280725ef1bd0de;hb=4f7e2c38e864d7eaeb407ac501478e9579624d1b;hp=dea81b1e88704282dc0ae972c1172219f7685377;hpb=e3fc3858a2e9d6483a68a6696d07f29ccc799cce;p=oota-llvm.git diff --git a/include/llvm/Analysis/SparsePropagation.h b/include/llvm/Analysis/SparsePropagation.h index dea81b1e887..76c8ccf59c2 100644 --- a/include/llvm/Analysis/SparsePropagation.h +++ b/include/llvm/Analysis/SparsePropagation.h @@ -12,27 +12,30 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_ANALYSIS_SPARSE_PROPAGATION_H -#define LLVM_ANALYSIS_SPARSE_PROPAGATION_H +#ifndef LLVM_ANALYSIS_SPARSEPROPAGATION_H +#define LLVM_ANALYSIS_SPARSEPROPAGATION_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/SmallVector.h" -#include #include +#include namespace llvm { class Value; class Constant; + class Argument; class Instruction; class PHINode; class TerminatorInst; class BasicBlock; class Function; class SparseSolver; + class raw_ostream; + + template class SmallVectorImpl; /// AbstractLatticeFunction - This class is implemented by the dataflow instance -/// to specify what the lattice values are and what how they handle merges etc. +/// to specify what the lattice values are and how they handle merges etc. /// This gives the client the power to compute lattice values from instructions, /// constants, etc. The requirement is that lattice values must all fit into /// a void*. If a void* is not sufficient, the implementation should use this @@ -68,6 +71,12 @@ public: virtual LatticeVal ComputeConstant(Constant *C) { return getOverdefinedVal(); // always safe } + + /// IsSpecialCasedPHI - Given a PHI node, determine whether this PHI node is + /// one that the we want to handle through ComputeInstructionState. + virtual bool IsSpecialCasedPHI(PHINode *PN) { + return false; + } /// GetConstant - If the specified lattice value is representable as an LLVM /// constant value, return it. Otherwise return null. The returned value @@ -75,6 +84,12 @@ public: virtual Constant *GetConstant(LatticeVal LV, Value *Val, SparseSolver &SS) { return 0; } + + /// ComputeArgument - Given a formal argument value, compute and return a + /// lattice value corresponding to the specified argument. + virtual LatticeVal ComputeArgument(Argument *I) { + return getOverdefinedVal(); // always safe + } /// MergeValues - Compute and return the merge of the two specified lattice /// values. Merging should only move one direction down the lattice to @@ -90,7 +105,7 @@ public: } /// PrintValue - Render the specified lattice value to the specified stream. - virtual void PrintValue(LatticeVal V, std::ostream &OS); + virtual void PrintValue(LatticeVal V, raw_ostream &OS); }; @@ -115,11 +130,12 @@ class SparseSolver { /// PHI nodes retriggered. typedef std::pair Edge; std::set KnownFeasibleEdges; - - SparseSolver(const SparseSolver&); // DO NOT IMPLEMENT - void operator=(const SparseSolver&); // DO NOT IMPLEMENT + + SparseSolver(const SparseSolver&) LLVM_DELETED_FUNCTION; + void operator=(const SparseSolver&) LLVM_DELETED_FUNCTION; public: - SparseSolver(AbstractLatticeFunction *Lattice) : LatticeFunc(Lattice) {} + explicit SparseSolver(AbstractLatticeFunction *Lattice) + : LatticeFunc(Lattice) {} ~SparseSolver() { delete LatticeFunc; } @@ -128,13 +144,13 @@ public: /// void Solve(Function &F); - void Print(Function &F, std::ostream &OS); + void Print(Function &F, raw_ostream &OS) const; /// getLatticeState - Return the LatticeVal object that corresponds to the /// value. If an value is not in the map, it is returned as untracked, /// unlike the getOrInitValueState method. LatticeVal getLatticeState(Value *V) const { - DenseMap::iterator I = ValueState.find(V); + DenseMap::const_iterator I = ValueState.find(V); return I != ValueState.end() ? I->second : LatticeFunc->getUntrackedVal(); } @@ -147,8 +163,19 @@ public: LatticeVal getOrInitValueState(Value *V); /// isEdgeFeasible - Return true if the control flow edge from the 'From' - /// basic block to the 'To' basic block is currently feasible... - bool isEdgeFeasible(BasicBlock *From, BasicBlock *To); + /// basic block to the 'To' basic block is currently feasible. If + /// AggressiveUndef is true, then this treats values with unknown lattice + /// values as undefined. This is generally only useful when solving the + /// lattice, not when querying it. + bool isEdgeFeasible(BasicBlock *From, BasicBlock *To, + bool AggressiveUndef = false); + + /// isBlockExecutable - Return true if there are any known feasible + /// edges into the basic block. This is generally only useful when + /// querying the lattice. + bool isBlockExecutable(BasicBlock *BB) const { + return BBExecutable.count(BB); + } private: /// UpdateState - When the state for some instruction is potentially updated, @@ -165,7 +192,8 @@ private: /// getFeasibleSuccessors - Return a vector of booleans to indicate which /// successors are reachable from a given terminator instruction. - void getFeasibleSuccessors(TerminatorInst &TI, SmallVectorImpl &Succs); + void getFeasibleSuccessors(TerminatorInst &TI, SmallVectorImpl &Succs, + bool AggressiveUndef); void visitInst(Instruction &I); void visitPHINode(PHINode &I); @@ -175,4 +203,4 @@ private: } // end namespace llvm -#endif // LLVM_ANALYSIS_SPARSE_PROPAGATION_H +#endif // LLVM_ANALYSIS_SPARSEPROPAGATION_H