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

Side by Side Diff: src/compiler/scheduler.cc

Issue 865393004: [turbofan] Move GetCommonDominator to BasicBlock. (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 | « src/compiler/scheduler.h ('k') | test/unittests/compiler/schedule-unittest.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 #include <deque> 5 #include <deque>
6 #include <queue> 6 #include <queue>
7 7
8 #include "src/compiler/scheduler.h" 8 #include "src/compiler/scheduler.h"
9 9
10 #include "src/bit-vector.h" 10 #include "src/bit-vector.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 node->op()->mnemonic(), from->id(), from->op()->mnemonic(), 201 node->op()->mnemonic(), from->id(), from->op()->mnemonic(),
202 GetData(node)->unscheduled_count_); 202 GetData(node)->unscheduled_count_);
203 } 203 }
204 if (GetData(node)->unscheduled_count_ == 0) { 204 if (GetData(node)->unscheduled_count_ == 0) {
205 Trace(" newly eligible #%d:%s\n", node->id(), node->op()->mnemonic()); 205 Trace(" newly eligible #%d:%s\n", node->id(), node->op()->mnemonic());
206 schedule_queue_.push(node); 206 schedule_queue_.push(node);
207 } 207 }
208 } 208 }
209 209
210 210
211 BasicBlock* Scheduler::GetCommonDominator(BasicBlock* b1, BasicBlock* b2) {
212 while (b1 != b2) {
213 int32_t b1_depth = b1->dominator_depth();
214 int32_t b2_depth = b2->dominator_depth();
215 if (b1_depth < b2_depth) {
216 b2 = b2->dominator();
217 } else {
218 b1 = b1->dominator();
219 }
220 }
221 return b1;
222 }
223
224
225 // ----------------------------------------------------------------------------- 211 // -----------------------------------------------------------------------------
226 // Phase 1: Build control-flow graph. 212 // Phase 1: Build control-flow graph.
227 213
228 214
229 // Internal class to build a control flow graph (i.e the basic blocks and edges 215 // Internal class to build a control flow graph (i.e the basic blocks and edges
230 // between them within a Schedule) from the node graph. Visits control edges of 216 // between them within a Schedule) from the node graph. Visits control edges of
231 // the graph backwards from an end node in order to find the connected control 217 // the graph backwards from an end node in order to find the connected control
232 // subgraph, needed for scheduling. 218 // subgraph, needed for scheduling.
233 class CFGBuilder : public ZoneObject { 219 class CFGBuilder : public ZoneObject {
234 public: 220 public:
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 auto pred = block->predecessors().begin(); 1021 auto pred = block->predecessors().begin();
1036 auto end = block->predecessors().end(); 1022 auto end = block->predecessors().end();
1037 DCHECK(pred != end); // All blocks except start have predecessors. 1023 DCHECK(pred != end); // All blocks except start have predecessors.
1038 BasicBlock* dominator = *pred; 1024 BasicBlock* dominator = *pred;
1039 // For multiple predecessors, walk up the dominator tree until a common 1025 // For multiple predecessors, walk up the dominator tree until a common
1040 // dominator is found. Visitation order guarantees that all predecessors 1026 // dominator is found. Visitation order guarantees that all predecessors
1041 // except for backwards edges have been visited. 1027 // except for backwards edges have been visited.
1042 for (++pred; pred != end; ++pred) { 1028 for (++pred; pred != end; ++pred) {
1043 // Don't examine backwards edges. 1029 // Don't examine backwards edges.
1044 if ((*pred)->dominator_depth() < 0) continue; 1030 if ((*pred)->dominator_depth() < 0) continue;
1045 dominator = GetCommonDominator(dominator, *pred); 1031 dominator = BasicBlock::GetCommonDominator(dominator, *pred);
1046 } 1032 }
1047 block->set_dominator(dominator); 1033 block->set_dominator(dominator);
1048 block->set_dominator_depth(dominator->dominator_depth() + 1); 1034 block->set_dominator_depth(dominator->dominator_depth() + 1);
1049 // Propagate "deferredness" of the dominator. 1035 // Propagate "deferredness" of the dominator.
1050 if (dominator->deferred()) block->set_deferred(true); 1036 if (dominator->deferred()) block->set_deferred(true);
1051 Trace("Block B%d's idom is B%d, depth = %d\n", block->id().ToInt(), 1037 Trace("Block B%d's idom is B%d, depth = %d\n", block->id().ToInt(),
1052 dominator->id().ToInt(), block->dominator_depth()); 1038 dominator->id().ToInt(), block->dominator_depth());
1053 } 1039 }
1054 } 1040 }
1055 1041
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 queue_.push(node); 1174 queue_.push(node);
1189 Trace("Propagating #%d:%s minimum_block = B%d, dominator_depth = %d\n", 1175 Trace("Propagating #%d:%s minimum_block = B%d, dominator_depth = %d\n",
1190 node->id(), node->op()->mnemonic(), 1176 node->id(), node->op()->mnemonic(),
1191 data->minimum_block_->id().ToInt(), 1177 data->minimum_block_->id().ToInt(),
1192 data->minimum_block_->dominator_depth()); 1178 data->minimum_block_->dominator_depth());
1193 } 1179 }
1194 } 1180 }
1195 1181
1196 #if DEBUG 1182 #if DEBUG
1197 bool InsideSameDominatorChain(BasicBlock* b1, BasicBlock* b2) { 1183 bool InsideSameDominatorChain(BasicBlock* b1, BasicBlock* b2) {
1198 BasicBlock* dominator = scheduler_->GetCommonDominator(b1, b2); 1184 BasicBlock* dominator = BasicBlock::GetCommonDominator(b1, b2);
1199 return dominator == b1 || dominator == b2; 1185 return dominator == b1 || dominator == b2;
1200 } 1186 }
1201 #endif 1187 #endif
1202 1188
1203 Scheduler* scheduler_; 1189 Scheduler* scheduler_;
1204 Schedule* schedule_; 1190 Schedule* schedule_;
1205 ZoneQueue<Node*> queue_; 1191 ZoneQueue<Node*> queue_;
1206 }; 1192 };
1207 1193
1208 1194
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 DCHECK_EQ(Scheduler::kSchedulable, scheduler_->GetPlacement(node)); 1256 DCHECK_EQ(Scheduler::kSchedulable, scheduler_->GetPlacement(node));
1271 1257
1272 // Determine the dominating block for all of the uses of this node. It is 1258 // Determine the dominating block for all of the uses of this node. It is
1273 // the latest block that this node can be scheduled in. 1259 // the latest block that this node can be scheduled in.
1274 Trace("Scheduling #%d:%s\n", node->id(), node->op()->mnemonic()); 1260 Trace("Scheduling #%d:%s\n", node->id(), node->op()->mnemonic());
1275 BasicBlock* block = GetCommonDominatorOfUses(node); 1261 BasicBlock* block = GetCommonDominatorOfUses(node);
1276 DCHECK_NOT_NULL(block); 1262 DCHECK_NOT_NULL(block);
1277 1263
1278 // The schedule early block dominates the schedule late block. 1264 // The schedule early block dominates the schedule late block.
1279 BasicBlock* min_block = scheduler_->GetData(node)->minimum_block_; 1265 BasicBlock* min_block = scheduler_->GetData(node)->minimum_block_;
1280 DCHECK_EQ(min_block, scheduler_->GetCommonDominator(block, min_block)); 1266 DCHECK_EQ(min_block, BasicBlock::GetCommonDominator(block, min_block));
1281 Trace("Schedule late of #%d:%s is B%d at loop depth %d, minimum = B%d\n", 1267 Trace("Schedule late of #%d:%s is B%d at loop depth %d, minimum = B%d\n",
1282 node->id(), node->op()->mnemonic(), block->id().ToInt(), 1268 node->id(), node->op()->mnemonic(), block->id().ToInt(),
1283 block->loop_depth(), min_block->id().ToInt()); 1269 block->loop_depth(), min_block->id().ToInt());
1284 1270
1285 // Hoist nodes out of loops if possible. Nodes can be hoisted iteratively 1271 // Hoist nodes out of loops if possible. Nodes can be hoisted iteratively
1286 // into enclosing loop pre-headers until they would preceed their schedule 1272 // into enclosing loop pre-headers until they would preceed their schedule
1287 // early position. 1273 // early position.
1288 BasicBlock* hoist_block = GetPreHeader(block); 1274 BasicBlock* hoist_block = GetPreHeader(block);
1289 while (hoist_block != NULL && 1275 while (hoist_block != NULL &&
1290 hoist_block->dominator_depth() >= min_block->dominator_depth()) { 1276 hoist_block->dominator_depth() >= min_block->dominator_depth()) {
(...skipping 21 matching lines...) Expand all
1312 return NULL; 1298 return NULL;
1313 } 1299 }
1314 } 1300 }
1315 1301
1316 BasicBlock* GetCommonDominatorOfUses(Node* node) { 1302 BasicBlock* GetCommonDominatorOfUses(Node* node) {
1317 BasicBlock* block = NULL; 1303 BasicBlock* block = NULL;
1318 for (Edge edge : node->use_edges()) { 1304 for (Edge edge : node->use_edges()) {
1319 BasicBlock* use_block = GetBlockForUse(edge); 1305 BasicBlock* use_block = GetBlockForUse(edge);
1320 block = block == NULL ? use_block : use_block == NULL 1306 block = block == NULL ? use_block : use_block == NULL
1321 ? block 1307 ? block
1322 : scheduler_->GetCommonDominator( 1308 : BasicBlock::GetCommonDominator(
1323 block, use_block); 1309 block, use_block);
1324 } 1310 }
1325 return block; 1311 return block;
1326 } 1312 }
1327 1313
1328 BasicBlock* GetBlockForUse(Edge edge) { 1314 BasicBlock* GetBlockForUse(Edge edge) {
1329 Node* use = edge.from(); 1315 Node* use = edge.from();
1330 IrOpcode::Value opcode = use->opcode(); 1316 IrOpcode::Value opcode = use->opcode();
1331 if (IrOpcode::IsPhiOpcode(opcode)) { 1317 if (IrOpcode::IsPhiOpcode(opcode)) {
1332 // If the use is from a coupled (i.e. floating) phi, compute the common 1318 // If the use is from a coupled (i.e. floating) phi, compute the common
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 for (Node* const node : *nodes) { 1457 for (Node* const node : *nodes) {
1472 schedule_->SetBlockForNode(to, node); 1458 schedule_->SetBlockForNode(to, node);
1473 scheduled_nodes_[to->id().ToSize()].push_back(node); 1459 scheduled_nodes_[to->id().ToSize()].push_back(node);
1474 } 1460 }
1475 nodes->clear(); 1461 nodes->clear();
1476 } 1462 }
1477 1463
1478 } // namespace compiler 1464 } // namespace compiler
1479 } // namespace internal 1465 } // namespace internal
1480 } // namespace v8 1466 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/scheduler.h ('k') | test/unittests/compiler/schedule-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698