LLVM  6.0.0svn
Interval.h
Go to the documentation of this file.
1 //===- llvm/Analysis/Interval.h - Interval Class Declaration ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the Interval class, which
11 // represents a set of CFG nodes and is a portion of an interval partition.
12 //
13 // Intervals have some interesting and useful properties, including the
14 // following:
15 // 1. The header node of an interval dominates all of the elements of the
16 // interval
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLVM_ANALYSIS_INTERVAL_H
21 #define LLVM_ANALYSIS_INTERVAL_H
22 
23 #include "llvm/ADT/GraphTraits.h"
24 #include <vector>
25 
26 namespace llvm {
27 
28 class BasicBlock;
29 class raw_ostream;
30 
31 //===----------------------------------------------------------------------===//
32 //
33 /// Interval Class - An Interval is a set of nodes defined such that every node
34 /// in the interval has all of its predecessors in the interval (except for the
35 /// header)
36 ///
37 class Interval {
38  /// HeaderNode - The header BasicBlock, which dominates all BasicBlocks in this
39  /// interval. Also, any loops in this interval must go through the HeaderNode.
40  ///
41  BasicBlock *HeaderNode;
42 public:
43  typedef std::vector<BasicBlock*>::iterator succ_iterator;
44  typedef std::vector<BasicBlock*>::iterator pred_iterator;
45  typedef std::vector<BasicBlock*>::iterator node_iterator;
46 
47  inline Interval(BasicBlock *Header) : HeaderNode(Header) {
48  Nodes.push_back(Header);
49  }
50 
51  inline BasicBlock *getHeaderNode() const { return HeaderNode; }
52 
53  /// Nodes - The basic blocks in this interval.
54  ///
55  std::vector<BasicBlock*> Nodes;
56 
57  /// Successors - List of BasicBlocks that are reachable directly from nodes in
58  /// this interval, but are not in the interval themselves.
59  /// These nodes necessarily must be header nodes for other intervals.
60  ///
61  std::vector<BasicBlock*> Successors;
62 
63  /// Predecessors - List of BasicBlocks that have this Interval's header block
64  /// as one of their successors.
65  ///
66  std::vector<BasicBlock*> Predecessors;
67 
68  /// contains - Find out if a basic block is in this interval
69  inline bool contains(BasicBlock *BB) const {
70  for (BasicBlock *Node : Nodes)
71  if (Node == BB)
72  return true;
73  return false;
74  // I don't want the dependency on <algorithm>
75  //return find(Nodes.begin(), Nodes.end(), BB) != Nodes.end();
76  }
77 
78  /// isSuccessor - find out if a basic block is a successor of this Interval
79  inline bool isSuccessor(BasicBlock *BB) const {
80  for (BasicBlock *Successor : Successors)
81  if (Successor == BB)
82  return true;
83  return false;
84  // I don't want the dependency on <algorithm>
85  //return find(Successors.begin(), Successors.end(), BB) != Successors.end();
86  }
87 
88  /// Equality operator. It is only valid to compare two intervals from the
89  /// same partition, because of this, all we have to check is the header node
90  /// for equality.
91  ///
92  inline bool operator==(const Interval &I) const {
93  return HeaderNode == I.HeaderNode;
94  }
95 
96  /// isLoop - Find out if there is a back edge in this interval...
97  bool isLoop() const;
98 
99  /// print - Show contents in human readable format...
100  void print(raw_ostream &O) const;
101 };
102 
103 /// succ_begin/succ_end - define methods so that Intervals may be used
104 /// just like BasicBlocks can with the succ_* functions, and *::succ_iterator.
105 ///
107  return I->Successors.begin();
108 }
110  return I->Successors.end();
111 }
112 
113 /// pred_begin/pred_end - define methods so that Intervals may be used
114 /// just like BasicBlocks can with the pred_* functions, and *::pred_iterator.
115 ///
117  return I->Predecessors.begin();
118 }
120  return I->Predecessors.end();
121 }
122 
123 template <> struct GraphTraits<Interval*> {
124  typedef Interval *NodeRef;
126 
127  static NodeRef getEntryNode(Interval *I) { return I; }
128 
129  /// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
130  static ChildIteratorType child_begin(NodeRef N) { return succ_begin(N); }
131  static ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
132 };
133 
134 template <> struct GraphTraits<Inverse<Interval*> > {
135  typedef Interval *NodeRef;
137  static NodeRef getEntryNode(Inverse<Interval *> G) { return G.Graph; }
138  static ChildIteratorType child_begin(NodeRef N) { return pred_begin(N); }
139  static ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
140 };
141 
142 } // End llvm namespace
143 
144 #endif
Interval::pred_iterator ChildIteratorType
Definition: Interval.h:136
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isLoop() const
isLoop - Find out if there is a back edge in this interval...
Definition: Interval.cpp:29
Various leaf nodes.
Definition: ISDOpcodes.h:60
bool operator==(const Interval &I) const
Equality operator.
Definition: Interval.h:92
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Definition: Interval.h:37
static ChildIteratorType child_begin(NodeRef N)
nodes_iterator/begin/end - Allow iteration over all nodes in the graph
Definition: Interval.h:130
static NodeRef getEntryNode(Inverse< Interval *> G)
Definition: Interval.h:137
Interval::succ_iterator ChildIteratorType
Definition: Interval.h:125
static ChildIteratorType child_end(NodeRef N)
Definition: Interval.h:131
std::vector< BasicBlock * >::iterator node_iterator
Definition: Interval.h:45
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:106
static ChildIteratorType child_begin(NodeRef N)
Definition: Interval.h:138
bool contains(BasicBlock *BB) const
contains - Find out if a basic block is in this interval
Definition: Interval.h:69
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:109
BasicBlock * getHeaderNode() const
Definition: Interval.h:51
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:116
bool isSuccessor(BasicBlock *BB) const
isSuccessor - find out if a basic block is a successor of this Interval
Definition: Interval.h:79
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:119
std::vector< BasicBlock * > Nodes
Nodes - The basic blocks in this interval.
Definition: Interval.h:55
const GraphType & Graph
Definition: GraphTraits.h:77
static NodeRef getEntryNode(Interval *I)
Definition: Interval.h:127
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
const size_t N
std::vector< BasicBlock * > Predecessors
Predecessors - List of BasicBlocks that have this Interval&#39;s header block as one of their successors...
Definition: Interval.h:66
std::vector< BasicBlock * > Successors
Successors - List of BasicBlocks that are reachable directly from nodes in this interval, but are not in the interval themselves.
Definition: Interval.h:61
#define I(x, y, z)
Definition: MD5.cpp:58
void print(raw_ostream &O) const
print - Show contents in human readable format...
Definition: Interval.cpp:40
static ChildIteratorType child_end(NodeRef N)
Definition: Interval.h:139
std::vector< BasicBlock * >::iterator succ_iterator
Definition: Interval.h:43
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
Interval(BasicBlock *Header)
Definition: Interval.h:47
std::vector< BasicBlock * >::iterator pred_iterator
Definition: Interval.h:44