Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: src/compiler/loop-analysis.h

Issue 855653002: [turbofan] Improve loop analysis to handle more than 32 loops. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler/loop-analysis.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "src/zone-containers.h" 11 #include "src/zone-containers.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 namespace compiler { 15 namespace compiler {
16 16
17 class LoopFinderImpl; 17 class LoopFinderImpl;
18 18
19 typedef base::iterator_range<Node**> NodeRange; 19 typedef base::iterator_range<Node**> NodeRange;
20 20
21 // Represents a tree of loops in a graph. 21 // Represents a tree of loops in a graph.
22 class LoopTree : public ZoneObject { 22 class LoopTree : public ZoneObject {
23 public: 23 public:
24 LoopTree(size_t num_nodes, Zone* zone) 24 LoopTree(size_t num_nodes, Zone* zone)
25 : zone_(zone), 25 : zone_(zone),
26 outer_loops_(zone), 26 outer_loops_(zone),
27 all_loops_(zone), 27 all_loops_(zone),
28 node_to_loop_num_(static_cast<int>(num_nodes), 0, zone), 28 node_to_loop_num_(static_cast<int>(num_nodes), -1, zone),
29 loop_nodes_(zone) {} 29 loop_nodes_(zone) {}
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_; }
(...skipping 15 matching lines...) Expand all
54 ZoneVector<Loop*> children_; 54 ZoneVector<Loop*> children_;
55 int header_start_; 55 int header_start_;
56 int body_start_; 56 int body_start_;
57 int body_end_; 57 int body_end_;
58 }; 58 };
59 59
60 // Return the innermost nested loop, if any, that contains {node}. 60 // Return the innermost nested loop, if any, that contains {node}.
61 Loop* ContainingLoop(Node* node) { 61 Loop* ContainingLoop(Node* node) {
62 if (node->id() >= static_cast<int>(node_to_loop_num_.size())) 62 if (node->id() >= static_cast<int>(node_to_loop_num_.size()))
63 return nullptr; 63 return nullptr;
64 uint8_t num = node_to_loop_num_[node->id()]; 64 int num = node_to_loop_num_[node->id()];
65 return num > 0 ? &all_loops_[num - 1] : nullptr; 65 return num > 0 ? &all_loops_[num - 1] : nullptr;
66 } 66 }
67 67
68 // Check if the {loop} contains the {node}, either directly or by containing 68 // Check if the {loop} contains the {node}, either directly or by containing
69 // a nested loop that contains {node}. 69 // a nested loop that contains {node}.
70 bool Contains(Loop* loop, Node* node) { 70 bool Contains(Loop* loop, Node* node) {
71 for (Loop* c = ContainingLoop(node); c != nullptr; c = c->parent_) { 71 for (Loop* c = ContainingLoop(node); c != nullptr; c = c->parent_) {
72 if (c == loop) return true; 72 if (c == loop) return true;
73 } 73 }
74 return false; 74 return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 child->parent_ = parent; 109 child->parent_ = parent;
110 child->depth_ = parent->depth_ + 1; 110 child->depth_ = parent->depth_ + 1;
111 } else { 111 } else {
112 outer_loops_.push_back(child); 112 outer_loops_.push_back(child);
113 } 113 }
114 } 114 }
115 115
116 Zone* zone_; 116 Zone* zone_;
117 ZoneVector<Loop*> outer_loops_; 117 ZoneVector<Loop*> outer_loops_;
118 ZoneVector<Loop> all_loops_; 118 ZoneVector<Loop> all_loops_;
119 // TODO(titzer): lift loop count restriction. 119 ZoneVector<int> node_to_loop_num_;
120 ZoneVector<uint8_t> node_to_loop_num_;
121 ZoneVector<Node*> loop_nodes_; 120 ZoneVector<Node*> loop_nodes_;
122 }; 121 };
123 122
124 123
125 class LoopFinder { 124 class LoopFinder {
126 public: 125 public:
127 // Build a loop tree for the entire graph. 126 // Build a loop tree for the entire graph.
128 static LoopTree* BuildLoopTree(Graph* graph, Zone* temp_zone); 127 static LoopTree* BuildLoopTree(Graph* graph, Zone* temp_zone);
129 }; 128 };
130 129
131 } // namespace compiler 130 } // namespace compiler
132 } // namespace internal 131 } // namespace internal
133 } // namespace v8 132 } // namespace v8
134 133
135 #endif // V8_COMPILER_LOOP_ANALYSIS_H_ 134 #endif // V8_COMPILER_LOOP_ANALYSIS_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler/loop-analysis.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698