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

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

Issue 491303002: Add ScheduleVerifier. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/verifier.h ('k') | src/data-flow.h » ('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 #include "src/compiler/verifier.h" 5 #include "src/compiler/verifier.h"
6 6
7 #include <deque>
8 #include <queue>
9
7 #include "src/compiler/generic-algorithm.h" 10 #include "src/compiler/generic-algorithm.h"
8 #include "src/compiler/generic-node-inl.h" 11 #include "src/compiler/generic-node-inl.h"
9 #include "src/compiler/generic-node.h" 12 #include "src/compiler/generic-node.h"
10 #include "src/compiler/graph-inl.h" 13 #include "src/compiler/graph-inl.h"
11 #include "src/compiler/graph.h" 14 #include "src/compiler/graph.h"
12 #include "src/compiler/node.h" 15 #include "src/compiler/node.h"
13 #include "src/compiler/node-properties-inl.h" 16 #include "src/compiler/node-properties-inl.h"
14 #include "src/compiler/node-properties.h" 17 #include "src/compiler/node-properties.h"
15 #include "src/compiler/opcodes.h" 18 #include "src/compiler/opcodes.h"
16 #include "src/compiler/operator.h" 19 #include "src/compiler/operator.h"
20 #include "src/compiler/schedule.h"
21 #include "src/data-flow.h"
17 22
18 namespace v8 { 23 namespace v8 {
19 namespace internal { 24 namespace internal {
20 namespace compiler { 25 namespace compiler {
21 26
22 27
23 static bool IsDefUseChainLinkPresent(Node* def, Node* use) { 28 static bool IsDefUseChainLinkPresent(Node* def, Node* use) {
24 Node::Uses uses = def->uses(); 29 Node::Uses uses = def->uses();
25 for (Node::Uses::iterator it = uses.begin(); it != uses.end(); ++it) { 30 for (Node::Uses::iterator it = uses.begin(); it != uses.end(); ++it) {
26 if (*it == use) return true; 31 if (*it == use) return true;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 visitor.from_start = false; 238 visitor.from_start = false;
234 graph->VisitNodeInputsFromEnd(&visitor); 239 graph->VisitNodeInputsFromEnd(&visitor);
235 240
236 // All control nodes reachable from end are reachable from start. 241 // All control nodes reachable from end are reachable from start.
237 for (NodeSet::iterator it = visitor.reached_from_end.begin(); 242 for (NodeSet::iterator it = visitor.reached_from_end.begin();
238 it != visitor.reached_from_end.end(); ++it) { 243 it != visitor.reached_from_end.end(); ++it) {
239 CHECK(!NodeProperties::IsControl(*it) || 244 CHECK(!NodeProperties::IsControl(*it) ||
240 visitor.reached_from_start.count(*it)); 245 visitor.reached_from_start.count(*it));
241 } 246 }
242 } 247 }
248
249
250 static bool FindDominatingDef(Schedule* schedule, Node* node,
Jarin 2014/08/22 11:55:32 FindDominatingDef suggests that it returns the dom
titzer 2014/08/22 12:18:35 Done.
251 BasicBlock* container, BasicBlock* use_block,
252 int use_pos) {
253 BasicBlock* block = use_block;
254 while (true) {
255 while (use_pos >= 0) {
256 if (block->nodes_[use_pos] == node) return true;
Jarin 2014/08/22 11:55:32 It looks like the verifier would be happy if I con
Jarin 2014/08/22 12:05:20 Ah, as discussed offline, ignore this comment. I h
257 use_pos--;
258 }
259 block = schedule->dominator(block);
260 if (block == NULL) break;
261 use_pos = block->nodes_.size() - 1;
Jarin 2014/08/22 11:55:31 I guess this will not compile on Win64. Perhaps us
titzer 2014/08/22 12:18:35 Done.
262 if (node == block->control_input_) return true;
263 }
264 return false;
265 }
266
267
268 static void CheckInputsDominate(Schedule* schedule, BasicBlock* block,
269 Node* node, int use_pos) {
270 for (int j = OperatorProperties::GetValueInputCount(node->op()) - 1; j >= 0;
271 j--) {
272 BasicBlock* use_block = block;
273 if (node->opcode() == IrOpcode::kPhi) {
274 use_block = use_block->PredecessorAt(j);
275 use_pos = use_block->nodes_.size() - 1;
Jarin 2014/08/22 11:55:31 Again, this will not compile on Win64.
titzer 2014/08/22 12:18:35 Done.
276 }
277 Node* input = node->InputAt(j);
278 if (!FindDominatingDef(schedule, node->InputAt(j), block, use_block,
279 use_pos)) {
280 V8_Fatal(__FILE__, __LINE__,
281 "Node #%d:%s in B%d is not dominated by input@%d #%d:%s",
282 node->id(), node->op()->mnemonic(), block->id(), j, input->id(),
283 input->op()->mnemonic());
284 }
285 }
286 }
287
288
289 void ScheduleVerifier::Run(Schedule* schedule) {
290 const int count = schedule->BasicBlockCount();
291 Zone tmp_zone(schedule->zone()->isolate());
292 Zone* zone = &tmp_zone;
293 BasicBlock* start = schedule->start();
294 BasicBlockVector* rpo_order = schedule->rpo_order();
295
296 // Verify the RPO order contains only blocks from this schedule.
297 CHECK_GE(count, static_cast<int>(rpo_order->size()));
298 for (BasicBlockVector::iterator b = rpo_order->begin(); b != rpo_order->end();
299 ++b) {
300 CHECK_EQ((*b), schedule->GetBlockById((*b)->id()));
301 }
302
303 // Verify RPO numbers of blocks.
304 CHECK_EQ(start, rpo_order->at(0)); // Start should be first.
305 for (size_t b = 0; b < rpo_order->size(); b++) {
306 BasicBlock* block = rpo_order->at(b);
307 CHECK_EQ(b, block->rpo_number_);
308 BasicBlock* dom = schedule->dominator(block);
309 if (b == 0) {
310 // All blocks except start should have a dominator.
311 CHECK_EQ(NULL, dom);
312 } else {
313 // Check that the immediate dominator appears somewhere before the block.
314 CHECK_NE(NULL, dom);
315 CHECK_LT(dom->rpo_number_, block->rpo_number_);
316 }
317 }
318
319 // Verify that all blocks reachable from start are in the RPO.
320 BoolVector marked(count, false, BoolVector::allocator_type(zone));
321 {
322 std::queue<BasicBlock*> queue;
323 queue.push(start);
324 marked[start->id()] = true;
325 while (!queue.empty()) {
326 BasicBlock* block = queue.front();
327 queue.pop();
328 for (int s = 0; s < block->SuccessorCount(); s++) {
329 BasicBlock* succ = block->SuccessorAt(s);
330 if (!marked[succ->id()]) {
331 marked[succ->id()] = true;
332 queue.push(succ);
333 }
334 }
335 }
336 }
337 // Verify marked blocks are in the RPO.
338 for (int i = 0; i < count; i++) {
339 BasicBlock* block = schedule->GetBlockById(i);
340 if (marked[i]) {
341 CHECK_GE(block->rpo_number_, 0);
342 CHECK_EQ(block, rpo_order->at(block->rpo_number_));
343 }
344 }
345 // Verify RPO blocks are marked.
346 for (size_t b = 0; b < rpo_order->size(); b++) {
347 CHECK(marked[rpo_order->at(b)->id()]);
348 }
349
350 {
351 // Verify the dominance relation.
352 ZoneList<BitVector*> dominators(count, zone);
353 dominators.Initialize(count, zone);
354 dominators.AddBlock(NULL, count, zone);
355
356 // Compute a set of all the nodes that dominate a given node by using
357 // a forward fixpoint. O(n^2).
358 std::queue<BasicBlock*> queue;
359 queue.push(start);
360 dominators[start->id()] = new (zone) BitVector(count, zone);
361 while (!queue.empty()) {
362 BasicBlock* block = queue.front();
363 queue.pop();
364 BitVector* block_doms = dominators[block->id()];
365 BasicBlock* idom = schedule->dominator(block);
366 if (idom != NULL && !block_doms->Contains(idom->id())) {
367 V8_Fatal(__FILE__, __LINE__, "Block B%d is not dominated by B%d",
368 block->id(), idom->id());
369 }
370 for (int s = 0; s < block->SuccessorCount(); s++) {
371 BasicBlock* succ = block->SuccessorAt(s);
372 BitVector* succ_doms = dominators[succ->id()];
373
374 if (succ_doms == NULL) {
375 // First time visiting the node. S.vec = B U B.vec
376 succ_doms = new (zone) BitVector(count, zone);
377 succ_doms->CopyFrom(*block_doms);
378 succ_doms->Add(block->id());
379 dominators[succ->id()] = succ_doms;
380 queue.push(succ);
381 } else {
382 // Nth time visiting the successor. S.vec = S.vec ^ (B U B.vec)
383 bool had = succ_doms->Contains(block->id());
384 if (had) succ_doms->Remove(block->id());
385 if (succ_doms->IntersectIsChanged(*block_doms)) queue.push(succ);
386 if (had) succ_doms->Add(block->id());
387 }
388 }
389 }
390
391 // Verify the immediateness of dominators.
392 for (BasicBlockVector::iterator b = rpo_order->begin();
393 b != rpo_order->end(); ++b) {
394 BasicBlock* block = *b;
395 BasicBlock* idom = schedule->dominator(block);
396 if (idom == NULL) continue;
397 BitVector* block_doms = dominators[block->id()];
398
399 for (BitVector::Iterator it(block_doms); !it.Done(); it.Advance()) {
400 BasicBlock* dom = schedule->GetBlockById(it.Current());
401 if (dom != idom && !dominators[idom->id()]->Contains(dom->id())) {
402 V8_Fatal(__FILE__, __LINE__,
403 "Block B%d is not immediately dominated by B%d", block->id(),
404 idom->id());
405 }
406 }
407 }
408 }
409
410 // Verify phis are placed in the block of their control input.
411 for (BasicBlockVector::iterator b = rpo_order->begin(); b != rpo_order->end();
412 ++b) {
413 for (BasicBlock::const_iterator i = (*b)->begin(); i != (*b)->end(); ++i) {
414 Node* phi = *i;
415 if (phi->opcode() != IrOpcode::kPhi) continue;
416 // TODO(titzer): Nasty special case. Phis from RawMachineAssembler
417 // schedules don't have control inputs.
Jarin 2014/08/22 11:55:31 Note: At some point we will have to fix RawMachine
titzer 2014/08/22 12:18:35 Yeah, I know.
418 if (phi->InputCount() >
419 OperatorProperties::GetValueInputCount(phi->op())) {
420 Node* control = NodeProperties::GetControlInput(phi);
421 CHECK(control->opcode() == IrOpcode::kMerge ||
422 control->opcode() == IrOpcode::kLoop);
423 CHECK_EQ((*b), schedule->block(control));
424 }
425 }
426 }
427
428 // Verify that all uses are dominated by their definitions.
429 for (BasicBlockVector::iterator b = rpo_order->begin(); b != rpo_order->end();
430 ++b) {
431 BasicBlock* block = *b;
432
433 // Check inputs to control for this block.
434 Node* control = block->control_input_;
435 if (control != NULL) {
436 CHECK_EQ(block, schedule->block(control));
437 CheckInputsDominate(schedule, block, control,
438 static_cast<int>(block->nodes_.size() - 1));
439 }
440 // Check inputs for all nodes in the block.
441 for (size_t i = 0; i < block->nodes_.size(); i++) {
442 Node* node = block->nodes_[i];
443 CheckInputsDominate(schedule, block, node, static_cast<int>(i - 1));
444 }
445 }
446 }
243 } 447 }
244 } 448 }
245 } // namespace v8::internal::compiler 449 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/verifier.h ('k') | src/data-flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698