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

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

Issue 285483002: More general dead phi elimination. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "vm/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/cpu.h" 9 #include "vm/cpu.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 7250 matching lines...) Expand 10 before | Expand all | Expand 10 after
7261 }; 7261 };
7262 7262
7263 7263
7264 void DeadStoreElimination::Optimize(FlowGraph* graph) { 7264 void DeadStoreElimination::Optimize(FlowGraph* graph) {
7265 if (FLAG_dead_store_elimination) { 7265 if (FLAG_dead_store_elimination) {
7266 StoreOptimizer::OptimizeGraph(graph); 7266 StoreOptimizer::OptimizeGraph(graph);
7267 } 7267 }
7268 } 7268 }
7269 7269
7270 7270
7271 void DeadCodeElimination::EliminateDeadPhis(FlowGraph* flow_graph) {
7272 GrowableArray<PhiInstr*> live_phis;
7273 for (BlockIterator b = flow_graph->postorder_iterator();
7274 !b.Done();
7275 b.Advance()) {
7276 JoinEntryInstr* join = b.Current()->AsJoinEntry();
7277 if (join != NULL) {
7278 for (PhiIterator it(join); !it.Done(); it.Advance()) {
7279 PhiInstr* phi = it.Current();
7280 // Phis that have uses and phis inside try blocks are
7281 // marked as live.
7282 if (phi->HasUses() || join->InsideTryBlock()) {
7283 live_phis.Add(phi);
7284 phi->mark_alive();
7285 } else {
7286 phi->mark_dead();
7287 }
7288 }
7289 }
7290 }
7291
7292 while (!live_phis.is_empty()) {
7293 PhiInstr* phi = live_phis.RemoveLast();
7294 for (intptr_t i = 0; i < phi->InputCount(); i++) {
7295 Value* val = phi->InputAt(i);
7296 PhiInstr* used_phi = val->definition()->AsPhi();
7297 if ((used_phi != NULL) && !used_phi->is_alive()) {
7298 used_phi->mark_alive();
7299 live_phis.Add(used_phi);
7300 }
7301 }
7302 }
7303
7304 for (BlockIterator it(flow_graph->postorder_iterator());
7305 !it.Done();
7306 it.Advance()) {
7307 JoinEntryInstr* join = it.Current()->AsJoinEntry();
7308 if (join != NULL) {
srdjan 2014/05/12 21:21:44 if ((join != NULL ) && (join->phis_ != NULL)) {
7309 if (join->phis_ == NULL) continue;
7310
7311 // Eliminate dead phis and compact the phis_ array of the block.
7312 intptr_t to_index = 0;
7313 for (intptr_t i = 0; i < join->phis_->length(); ++i) {
7314 PhiInstr* phi = (*join->phis_)[i];
7315 if (phi != NULL) {
7316 if (!phi->is_alive()) {
7317 phi->ReplaceUsesWith(flow_graph->constant_null());
7318 phi->UnuseAllInputs();
7319 (*join->phis_)[i] = NULL;
7320 if (FLAG_trace_optimization) {
7321 OS::Print("Removing dead phi v%" Pd "\n", phi->ssa_temp_index());
7322 }
7323 } else if (phi->IsRedundant()) {
7324 phi->ReplaceUsesWith(phi->InputAt(0)->definition());
7325 phi->UnuseAllInputs();
7326 (*join->phis_)[i] = NULL;
7327 if (FLAG_trace_optimization) {
7328 OS::Print("Removing redundant phi v%" Pd "\n",
7329 phi->ssa_temp_index());
7330 }
7331 } else {
7332 (*join->phis_)[to_index++] = phi;
7333 }
7334 }
7335 }
7336 if (to_index == 0) {
7337 join->phis_ = NULL;
7338 } else {
7339 join->phis_->TruncateTo(to_index);
7340 }
7341 }
7342 }
7343 }
7344
7345
7271 class CSEInstructionMap : public ValueObject { 7346 class CSEInstructionMap : public ValueObject {
7272 public: 7347 public:
7273 // Right now CSE and LICM track a single effect: possible externalization of 7348 // Right now CSE and LICM track a single effect: possible externalization of
7274 // strings. 7349 // strings.
7275 // Other effects like modifications of fields are tracked in a separate load 7350 // Other effects like modifications of fields are tracked in a separate load
7276 // forwarding pass via Alias structure. 7351 // forwarding pass via Alias structure.
7277 COMPILE_ASSERT(EffectSet::kLastEffect == 1, single_effect_is_tracked); 7352 COMPILE_ASSERT(EffectSet::kLastEffect == 1, single_effect_is_tracked);
7278 7353
7279 CSEInstructionMap() : independent_(), dependent_() { } 7354 CSEInstructionMap() : independent_(), dependent_() { }
7280 explicit CSEInstructionMap(const CSEInstructionMap& other) 7355 explicit CSEInstructionMap(const CSEInstructionMap& other)
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
8765 } 8840 }
8766 8841
8767 8842
8768 void ConstantPropagator::Transform() { 8843 void ConstantPropagator::Transform() {
8769 if (FLAG_trace_constant_propagation) { 8844 if (FLAG_trace_constant_propagation) {
8770 OS::Print("\n==== Before constant propagation ====\n"); 8845 OS::Print("\n==== Before constant propagation ====\n");
8771 FlowGraphPrinter printer(*graph_); 8846 FlowGraphPrinter printer(*graph_);
8772 printer.PrintBlocks(); 8847 printer.PrintBlocks();
8773 } 8848 }
8774 8849
8775 GrowableArray<PhiInstr*> redundant_phis(10);
8776
8777 // We will recompute dominators, block ordering, block ids, block last 8850 // We will recompute dominators, block ordering, block ids, block last
8778 // instructions, previous pointers, predecessors, etc. after eliminating 8851 // instructions, previous pointers, predecessors, etc. after eliminating
8779 // unreachable code. We do not maintain those properties during the 8852 // unreachable code. We do not maintain those properties during the
8780 // transformation. 8853 // transformation.
8781 for (BlockIterator b = graph_->reverse_postorder_iterator(); 8854 for (BlockIterator b = graph_->reverse_postorder_iterator();
8782 !b.Done(); 8855 !b.Done();
8783 b.Advance()) { 8856 b.Advance()) {
8784 BlockEntryInstr* block = b.Current(); 8857 BlockEntryInstr* block = b.Current();
8785 if (!reachable_->Contains(block->preorder_number())) { 8858 if (!reachable_->Contains(block->preorder_number())) {
8786 if (FLAG_trace_constant_propagation) { 8859 if (FLAG_trace_constant_propagation) {
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
9518 } 9591 }
9519 9592
9520 // Insert materializations at environment uses. 9593 // Insert materializations at environment uses.
9521 for (intptr_t i = 0; i < exits.length(); i++) { 9594 for (intptr_t i = 0; i < exits.length(); i++) {
9522 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *slots); 9595 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *slots);
9523 } 9596 }
9524 } 9597 }
9525 9598
9526 9599
9527 } // namespace dart 9600 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698