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

Side by Side Diff: vm/intermediate_language.cc

Issue 10665022: Make IL instructions a doubly-linked list within basic blocks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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 | « vm/intermediate_language.h ('k') | 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flow_graph_builder.h" 9 #include "vm/flow_graph_builder.h"
10 #include "vm/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 FOR_EACH_COMPUTATION(DEFINE_ACCEPT) 61 FOR_EACH_COMPUTATION(DEFINE_ACCEPT)
62 62
63 #undef DEFINE_ACCEPT 63 #undef DEFINE_ACCEPT
64 64
65 65
66 #define DEFINE_ACCEPT(ShortName) \ 66 #define DEFINE_ACCEPT(ShortName) \
67 Instruction* ShortName##Instr::Accept(FlowGraphVisitor* visitor) { \ 67 Instruction* ShortName##Instr::Accept(FlowGraphVisitor* visitor) { \
68 visitor->Visit##ShortName(this); \ 68 visitor->Visit##ShortName(this); \
69 return StraightLineSuccessor(); \ 69 return successor(); \
70 } 70 }
71 71
72 FOR_EACH_INSTRUCTION(DEFINE_ACCEPT) 72 FOR_EACH_INSTRUCTION(DEFINE_ACCEPT)
73 73
74 #undef DEFINE_ACCEPT 74 #undef DEFINE_ACCEPT
75 75
76 76
77 // True iff. the v2 is above v1 on stack, or one of them is constant. 77 // True iff. the v2 is above v1 on stack, or one of them is constant.
78 static bool VerifyValues(Value* v1, Value* v2) { 78 static bool VerifyValues(Value* v1, Value* v2) {
79 ASSERT(v1->IsUse() && v2->IsUse()); 79 ASSERT(v1->IsUse() && v2->IsUse());
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 BitVector* vars = 452 BitVector* vars =
453 (variable_count == 0) ? NULL : new BitVector(variable_count); 453 (variable_count == 0) ? NULL : new BitVector(variable_count);
454 assigned_vars->Add(vars); 454 assigned_vars->Add(vars);
455 // The preorder, parent, and assigned_vars arrays are all indexed by 455 // The preorder, parent, and assigned_vars arrays are all indexed by
456 // preorder block number, so they should stay in lockstep. 456 // preorder block number, so they should stay in lockstep.
457 ASSERT(preorder->length() == parent->length()); 457 ASSERT(preorder->length() == parent->length());
458 ASSERT(preorder->length() == assigned_vars->length()); 458 ASSERT(preorder->length() == assigned_vars->length());
459 459
460 // 5. Iterate straight-line successors until a branch instruction or 460 // 5. Iterate straight-line successors until a branch instruction or
461 // another basic block entry instruction, and visit that instruction. 461 // another basic block entry instruction, and visit that instruction.
462 ASSERT(StraightLineSuccessor() != NULL); 462 ASSERT(successor() != NULL);
463 Instruction* next = StraightLineSuccessor(); 463 Instruction* next = successor();
464 if (next->IsBlockEntry()) { 464 if (next->IsBlockEntry()) {
465 set_last_instruction(this); 465 set_last_instruction(this);
466 } else { 466 } else {
467 while ((next != NULL) && !next->IsBlockEntry() && !next->IsBranch()) { 467 while ((next != NULL) && !next->IsBlockEntry() && !next->IsBranch()) {
468 if (vars != NULL) next->RecordAssignedVars(vars); 468 if (vars != NULL) next->RecordAssignedVars(vars);
469 set_last_instruction(next); 469 set_last_instruction(next);
470 next = next->StraightLineSuccessor(); 470 next = next->successor();
471 } 471 }
472 } 472 }
473 if (next != NULL) { 473 if (next != NULL) {
474 next->DiscoverBlocks(this, preorder, postorder, 474 next->DiscoverBlocks(this, preorder, postorder,
475 parent, assigned_vars, variable_count); 475 parent, assigned_vars, variable_count);
476 } 476 }
477 477
478 // 6. Assign postorder number and add the block entry to the list. 478 // 6. Assign postorder number and add the block entry to the list.
479 set_postorder_number(postorder->length()); 479 set_postorder_number(postorder->length());
480 postorder->Add(this); 480 postorder->Add(this);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 514 }
515 ASSERT((*phis_)[var_index] == NULL); 515 ASSERT((*phis_)[var_index] == NULL);
516 (*phis_)[var_index] = new PhiInstr(PredecessorCount()); 516 (*phis_)[var_index] = new PhiInstr(PredecessorCount());
517 phi_count_++; 517 phi_count_++;
518 } 518 }
519 519
520 520
521 intptr_t Instruction::SuccessorCount() const { 521 intptr_t Instruction::SuccessorCount() const {
522 ASSERT(!IsBranch()); 522 ASSERT(!IsBranch());
523 ASSERT(!IsGraphEntry()); 523 ASSERT(!IsGraphEntry());
524 ASSERT(StraightLineSuccessor() == NULL || 524 ASSERT(successor() == NULL ||
525 StraightLineSuccessor()->IsBlockEntry()); 525 successor()->IsBlockEntry());
526 return StraightLineSuccessor() != NULL ? 1 : 0; 526 return successor() != NULL ? 1 : 0;
527 } 527 }
528 528
529 529
530 BlockEntryInstr* Instruction::SuccessorAt(intptr_t index) const { 530 BlockEntryInstr* Instruction::SuccessorAt(intptr_t index) const {
531 return StraightLineSuccessor()->AsBlockEntry(); 531 return successor()->AsBlockEntry();
532 }
533
534
535 void Instruction::RemoveFromGraph() {
536 ASSERT(!IsBlockEntry());
537 ASSERT(previous() != NULL);
538 Instruction* next = successor();
539 previous()->set_successor(next);
540 if (next != NULL) {
541 if (!next->IsBlockEntry()) {
542 next->set_previous(previous());
543 } else {
544 // Removing the last instruction of a block.
545 ASSERT(!IsBranch());
546 ASSERT(!IsThrow());
547 ASSERT(!IsReturn());
548 ASSERT(!IsReThrow());
549 // Update last_instruction of the current basic block.
550 Instruction* current = this;
551 while (!current->IsBlockEntry()) {
552 current = current->previous();
553 }
554 ASSERT(current->AsBlockEntry()->last_instruction() == this);
555 current->AsBlockEntry()->set_last_instruction(previous());
556 }
557 }
558 // Reset successor and previous instruction to indicate
559 // that the instruction is removed from the graph.
560 set_successor(NULL);
561 set_previous(NULL);
562 }
563
564
565 bool Instruction::is_linked() const {
566 ASSERT(!IsBlockEntry() || ((successor() != NULL) && (previous() == NULL)));
567 ASSERT(IsBlockEntry() || previous() != NULL);
568 return (previous() != NULL) || (successor() != NULL);
532 } 569 }
533 570
534 571
535 intptr_t GraphEntryInstr::SuccessorCount() const { 572 intptr_t GraphEntryInstr::SuccessorCount() const {
536 return 1 + catch_entries_.length(); 573 return 1 + catch_entries_.length();
537 } 574 }
538 575
539 576
540 BlockEntryInstr* GraphEntryInstr::SuccessorAt(intptr_t index) const { 577 BlockEntryInstr* GraphEntryInstr::SuccessorAt(intptr_t index) const {
541 if (index == 0) return normal_entry_; 578 if (index == 0) return normal_entry_;
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 const ExternalLabel label(closure_function.ToCString(), stub.EntryPoint()); 1345 const ExternalLabel label(closure_function.ToCString(), stub.EntryPoint());
1309 compiler->GenerateCall(token_pos(), try_index(), &label, 1346 compiler->GenerateCall(token_pos(), try_index(), &label,
1310 PcDescriptors::kOther); 1347 PcDescriptors::kOther);
1311 __ Drop(2); // Discard type arguments and receiver. 1348 __ Drop(2); // Discard type arguments and receiver.
1312 } 1349 }
1313 1350
1314 1351
1315 #undef __ 1352 #undef __
1316 1353
1317 } // namespace dart 1354 } // namespace dart
OLDNEW
« no previous file with comments | « vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698