| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 class BindInstr; | 111 class BindInstr; |
| 112 class BranchInstr; | 112 class BranchInstr; |
| 113 class BufferFormatter; | 113 class BufferFormatter; |
| 114 class Instruction; | 114 class Instruction; |
| 115 class Value; | 115 class Value; |
| 116 | 116 |
| 117 class Computation : public ZoneAllocated { | 117 class Computation : public ZoneAllocated { |
| 118 public: | 118 public: |
| 119 static const int kNoCid = -1; | 119 static const int kNoCid = -1; |
| 120 | 120 |
| 121 Computation() : cid_(-1), ic_data_(NULL), instr_(NULL), locs_(NULL) { | 121 Computation() : cid_(-1), ic_data_(NULL), locs_(NULL) { |
| 122 Isolate* isolate = Isolate::Current(); | 122 Isolate* isolate = Isolate::Current(); |
| 123 cid_ = GetNextCid(isolate); | 123 cid_ = GetNextCid(isolate); |
| 124 ic_data_ = GetICDataForCid(cid_, isolate); | 124 ic_data_ = GetICDataForCid(cid_, isolate); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Unique computation/instruction id, used for deoptimization. | 127 // Unique computation/instruction id, used for deoptimization. |
| 128 intptr_t cid() const { return cid_; } | 128 intptr_t cid() const { return cid_; } |
| 129 | 129 |
| 130 ICData* ic_data() const { return ic_data_; } | 130 ICData* ic_data() const { return ic_data_; } |
| 131 void set_ic_data(ICData* value) { ic_data_ = value; } | 131 void set_ic_data(ICData* value) { ic_data_ = value; } |
| 132 bool HasICData() const { | 132 bool HasICData() const { |
| 133 return (ic_data() != NULL) && !ic_data()->IsNull(); | 133 return (ic_data() != NULL) && !ic_data()->IsNull(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Visiting support. | 136 // Visiting support. |
| 137 virtual void Accept(FlowGraphVisitor* visitor) = 0; | 137 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr) = 0; |
| 138 | 138 |
| 139 virtual intptr_t InputCount() const = 0; | 139 virtual intptr_t InputCount() const = 0; |
| 140 virtual Value* InputAt(intptr_t i) const = 0; | 140 virtual Value* InputAt(intptr_t i) const = 0; |
| 141 virtual void SetInputAt(intptr_t i, Value* value) = 0; | 141 virtual void SetInputAt(intptr_t i, Value* value) = 0; |
| 142 | 142 |
| 143 // Static type of the computation. | 143 // Static type of the computation. |
| 144 virtual RawAbstractType* StaticType() const = 0; | 144 virtual RawAbstractType* StaticType() const = 0; |
| 145 | 145 |
| 146 // Mutate assigned_vars to add the local variable index for all | 146 // Mutate assigned_vars to add the local variable index for all |
| 147 // frame-allocated locals assigned to by the computation. | 147 // frame-allocated locals assigned to by the computation. |
| 148 virtual void RecordAssignedVars(BitVector* assigned_vars); | 148 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 149 | 149 |
| 150 virtual const char* DebugName() const = 0; | 150 virtual const char* DebugName() const = 0; |
| 151 | 151 |
| 152 // Printing support. These functions are sometimes overridden for custom | 152 // Printing support. These functions are sometimes overridden for custom |
| 153 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". | 153 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". |
| 154 virtual void PrintTo(BufferFormatter* f) const; | 154 virtual void PrintTo(BufferFormatter* f) const; |
| 155 virtual void PrintOperandsTo(BufferFormatter* f) const; | 155 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 156 | 156 |
| 157 // Returns structure describing location constraints required | 157 // Returns structure describing location constraints required |
| 158 // to emit native code for this computation. | 158 // to emit native code for this computation. |
| 159 LocationSummary* locs() { | 159 LocationSummary* locs() { |
| 160 if (locs_ == NULL) { | 160 if (locs_ == NULL) { |
| 161 locs_ = MakeLocationSummary(); | 161 locs_ = MakeLocationSummary(); |
| 162 } | 162 } |
| 163 return locs_; | 163 return locs_; |
| 164 } | 164 } |
| 165 | 165 |
| 166 void set_instr(BindInstr* instr) { instr_ = instr; } | |
| 167 BindInstr* instr() const { return instr_; } | |
| 168 | |
| 169 // Create a location summary for this computation. | 166 // Create a location summary for this computation. |
| 170 // TODO(fschneider): Temporarily returns NULL for instructions | 167 // TODO(fschneider): Temporarily returns NULL for instructions |
| 171 // that are not yet converted to the location based code generation. | 168 // that are not yet converted to the location based code generation. |
| 172 virtual LocationSummary* MakeLocationSummary() const = 0; | 169 virtual LocationSummary* MakeLocationSummary() const = 0; |
| 173 | 170 |
| 174 // TODO(fschneider): Make EmitNativeCode and locs const. | 171 // TODO(fschneider): Make EmitNativeCode and locs const. |
| 175 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0; | 172 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0; |
| 176 | 173 |
| 177 static LocationSummary* MakeCallSummary(); | 174 static LocationSummary* MakeCallSummary(); |
| 178 | 175 |
| 179 void ReplaceWith(Computation* other); | |
| 180 | |
| 181 // Declare an enum value used to define type-test predicates. | 176 // Declare an enum value used to define type-test predicates. |
| 182 enum ComputationType { | 177 enum ComputationType { |
| 183 #define DECLARE_COMPUTATION_TYPE(ShortName, ClassName) k##ShortName, | 178 #define DECLARE_COMPUTATION_TYPE(ShortName, ClassName) k##ShortName, |
| 184 | 179 |
| 185 FOR_EACH_COMPUTATION(DECLARE_COMPUTATION_TYPE) | 180 FOR_EACH_COMPUTATION(DECLARE_COMPUTATION_TYPE) |
| 186 | 181 |
| 187 #undef DECLARE_COMPUTATION_TYPE | 182 #undef DECLARE_COMPUTATION_TYPE |
| 188 }; | 183 }; |
| 189 | 184 |
| 190 virtual ComputationType computation_type() const = 0; | 185 virtual ComputationType computation_type() const = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 213 return NULL; | 208 return NULL; |
| 214 } | 209 } |
| 215 ICData& ic_data_handle = ICData::ZoneHandle(); | 210 ICData& ic_data_handle = ICData::ZoneHandle(); |
| 216 ic_data_handle ^= array_handle.At(cid); | 211 ic_data_handle ^= array_handle.At(cid); |
| 217 return &ic_data_handle; | 212 return &ic_data_handle; |
| 218 } | 213 } |
| 219 } | 214 } |
| 220 | 215 |
| 221 intptr_t cid_; | 216 intptr_t cid_; |
| 222 ICData* ic_data_; | 217 ICData* ic_data_; |
| 223 BindInstr* instr_; | |
| 224 LocationSummary* locs_; | 218 LocationSummary* locs_; |
| 225 | 219 |
| 226 DISALLOW_COPY_AND_ASSIGN(Computation); | 220 DISALLOW_COPY_AND_ASSIGN(Computation); |
| 227 }; | 221 }; |
| 228 | 222 |
| 229 | 223 |
| 230 // An embedded container with N elements of type T. Used (with partial | 224 // An embedded container with N elements of type T. Used (with partial |
| 231 // specialization for N=0) because embedded arrays cannot have size 0. | 225 // specialization for N=0) because embedded arrays cannot have size 0. |
| 232 template<typename T, intptr_t N> | 226 template<typename T, intptr_t N> |
| 233 class EmbeddedArray { | 227 class EmbeddedArray { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 public: | 288 public: |
| 295 Value() { } | 289 Value() { } |
| 296 | 290 |
| 297 private: | 291 private: |
| 298 DISALLOW_COPY_AND_ASSIGN(Value); | 292 DISALLOW_COPY_AND_ASSIGN(Value); |
| 299 }; | 293 }; |
| 300 | 294 |
| 301 | 295 |
| 302 // Functions defined in all concrete computation classes. | 296 // Functions defined in all concrete computation classes. |
| 303 #define DECLARE_COMPUTATION(ShortName) \ | 297 #define DECLARE_COMPUTATION(ShortName) \ |
| 304 virtual void Accept(FlowGraphVisitor* visitor); \ | 298 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr); \ |
| 305 virtual ComputationType computation_type() const { \ | 299 virtual ComputationType computation_type() const { \ |
| 306 return Computation::k##ShortName; \ | 300 return Computation::k##ShortName; \ |
| 307 } \ | 301 } \ |
| 308 virtual const char* DebugName() const { return #ShortName; } \ | 302 virtual const char* DebugName() const { return #ShortName; } \ |
| 309 virtual RawAbstractType* StaticType() const; \ | 303 virtual RawAbstractType* StaticType() const; \ |
| 310 virtual LocationSummary* MakeLocationSummary() const; \ | 304 virtual LocationSummary* MakeLocationSummary() const; \ |
| 311 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 305 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 312 | 306 |
| 313 // Functions defined in all concrete value classes. | 307 // Functions defined in all concrete value classes. |
| 314 #define DECLARE_VALUE(ShortName) \ | 308 #define DECLARE_VALUE(ShortName) \ |
| (...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 } | 2090 } |
| 2097 | 2091 |
| 2098 | 2092 |
| 2099 class BindInstr : public Definition { | 2093 class BindInstr : public Definition { |
| 2100 public: | 2094 public: |
| 2101 enum UseKind { kUnused, kUsed }; | 2095 enum UseKind { kUnused, kUsed }; |
| 2102 | 2096 |
| 2103 BindInstr(UseKind used, Computation* computation) | 2097 BindInstr(UseKind used, Computation* computation) |
| 2104 : computation_(computation), is_used_(used != kUnused) { | 2098 : computation_(computation), is_used_(used != kUnused) { |
| 2105 ASSERT(computation != NULL); | 2099 ASSERT(computation != NULL); |
| 2106 computation->set_instr(this); | |
| 2107 } | 2100 } |
| 2108 | 2101 |
| 2109 DECLARE_INSTRUCTION(Bind) | 2102 DECLARE_INSTRUCTION(Bind) |
| 2110 | 2103 |
| 2111 Computation* computation() const { return computation_; } | 2104 Computation* computation() const { return computation_; } |
| 2112 void replace_computation(Computation* value) { computation_ = value; } | 2105 void set_computation(Computation* value) { computation_ = value; } |
| 2113 bool is_used() const { return is_used_; } | 2106 bool is_used() const { return is_used_; } |
| 2114 | 2107 |
| 2115 // Static type of the underlying computation. | 2108 // Static type of the underlying computation. |
| 2116 virtual RawAbstractType* StaticType() const { | 2109 virtual RawAbstractType* StaticType() const { |
| 2117 return computation()->StaticType(); | 2110 return computation()->StaticType(); |
| 2118 } | 2111 } |
| 2119 | 2112 |
| 2120 virtual void RecordAssignedVars(BitVector* assigned_vars); | 2113 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 2121 | 2114 |
| 2122 virtual LocationSummary* locs() { | 2115 virtual LocationSummary* locs() { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2374 : block_order_(block_order) { } | 2367 : block_order_(block_order) { } |
| 2375 virtual ~FlowGraphVisitor() { } | 2368 virtual ~FlowGraphVisitor() { } |
| 2376 | 2369 |
| 2377 // Visit each block in the block order, and for each block its | 2370 // Visit each block in the block order, and for each block its |
| 2378 // instructions in order from the block entry to exit. | 2371 // instructions in order from the block entry to exit. |
| 2379 virtual void VisitBlocks(); | 2372 virtual void VisitBlocks(); |
| 2380 | 2373 |
| 2381 // Visit functions for instruction and computation classes, with empty | 2374 // Visit functions for instruction and computation classes, with empty |
| 2382 // default implementations. | 2375 // default implementations. |
| 2383 #define DECLARE_VISIT_COMPUTATION(ShortName, ClassName) \ | 2376 #define DECLARE_VISIT_COMPUTATION(ShortName, ClassName) \ |
| 2384 virtual void Visit##ShortName(ClassName* comp) { } | 2377 virtual void Visit##ShortName(ClassName* comp, BindInstr* instr) { } |
| 2385 | 2378 |
| 2386 #define DECLARE_VISIT_INSTRUCTION(ShortName) \ | 2379 #define DECLARE_VISIT_INSTRUCTION(ShortName) \ |
| 2387 virtual void Visit##ShortName(ShortName##Instr* instr) { } | 2380 virtual void Visit##ShortName(ShortName##Instr* instr) { } |
| 2388 | 2381 |
| 2389 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION) | 2382 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION) |
| 2390 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) | 2383 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 2391 | 2384 |
| 2392 #undef DECLARE_VISIT_COMPUTATION | 2385 #undef DECLARE_VISIT_COMPUTATION |
| 2393 #undef DECLARE_VISIT_INSTRUCTION | 2386 #undef DECLARE_VISIT_INSTRUCTION |
| 2394 | 2387 |
| 2395 protected: | 2388 protected: |
| 2396 const GrowableArray<BlockEntryInstr*>& block_order_; | 2389 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2397 | 2390 |
| 2398 private: | 2391 private: |
| 2399 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2392 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2400 }; | 2393 }; |
| 2401 | 2394 |
| 2402 | 2395 |
| 2403 } // namespace dart | 2396 } // namespace dart |
| 2404 | 2397 |
| 2405 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2398 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |