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

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

Issue 10382234: Introduce locations based code generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed Srdjan comments 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"
11 #include "vm/handles_impl.h" 11 #include "vm/handles_impl.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 class BitVector; 16 class BitVector;
17 class FlowGraphCompiler;
17 class FlowGraphVisitor; 18 class FlowGraphVisitor;
18 class LocalVariable; 19 class LocalVariable;
20 class LocationSummary;
19 21
20 // M is a two argument macro. It is applied to each concrete value's 22 // M is a two argument macro. It is applied to each concrete value's
21 // typename and classname. 23 // typename and classname.
22 #define FOR_EACH_VALUE(M) \ 24 #define FOR_EACH_VALUE(M) \
23 M(Use, UseVal) \ 25 M(Use, UseVal) \
24 M(Constant, ConstantVal) \ 26 M(Constant, ConstantVal) \
25 27
26 28
27 // M is a two argument macro. It is applied to each concrete instruction's 29 // M is a two argument macro. It is applied to each concrete instruction's
28 // (including the values) typename and classname. 30 // (including the values) typename and classname.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // frame-allocated locals assigned to by the computation. 103 // frame-allocated locals assigned to by the computation.
102 virtual void RecordAssignedVars(BitVector* assigned_vars); 104 virtual void RecordAssignedVars(BitVector* assigned_vars);
103 105
104 virtual const char* DebugName() const = 0; 106 virtual const char* DebugName() const = 0;
105 107
106 // Printing support. These functions are sometimes overridden for custom 108 // Printing support. These functions are sometimes overridden for custom
107 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". 109 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)".
108 virtual void PrintTo(BufferFormatter* f) const; 110 virtual void PrintTo(BufferFormatter* f) const;
109 virtual void PrintOperandsTo(BufferFormatter* f) const; 111 virtual void PrintOperandsTo(BufferFormatter* f) const;
110 112
113 // Returns structure describing location constraints required
114 // to emit native code for this computation.
115 virtual LocationSummary* locs() const {
116 // TODO(vegorov): This should be pure virtual method.
117 // However we are temporary using NULL for instructions that
118 // were not converted to the location based code generation yet.
119 return NULL;
120 }
121
122 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
123 UNIMPLEMENTED();
124 }
125
111 private: 126 private:
112 friend class Instruction; 127 friend class Instruction;
113 static intptr_t GetNextCid(Isolate* isolate) { 128 static intptr_t GetNextCid(Isolate* isolate) {
114 intptr_t tmp = isolate->computation_id(); 129 intptr_t tmp = isolate->computation_id();
115 isolate->set_computation_id(tmp + 1); 130 isolate->set_computation_id(tmp + 1);
116 return tmp; 131 return tmp;
117 } 132 }
118 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) { 133 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) {
119 if (isolate->ic_data_array() == Array::null()) { 134 if (isolate->ic_data_array() == Array::null()) {
120 return NULL; 135 return NULL;
(...skipping 15 matching lines...) Expand all
136 151
137 152
138 // An embedded container with N elements of type T. Used (with partial 153 // An embedded container with N elements of type T. Used (with partial
139 // specialization for N=0) because embedded arrays cannot have size 0. 154 // specialization for N=0) because embedded arrays cannot have size 0.
140 template<typename T, intptr_t N> 155 template<typename T, intptr_t N>
141 class EmbeddedArray { 156 class EmbeddedArray {
142 public: 157 public:
143 EmbeddedArray() : elements_() { } 158 EmbeddedArray() : elements_() { }
144 159
145 intptr_t length() const { return N; } 160 intptr_t length() const { return N; }
161
146 const T& operator[](intptr_t i) const { 162 const T& operator[](intptr_t i) const {
147 ASSERT(i < length()); 163 ASSERT(i < length());
148 return elements_[i]; 164 return elements_[i];
149 } 165 }
166
150 T& operator[](intptr_t i) { 167 T& operator[](intptr_t i) {
151 ASSERT(i < length()); 168 ASSERT(i < length());
152 return elements_[i]; 169 return elements_[i];
153 } 170 }
154 171
172 const T& At(intptr_t i) const {
173 return (*this)[i];
174 }
175
176 void SetAt(intptr_t i, const T& val) {
177 (*this)[i] = val;
178 }
srdjan 2012/05/21 16:05:22 Maybe we should get rid of operators (some other C
179
155 private: 180 private:
156 T elements_[N]; 181 T elements_[N];
157 }; 182 };
158 183
159 184
160 template<typename T> 185 template<typename T>
161 class EmbeddedArray<T, 0> { 186 class EmbeddedArray<T, 0> {
162 public: 187 public:
163 intptr_t length() const { return 0; } 188 intptr_t length() const { return 0; }
164 const T& operator[](intptr_t i) const { 189 const T& operator[](intptr_t i) const {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 }; 467 };
443 468
444 469
445 class StrictCompareComp : public TemplateComputation<2> { 470 class StrictCompareComp : public TemplateComputation<2> {
446 public: 471 public:
447 StrictCompareComp(Token::Kind kind, Value* left, Value* right) 472 StrictCompareComp(Token::Kind kind, Value* left, Value* right)
448 : kind_(kind) { 473 : kind_(kind) {
449 ASSERT((kind_ == Token::kEQ_STRICT) || (kind_ == Token::kNE_STRICT)); 474 ASSERT((kind_ == Token::kEQ_STRICT) || (kind_ == Token::kNE_STRICT));
450 inputs_[0] = left; 475 inputs_[0] = left;
451 inputs_[1] = right; 476 inputs_[1] = right;
477 location_summary_ = MakeLocationSummary();
452 } 478 }
453 479
454 DECLARE_COMPUTATION(StrictCompare) 480 DECLARE_COMPUTATION(StrictCompare)
455 481
456 Token::Kind kind() const { return kind_; } 482 Token::Kind kind() const { return kind_; }
457 Value* left() const { return inputs_[0]; } 483 Value* left() const { return inputs_[0]; }
458 Value* right() const { return inputs_[1]; } 484 Value* right() const { return inputs_[1]; }
459 485
460 virtual void PrintOperandsTo(BufferFormatter* f) const; 486 virtual void PrintOperandsTo(BufferFormatter* f) const;
461 487
488 virtual LocationSummary* locs() const {
489 return location_summary_;
490 }
491
492 // Platform specific summary factory for this instruction.
493 LocationSummary* MakeLocationSummary();
494
495 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
496
462 private: 497 private:
463 const Token::Kind kind_; 498 const Token::Kind kind_;
464 499
500 LocationSummary* location_summary_;
501
465 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); 502 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp);
466 }; 503 };
467 504
468 505
469 class EqualityCompareComp : public TemplateComputation<2> { 506 class EqualityCompareComp : public TemplateComputation<2> {
470 public: 507 public:
471 EqualityCompareComp(intptr_t token_index, 508 EqualityCompareComp(intptr_t token_index,
472 intptr_t try_index, 509 intptr_t try_index,
473 Value* left, 510 Value* left,
474 Value* right) 511 Value* right)
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 virtual type##Instr* As##type() { return NULL; } 1393 virtual type##Instr* As##type() { return NULL; }
1357 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) 1394 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK)
1358 #undef INSTRUCTION_TYPE_CHECK 1395 #undef INSTRUCTION_TYPE_CHECK
1359 1396
1360 // Static type of the instruction. 1397 // Static type of the instruction.
1361 virtual RawAbstractType* StaticType() const { 1398 virtual RawAbstractType* StaticType() const {
1362 UNREACHABLE(); 1399 UNREACHABLE();
1363 return AbstractType::null(); 1400 return AbstractType::null();
1364 } 1401 }
1365 1402
1403 // Returns structure describing location constraints required
1404 // to emit native code for this instruction.
1405 virtual LocationSummary* locs() const {
1406 // TODO(vegorov): This should be pure virtual method.
1407 // However we are temporary using NULL for instructions that
1408 // were not converted to the location based code generation yet.
1409 return NULL;
1410 }
1411
1412 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
1413 UNIMPLEMENTED();
1414 }
1415
1366 private: 1416 private:
1367 intptr_t cid_; 1417 intptr_t cid_;
1368 ICData* ic_data_; 1418 ICData* ic_data_;
1369 DISALLOW_COPY_AND_ASSIGN(Instruction); 1419 DISALLOW_COPY_AND_ASSIGN(Instruction);
1370 }; 1420 };
1371 1421
1372 1422
1373 // Basic block entries are administrative nodes. There is a distinguished 1423 // Basic block entries are administrative nodes. There is a distinguished
1374 // graph entry with no predecessor. Joins are the only nodes with multiple 1424 // graph entry with no predecessor. Joins are the only nodes with multiple
1375 // predecessors. Targets are all other basic block entries. The types 1425 // predecessors. Targets are all other basic block entries. The types
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 explicit DoInstr(Computation* comp) 1603 explicit DoInstr(Computation* comp)
1554 : computation_(comp), successor_(NULL) { } 1604 : computation_(comp), successor_(NULL) { }
1555 1605
1556 DECLARE_INSTRUCTION(Do) 1606 DECLARE_INSTRUCTION(Do)
1557 1607
1558 Computation* computation() const { return computation_; } 1608 Computation* computation() const { return computation_; }
1559 1609
1560 virtual Instruction* StraightLineSuccessor() const { 1610 virtual Instruction* StraightLineSuccessor() const {
1561 return successor_; 1611 return successor_;
1562 } 1612 }
1613
1563 virtual void SetSuccessor(Instruction* instr) { 1614 virtual void SetSuccessor(Instruction* instr) {
1564 ASSERT(successor_ == NULL); 1615 ASSERT(successor_ == NULL);
1565 successor_ = instr; 1616 successor_ = instr;
1566 } 1617 }
1567 1618
1568 virtual void RecordAssignedVars(BitVector* assigned_vars); 1619 virtual void RecordAssignedVars(BitVector* assigned_vars);
1569 1620
1621 virtual LocationSummary* locs() const {
1622 return computation()->locs();
1623 }
1624
1625 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
1626 computation()->EmitNativeCode(compiler);
1627 }
1628
1570 private: 1629 private:
1571 Computation* computation_; 1630 Computation* computation_;
1572 Instruction* successor_; 1631 Instruction* successor_;
1573 1632
1574 DISALLOW_COPY_AND_ASSIGN(DoInstr); 1633 DISALLOW_COPY_AND_ASSIGN(DoInstr);
1575 }; 1634 };
1576 1635
1577 1636
1578 class Definition : public Instruction { 1637 class Definition : public Instruction {
1579 public: 1638 public:
(...skipping 16 matching lines...) Expand all
1596 explicit BindInstr(Computation* computation) 1655 explicit BindInstr(Computation* computation)
1597 : Definition(), computation_(computation), successor_(NULL) { } 1656 : Definition(), computation_(computation), successor_(NULL) { }
1598 1657
1599 DECLARE_INSTRUCTION(Bind) 1658 DECLARE_INSTRUCTION(Bind)
1600 1659
1601 Computation* computation() const { return computation_; } 1660 Computation* computation() const { return computation_; }
1602 1661
1603 virtual Instruction* StraightLineSuccessor() const { 1662 virtual Instruction* StraightLineSuccessor() const {
1604 return successor_; 1663 return successor_;
1605 } 1664 }
1665
1606 virtual void SetSuccessor(Instruction* instr) { 1666 virtual void SetSuccessor(Instruction* instr) {
1607 ASSERT(successor_ == NULL); 1667 ASSERT(successor_ == NULL);
1608 successor_ = instr; 1668 successor_ = instr;
1609 } 1669 }
1610 1670
1611 // Static type of the underlying computation. 1671 // Static type of the underlying computation.
1612 virtual RawAbstractType* StaticType() const { 1672 virtual RawAbstractType* StaticType() const {
1613 return computation()->StaticType(); 1673 return computation()->StaticType();
1614 } 1674 }
1615 1675
1616 virtual void RecordAssignedVars(BitVector* assigned_vars); 1676 virtual void RecordAssignedVars(BitVector* assigned_vars);
1617 1677
1678 virtual LocationSummary* locs() const {
1679 return computation()->locs();
1680 }
1681
1682 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
1683
1618 private: 1684 private:
1619 Computation* computation_; 1685 Computation* computation_;
1620 Instruction* successor_; 1686 Instruction* successor_;
1621 1687
1622 DISALLOW_COPY_AND_ASSIGN(BindInstr); 1688 DISALLOW_COPY_AND_ASSIGN(BindInstr);
1623 }; 1689 };
1624 1690
1625 1691
1626 class ReturnInstr : public Instruction { 1692 class ReturnInstr : public Instruction {
1627 public: 1693 public:
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 const GrowableArray<BlockEntryInstr*>& block_order_; 1864 const GrowableArray<BlockEntryInstr*>& block_order_;
1799 1865
1800 private: 1866 private:
1801 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 1867 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
1802 }; 1868 };
1803 1869
1804 1870
1805 } // namespace dart 1871 } // namespace dart
1806 1872
1807 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 1873 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698