| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ |
| 6 #define VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define VM_INTERMEDIATE_LANGUAGE_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 280 |
| 281 Instruction* instruction() const { return instruction_; } | 281 Instruction* instruction() const { return instruction_; } |
| 282 void set_instruction(Instruction* instruction) { instruction_ = instruction; } | 282 void set_instruction(Instruction* instruction) { instruction_ = instruction; } |
| 283 | 283 |
| 284 intptr_t use_index() const { return use_index_; } | 284 intptr_t use_index() const { return use_index_; } |
| 285 void set_use_index(intptr_t index) { use_index_ = index; } | 285 void set_use_index(intptr_t index) { use_index_ = index; } |
| 286 | 286 |
| 287 static void AddToList(Value* value, Value** list); | 287 static void AddToList(Value* value, Value** list); |
| 288 void RemoveFromUseList(); | 288 void RemoveFromUseList(); |
| 289 | 289 |
| 290 // Change the definition after use lists have been computed. |
| 291 inline void BindTo(Definition* definition); |
| 292 |
| 290 Value* Copy() { return new Value(definition_); } | 293 Value* Copy() { return new Value(definition_); } |
| 291 | 294 |
| 292 // This function must only be used when the new Value is dominated by | 295 // This function must only be used when the new Value is dominated by |
| 293 // the original Value. | 296 // the original Value. |
| 294 Value* CopyWithType() { | 297 Value* CopyWithType() { |
| 295 Value* copy = new Value(definition_); | 298 Value* copy = new Value(definition_); |
| 296 copy->reaching_type_ = reaching_type_; | 299 copy->reaching_type_ = reaching_type_; |
| 297 return copy; | 300 return copy; |
| 298 } | 301 } |
| 299 | 302 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 next_ = instr; | 573 next_ = instr; |
| 571 } | 574 } |
| 572 | 575 |
| 573 // Link together two instruction. | 576 // Link together two instruction. |
| 574 void LinkTo(Instruction* next) { | 577 void LinkTo(Instruction* next) { |
| 575 ASSERT(this != next); | 578 ASSERT(this != next); |
| 576 this->set_next(next); | 579 this->set_next(next); |
| 577 next->set_previous(this); | 580 next->set_previous(this); |
| 578 } | 581 } |
| 579 | 582 |
| 580 // Removed this instruction from the graph. | 583 // Removed this instruction from the graph, after use lists have been |
| 584 // computed. If the instruction is a definition with uses, those uses are |
| 585 // unaffected (so the instruction can be reinserted, e.g., hoisting). |
| 581 Instruction* RemoveFromGraph(bool return_previous = true); | 586 Instruction* RemoveFromGraph(bool return_previous = true); |
| 582 | 587 |
| 583 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 588 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 584 // a block) successors. Branch instruction with >1 successors override this | 589 // a block) successors. Branch instruction with >1 successors override this |
| 585 // function. | 590 // function. |
| 586 virtual intptr_t SuccessorCount() const; | 591 virtual intptr_t SuccessorCount() const; |
| 587 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 592 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 588 | 593 |
| 589 void Goto(JoinEntryInstr* entry); | 594 void Goto(JoinEntryInstr* entry); |
| 590 | 595 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 616 | 621 |
| 617 virtual LocationSummary* MakeLocationSummary() const = 0; | 622 virtual LocationSummary* MakeLocationSummary() const = 0; |
| 618 | 623 |
| 619 static LocationSummary* MakeCallSummary(); | 624 static LocationSummary* MakeCallSummary(); |
| 620 | 625 |
| 621 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { | 626 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 622 UNIMPLEMENTED(); | 627 UNIMPLEMENTED(); |
| 623 } | 628 } |
| 624 | 629 |
| 625 Environment* env() const { return env_; } | 630 Environment* env() const { return env_; } |
| 626 void set_env(Environment* env) { env_ = env; } | 631 void SetEnvironment(Environment* deopt_env); |
| 632 void RemoveEnvironment(); |
| 627 | 633 |
| 628 intptr_t lifetime_position() const { return lifetime_position_; } | 634 intptr_t lifetime_position() const { return lifetime_position_; } |
| 629 void set_lifetime_position(intptr_t pos) { | 635 void set_lifetime_position(intptr_t pos) { |
| 630 lifetime_position_ = pos; | 636 lifetime_position_ = pos; |
| 631 } | 637 } |
| 632 | 638 |
| 633 // Returns representation expected for the input operand at the given index. | 639 // Returns representation expected for the input operand at the given index. |
| 634 virtual Representation RequiredInputRepresentation(intptr_t idx) const { | 640 virtual Representation RequiredInputRepresentation(intptr_t idx) const { |
| 635 return kTagged; | 641 return kTagged; |
| 636 } | 642 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 650 virtual intptr_t DeoptimizationTarget() const { | 656 virtual intptr_t DeoptimizationTarget() const { |
| 651 UNREACHABLE(); | 657 UNREACHABLE(); |
| 652 return Isolate::kNoDeoptId; | 658 return Isolate::kNoDeoptId; |
| 653 } | 659 } |
| 654 | 660 |
| 655 // Returns a replacement for the instruction or NULL if the instruction can | 661 // Returns a replacement for the instruction or NULL if the instruction can |
| 656 // be eliminated. By default returns the this instruction which means no | 662 // be eliminated. By default returns the this instruction which means no |
| 657 // change. | 663 // change. |
| 658 virtual Instruction* Canonicalize(FlowGraphOptimizer* optimizer); | 664 virtual Instruction* Canonicalize(FlowGraphOptimizer* optimizer); |
| 659 | 665 |
| 660 // Insert this instruction before 'next'. | 666 // Insert this instruction before 'next' after use lists are computed. |
| 661 void InsertBefore(Instruction* next); | 667 // Instructions cannot be inserted before a block entry or any other |
| 668 // instruction without a previous instruction. |
| 669 void InsertBefore(Instruction* next) { InsertAfter(next->previous()); } |
| 662 | 670 |
| 663 // Insert this instruction after 'prev'. | 671 // Insert this instruction after 'prev' after use lists are computed. |
| 664 void InsertAfter(Instruction* prev); | 672 void InsertAfter(Instruction* prev); |
| 665 | 673 |
| 666 // Returns true if the instruction is affected by side effects. | 674 // Returns true if the instruction is affected by side effects. |
| 667 // Only instructions that are not affected by side effects can participate | 675 // Only instructions that are not affected by side effects can participate |
| 668 // in redundancy elimination or loop invariant code motion. | 676 // in redundancy elimination or loop invariant code motion. |
| 669 // TODO(fschneider): Make this abstract and implement for all instructions | 677 // TODO(fschneider): Make this abstract and implement for all instructions |
| 670 // instead of returning the safe default (true). | 678 // instead of returning the safe default (true). |
| 671 virtual bool AffectedBySideEffect() const { return true; } | 679 virtual bool AffectedBySideEffect() const { return true; } |
| 672 | 680 |
| 673 // Get the block entry for this instruction. | 681 // Get the block entry for this instruction. |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 Value* input_use_list_; | 1389 Value* input_use_list_; |
| 1382 Value* env_use_list_; | 1390 Value* env_use_list_; |
| 1383 UseKind use_kind_; | 1391 UseKind use_kind_; |
| 1384 | 1392 |
| 1385 Object& constant_value_; | 1393 Object& constant_value_; |
| 1386 | 1394 |
| 1387 DISALLOW_COPY_AND_ASSIGN(Definition); | 1395 DISALLOW_COPY_AND_ASSIGN(Definition); |
| 1388 }; | 1396 }; |
| 1389 | 1397 |
| 1390 | 1398 |
| 1399 // Change a value's definition after use lists have been computed. |
| 1400 inline void Value::BindTo(Definition* def) { |
| 1401 RemoveFromUseList(); |
| 1402 set_definition(def); |
| 1403 def->AddInputUse(this); |
| 1404 } |
| 1405 |
| 1406 |
| 1391 class PhiInstr : public Definition { | 1407 class PhiInstr : public Definition { |
| 1392 public: | 1408 public: |
| 1393 PhiInstr(JoinEntryInstr* block, intptr_t num_inputs) | 1409 PhiInstr(JoinEntryInstr* block, intptr_t num_inputs) |
| 1394 : block_(block), | 1410 : block_(block), |
| 1395 inputs_(num_inputs), | 1411 inputs_(num_inputs), |
| 1396 is_alive_(false), | 1412 is_alive_(false), |
| 1397 representation_(kTagged), | 1413 representation_(kTagged), |
| 1398 reaching_defs_(NULL) { | 1414 reaching_defs_(NULL) { |
| 1399 for (intptr_t i = 0; i < num_inputs; ++i) { | 1415 for (intptr_t i = 0; i < num_inputs; ++i) { |
| 1400 inputs_.Add(NULL); | 1416 inputs_.Add(NULL); |
| (...skipping 3077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4478 ForwardInstructionIterator* current_iterator_; | 4494 ForwardInstructionIterator* current_iterator_; |
| 4479 | 4495 |
| 4480 private: | 4496 private: |
| 4481 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 4497 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 4482 }; | 4498 }; |
| 4483 | 4499 |
| 4484 | 4500 |
| 4485 } // namespace dart | 4501 } // namespace dart |
| 4486 | 4502 |
| 4487 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 4503 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |