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 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1983 // concatenated. | 1983 // concatenated. |
| 1984 #define FOR_EACH_INSTRUCTION(M) \ | 1984 #define FOR_EACH_INSTRUCTION(M) \ |
| 1985 M(GraphEntry) \ | 1985 M(GraphEntry) \ |
| 1986 M(JoinEntry) \ | 1986 M(JoinEntry) \ |
| 1987 M(TargetEntry) \ | 1987 M(TargetEntry) \ |
| 1988 M(Phi) \ | 1988 M(Phi) \ |
| 1989 M(Bind) \ | 1989 M(Bind) \ |
| 1990 M(Parameter) \ | 1990 M(Parameter) \ |
| 1991 M(ParallelMove) \ | 1991 M(ParallelMove) \ |
| 1992 M(PushArgument) \ | 1992 M(PushArgument) \ |
| 1993 M(Return) \ | 1993 M(Return) \ |
|
Kevin Millikin (Google)
2012/08/24 12:37:26
Return, Throw, ReThrow, and Goto should also becom
| |
| 1994 M(Throw) \ | 1994 M(Throw) \ |
| 1995 M(ReThrow) \ | 1995 M(ReThrow) \ |
| 1996 M(Goto) \ | 1996 M(Goto) \ |
| 1997 M(Branch) \ | 1997 M(Branch) \ |
| 1998 M(StrictCompareAndBranch) | |
| 1998 | 1999 |
| 1999 | 2000 |
| 2000 // Forward declarations for Instruction classes. | 2001 // Forward declarations for Instruction classes. |
| 2001 class BlockEntryInstr; | 2002 class BlockEntryInstr; |
| 2002 class FlowGraphBuilder; | 2003 class FlowGraphBuilder; |
| 2003 class Environment; | 2004 class Environment; |
| 2004 | 2005 |
| 2005 #define FORWARD_DECLARATION(type) class type##Instr; | 2006 #define FORWARD_DECLARATION(type) class type##Instr; |
| 2006 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) | 2007 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 2007 #undef FORWARD_DECLARATION | 2008 #undef FORWARD_DECLARATION |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2949 | 2950 |
| 2950 private: | 2951 private: |
| 2951 JoinEntryInstr* successor_; | 2952 JoinEntryInstr* successor_; |
| 2952 | 2953 |
| 2953 // Parallel move that will be used by linear scan register allocator to | 2954 // Parallel move that will be used by linear scan register allocator to |
| 2954 // connect live ranges at the end of the block and resolve phis. | 2955 // connect live ranges at the end of the block and resolve phis. |
| 2955 ParallelMoveInstr* parallel_move_; | 2956 ParallelMoveInstr* parallel_move_; |
| 2956 }; | 2957 }; |
| 2957 | 2958 |
| 2958 | 2959 |
| 2959 class BranchInstr : public TemplateInstruction<2> { | 2960 class ControlInstruction : public Instruction { |
| 2961 public: | |
| 2962 ControlInstruction() : true_successor_(NULL), false_successor_(NULL) { } | |
| 2963 | |
| 2964 TargetEntryInstr* true_successor() const { return true_successor_; } | |
| 2965 TargetEntryInstr* false_successor() const { return false_successor_; } | |
| 2966 | |
| 2967 TargetEntryInstr** true_successor_address() { return &true_successor_; } | |
| 2968 TargetEntryInstr** false_successor_address() { return &false_successor_; } | |
| 2969 | |
| 2970 virtual intptr_t SuccessorCount() const; | |
| 2971 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | |
| 2972 | |
| 2973 virtual void DiscoverBlocks( | |
| 2974 BlockEntryInstr* current_block, | |
| 2975 GrowableArray<BlockEntryInstr*>* preorder, | |
| 2976 GrowableArray<BlockEntryInstr*>* postorder, | |
| 2977 GrowableArray<intptr_t>* parent, | |
| 2978 GrowableArray<BitVector*>* assigned_vars, | |
| 2979 intptr_t variable_count, | |
| 2980 intptr_t fixed_parameter_count); | |
| 2981 | |
| 2982 | |
| 2983 void EmitBranchOnCondition(FlowGraphCompiler* compiler, | |
| 2984 Condition true_condition); | |
| 2985 | |
| 2986 private: | |
| 2987 TargetEntryInstr* true_successor_; | |
| 2988 TargetEntryInstr* false_successor_; | |
| 2989 | |
| 2990 DISALLOW_COPY_AND_ASSIGN(ControlInstruction); | |
| 2991 }; | |
| 2992 | |
| 2993 | |
| 2994 template<intptr_t N> | |
| 2995 class TemplateControlInstruction: public ControlInstruction { | |
| 2996 public: | |
| 2997 TemplateControlInstruction<N>() : locs_(NULL) { } | |
| 2998 | |
| 2999 virtual intptr_t InputCount() const { return N; } | |
| 3000 virtual Value* InputAt(intptr_t i) const { return inputs_[i]; } | |
| 3001 virtual void SetInputAt(intptr_t i, Value* value) { | |
| 3002 ASSERT(value != NULL); | |
| 3003 inputs_[i] = value; | |
| 3004 } | |
| 3005 | |
| 3006 virtual LocationSummary* locs() { | |
| 3007 if (locs_ == NULL) { | |
| 3008 locs_ = MakeLocationSummary(); | |
| 3009 } | |
| 3010 return locs_; | |
| 3011 } | |
| 3012 | |
| 3013 virtual LocationSummary* MakeLocationSummary() const = 0; | |
| 3014 | |
| 3015 protected: | |
| 3016 EmbeddedArray<Value*, N> inputs_; | |
| 3017 | |
| 3018 private: | |
| 3019 LocationSummary* locs_; | |
| 3020 }; | |
| 3021 | |
| 3022 | |
| 3023 class BranchInstr : public TemplateControlInstruction<2> { | |
| 2960 public: | 3024 public: |
| 2961 BranchInstr(intptr_t token_pos, | 3025 BranchInstr(intptr_t token_pos, |
| 2962 intptr_t try_index, | 3026 intptr_t try_index, |
| 2963 Value* left, | 3027 Value* left, |
| 2964 Value* right, | 3028 Value* right, |
| 2965 Token::Kind kind) | 3029 Token::Kind kind) |
| 2966 : deopt_id_(Isolate::kNoDeoptId), | 3030 : deopt_id_(Isolate::kNoDeoptId), |
| 2967 ic_data_(NULL), | 3031 ic_data_(NULL), |
| 2968 token_pos_(token_pos), | 3032 token_pos_(token_pos), |
| 2969 try_index_(try_index), | 3033 try_index_(try_index), |
| 2970 kind_(kind), | 3034 kind_(kind) { |
| 2971 true_successor_(NULL), | |
| 2972 false_successor_(NULL) { | |
| 2973 ASSERT(left != NULL); | 3035 ASSERT(left != NULL); |
| 2974 ASSERT(right != NULL); | 3036 ASSERT(right != NULL); |
| 2975 inputs_[0] = left; | 3037 inputs_[0] = left; |
| 2976 inputs_[1] = right; | 3038 inputs_[1] = right; |
| 3039 ASSERT(!Token::IsStrictEqualityOperator(kind)); | |
| 2977 ASSERT(Token::IsEqualityOperator(kind) || | 3040 ASSERT(Token::IsEqualityOperator(kind) || |
| 2978 Token::IsRelationalOperator(kind) || | 3041 Token::IsRelationalOperator(kind) || |
| 2979 Token::IsTypeTestOperator(kind)); | 3042 Token::IsTypeTestOperator(kind)); |
| 2980 Isolate* isolate = Isolate::Current(); | 3043 Isolate* isolate = Isolate::Current(); |
| 2981 deopt_id_ = isolate->GetNextDeoptId(); | 3044 deopt_id_ = isolate->GetNextDeoptId(); |
| 2982 ic_data_ = isolate->GetICDataForDeoptId(deopt_id_); | 3045 ic_data_ = isolate->GetICDataForDeoptId(deopt_id_); |
| 2983 } | 3046 } |
| 2984 | 3047 |
| 2985 DECLARE_INSTRUCTION(Branch) | 3048 DECLARE_INSTRUCTION(Branch) |
| 2986 | 3049 |
| 3050 Value* left() const { return inputs_[0]; } | |
| 3051 Value* right() const { return inputs_[1]; } | |
| 3052 | |
| 2987 virtual intptr_t ArgumentCount() const { return 0; } | 3053 virtual intptr_t ArgumentCount() const { return 0; } |
| 2988 | 3054 |
| 2989 Value* left() const { return inputs_[0]; } | |
| 2990 Value* right() const { return inputs_[1]; } | |
| 2991 Token::Kind kind() const { return kind_; } | 3055 Token::Kind kind() const { return kind_; } |
| 2992 void set_kind(Token::Kind kind) { | 3056 void set_kind(Token::Kind kind) { |
| 3057 ASSERT(!Token::IsStrictEqualityOperator(kind)); | |
| 2993 ASSERT(Token::IsEqualityOperator(kind) || | 3058 ASSERT(Token::IsEqualityOperator(kind) || |
| 2994 Token::IsRelationalOperator(kind) || | 3059 Token::IsRelationalOperator(kind) || |
| 2995 Token::IsTypeTestOperator(kind)); | 3060 Token::IsTypeTestOperator(kind)); |
| 2996 kind_ = kind; | 3061 kind_ = kind; |
| 2997 } | 3062 } |
| 2998 | 3063 |
| 2999 intptr_t deopt_id() const { return deopt_id_; } | 3064 intptr_t deopt_id() const { return deopt_id_; } |
| 3000 | 3065 |
| 3001 const ICData* ic_data() const { return ic_data_; } | 3066 const ICData* ic_data() const { return ic_data_; } |
| 3002 bool HasICData() const { | 3067 bool HasICData() const { |
| 3003 return (ic_data() != NULL) && !ic_data()->IsNull(); | 3068 return (ic_data() != NULL) && !ic_data()->IsNull(); |
| 3004 } | 3069 } |
| 3005 | 3070 |
| 3006 intptr_t token_pos() const { return token_pos_;} | 3071 intptr_t token_pos() const { return token_pos_;} |
| 3007 intptr_t try_index() const { return try_index_; } | 3072 intptr_t try_index() const { return try_index_; } |
| 3008 | 3073 |
| 3009 TargetEntryInstr* true_successor() const { return true_successor_; } | |
| 3010 TargetEntryInstr* false_successor() const { return false_successor_; } | |
| 3011 | |
| 3012 TargetEntryInstr** true_successor_address() { return &true_successor_; } | |
| 3013 TargetEntryInstr** false_successor_address() { return &false_successor_; } | |
| 3014 | |
| 3015 virtual intptr_t SuccessorCount() const; | |
| 3016 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | |
| 3017 | |
| 3018 virtual void DiscoverBlocks( | |
| 3019 BlockEntryInstr* current_block, | |
| 3020 GrowableArray<BlockEntryInstr*>* preorder, | |
| 3021 GrowableArray<BlockEntryInstr*>* postorder, | |
| 3022 GrowableArray<intptr_t>* parent, | |
| 3023 GrowableArray<BitVector*>* assigned_vars, | |
| 3024 intptr_t variable_count, | |
| 3025 intptr_t fixed_parameter_count); | |
| 3026 | |
| 3027 virtual LocationSummary* MakeLocationSummary() const; | 3074 virtual LocationSummary* MakeLocationSummary() const; |
| 3028 | 3075 |
| 3029 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 3076 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 3030 | 3077 |
| 3031 void EmitBranchOnCondition(FlowGraphCompiler* compiler, | |
| 3032 Condition true_condition); | |
| 3033 | |
| 3034 virtual bool CanDeoptimize() const { return true; } | 3078 virtual bool CanDeoptimize() const { return true; } |
| 3035 | 3079 |
| 3036 private: | 3080 private: |
| 3037 intptr_t deopt_id_; | 3081 intptr_t deopt_id_; |
| 3038 ICData* ic_data_; | 3082 ICData* ic_data_; |
| 3039 const intptr_t token_pos_; | 3083 const intptr_t token_pos_; |
| 3040 const intptr_t try_index_; | 3084 const intptr_t try_index_; |
| 3041 Token::Kind kind_; | 3085 Token::Kind kind_; |
| 3042 TargetEntryInstr* true_successor_; | |
| 3043 TargetEntryInstr* false_successor_; | |
| 3044 | 3086 |
| 3045 DISALLOW_COPY_AND_ASSIGN(BranchInstr); | 3087 DISALLOW_COPY_AND_ASSIGN(BranchInstr); |
| 3046 }; | 3088 }; |
| 3047 | 3089 |
| 3048 | 3090 |
| 3091 class StrictCompareAndBranchInstr : public TemplateControlInstruction<2> { | |
|
srdjan
2012/08/24 21:35:05
You could use this to replace BranchInstr in FlowG
Florian Schneider
2012/08/27 08:55:30
Currently it is not very convenient to replace bra
| |
| 3092 public: | |
| 3093 StrictCompareAndBranchInstr(Value* left, Value* right, Token::Kind kind) | |
| 3094 : kind_(kind) { | |
| 3095 ASSERT(left != NULL); | |
| 3096 ASSERT(right != NULL); | |
| 3097 inputs_[0] = left; | |
| 3098 inputs_[1] = right; | |
| 3099 ASSERT(Token::IsStrictEqualityOperator(kind)); | |
| 3100 } | |
| 3101 | |
| 3102 DECLARE_INSTRUCTION(StrictCompareAndBranch) | |
| 3103 | |
| 3104 Value* left() const { return inputs_[0]; } | |
| 3105 Value* right() const { return inputs_[1]; } | |
| 3106 | |
| 3107 virtual intptr_t ArgumentCount() const { return 0; } | |
| 3108 | |
| 3109 Token::Kind kind() const { return kind_; } | |
| 3110 | |
| 3111 virtual LocationSummary* MakeLocationSummary() const; | |
| 3112 | |
| 3113 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | |
| 3114 | |
| 3115 virtual bool CanDeoptimize() const { return false; } | |
| 3116 | |
| 3117 private: | |
| 3118 Token::Kind kind_; | |
|
srdjan
2012/08/24 18:55:39
const
Florian Schneider
2012/08/27 08:55:30
Done.
| |
| 3119 | |
| 3120 DISALLOW_COPY_AND_ASSIGN(StrictCompareAndBranchInstr); | |
| 3121 }; | |
| 3122 | |
| 3123 | |
| 3049 #undef DECLARE_INSTRUCTION | 3124 #undef DECLARE_INSTRUCTION |
| 3050 | 3125 |
| 3051 | 3126 |
| 3052 class Environment : public ZoneAllocated { | 3127 class Environment : public ZoneAllocated { |
| 3053 public: | 3128 public: |
| 3054 // Construct an environment by constructing uses from an array of definitions. | 3129 // Construct an environment by constructing uses from an array of definitions. |
| 3055 Environment(const GrowableArray<Definition*>& definitions, | 3130 Environment(const GrowableArray<Definition*>& definitions, |
| 3056 intptr_t fixed_parameter_count); | 3131 intptr_t fixed_parameter_count); |
| 3057 | 3132 |
| 3058 void set_locations(Location* locations) { | 3133 void set_locations(Location* locations) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3135 ForwardInstructionIterator* current_iterator_; | 3210 ForwardInstructionIterator* current_iterator_; |
| 3136 | 3211 |
| 3137 private: | 3212 private: |
| 3138 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 3213 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 3139 }; | 3214 }; |
| 3140 | 3215 |
| 3141 | 3216 |
| 3142 } // namespace dart | 3217 } // namespace dart |
| 3143 | 3218 |
| 3144 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 3219 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |