| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 class BindInstr; | 110 class BindInstr; |
| 111 class BranchInstr; | 111 class BranchInstr; |
| 112 class BufferFormatter; | 112 class BufferFormatter; |
| 113 class ComparisonComp; | 113 class ComparisonComp; |
| 114 class Instruction; | 114 class Instruction; |
| 115 class PushArgumentInstr; | 115 class PushArgumentInstr; |
| 116 class Value; | 116 class Value; |
| 117 | 117 |
| 118 class Computation : public ZoneAllocated { | 118 class Computation : public ZoneAllocated { |
| 119 public: | 119 public: |
| 120 static const intptr_t kNoCid = -1; | 120 Computation() : deopt_id_(Isolate::kNoDeoptId), ic_data_(NULL), locs_(NULL) { |
| 121 | |
| 122 Computation() : cid_(kNoCid), ic_data_(NULL), locs_(NULL) { | |
| 123 Isolate* isolate = Isolate::Current(); | 121 Isolate* isolate = Isolate::Current(); |
| 124 cid_ = isolate->GetNextCid(); | 122 deopt_id_ = isolate->GetNextDeoptId(); |
| 125 ic_data_ = isolate->GetICDataForCid(cid_); | 123 ic_data_ = isolate->GetICDataForDeoptId(deopt_id_); |
| 126 } | 124 } |
| 127 | 125 |
| 128 // Unique computation/instruction id, used for deoptimization. | 126 // Unique id used for deoptimization. |
| 129 intptr_t cid() const { return cid_; } | 127 intptr_t deopt_id() const { return deopt_id_; } |
| 130 | 128 |
| 131 ICData* ic_data() const { return ic_data_; } | 129 ICData* ic_data() const { return ic_data_; } |
| 132 void set_ic_data(ICData* value) { ic_data_ = value; } | 130 void set_ic_data(ICData* value) { ic_data_ = value; } |
| 133 bool HasICData() const { | 131 bool HasICData() const { |
| 134 return (ic_data() != NULL) && !ic_data()->IsNull(); | 132 return (ic_data() != NULL) && !ic_data()->IsNull(); |
| 135 } | 133 } |
| 136 | 134 |
| 137 // Visiting support. | 135 // Visiting support. |
| 138 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr) = 0; | 136 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr) = 0; |
| 139 | 137 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 195 |
| 198 // Declare predicate for each computation. | 196 // Declare predicate for each computation. |
| 199 #define DECLARE_PREDICATE(ShortName, ClassName) \ | 197 #define DECLARE_PREDICATE(ShortName, ClassName) \ |
| 200 inline bool Is##ShortName() const; \ | 198 inline bool Is##ShortName() const; \ |
| 201 inline const ClassName* As##ShortName() const; \ | 199 inline const ClassName* As##ShortName() const; \ |
| 202 inline ClassName* As##ShortName(); | 200 inline ClassName* As##ShortName(); |
| 203 FOR_EACH_COMPUTATION(DECLARE_PREDICATE) | 201 FOR_EACH_COMPUTATION(DECLARE_PREDICATE) |
| 204 #undef DECLARE_PREDICATE | 202 #undef DECLARE_PREDICATE |
| 205 | 203 |
| 206 private: | 204 private: |
| 207 intptr_t cid_; | 205 intptr_t deopt_id_; |
| 208 ICData* ic_data_; | 206 ICData* ic_data_; |
| 209 LocationSummary* locs_; | 207 LocationSummary* locs_; |
| 210 | 208 |
| 211 DISALLOW_COPY_AND_ASSIGN(Computation); | 209 DISALLOW_COPY_AND_ASSIGN(Computation); |
| 212 }; | 210 }; |
| 213 | 211 |
| 214 | 212 |
| 215 // An embedded container with N elements of type T. Used (with partial | 213 // An embedded container with N elements of type T. Used (with partial |
| 216 // specialization for N=0) because embedded arrays cannot have size 0. | 214 // specialization for N=0) because embedded arrays cannot have size 0. |
| 217 template<typename T, intptr_t N> | 215 template<typename T, intptr_t N> |
| (...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2434 Value* value_; | 2432 Value* value_; |
| 2435 | 2433 |
| 2436 DISALLOW_COPY_AND_ASSIGN(PushArgumentInstr); | 2434 DISALLOW_COPY_AND_ASSIGN(PushArgumentInstr); |
| 2437 }; | 2435 }; |
| 2438 | 2436 |
| 2439 | 2437 |
| 2440 class ReturnInstr : public InstructionWithInputs { | 2438 class ReturnInstr : public InstructionWithInputs { |
| 2441 public: | 2439 public: |
| 2442 ReturnInstr(intptr_t token_pos, Value* value) | 2440 ReturnInstr(intptr_t token_pos, Value* value) |
| 2443 : InstructionWithInputs(), | 2441 : InstructionWithInputs(), |
| 2444 cid_(Isolate::Current()->GetNextCid()), | 2442 deopt_id_(Isolate::Current()->GetNextDeoptId()), |
| 2445 token_pos_(token_pos), | 2443 token_pos_(token_pos), |
| 2446 value_(value) { | 2444 value_(value) { |
| 2447 ASSERT(value_ != NULL); | 2445 ASSERT(value_ != NULL); |
| 2448 } | 2446 } |
| 2449 | 2447 |
| 2450 DECLARE_INSTRUCTION(Return) | 2448 DECLARE_INSTRUCTION(Return) |
| 2451 | 2449 |
| 2452 virtual intptr_t ArgumentCount() const { return 0; } | 2450 virtual intptr_t ArgumentCount() const { return 0; } |
| 2453 | 2451 |
| 2454 intptr_t cid() const { return cid_; } | 2452 intptr_t deopt_id() const { return deopt_id_; } |
| 2455 intptr_t token_pos() const { return token_pos_; } | 2453 intptr_t token_pos() const { return token_pos_; } |
| 2456 Value* value() const { return value_; } | 2454 Value* value() const { return value_; } |
| 2457 | 2455 |
| 2458 virtual LocationSummary* MakeLocationSummary() const; | 2456 virtual LocationSummary* MakeLocationSummary() const; |
| 2459 | 2457 |
| 2460 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 2458 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 2461 | 2459 |
| 2462 virtual bool CanDeoptimize() const { return false; } | 2460 virtual bool CanDeoptimize() const { return false; } |
| 2463 | 2461 |
| 2464 private: | 2462 private: |
| 2465 const intptr_t cid_; // Computation/instruction id. | 2463 const intptr_t deopt_id_; |
| 2466 const intptr_t token_pos_; | 2464 const intptr_t token_pos_; |
| 2467 Value* value_; | 2465 Value* value_; |
| 2468 | 2466 |
| 2469 DISALLOW_COPY_AND_ASSIGN(ReturnInstr); | 2467 DISALLOW_COPY_AND_ASSIGN(ReturnInstr); |
| 2470 }; | 2468 }; |
| 2471 | 2469 |
| 2472 | 2470 |
| 2473 class ThrowInstr : public InstructionWithInputs { | 2471 class ThrowInstr : public InstructionWithInputs { |
| 2474 public: | 2472 public: |
| 2475 ThrowInstr(intptr_t token_pos, intptr_t try_index) | 2473 ThrowInstr(intptr_t token_pos, intptr_t try_index) |
| 2476 : InstructionWithInputs(), | 2474 : InstructionWithInputs(), |
| 2477 cid_(Isolate::Current()->GetNextCid()), | 2475 deopt_id_(Isolate::Current()->GetNextDeoptId()), |
| 2478 token_pos_(token_pos), | 2476 token_pos_(token_pos), |
| 2479 try_index_(try_index) { } | 2477 try_index_(try_index) { } |
| 2480 | 2478 |
| 2481 DECLARE_CALL_INSTRUCTION(Throw) | 2479 DECLARE_CALL_INSTRUCTION(Throw) |
| 2482 | 2480 |
| 2483 virtual intptr_t ArgumentCount() const { return 1; } | 2481 virtual intptr_t ArgumentCount() const { return 1; } |
| 2484 | 2482 |
| 2485 intptr_t cid() const { return cid_; } | 2483 intptr_t deopt_id() const { return deopt_id_; } |
| 2486 intptr_t token_pos() const { return token_pos_; } | 2484 intptr_t token_pos() const { return token_pos_; } |
| 2487 intptr_t try_index() const { return try_index_; } | 2485 intptr_t try_index() const { return try_index_; } |
| 2488 | 2486 |
| 2489 virtual LocationSummary* MakeLocationSummary() const; | 2487 virtual LocationSummary* MakeLocationSummary() const; |
| 2490 | 2488 |
| 2491 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 2489 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 2492 | 2490 |
| 2493 virtual bool CanDeoptimize() const { return false; } | 2491 virtual bool CanDeoptimize() const { return false; } |
| 2494 | 2492 |
| 2495 private: | 2493 private: |
| 2496 const intptr_t cid_; // Computation/instruction id. | 2494 const intptr_t deopt_id_; |
| 2497 const intptr_t token_pos_; | 2495 const intptr_t token_pos_; |
| 2498 const intptr_t try_index_; | 2496 const intptr_t try_index_; |
| 2499 | 2497 |
| 2500 DISALLOW_COPY_AND_ASSIGN(ThrowInstr); | 2498 DISALLOW_COPY_AND_ASSIGN(ThrowInstr); |
| 2501 }; | 2499 }; |
| 2502 | 2500 |
| 2503 | 2501 |
| 2504 class ReThrowInstr : public InstructionWithInputs { | 2502 class ReThrowInstr : public InstructionWithInputs { |
| 2505 public: | 2503 public: |
| 2506 ReThrowInstr(intptr_t token_pos, | 2504 ReThrowInstr(intptr_t token_pos, |
| 2507 intptr_t try_index) | 2505 intptr_t try_index) |
| 2508 : InstructionWithInputs(), | 2506 : InstructionWithInputs(), |
| 2509 cid_(Isolate::Current()->GetNextCid()), | 2507 deopt_id_(Isolate::Current()->GetNextDeoptId()), |
| 2510 token_pos_(token_pos), | 2508 token_pos_(token_pos), |
| 2511 try_index_(try_index) { } | 2509 try_index_(try_index) { } |
| 2512 | 2510 |
| 2513 DECLARE_CALL_INSTRUCTION(ReThrow) | 2511 DECLARE_CALL_INSTRUCTION(ReThrow) |
| 2514 | 2512 |
| 2515 virtual intptr_t ArgumentCount() const { return 2; } | 2513 virtual intptr_t ArgumentCount() const { return 2; } |
| 2516 | 2514 |
| 2517 intptr_t cid() const { return cid_; } | 2515 intptr_t deopt_id() const { return deopt_id_; } |
| 2518 intptr_t token_pos() const { return token_pos_; } | 2516 intptr_t token_pos() const { return token_pos_; } |
| 2519 intptr_t try_index() const { return try_index_; } | 2517 intptr_t try_index() const { return try_index_; } |
| 2520 | 2518 |
| 2521 virtual LocationSummary* MakeLocationSummary() const; | 2519 virtual LocationSummary* MakeLocationSummary() const; |
| 2522 | 2520 |
| 2523 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 2521 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 2524 | 2522 |
| 2525 virtual bool CanDeoptimize() const { return false; } | 2523 virtual bool CanDeoptimize() const { return false; } |
| 2526 | 2524 |
| 2527 private: | 2525 private: |
| 2528 const intptr_t cid_; // Computation/instruction id. | 2526 const intptr_t deopt_id_; |
| 2529 const intptr_t token_pos_; | 2527 const intptr_t token_pos_; |
| 2530 const intptr_t try_index_; | 2528 const intptr_t try_index_; |
| 2531 | 2529 |
| 2532 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); | 2530 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); |
| 2533 }; | 2531 }; |
| 2534 | 2532 |
| 2535 | 2533 |
| 2536 class GotoInstr : public InstructionWithInputs { | 2534 class GotoInstr : public InstructionWithInputs { |
| 2537 public: | 2535 public: |
| 2538 explicit GotoInstr(JoinEntryInstr* entry) | 2536 explicit GotoInstr(JoinEntryInstr* entry) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2580 | 2578 |
| 2581 | 2579 |
| 2582 class BranchInstr : public InstructionWithInputs { | 2580 class BranchInstr : public InstructionWithInputs { |
| 2583 public: | 2581 public: |
| 2584 BranchInstr(intptr_t token_pos, | 2582 BranchInstr(intptr_t token_pos, |
| 2585 intptr_t try_index, | 2583 intptr_t try_index, |
| 2586 Value* left, | 2584 Value* left, |
| 2587 Value* right, | 2585 Value* right, |
| 2588 Token::Kind kind) | 2586 Token::Kind kind) |
| 2589 : InstructionWithInputs(), | 2587 : InstructionWithInputs(), |
| 2590 cid_(Computation::kNoCid), | 2588 deopt_id_(Isolate::kNoDeoptId), |
| 2591 ic_data_(NULL), | 2589 ic_data_(NULL), |
| 2592 token_pos_(token_pos), | 2590 token_pos_(token_pos), |
| 2593 try_index_(try_index), | 2591 try_index_(try_index), |
| 2594 left_(left), | 2592 left_(left), |
| 2595 right_(right), | 2593 right_(right), |
| 2596 kind_(kind), | 2594 kind_(kind), |
| 2597 true_successor_(NULL), | 2595 true_successor_(NULL), |
| 2598 false_successor_(NULL) { | 2596 false_successor_(NULL) { |
| 2599 ASSERT(left_ != NULL); | 2597 ASSERT(left_ != NULL); |
| 2600 ASSERT(right_ != NULL); | 2598 ASSERT(right_ != NULL); |
| 2601 ASSERT(Token::IsEqualityOperator(kind) || | 2599 ASSERT(Token::IsEqualityOperator(kind) || |
| 2602 Token::IsRelationalOperator(kind) || | 2600 Token::IsRelationalOperator(kind) || |
| 2603 Token::IsTypeTestOperator(kind)); | 2601 Token::IsTypeTestOperator(kind)); |
| 2604 Isolate* isolate = Isolate::Current(); | 2602 Isolate* isolate = Isolate::Current(); |
| 2605 cid_ = isolate->GetNextCid(); | 2603 deopt_id_ = isolate->GetNextDeoptId(); |
| 2606 ic_data_ = isolate->GetICDataForCid(cid_); | 2604 ic_data_ = isolate->GetICDataForDeoptId(deopt_id_); |
| 2607 } | 2605 } |
| 2608 | 2606 |
| 2609 DECLARE_INSTRUCTION(Branch) | 2607 DECLARE_INSTRUCTION(Branch) |
| 2610 | 2608 |
| 2611 virtual intptr_t ArgumentCount() const { return 0; } | 2609 virtual intptr_t ArgumentCount() const { return 0; } |
| 2612 | 2610 |
| 2613 Value* left() const { return left_; } | 2611 Value* left() const { return left_; } |
| 2614 Value* right() const { return right_; } | 2612 Value* right() const { return right_; } |
| 2615 Token::Kind kind() const { return kind_; } | 2613 Token::Kind kind() const { return kind_; } |
| 2616 void set_kind(Token::Kind kind) { | 2614 void set_kind(Token::Kind kind) { |
| 2617 ASSERT(Token::IsEqualityOperator(kind) || | 2615 ASSERT(Token::IsEqualityOperator(kind) || |
| 2618 Token::IsRelationalOperator(kind) || | 2616 Token::IsRelationalOperator(kind) || |
| 2619 Token::IsTypeTestOperator(kind)); | 2617 Token::IsTypeTestOperator(kind)); |
| 2620 kind_ = kind; | 2618 kind_ = kind; |
| 2621 } | 2619 } |
| 2622 | 2620 |
| 2623 intptr_t cid() const { return cid_; } | 2621 intptr_t deopt_id() const { return deopt_id_; } |
| 2624 | 2622 |
| 2625 const ICData* ic_data() const { return ic_data_; } | 2623 const ICData* ic_data() const { return ic_data_; } |
| 2626 bool HasICData() const { | 2624 bool HasICData() const { |
| 2627 return (ic_data() != NULL) && !ic_data()->IsNull(); | 2625 return (ic_data() != NULL) && !ic_data()->IsNull(); |
| 2628 } | 2626 } |
| 2629 | 2627 |
| 2630 intptr_t token_pos() const { return token_pos_;} | 2628 intptr_t token_pos() const { return token_pos_;} |
| 2631 intptr_t try_index() const { return try_index_; } | 2629 intptr_t try_index() const { return try_index_; } |
| 2632 | 2630 |
| 2633 TargetEntryInstr* true_successor() const { return true_successor_; } | 2631 TargetEntryInstr* true_successor() const { return true_successor_; } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2651 virtual LocationSummary* MakeLocationSummary() const; | 2649 virtual LocationSummary* MakeLocationSummary() const; |
| 2652 | 2650 |
| 2653 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 2651 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 2654 | 2652 |
| 2655 void EmitBranchOnCondition(FlowGraphCompiler* compiler, | 2653 void EmitBranchOnCondition(FlowGraphCompiler* compiler, |
| 2656 Condition true_condition); | 2654 Condition true_condition); |
| 2657 | 2655 |
| 2658 virtual bool CanDeoptimize() const { return true; } | 2656 virtual bool CanDeoptimize() const { return true; } |
| 2659 | 2657 |
| 2660 private: | 2658 private: |
| 2661 intptr_t cid_; // Computation/instruction id. | 2659 intptr_t deopt_id_; |
| 2662 ICData* ic_data_; | 2660 ICData* ic_data_; |
| 2663 const intptr_t token_pos_; | 2661 const intptr_t token_pos_; |
| 2664 const intptr_t try_index_; | 2662 const intptr_t try_index_; |
| 2665 Value* left_; | 2663 Value* left_; |
| 2666 Value* right_; | 2664 Value* right_; |
| 2667 Token::Kind kind_; | 2665 Token::Kind kind_; |
| 2668 TargetEntryInstr* true_successor_; | 2666 TargetEntryInstr* true_successor_; |
| 2669 TargetEntryInstr* false_successor_; | 2667 TargetEntryInstr* false_successor_; |
| 2670 | 2668 |
| 2671 DISALLOW_COPY_AND_ASSIGN(BranchInstr); | 2669 DISALLOW_COPY_AND_ASSIGN(BranchInstr); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2755 const GrowableArray<BlockEntryInstr*>& block_order_; | 2753 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2756 | 2754 |
| 2757 private: | 2755 private: |
| 2758 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2756 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2759 }; | 2757 }; |
| 2760 | 2758 |
| 2761 | 2759 |
| 2762 } // namespace dart | 2760 } // namespace dart |
| 2763 | 2761 |
| 2764 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2762 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |