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

Unified Diff: lib/compiler/implementation/ssa/optimize.dart

Issue 10539156: Track fields which are known to be always set to integer constants (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed second round of comments Created 8 years, 6 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 | « lib/compiler/implementation/ssa/nodes.dart ('k') | lib/compiler/implementation/universe.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/optimize.dart
diff --git a/lib/compiler/implementation/ssa/optimize.dart b/lib/compiler/implementation/ssa/optimize.dart
index 79deacf0a2e6a60de79240522fd98b00cfc158dd..3e7405fa1828b7ef27dce927c272ba4d51d6cebb 100644
--- a/lib/compiler/implementation/ssa/optimize.dart
+++ b/lib/compiler/implementation/ssa/optimize.dart
@@ -36,7 +36,8 @@ class SsaOptimizerTask extends CompilerTask {
new SsaDeadPhiEliminator(),
new SsaGlobalValueNumberer(compiler),
new SsaCodeMotion(),
- new SsaDeadCodeEliminator()];
+ new SsaDeadCodeEliminator(),
+ new SsaProcessRecompileCandidates(backend, work)];
runPhases(graph, phases);
});
}
@@ -1171,3 +1172,67 @@ class SsaTypeConversionInserter extends HBaseVisitor
}
}
}
+
+class SsaProcessRecompileCandidates
+ extends HBaseVisitor implements OptimizationPhase {
+ final String name = "SsaProcessRecompileCandidates";
+ final JavaScriptBackend backend;
+ final WorkItem work;
+ HGraph graph;
+ Compiler get compiler() => backend.compiler;
+
+ SsaProcessRecompileCandidates(this.backend, this.work);
+
+ void visitGraph(HGraph visitee) {
+ graph = visitee;
+ visitDominatorTree(visitee);
+ }
+
+ HInstruction visitEquals(HEquals node) {
+ // Try to optimize the case where a field which is known to always be an
+ // integer is compared with a constant integer literal.
+ if (node.left is HFieldGet &&
+ node.right is HConstant &&
+ node.right.isInteger()) {
+ HFieldGet left = node.left;
+ HConstant right = node.right;
+ if (left.element != null) {
+ Type type = left.receiver.propagatedType.computeType(compiler);
+ switch (compiler.phase) {
+ case Compiler.PHASE_COMPILING:
+ if (compiler.codegenWorld.couldHaveFieldOnlyIntegerSetters(
+ type, left.element.name) &&
+ compiler.codegenWorld.hasFieldOnlyIntegerInitializers(
+ type, left.element.name)) {
+ compiler.enqueuer.codegen.registerRecompilationCandidate(
+ work.element);
+ }
+ break;
+ case Compiler.PHASE_RECOMPILING:
+ if (compiler.codegenWorld.hasFieldOnlyIntegerSetters(
+ type, left.element.name) &&
+ compiler.codegenWorld.hasFieldOnlyIntegerInitializers(
+ type, left.element.name)) {
+ if (compiler.codegenWorld.hasInvokedSetter(left.element,
+ compiler)) {
+ // If there are invoked setters we don't know for sure that the
+ // field will hold an integer, but the fact that the class
+ // itself always sets an integer in the fiels is still a strong
+ // signal to indiate the expected type of the field.
+ left.propagatedType = HType.INTEGER;
+ graph.highTypeLikelyhood = true;
+ } else {
+ // If there are no invoked setters we know the type of this
+ // field for sure.
+ left.guaranteedType = HType.INTEGER;
+ }
+ }
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ }
+}
« no previous file with comments | « lib/compiler/implementation/ssa/nodes.dart ('k') | lib/compiler/implementation/universe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698