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

Side by Side Diff: src/compiler/machine-graph-verifier.cc

Issue 2401553002: [turbofan] Renames variables in machine-graph-verifier.cc to make them consistent. (Closed)
Patch Set: Created 4 years, 2 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/machine-graph-verifier.h" 5 #include "src/compiler/machine-graph-verifier.h"
6 6
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/graph.h" 8 #include "src/compiler/graph.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/node-properties.h" 11 #include "src/compiler/node-properties.h"
12 #include "src/compiler/node.h" 12 #include "src/compiler/node.h"
13 #include "src/compiler/schedule.h" 13 #include "src/compiler/schedule.h"
14 #include "src/zone/zone.h" 14 #include "src/zone/zone.h"
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 namespace compiler { 18 namespace compiler {
19 19
20 namespace { 20 namespace {
21 21
22 class MachineRepresentationInferrer { 22 class MachineRepresentationInferrer {
23 public: 23 public:
24 MachineRepresentationInferrer(Schedule const* schedule, Graph const* graph, 24 MachineRepresentationInferrer(Schedule const* schedule, Graph const* graph,
25 Linkage* linkage, Zone* zone) 25 Linkage* linkage, Zone* zone)
26 : schedule_(schedule), 26 : schedule_(schedule),
27 linkage_(linkage), 27 linkage_(linkage),
28 representation_vector_(graph->NodeCount(), zone) { 28 representation_vector_(graph->NodeCount(), MachineRepresentation::kNone,
29 zone) {
29 Run(); 30 Run();
30 } 31 }
31 32
32 MachineRepresentation GetRepresentation(Node const* node) const { 33 MachineRepresentation GetRepresentation(Node const* node) const {
33 return representation_vector_.at(node->id()); 34 return representation_vector_.at(node->id());
34 } 35 }
35 36
36 private: 37 private:
37 MachineRepresentation GetProjectionType(Node const* projection) { 38 MachineRepresentation GetProjectionType(Node const* projection) {
38 size_t index = ProjectionIndexOf(projection->op()); 39 size_t index = ProjectionIndexOf(projection->op());
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 228 }
228 } 229 }
229 230
230 Schedule const* const schedule_; 231 Schedule const* const schedule_;
231 Linkage const* const linkage_; 232 Linkage const* const linkage_;
232 ZoneVector<MachineRepresentation> representation_vector_; 233 ZoneVector<MachineRepresentation> representation_vector_;
233 }; 234 };
234 235
235 class MachineRepresentationChecker { 236 class MachineRepresentationChecker {
236 public: 237 public:
237 MachineRepresentationChecker(Schedule const* const schedule, 238 MachineRepresentationChecker(
238 MachineRepresentationInferrer const* const typer) 239 Schedule const* const schedule,
239 : schedule_(schedule), typer_(typer) {} 240 MachineRepresentationInferrer const* const inferrer)
241 : schedule_(schedule), inferrer_(inferrer) {}
240 242
241 void Run() { 243 void Run() {
242 BasicBlockVector const* blocks = schedule_->all_blocks(); 244 BasicBlockVector const* blocks = schedule_->all_blocks();
243 for (BasicBlock* block : *blocks) { 245 for (BasicBlock* block : *blocks) {
244 for (size_t i = 0; i <= block->NodeCount(); ++i) { 246 for (size_t i = 0; i <= block->NodeCount(); ++i) {
245 Node const* node = 247 Node const* node =
246 i < block->NodeCount() ? block->NodeAt(i) : block->control_input(); 248 i < block->NodeCount() ? block->NodeAt(i) : block->control_input();
247 if (node == nullptr) { 249 if (node == nullptr) {
248 DCHECK_EQ(block->NodeCount(), i); 250 DCHECK_EQ(block->NodeCount(), i);
249 break; 251 break;
250 } 252 }
251 switch (node->opcode()) { 253 switch (node->opcode()) {
252 case IrOpcode::kCall: 254 case IrOpcode::kCall:
253 case IrOpcode::kTailCall: 255 case IrOpcode::kTailCall:
254 CheckCallInputs(node); 256 CheckCallInputs(node);
255 break; 257 break;
256 case IrOpcode::kChangeBitToTagged: 258 case IrOpcode::kChangeBitToTagged:
257 CHECK_EQ(MachineRepresentation::kBit, 259 CHECK_EQ(MachineRepresentation::kBit,
258 typer_->GetRepresentation(node->InputAt(0))); 260 inferrer_->GetRepresentation(node->InputAt(0)));
259 break; 261 break;
260 case IrOpcode::kChangeTaggedToBit: 262 case IrOpcode::kChangeTaggedToBit:
261 CHECK_EQ(MachineRepresentation::kTagged, 263 CHECK_EQ(MachineRepresentation::kTagged,
262 typer_->GetRepresentation(node->InputAt(0))); 264 inferrer_->GetRepresentation(node->InputAt(0)));
263 break; 265 break;
264 case IrOpcode::kRoundInt64ToFloat64: 266 case IrOpcode::kRoundInt64ToFloat64:
265 case IrOpcode::kRoundUint64ToFloat64: 267 case IrOpcode::kRoundUint64ToFloat64:
266 case IrOpcode::kRoundInt64ToFloat32: 268 case IrOpcode::kRoundInt64ToFloat32:
267 case IrOpcode::kRoundUint64ToFloat32: 269 case IrOpcode::kRoundUint64ToFloat32:
268 case IrOpcode::kTruncateInt64ToInt32: 270 case IrOpcode::kTruncateInt64ToInt32:
269 CheckValueInputForInt64Op(node, 0); 271 CheckValueInputForInt64Op(node, 0);
270 break; 272 break;
271 case IrOpcode::kBitcastWordToTagged: 273 case IrOpcode::kBitcastWordToTagged:
272 case IrOpcode::kBitcastWordToTaggedSigned: 274 case IrOpcode::kBitcastWordToTaggedSigned:
(...skipping 10 matching lines...) Expand all
283 case IrOpcode::kChangeFloat64ToUint32: 285 case IrOpcode::kChangeFloat64ToUint32:
284 case IrOpcode::kRoundFloat64ToInt32: 286 case IrOpcode::kRoundFloat64ToInt32:
285 case IrOpcode::kFloat64ExtractLowWord32: 287 case IrOpcode::kFloat64ExtractLowWord32:
286 case IrOpcode::kFloat64ExtractHighWord32: 288 case IrOpcode::kFloat64ExtractHighWord32:
287 case IrOpcode::kBitcastFloat64ToInt64: 289 case IrOpcode::kBitcastFloat64ToInt64:
288 CheckValueInputForFloat64Op(node, 0); 290 CheckValueInputForFloat64Op(node, 0);
289 break; 291 break;
290 case IrOpcode::kWord64Equal: 292 case IrOpcode::kWord64Equal:
291 CheckValueInputIsTaggedOrPointer(node, 0); 293 CheckValueInputIsTaggedOrPointer(node, 0);
292 CheckValueInputRepresentationIs( 294 CheckValueInputRepresentationIs(
293 node, 1, typer_->GetRepresentation(node->InputAt(0))); 295 node, 1, inferrer_->GetRepresentation(node->InputAt(0)));
294 break; 296 break;
295 case IrOpcode::kInt64LessThan: 297 case IrOpcode::kInt64LessThan:
296 case IrOpcode::kInt64LessThanOrEqual: 298 case IrOpcode::kInt64LessThanOrEqual:
297 case IrOpcode::kUint64LessThan: 299 case IrOpcode::kUint64LessThan:
298 case IrOpcode::kUint64LessThanOrEqual: 300 case IrOpcode::kUint64LessThanOrEqual:
299 CheckValueInputForInt64Op(node, 0); 301 CheckValueInputForInt64Op(node, 0);
300 CheckValueInputForInt64Op(node, 1); 302 CheckValueInputForInt64Op(node, 1);
301 break; 303 break;
302 case IrOpcode::kInt32x4ExtractLane: 304 case IrOpcode::kInt32x4ExtractLane:
303 CheckValueInputRepresentationIs(node, 0, 305 CheckValueInputRepresentationIs(node, 0,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 case MachineRepresentation::kTaggedPointer: 395 case MachineRepresentation::kTaggedPointer:
394 case MachineRepresentation::kTaggedSigned: 396 case MachineRepresentation::kTaggedSigned:
395 CheckValueInputIsTagged(node, 2); 397 CheckValueInputIsTagged(node, 2);
396 break; 398 break;
397 default: 399 default:
398 CheckValueInputRepresentationIs( 400 CheckValueInputRepresentationIs(
399 node, 2, AtomicStoreRepresentationOf(node->op())); 401 node, 2, AtomicStoreRepresentationOf(node->op()));
400 } 402 }
401 break; 403 break;
402 case IrOpcode::kPhi: 404 case IrOpcode::kPhi:
403 switch (typer_->GetRepresentation(node)) { 405 switch (inferrer_->GetRepresentation(node)) {
404 case MachineRepresentation::kTagged: 406 case MachineRepresentation::kTagged:
405 case MachineRepresentation::kTaggedPointer: 407 case MachineRepresentation::kTaggedPointer:
406 case MachineRepresentation::kTaggedSigned: 408 case MachineRepresentation::kTaggedSigned:
407 for (int i = 0; i < node->op()->ValueInputCount(); ++i) { 409 for (int i = 0; i < node->op()->ValueInputCount(); ++i) {
408 CheckValueInputIsTagged(node, i); 410 CheckValueInputIsTagged(node, i);
409 } 411 }
410 break; 412 break;
411 default: 413 default:
412 for (int i = 0; i < node->op()->ValueInputCount(); ++i) { 414 for (int i = 0; i < node->op()->ValueInputCount(); ++i) {
413 CheckValueInputRepresentationIs( 415 CheckValueInputRepresentationIs(
414 node, i, typer_->GetRepresentation(node)); 416 node, i, inferrer_->GetRepresentation(node));
415 } 417 }
416 break; 418 break;
417 } 419 }
418 break; 420 break;
419 case IrOpcode::kBranch: 421 case IrOpcode::kBranch:
420 case IrOpcode::kSwitch: 422 case IrOpcode::kSwitch:
421 CheckValueInputForInt32Op(node, 0); 423 CheckValueInputForInt32Op(node, 0);
422 break; 424 break;
423 case IrOpcode::kReturn: 425 case IrOpcode::kReturn:
424 // TODO(epertoso): use the linkage to determine which tipe we 426 // TODO(epertoso): use the linkage to determine which tipe we
(...skipping 12 matching lines...) Expand all
437 break; 439 break;
438 } 440 }
439 } 441 }
440 } 442 }
441 } 443 }
442 444
443 private: 445 private:
444 void CheckValueInputRepresentationIs(Node const* node, int index, 446 void CheckValueInputRepresentationIs(Node const* node, int index,
445 MachineRepresentation representation) { 447 MachineRepresentation representation) {
446 Node const* input = node->InputAt(index); 448 Node const* input = node->InputAt(index);
447 if (typer_->GetRepresentation(input) != representation) { 449 if (inferrer_->GetRepresentation(input) != representation) {
448 std::stringstream str; 450 std::stringstream str;
449 str << "TypeError: node #" << node->id() << ":" << *node->op() 451 str << "TypeError: node #" << node->id() << ":" << *node->op()
450 << " uses node #" << input->id() << ":" << *input->op() 452 << " uses node #" << input->id() << ":" << *input->op()
451 << " which doesn't have a " << MachineReprToString(representation) 453 << " which doesn't have a " << MachineReprToString(representation)
452 << " representation."; 454 << " representation.";
453 FATAL(str.str().c_str()); 455 FATAL(str.str().c_str());
454 } 456 }
455 } 457 }
456 458
457 void CheckValueInputIsTagged(Node const* node, int index) { 459 void CheckValueInputIsTagged(Node const* node, int index) {
458 Node const* input = node->InputAt(index); 460 Node const* input = node->InputAt(index);
459 switch (typer_->GetRepresentation(input)) { 461 switch (inferrer_->GetRepresentation(input)) {
460 case MachineRepresentation::kTagged: 462 case MachineRepresentation::kTagged:
461 case MachineRepresentation::kTaggedPointer: 463 case MachineRepresentation::kTaggedPointer:
462 case MachineRepresentation::kTaggedSigned: 464 case MachineRepresentation::kTaggedSigned:
463 return; 465 return;
464 default: 466 default:
465 break; 467 break;
466 } 468 }
467 std::ostringstream str; 469 std::ostringstream str;
468 str << "TypeError: node #" << node->id() << ":" << *node->op() 470 str << "TypeError: node #" << node->id() << ":" << *node->op()
469 << " uses node #" << input->id() << ":" << *input->op() 471 << " uses node #" << input->id() << ":" << *input->op()
470 << " which doesn't have a tagged representation."; 472 << " which doesn't have a tagged representation.";
471 FATAL(str.str().c_str()); 473 FATAL(str.str().c_str());
472 } 474 }
473 475
474 void CheckValueInputIsTaggedOrPointer(Node const* node, int index) { 476 void CheckValueInputIsTaggedOrPointer(Node const* node, int index) {
475 Node const* input = node->InputAt(index); 477 Node const* input = node->InputAt(index);
476 switch (typer_->GetRepresentation(input)) { 478 switch (inferrer_->GetRepresentation(input)) {
477 case MachineRepresentation::kTagged: 479 case MachineRepresentation::kTagged:
478 case MachineRepresentation::kTaggedPointer: 480 case MachineRepresentation::kTaggedPointer:
479 case MachineRepresentation::kTaggedSigned: 481 case MachineRepresentation::kTaggedSigned:
480 return; 482 return;
481 default: 483 default:
482 break; 484 break;
483 } 485 }
484 if (typer_->GetRepresentation(input) != 486 if (inferrer_->GetRepresentation(input) !=
485 MachineType::PointerRepresentation()) { 487 MachineType::PointerRepresentation()) {
486 std::ostringstream str; 488 std::ostringstream str;
487 str << "TypeError: node #" << node->id() << ":" << *node->op() 489 str << "TypeError: node #" << node->id() << ":" << *node->op()
488 << " uses node #" << input->id() << ":" << *input->op() 490 << " uses node #" << input->id() << ":" << *input->op()
489 << " which doesn't have a tagged or pointer representation."; 491 << " which doesn't have a tagged or pointer representation.";
490 FATAL(str.str().c_str()); 492 FATAL(str.str().c_str());
491 } 493 }
492 } 494 }
493 495
494 void CheckValueInputForInt32Op(Node const* node, int index) { 496 void CheckValueInputForInt32Op(Node const* node, int index) {
495 Node const* input = node->InputAt(index); 497 Node const* input = node->InputAt(index);
496 switch (typer_->GetRepresentation(input)) { 498 switch (inferrer_->GetRepresentation(input)) {
497 case MachineRepresentation::kBit: 499 case MachineRepresentation::kBit:
498 case MachineRepresentation::kWord8: 500 case MachineRepresentation::kWord8:
499 case MachineRepresentation::kWord16: 501 case MachineRepresentation::kWord16:
500 case MachineRepresentation::kWord32: 502 case MachineRepresentation::kWord32:
501 return; 503 return;
502 case MachineRepresentation::kNone: { 504 case MachineRepresentation::kNone: {
503 std::ostringstream str; 505 std::ostringstream str;
504 str << "TypeError: node #" << input->id() << ":" << *input->op() 506 str << "TypeError: node #" << input->id() << ":" << *input->op()
505 << " is untyped."; 507 << " is untyped.";
506 FATAL(str.str().c_str()); 508 FATAL(str.str().c_str());
507 break; 509 break;
508 } 510 }
509 default: 511 default:
510 break; 512 break;
511 } 513 }
512 std::ostringstream str; 514 std::ostringstream str;
513 str << "TypeError: node #" << node->id() << ":" << *node->op() 515 str << "TypeError: node #" << node->id() << ":" << *node->op()
514 << " uses node #" << input->id() << ":" << *input->op() 516 << " uses node #" << input->id() << ":" << *input->op()
515 << " which doesn't have an int32-compatible representation."; 517 << " which doesn't have an int32-compatible representation.";
516 FATAL(str.str().c_str()); 518 FATAL(str.str().c_str());
517 } 519 }
518 520
519 void CheckValueInputForInt64Op(Node const* node, int index) { 521 void CheckValueInputForInt64Op(Node const* node, int index) {
520 Node const* input = node->InputAt(index); 522 Node const* input = node->InputAt(index);
521 switch (typer_->GetRepresentation(input)) { 523 switch (inferrer_->GetRepresentation(input)) {
522 case MachineRepresentation::kWord64: 524 case MachineRepresentation::kWord64:
523 return; 525 return;
524 case MachineRepresentation::kNone: { 526 case MachineRepresentation::kNone: {
525 std::ostringstream str; 527 std::ostringstream str;
526 str << "TypeError: node #" << input->id() << ":" << *input->op() 528 str << "TypeError: node #" << input->id() << ":" << *input->op()
527 << " is untyped."; 529 << " is untyped.";
528 FATAL(str.str().c_str()); 530 FATAL(str.str().c_str());
529 break; 531 break;
530 } 532 }
531 533
532 default: 534 default:
533 break; 535 break;
534 } 536 }
535 std::ostringstream str; 537 std::ostringstream str;
536 str << "TypeError: node #" << node->id() << ":" << *node->op() 538 str << "TypeError: node #" << node->id() << ":" << *node->op()
537 << " uses node #" << input->id() << ":" << *input->op() 539 << " uses node #" << input->id() << ":" << *input->op()
538 << " which doesn't have a kWord64 representation."; 540 << " which doesn't have a kWord64 representation.";
539 FATAL(str.str().c_str()); 541 FATAL(str.str().c_str());
540 } 542 }
541 543
542 void CheckValueInputForFloat32Op(Node const* node, int index) { 544 void CheckValueInputForFloat32Op(Node const* node, int index) {
543 Node const* input = node->InputAt(index); 545 Node const* input = node->InputAt(index);
544 if (MachineRepresentation::kFloat32 == typer_->GetRepresentation(input)) { 546 if (MachineRepresentation::kFloat32 ==
547 inferrer_->GetRepresentation(input)) {
545 return; 548 return;
546 } 549 }
547 std::ostringstream str; 550 std::ostringstream str;
548 str << "TypeError: node #" << node->id() << ":" << *node->op() 551 str << "TypeError: node #" << node->id() << ":" << *node->op()
549 << " uses node #" << input->id() << ":" << *input->op() 552 << " uses node #" << input->id() << ":" << *input->op()
550 << " which doesn't have a kFloat32 representation."; 553 << " which doesn't have a kFloat32 representation.";
551 FATAL(str.str().c_str()); 554 FATAL(str.str().c_str());
552 } 555 }
553 556
554 void CheckValueInputForFloat64Op(Node const* node, int index) { 557 void CheckValueInputForFloat64Op(Node const* node, int index) {
555 Node const* input = node->InputAt(index); 558 Node const* input = node->InputAt(index);
556 if (MachineRepresentation::kFloat64 == typer_->GetRepresentation(input)) { 559 if (MachineRepresentation::kFloat64 ==
560 inferrer_->GetRepresentation(input)) {
557 return; 561 return;
558 } 562 }
559 std::ostringstream str; 563 std::ostringstream str;
560 str << "TypeError: node #" << node->id() << ":" << *node->op() 564 str << "TypeError: node #" << node->id() << ":" << *node->op()
561 << " uses node #" << input->id() << ":" << *input->op() 565 << " uses node #" << input->id() << ":" << *input->op()
562 << " which doesn't have a kFloat64 representation."; 566 << " which doesn't have a kFloat64 representation.";
563 FATAL(str.str().c_str()); 567 FATAL(str.str().c_str());
564 } 568 }
565 569
566 void CheckCallInputs(Node const* node) { 570 void CheckCallInputs(Node const* node) {
567 CallDescriptor const* desc = CallDescriptorOf(node->op()); 571 CallDescriptor const* desc = CallDescriptorOf(node->op());
568 std::ostringstream str; 572 std::ostringstream str;
569 bool should_log_error = false; 573 bool should_log_error = false;
570 for (size_t i = 0; i < desc->InputCount(); ++i) { 574 for (size_t i = 0; i < desc->InputCount(); ++i) {
571 Node const* input = node->InputAt(static_cast<int>(i)); 575 Node const* input = node->InputAt(static_cast<int>(i));
572 MachineRepresentation const input_type = typer_->GetRepresentation(input); 576 MachineRepresentation const input_type =
577 inferrer_->GetRepresentation(input);
573 MachineRepresentation const expected_input_type = 578 MachineRepresentation const expected_input_type =
574 desc->GetInputType(i).representation(); 579 desc->GetInputType(i).representation();
575 if (!IsCompatible(expected_input_type, input_type)) { 580 if (!IsCompatible(expected_input_type, input_type)) {
576 if (!should_log_error) { 581 if (!should_log_error) {
577 should_log_error = true; 582 should_log_error = true;
578 str << "TypeError: node #" << node->id() << ":" << *node->op() 583 str << "TypeError: node #" << node->id() << ":" << *node->op()
579 << " has wrong type for:" << std::endl; 584 << " has wrong type for:" << std::endl;
580 } else { 585 } else {
581 str << std::endl; 586 str << std::endl;
582 } 587 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 actual == MachineRepresentation::kWord8 || 647 actual == MachineRepresentation::kWord8 ||
643 actual == MachineRepresentation::kWord16 || 648 actual == MachineRepresentation::kWord16 ||
644 actual == MachineRepresentation::kWord32); 649 actual == MachineRepresentation::kWord32);
645 case MachineRepresentation::kNone: 650 case MachineRepresentation::kNone:
646 UNREACHABLE(); 651 UNREACHABLE();
647 } 652 }
648 return false; 653 return false;
649 } 654 }
650 655
651 Schedule const* const schedule_; 656 Schedule const* const schedule_;
652 MachineRepresentationInferrer const* const typer_; 657 MachineRepresentationInferrer const* const inferrer_;
653 }; 658 };
654 659
655 } // namespace 660 } // namespace
656 661
657 void MachineGraphVerifier::Run(Graph* graph, Schedule const* const schedule, 662 void MachineGraphVerifier::Run(Graph* graph, Schedule const* const schedule,
658 Linkage* linkage, Zone* temp_zone) { 663 Linkage* linkage, Zone* temp_zone) {
659 MachineRepresentationInferrer representation_inferrer(schedule, graph, 664 MachineRepresentationInferrer representation_inferrer(schedule, graph,
660 linkage, temp_zone); 665 linkage, temp_zone);
661 MachineRepresentationChecker checker(schedule, &representation_inferrer); 666 MachineRepresentationChecker checker(schedule, &representation_inferrer);
662 checker.Run(); 667 checker.Run();
663 } 668 }
664 669
665 } // namespace compiler 670 } // namespace compiler
666 } // namespace internal 671 } // namespace internal
667 } // namespace v8 672 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698