Chromium Code Reviews| 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 #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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 // Returns true, if this computation can deoptimize. | 149 // Returns true, if this computation can deoptimize. |
| 150 virtual bool CanDeoptimize() const = 0; | 150 virtual bool CanDeoptimize() const = 0; |
| 151 | 151 |
| 152 // Optimize this computation. Returns a replacement for the instruction | 152 // Optimize this computation. Returns a replacement for the instruction |
| 153 // that wraps this computation or NULL if nothing to replace. | 153 // that wraps this computation or NULL if nothing to replace. |
| 154 virtual Definition* TryReplace(BindInstr* instr) { return NULL; } | 154 virtual Definition* TryReplace(BindInstr* instr) { return NULL; } |
| 155 | 155 |
| 156 // Compile time type of the computation, which typically depends on the | 156 // Compile time type of the computation, which typically depends on the |
| 157 // compile time types (and possibly propagated types) of its inputs. | 157 // compile time types (and possibly propagated types) of its inputs. |
| 158 virtual RawAbstractType* CompileType() const = 0; | 158 virtual RawAbstractType* CompileType() const = 0; |
| 159 virtual intptr_t ResultCid() const { return kDynamicCid; } | |
|
regis
2012/08/15 22:46:54
This is correct to provide a default implementatio
srdjan
2012/08/16 00:34:46
Added TODO.
| |
| 159 | 160 |
| 160 // Mutate assigned_vars to add the local variable index for all | 161 // Mutate assigned_vars to add the local variable index for all |
| 161 // frame-allocated locals assigned to by the computation. | 162 // frame-allocated locals assigned to by the computation. |
| 162 virtual void RecordAssignedVars(BitVector* assigned_vars, | 163 virtual void RecordAssignedVars(BitVector* assigned_vars, |
| 163 intptr_t fixed_parameter_count); | 164 intptr_t fixed_parameter_count); |
| 164 | 165 |
| 165 virtual const char* DebugName() const = 0; | 166 virtual const char* DebugName() const = 0; |
| 166 | 167 |
| 167 // Printing support. These functions are sometimes overridden for custom | 168 // Printing support. These functions are sometimes overridden for custom |
| 168 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". | 169 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 inline Definition* definition() const; | 348 inline Definition* definition() const; |
| 348 void SetDefinition(Definition* definition); | 349 void SetDefinition(Definition* definition); |
| 349 | 350 |
| 350 virtual bool CanDeoptimize() const { return false; } | 351 virtual bool CanDeoptimize() const { return false; } |
| 351 | 352 |
| 352 UseVal* next_use() const { return next_use_; } | 353 UseVal* next_use() const { return next_use_; } |
| 353 UseVal* previous_use() const { return previous_use_; } | 354 UseVal* previous_use() const { return previous_use_; } |
| 354 virtual void RemoveFromUseList(); | 355 virtual void RemoveFromUseList(); |
| 355 virtual void RemoveInputUses() { RemoveFromUseList(); } | 356 virtual void RemoveInputUses() { RemoveFromUseList(); } |
| 356 | 357 |
| 358 virtual intptr_t ResultCid() const; | |
| 359 | |
| 357 private: | 360 private: |
| 358 void AddToUseList(); | 361 void AddToUseList(); |
| 359 Definition* definition_; | 362 Definition* definition_; |
| 360 UseVal* next_use_; | 363 UseVal* next_use_; |
| 361 UseVal* previous_use_; | 364 UseVal* previous_use_; |
| 362 | 365 |
| 363 friend class Definition; | 366 friend class Definition; |
| 364 | 367 |
| 365 DISALLOW_COPY_AND_ASSIGN(UseVal); | 368 DISALLOW_COPY_AND_ASSIGN(UseVal); |
| 366 }; | 369 }; |
| 367 | 370 |
| 368 | 371 |
| 369 class ConstantVal: public Value { | 372 class ConstantVal : public Value { |
| 370 public: | 373 public: |
| 371 explicit ConstantVal(const Object& value) | 374 explicit ConstantVal(const Object& value) |
| 372 : value_(value) { | 375 : value_(value) { |
| 373 ASSERT(value.IsZoneHandle()); | 376 ASSERT(value.IsZoneHandle()); |
| 374 ASSERT(value.IsSmi() || value.IsOld()); | 377 ASSERT(value.IsSmi() || value.IsOld()); |
| 375 } | 378 } |
| 376 | 379 |
| 377 DECLARE_VALUE(Constant) | 380 DECLARE_VALUE(Constant) |
| 378 | 381 |
| 379 const Object& value() const { return value_; } | 382 const Object& value() const { return value_; } |
| 380 | 383 |
| 381 virtual bool CanDeoptimize() const { return false; } | 384 virtual bool CanDeoptimize() const { return false; } |
| 382 | 385 |
| 383 virtual void RemoveFromUseList() { } | 386 virtual void RemoveFromUseList() { } |
| 384 | 387 |
| 388 virtual intptr_t ResultCid() const; | |
| 389 | |
| 385 private: | 390 private: |
| 386 const Object& value_; | 391 const Object& value_; |
| 387 | 392 |
| 388 DISALLOW_COPY_AND_ASSIGN(ConstantVal); | 393 DISALLOW_COPY_AND_ASSIGN(ConstantVal); |
| 389 }; | 394 }; |
| 390 | 395 |
| 391 #undef DECLARE_VALUE | 396 #undef DECLARE_VALUE |
| 392 | 397 |
| 393 | 398 |
| 394 class AssertAssignableComp : public TemplateComputation<3> { | 399 class AssertAssignableComp : public TemplateComputation<3> { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 } | 477 } |
| 473 void eliminate() { | 478 void eliminate() { |
| 474 ASSERT(!is_eliminated_); | 479 ASSERT(!is_eliminated_); |
| 475 is_eliminated_ = true; | 480 is_eliminated_ = true; |
| 476 } | 481 } |
| 477 | 482 |
| 478 virtual void PrintOperandsTo(BufferFormatter* f) const; | 483 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 479 | 484 |
| 480 virtual bool CanDeoptimize() const { return false; } | 485 virtual bool CanDeoptimize() const { return false; } |
| 481 | 486 |
| 487 virtual intptr_t ResultCid() const { return kBoolCid; } | |
| 488 | |
| 482 private: | 489 private: |
| 483 const intptr_t token_pos_; | 490 const intptr_t token_pos_; |
| 484 const intptr_t try_index_; | 491 const intptr_t try_index_; |
| 485 bool is_eliminated_; | 492 bool is_eliminated_; |
| 486 | 493 |
| 487 DISALLOW_COPY_AND_ASSIGN(AssertBooleanComp); | 494 DISALLOW_COPY_AND_ASSIGN(AssertBooleanComp); |
| 488 }; | 495 }; |
| 489 | 496 |
| 490 | 497 |
| 491 // Denotes the current context, normally held in a register. This is | 498 // Denotes the current context, normally held in a register. This is |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 } | 673 } |
| 667 | 674 |
| 668 DECLARE_COMPUTATION(StrictCompare) | 675 DECLARE_COMPUTATION(StrictCompare) |
| 669 | 676 |
| 670 virtual void PrintOperandsTo(BufferFormatter* f) const; | 677 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 671 | 678 |
| 672 virtual bool CanDeoptimize() const { return false; } | 679 virtual bool CanDeoptimize() const { return false; } |
| 673 | 680 |
| 674 virtual Definition* TryReplace(BindInstr* instr); | 681 virtual Definition* TryReplace(BindInstr* instr); |
| 675 | 682 |
| 683 virtual intptr_t ResultCid() const { return kBoolCid; } | |
| 684 | |
| 676 private: | 685 private: |
| 677 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); | 686 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); |
| 678 }; | 687 }; |
| 679 | 688 |
| 680 | 689 |
| 681 class EqualityCompareComp : public ComparisonComp { | 690 class EqualityCompareComp : public ComparisonComp { |
| 682 public: | 691 public: |
| 683 EqualityCompareComp(intptr_t token_pos, | 692 EqualityCompareComp(intptr_t token_pos, |
| 684 intptr_t try_index, | 693 intptr_t try_index, |
| 685 Token::Kind kind, | 694 Token::Kind kind, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 698 intptr_t try_index() const { return try_index_; } | 707 intptr_t try_index() const { return try_index_; } |
| 699 | 708 |
| 700 // Receiver class id is computed from collected ICData. | 709 // Receiver class id is computed from collected ICData. |
| 701 void set_receiver_class_id(intptr_t value) { receiver_class_id_ = value; } | 710 void set_receiver_class_id(intptr_t value) { receiver_class_id_ = value; } |
| 702 intptr_t receiver_class_id() const { return receiver_class_id_; } | 711 intptr_t receiver_class_id() const { return receiver_class_id_; } |
| 703 | 712 |
| 704 virtual void PrintOperandsTo(BufferFormatter* f) const; | 713 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 705 | 714 |
| 706 virtual bool CanDeoptimize() const { return true; } | 715 virtual bool CanDeoptimize() const { return true; } |
| 707 | 716 |
| 717 virtual intptr_t ResultCid() const { return kBoolCid; } | |
| 718 | |
| 708 private: | 719 private: |
| 709 const intptr_t token_pos_; | 720 const intptr_t token_pos_; |
| 710 const intptr_t try_index_; | 721 const intptr_t try_index_; |
| 711 intptr_t receiver_class_id_; // Set by optimizer. | 722 intptr_t receiver_class_id_; // Set by optimizer. |
| 712 | 723 |
| 713 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp); | 724 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp); |
| 714 }; | 725 }; |
| 715 | 726 |
| 716 | 727 |
| 717 class RelationalOpComp : public ComparisonComp { | 728 class RelationalOpComp : public ComparisonComp { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 738 void set_operands_class_id(intptr_t value) { | 749 void set_operands_class_id(intptr_t value) { |
| 739 operands_class_id_ = value; | 750 operands_class_id_ = value; |
| 740 } | 751 } |
| 741 | 752 |
| 742 intptr_t operands_class_id() const { return operands_class_id_; } | 753 intptr_t operands_class_id() const { return operands_class_id_; } |
| 743 | 754 |
| 744 virtual void PrintOperandsTo(BufferFormatter* f) const; | 755 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 745 | 756 |
| 746 virtual bool CanDeoptimize() const { return true; } | 757 virtual bool CanDeoptimize() const { return true; } |
| 747 | 758 |
| 759 virtual intptr_t ResultCid() const { return kBoolCid; } | |
| 760 | |
| 748 private: | 761 private: |
| 749 const intptr_t token_pos_; | 762 const intptr_t token_pos_; |
| 750 const intptr_t try_index_; | 763 const intptr_t try_index_; |
| 751 intptr_t operands_class_id_; // class id of both operands. | 764 intptr_t operands_class_id_; // class id of both operands. |
| 752 | 765 |
| 753 DISALLOW_COPY_AND_ASSIGN(RelationalOpComp); | 766 DISALLOW_COPY_AND_ASSIGN(RelationalOpComp); |
| 754 }; | 767 }; |
| 755 | 768 |
| 756 | 769 |
| 757 class StaticCallComp : public TemplateComputation<0> { | 770 class StaticCallComp : public TemplateComputation<0> { |
| (...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2348 }; | 2361 }; |
| 2349 | 2362 |
| 2350 | 2363 |
| 2351 // Abstract super-class of all instructions that define a value (Bind, Phi). | 2364 // Abstract super-class of all instructions that define a value (Bind, Phi). |
| 2352 class Definition : public Instruction { | 2365 class Definition : public Instruction { |
| 2353 public: | 2366 public: |
| 2354 Definition() | 2367 Definition() |
| 2355 : temp_index_(-1), | 2368 : temp_index_(-1), |
| 2356 ssa_temp_index_(-1), | 2369 ssa_temp_index_(-1), |
| 2357 propagated_type_(AbstractType::Handle()), | 2370 propagated_type_(AbstractType::Handle()), |
| 2371 propagated_cid_(kIllegalCid), | |
| 2358 use_list_(NULL) { } | 2372 use_list_(NULL) { } |
| 2359 | 2373 |
| 2360 virtual bool IsDefinition() const { return true; } | 2374 virtual bool IsDefinition() const { return true; } |
| 2361 virtual Definition* AsDefinition() { return this; } | 2375 virtual Definition* AsDefinition() { return this; } |
| 2362 | 2376 |
| 2363 intptr_t temp_index() const { return temp_index_; } | 2377 intptr_t temp_index() const { return temp_index_; } |
| 2364 void set_temp_index(intptr_t index) { temp_index_ = index; } | 2378 void set_temp_index(intptr_t index) { temp_index_ = index; } |
| 2365 | 2379 |
| 2366 intptr_t ssa_temp_index() const { return ssa_temp_index_; } | 2380 intptr_t ssa_temp_index() const { return ssa_temp_index_; } |
| 2367 void set_ssa_temp_index(intptr_t index) { | 2381 void set_ssa_temp_index(intptr_t index) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2386 if (propagated_type.IsNull()) { | 2400 if (propagated_type.IsNull()) { |
| 2387 // Not a typed definition, e.g. access to a VM field. | 2401 // Not a typed definition, e.g. access to a VM field. |
| 2388 return false; | 2402 return false; |
| 2389 } | 2403 } |
| 2390 const bool changed = | 2404 const bool changed = |
| 2391 propagated_type_.IsNull() || !propagated_type.Equals(propagated_type_); | 2405 propagated_type_.IsNull() || !propagated_type.Equals(propagated_type_); |
| 2392 propagated_type_ = propagated_type.raw(); | 2406 propagated_type_ = propagated_type.raw(); |
| 2393 return changed; | 2407 return changed; |
| 2394 } | 2408 } |
| 2395 | 2409 |
| 2410 bool has_propagated_cid() const { return propagated_cid_ != kIllegalCid; } | |
| 2411 intptr_t propagated_cid() const { return propagated_cid_; } | |
| 2412 | |
| 2413 // Returns true if the propagated cid has changed. | |
| 2414 // Merges the cids: | |
| 2415 // - overwrite if not set before. | |
| 2416 // - if cid-s differ set to kDynamicCid. | |
| 2417 bool SetPropagatedCid(intptr_t cid) { | |
|
regis
2012/08/15 22:46:54
I see now that you are not just setting the propag
srdjan
2012/08/16 00:34:46
Moved the merge logic out.
| |
| 2418 ASSERT(cid != 1); | |
| 2419 ASSERT(cid != kIllegalCid); | |
| 2420 if (propagated_cid_ == kDynamicCid) { | |
| 2421 return false; | |
| 2422 } | |
| 2423 if (propagated_cid_ == kIllegalCid) { | |
| 2424 propagated_cid_ = cid; | |
| 2425 return true; | |
| 2426 } | |
| 2427 if (propagated_cid_ != cid) { | |
| 2428 propagated_cid_ = kDynamicCid; | |
| 2429 return true; | |
| 2430 } | |
| 2431 return false; | |
| 2432 } | |
| 2433 | |
| 2396 UseVal* use_list() { return use_list_; } | 2434 UseVal* use_list() { return use_list_; } |
| 2397 void set_use_list(UseVal* head) { | 2435 void set_use_list(UseVal* head) { |
| 2398 ASSERT(head == NULL || head->previous_use() == NULL); | 2436 ASSERT(head == NULL || head->previous_use() == NULL); |
| 2399 use_list_ = head; | 2437 use_list_ = head; |
| 2400 } | 2438 } |
| 2401 | 2439 |
| 2402 void ReplaceUsesWith(Definition* other); | 2440 void ReplaceUsesWith(Definition* other); |
| 2403 | 2441 |
| 2404 private: | 2442 private: |
| 2405 intptr_t temp_index_; | 2443 intptr_t temp_index_; |
| 2406 intptr_t ssa_temp_index_; | 2444 intptr_t ssa_temp_index_; |
| 2407 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_; | 2445 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_; |
| 2408 // For now: | 2446 // For now: |
| 2409 AbstractType& propagated_type_; | 2447 AbstractType& propagated_type_; |
| 2448 intptr_t propagated_cid_; | |
| 2410 UseVal* use_list_; | 2449 UseVal* use_list_; |
| 2411 | 2450 |
| 2412 DISALLOW_COPY_AND_ASSIGN(Definition); | 2451 DISALLOW_COPY_AND_ASSIGN(Definition); |
| 2413 }; | 2452 }; |
| 2414 | 2453 |
| 2415 | 2454 |
| 2416 Definition* UseVal::definition() const { | 2455 Definition* UseVal::definition() const { |
| 2417 // Check that the definition is either a Phi or a linked in the the IR. | 2456 // Check that the definition is either a Phi or a linked in the the IR. |
| 2418 ASSERT(definition_ != NULL); | 2457 ASSERT(definition_ != NULL); |
| 2419 return definition_; | 2458 return definition_; |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2905 const GrowableArray<BlockEntryInstr*>& block_order_; | 2944 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2906 | 2945 |
| 2907 private: | 2946 private: |
| 2908 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2947 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2909 }; | 2948 }; |
| 2910 | 2949 |
| 2911 | 2950 |
| 2912 } // namespace dart | 2951 } // namespace dart |
| 2913 | 2952 |
| 2914 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2953 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |