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

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

Issue 10431006: First step toward an optimizing compiler: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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) 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 M(AllocateObjectWithBoundsCheck, AllocateObjectWithBoundsCheckComp) \ 57 M(AllocateObjectWithBoundsCheck, AllocateObjectWithBoundsCheckComp) \
58 M(NativeLoadField, NativeLoadFieldComp) \ 58 M(NativeLoadField, NativeLoadFieldComp) \
59 M(NativeStoreField, NativeStoreFieldComp) \ 59 M(NativeStoreField, NativeStoreFieldComp) \
60 M(InstantiateTypeArguments, InstantiateTypeArgumentsComp) \ 60 M(InstantiateTypeArguments, InstantiateTypeArgumentsComp) \
61 M(ExtractConstructorTypeArguments, ExtractConstructorTypeArgumentsComp) \ 61 M(ExtractConstructorTypeArguments, ExtractConstructorTypeArgumentsComp) \
62 M(ExtractConstructorInstantiator, ExtractConstructorInstantiatorComp) \ 62 M(ExtractConstructorInstantiator, ExtractConstructorInstantiatorComp) \
63 M(AllocateContext, AllocateContextComp) \ 63 M(AllocateContext, AllocateContextComp) \
64 M(ChainContext, ChainContextComp) \ 64 M(ChainContext, ChainContextComp) \
65 M(CloneContext, CloneContextComp) \ 65 M(CloneContext, CloneContextComp) \
66 M(CatchEntry, CatchEntryComp) \ 66 M(CatchEntry, CatchEntryComp) \
67 M(BinaryOp, BinaryOpComp) \
67 68
68 69
69 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; 70 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName;
70 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) 71 FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
71 #undef FORWARD_DECLARATION 72 #undef FORWARD_DECLARATION
72 73
73 // Forward declarations. 74 // Forward declarations.
74 class BufferFormatter; 75 class BufferFormatter;
75 class Value; 76 class Value;
76 77
77 78
78 class Computation : public ZoneAllocated { 79 class Computation : public ZoneAllocated {
79 public: 80 public:
80 static const int kNoCid = -1; 81 static const int kNoCid = -1;
81 82
82 Computation() : cid_(-1), ic_data_(NULL), locs_(NULL) { 83 Computation() : cid_(-1), ic_data_(NULL), use_(NULL), locs_(NULL) {
83 Isolate* isolate = Isolate::Current(); 84 Isolate* isolate = Isolate::Current();
84 cid_ = GetNextCid(isolate); 85 cid_ = GetNextCid(isolate);
85 ic_data_ = GetICDataForCid(cid_, isolate); 86 ic_data_ = GetICDataForCid(cid_, isolate);
86 } 87 }
87 88
88 // Unique computation/instruction id, used for deoptimization. 89 // Unique computation/instruction id, used for deoptimization.
89 intptr_t cid() const { return cid_; } 90 intptr_t cid() const { return cid_; }
90 91
91 const ICData* ic_data() const { return ic_data_; } 92 ICData* ic_data() const { return ic_data_; }
93 void set_ic_data(ICData* value) { ic_data_ = value; }
92 94
93 // Visiting support. 95 // Visiting support.
94 virtual void Accept(FlowGraphVisitor* visitor) = 0; 96 virtual void Accept(FlowGraphVisitor* visitor) = 0;
95 97
96 virtual intptr_t InputCount() const = 0; 98 virtual intptr_t InputCount() const = 0;
97 virtual Value* InputAt(intptr_t i) const = 0; 99 virtual Value* InputAt(intptr_t i) const = 0;
98 100
99 // Static type of the computation. 101 // Static type of the computation.
100 virtual RawAbstractType* StaticType() const = 0; 102 virtual RawAbstractType* StaticType() const = 0;
101 103
(...skipping 10 matching lines...) Expand all
112 114
113 // Returns structure describing location constraints required 115 // Returns structure describing location constraints required
114 // to emit native code for this computation. 116 // to emit native code for this computation.
115 LocationSummary* locs() { 117 LocationSummary* locs() {
116 if (locs_ == NULL) { 118 if (locs_ == NULL) {
117 locs_ = MakeLocationSummary(); 119 locs_ = MakeLocationSummary();
118 } 120 }
119 return locs_; 121 return locs_;
120 } 122 }
121 123
124 // TODO(srdjan): Eliminate Instructions hierarchy. If 'use' is NULL
125 // it acts as a DoInstr, otherwise a BindInstr.
126 void set_use(UseVal* value) { use_ = value; }
127 UseVal* use() const { return use_; }
128 bool has_use() const { return use_ != NULL; }
129
122 // Create a location summary for this computation. 130 // Create a location summary for this computation.
123 // TODO(fschneider): Temporarily returns NULL for instructions 131 // TODO(fschneider): Temporarily returns NULL for instructions
124 // that are not yet converted to the location based code generation. 132 // that are not yet converted to the location based code generation.
125 virtual LocationSummary* MakeLocationSummary() const = 0; 133 virtual LocationSummary* MakeLocationSummary() const = 0;
126 134
127 // TODO(fschneider): Make EmitNativeCode and locs const. 135 // TODO(fschneider): Make EmitNativeCode and locs const.
128 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0; 136 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0;
129 137
130 private: 138 private:
131 friend class Instruction; 139 friend class Instruction;
132 static intptr_t GetNextCid(Isolate* isolate) { 140 static intptr_t GetNextCid(Isolate* isolate) {
133 intptr_t tmp = isolate->computation_id(); 141 intptr_t tmp = isolate->computation_id();
134 isolate->set_computation_id(tmp + 1); 142 isolate->set_computation_id(tmp + 1);
135 return tmp; 143 return tmp;
136 } 144 }
137 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) { 145 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) {
138 if (isolate->ic_data_array() == Array::null()) { 146 if (isolate->ic_data_array() == Array::null()) {
139 return NULL; 147 return NULL;
140 } else { 148 } else {
141 const Array& array_handle = Array::Handle(isolate->ic_data_array()); 149 const Array& array_handle = Array::Handle(isolate->ic_data_array());
150 if (cid >= array_handle.Length()) {
151 // For computations being added in the optimizing compiler.
152 return NULL;
153 }
142 ICData& ic_data_handle = ICData::ZoneHandle(); 154 ICData& ic_data_handle = ICData::ZoneHandle();
143 if (cid < array_handle.Length()) { 155 ic_data_handle ^= array_handle.At(cid);
144 ic_data_handle ^= array_handle.At(cid);
145 }
146 return &ic_data_handle; 156 return &ic_data_handle;
147 } 157 }
148 } 158 }
149 159
150 intptr_t cid_; 160 intptr_t cid_;
151 ICData* ic_data_; 161 ICData* ic_data_;
162 UseVal* use_;
Florian Schneider 2012/05/24 00:20:39 Maybe store a Instruction* that points to the corr
srdjan 2012/05/24 01:36:26 Done.
152 LocationSummary* locs_; 163 LocationSummary* locs_;
153 164
154 DISALLOW_COPY_AND_ASSIGN(Computation); 165 DISALLOW_COPY_AND_ASSIGN(Computation);
155 }; 166 };
156 167
157 168
158 // An embedded container with N elements of type T. Used (with partial 169 // An embedded container with N elements of type T. Used (with partial
159 // specialization for N=0) because embedded arrays cannot have size 0. 170 // specialization for N=0) because embedded arrays cannot have size 0.
160 template<typename T, intptr_t N> 171 template<typename T, intptr_t N>
161 class EmbeddedArray { 172 class EmbeddedArray {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 virtual LocationSummary* MakeLocationSummary() const; \ 252 virtual LocationSummary* MakeLocationSummary() const; \
242 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 253 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
243 254
244 // Functions defined in all concrete value classes. 255 // Functions defined in all concrete value classes.
245 #define DECLARE_VALUE(ShortName) \ 256 #define DECLARE_VALUE(ShortName) \
246 DECLARE_COMPUTATION(ShortName) \ 257 DECLARE_COMPUTATION(ShortName) \
247 virtual ShortName##Val* As##ShortName() { return this; } \ 258 virtual ShortName##Val* As##ShortName() { return this; } \
248 virtual void PrintTo(BufferFormatter* f) const; 259 virtual void PrintTo(BufferFormatter* f) const;
249 260
250 261
251 // Definitions and uses are mutually recursive. 262 class BindInstr;
252 class Definition;
253 263
254 class UseVal : public Value { 264 class UseVal : public Value {
255 public: 265 public:
256 explicit UseVal(Definition* definition) : definition_(definition) { } 266 explicit UseVal(BindInstr* definition);
257 267
258 DECLARE_VALUE(Use) 268 DECLARE_VALUE(Use)
259 269
260 Definition* definition() const { return definition_; } 270 BindInstr* definition() const { return definition_; }
261 271
262 private: 272 private:
263 Definition* const definition_; 273 BindInstr* definition_;
264 274
265 DISALLOW_COPY_AND_ASSIGN(UseVal); 275 DISALLOW_COPY_AND_ASSIGN(UseVal);
266 }; 276 };
267 277
268 278
269 class ConstantVal: public Value { 279 class ConstantVal: public Value {
270 public: 280 public:
271 explicit ConstantVal(const Object& value) 281 explicit ConstantVal(const Object& value)
272 : value_(value) { 282 : value_(value) {
273 ASSERT(value.IsZoneHandle()); 283 ASSERT(value.IsZoneHandle());
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 virtual void PrintOperandsTo(BufferFormatter* f) const; 1283 virtual void PrintOperandsTo(BufferFormatter* f) const;
1274 1284
1275 private: 1285 private:
1276 const LocalVariable& exception_var_; 1286 const LocalVariable& exception_var_;
1277 const LocalVariable& stacktrace_var_; 1287 const LocalVariable& stacktrace_var_;
1278 1288
1279 DISALLOW_COPY_AND_ASSIGN(CatchEntryComp); 1289 DISALLOW_COPY_AND_ASSIGN(CatchEntryComp);
1280 }; 1290 };
1281 1291
1282 1292
1293 class BinaryOpComp : public TemplateComputation<2> {
1294 public:
1295 BinaryOpComp(Token::Kind op_kind,
1296 InstanceCallComp* instance_call,
1297 Value* left,
1298 Value* right)
1299 : op_kind_(op_kind), instance_call_(instance_call) {
1300 inputs_[0] = left;
1301 inputs_[1] = right;
1302 }
1303
1304 Value* left() const { return inputs_[0]; }
1305 Value* right() const { return inputs_[1]; }
1306
1307 Token::Kind op_kind() const { return op_kind_; }
1308
1309 InstanceCallComp* instance_call() const { return instance_call_; }
1310
1311 virtual void PrintOperandsTo(BufferFormatter* f) const;
1312
1313 DECLARE_COMPUTATION(BinaryOp)
1314
1315 private:
1316 const Token::Kind op_kind_;
1317 InstanceCallComp* instance_call_;
1318
1319 DISALLOW_COPY_AND_ASSIGN(BinaryOpComp);
1320 };
1321
1283 #undef DECLARE_COMPUTATION 1322 #undef DECLARE_COMPUTATION
1284 1323
1285 1324
1286 // Instructions. 1325 // Instructions.
1287 // 1326 //
1288 // <Instruction> ::= JoinEntry <Instruction> 1327 // <Instruction> ::= JoinEntry <Instruction>
1289 // | TargetEntry <Instruction> 1328 // | TargetEntry <Instruction>
1290 // | Do <Computation> <Instruction> 1329 // | Do <Computation> <Instruction>
1291 // | Return <Value> 1330 // | Return <Value>
1292 // | Branch <Value> <Instruction> <Instruction> 1331 // | Branch <Value> <Instruction> <Instruction>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 // Unique computation/instruction id, used for deoptimization, e.g. for 1376 // Unique computation/instruction id, used for deoptimization, e.g. for
1338 // ReturnInstr, ThrowInstr and ReThrowInstr. 1377 // ReturnInstr, ThrowInstr and ReThrowInstr.
1339 intptr_t cid() const { return cid_; } 1378 intptr_t cid() const { return cid_; }
1340 1379
1341 const ICData* ic_data() const { return ic_data_; } 1380 const ICData* ic_data() const { return ic_data_; }
1342 1381
1343 virtual bool IsBlockEntry() const { return false; } 1382 virtual bool IsBlockEntry() const { return false; }
1344 BlockEntryInstr* AsBlockEntry() { 1383 BlockEntryInstr* AsBlockEntry() {
1345 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; 1384 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL;
1346 } 1385 }
1347 virtual bool IsDefinition() const { return false; } 1386 virtual bool IsBindInstr() const { return false; }
1348 Definition* AsDefinition() { 1387 virtual BindInstr* AsBindInstr() {
1349 return IsDefinition() ? reinterpret_cast<Definition*>(this) : NULL; 1388 return NULL;
1350 } 1389 }
1351 1390
1352 virtual intptr_t InputCount() const = 0; 1391 virtual intptr_t InputCount() const = 0;
1353 1392
1354 // Visiting support. 1393 // Visiting support.
1355 virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0; 1394 virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0;
1356 1395
1357 virtual Instruction* StraightLineSuccessor() const = 0; 1396 virtual Instruction* StraightLineSuccessor() const = 0;
1358 virtual void SetSuccessor(Instruction* instr) = 0; 1397 virtual void SetSuccessor(Instruction* instr) = 0;
1359 1398
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 } 1666 }
1628 1667
1629 private: 1668 private:
1630 Computation* computation_; 1669 Computation* computation_;
1631 Instruction* successor_; 1670 Instruction* successor_;
1632 1671
1633 DISALLOW_COPY_AND_ASSIGN(DoInstr); 1672 DISALLOW_COPY_AND_ASSIGN(DoInstr);
1634 }; 1673 };
1635 1674
1636 1675
1637 class Definition : public Instruction { 1676 class BindInstr : public Instruction {
1638 public: 1677 public:
1639 Definition() : temp_index_(-1) { } 1678 explicit BindInstr(Computation* computation)
1679 : temp_index_(-1), computation_(computation), successor_(NULL) { }
1640 1680
1641 virtual bool IsDefinition() const { return true; } 1681 DECLARE_INSTRUCTION(Bind)
1682
1683 virtual bool IsBindInstr() const { return true; }
1684 virtual BindInstr* AsBindInstr() { return this; }
1642 1685
1643 intptr_t temp_index() const { return temp_index_; } 1686 intptr_t temp_index() const { return temp_index_; }
1644 void set_temp_index(intptr_t index) { temp_index_ = index; } 1687 void set_temp_index(intptr_t index) { temp_index_ = index; }
1645 1688
1646 private: 1689 Computation* computation() const { return computation_; }
1647 intptr_t temp_index_; 1690 void replace_computation(Computation* value) { computation_ = value; }
1648 1691
1649 DISALLOW_COPY_AND_ASSIGN(Definition); 1692 void SetUse(UseVal* value) {
1650 }; 1693 computation()->set_use(value);
1651 1694 }
1652
1653 class BindInstr : public Definition {
1654 public:
1655 explicit BindInstr(Computation* computation)
1656 : Definition(), computation_(computation), successor_(NULL) { }
1657
1658 DECLARE_INSTRUCTION(Bind)
1659
1660 Computation* computation() const { return computation_; }
1661 1695
1662 virtual Instruction* StraightLineSuccessor() const { 1696 virtual Instruction* StraightLineSuccessor() const {
1663 return successor_; 1697 return successor_;
1664 } 1698 }
1665 1699
1666 virtual void SetSuccessor(Instruction* instr) { 1700 virtual void SetSuccessor(Instruction* instr) {
1667 ASSERT(successor_ == NULL); 1701 ASSERT(successor_ == NULL);
1668 successor_ = instr; 1702 successor_ = instr;
1669 } 1703 }
1670 1704
1671 // Static type of the underlying computation. 1705 // Static type of the underlying computation.
1672 virtual RawAbstractType* StaticType() const { 1706 virtual RawAbstractType* StaticType() const {
1673 return computation()->StaticType(); 1707 return computation()->StaticType();
1674 } 1708 }
1675 1709
1676 virtual void RecordAssignedVars(BitVector* assigned_vars); 1710 virtual void RecordAssignedVars(BitVector* assigned_vars);
1677 1711
1678 virtual LocationSummary* locs() const { 1712 virtual LocationSummary* locs() const {
1679 return computation()->locs(); 1713 return computation()->locs();
1680 } 1714 }
1681 1715
1682 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 1716 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
1683 1717
1684 private: 1718 private:
1719 intptr_t temp_index_;
1685 Computation* computation_; 1720 Computation* computation_;
1686 Instruction* successor_; 1721 Instruction* successor_;
1687 1722
1688 DISALLOW_COPY_AND_ASSIGN(BindInstr); 1723 DISALLOW_COPY_AND_ASSIGN(BindInstr);
1689 }; 1724 };
1690 1725
1691 1726
1692 class ReturnInstr : public Instruction { 1727 class ReturnInstr : public Instruction {
1693 public: 1728 public:
1694 ReturnInstr(intptr_t token_index, Value* value) 1729 ReturnInstr(intptr_t token_index, Value* value)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 const GrowableArray<BlockEntryInstr*>& block_order_; 1899 const GrowableArray<BlockEntryInstr*>& block_order_;
1865 1900
1866 private: 1901 private:
1867 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 1902 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
1868 }; 1903 };
1869 1904
1870 1905
1871 } // namespace dart 1906 } // namespace dart
1872 1907
1873 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 1908 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698