| OLD | NEW |
| 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 Loading... |
| 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 successor(); \ | 69 return next(); \ |
| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 BitVector* vars = | 438 BitVector* vars = |
| 439 (variable_count == 0) ? NULL : new BitVector(variable_count); | 439 (variable_count == 0) ? NULL : new BitVector(variable_count); |
| 440 assigned_vars->Add(vars); | 440 assigned_vars->Add(vars); |
| 441 // The preorder, parent, and assigned_vars arrays are all indexed by | 441 // The preorder, parent, and assigned_vars arrays are all indexed by |
| 442 // preorder block number, so they should stay in lockstep. | 442 // preorder block number, so they should stay in lockstep. |
| 443 ASSERT(preorder->length() == parent->length()); | 443 ASSERT(preorder->length() == parent->length()); |
| 444 ASSERT(preorder->length() == assigned_vars->length()); | 444 ASSERT(preorder->length() == assigned_vars->length()); |
| 445 | 445 |
| 446 // 5. Iterate straight-line successors until a branch instruction or | 446 // 5. Iterate straight-line successors until a branch instruction or |
| 447 // another basic block entry instruction, and visit that instruction. | 447 // another basic block entry instruction, and visit that instruction. |
| 448 ASSERT(successor() != NULL); | 448 ASSERT(next() != NULL); |
| 449 Instruction* next = successor(); | 449 Instruction* next_instr = next(); |
| 450 if (next->IsBlockEntry()) { | 450 if (next_instr->IsBlockEntry()) { |
| 451 set_last_instruction(this); | 451 set_last_instruction(this); |
| 452 } else { | 452 } else { |
| 453 while ((next != NULL) && !next->IsBlockEntry() && !next->IsBranch()) { | 453 while ((next_instr != NULL) && |
| 454 if (vars != NULL) next->RecordAssignedVars(vars); | 454 !next_instr->IsBlockEntry() && |
| 455 set_last_instruction(next); | 455 !next_instr->IsBranch()) { |
| 456 next = next->successor(); | 456 if (vars != NULL) next_instr->RecordAssignedVars(vars); |
| 457 set_last_instruction(next_instr); |
| 458 next_instr = next_instr->next(); |
| 457 } | 459 } |
| 458 } | 460 } |
| 459 if (next != NULL) { | 461 if (next_instr != NULL) { |
| 460 next->DiscoverBlocks(this, preorder, postorder, | 462 next_instr->DiscoverBlocks(this, preorder, postorder, |
| 461 parent, assigned_vars, variable_count); | 463 parent, assigned_vars, variable_count); |
| 462 } | 464 } |
| 463 | 465 |
| 464 // 6. Assign postorder number and add the block entry to the list. | 466 // 6. Assign postorder number and add the block entry to the list. |
| 465 set_postorder_number(postorder->length()); | 467 set_postorder_number(postorder->length()); |
| 466 postorder->Add(this); | 468 postorder->Add(this); |
| 467 } | 469 } |
| 468 | 470 |
| 469 | 471 |
| 470 void BranchInstr::DiscoverBlocks( | 472 void BranchInstr::DiscoverBlocks( |
| 471 BlockEntryInstr* current_block, | 473 BlockEntryInstr* current_block, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 500 } | 502 } |
| 501 ASSERT((*phis_)[var_index] == NULL); | 503 ASSERT((*phis_)[var_index] == NULL); |
| 502 (*phis_)[var_index] = new PhiInstr(PredecessorCount()); | 504 (*phis_)[var_index] = new PhiInstr(PredecessorCount()); |
| 503 phi_count_++; | 505 phi_count_++; |
| 504 } | 506 } |
| 505 | 507 |
| 506 | 508 |
| 507 intptr_t Instruction::SuccessorCount() const { | 509 intptr_t Instruction::SuccessorCount() const { |
| 508 ASSERT(!IsBranch()); | 510 ASSERT(!IsBranch()); |
| 509 ASSERT(!IsGraphEntry()); | 511 ASSERT(!IsGraphEntry()); |
| 510 ASSERT(successor() == NULL || | 512 ASSERT(next() == NULL || next()->IsBlockEntry()); |
| 511 successor()->IsBlockEntry()); | 513 return (next() != NULL) ? 1 : 0; |
| 512 return successor() != NULL ? 1 : 0; | |
| 513 } | 514 } |
| 514 | 515 |
| 515 | 516 |
| 516 BlockEntryInstr* Instruction::SuccessorAt(intptr_t index) const { | 517 BlockEntryInstr* Instruction::SuccessorAt(intptr_t index) const { |
| 517 return successor()->AsBlockEntry(); | 518 return next()->AsBlockEntry(); |
| 518 } | 519 } |
| 519 | 520 |
| 520 | 521 |
| 521 intptr_t GraphEntryInstr::SuccessorCount() const { | 522 intptr_t GraphEntryInstr::SuccessorCount() const { |
| 522 return 1 + catch_entries_.length(); | 523 return 1 + catch_entries_.length(); |
| 523 } | 524 } |
| 524 | 525 |
| 525 | 526 |
| 526 BlockEntryInstr* GraphEntryInstr::SuccessorAt(intptr_t index) const { | 527 BlockEntryInstr* GraphEntryInstr::SuccessorAt(intptr_t index) const { |
| 527 if (index == 0) return normal_entry_; | 528 if (index == 0) return normal_entry_; |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 const ExternalLabel label(closure_function.ToCString(), stub.EntryPoint()); | 1293 const ExternalLabel label(closure_function.ToCString(), stub.EntryPoint()); |
| 1293 compiler->GenerateCall(token_pos(), try_index(), &label, | 1294 compiler->GenerateCall(token_pos(), try_index(), &label, |
| 1294 PcDescriptors::kOther); | 1295 PcDescriptors::kOther); |
| 1295 __ Drop(2); // Discard type arguments and receiver. | 1296 __ Drop(2); // Discard type arguments and receiver. |
| 1296 } | 1297 } |
| 1297 | 1298 |
| 1298 | 1299 |
| 1299 #undef __ | 1300 #undef __ |
| 1300 | 1301 |
| 1301 } // namespace dart | 1302 } // namespace dart |
| OLD | NEW |