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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/task.dart

Issue 1344173005: dart2js CPS: Small cleanup of the compilation pipeline. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
Index: pkg/compiler/lib/src/js_backend/codegen/task.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/task.dart b/pkg/compiler/lib/src/js_backend/codegen/task.dart
index bd52462019b4a03d1324b1ec01eed91cd7994e76..4bae7de618247d09c78626fde586b6063623092d 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/task.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/task.dart
@@ -84,10 +84,10 @@ class CpsFunctionCompiler implements FunctionCompiler {
if (tracer != null) {
tracer.traceCompilation(element.name, null);
}
- cps.FunctionDefinition cpsFunction = compileToCpsIR(element);
- cpsFunction = optimizeCpsIR(cpsFunction);
- tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction);
- treeFunction = optimizeTreeIR(treeFunction);
+ cps.FunctionDefinition cpsFunction = compileToCpsIr(element);
+ cpsFunction = optimizeCpsIr(cpsFunction);
+ tree_ir.FunctionDefinition treeFunction = compileToTreeIr(cpsFunction);
+ treeFunction = optimizeTreeIr(treeFunction);
return compileToJavaScript(work, treeFunction);
} on CodegenBailout catch (e) {
String message = "Unable to compile $element with the new compiler.\n"
@@ -107,23 +107,29 @@ class CpsFunctionCompiler implements FunctionCompiler {
}
}
- cps.FunctionDefinition compileToCpsIR(AstElement element) {
- cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element);
- if (cpsNode == null) {
+ void applyCpsPass(cps_opt.Pass pass, cps.FunctionDefinition cpsFunction) {
+ pass.rewrite(cpsFunction);
+ traceGraph(pass.passName, cpsFunction);
+ dumpTypedIr(pass.passName, cpsFunction);
+ assert(checkCpsIntegrity(cpsFunction));
+ }
+
+ cps.FunctionDefinition compileToCpsIr(AstElement element) {
+ cps.FunctionDefinition cpsFunction = irBuilderTask.buildNode(element);
+ if (cpsFunction == null) {
if (irBuilderTask.bailoutMessage == null) {
giveUp('unable to build cps definition of $element');
} else {
giveUp(irBuilderTask.bailoutMessage);
}
}
- traceGraph("IR Builder", cpsNode);
+ traceGraph('IR Builder', cpsFunction);
+ dumpTypedIr('IR Builder', cpsFunction);
// Eliminating redundant phis before the unsugaring pass will make it
// insert fewer getInterceptor calls.
- new RedundantPhiEliminator().rewrite(cpsNode);
- traceGraph("Redundant phi elimination", cpsNode);
- new UnsugarVisitor(glue).rewrite(cpsNode);
- traceGraph("Unsugaring", cpsNode);
- return cpsNode;
+ applyCpsPass(new RedundantPhiEliminator(), cpsFunction);
+ applyCpsPass(new UnsugarVisitor(glue), cpsFunction);
+ return cpsFunction;
}
static const Pattern PRINT_TYPED_IR_FILTER = null;
@@ -143,10 +149,9 @@ class CpsFunctionCompiler implements FunctionCompiler {
throw 'unsupported: $type';
}
- void dumpTypedIR(cps.FunctionDefinition cpsNode,
- TypePropagator typePropagator) {
+ void dumpTypedIr(String passName, cps.FunctionDefinition cpsFunction) {
if (PRINT_TYPED_IR_FILTER != null &&
- PRINT_TYPED_IR_FILTER.matchAsPrefix(cpsNode.element.name) != null) {
+ PRINT_TYPED_IR_FILTER.matchAsPrefix(cpsFunction.element.name) != null) {
String printType(nodeOrRef, String s) {
cps.Node node = nodeOrRef is cps.Reference
? nodeOrRef.definition
@@ -156,7 +161,8 @@ class CpsFunctionCompiler implements FunctionCompiler {
: s;
}
DEBUG_MODE = true;
- print(new SExpressionStringifier(printType).visit(cpsNode));
+ print(';;; ==== After $passName ====');
+ print(new SExpressionStringifier(printType).visit(cpsFunction));
}
}
@@ -165,38 +171,28 @@ class CpsFunctionCompiler implements FunctionCompiler {
return true; // So this can be used from assert().
}
- cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) {
- // Transformations on the CPS IR.
- void applyCpsPass(cps_opt.Pass pass) {
- pass.rewrite(cpsNode);
- traceGraph(pass.passName, cpsNode);
- assert(checkCpsIntegrity(cpsNode));
- }
-
+ cps.FunctionDefinition optimizeCpsIr(cps.FunctionDefinition cpsFunction) {
TypeMaskSystem typeSystem = new TypeMaskSystem(compiler);
- applyCpsPass(new RedundantJoinEliminator());
- applyCpsPass(new RedundantPhiEliminator());
- applyCpsPass(new InsertRefinements(typeSystem));
- TypePropagator typePropagator =
- new TypePropagator(compiler, typeSystem, this);
- applyCpsPass(typePropagator);
- dumpTypedIR(cpsNode, typePropagator);
- applyCpsPass(new RemoveRefinements());
- applyCpsPass(new ShrinkingReducer());
- applyCpsPass(new ScalarReplacer(compiler));
- applyCpsPass(new MutableVariableEliminator());
- applyCpsPass(new RedundantJoinEliminator());
- applyCpsPass(new RedundantPhiEliminator());
- applyCpsPass(new ShrinkingReducer());
- applyCpsPass(new LoopInvariantCodeMotion());
- applyCpsPass(new ShareInterceptors());
- applyCpsPass(new ShrinkingReducer());
-
- return cpsNode;
+ applyCpsPass(new RedundantJoinEliminator(), cpsFunction);
+ applyCpsPass(new RedundantPhiEliminator(), cpsFunction);
+ applyCpsPass(new InsertRefinements(typeSystem), cpsFunction);
+ applyCpsPass(new TypePropagator(compiler, typeSystem, this), cpsFunction);
+ applyCpsPass(new RemoveRefinements(), cpsFunction);
+ applyCpsPass(new ShrinkingReducer(), cpsFunction);
+ applyCpsPass(new ScalarReplacer(compiler), cpsFunction);
+ applyCpsPass(new MutableVariableEliminator(), cpsFunction);
+ applyCpsPass(new RedundantJoinEliminator(), cpsFunction);
+ applyCpsPass(new RedundantPhiEliminator(), cpsFunction);
+ applyCpsPass(new ShrinkingReducer(), cpsFunction);
+ applyCpsPass(new LoopInvariantCodeMotion(), cpsFunction);
+ applyCpsPass(new ShareInterceptors(), cpsFunction);
+ applyCpsPass(new ShrinkingReducer(), cpsFunction);
+
+ return cpsFunction;
}
- tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) {
+ tree_ir.FunctionDefinition compileToTreeIr(cps.FunctionDefinition cpsNode) {
tree_builder.Builder builder = new tree_builder.Builder(
compiler.internalError);
tree_ir.FunctionDefinition treeNode = builder.buildFunction(cpsNode);
@@ -211,7 +207,7 @@ class CpsFunctionCompiler implements FunctionCompiler {
return true; // So this can be used from assert().
}
- tree_ir.FunctionDefinition optimizeTreeIR(tree_ir.FunctionDefinition node) {
+ tree_ir.FunctionDefinition optimizeTreeIr(tree_ir.FunctionDefinition node) {
void applyTreePass(tree_opt.Pass pass) {
pass.rewrite(node);
traceGraph(pass.passName, node);
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/unsugar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698