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

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

Issue 18111006: Collect edge count profiling data and reorder basic blocks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 GrowableArray<BlockEntryInstr*>* preorder, 1142 GrowableArray<BlockEntryInstr*>* preorder,
1143 GrowableArray<BlockEntryInstr*>* postorder, 1143 GrowableArray<BlockEntryInstr*>* postorder,
1144 GrowableArray<intptr_t>* parent, 1144 GrowableArray<intptr_t>* parent,
1145 intptr_t variable_count, 1145 intptr_t variable_count,
1146 intptr_t fixed_parameter_count); 1146 intptr_t fixed_parameter_count);
1147 1147
1148 // Perform a depth first search to prune code not reachable from an OSR 1148 // Perform a depth first search to prune code not reachable from an OSR
1149 // entry point. 1149 // entry point.
1150 bool PruneUnreachable(FlowGraphBuilder* builder, 1150 bool PruneUnreachable(FlowGraphBuilder* builder,
1151 GraphEntryInstr* graph_entry, 1151 GraphEntryInstr* graph_entry,
1152 Instruction* parent,
1152 intptr_t osr_id, 1153 intptr_t osr_id,
1153 BitVector* block_marks); 1154 BitVector* block_marks);
1154 1155
1155 virtual intptr_t InputCount() const { return 0; } 1156 virtual intptr_t InputCount() const { return 0; }
1156 virtual Value* InputAt(intptr_t i) const { 1157 virtual Value* InputAt(intptr_t i) const {
1157 UNREACHABLE(); 1158 UNREACHABLE();
1158 return NULL; 1159 return NULL;
1159 } 1160 }
1160 1161
1161 virtual intptr_t ArgumentCount() const { return 0; } 1162 virtual intptr_t ArgumentCount() const { return 0; }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1308
1308 CatchBlockEntryInstr* GetCatchEntry(intptr_t index); 1309 CatchBlockEntryInstr* GetCatchEntry(intptr_t index);
1309 1310
1310 GrowableArray<Definition*>* initial_definitions() { 1311 GrowableArray<Definition*>* initial_definitions() {
1311 return &initial_definitions_; 1312 return &initial_definitions_;
1312 } 1313 }
1313 ConstantInstr* constant_null(); 1314 ConstantInstr* constant_null();
1314 1315
1315 bool IsCompiledForOsr() const { return osr_id_ != Isolate::kNoDeoptId; } 1316 bool IsCompiledForOsr() const { return osr_id_ != Isolate::kNoDeoptId; }
1316 1317
1318 intptr_t entry_count() const { return entry_count_; }
1319 void set_entry_count(intptr_t count) { entry_count_ = count; }
1320
1317 intptr_t spill_slot_count() const { return spill_slot_count_; } 1321 intptr_t spill_slot_count() const { return spill_slot_count_; }
1318 void set_spill_slot_count(intptr_t count) { 1322 void set_spill_slot_count(intptr_t count) {
1319 ASSERT(count >= 0); 1323 ASSERT(count >= 0);
1320 spill_slot_count_ = count; 1324 spill_slot_count_ = count;
1321 } 1325 }
1322 1326
1323 // Number of stack slots reserved for compiling try-catch. For functions 1327 // Number of stack slots reserved for compiling try-catch. For functions
1324 // without try-catch, this is 0. Otherwise, it is the number of local 1328 // without try-catch, this is 0. Otherwise, it is the number of local
1325 // variables. 1329 // variables.
1326 intptr_t fixed_slot_count() const { return fixed_slot_count_; } 1330 intptr_t fixed_slot_count() const { return fixed_slot_count_; }
(...skipping 15 matching lines...) Expand all
1342 1346
1343 private: 1347 private:
1344 virtual void ClearPredecessors() {} 1348 virtual void ClearPredecessors() {}
1345 virtual void AddPredecessor(BlockEntryInstr* predecessor) { UNREACHABLE(); } 1349 virtual void AddPredecessor(BlockEntryInstr* predecessor) { UNREACHABLE(); }
1346 1350
1347 const ParsedFunction& parsed_function_; 1351 const ParsedFunction& parsed_function_;
1348 TargetEntryInstr* normal_entry_; 1352 TargetEntryInstr* normal_entry_;
1349 GrowableArray<CatchBlockEntryInstr*> catch_entries_; 1353 GrowableArray<CatchBlockEntryInstr*> catch_entries_;
1350 GrowableArray<Definition*> initial_definitions_; 1354 GrowableArray<Definition*> initial_definitions_;
1351 const intptr_t osr_id_; 1355 const intptr_t osr_id_;
1356 intptr_t entry_count_;
1352 intptr_t spill_slot_count_; 1357 intptr_t spill_slot_count_;
1353 intptr_t fixed_slot_count_; // For try-catch in optimized code. 1358 intptr_t fixed_slot_count_; // For try-catch in optimized code.
1354 1359
1355 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); 1360 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr);
1356 }; 1361 };
1357 1362
1358 1363
1359 class JoinEntryInstr : public BlockEntryInstr { 1364 class JoinEntryInstr : public BlockEntryInstr {
1360 public: 1365 public:
1361 JoinEntryInstr(intptr_t block_id, intptr_t try_index) 1366 JoinEntryInstr(intptr_t block_id, intptr_t try_index)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 1430
1426 private: 1431 private:
1427 ZoneGrowableArray<PhiInstr*>* phis_; 1432 ZoneGrowableArray<PhiInstr*>* phis_;
1428 intptr_t index_; 1433 intptr_t index_;
1429 }; 1434 };
1430 1435
1431 1436
1432 class TargetEntryInstr : public BlockEntryInstr { 1437 class TargetEntryInstr : public BlockEntryInstr {
1433 public: 1438 public:
1434 TargetEntryInstr(intptr_t block_id, intptr_t try_index) 1439 TargetEntryInstr(intptr_t block_id, intptr_t try_index)
1435 : BlockEntryInstr(block_id, try_index), predecessor_(NULL) { } 1440 : BlockEntryInstr(block_id, try_index),
1441 predecessor_(NULL),
1442 edge_weight_(0.0) {
1443 }
1436 1444
1437 DECLARE_INSTRUCTION(TargetEntry) 1445 DECLARE_INSTRUCTION(TargetEntry)
1438 1446
1447 double edge_weight() const { return edge_weight_; }
1448 void set_edge_weight(double weight) { edge_weight_ = weight; }
1449 void adjust_edge_weight(double scale_factor) { edge_weight_ *= scale_factor; }
1450
1439 virtual intptr_t PredecessorCount() const { 1451 virtual intptr_t PredecessorCount() const {
1440 return (predecessor_ == NULL) ? 0 : 1; 1452 return (predecessor_ == NULL) ? 0 : 1;
1441 } 1453 }
1442 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { 1454 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const {
1443 ASSERT((index == 0) && (predecessor_ != NULL)); 1455 ASSERT((index == 0) && (predecessor_ != NULL));
1444 return predecessor_; 1456 return predecessor_;
1445 } 1457 }
1446 1458
1447 virtual void PrintTo(BufferFormatter* f) const; 1459 virtual void PrintTo(BufferFormatter* f) const;
1448 1460
1449 private: 1461 private:
1450 friend class BlockEntryInstr; // Access to predecessor_ when inlining. 1462 friend class BlockEntryInstr; // Access to predecessor_ when inlining.
1451 1463
1452 virtual void ClearPredecessors() { predecessor_ = NULL; } 1464 virtual void ClearPredecessors() { predecessor_ = NULL; }
1453 virtual void AddPredecessor(BlockEntryInstr* predecessor) { 1465 virtual void AddPredecessor(BlockEntryInstr* predecessor) {
1454 ASSERT(predecessor_ == NULL); 1466 ASSERT(predecessor_ == NULL);
1455 predecessor_ = predecessor; 1467 predecessor_ = predecessor;
1456 } 1468 }
1457 1469
1458 BlockEntryInstr* predecessor_; 1470 BlockEntryInstr* predecessor_;
1471 double edge_weight_;
1459 1472
1460 DISALLOW_COPY_AND_ASSIGN(TargetEntryInstr); 1473 DISALLOW_COPY_AND_ASSIGN(TargetEntryInstr);
1461 }; 1474 };
1462 1475
1463 1476
1464 class CatchBlockEntryInstr : public BlockEntryInstr { 1477 class CatchBlockEntryInstr : public BlockEntryInstr {
1465 public: 1478 public:
1466 CatchBlockEntryInstr(intptr_t block_id, 1479 CatchBlockEntryInstr(intptr_t block_id,
1467 intptr_t try_index, 1480 intptr_t try_index,
1468 const Array& handler_types, 1481 const Array& handler_types,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 Definition(); 1532 Definition();
1520 1533
1521 virtual Definition* AsDefinition() { return this; } 1534 virtual Definition* AsDefinition() { return this; }
1522 1535
1523 bool IsComparison() { return (AsComparison() != NULL); } 1536 bool IsComparison() { return (AsComparison() != NULL); }
1524 virtual ComparisonInstr* AsComparison() { return NULL; } 1537 virtual ComparisonInstr* AsComparison() { return NULL; }
1525 1538
1526 // Overridden by definitions that push arguments. 1539 // Overridden by definitions that push arguments.
1527 virtual intptr_t ArgumentCount() const { return 0; } 1540 virtual intptr_t ArgumentCount() const { return 0; }
1528 1541
1542 // Overridden by definitions that have call counts.
1543 virtual intptr_t CallCount() const {
1544 UNREACHABLE();
1545 return -1;
1546 }
1547
1529 intptr_t temp_index() const { return temp_index_; } 1548 intptr_t temp_index() const { return temp_index_; }
1530 void set_temp_index(intptr_t index) { temp_index_ = index; } 1549 void set_temp_index(intptr_t index) { temp_index_ = index; }
1531 void ClearTempIndex() { temp_index_ = -1; } 1550 void ClearTempIndex() { temp_index_ = -1; }
1532 1551
1533 intptr_t ssa_temp_index() const { return ssa_temp_index_; } 1552 intptr_t ssa_temp_index() const { return ssa_temp_index_; }
1534 void set_ssa_temp_index(intptr_t index) { 1553 void set_ssa_temp_index(intptr_t index) {
1535 ASSERT(index >= 0); 1554 ASSERT(index >= 0);
1536 ASSERT(is_used()); 1555 ASSERT(is_used());
1537 ssa_temp_index_ = index; 1556 ssa_temp_index_ = index;
1538 } 1557 }
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 const intptr_t token_pos_; 1955 const intptr_t token_pos_;
1937 1956
1938 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); 1957 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr);
1939 }; 1958 };
1940 1959
1941 1960
1942 class GotoInstr : public TemplateInstruction<0> { 1961 class GotoInstr : public TemplateInstruction<0> {
1943 public: 1962 public:
1944 explicit GotoInstr(JoinEntryInstr* entry) 1963 explicit GotoInstr(JoinEntryInstr* entry)
1945 : successor_(entry), 1964 : successor_(entry),
1946 parallel_move_(NULL) { } 1965 edge_weight_(0.0),
1966 parallel_move_(NULL) {
1967 }
1947 1968
1948 DECLARE_INSTRUCTION(Goto) 1969 DECLARE_INSTRUCTION(Goto)
1949 1970
1950 virtual intptr_t ArgumentCount() const { return 0; } 1971 virtual intptr_t ArgumentCount() const { return 0; }
1951 1972
1952 JoinEntryInstr* successor() const { return successor_; } 1973 JoinEntryInstr* successor() const { return successor_; }
1953 void set_successor(JoinEntryInstr* successor) { successor_ = successor; } 1974 void set_successor(JoinEntryInstr* successor) { successor_ = successor; }
1954 virtual intptr_t SuccessorCount() const; 1975 virtual intptr_t SuccessorCount() const;
1955 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; 1976 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const;
1956 1977
1978 double edge_weight() const { return edge_weight_; }
1979 void set_edge_weight(double weight) { edge_weight_ = weight; }
1980 void adjust_edge_weight(double scale_factor) { edge_weight_ *= scale_factor; }
1981
1957 virtual bool CanBecomeDeoptimizationTarget() const { 1982 virtual bool CanBecomeDeoptimizationTarget() const {
1958 // Goto instruction can be used as a deoptimization target when LICM 1983 // Goto instruction can be used as a deoptimization target when LICM
1959 // hoists instructions out of the loop. 1984 // hoists instructions out of the loop.
1960 return true; 1985 return true;
1961 } 1986 }
1962 1987
1963 virtual bool CanDeoptimize() const { return false; } 1988 virtual bool CanDeoptimize() const { return false; }
1964 1989
1965 virtual EffectSet Effects() const { return EffectSet::None(); } 1990 virtual EffectSet Effects() const { return EffectSet::None(); }
1966 1991
(...skipping 11 matching lines...) Expand all
1978 } 2003 }
1979 return parallel_move_; 2004 return parallel_move_;
1980 } 2005 }
1981 2006
1982 virtual void PrintTo(BufferFormatter* f) const; 2007 virtual void PrintTo(BufferFormatter* f) const;
1983 2008
1984 virtual bool MayThrow() const { return false; } 2009 virtual bool MayThrow() const { return false; }
1985 2010
1986 private: 2011 private:
1987 JoinEntryInstr* successor_; 2012 JoinEntryInstr* successor_;
2013 double edge_weight_;
1988 2014
1989 // Parallel move that will be used by linear scan register allocator to 2015 // Parallel move that will be used by linear scan register allocator to
1990 // connect live ranges at the end of the block and resolve phis. 2016 // connect live ranges at the end of the block and resolve phis.
1991 ParallelMoveInstr* parallel_move_; 2017 ParallelMoveInstr* parallel_move_;
1992 }; 2018 };
1993 2019
1994 2020
1995 class ControlInstruction : public Instruction { 2021 class ControlInstruction : public Instruction {
1996 public: 2022 public:
1997 ControlInstruction() : true_successor_(NULL), false_successor_(NULL) { } 2023 ControlInstruction() : true_successor_(NULL), false_successor_(NULL) { }
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 DECLARE_INSTRUCTION(ClosureCall) 2571 DECLARE_INSTRUCTION(ClosureCall)
2546 2572
2547 const Array& argument_names() const { return ast_node_.arguments()->names(); } 2573 const Array& argument_names() const { return ast_node_.arguments()->names(); }
2548 intptr_t token_pos() const { return ast_node_.token_pos(); } 2574 intptr_t token_pos() const { return ast_node_.token_pos(); }
2549 2575
2550 virtual intptr_t ArgumentCount() const { return arguments_->length(); } 2576 virtual intptr_t ArgumentCount() const { return arguments_->length(); }
2551 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { 2577 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const {
2552 return (*arguments_)[index]; 2578 return (*arguments_)[index];
2553 } 2579 }
2554 2580
2581 // TODO(kmillikin): implement exact call counts for closure calls.
2582 virtual intptr_t CallCount() const { return 1; }
2583
2555 virtual void PrintOperandsTo(BufferFormatter* f) const; 2584 virtual void PrintOperandsTo(BufferFormatter* f) const;
2556 2585
2557 virtual bool CanDeoptimize() const { return true; } 2586 virtual bool CanDeoptimize() const { return true; }
2558 2587
2559 virtual EffectSet Effects() const { return EffectSet::All(); } 2588 virtual EffectSet Effects() const { return EffectSet::All(); }
2560 2589
2561 virtual bool MayThrow() const { return true; } 2590 virtual bool MayThrow() const { return true; }
2562 2591
2563 private: 2592 private:
2564 const ClosureCallNode& ast_node_; 2593 const ClosureCallNode& ast_node_;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 InstanceCallInstr* instance_call() const { return instance_call_; } 2686 InstanceCallInstr* instance_call() const { return instance_call_; }
2658 bool with_checks() const { return with_checks_; } 2687 bool with_checks() const { return with_checks_; }
2659 2688
2660 virtual intptr_t ArgumentCount() const { 2689 virtual intptr_t ArgumentCount() const {
2661 return instance_call()->ArgumentCount(); 2690 return instance_call()->ArgumentCount();
2662 } 2691 }
2663 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { 2692 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const {
2664 return instance_call()->PushArgumentAt(index); 2693 return instance_call()->PushArgumentAt(index);
2665 } 2694 }
2666 2695
2696 virtual intptr_t CallCount() const { return ic_data().AggregateCount(); }
2697
2667 DECLARE_INSTRUCTION(PolymorphicInstanceCall) 2698 DECLARE_INSTRUCTION(PolymorphicInstanceCall)
2668 2699
2669 const ICData& ic_data() const { return ic_data_; } 2700 const ICData& ic_data() const { return ic_data_; }
2670 2701
2671 virtual bool CanDeoptimize() const { return true; } 2702 virtual bool CanDeoptimize() const { return true; }
2672 2703
2673 virtual EffectSet Effects() const { return EffectSet::All(); } 2704 virtual EffectSet Effects() const { return EffectSet::All(); }
2674 2705
2675 virtual void PrintOperandsTo(BufferFormatter* f) const; 2706 virtual void PrintOperandsTo(BufferFormatter* f) const;
2676 2707
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
3068 // Accessors forwarded to the AST node. 3099 // Accessors forwarded to the AST node.
3069 const Function& function() const { return function_; } 3100 const Function& function() const { return function_; }
3070 const Array& argument_names() const { return argument_names_; } 3101 const Array& argument_names() const { return argument_names_; }
3071 intptr_t token_pos() const { return token_pos_; } 3102 intptr_t token_pos() const { return token_pos_; }
3072 3103
3073 virtual intptr_t ArgumentCount() const { return arguments_->length(); } 3104 virtual intptr_t ArgumentCount() const { return arguments_->length(); }
3074 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { 3105 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const {
3075 return (*arguments_)[index]; 3106 return (*arguments_)[index];
3076 } 3107 }
3077 3108
3109 virtual intptr_t CallCount() const { return ic_data()->AggregateCount(); }
3110
3078 virtual void PrintOperandsTo(BufferFormatter* f) const; 3111 virtual void PrintOperandsTo(BufferFormatter* f) const;
3079 3112
3080 virtual bool CanDeoptimize() const { return true; } 3113 virtual bool CanDeoptimize() const { return true; }
3081 3114
3082 virtual EffectSet Effects() const { return EffectSet::All(); } 3115 virtual EffectSet Effects() const { return EffectSet::All(); }
3083 3116
3084 void set_result_cid(intptr_t value) { result_cid_ = value; } 3117 void set_result_cid(intptr_t value) { result_cid_ = value; }
3085 3118
3086 bool is_known_list_constructor() const { return is_known_list_constructor_; } 3119 bool is_known_list_constructor() const { return is_known_list_constructor_; }
3087 void set_is_known_list_constructor(bool value) { 3120 void set_is_known_list_constructor(bool value) {
(...skipping 3384 matching lines...) Expand 10 before | Expand all | Expand 10 after
6472 ForwardInstructionIterator* current_iterator_; 6505 ForwardInstructionIterator* current_iterator_;
6473 6506
6474 private: 6507 private:
6475 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 6508 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
6476 }; 6509 };
6477 6510
6478 6511
6479 } // namespace dart 6512 } // namespace dart
6480 6513
6481 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 6514 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698