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/flow_graph.h" | 9 #include "vm/flow_graph.h" |
9 | 10 |
10 namespace dart { | 11 namespace dart { |
11 | 12 |
12 // Compute the edge count at the deopt id of a TargetEntry or Goto. | 13 // Compute the edge count at the deopt id of a TargetEntry or Goto. |
13 static intptr_t ComputeEdgeCount(const Code& unoptimized_code, | 14 static intptr_t ComputeEdgeCount(const Code& unoptimized_code, |
14 intptr_t deopt_id) { | 15 intptr_t deopt_id) { |
15 ASSERT(deopt_id != Isolate::kNoDeoptId); | 16 ASSERT(deopt_id != Isolate::kNoDeoptId); |
16 | 17 |
17 // Intrinsified functions do not have edge counts, so give all edges equal | |
18 // weights. | |
19 if (unoptimized_code.pointer_offsets_length() == 0) return 1; | |
20 | |
21 uword pc = unoptimized_code.GetPcForDeoptId(deopt_id, PcDescriptors::kDeopt); | 18 uword pc = unoptimized_code.GetPcForDeoptId(deopt_id, PcDescriptors::kDeopt); |
22 Array& array = Array::Handle(); | 19 Array& array = Array::Handle(); |
23 // Pointer offsets are sorted in decreasing order. Find the first one | 20 array ^= CodePatcher::GetEdgeCounterAt(pc, unoptimized_code); |
24 // after the deopt id's pc. | |
25 // TODO(kmillikin): Use a more reliable way to find the counter. | |
26 for (intptr_t j = unoptimized_code.pointer_offsets_length() - 1; | |
27 j >= 0; | |
28 --j) { | |
29 uword addr = | |
30 unoptimized_code.GetPointerOffsetAt(j) + unoptimized_code.EntryPoint(); | |
31 if (addr > pc) { | |
32 array ^= *reinterpret_cast<RawObject**>(addr); | |
33 break; | |
34 } | |
35 } | |
36 ASSERT(!array.IsNull()); | 21 ASSERT(!array.IsNull()); |
37 return Smi::Value(Smi::RawCast(array.At(0))); | 22 return Smi::Value(Smi::RawCast(array.At(0))); |
38 } | 23 } |
39 | 24 |
40 | 25 |
41 // There is an edge from instruction->successor. Set its weight (edge count | 26 // There is an edge from instruction->successor. Set its weight (edge count |
42 // per function entry). | 27 // per function entry). |
43 static void SetEdgeWeight(Instruction* instruction, | 28 static void SetEdgeWeight(Instruction* instruction, |
44 BlockEntryInstr* successor, | 29 BlockEntryInstr* successor, |
45 const Code& unoptimized_code, | 30 const Code& unoptimized_code, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 186 |
202 Union(&chains, source_chain, target_chain); | 187 Union(&chains, source_chain, target_chain); |
203 } | 188 } |
204 | 189 |
205 // Build a new block order. Emit each chain when its first block occurs | 190 // Build a new block order. Emit each chain when its first block occurs |
206 // in the original reverse postorder ordering (which gives a topological | 191 // in the original reverse postorder ordering (which gives a topological |
207 // sort of the blocks). | 192 // sort of the blocks). |
208 for (intptr_t i = block_count - 1; i >= 0; --i) { | 193 for (intptr_t i = block_count - 1; i >= 0; --i) { |
209 if (chains[i]->first->block == flow_graph()->postorder()[i]) { | 194 if (chains[i]->first->block == flow_graph()->postorder()[i]) { |
210 for (Link* link = chains[i]->first; link != NULL; link = link->next) { | 195 for (Link* link = chains[i]->first; link != NULL; link = link->next) { |
211 flow_graph()->codegen_block_order(true)->Add(link->block); | 196 flow_graph()->CodegenBlockOrder(true)->Add(link->block); |
212 } | 197 } |
213 } | 198 } |
214 } | 199 } |
215 } | 200 } |
216 | 201 |
217 } // namespace dart | 202 } // namespace dart |
OLD | NEW |