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

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

Issue 10377104: Compute assigned variables and dominance frontiers. (Closed) Base URL: https://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"
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 FlowGraphVisitor; 17 class FlowGraphVisitor;
17 class LocalVariable; 18 class LocalVariable;
18 19
19 // M is a two argument macro. It is applied to each concrete value's 20 // M is a two argument macro. It is applied to each concrete value's
20 // typename and classname. 21 // typename and classname.
21 #define FOR_EACH_VALUE(M) \ 22 #define FOR_EACH_VALUE(M) \
22 M(Use, UseVal) \ 23 M(Use, UseVal) \
23 M(Constant, ConstantVal) \ 24 M(Constant, ConstantVal) \
24 25
25 26
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Unique computation/instruction id, used for deoptimization. 80 // Unique computation/instruction id, used for deoptimization.
80 intptr_t cid() const { return cid_; } 81 intptr_t cid() const { return cid_; }
81 82
82 const ICData* ic_data() const { return ic_data_; } 83 const ICData* ic_data() const { return ic_data_; }
83 84
84 // Visiting support. 85 // Visiting support.
85 virtual void Accept(FlowGraphVisitor* visitor) = 0; 86 virtual void Accept(FlowGraphVisitor* visitor) = 0;
86 87
87 virtual intptr_t InputCount() const = 0; 88 virtual intptr_t InputCount() const = 0;
88 89
90 virtual void RecordAssignedVars(BitVector* assigned_vars);
srdjan 2012/05/12 00:00:55 Please document what does BitVector represent.
Kevin Millikin (Google) 2012/05/15 11:51:44 Done.
91
89 private: 92 private:
90 friend class Instruction; 93 friend class Instruction;
91 static intptr_t GetNextCid(Isolate* isolate) { 94 static intptr_t GetNextCid(Isolate* isolate) {
92 intptr_t tmp = isolate->computation_id(); 95 intptr_t tmp = isolate->computation_id();
93 isolate->set_computation_id(tmp + 1); 96 isolate->set_computation_id(tmp + 1);
94 return tmp; 97 return tmp;
95 } 98 }
96 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) { 99 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) {
97 if (isolate->ic_data_array() == Array::null()) { 100 if (isolate->ic_data_array() == Array::null()) {
98 return NULL; 101 return NULL;
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 : local_(local), context_level_(context_level) { 514 : local_(local), context_level_(context_level) {
512 inputs_[0] = value; 515 inputs_[0] = value;
513 } 516 }
514 517
515 DECLARE_COMPUTATION(StoreLocal) 518 DECLARE_COMPUTATION(StoreLocal)
516 519
517 const LocalVariable& local() const { return local_; } 520 const LocalVariable& local() const { return local_; }
518 Value* value() { return inputs_[0]; } 521 Value* value() { return inputs_[0]; }
519 intptr_t context_level() const { return context_level_; } 522 intptr_t context_level() const { return context_level_; }
520 523
524 virtual void RecordAssignedVars(BitVector* assigned_vars);
525
521 private: 526 private:
522 const LocalVariable& local_; 527 const LocalVariable& local_;
523 const intptr_t context_level_; 528 const intptr_t context_level_;
524 529
525 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp); 530 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp);
526 }; 531 };
527 532
528 533
529 class NativeCallComp : public TemplateComputation<0> { 534 class NativeCallComp : public TemplateComputation<0> {
530 public: 535 public:
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 virtual Instruction* StraightLineSuccessor() const = 0; 1190 virtual Instruction* StraightLineSuccessor() const = 0;
1186 virtual void SetSuccessor(Instruction* instr) = 0; 1191 virtual void SetSuccessor(Instruction* instr) = 0;
1187 1192
1188 // Discover basic-block structure by performing a recursive depth first 1193 // Discover basic-block structure by performing a recursive depth first
1189 // traversal of the instruction graph reachable from this instruction. As 1194 // traversal of the instruction graph reachable from this instruction. As
1190 // a side effect, the block entry instructions in the graph are assigned 1195 // a side effect, the block entry instructions in the graph are assigned
1191 // numbers in both preorder and postorder. The array 'preorder' maps 1196 // numbers in both preorder and postorder. The array 'preorder' maps
1192 // preorder block numbers to the block entry instruction with that number 1197 // preorder block numbers to the block entry instruction with that number
1193 // and analogously for the array 'postorder'. The depth first spanning 1198 // and analogously for the array 'postorder'. The depth first spanning
1194 // tree is recorded in the array 'parent', which maps preorder block 1199 // tree is recorded in the array 'parent', which maps preorder block
1195 // numbers to the preorder number of the block's spanning-tree parent. As 1200 // numbers to the preorder number of the block's spanning-tree parent.
1196 // a side effect of this function, the set of basic block predecessors 1201 // The array 'assigned_vars' maps preorder block numbers to the set of
1197 // (e.g., block entry instructions of predecessor blocks) and also the 1202 // assigned frame-allocated local variables in the block. As a side
1198 // last instruction in the block is recorded in each entry instruction. 1203 // effect of this function, the set of basic block predecessors (e.g.,
1204 // block entry instructions of predecessor blocks) and also the last
1205 // instruction in the block is recorded in each entry instruction.
1199 virtual void DiscoverBlocks( 1206 virtual void DiscoverBlocks(
1200 BlockEntryInstr* current_block, 1207 BlockEntryInstr* current_block,
1201 GrowableArray<BlockEntryInstr*>* preorder, 1208 GrowableArray<BlockEntryInstr*>* preorder,
1202 GrowableArray<BlockEntryInstr*>* postorder, 1209 GrowableArray<BlockEntryInstr*>* postorder,
1203 GrowableArray<intptr_t>* parent) { 1210 GrowableArray<intptr_t>* parent,
1211 GrowableArray<BitVector*>* assigned_vars,
1212 intptr_t variable_count) {
1204 // Never called for instructions except block entries and branches. 1213 // Never called for instructions except block entries and branches.
1205 UNREACHABLE(); 1214 UNREACHABLE();
1206 } 1215 }
1207 1216
1217 virtual void RecordAssignedVars(BitVector* assigned_vars);
1218
1208 #define INSTRUCTION_TYPE_CHECK(type) \ 1219 #define INSTRUCTION_TYPE_CHECK(type) \
1209 virtual bool Is##type() const { return false; } \ 1220 virtual bool Is##type() const { return false; } \
1210 virtual type##Instr* As##type() { return NULL; } 1221 virtual type##Instr* As##type() { return NULL; }
1211 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) 1222 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK)
1212 #undef INSTRUCTION_TYPE_CHECK 1223 #undef INSTRUCTION_TYPE_CHECK
1213 1224
1214 private: 1225 private:
1215 intptr_t cid_; 1226 intptr_t cid_;
1216 ICData* ic_data_; 1227 ICData* ic_data_;
1217 DISALLOW_COPY_AND_ASSIGN(Instruction); 1228 DISALLOW_COPY_AND_ASSIGN(Instruction);
1218 }; 1229 };
1219 1230
1220 1231
1221 // Basic block entries are administrative nodes. Joins are the only nodes 1232 // Basic block entries are administrative nodes. Joins are the only nodes
1222 // with multiple predecessors. Targets are the other basic block entries. 1233 // with multiple predecessors. Targets are the other basic block entries.
1223 // The types enforce edge-split form---joins are forbidden as the successors 1234 // The types enforce edge-split form---joins are forbidden as the successors
1224 // of branches. 1235 // of branches.
1225 class BlockEntryInstr : public Instruction { 1236 class BlockEntryInstr : public Instruction {
1226 public: 1237 public:
1227 virtual bool IsBlockEntry() const { return true; } 1238 virtual bool IsBlockEntry() const { return true; }
1228 1239
1229 virtual intptr_t PredecessorCount() const = 0; 1240 virtual intptr_t PredecessorCount() const = 0;
1230 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const = 0; 1241 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const = 0;
1242 virtual void AddPredecessor(BlockEntryInstr* predecessor) = 0;
1231 1243
1232 intptr_t preorder_number() const { return preorder_number_; } 1244 intptr_t preorder_number() const { return preorder_number_; }
1233 void set_preorder_number(intptr_t number) { preorder_number_ = number; } 1245 void set_preorder_number(intptr_t number) { preorder_number_ = number; }
1234 1246
1235 intptr_t postorder_number() const { return postorder_number_; } 1247 intptr_t postorder_number() const { return postorder_number_; }
1236 void set_postorder_number(intptr_t number) { postorder_number_ = number; } 1248 void set_postorder_number(intptr_t number) { postorder_number_ = number; }
1237 1249
1238 BlockEntryInstr* dominator() const { return dominator_; } 1250 BlockEntryInstr* dominator() const { return dominator_; }
1239 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; } 1251 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; }
1240 1252
1241 Instruction* last_instruction() const { return last_instruction_; } 1253 Instruction* last_instruction() const { return last_instruction_; }
1242 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; } 1254 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; }
1243 1255
1256 virtual void DiscoverBlocks(
Kevin Millikin (Google) 2012/05/11 10:39:00 All these arguments is a bad smell, I plan to refa
srdjan 2012/05/12 00:00:55 Sounds good.
1257 BlockEntryInstr* current_block,
1258 GrowableArray<BlockEntryInstr*>* preorder,
1259 GrowableArray<BlockEntryInstr*>* postorder,
1260 GrowableArray<intptr_t>* parent,
1261 GrowableArray<BitVector*>* assigned_vars,
1262 intptr_t variable_count);
1263
1244 protected: 1264 protected:
1245 BlockEntryInstr() 1265 BlockEntryInstr()
1246 : preorder_number_(-1), 1266 : preorder_number_(-1),
1247 postorder_number_(-1), 1267 postorder_number_(-1),
1248 dominator_(NULL), 1268 dominator_(NULL),
1249 last_instruction_(NULL) { } 1269 last_instruction_(NULL) { }
1250 1270
1251 private: 1271 private:
1252 intptr_t preorder_number_; 1272 intptr_t preorder_number_;
1253 intptr_t postorder_number_; 1273 intptr_t postorder_number_;
(...skipping 10 matching lines...) Expand all
1264 : BlockEntryInstr(), 1284 : BlockEntryInstr(),
1265 predecessors_(2), // Two is the assumed to be the common case. 1285 predecessors_(2), // Two is the assumed to be the common case.
1266 successor_(NULL) { } 1286 successor_(NULL) { }
1267 1287
1268 DECLARE_INSTRUCTION(JoinEntry) 1288 DECLARE_INSTRUCTION(JoinEntry)
1269 1289
1270 virtual intptr_t PredecessorCount() const { return predecessors_.length(); } 1290 virtual intptr_t PredecessorCount() const { return predecessors_.length(); }
1271 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { 1291 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const {
1272 return predecessors_[index]; 1292 return predecessors_[index];
1273 } 1293 }
1294 virtual void AddPredecessor(BlockEntryInstr* predecessor) {
1295 predecessors_.Add(predecessor);
1296 }
1274 1297
1275 virtual Instruction* StraightLineSuccessor() const { 1298 virtual Instruction* StraightLineSuccessor() const {
1276 return successor_; 1299 return successor_;
1277 } 1300 }
1278 virtual void SetSuccessor(Instruction* instr) { 1301 virtual void SetSuccessor(Instruction* instr) {
1279 ASSERT(successor_ == NULL); 1302 ASSERT(successor_ == NULL);
1280 successor_ = instr; 1303 successor_ = instr;
1281 } 1304 }
1282 1305
1283 virtual void DiscoverBlocks(
1284 BlockEntryInstr* current_block,
1285 GrowableArray<BlockEntryInstr*>* preorder,
1286 GrowableArray<BlockEntryInstr*>* postorder,
1287 GrowableArray<intptr_t>* parent);
1288
1289 private: 1306 private:
1290 ZoneGrowableArray<BlockEntryInstr*> predecessors_; 1307 ZoneGrowableArray<BlockEntryInstr*> predecessors_;
1291 Instruction* successor_; 1308 Instruction* successor_;
1292 1309
1293 DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr); 1310 DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr);
1294 }; 1311 };
1295 1312
1296 1313
1297 class TargetEntryInstr : public BlockEntryInstr { 1314 class TargetEntryInstr : public BlockEntryInstr {
1298 public: 1315 public:
(...skipping 12 matching lines...) Expand all
1311 1328
1312 DECLARE_INSTRUCTION(TargetEntry) 1329 DECLARE_INSTRUCTION(TargetEntry)
1313 1330
1314 virtual intptr_t PredecessorCount() const { 1331 virtual intptr_t PredecessorCount() const {
1315 return (predecessor_ == NULL) ? 0 : 1; 1332 return (predecessor_ == NULL) ? 0 : 1;
1316 } 1333 }
1317 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { 1334 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const {
1318 ASSERT((index == 0) && (predecessor_ != NULL)); 1335 ASSERT((index == 0) && (predecessor_ != NULL));
1319 return predecessor_; 1336 return predecessor_;
1320 } 1337 }
1338 virtual void AddPredecessor(BlockEntryInstr* predecessor) {
1339 ASSERT(predecessor_ == NULL);
1340 predecessor_ = predecessor;
1341 }
1321 1342
1322 virtual Instruction* StraightLineSuccessor() const { 1343 virtual Instruction* StraightLineSuccessor() const {
1323 return successor_; 1344 return successor_;
1324 } 1345 }
1325 virtual void SetSuccessor(Instruction* instr) { 1346 virtual void SetSuccessor(Instruction* instr) {
1326 ASSERT(successor_ == NULL); 1347 ASSERT(successor_ == NULL);
1327 successor_ = instr; 1348 successor_ = instr;
1328 } 1349 }
1329 1350
1330 virtual void DiscoverBlocks(
1331 BlockEntryInstr* current_block,
1332 GrowableArray<BlockEntryInstr*>* preorder,
1333 GrowableArray<BlockEntryInstr*>* postorder,
1334 GrowableArray<intptr_t>* parent);
1335
1336 bool HasTryIndex() const { 1351 bool HasTryIndex() const {
1337 return try_index_ != CatchClauseNode::kInvalidTryIndex; 1352 return try_index_ != CatchClauseNode::kInvalidTryIndex;
1338 } 1353 }
1339 1354
1340 intptr_t try_index() const { 1355 intptr_t try_index() const {
1341 ASSERT(HasTryIndex()); 1356 ASSERT(HasTryIndex());
1342 return try_index_; 1357 return try_index_;
1343 } 1358 }
1344 1359
1345 private: 1360 private:
(...skipping 15 matching lines...) Expand all
1361 Computation* computation() const { return computation_; } 1376 Computation* computation() const { return computation_; }
1362 1377
1363 virtual Instruction* StraightLineSuccessor() const { 1378 virtual Instruction* StraightLineSuccessor() const {
1364 return successor_; 1379 return successor_;
1365 } 1380 }
1366 virtual void SetSuccessor(Instruction* instr) { 1381 virtual void SetSuccessor(Instruction* instr) {
1367 ASSERT(successor_ == NULL); 1382 ASSERT(successor_ == NULL);
1368 successor_ = instr; 1383 successor_ = instr;
1369 } 1384 }
1370 1385
1386 virtual void RecordAssignedVars(BitVector* assigned_vars);
1387
1371 private: 1388 private:
1372 Computation* computation_; 1389 Computation* computation_;
1373 Instruction* successor_; 1390 Instruction* successor_;
1374 1391
1375 DISALLOW_COPY_AND_ASSIGN(DoInstr); 1392 DISALLOW_COPY_AND_ASSIGN(DoInstr);
1376 }; 1393 };
1377 1394
1378 1395
1379 class Definition : public Instruction { 1396 class Definition : public Instruction {
1380 public: 1397 public:
(...skipping 21 matching lines...) Expand all
1402 Computation* computation() const { return computation_; } 1419 Computation* computation() const { return computation_; }
1403 1420
1404 virtual Instruction* StraightLineSuccessor() const { 1421 virtual Instruction* StraightLineSuccessor() const {
1405 return successor_; 1422 return successor_;
1406 } 1423 }
1407 virtual void SetSuccessor(Instruction* instr) { 1424 virtual void SetSuccessor(Instruction* instr) {
1408 ASSERT(successor_ == NULL); 1425 ASSERT(successor_ == NULL);
1409 successor_ = instr; 1426 successor_ = instr;
1410 } 1427 }
1411 1428
1429 virtual void RecordAssignedVars(BitVector* assigned_vars);
1430
1412 private: 1431 private:
1413 Computation* computation_; 1432 Computation* computation_;
1414 Instruction* successor_; 1433 Instruction* successor_;
1415 1434
1416 DISALLOW_COPY_AND_ASSIGN(BindInstr); 1435 DISALLOW_COPY_AND_ASSIGN(BindInstr);
1417 }; 1436 };
1418 1437
1419 1438
1420 // The non-optimizing compiler assumes that there is exactly one use of 1439 // The non-optimizing compiler assumes that there is exactly one use of
1421 // every temporary so they can be deallocated at their use. Some AST nodes, 1440 // every temporary so they can be deallocated at their use. Some AST nodes,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 TargetEntryInstr** true_successor_address() { return &true_successor_; } 1622 TargetEntryInstr** true_successor_address() { return &true_successor_; }
1604 TargetEntryInstr** false_successor_address() { return &false_successor_; } 1623 TargetEntryInstr** false_successor_address() { return &false_successor_; }
1605 1624
1606 virtual Instruction* StraightLineSuccessor() const { return NULL; } 1625 virtual Instruction* StraightLineSuccessor() const { return NULL; }
1607 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } 1626 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); }
1608 1627
1609 virtual void DiscoverBlocks( 1628 virtual void DiscoverBlocks(
1610 BlockEntryInstr* current_block, 1629 BlockEntryInstr* current_block,
1611 GrowableArray<BlockEntryInstr*>* preorder, 1630 GrowableArray<BlockEntryInstr*>* preorder,
1612 GrowableArray<BlockEntryInstr*>* postorder, 1631 GrowableArray<BlockEntryInstr*>* postorder,
1613 GrowableArray<intptr_t>* parent); 1632 GrowableArray<intptr_t>* parent,
1633 GrowableArray<BitVector*>* assigned_vars,
1634 intptr_t variable_count);
1614 1635
1615 private: 1636 private:
1616 Value* value_; 1637 Value* value_;
1617 TargetEntryInstr* true_successor_; 1638 TargetEntryInstr* true_successor_;
1618 TargetEntryInstr* false_successor_; 1639 TargetEntryInstr* false_successor_;
1619 1640
1620 DISALLOW_COPY_AND_ASSIGN(BranchInstr); 1641 DISALLOW_COPY_AND_ASSIGN(BranchInstr);
1621 }; 1642 };
1622 1643
1623 #undef DECLARE_INSTRUCTION 1644 #undef DECLARE_INSTRUCTION
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 const GrowableArray<BlockEntryInstr*>& block_order_; 1681 const GrowableArray<BlockEntryInstr*>& block_order_;
1661 1682
1662 private: 1683 private:
1663 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 1684 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
1664 }; 1685 };
1665 1686
1666 1687
1667 } // namespace dart 1688 } // namespace dart
1668 1689
1669 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 1690 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698