Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "vm/block_scheduler.h" | 5 #include "vm/block_scheduler.h" |
| 6 | 6 |
| 7 #include "vm/allocation.h" | 7 #include "vm/allocation.h" |
| 8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 9 #include "vm/flow_graph.h" | 9 #include "vm/flow_graph.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DEFINE_FLAG(bool, emit_edge_counters, true, "Emit edge counters at targets."); | 13 DEFINE_FLAG(bool, emit_edge_counters, true, "Emit edge counters at targets."); |
| 14 | 14 |
| 15 // Compute the edge count at the deopt id of a TargetEntry or Goto. | 15 // Compute the edge count at the deopt id of a TargetEntry or Goto. |
|
srdjan
2015/09/23 19:24:43
s/deopt id/edge id/
Florian Schneider
2015/09/28 09:19:43
Done.
| |
| 16 static intptr_t ComputeEdgeCount( | 16 static intptr_t ComputeEdgeCount(const Array& edge_counters, intptr_t edge_id) { |
|
siva
2015/09/26 00:16:58
This function does not seem to compute anything wh
Florian Schneider
2015/09/28 09:19:43
Done.
| |
| 17 const Code& unoptimized_code, | |
| 18 const ZoneGrowableArray<uword>& deopt_id_pc_pairs, | |
| 19 intptr_t deopt_id) { | |
| 20 ASSERT(deopt_id != Isolate::kNoDeoptId); | |
| 21 | |
| 22 if (!FLAG_emit_edge_counters) { | 17 if (!FLAG_emit_edge_counters) { |
| 23 // Assume everything was visited once. | 18 // Assume everything was visited once. |
| 24 return 1; | 19 return 1; |
| 25 } | 20 } |
| 26 | 21 return Smi::Value(Smi::RawCast(edge_counters.At(edge_id))); |
| 27 for (intptr_t i = 0; i < deopt_id_pc_pairs.length(); i += 2) { | |
| 28 intptr_t deopt_id_entry = static_cast<intptr_t>(deopt_id_pc_pairs[i]); | |
| 29 uword pc = deopt_id_pc_pairs[i + 1]; | |
| 30 if (deopt_id_entry == deopt_id) { | |
| 31 Array& array = Array::Handle(); | |
| 32 array ^= CodePatcher::GetEdgeCounterAt(pc, unoptimized_code); | |
| 33 ASSERT(!array.IsNull()); | |
| 34 return Smi::Value(Smi::RawCast(array.At(0))); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 UNREACHABLE(); | |
| 39 return 1; | |
| 40 } | 22 } |
| 41 | 23 |
| 42 | 24 |
| 43 // There is an edge from instruction->successor. Set its weight (edge count | 25 // There is an edge from instruction->successor. Set its weight (edge count |
| 44 // per function entry). | 26 // per function entry). |
| 45 static void SetEdgeWeight(Instruction* instruction, | 27 static void SetEdgeWeight(BlockEntryInstr* block, |
| 46 BlockEntryInstr* successor, | 28 BlockEntryInstr* successor, |
| 47 const Code& unoptimized_code, | 29 const Array& edge_counters, |
| 48 const ZoneGrowableArray<uword>& deopt_id_pc_pairs, | |
| 49 intptr_t entry_count) { | 30 intptr_t entry_count) { |
| 50 TargetEntryInstr* target = successor->AsTargetEntry(); | 31 TargetEntryInstr* target = successor->AsTargetEntry(); |
| 51 if (target != NULL) { | 32 if (target != NULL) { |
| 52 // If this block ends in a goto, the edge count of this edge is the same | 33 // If this block ends in a goto, the edge count of this edge is the same |
| 53 // as the count on the single outgoing edge. This is true as long as the | 34 // as the count on the single outgoing edge. This is true as long as the |
| 54 // block does not throw an exception. | 35 // block does not throw an exception. |
| 55 GotoInstr* jump = target->last_instruction()->AsGoto(); | 36 intptr_t count = ComputeEdgeCount(edge_counters, target->preorder_number()); |
| 56 const intptr_t deopt_id = | |
| 57 (jump != NULL) ? jump->deopt_id() : target->deopt_id(); | |
| 58 intptr_t count = ComputeEdgeCount(unoptimized_code, | |
| 59 deopt_id_pc_pairs, | |
| 60 deopt_id); | |
| 61 if ((count >= 0) && (entry_count != 0)) { | 37 if ((count >= 0) && (entry_count != 0)) { |
| 62 double weight = | 38 double weight = |
| 63 static_cast<double>(count) / static_cast<double>(entry_count); | 39 static_cast<double>(count) / static_cast<double>(entry_count); |
| 64 target->set_edge_weight(weight); | 40 target->set_edge_weight(weight); |
| 65 } | 41 } |
| 66 } else { | 42 } else { |
| 67 GotoInstr* jump = instruction->AsGoto(); | 43 GotoInstr* jump = block->last_instruction()->AsGoto(); |
| 68 if (jump != NULL) { | 44 if (jump != NULL) { |
| 69 intptr_t count = ComputeEdgeCount(unoptimized_code, | 45 intptr_t count = |
| 70 deopt_id_pc_pairs, | 46 ComputeEdgeCount(edge_counters, block->preorder_number()); |
| 71 jump->deopt_id()); | |
| 72 if ((count >= 0) && (entry_count != 0)) { | 47 if ((count >= 0) && (entry_count != 0)) { |
| 73 double weight = | 48 double weight = |
| 74 static_cast<double>(count) / static_cast<double>(entry_count); | 49 static_cast<double>(count) / static_cast<double>(entry_count); |
| 75 jump->set_edge_weight(weight); | 50 jump->set_edge_weight(weight); |
| 76 } | 51 } |
| 77 } | 52 } |
| 78 } | 53 } |
| 79 } | 54 } |
| 80 | 55 |
| 81 | 56 |
| 82 void BlockScheduler::AssignEdgeWeights() const { | 57 void BlockScheduler::AssignEdgeWeights() const { |
| 83 if (!FLAG_emit_edge_counters) { | 58 if (!FLAG_emit_edge_counters) { |
| 84 return; | 59 return; |
| 85 } | 60 } |
| 86 const Code& unoptimized_code = flow_graph()->parsed_function().code(); | |
| 87 ASSERT(!unoptimized_code.IsNull()); | |
| 88 | 61 |
| 89 ZoneGrowableArray<uword>* deopt_id_pc_pairs = new ZoneGrowableArray<uword>(); | 62 const Array& ic_data_array = Array::Handle( |
|
srdjan
2015/09/23 19:24:43
flow_graph()->zone(),
Florian Schneider
2015/09/28 09:19:43
Done.
| |
| 90 const PcDescriptors& descriptors = | 63 flow_graph()->parsed_function().function().ic_data_array()); |
| 91 PcDescriptors::Handle(unoptimized_code.pc_descriptors()); | 64 Array& edge_counters = Array::Handle(); |
| 92 PcDescriptors::Iterator iter(descriptors, RawPcDescriptors::kDeopt); | 65 edge_counters ^= ic_data_array.At(0); |
| 93 uword entry = unoptimized_code.EntryPoint(); | |
| 94 while (iter.MoveNext()) { | |
| 95 intptr_t deopt_id = iter.DeoptId(); | |
| 96 ASSERT(deopt_id != Isolate::kNoDeoptId); | |
| 97 uint32_t pc_offset = iter.PcOffset(); | |
| 98 deopt_id_pc_pairs->Add(static_cast<uword>(deopt_id)); | |
| 99 deopt_id_pc_pairs->Add(entry + pc_offset); | |
| 100 } | |
| 101 | 66 |
| 102 intptr_t entry_count = | 67 intptr_t entry_count = ComputeEdgeCount( |
| 103 ComputeEdgeCount(unoptimized_code, | 68 edge_counters, |
| 104 *deopt_id_pc_pairs, | 69 flow_graph()->graph_entry()->normal_entry()->preorder_number()); |
| 105 flow_graph()->graph_entry()->normal_entry()->deopt_id()); | |
| 106 flow_graph()->graph_entry()->set_entry_count(entry_count); | 70 flow_graph()->graph_entry()->set_entry_count(entry_count); |
| 107 | 71 |
| 108 for (BlockIterator it = flow_graph()->reverse_postorder_iterator(); | 72 for (BlockIterator it = flow_graph()->reverse_postorder_iterator(); |
| 109 !it.Done(); | 73 !it.Done(); |
| 110 it.Advance()) { | 74 it.Advance()) { |
| 111 BlockEntryInstr* block = it.Current(); | 75 BlockEntryInstr* block = it.Current(); |
| 112 Instruction* last = block->last_instruction(); | 76 Instruction* last = block->last_instruction(); |
| 113 for (intptr_t i = 0; i < last->SuccessorCount(); ++i) { | 77 for (intptr_t i = 0; i < last->SuccessorCount(); ++i) { |
| 114 BlockEntryInstr* succ = last->SuccessorAt(i); | 78 BlockEntryInstr* succ = last->SuccessorAt(i); |
| 115 SetEdgeWeight(last, succ, | 79 SetEdgeWeight(block, succ, edge_counters, entry_count); |
| 116 unoptimized_code, *deopt_id_pc_pairs, entry_count); | |
| 117 } | 80 } |
| 118 } | 81 } |
| 119 } | 82 } |
| 120 | 83 |
| 121 | 84 |
| 122 // A weighted control-flow graph edge. | 85 // A weighted control-flow graph edge. |
| 123 struct Edge { | 86 struct Edge { |
| 124 Edge(BlockEntryInstr* source, BlockEntryInstr* target, double weight) | 87 Edge(BlockEntryInstr* source, BlockEntryInstr* target, double weight) |
| 125 : source(source), target(target), weight(weight) { } | 88 : source(source), target(target), weight(weight) { } |
| 126 | 89 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 for (intptr_t i = block_count - 1; i >= 0; --i) { | 205 for (intptr_t i = block_count - 1; i >= 0; --i) { |
| 243 if (chains[i]->first->block == flow_graph()->postorder()[i]) { | 206 if (chains[i]->first->block == flow_graph()->postorder()[i]) { |
| 244 for (Link* link = chains[i]->first; link != NULL; link = link->next) { | 207 for (Link* link = chains[i]->first; link != NULL; link = link->next) { |
| 245 flow_graph()->CodegenBlockOrder(true)->Add(link->block); | 208 flow_graph()->CodegenBlockOrder(true)->Add(link->block); |
| 246 } | 209 } |
| 247 } | 210 } |
| 248 } | 211 } |
| 249 } | 212 } |
| 250 | 213 |
| 251 } // namespace dart | 214 } // namespace dart |
| OLD | NEW |