OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_LOOP_ANALYSIS_H_ | 5 #ifndef V8_COMPILER_LOOP_ANALYSIS_H_ |
6 #define V8_COMPILER_LOOP_ANALYSIS_H_ | 6 #define V8_COMPILER_LOOP_ANALYSIS_H_ |
7 | 7 |
8 #include "src/base/iterator.h" | 8 #include "src/base/iterator.h" |
9 #include "src/compiler/graph.h" | 9 #include "src/compiler/graph.h" |
10 #include "src/compiler/node.h" | 10 #include "src/compiler/node.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Represents a loop in the tree of loops, including the header nodes, | 31 // Represents a loop in the tree of loops, including the header nodes, |
32 // the body, and any nested loops. | 32 // the body, and any nested loops. |
33 class Loop { | 33 class Loop { |
34 public: | 34 public: |
35 Loop* parent() const { return parent_; } | 35 Loop* parent() const { return parent_; } |
36 const ZoneVector<Loop*>& children() const { return children_; } | 36 const ZoneVector<Loop*>& children() const { return children_; } |
37 size_t HeaderSize() const { return body_start_ - header_start_; } | 37 size_t HeaderSize() const { return body_start_ - header_start_; } |
38 size_t BodySize() const { return body_end_ - body_start_; } | 38 size_t BodySize() const { return body_end_ - body_start_; } |
39 size_t TotalSize() const { return body_end_ - header_start_; } | 39 size_t TotalSize() const { return body_end_ - header_start_; } |
| 40 size_t depth() const { return static_cast<size_t>(depth_); } |
40 | 41 |
41 private: | 42 private: |
42 friend class LoopTree; | 43 friend class LoopTree; |
43 friend class LoopFinderImpl; | 44 friend class LoopFinderImpl; |
44 | 45 |
45 explicit Loop(Zone* zone) | 46 explicit Loop(Zone* zone) |
46 : parent_(nullptr), | 47 : parent_(nullptr), |
47 depth_(0), | 48 depth_(0), |
48 children_(zone), | 49 children_(zone), |
49 header_start_(-1), | 50 header_start_(-1), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 return NodeRange(&loop_nodes_[0] + loop->header_start_, | 88 return NodeRange(&loop_nodes_[0] + loop->header_start_, |
88 &loop_nodes_[0] + loop->body_start_); | 89 &loop_nodes_[0] + loop->body_start_); |
89 } | 90 } |
90 | 91 |
91 // Return a range which can iterate over the body nodes of {loop}. | 92 // Return a range which can iterate over the body nodes of {loop}. |
92 NodeRange BodyNodes(Loop* loop) { | 93 NodeRange BodyNodes(Loop* loop) { |
93 return NodeRange(&loop_nodes_[0] + loop->body_start_, | 94 return NodeRange(&loop_nodes_[0] + loop->body_start_, |
94 &loop_nodes_[0] + loop->body_end_); | 95 &loop_nodes_[0] + loop->body_end_); |
95 } | 96 } |
96 | 97 |
| 98 // Return a range which can iterate over the nodes of {loop}. |
| 99 NodeRange LoopNodes(Loop* loop) { |
| 100 return NodeRange(&loop_nodes_[0] + loop->header_start_, |
| 101 &loop_nodes_[0] + loop->body_end_); |
| 102 } |
| 103 |
| 104 // Return the node that represents the control, i.e. the loop node itself. |
| 105 Node* GetLoopControl(Loop* loop) { |
| 106 // TODO(turbofan): make the loop control node always first? |
| 107 for (Node* node : HeaderNodes(loop)) { |
| 108 if (node->opcode() == IrOpcode::kLoop) return node; |
| 109 } |
| 110 UNREACHABLE(); |
| 111 return NULL; |
| 112 } |
| 113 |
97 private: | 114 private: |
98 friend class LoopFinderImpl; | 115 friend class LoopFinderImpl; |
99 | 116 |
100 Loop* NewLoop() { | 117 Loop* NewLoop() { |
101 all_loops_.push_back(Loop(zone_)); | 118 all_loops_.push_back(Loop(zone_)); |
102 Loop* result = &all_loops_.back(); | 119 Loop* result = &all_loops_.back(); |
103 return result; | 120 return result; |
104 } | 121 } |
105 | 122 |
106 void SetParent(Loop* parent, Loop* child) { | 123 void SetParent(Loop* parent, Loop* child) { |
(...skipping 14 matching lines...) Expand all Loading... |
121 ZoneVector<Node*> loop_nodes_; | 138 ZoneVector<Node*> loop_nodes_; |
122 }; | 139 }; |
123 | 140 |
124 | 141 |
125 class LoopFinder { | 142 class LoopFinder { |
126 public: | 143 public: |
127 // Build a loop tree for the entire graph. | 144 // Build a loop tree for the entire graph. |
128 static LoopTree* BuildLoopTree(Graph* graph, Zone* temp_zone); | 145 static LoopTree* BuildLoopTree(Graph* graph, Zone* temp_zone); |
129 }; | 146 }; |
130 | 147 |
| 148 |
131 } // namespace compiler | 149 } // namespace compiler |
132 } // namespace internal | 150 } // namespace internal |
133 } // namespace v8 | 151 } // namespace v8 |
134 | 152 |
135 #endif // V8_COMPILER_LOOP_ANALYSIS_H_ | 153 #endif // V8_COMPILER_LOOP_ANALYSIS_H_ |
OLD | NEW |