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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 10872035: Add a simple dominator based redundancy elimination. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/hash_map.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_optimizer.cc
===================================================================
--- runtime/vm/flow_graph_optimizer.cc (revision 11221)
+++ runtime/vm/flow_graph_optimizer.cc (working copy)
@@ -955,29 +955,45 @@
}
-void LocalCSE::Optimize() {
- for (intptr_t i = 0; i < blocks_.length(); ++i) {
- BlockEntryInstr* entry = blocks_[i];
- DirectChainedHashMap<BindInstr*> map;
- ASSERT(map.IsEmpty());
- for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) {
- BindInstr* instr = it.Current()->AsBind();
- if (instr == NULL || instr->computation()->HasSideEffect()) continue;
- BindInstr* result = map.Lookup(instr);
- if (result == NULL) {
- map.Insert(instr);
- continue;
- }
- // Replace current with lookup result.
- instr->ReplaceUsesWith(result);
- it.RemoveCurrentFromGraph();
- if (FLAG_trace_optimization) {
- OS::Print("Replacing v%d with v%d\n",
- instr->ssa_temp_index(),
- result->ssa_temp_index());
- }
+void DominatorBasedCSE::Optimize(BlockEntryInstr* graph_entry) {
+ ASSERT(graph_entry->IsGraphEntry());
+ DirectChainedHashMap<BindInstr*> map;
+ OptimizeRecursive(graph_entry, &map);
+}
+
+
+void DominatorBasedCSE::OptimizeRecursive(
+ BlockEntryInstr* block,
+ DirectChainedHashMap<BindInstr*>* map) {
+ for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
+ BindInstr* instr = it.Current()->AsBind();
+ if (instr == NULL || instr->computation()->HasSideEffect()) continue;
+ BindInstr* result = map->Lookup(instr);
+ if (result == NULL) {
+ map->Insert(instr);
+ continue;
}
+ // Replace current with lookup result.
+ instr->ReplaceUsesWith(result);
+ it.RemoveCurrentFromGraph();
+ if (FLAG_trace_optimization) {
+ OS::Print("Replacing v%d with v%d\n",
+ instr->ssa_temp_index(),
+ result->ssa_temp_index());
+ }
}
+
+ // Process children in the dominator tree recursively.
+ intptr_t num_children = block->dominated_blocks().length();
+ for (intptr_t i = 0; i < num_children; ++i) {
+ BlockEntryInstr* child = block->dominated_blocks()[i];
+ if (i < num_children - 1) {
Kevin Millikin (Google) 2012/08/23 13:12:39 There's an extra space here for some reason.
Florian Schneider 2012/08/23 13:17:50 Done.
+ DirectChainedHashMap<BindInstr*> child_map(*map); // Copy map.
+ OptimizeRecursive(child, &child_map);
+ } else {
+ OptimizeRecursive(child, map); // Reuse map for the last child.
+ }
+ }
}
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/hash_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698