Chromium Code Reviews| 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_CONTROL_EQUIVALENCE_H_ | 5 #ifndef V8_COMPILER_CONTROL_EQUIVALENCE_H_ |
| 6 #define V8_COMPILER_CONTROL_EQUIVALENCE_H_ | 6 #define V8_COMPILER_CONTROL_EQUIVALENCE_H_ |
| 7 | 7 |
| 8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
| 9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| 11 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
| 12 | 12 |
| 13 #define TRACE(...) \ | |
|
Michael Starzinger
2015/03/17 17:08:07
nit: Can we move it into the namespaces for consis
titzer
2015/03/17 17:32:42
Done.
| |
| 14 do { \ | |
| 15 if (FLAG_trace_turbo_scheduler) PrintF(__VA_ARGS__); \ | |
| 16 } while (false) | |
| 17 | |
| 13 namespace v8 { | 18 namespace v8 { |
| 14 namespace internal { | 19 namespace internal { |
| 15 namespace compiler { | 20 namespace compiler { |
| 16 | 21 |
| 17 // Determines control dependence equivalence classes for control nodes. Any two | 22 // Determines control dependence equivalence classes for control nodes. Any two |
| 18 // nodes having the same set of control dependences land in one class. These | 23 // nodes having the same set of control dependences land in one class. These |
| 19 // classes can in turn be used to: | 24 // classes can in turn be used to: |
| 20 // - Build a program structure tree (PST) for controls in the graph. | 25 // - Build a program structure tree (PST) for controls in the graph. |
| 21 // - Determine single-entry single-exit (SESE) regions within the graph. | 26 // - Determine single-entry single-exit (SESE) regions within the graph. |
| 22 // | 27 // |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 bool on_stack; // Indicates node is on DFS stack during walk. | 94 bool on_stack; // Indicates node is on DFS stack during walk. |
| 90 bool participates; // Indicates node participates in DFS walk. | 95 bool participates; // Indicates node participates in DFS walk. |
| 91 BracketList blist; // List of brackets per node. | 96 BracketList blist; // List of brackets per node. |
| 92 }; | 97 }; |
| 93 | 98 |
| 94 // The per-node data computed during the DFS walk. | 99 // The per-node data computed during the DFS walk. |
| 95 typedef ZoneVector<NodeData> Data; | 100 typedef ZoneVector<NodeData> Data; |
| 96 | 101 |
| 97 // Called at pre-visit during DFS walk. | 102 // Called at pre-visit during DFS walk. |
| 98 void VisitPre(Node* node) { | 103 void VisitPre(Node* node) { |
| 99 Trace("CEQ: Pre-visit of #%d:%s\n", node->id(), node->op()->mnemonic()); | 104 TRACE("CEQ: Pre-visit of #%d:%s\n", node->id(), node->op()->mnemonic()); |
| 100 | 105 |
| 101 // Dispense a new pre-order number. | 106 // Dispense a new pre-order number. |
| 102 SetNumber(node, NewDFSNumber()); | 107 SetNumber(node, NewDFSNumber()); |
| 103 Trace(" Assigned DFS number is %d\n", GetNumber(node)); | 108 TRACE(" Assigned DFS number is %d\n", GetNumber(node)); |
| 104 } | 109 } |
| 105 | 110 |
| 106 // Called at mid-visit during DFS walk. | 111 // Called at mid-visit during DFS walk. |
| 107 void VisitMid(Node* node, DFSDirection direction) { | 112 void VisitMid(Node* node, DFSDirection direction) { |
| 108 Trace("CEQ: Mid-visit of #%d:%s\n", node->id(), node->op()->mnemonic()); | 113 TRACE("CEQ: Mid-visit of #%d:%s\n", node->id(), node->op()->mnemonic()); |
| 109 BracketList& blist = GetBracketList(node); | 114 BracketList& blist = GetBracketList(node); |
| 110 | 115 |
| 111 // Remove brackets pointing to this node [line:19]. | 116 // Remove brackets pointing to this node [line:19]. |
| 112 BracketListDelete(blist, node, direction); | 117 BracketListDelete(blist, node, direction); |
| 113 | 118 |
| 114 // Potentially introduce artificial dependency from start to end. | 119 // Potentially introduce artificial dependency from start to end. |
| 115 if (blist.empty()) { | 120 if (blist.empty()) { |
| 116 DCHECK_EQ(kInputDirection, direction); | 121 DCHECK_EQ(kInputDirection, direction); |
| 117 VisitBackedge(node, graph_->end(), kInputDirection); | 122 VisitBackedge(node, graph_->end(), kInputDirection); |
| 118 } | 123 } |
| 119 | 124 |
| 120 // Potentially start a new equivalence class [line:37]. | 125 // Potentially start a new equivalence class [line:37]. |
| 121 BracketListTrace(blist); | 126 BracketListTRACE(blist); |
| 122 Bracket* recent = &blist.back(); | 127 Bracket* recent = &blist.back(); |
| 123 if (recent->recent_size != blist.size()) { | 128 if (recent->recent_size != blist.size()) { |
| 124 recent->recent_size = blist.size(); | 129 recent->recent_size = blist.size(); |
| 125 recent->recent_class = NewClassNumber(); | 130 recent->recent_class = NewClassNumber(); |
| 126 } | 131 } |
| 127 | 132 |
| 128 // Assign equivalence class to node. | 133 // Assign equivalence class to node. |
| 129 SetClass(node, recent->recent_class); | 134 SetClass(node, recent->recent_class); |
| 130 Trace(" Assigned class number is %d\n", GetClass(node)); | 135 TRACE(" Assigned class number is %d\n", GetClass(node)); |
| 131 } | 136 } |
| 132 | 137 |
| 133 // Called at post-visit during DFS walk. | 138 // Called at post-visit during DFS walk. |
| 134 void VisitPost(Node* node, Node* parent_node, DFSDirection direction) { | 139 void VisitPost(Node* node, Node* parent_node, DFSDirection direction) { |
| 135 Trace("CEQ: Post-visit of #%d:%s\n", node->id(), node->op()->mnemonic()); | 140 TRACE("CEQ: Post-visit of #%d:%s\n", node->id(), node->op()->mnemonic()); |
| 136 BracketList& blist = GetBracketList(node); | 141 BracketList& blist = GetBracketList(node); |
| 137 | 142 |
| 138 // Remove brackets pointing to this node [line:19]. | 143 // Remove brackets pointing to this node [line:19]. |
| 139 BracketListDelete(blist, node, direction); | 144 BracketListDelete(blist, node, direction); |
| 140 | 145 |
| 141 // Propagate bracket list up the DFS tree [line:13]. | 146 // Propagate bracket list up the DFS tree [line:13]. |
| 142 if (parent_node != NULL) { | 147 if (parent_node != NULL) { |
| 143 BracketList& parent_blist = GetBracketList(parent_node); | 148 BracketList& parent_blist = GetBracketList(parent_node); |
| 144 parent_blist.splice(parent_blist.end(), blist); | 149 parent_blist.splice(parent_blist.end(), blist); |
| 145 } | 150 } |
| 146 } | 151 } |
| 147 | 152 |
| 148 // Called when hitting a back edge in the DFS walk. | 153 // Called when hitting a back edge in the DFS walk. |
| 149 void VisitBackedge(Node* from, Node* to, DFSDirection direction) { | 154 void VisitBackedge(Node* from, Node* to, DFSDirection direction) { |
| 150 Trace("CEQ: Backedge from #%d:%s to #%d:%s\n", from->id(), | 155 TRACE("CEQ: Backedge from #%d:%s to #%d:%s\n", from->id(), |
| 151 from->op()->mnemonic(), to->id(), to->op()->mnemonic()); | 156 from->op()->mnemonic(), to->id(), to->op()->mnemonic()); |
| 152 | 157 |
| 153 // Push backedge onto the bracket list [line:25]. | 158 // Push backedge onto the bracket list [line:25]. |
| 154 Bracket bracket = {direction, kInvalidClass, 0, from, to}; | 159 Bracket bracket = {direction, kInvalidClass, 0, from, to}; |
| 155 GetBracketList(from).push_back(bracket); | 160 GetBracketList(from).push_back(bracket); |
| 156 } | 161 } |
| 157 | 162 |
| 158 // Performs and undirected DFS walk of the graph. Conceptually all nodes are | 163 // Performs and undirected DFS walk of the graph. Conceptually all nodes are |
| 159 // expanded, splitting "input" and "use" out into separate nodes. During the | 164 // expanded, splitting "input" and "use" out into separate nodes. During the |
| 160 // traversal, edges towards the representative nodes are preferred. | 165 // traversal, edges towards the representative nodes are preferred. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 DCHECK_EQ(stack.top().node, node); | 314 DCHECK_EQ(stack.top().node, node); |
| 310 GetData(node)->on_stack = false; | 315 GetData(node)->on_stack = false; |
| 311 GetData(node)->visited = true; | 316 GetData(node)->visited = true; |
| 312 stack.pop(); | 317 stack.pop(); |
| 313 } | 318 } |
| 314 | 319 |
| 315 // TODO(mstarzinger): Optimize this to avoid linear search. | 320 // TODO(mstarzinger): Optimize this to avoid linear search. |
| 316 void BracketListDelete(BracketList& blist, Node* to, DFSDirection direction) { | 321 void BracketListDelete(BracketList& blist, Node* to, DFSDirection direction) { |
| 317 for (BracketList::iterator i = blist.begin(); i != blist.end(); /*nop*/) { | 322 for (BracketList::iterator i = blist.begin(); i != blist.end(); /*nop*/) { |
| 318 if (i->to == to && i->direction != direction) { | 323 if (i->to == to && i->direction != direction) { |
| 319 Trace(" BList erased: {%d->%d}\n", i->from->id(), i->to->id()); | 324 TRACE(" BList erased: {%d->%d}\n", i->from->id(), i->to->id()); |
| 320 i = blist.erase(i); | 325 i = blist.erase(i); |
| 321 } else { | 326 } else { |
| 322 ++i; | 327 ++i; |
| 323 } | 328 } |
| 324 } | 329 } |
| 325 } | 330 } |
| 326 | 331 |
| 327 void BracketListTrace(BracketList& blist) { | 332 void BracketListTRACE(BracketList& blist) { |
| 328 if (FLAG_trace_turbo_scheduler) { | 333 if (FLAG_trace_turbo_scheduler) { |
| 329 Trace(" BList: "); | 334 TRACE(" BList: "); |
| 330 for (Bracket bracket : blist) { | 335 for (Bracket bracket : blist) { |
| 331 Trace("{%d->%d} ", bracket.from->id(), bracket.to->id()); | 336 TRACE("{%d->%d} ", bracket.from->id(), bracket.to->id()); |
| 332 } | 337 } |
| 333 Trace("\n"); | 338 TRACE("\n"); |
| 334 } | 339 } |
| 335 } | 340 } |
| 336 | 341 |
| 337 void Trace(const char* msg, ...) { | |
| 338 if (FLAG_trace_turbo_scheduler) { | |
| 339 va_list arguments; | |
| 340 va_start(arguments, msg); | |
| 341 base::OS::VPrint(msg, arguments); | |
| 342 va_end(arguments); | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 Zone* zone_; | 342 Zone* zone_; |
| 347 Graph* graph_; | 343 Graph* graph_; |
| 348 int dfs_number_; // Generates new DFS pre-order numbers on demand. | 344 int dfs_number_; // Generates new DFS pre-order numbers on demand. |
| 349 int class_number_; // Generates new equivalence class numbers on demand. | 345 int class_number_; // Generates new equivalence class numbers on demand. |
| 350 Data node_data_; // Per-node data stored as a side-table. | 346 Data node_data_; // Per-node data stored as a side-table. |
| 351 }; | 347 }; |
| 352 | 348 |
| 349 #undef TRACE | |
| 350 | |
| 353 } // namespace compiler | 351 } // namespace compiler |
| 354 } // namespace internal | 352 } // namespace internal |
| 355 } // namespace v8 | 353 } // namespace v8 |
| 356 | 354 |
| 357 #endif // V8_COMPILER_CONTROL_EQUIVALENCE_H_ | 355 #endif // V8_COMPILER_CONTROL_EQUIVALENCE_H_ |
| OLD | NEW |