Chromium Code Reviews| Index: runtime/vm/block_scheduler.cc |
| diff --git a/runtime/vm/block_scheduler.cc b/runtime/vm/block_scheduler.cc |
| index 1e2dd98bdba09e131d3b397243ee6e6809695c52..5161502ca310f589b9aa568f887b9a2072f52f4c 100644 |
| --- a/runtime/vm/block_scheduler.cc |
| +++ b/runtime/vm/block_scheduler.cc |
| @@ -13,20 +13,32 @@ namespace dart { |
| DEFINE_FLAG(bool, emit_edge_counters, true, "Emit edge counters at targets."); |
| // Compute the edge count at the deopt id of a TargetEntry or Goto. |
| -static intptr_t ComputeEdgeCount(const Code& unoptimized_code, |
| - intptr_t deopt_id) { |
| +static intptr_t ComputeEdgeCount( |
| + const Code& unoptimized_code, |
| + const ZoneGrowableArray<uword>& deopt_id_pc_pairs, |
| + intptr_t deopt_id) { |
| ASSERT(deopt_id != Isolate::kNoDeoptId); |
| if (!FLAG_emit_edge_counters) { |
| // Assume everything was visited once. |
| return 1; |
| } |
| - const uword pc = |
| - unoptimized_code.GetPcForDeoptId(deopt_id, RawPcDescriptors::kDeopt); |
| - Array& array = Array::Handle(); |
| - array ^= CodePatcher::GetEdgeCounterAt(pc, unoptimized_code); |
| - ASSERT(!array.IsNull()); |
| - return Smi::Value(Smi::RawCast(array.At(0))); |
| + |
| + intptr_t n = deopt_id_pc_pairs.length(); |
| + intptr_t i = 0; |
| + while (i < n) { |
|
Florian Schneider
2015/05/18 11:33:28
I'd turn this into a for-loop.
rmacnak
2015/05/18 18:03:54
Done.
|
| + intptr_t deopt_id_entry = static_cast<intptr_t>(deopt_id_pc_pairs[i++]); |
| + uword pc = deopt_id_pc_pairs[i++]; |
| + if (deopt_id_entry == deopt_id) { |
| + Array& array = Array::Handle(); |
| + array ^= CodePatcher::GetEdgeCounterAt(pc, unoptimized_code); |
| + ASSERT(!array.IsNull()); |
| + return Smi::Value(Smi::RawCast(array.At(0))); |
| + } |
| + } |
| + |
| + UNREACHABLE(); |
| + return 1; |
| } |
| @@ -35,6 +47,7 @@ static intptr_t ComputeEdgeCount(const Code& unoptimized_code, |
| static void SetEdgeWeight(Instruction* instruction, |
| BlockEntryInstr* successor, |
| const Code& unoptimized_code, |
| + const ZoneGrowableArray<uword>& deopt_id_pc_pairs, |
| intptr_t entry_count) { |
| TargetEntryInstr* target = successor->AsTargetEntry(); |
| if (target != NULL) { |
| @@ -44,7 +57,9 @@ static void SetEdgeWeight(Instruction* instruction, |
| GotoInstr* jump = target->last_instruction()->AsGoto(); |
| const intptr_t deopt_id = |
| (jump != NULL) ? jump->deopt_id() : target->deopt_id(); |
| - intptr_t count = ComputeEdgeCount(unoptimized_code, deopt_id); |
| + intptr_t count = ComputeEdgeCount(unoptimized_code, |
| + deopt_id_pc_pairs, |
| + deopt_id); |
| if ((count >= 0) && (entry_count != 0)) { |
| double weight = |
| static_cast<double>(count) / static_cast<double>(entry_count); |
| @@ -53,7 +68,9 @@ static void SetEdgeWeight(Instruction* instruction, |
| } else { |
| GotoInstr* jump = instruction->AsGoto(); |
| if (jump != NULL) { |
| - intptr_t count = ComputeEdgeCount(unoptimized_code, jump->deopt_id()); |
| + intptr_t count = ComputeEdgeCount(unoptimized_code, |
| + deopt_id_pc_pairs, |
| + jump->deopt_id()); |
| if ((count >= 0) && (entry_count != 0)) { |
| double weight = |
| static_cast<double>(count) / static_cast<double>(entry_count); |
| @@ -68,8 +85,22 @@ void BlockScheduler::AssignEdgeWeights() const { |
| const Code& unoptimized_code = flow_graph()->parsed_function().code(); |
| ASSERT(!unoptimized_code.IsNull()); |
| + ZoneGrowableArray<uword>* deopt_id_pc_pairs = new ZoneGrowableArray<uword>(); |
|
Florian Schneider
2015/05/18 11:33:28
I wonder if using DirectChainedHashMap from hash_m
rmacnak
2015/05/18 18:03:54
I'll take a look.
|
| + const PcDescriptors& descriptors = |
| + PcDescriptors::Handle(unoptimized_code.pc_descriptors()); |
| + PcDescriptors::Iterator iter(descriptors, RawPcDescriptors::kDeopt); |
| + uword entry = unoptimized_code.EntryPoint(); |
| + while (iter.MoveNext()) { |
| + intptr_t deopt_id = iter.DeoptId(); |
| + ASSERT(deopt_id != Isolate::kNoDeoptId); |
| + uint32_t pc_offset = iter.PcOffset(); |
| + deopt_id_pc_pairs->Add(static_cast<uword>(deopt_id)); |
| + deopt_id_pc_pairs->Add(entry + pc_offset); |
| + } |
| + |
| intptr_t entry_count = |
| ComputeEdgeCount(unoptimized_code, |
| + *deopt_id_pc_pairs, |
| flow_graph()->graph_entry()->normal_entry()->deopt_id()); |
| flow_graph()->graph_entry()->set_entry_count(entry_count); |
| @@ -80,7 +111,8 @@ void BlockScheduler::AssignEdgeWeights() const { |
| Instruction* last = block->last_instruction(); |
| for (intptr_t i = 0; i < last->SuccessorCount(); ++i) { |
| BlockEntryInstr* succ = last->SuccessorAt(i); |
| - SetEdgeWeight(last, succ, unoptimized_code, entry_count); |
| + SetEdgeWeight(last, succ, |
| + unoptimized_code, *deopt_id_pc_pairs, entry_count); |
| } |
| } |
| } |