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

Side by Side Diff: runtime/vm/branch_optimizer.cc

Issue 2896903002: Shuffle around deopt id allocation to give the flow graph builder a chance to record other data as … (Closed)
Patch Set: format Created 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/branch_optimizer.h" 5 #include "vm/branch_optimizer.h"
6 6
7 #include "vm/flow_graph.h" 7 #include "vm/flow_graph.h"
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 (block->phis()->length() == 1); 59 (block->phis()->length() == 1);
60 } 60 }
61 61
62 62
63 JoinEntryInstr* BranchSimplifier::ToJoinEntry(Zone* zone, 63 JoinEntryInstr* BranchSimplifier::ToJoinEntry(Zone* zone,
64 TargetEntryInstr* target) { 64 TargetEntryInstr* target) {
65 // Convert a target block into a join block. Branches will be duplicated 65 // Convert a target block into a join block. Branches will be duplicated
66 // so the former true and false targets become joins of the control flows 66 // so the former true and false targets become joins of the control flows
67 // from all the duplicated branches. 67 // from all the duplicated branches.
68 JoinEntryInstr* join = 68 JoinEntryInstr* join =
69 new (zone) JoinEntryInstr(target->block_id(), target->try_index()); 69 new (zone) JoinEntryInstr(target->block_id(), target->try_index(),
70 Thread::Current()->GetNextDeoptId());
Vyacheslav Egorov (Google) 2017/05/23 12:00:00 This can be Thread::kNoDeoptId because we copy the
70 join->InheritDeoptTarget(zone, target); 71 join->InheritDeoptTarget(zone, target);
71 join->LinkTo(target->next()); 72 join->LinkTo(target->next());
72 join->set_last_instruction(target->last_instruction()); 73 join->set_last_instruction(target->last_instruction());
73 target->UnuseAllInputs(); 74 target->UnuseAllInputs();
74 return join; 75 return join;
75 } 76 }
76 77
77 78
78 BranchInstr* BranchSimplifier::CloneBranch(Zone* zone, 79 BranchInstr* BranchSimplifier::CloneBranch(Zone* zone,
79 BranchInstr* branch, 80 BranchInstr* branch,
80 Value* new_left, 81 Value* new_left,
81 Value* new_right) { 82 Value* new_right) {
82 ComparisonInstr* comparison = branch->comparison(); 83 ComparisonInstr* comparison = branch->comparison();
83 ComparisonInstr* new_comparison = 84 ComparisonInstr* new_comparison =
84 comparison->CopyWithNewOperands(new_left, new_right); 85 comparison->CopyWithNewOperands(new_left, new_right);
85 BranchInstr* new_branch = new (zone) BranchInstr(new_comparison); 86 BranchInstr* new_branch = new (zone)
87 BranchInstr(new_comparison, Thread::Current()->GetNextDeoptId());
Vyacheslav Egorov (Google) 2017/05/23 12:00:00 This should probably be Thread::kNoDeoptId (e.g.
86 return new_branch; 88 return new_branch;
87 } 89 }
88 90
89 91
90 void BranchSimplifier::Simplify(FlowGraph* flow_graph) { 92 void BranchSimplifier::Simplify(FlowGraph* flow_graph) {
91 // Optimize some branches that test the value of a phi. When it is safe 93 // Optimize some branches that test the value of a phi. When it is safe
92 // to do so, push the branch to each of the predecessor blocks. This is 94 // to do so, push the branch to each of the predecessor blocks. This is
93 // an optimization when (a) it can avoid materializing a boolean object at 95 // an optimization when (a) it can avoid materializing a boolean object at
94 // the phi only to test its value, and (b) it can expose opportunities for 96 // the phi only to test its value, and (b) it can expose opportunities for
95 // constant propagation and unreachable code elimination. This 97 // constant propagation and unreachable code elimination. This
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 old_goto->UnuseAllInputs(); 178 old_goto->UnuseAllInputs();
177 179
178 // Update the predecessor block. We may have created another 180 // Update the predecessor block. We may have created another
179 // instance of the pattern so add it to the worklist if necessary. 181 // instance of the pattern so add it to the worklist if necessary.
180 BlockEntryInstr* branch_block = new_branch->GetBlock(); 182 BlockEntryInstr* branch_block = new_branch->GetBlock();
181 branch_block->set_last_instruction(new_branch); 183 branch_block->set_last_instruction(new_branch);
182 if (branch_block->IsJoinEntry()) worklist.Add(branch_block); 184 if (branch_block->IsJoinEntry()) worklist.Add(branch_block);
183 185
184 // Connect the branch to the true and false joins, via empty target 186 // Connect the branch to the true and false joins, via empty target
185 // blocks. 187 // blocks.
186 TargetEntryInstr* true_target = new (zone) TargetEntryInstr( 188 TargetEntryInstr* true_target = new (zone)
187 flow_graph->max_block_id() + 1, block->try_index()); 189 TargetEntryInstr(flow_graph->max_block_id() + 1, block->try_index(),
190 Thread::Current()->GetNextDeoptId());
Vyacheslav Egorov (Google) 2017/05/23 12:00:01 kNoDeoptId here, because it is overwritten anyway
188 true_target->InheritDeoptTarget(zone, join_true); 191 true_target->InheritDeoptTarget(zone, join_true);
189 TargetEntryInstr* false_target = new (zone) TargetEntryInstr( 192 TargetEntryInstr* false_target = new (zone)
190 flow_graph->max_block_id() + 2, block->try_index()); 193 TargetEntryInstr(flow_graph->max_block_id() + 2, block->try_index(),
Vyacheslav Egorov (Google) 2017/05/23 12:00:01 ditto
194 Thread::Current()->GetNextDeoptId());
191 false_target->InheritDeoptTarget(zone, join_false); 195 false_target->InheritDeoptTarget(zone, join_false);
192 flow_graph->set_max_block_id(flow_graph->max_block_id() + 2); 196 flow_graph->set_max_block_id(flow_graph->max_block_id() + 2);
193 *new_branch->true_successor_address() = true_target; 197 *new_branch->true_successor_address() = true_target;
194 *new_branch->false_successor_address() = false_target; 198 *new_branch->false_successor_address() = false_target;
195 GotoInstr* goto_true = new (zone) GotoInstr(join_true); 199 GotoInstr* goto_true = new (zone)
200 GotoInstr(join_true, Thread::Current()->GetNextDeoptId());
Vyacheslav Egorov (Google) 2017/05/23 12:00:00 ditto
196 goto_true->InheritDeoptTarget(zone, join_true); 201 goto_true->InheritDeoptTarget(zone, join_true);
197 true_target->LinkTo(goto_true); 202 true_target->LinkTo(goto_true);
198 true_target->set_last_instruction(goto_true); 203 true_target->set_last_instruction(goto_true);
199 GotoInstr* goto_false = new (zone) GotoInstr(join_false); 204 GotoInstr* goto_false = new (zone)
205 GotoInstr(join_false, Thread::Current()->GetNextDeoptId());
Vyacheslav Egorov (Google) 2017/05/23 12:00:01 ditto
200 goto_false->InheritDeoptTarget(zone, join_false); 206 goto_false->InheritDeoptTarget(zone, join_false);
201 false_target->LinkTo(goto_false); 207 false_target->LinkTo(goto_false);
202 false_target->set_last_instruction(goto_false); 208 false_target->set_last_instruction(goto_false);
203 } 209 }
204 // When all predecessors have been rewritten, the original block is 210 // When all predecessors have been rewritten, the original block is
205 // unreachable from the graph. 211 // unreachable from the graph.
206 phi->UnuseAllInputs(); 212 phi->UnuseAllInputs();
207 branch->UnuseAllInputs(); 213 branch->UnuseAllInputs();
208 block->UnuseAllInputs(); 214 block->UnuseAllInputs();
209 ASSERT(!phi->HasUses()); 215 ASSERT(!phi->HasUses());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // Check if the platform supports efficient branchless IfThenElseInstr 295 // Check if the platform supports efficient branchless IfThenElseInstr
290 // for the given combination of comparison and values flowing from 296 // for the given combination of comparison and values flowing from
291 // false and true paths. 297 // false and true paths.
292 if (IfThenElseInstr::Supports(comparison, v1, v2)) { 298 if (IfThenElseInstr::Supports(comparison, v1, v2)) {
293 Value* if_true = (pred1 == branch->true_successor()) ? v1 : v2; 299 Value* if_true = (pred1 == branch->true_successor()) ? v1 : v2;
294 Value* if_false = (pred2 == branch->true_successor()) ? v1 : v2; 300 Value* if_false = (pred2 == branch->true_successor()) ? v1 : v2;
295 301
296 ComparisonInstr* new_comparison = comparison->CopyWithNewOperands( 302 ComparisonInstr* new_comparison = comparison->CopyWithNewOperands(
297 comparison->left()->Copy(zone), comparison->right()->Copy(zone)); 303 comparison->left()->Copy(zone), comparison->right()->Copy(zone));
298 IfThenElseInstr* if_then_else = new (zone) IfThenElseInstr( 304 IfThenElseInstr* if_then_else = new (zone) IfThenElseInstr(
299 new_comparison, if_true->Copy(zone), if_false->Copy(zone)); 305 new_comparison, if_true->Copy(zone), if_false->Copy(zone),
306 Thread::Current()->GetNextDeoptId());
Vyacheslav Egorov (Google) 2017/05/23 12:00:00 I think this should be Thread::kNoDeoptId because
300 flow_graph->InsertBefore(branch, if_then_else, NULL, 307 flow_graph->InsertBefore(branch, if_then_else, NULL,
301 FlowGraph::kValue); 308 FlowGraph::kValue);
302 309
303 phi->ReplaceUsesWith(if_then_else); 310 phi->ReplaceUsesWith(if_then_else);
304 311
305 // Connect IfThenElseInstr to the first instruction in the merge block 312 // Connect IfThenElseInstr to the first instruction in the merge block
306 // effectively eliminating diamond control flow. 313 // effectively eliminating diamond control flow.
307 // Current block as well as pred1 and pred2 blocks are no longer in 314 // Current block as well as pred1 and pred2 blocks are no longer in
308 // the graph at this point. 315 // the graph at this point.
309 if_then_else->LinkTo(join->next()); 316 if_then_else->LinkTo(join->next());
(...skipping 25 matching lines...) Expand all
335 if (changed) { 342 if (changed) {
336 // We may have changed the block order and the dominator tree. 343 // We may have changed the block order and the dominator tree.
337 flow_graph->DiscoverBlocks(); 344 flow_graph->DiscoverBlocks();
338 GrowableArray<BitVector*> dominance_frontier; 345 GrowableArray<BitVector*> dominance_frontier;
339 flow_graph->ComputeDominators(&dominance_frontier); 346 flow_graph->ComputeDominators(&dominance_frontier);
340 } 347 }
341 } 348 }
342 349
343 350
344 } // namespace dart 351 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698