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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2324213003: build kernel for the entire program after resolution (Closed)
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
9 import '../common/tasks.dart' show CompilerTask; 9 import '../common/tasks.dart' show CompilerTask;
10 import '../compiler.dart'; 10 import '../compiler.dart';
(...skipping 19 matching lines...) Expand all
30 String get name => 'SSA kernel builder'; 30 String get name => 'SSA kernel builder';
31 31
32 SsaKernelBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) 32 SsaKernelBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory)
33 : backend = backend, 33 : backend = backend,
34 super(backend.compiler.measurer); 34 super(backend.compiler.measurer);
35 35
36 HGraph build(CodegenWorkItem work) { 36 HGraph build(CodegenWorkItem work) {
37 return measure(() { 37 return measure(() {
38 AstElement element = work.element.implementation; 38 AstElement element = work.element.implementation;
39 TreeElements treeElements = work.resolvedAst.elements; 39 TreeElements treeElements = work.resolvedAst.elements;
40 Kernel kernel = new Kernel(backend.compiler); 40 // Kernel kernel = new Kernel(backend.compiler);
Siggi Cherem (dart-lang) 2016/09/09 22:49:23 delete?
Harry Terkelsen 2016/09/09 22:56:47 Done.
41 KernelVisitor visitor = new KernelVisitor(element, treeElements, kernel); 41 // KernelVisitor visitor = new KernelVisitor(element, treeElements, kernel) ;
42 IrFunction function; 42 // IrFunction function;
43 try { 43 // try {
44 function = visitor.buildFunction(); 44 // function = visitor.buildFunction();
45 } catch (e) { 45 // } catch (e) {
46 throw "Failed to convert to Kernel IR: $e"; 46 // throw "Failed to convert to Kernel IR: $e";
47 } 47 // }
48 Kernel kernel = backend.kernelTask.kernel;
49 ir.Procedure function = kernel.functions[element];
48 KernelSsaBuilder builder = new KernelSsaBuilder( 50 KernelSsaBuilder builder = new KernelSsaBuilder(
49 function, 51 function,
50 element, 52 element,
51 work.resolvedAst, 53 work.resolvedAst,
52 backend.compiler, 54 backend.compiler,
53 work.registry, 55 work.registry,
54 sourceInformationFactory, 56 sourceInformationFactory,
55 visitor,
56 kernel); 57 kernel);
57 return builder.build(); 58 return builder.build();
58 }); 59 });
59 } 60 }
60 } 61 }
61 62
62 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { 63 class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
63 final IrFunction function; 64 final ir.Procedure function;
64 final FunctionElement functionElement; 65 final FunctionElement functionElement;
65 final ResolvedAst resolvedAst; 66 final ResolvedAst resolvedAst;
66 final Compiler compiler; 67 final Compiler compiler;
67 final CodegenRegistry registry; 68 final CodegenRegistry registry;
68 69
69 JavaScriptBackend get backend => compiler.backend; 70 JavaScriptBackend get backend => compiler.backend;
70 71
71 SourceInformationBuilder sourceInformationBuilder; 72 SourceInformationBuilder sourceInformationBuilder;
72 KernelAstAdapter astAdapter; 73 KernelAstAdapter astAdapter;
73 74
74 KernelSsaBuilder( 75 KernelSsaBuilder(
75 this.function, 76 this.function,
76 this.functionElement, 77 this.functionElement,
77 this.resolvedAst, 78 this.resolvedAst,
78 this.compiler, 79 this.compiler,
79 this.registry, 80 this.registry,
80 SourceInformationStrategy sourceInformationFactory, 81 SourceInformationStrategy sourceInformationFactory,
81 KernelVisitor visitor,
82 Kernel kernel) { 82 Kernel kernel) {
83 graph.element = functionElement; 83 graph.element = functionElement;
84 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? 84 // TODO(het): Should sourceInformationBuilder be in GraphBuilder?
85 this.sourceInformationBuilder = 85 this.sourceInformationBuilder =
86 sourceInformationFactory.createBuilderForContext(resolvedAst); 86 sourceInformationFactory.createBuilderForContext(resolvedAst);
87 graph.sourceInformation = 87 graph.sourceInformation =
88 sourceInformationBuilder.buildVariableDeclaration(); 88 sourceInformationBuilder.buildVariableDeclaration();
89 this.localsHandler = 89 this.localsHandler =
90 new LocalsHandler(this, functionElement, null, compiler); 90 new LocalsHandler(this, functionElement, null, compiler);
91 this.astAdapter = new KernelAstAdapter( 91 this.astAdapter = new KernelAstAdapter(
92 compiler.backend, 92 compiler.backend,
93 resolvedAst, 93 resolvedAst,
94 visitor.nodeToAst, 94 kernel.nodeToAst,
95 visitor.nodeToElement, 95 kernel.nodeToElement,
96 kernel.functions, 96 kernel.functions,
97 kernel.classes, 97 kernel.classes,
98 kernel.libraries); 98 kernel.libraries);
99 } 99 }
100 100
101 HGraph build() { 101 HGraph build() {
102 // TODO(het): no reason to do this here... 102 // TODO(het): no reason to do this here...
103 HInstruction.idCounter = 0; 103 HInstruction.idCounter = 0;
104 if (function.kind == ir.ProcedureKind.Method || 104 if (function.kind == ir.ProcedureKind.Method ||
105 function.kind == ir.ProcedureKind.Operator) { 105 function.kind == ir.ProcedureKind.Operator) {
(...skipping 19 matching lines...) Expand all
125 125
126 // TODO(het): This implementation is shared with [SsaBuilder]. Should we just 126 // TODO(het): This implementation is shared with [SsaBuilder]. Should we just
127 // allow [GraphBuilder] to access `compiler`? 127 // allow [GraphBuilder] to access `compiler`?
128 @override 128 @override
129 pushCheckNull(HInstruction expression) { 129 pushCheckNull(HInstruction expression) {
130 push(new HIdentity( 130 push(new HIdentity(
131 expression, graph.addConstantNull(compiler), null, backend.boolType)); 131 expression, graph.addConstantNull(compiler), null, backend.boolType));
132 } 132 }
133 133
134 /// Builds a SSA graph for [method]. 134 /// Builds a SSA graph for [method].
135 void buildMethod(IrFunction method, FunctionElement functionElement) { 135 void buildMethod(ir.Procedure method, FunctionElement functionElement) {
136 openFunction(method, functionElement); 136 openFunction(functionElement);
137 method.node.body.accept(this); 137 method.function.body.accept(this);
138 closeFunction(); 138 closeFunction();
139 } 139 }
140 140
141 void openFunction(IrFunction method, FunctionElement functionElement) { 141 // TODO(het): get function element from astAdapter?
142 void openFunction(FunctionElement functionElement) {
142 HBasicBlock block = graph.addNewBlock(); 143 HBasicBlock block = graph.addNewBlock();
143 open(graph.entry); 144 open(graph.entry);
144 localsHandler.startFunction(functionElement, resolvedAst.node); 145 localsHandler.startFunction(functionElement, resolvedAst.node);
145 close(new HGoto()).addSuccessor(block); 146 close(new HGoto()).addSuccessor(block);
146 147
147 open(block); 148 open(block);
148 } 149 }
149 150
150 void closeFunction() { 151 void closeFunction() {
151 if (!isAborted()) closeAndGotoExit(new HGoto()); 152 if (!isAborted()) closeAndGotoExit(new HGoto());
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 visitThisExpression(ir.ThisExpression thisExpression) { 307 visitThisExpression(ir.ThisExpression thisExpression) {
307 stack.add(localsHandler.readThis()); 308 stack.add(localsHandler.readThis());
308 } 309 }
309 310
310 @override 311 @override
311 visitNot(ir.Not not) { 312 visitNot(ir.Not not) {
312 not.operand.accept(this); 313 not.operand.accept(this);
313 push(new HNot(popBoolified(), backend.boolType)); 314 push(new HNot(popBoolified(), backend.boolType));
314 } 315 }
315 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698