5 #ifndef V8_COMPILER_LOOP_ANALYSIS_H_ 6 #define V8_COMPILER_LOOP_ANALYSIS_H_ 8 #include "src/base/iterator.h" 9 #include "src/compiler/graph.h" 10 #include "src/compiler/node.h" 11 #include "src/globals.h" 12 #include "src/zone/zone-containers.h" 19 static const int kAssumedLoopEntryIndex = 0;
23 typedef base::iterator_range<Node**> NodeRange;
32 node_to_loop_num_(static_cast<int>(num_nodes), -1, zone),
39 Loop* parent()
const {
return parent_; }
41 size_t HeaderSize()
const {
return body_start_ - header_start_; }
42 size_t BodySize()
const {
return exits_start_ - body_start_; }
43 size_t ExitsSize()
const {
return exits_end_ - exits_start_; }
44 size_t TotalSize()
const {
return exits_end_ - header_start_; }
45 size_t depth()
const {
return static_cast<size_t>(depth_); }
70 if (node->id() >= node_to_loop_num_.size())
return nullptr;
71 int num = node_to_loop_num_[node->id()];
72 return num > 0 ? &all_loops_[num - 1] :
nullptr;
77 bool Contains(Loop* loop,
Node* node) {
78 for (Loop* c = ContainingLoop(node); c !=
nullptr; c = c->parent_) {
79 if (c == loop)
return true;
85 const ZoneVector<Loop*>& outer_loops()
const {
return outer_loops_; }
88 int LoopNum(Loop* loop)
const {
89 return 1 +
static_cast<int>(loop - &all_loops_[0]);
93 NodeRange HeaderNodes(Loop* loop) {
94 return NodeRange(&loop_nodes_[0] + loop->header_start_,
95 &loop_nodes_[0] + loop->body_start_);
99 Node* HeaderNode(Loop* loop);
102 NodeRange BodyNodes(Loop* loop) {
103 return NodeRange(&loop_nodes_[0] + loop->body_start_,
104 &loop_nodes_[0] + loop->exits_start_);
108 NodeRange ExitNodes(Loop* loop) {
109 return NodeRange(&loop_nodes_[0] + loop->exits_start_,
110 &loop_nodes_[0] + loop->exits_end_);
114 NodeRange LoopNodes(Loop* loop) {
115 return NodeRange(&loop_nodes_[0] + loop->header_start_,
116 &loop_nodes_[0] + loop->exits_end_);
120 Node* GetLoopControl(Loop* loop) {
122 for (Node* node : HeaderNodes(loop)) {
123 if (node->opcode() == IrOpcode::kLoop)
return node;
128 Zone* zone()
const {
return zone_; }
131 friend class LoopFinderImpl;
134 all_loops_.push_back(Loop(zone_));
135 Loop* result = &all_loops_.back();
139 void SetParent(Loop* parent, Loop* child) {
140 if (parent !=
nullptr) {
141 parent->children_.push_back(child);
142 child->parent_ = parent;
143 child->depth_ = parent->depth_ + 1;
145 outer_loops_.push_back(child);
150 ZoneVector<Loop*> outer_loops_;
151 ZoneVector<Loop> all_loops_;
152 ZoneVector<int> node_to_loop_num_;
153 ZoneVector<Node*> loop_nodes_;
167 #endif // V8_COMPILER_LOOP_ANALYSIS_H_