Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.0 KiB

  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. #ifndef LLVM_ANALYSIS_INTERVAL_H
  20. #define LLVM_ANALYSIS_INTERVAL_H
  21. #include "llvm/ADT/GraphTraits.h"
  22. #include <vector>
  23. namespace llvm {
  24. class BasicBlock;
  25. class raw_ostream;
  26. //===----------------------------------------------------------------------===//
  27. //
  28. /// Interval Class - An Interval is a set of nodes defined such that every node
  29. /// in the interval has all of its predecessors in the interval (except for the
  30. /// header)
  31. ///
  32. class Interval {
  33. /// HeaderNode - The header BasicBlock, which dominates all BasicBlocks in this
  34. /// interval. Also, any loops in this interval must go through the HeaderNode.
  35. ///
  36. BasicBlock *HeaderNode;
  37. public:
  38. typedef std::vector<BasicBlock*>::iterator succ_iterator;
  39. typedef std::vector<BasicBlock*>::iterator pred_iterator;
  40. typedef std::vector<BasicBlock*>::iterator node_iterator;
  41. inline Interval(BasicBlock *Header) : HeaderNode(Header) {
  42. Nodes.push_back(Header);
  43. }
  44. inline Interval(const Interval &I) // copy ctor
  45. : HeaderNode(I.HeaderNode), Nodes(I.Nodes), Successors(I.Successors) {}
  46. inline BasicBlock *getHeaderNode() const { return HeaderNode; }
  47. /// Nodes - The basic blocks in this interval.
  48. ///
  49. std::vector<BasicBlock*> Nodes;
  50. /// Successors - List of BasicBlocks that are reachable directly from nodes in
  51. /// this interval, but are not in the interval themselves.
  52. /// These nodes necessarily must be header nodes for other intervals.
  53. ///
  54. std::vector<BasicBlock*> Successors;
  55. /// Predecessors - List of BasicBlocks that have this Interval's header block
  56. /// as one of their successors.
  57. ///
  58. std::vector<BasicBlock*> Predecessors;
  59. /// contains - Find out if a basic block is in this interval
  60. inline bool contains(BasicBlock *BB) const {
  61. for (unsigned i = 0; i < Nodes.size(); ++i)
  62. if (Nodes[i] == BB) return true;
  63. return false;
  64. // I don't want the dependency on <algorithm>
  65. //return find(Nodes.begin(), Nodes.end(), BB) != Nodes.end();
  66. }
  67. /// isSuccessor - find out if a basic block is a successor of this Interval
  68. inline bool isSuccessor(BasicBlock *BB) const {
  69. for (unsigned i = 0; i < Successors.size(); ++i)
  70. if (Successors[i] == BB) return true;
  71. return false;
  72. // I don't want the dependency on <algorithm>
  73. //return find(Successors.begin(), Successors.end(), BB) != Successors.end();
  74. }
  75. /// Equality operator. It is only valid to compare two intervals from the
  76. /// same partition, because of this, all we have to check is the header node
  77. /// for equality.
  78. ///
  79. inline bool operator==(const Interval &I) const {
  80. return HeaderNode == I.HeaderNode;
  81. }
  82. /// isLoop - Find out if there is a back edge in this interval...
  83. bool isLoop() const;
  84. /// print - Show contents in human readable format...
  85. void print(raw_ostream &O) const;
  86. };
  87. /// succ_begin/succ_end - define methods so that Intervals may be used
  88. /// just like BasicBlocks can with the succ_* functions, and *::succ_iterator.
  89. ///
  90. inline Interval::succ_iterator succ_begin(Interval *I) {
  91. return I->Successors.begin();
  92. }
  93. inline Interval::succ_iterator succ_end(Interval *I) {
  94. return I->Successors.end();
  95. }
  96. /// pred_begin/pred_end - define methods so that Intervals may be used
  97. /// just like BasicBlocks can with the pred_* functions, and *::pred_iterator.
  98. ///
  99. inline Interval::pred_iterator pred_begin(Interval *I) {
  100. return I->Predecessors.begin();
  101. }
  102. inline Interval::pred_iterator pred_end(Interval *I) {
  103. return I->Predecessors.end();
  104. }
  105. template <> struct GraphTraits<Interval*> {
  106. typedef Interval NodeType;
  107. typedef Interval::succ_iterator ChildIteratorType;
  108. static NodeType *getEntryNode(Interval *I) { return I; }
  109. /// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
  110. static inline ChildIteratorType child_begin(NodeType *N) {
  111. return succ_begin(N);
  112. }
  113. static inline ChildIteratorType child_end(NodeType *N) {
  114. return succ_end(N);
  115. }
  116. };
  117. template <> struct GraphTraits<Inverse<Interval*> > {
  118. typedef Interval NodeType;
  119. typedef Interval::pred_iterator ChildIteratorType;
  120. static NodeType *getEntryNode(Inverse<Interval *> G) { return G.Graph; }
  121. static inline ChildIteratorType child_begin(NodeType *N) {
  122. return pred_begin(N);
  123. }
  124. static inline ChildIteratorType child_end(NodeType *N) {
  125. return pred_end(N);
  126. }
  127. };
  128. } // End llvm namespace
  129. #endif