Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 14057004: Convert diamond shaped control flow into a single conditional instruction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address Florian's comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 M(UnboxInteger) \ 492 M(UnboxInteger) \
493 M(BoxInteger) \ 493 M(BoxInteger) \
494 M(BinaryMintOp) \ 494 M(BinaryMintOp) \
495 M(ShiftMintOp) \ 495 M(ShiftMintOp) \
496 M(UnaryMintOp) \ 496 M(UnaryMintOp) \
497 M(CheckArrayBound) \ 497 M(CheckArrayBound) \
498 M(Constraint) \ 498 M(Constraint) \
499 M(StringFromCharCode) \ 499 M(StringFromCharCode) \
500 M(InvokeMathCFunction) \ 500 M(InvokeMathCFunction) \
501 M(GuardField) \ 501 M(GuardField) \
502 502 M(IfThenElse) \
503 503
504 #define FORWARD_DECLARATION(type) class type##Instr; 504 #define FORWARD_DECLARATION(type) class type##Instr;
505 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) 505 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION)
506 #undef FORWARD_DECLARATION 506 #undef FORWARD_DECLARATION
507 507
508 508
509 // Functions required in all concrete instruction classes. 509 // Functions required in all concrete instruction classes.
510 #define DECLARE_INSTRUCTION(type) \ 510 #define DECLARE_INSTRUCTION(type) \
511 virtual Tag tag() const { return k##type; } \ 511 virtual Tag tag() const { return k##type; } \
512 virtual void Accept(FlowGraphVisitor* visitor); \ 512 virtual void Accept(FlowGraphVisitor* visitor); \
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 994
995 virtual BlockEntryInstr* GetBlock() const { 995 virtual BlockEntryInstr* GetBlock() const {
996 return const_cast<BlockEntryInstr*>(this); 996 return const_cast<BlockEntryInstr*>(this);
997 } 997 }
998 998
999 // Helper to mutate the graph during inlining. This block should be 999 // Helper to mutate the graph during inlining. This block should be
1000 // replaced with new_block as a predecessor of all of this block's 1000 // replaced with new_block as a predecessor of all of this block's
1001 // successors. 1001 // successors.
1002 void ReplaceAsPredecessorWith(BlockEntryInstr* new_block); 1002 void ReplaceAsPredecessorWith(BlockEntryInstr* new_block);
1003 1003
1004 void set_block_id(intptr_t block_id) { block_id_ = block_id; }
1005
1004 protected: 1006 protected:
1005 BlockEntryInstr(intptr_t block_id, intptr_t try_index) 1007 BlockEntryInstr(intptr_t block_id, intptr_t try_index)
1006 : block_id_(block_id), 1008 : block_id_(block_id),
1007 try_index_(try_index), 1009 try_index_(try_index),
1008 preorder_number_(-1), 1010 preorder_number_(-1),
1009 postorder_number_(-1), 1011 postorder_number_(-1),
1010 dominator_(NULL), 1012 dominator_(NULL),
1011 dominated_blocks_(1), 1013 dominated_blocks_(1),
1012 last_instruction_(NULL), 1014 last_instruction_(NULL),
1013 parallel_move_(NULL), 1015 parallel_move_(NULL),
1014 loop_info_(NULL) { } 1016 loop_info_(NULL) { }
1015 1017
1016 private: 1018 private:
1017 virtual void RawSetInputAt(intptr_t i, Value* value) { UNREACHABLE(); } 1019 virtual void RawSetInputAt(intptr_t i, Value* value) { UNREACHABLE(); }
1018 1020
1019 virtual void ClearPredecessors() = 0; 1021 virtual void ClearPredecessors() = 0;
1020 virtual void AddPredecessor(BlockEntryInstr* predecessor) = 0; 1022 virtual void AddPredecessor(BlockEntryInstr* predecessor) = 0;
1021 1023
1022 const intptr_t block_id_; 1024 intptr_t block_id_;
1023 const intptr_t try_index_; 1025 const intptr_t try_index_;
1024 intptr_t preorder_number_; 1026 intptr_t preorder_number_;
1025 intptr_t postorder_number_; 1027 intptr_t postorder_number_;
1026 // Starting and ending lifetime positions for this block. Used by 1028 // Starting and ending lifetime positions for this block. Used by
1027 // the linear scan register allocator. 1029 // the linear scan register allocator.
1028 intptr_t start_pos_; 1030 intptr_t start_pos_;
1029 intptr_t end_pos_; 1031 intptr_t end_pos_;
1030 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry. 1032 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry.
1031 // TODO(fschneider): Optimize the case of one child to save space. 1033 // TODO(fschneider): Optimize the case of one child to save space.
1032 GrowableArray<BlockEntryInstr*> dominated_blocks_; 1034 GrowableArray<BlockEntryInstr*> dominated_blocks_;
(...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 2672
2671 private: 2673 private:
2672 const ICData* ic_data_; 2674 const ICData* ic_data_;
2673 const intptr_t token_pos_; 2675 const intptr_t token_pos_;
2674 intptr_t operands_class_id_; // class id of both operands. 2676 intptr_t operands_class_id_; // class id of both operands.
2675 2677
2676 DISALLOW_COPY_AND_ASSIGN(RelationalOpInstr); 2678 DISALLOW_COPY_AND_ASSIGN(RelationalOpInstr);
2677 }; 2679 };
2678 2680
2679 2681
2682 // TODO(vegorov): ComparisonInstr should be switched to use IfTheElseInstr for
2683 // materialization of true and false constants.
2684 class IfThenElseInstr : public TemplateDefinition<2> {
2685 public:
2686 IfThenElseInstr(Token::Kind kind,
2687 Value* left,
2688 Value* right,
2689 Value* if_true,
2690 Value* if_false)
2691 : kind_(kind),
2692 if_true_(Smi::Cast(if_true->BoundConstant()).Value()),
2693 if_false_(Smi::Cast(if_false->BoundConstant()).Value()) {
2694 ASSERT(Token::IsEqualityOperator(kind));
2695 SetInputAt(0, left);
2696 SetInputAt(1, right);
2697 }
2698
2699 // Returns true if this instruction is supported on the current platform.
2700 static bool IsSupported();
2701
2702 // Returns true if this combination of comparison and values flowing on
2703 // the true and false paths is supported on the current platform.
2704 static bool Supports(ComparisonInstr* comparison, Value* v1, Value* v2);
2705
2706 DECLARE_INSTRUCTION(IfThenElse)
2707
2708 virtual void PrintOperandsTo(BufferFormatter* f) const;
2709
2710 virtual CompileType ComputeType() const;
2711
2712 virtual void InferRange();
2713
2714 virtual bool CanDeoptimize() const { return false; }
2715 virtual bool HasSideEffect() const { return false; }
2716
2717 virtual bool AttributesEqual(Instruction* other) const {
2718 return kind_ == other->AsIfThenElse()->kind_;
2719 }
2720
2721 virtual bool AffectedBySideEffect() const {
2722 return false;
2723 }
2724
2725 Value* left() const { return inputs_[0]; }
2726 Value* right() const { return inputs_[1]; }
2727 intptr_t if_true() const { return if_true_; }
2728 intptr_t if_false() const { return if_false_; }
2729
2730 Token::Kind kind() const { return kind_; }
2731
2732 private:
2733 const Token::Kind kind_;
2734 const intptr_t if_true_;
2735 const intptr_t if_false_;
2736
2737 DISALLOW_COPY_AND_ASSIGN(IfThenElseInstr);
2738 };
2739
2740
2680 class StaticCallInstr : public TemplateDefinition<0> { 2741 class StaticCallInstr : public TemplateDefinition<0> {
2681 public: 2742 public:
2682 StaticCallInstr(intptr_t token_pos, 2743 StaticCallInstr(intptr_t token_pos,
2683 const Function& function, 2744 const Function& function,
2684 const Array& argument_names, 2745 const Array& argument_names,
2685 ZoneGrowableArray<PushArgumentInstr*>* arguments) 2746 ZoneGrowableArray<PushArgumentInstr*>* arguments)
2686 : token_pos_(token_pos), 2747 : token_pos_(token_pos),
2687 function_(function), 2748 function_(function),
2688 argument_names_(argument_names), 2749 argument_names_(argument_names),
2689 arguments_(arguments), 2750 arguments_(arguments),
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after
4697 ForwardInstructionIterator* current_iterator_; 4758 ForwardInstructionIterator* current_iterator_;
4698 4759
4699 private: 4760 private:
4700 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 4761 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
4701 }; 4762 };
4702 4763
4703 4764
4704 } // namespace dart 4765 } // namespace dart
4705 4766
4706 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 4767 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698