 Chromium Code Reviews
 Chromium Code Reviews Issue 395943003:
  Support allocation sinking for compound objects.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
    
  
    Issue 395943003:
  Support allocation sinking for compound objects.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart| 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 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1756 const LocalVariable& stacktrace_var_; | 1756 const LocalVariable& stacktrace_var_; | 
| 1757 const bool needs_stacktrace_; | 1757 const bool needs_stacktrace_; | 
| 1758 | 1758 | 
| 1759 DISALLOW_COPY_AND_ASSIGN(CatchBlockEntryInstr); | 1759 DISALLOW_COPY_AND_ASSIGN(CatchBlockEntryInstr); | 
| 1760 }; | 1760 }; | 
| 1761 | 1761 | 
| 1762 | 1762 | 
| 1763 // If the result of the allocation is not stored into any field, passed | 1763 // If the result of the allocation is not stored into any field, passed | 
| 1764 // as an argument or used in a phi then it can't alias with any other | 1764 // as an argument or used in a phi then it can't alias with any other | 
| 1765 // SSA value. | 1765 // SSA value. | 
| 1766 enum AliasIdentity { | 1766 class AliasIdentity { | 
| 
srdjan
2014/07/17 23:08:15
: public ValueObject ?
 
Vyacheslav Egorov (Google)
2014/07/18 11:25:08
Done.
 | |
| 1767 kIdentityUnknown, | 1767 public: | 
| 1768 kIdentityAliased, | 1768 // It is unknown if value has aliases. | 
| 1769 kIdentityNotAliased | 1769 static AliasIdentity Unknown() { return AliasIdentity(kUnknown); } | 
| 1770 | |
| 1771 // It is known that value can have aliases. | |
| 1772 static AliasIdentity Aliased() { return AliasIdentity(kAliased); } | |
| 1773 | |
| 1774 // It is known that value has no aliases. | |
| 1775 static AliasIdentity NotAliased() { return AliasIdentity(kNotAliased); } | |
| 1776 | |
| 1777 // It is known that value has no aliases and it was selected by | |
| 1778 // allocation sinking pass as a candidate. | |
| 1779 static AliasIdentity AllocationSinkingCandidate() { | |
| 1780 return AliasIdentity(kAllocationSinkingCandidate); | |
| 1781 } | |
| 1782 | |
| 1783 bool IsUnknown() const { return value_ == kUnknown; } | |
| 1784 bool IsAliased() const { return value_ == kAliased; } | |
| 1785 bool IsNotAliased() const { return (value_ & kNotAliased) != 0; } | |
| 1786 bool IsAllocationSinkingCandidate() const { | |
| 1787 return value_ == kAllocationSinkingCandidate; | |
| 1788 } | |
| 1789 | |
| 1790 private: | |
| 1791 explicit AliasIdentity(intptr_t value) : value_(value) { } | |
| 1792 | |
| 1793 enum { | |
| 1794 kUnknown = 0, | |
| 1795 kNotAliased = 1, | |
| 1796 kAliased = 2, | |
| 1797 kAllocationSinkingCandidate = 3, | |
| 1798 }; | |
| 1799 | |
| 1800 COMPILE_ASSERT((kUnknown & kNotAliased) == 0); | |
| 1801 COMPILE_ASSERT((kAliased & kNotAliased) == 0); | |
| 1802 COMPILE_ASSERT((kAllocationSinkingCandidate & kNotAliased) != 0); | |
| 1803 | |
| 1804 intptr_t value_; | |
| 
srdjan
2014/07/17 23:08:15
const
 
Vyacheslav Egorov (Google)
2014/07/18 11:25:08
It can't be const because we have fields of this t
 | |
| 1770 }; | 1805 }; | 
| 1771 | 1806 | 
| 1772 | 1807 | 
| 1773 // Abstract super-class of all instructions that define a value (Bind, Phi). | 1808 // Abstract super-class of all instructions that define a value (Bind, Phi). | 
| 1774 class Definition : public Instruction { | 1809 class Definition : public Instruction { | 
| 1775 public: | 1810 public: | 
| 1776 Definition(); | 1811 Definition(); | 
| 1777 | 1812 | 
| 1778 virtual Definition* AsDefinition() { return this; } | 1813 virtual Definition* AsDefinition() { return this; } | 
| 1779 | 1814 | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1920 } | 1955 } | 
| 1921 | 1956 | 
| 1922 void SetReplacement(Definition* other) { | 1957 void SetReplacement(Definition* other) { | 
| 1923 ASSERT(ssa_temp_index_ >= 0); | 1958 ASSERT(ssa_temp_index_ >= 0); | 
| 1924 ASSERT(WasEliminated()); | 1959 ASSERT(WasEliminated()); | 
| 1925 ssa_temp_index_ = kReplacementMarker; | 1960 ssa_temp_index_ = kReplacementMarker; | 
| 1926 temp_index_ = reinterpret_cast<intptr_t>(other); | 1961 temp_index_ = reinterpret_cast<intptr_t>(other); | 
| 1927 } | 1962 } | 
| 1928 | 1963 | 
| 1929 virtual AliasIdentity Identity() const { | 1964 virtual AliasIdentity Identity() const { | 
| 1930 // Only implemented for allocation instructions. | 1965 return AliasIdentity::Unknown(); | 
| 1931 UNREACHABLE(); | |
| 1932 return kIdentityUnknown; | |
| 1933 } | 1966 } | 
| 1934 | 1967 | 
| 1935 virtual void SetIdentity(AliasIdentity identity) { | 1968 virtual void SetIdentity(AliasIdentity identity) { | 
| 1936 UNREACHABLE(); | 1969 UNREACHABLE(); | 
| 1937 } | 1970 } | 
| 1938 | 1971 | 
| 1939 Definition* OriginalDefinition(); | 1972 Definition* OriginalDefinition(); | 
| 1940 | 1973 | 
| 1941 protected: | 1974 protected: | 
| 1942 friend class RangeAnalysis; | 1975 friend class RangeAnalysis; | 
| (...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3622 ZoneGrowableArray<PushArgumentInstr*>* arguments, | 3655 ZoneGrowableArray<PushArgumentInstr*>* arguments, | 
| 3623 const ZoneGrowableArray<const ICData*>& ic_data_array) | 3656 const ZoneGrowableArray<const ICData*>& ic_data_array) | 
| 3624 : ic_data_(GetICData(ic_data_array)), | 3657 : ic_data_(GetICData(ic_data_array)), | 
| 3625 token_pos_(token_pos), | 3658 token_pos_(token_pos), | 
| 3626 function_(function), | 3659 function_(function), | 
| 3627 argument_names_(argument_names), | 3660 argument_names_(argument_names), | 
| 3628 arguments_(arguments), | 3661 arguments_(arguments), | 
| 3629 result_cid_(kDynamicCid), | 3662 result_cid_(kDynamicCid), | 
| 3630 is_known_list_constructor_(false), | 3663 is_known_list_constructor_(false), | 
| 3631 is_native_list_factory_(false), | 3664 is_native_list_factory_(false), | 
| 3632 identity_(kIdentityUnknown) { | 3665 identity_(AliasIdentity::Unknown()) { | 
| 3633 ASSERT(function.IsZoneHandle()); | 3666 ASSERT(function.IsZoneHandle()); | 
| 3634 ASSERT(argument_names.IsZoneHandle() || argument_names.InVMHeap()); | 3667 ASSERT(argument_names.IsZoneHandle() || argument_names.InVMHeap()); | 
| 3635 } | 3668 } | 
| 3636 | 3669 | 
| 3637 // ICData for static calls carries call count. | 3670 // ICData for static calls carries call count. | 
| 3638 const ICData* ic_data() const { return ic_data_; } | 3671 const ICData* ic_data() const { return ic_data_; } | 
| 3639 bool HasICData() const { | 3672 bool HasICData() const { | 
| 3640 return (ic_data() != NULL) && !ic_data()->IsNull(); | 3673 return (ic_data() != NULL) && !ic_data()->IsNull(); | 
| 3641 } | 3674 } | 
| 3642 | 3675 | 
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4467 | 4500 | 
| 4468 | 4501 | 
| 4469 class AllocateObjectInstr : public TemplateDefinition<0> { | 4502 class AllocateObjectInstr : public TemplateDefinition<0> { | 
| 4470 public: | 4503 public: | 
| 4471 AllocateObjectInstr(intptr_t token_pos, | 4504 AllocateObjectInstr(intptr_t token_pos, | 
| 4472 const Class& cls, | 4505 const Class& cls, | 
| 4473 ZoneGrowableArray<PushArgumentInstr*>* arguments) | 4506 ZoneGrowableArray<PushArgumentInstr*>* arguments) | 
| 4474 : token_pos_(token_pos), | 4507 : token_pos_(token_pos), | 
| 4475 cls_(cls), | 4508 cls_(cls), | 
| 4476 arguments_(arguments), | 4509 arguments_(arguments), | 
| 4477 identity_(kIdentityUnknown), | 4510 identity_(AliasIdentity::Unknown()), | 
| 4478 closure_function_(Function::ZoneHandle()) { | 4511 closure_function_(Function::ZoneHandle()) { | 
| 4479 // Either no arguments or one type-argument and one instantiator. | 4512 // Either no arguments or one type-argument and one instantiator. | 
| 4480 ASSERT(arguments->is_empty() || (arguments->length() == 1)); | 4513 ASSERT(arguments->is_empty() || (arguments->length() == 1)); | 
| 4481 } | 4514 } | 
| 4482 | 4515 | 
| 4483 DECLARE_INSTRUCTION(AllocateObject) | 4516 DECLARE_INSTRUCTION(AllocateObject) | 
| 4484 virtual CompileType ComputeType() const; | 4517 virtual CompileType ComputeType() const; | 
| 4485 | 4518 | 
| 4486 virtual intptr_t ArgumentCount() const { return arguments_->length(); } | 4519 virtual intptr_t ArgumentCount() const { return arguments_->length(); } | 
| 4487 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { | 4520 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 4516 | 4549 | 
| 4517 DISALLOW_COPY_AND_ASSIGN(AllocateObjectInstr); | 4550 DISALLOW_COPY_AND_ASSIGN(AllocateObjectInstr); | 
| 4518 }; | 4551 }; | 
| 4519 | 4552 | 
| 4520 | 4553 | 
| 4521 // This instruction captures the state of the object which had its allocation | 4554 // This instruction captures the state of the object which had its allocation | 
| 4522 // removed during the AllocationSinking pass. | 4555 // removed during the AllocationSinking pass. | 
| 4523 // It does not produce any real code only deoptimization information. | 4556 // It does not produce any real code only deoptimization information. | 
| 4524 class MaterializeObjectInstr : public Definition { | 4557 class MaterializeObjectInstr : public Definition { | 
| 4525 public: | 4558 public: | 
| 4526 MaterializeObjectInstr(const Class& cls, | 4559 MaterializeObjectInstr(AllocateObjectInstr* allocation, | 
| 4560 const Class& cls, | |
| 4527 const ZoneGrowableArray<const Object*>& slots, | 4561 const ZoneGrowableArray<const Object*>& slots, | 
| 4528 ZoneGrowableArray<Value*>* values) | 4562 ZoneGrowableArray<Value*>* values) | 
| 4529 : cls_(cls), slots_(slots), values_(values), locations_(NULL) { | 4563 : allocation_(allocation), | 
| 4564 cls_(cls), | |
| 4565 slots_(slots), | |
| 4566 values_(values), | |
| 4567 locations_(NULL), | |
| 4568 visited_for_liveness_(false), | |
| 4569 registers_remapped_(false) { | |
| 4530 ASSERT(slots_.length() == values_->length()); | 4570 ASSERT(slots_.length() == values_->length()); | 
| 4531 for (intptr_t i = 0; i < InputCount(); i++) { | 4571 for (intptr_t i = 0; i < InputCount(); i++) { | 
| 4532 InputAt(i)->set_instruction(this); | 4572 InputAt(i)->set_instruction(this); | 
| 4533 InputAt(i)->set_use_index(i); | 4573 InputAt(i)->set_use_index(i); | 
| 4534 } | 4574 } | 
| 4535 } | 4575 } | 
| 4536 | 4576 | 
| 4577 AllocateObjectInstr* allocation() const { return allocation_; } | |
| 4537 const Class& cls() const { return cls_; } | 4578 const Class& cls() const { return cls_; } | 
| 4538 intptr_t FieldOffsetAt(intptr_t i) const { | 4579 intptr_t FieldOffsetAt(intptr_t i) const { | 
| 4539 return slots_[i]->IsField() | 4580 return slots_[i]->IsField() | 
| 4540 ? Field::Cast(*slots_[i]).Offset() | 4581 ? Field::Cast(*slots_[i]).Offset() | 
| 4541 : Smi::Cast(*slots_[i]).Value(); | 4582 : Smi::Cast(*slots_[i]).Value(); | 
| 4542 } | 4583 } | 
| 4543 const Location& LocationAt(intptr_t i) { | 4584 const Location& LocationAt(intptr_t i) { | 
| 4544 return locations_[i]; | 4585 return locations_[i]; | 
| 4545 } | 4586 } | 
| 4546 | 4587 | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 4569 virtual EffectSet Effects() const { return EffectSet::None(); } | 4610 virtual EffectSet Effects() const { return EffectSet::None(); } | 
| 4570 | 4611 | 
| 4571 Location* locations() { return locations_; } | 4612 Location* locations() { return locations_; } | 
| 4572 void set_locations(Location* locations) { locations_ = locations; } | 4613 void set_locations(Location* locations) { locations_ = locations; } | 
| 4573 | 4614 | 
| 4574 virtual bool MayThrow() const { return false; } | 4615 virtual bool MayThrow() const { return false; } | 
| 4575 | 4616 | 
| 4576 void RemapRegisters(intptr_t* fpu_reg_slots, | 4617 void RemapRegisters(intptr_t* fpu_reg_slots, | 
| 4577 intptr_t* cpu_reg_slots); | 4618 intptr_t* cpu_reg_slots); | 
| 4578 | 4619 | 
| 4620 bool was_visited_for_liveness() const { return visited_for_liveness_; } | |
| 4621 void mark_visited_for_liveness() { | |
| 4622 visited_for_liveness_ = true; | |
| 4623 } | |
| 4624 | |
| 4579 private: | 4625 private: | 
| 4580 virtual void RawSetInputAt(intptr_t i, Value* value) { | 4626 virtual void RawSetInputAt(intptr_t i, Value* value) { | 
| 4581 (*values_)[i] = value; | 4627 (*values_)[i] = value; | 
| 4582 } | 4628 } | 
| 4583 | 4629 | 
| 4630 AllocateObjectInstr* allocation_; | |
| 4584 const Class& cls_; | 4631 const Class& cls_; | 
| 4585 const ZoneGrowableArray<const Object*>& slots_; | 4632 const ZoneGrowableArray<const Object*>& slots_; | 
| 4586 ZoneGrowableArray<Value*>* values_; | 4633 ZoneGrowableArray<Value*>* values_; | 
| 4587 Location* locations_; | 4634 Location* locations_; | 
| 4588 | 4635 | 
| 4636 bool visited_for_liveness_; | |
| 4637 bool registers_remapped_; | |
| 4638 | |
| 4589 DISALLOW_COPY_AND_ASSIGN(MaterializeObjectInstr); | 4639 DISALLOW_COPY_AND_ASSIGN(MaterializeObjectInstr); | 
| 4590 }; | 4640 }; | 
| 4591 | 4641 | 
| 4592 | 4642 | 
| 4593 class CreateArrayInstr : public TemplateDefinition<2> { | 4643 class CreateArrayInstr : public TemplateDefinition<2> { | 
| 4594 public: | 4644 public: | 
| 4595 CreateArrayInstr(intptr_t token_pos, | 4645 CreateArrayInstr(intptr_t token_pos, | 
| 4596 Value* element_type, | 4646 Value* element_type, | 
| 4597 Value* num_elements) | 4647 Value* num_elements) | 
| 4598 : token_pos_(token_pos), identity_(kIdentityUnknown) { | 4648 : token_pos_(token_pos), identity_(AliasIdentity::Unknown()) { | 
| 4599 SetInputAt(kElementTypePos, element_type); | 4649 SetInputAt(kElementTypePos, element_type); | 
| 4600 SetInputAt(kLengthPos, num_elements); | 4650 SetInputAt(kLengthPos, num_elements); | 
| 4601 } | 4651 } | 
| 4602 | 4652 | 
| 4603 enum { | 4653 enum { | 
| 4604 kElementTypePos = 0, | 4654 kElementTypePos = 0, | 
| 4605 kLengthPos = 1 | 4655 kLengthPos = 1 | 
| 4606 }; | 4656 }; | 
| 4607 | 4657 | 
| 4608 DECLARE_INSTRUCTION(CreateArray) | 4658 DECLARE_INSTRUCTION(CreateArray) | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4691 } | 4741 } | 
| 4692 virtual bool AttributesEqual(Instruction* other) const { return true; } | 4742 virtual bool AttributesEqual(Instruction* other) const { return true; } | 
| 4693 | 4743 | 
| 4694 virtual bool MayThrow() const { return false; } | 4744 virtual bool MayThrow() const { return false; } | 
| 4695 | 4745 | 
| 4696 private: | 4746 private: | 
| 4697 DISALLOW_COPY_AND_ASSIGN(LoadClassIdInstr); | 4747 DISALLOW_COPY_AND_ASSIGN(LoadClassIdInstr); | 
| 4698 }; | 4748 }; | 
| 4699 | 4749 | 
| 4700 | 4750 | 
| 4701 | |
| 4702 | |
| 4703 class LoadFieldInstr : public TemplateDefinition<1> { | 4751 class LoadFieldInstr : public TemplateDefinition<1> { | 
| 4704 public: | 4752 public: | 
| 4705 LoadFieldInstr(Value* instance, | 4753 LoadFieldInstr(Value* instance, | 
| 4706 intptr_t offset_in_bytes, | 4754 intptr_t offset_in_bytes, | 
| 4707 const AbstractType& type, | 4755 const AbstractType& type, | 
| 4708 intptr_t token_pos) | 4756 intptr_t token_pos) | 
| 4709 : offset_in_bytes_(offset_in_bytes), | 4757 : offset_in_bytes_(offset_in_bytes), | 
| 4710 type_(type), | 4758 type_(type), | 
| 4711 result_cid_(kDynamicCid), | 4759 result_cid_(kDynamicCid), | 
| 4712 immutable_(false), | 4760 immutable_(false), | 
| (...skipping 3855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8568 ForwardInstructionIterator* current_iterator_; | 8616 ForwardInstructionIterator* current_iterator_; | 
| 8569 | 8617 | 
| 8570 private: | 8618 private: | 
| 8571 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 8619 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 
| 8572 }; | 8620 }; | 
| 8573 | 8621 | 
| 8574 | 8622 | 
| 8575 } // namespace dart | 8623 } // namespace dart | 
| 8576 | 8624 | 
| 8577 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 8625 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 
| OLD | NEW |