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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 11819031: Add canonicalize optimization for branches. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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/intermediate_language.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language.cc
===================================================================
--- runtime/vm/intermediate_language.cc (revision 16916)
+++ runtime/vm/intermediate_language.cc (working copy)
@@ -26,6 +26,7 @@
"Propagate IC data from unoptimized to optimized IC calls.");
DECLARE_FLAG(bool, enable_type_checks);
DECLARE_FLAG(int, max_polymorphic_checks);
+DECLARE_FLAG(bool, trace_optimization);
Definition::Definition()
: range_(NULL),
@@ -1686,6 +1687,43 @@
return this;
}
+
+Instruction* BranchInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
+ // Only handle strict-compares.
+ if (comparison()->IsStrictCompare()) {
+ Definition* replacement = comparison()->Canonicalize(optimizer);
+ if (replacement == comparison() || replacement == NULL) return this;
+ ComparisonInstr* comp = replacement->AsComparison();
+ if (comp == NULL) return this;
+
+ // Replace the comparison if the replacement is used at this branch,
+ // and has exactly one use.
+ if ((comp->input_use_list()->instruction() == this) &&
+ (comp->input_use_list()->next_use() == NULL) &&
+ (comp->env_use_list() == NULL)) {
+ comp->RemoveFromGraph();
+ // It is safe to pass a NULL iterator because we're replacing the
+ // comparison wrapped in a BranchInstr which does not modify the
+ // linked list of instructions.
+ ReplaceWith(comp, NULL /* ignored */);
+ for (intptr_t i = 0; i < comp->InputCount(); ++i) {
+ Value* operand = comp->InputAt(i);
+ operand->set_instruction(this);
+ }
+ if (FLAG_trace_optimization) {
+ OS::Print("Merging comparison v%"Pd"\n", comp->ssa_temp_index());
+ }
+ // Clear the comparison's use list, temp index and ssa temp index since
+ // the value of the comparison is not used outside the branch anymore.
+ comp->set_input_use_list(NULL);
+ comp->ClearSSATempIndex();
+ comp->ClearTempIndex();
+ }
+ }
+ return this;
+}
+
+
Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
if (!right()->BindsToConstant()) return this;
const Object& right_constant = right()->BoundConstant();
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698