00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef LLVM_INTERVAL_H
00021 #define LLVM_INTERVAL_H
00022
00023 #include "llvm/ADT/GraphTraits.h"
00024 #include <vector>
00025
00026 namespace llvm {
00027
00028 class BasicBlock;
00029 class raw_ostream;
00030
00031
00032
00037 class Interval {
00041 BasicBlock *HeaderNode;
00042 public:
00043 typedef std::vector<BasicBlock*>::iterator succ_iterator;
00044 typedef std::vector<BasicBlock*>::iterator pred_iterator;
00045 typedef std::vector<BasicBlock*>::iterator node_iterator;
00046
00047 inline Interval(BasicBlock *Header) : HeaderNode(Header) {
00048 Nodes.push_back(Header);
00049 }
00050
00051 inline Interval(const Interval &I)
00052 : HeaderNode(I.HeaderNode), Nodes(I.Nodes), Successors(I.Successors) {}
00053
00054 inline BasicBlock *getHeaderNode() const { return HeaderNode; }
00055
00058 std::vector<BasicBlock*> Nodes;
00059
00064 std::vector<BasicBlock*> Successors;
00065
00069 std::vector<BasicBlock*> Predecessors;
00070
00072 inline bool contains(BasicBlock *BB) const {
00073 for (unsigned i = 0; i < Nodes.size(); ++i)
00074 if (Nodes[i] == BB) return true;
00075 return false;
00076
00077
00078 }
00079
00081 inline bool isSuccessor(BasicBlock *BB) const {
00082 for (unsigned i = 0; i < Successors.size(); ++i)
00083 if (Successors[i] == BB) return true;
00084 return false;
00085
00086
00087 }
00088
00093 inline bool operator==(const Interval &I) const {
00094 return HeaderNode == I.HeaderNode;
00095 }
00096
00098 bool isLoop() const;
00099
00101 void print(raw_ostream &O) const;
00102 };
00103
00107 inline Interval::succ_iterator succ_begin(Interval *I) {
00108 return I->Successors.begin();
00109 }
00110 inline Interval::succ_iterator succ_end(Interval *I) {
00111 return I->Successors.end();
00112 }
00113
00117 inline Interval::pred_iterator pred_begin(Interval *I) {
00118 return I->Predecessors.begin();
00119 }
00120 inline Interval::pred_iterator pred_end(Interval *I) {
00121 return I->Predecessors.end();
00122 }
00123
00124 template <> struct GraphTraits<Interval*> {
00125 typedef Interval NodeType;
00126 typedef Interval::succ_iterator ChildIteratorType;
00127
00128 static NodeType *getEntryNode(Interval *I) { return I; }
00129
00131 static inline ChildIteratorType child_begin(NodeType *N) {
00132 return succ_begin(N);
00133 }
00134 static inline ChildIteratorType child_end(NodeType *N) {
00135 return succ_end(N);
00136 }
00137 };
00138
00139 template <> struct GraphTraits<Inverse<Interval*> > {
00140 typedef Interval NodeType;
00141 typedef Interval::pred_iterator ChildIteratorType;
00142 static NodeType *getEntryNode(Inverse<Interval *> G) { return G.Graph; }
00143 static inline ChildIteratorType child_begin(NodeType *N) {
00144 return pred_begin(N);
00145 }
00146 static inline ChildIteratorType child_end(NodeType *N) {
00147 return pred_end(N);
00148 }
00149 };
00150
00151 }
00152
00153 #endif