OLD | NEW |
---|---|
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 '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/codegen.dart' show CodegenWorkItem, CodegenRegistry; | 9 import '../common/codegen.dart' show CodegenRegistry; |
10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
11 import '../common/tasks.dart'; | |
12 import '../compiler.dart'; | 11 import '../compiler.dart'; |
13 import '../constants/values.dart' | 12 import '../constants/values.dart' |
14 show | 13 show |
15 ConstantValue, | 14 ConstantValue, |
16 InterceptorConstantValue, | 15 InterceptorConstantValue, |
17 StringConstantValue, | 16 StringConstantValue, |
18 TypeConstantValue; | 17 TypeConstantValue; |
19 import '../elements/elements.dart'; | 18 import '../elements/elements.dart'; |
20 import '../elements/entities.dart'; | 19 import '../elements/entities.dart'; |
21 import '../elements/resolution_types.dart'; | 20 import '../elements/resolution_types.dart'; |
22 import '../io/source_information.dart'; | 21 import '../io/source_information.dart'; |
23 import '../js/js.dart' as js; | 22 import '../js/js.dart' as js; |
24 import '../js_backend/backend.dart' show JavaScriptBackend; | 23 import '../js_backend/backend.dart' show JavaScriptBackend; |
25 import '../js_backend/element_strategy.dart' show ElementCodegenWorkItem; | |
26 import '../kernel/kernel.dart'; | |
27 import '../native/native.dart' as native; | 24 import '../native/native.dart' as native; |
28 import '../resolution/tree_elements.dart'; | 25 import '../resolution/tree_elements.dart'; |
29 import '../tree/nodes.dart' show Node; | 26 import '../tree/nodes.dart' show Node; |
30 import '../types/masks.dart'; | 27 import '../types/masks.dart'; |
31 import '../universe/selector.dart'; | 28 import '../universe/selector.dart'; |
32 import '../universe/side_effects.dart' show SideEffects; | 29 import '../universe/side_effects.dart' show SideEffects; |
33 import '../universe/use.dart' show DynamicUse; | 30 import '../universe/use.dart' show DynamicUse; |
34 import '../world.dart'; | 31 import '../world.dart'; |
35 import 'builder.dart'; | |
36 import 'graph_builder.dart'; | 32 import 'graph_builder.dart'; |
37 import 'jump_handler.dart'; | 33 import 'jump_handler.dart'; |
38 import 'kernel_ast_adapter.dart'; | 34 import 'kernel_ast_adapter.dart'; |
39 import 'kernel_string_builder.dart'; | 35 import 'kernel_string_builder.dart'; |
40 import 'locals_handler.dart'; | 36 import 'locals_handler.dart'; |
41 import 'loop_handler.dart'; | 37 import 'loop_handler.dart'; |
42 import 'nodes.dart'; | 38 import 'nodes.dart'; |
43 import 'ssa.dart'; | |
44 import 'ssa_branch_builder.dart'; | 39 import 'ssa_branch_builder.dart'; |
45 import 'switch_continue_analysis.dart'; | 40 import 'switch_continue_analysis.dart'; |
46 import 'type_builder.dart'; | 41 import 'type_builder.dart'; |
47 import 'types.dart' show TypeMaskFactory; | 42 import 'types.dart' show TypeMaskFactory; |
48 | 43 |
49 class SsaAstKernelBuilderTask extends SsaAstBuilderBase { | |
50 final SourceInformationStrategy sourceInformationFactory; | |
51 | |
52 String get name => 'SSA kernel builder'; | |
53 | |
54 SsaAstKernelBuilderTask( | |
55 JavaScriptBackend backend, this.sourceInformationFactory) | |
56 : super(backend); | |
57 | |
58 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { | |
59 return measure(() { | |
60 if (handleConstantField(work)) { | |
61 // No code is generated for `work.element`. | |
62 return null; | |
63 } | |
64 MemberElement element = work.element.implementation; | |
65 Kernel kernel = backend.kernelTask.kernel; | |
66 KernelSsaBuilder builder = new KernelSsaBuilder( | |
67 element, | |
68 work.resolvedAst, | |
69 backend.compiler, | |
70 closedWorld, | |
71 work.registry, | |
72 sourceInformationFactory, | |
73 kernel); | |
74 HGraph graph = builder.build(); | |
75 | |
76 if (backend.tracer.isEnabled) { | |
77 String name; | |
78 if (element.isClassMember) { | |
79 String className = element.enclosingClass.name; | |
80 String memberName = element.name; | |
81 name = "$className.$memberName"; | |
82 if (element.isGenerativeConstructorBody) { | |
83 name = "$name (body)"; | |
84 } | |
85 } else { | |
86 name = "${element.name}"; | |
87 } | |
88 backend.tracer.traceCompilation(name); | |
89 backend.tracer.traceGraph('builder', graph); | |
90 } | |
91 | |
92 return graph; | |
93 }); | |
94 } | |
95 } | |
96 | |
97 class KernelSsaBuilderTask extends CompilerTask implements SsaBuilderTask { | |
98 KernelSsaBuilderTask(Measurer measurer) : super(measurer); | |
99 | |
100 @override | |
101 HGraph build(CodegenWorkItem work, ClosedWorld closedWorld) { | |
102 throw new UnimplementedError("KernelSsaBuilderTask.build"); | |
103 } | |
104 } | |
105 | |
106 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { | 44 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { |
107 ir.Node target; | 45 ir.Node target; |
108 bool _targetIsConstructorBody = false; | 46 bool _targetIsConstructorBody = false; |
109 final MemberElement targetElement; | 47 final MemberElement targetElement; |
110 final ResolvedAst resolvedAst; | 48 |
49 /// The root node of [targetElement]. This is used as the key into the | |
50 /// [startFunction] of the locals handler. | |
51 // TODO(johnniwinther,efortuna): Avoid the need for AST nodes in the locals | |
Siggi Cherem (dart-lang)
2017/05/23 21:23:31
can we really avoid it?
Johnni Winther
2017/05/24 08:07:09
They are just used as keys to fetch the correspond
| |
52 // handler. | |
53 final Node functionNode; | |
111 final ClosedWorld closedWorld; | 54 final ClosedWorld closedWorld; |
112 final CodegenRegistry registry; | 55 final CodegenRegistry registry; |
113 | 56 |
114 /// Helper accessor for all kernel function-like targets (Procedure, | 57 /// Helper accessor for all kernel function-like targets (Procedure, |
115 /// FunctionExpression, FunctionDeclaration) of the inner FunctionNode itself. | 58 /// FunctionExpression, FunctionDeclaration) of the inner FunctionNode itself. |
116 /// If the current target is not a function-like target, _targetFunction will | 59 /// If the current target is not a function-like target, _targetFunction will |
117 /// be null. | 60 /// be null. |
118 ir.FunctionNode _targetFunction; | 61 ir.FunctionNode _targetFunction; |
119 | 62 |
120 /// A stack of [ResolutionDartType]s that have been seen during inlining of | 63 /// A stack of [ResolutionDartType]s that have been seen during inlining of |
(...skipping 22 matching lines...) Expand all Loading... | |
143 | 86 |
144 final Map<ir.VariableDeclaration, HInstruction> letBindings = | 87 final Map<ir.VariableDeclaration, HInstruction> letBindings = |
145 <ir.VariableDeclaration, HInstruction>{}; | 88 <ir.VariableDeclaration, HInstruction>{}; |
146 | 89 |
147 /// True if we are visiting the expression of a throw statement; we assume | 90 /// True if we are visiting the expression of a throw statement; we assume |
148 /// this is a slow path. | 91 /// this is a slow path. |
149 bool _inExpressionOfThrow = false; | 92 bool _inExpressionOfThrow = false; |
150 | 93 |
151 KernelSsaBuilder( | 94 KernelSsaBuilder( |
152 this.targetElement, | 95 this.targetElement, |
153 this.resolvedAst, | |
154 this.compiler, | 96 this.compiler, |
97 this.astAdapter, | |
155 this.closedWorld, | 98 this.closedWorld, |
156 this.registry, | 99 this.registry, |
157 SourceInformationStrategy sourceInformationFactory, | 100 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? |
158 Kernel kernel) { | 101 this.sourceInformationBuilder, |
102 this.functionNode) { | |
159 this.loopHandler = new KernelLoopHandler(this); | 103 this.loopHandler = new KernelLoopHandler(this); |
160 typeBuilder = new TypeBuilder(this); | 104 typeBuilder = new TypeBuilder(this); |
161 graph.element = targetElement; | 105 graph.element = targetElement; |
162 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? | |
163 this.sourceInformationBuilder = | |
164 sourceInformationFactory.createBuilderForContext(resolvedAst); | |
165 graph.sourceInformation = | 106 graph.sourceInformation = |
166 sourceInformationBuilder.buildVariableDeclaration(); | 107 sourceInformationBuilder.buildVariableDeclaration(); |
167 this.localsHandler = new LocalsHandler( | 108 this.localsHandler = new LocalsHandler( |
168 this, targetElement, null, nativeData, interceptorData); | 109 this, targetElement, null, nativeData, interceptorData); |
169 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, | |
170 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); | |
171 target = astAdapter.getInitialKernelNode(targetElement); | 110 target = astAdapter.getInitialKernelNode(targetElement); |
172 if (targetElement is ConstructorBodyElement) { | 111 if (targetElement is ConstructorBodyElement) { |
173 _targetIsConstructorBody = true; | 112 _targetIsConstructorBody = true; |
174 } | 113 } |
175 _targetStack.add(target); | 114 _targetStack.add(target); |
176 } | 115 } |
177 | 116 |
178 HGraph build() { | 117 HGraph build() { |
179 // TODO(het): no reason to do this here... | 118 // TODO(het): no reason to do this here... |
180 HInstruction.idCounter = 0; | 119 HInstruction.idCounter = 0; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 ir.Constructor constructor, List<HInstruction> inputs) { | 353 ir.Constructor constructor, List<HInstruction> inputs) { |
415 // TODO(sra): Inline the constructor body. | 354 // TODO(sra): Inline the constructor body. |
416 MemberEntity constructorBody = | 355 MemberEntity constructorBody = |
417 astAdapter.getConstructorBodyEntity(constructor); | 356 astAdapter.getConstructorBodyEntity(constructor); |
418 HInvokeConstructorBody invoke = new HInvokeConstructorBody( | 357 HInvokeConstructorBody invoke = new HInvokeConstructorBody( |
419 constructorBody, inputs, commonMasks.nonNullType); | 358 constructorBody, inputs, commonMasks.nonNullType); |
420 add(invoke); | 359 add(invoke); |
421 } | 360 } |
422 | 361 |
423 withCurrentIrNode(ir.Node node, f()) { | 362 withCurrentIrNode(ir.Node node, f()) { |
424 compiler.reporter.withCurrentElement(astAdapter.getElement(node), f); | 363 astAdapter.reporter.withCurrentElement(astAdapter.getElement(node), f); |
425 } | 364 } |
426 | 365 |
427 /// Sets context for generating code that is the result of inlining | 366 /// Sets context for generating code that is the result of inlining |
428 /// [inlinedTarget]. | 367 /// [inlinedTarget]. |
429 inlinedFrom(ir.TreeNode inlinedTarget, f()) { | 368 inlinedFrom(ir.TreeNode inlinedTarget, f()) { |
430 withCurrentIrNode(inlinedTarget, () { | 369 withCurrentIrNode(inlinedTarget, () { |
431 SourceInformationBuilder oldSourceInformationBuilder = | 370 SourceInformationBuilder oldSourceInformationBuilder = |
432 sourceInformationBuilder; | 371 sourceInformationBuilder; |
433 // TODO(sra): Update sourceInformationBuilder to Kernel. | 372 // TODO(sra): Update sourceInformationBuilder to Kernel. |
434 // sourceInformationBuilder = | 373 // sourceInformationBuilder = |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 void removeImplicitInstantiation(ResolutionDartType type) { | 645 void removeImplicitInstantiation(ResolutionDartType type) { |
707 if (type != null) { | 646 if (type != null) { |
708 currentImplicitInstantiations.removeLast(); | 647 currentImplicitInstantiations.removeLast(); |
709 } | 648 } |
710 } | 649 } |
711 | 650 |
712 void openFunction() { | 651 void openFunction() { |
713 HBasicBlock block = graph.addNewBlock(); | 652 HBasicBlock block = graph.addNewBlock(); |
714 open(graph.entry); | 653 open(graph.entry); |
715 | 654 |
716 Node function; | 655 localsHandler.startFunction(targetElement, functionNode); |
717 if (resolvedAst.kind == ResolvedAstKind.PARSED) { | |
718 function = resolvedAst.node; | |
719 } | |
720 localsHandler.startFunction(targetElement, function); | |
721 close(new HGoto()).addSuccessor(block); | 656 close(new HGoto()).addSuccessor(block); |
722 | 657 |
723 open(block); | 658 open(block); |
724 } | 659 } |
725 | 660 |
726 void closeFunction() { | 661 void closeFunction() { |
727 if (!isAborted()) closeAndGotoExit(new HGoto()); | 662 if (!isAborted()) closeAndGotoExit(new HGoto()); |
728 graph.finalize(); | 663 graph.finalize(); |
729 } | 664 } |
730 | 665 |
(...skipping 2723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3454 enterBlock.setBlockFlow( | 3389 enterBlock.setBlockFlow( |
3455 new HTryBlockInformation( | 3390 new HTryBlockInformation( |
3456 kernelBuilder.wrapStatementGraph(bodyGraph), | 3391 kernelBuilder.wrapStatementGraph(bodyGraph), |
3457 exception, | 3392 exception, |
3458 kernelBuilder.wrapStatementGraph(catchGraph), | 3393 kernelBuilder.wrapStatementGraph(catchGraph), |
3459 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3394 kernelBuilder.wrapStatementGraph(finallyGraph)), |
3460 exitBlock); | 3395 exitBlock); |
3461 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3396 kernelBuilder.inTryStatement = previouslyInTryStatement; |
3462 } | 3397 } |
3463 } | 3398 } |
OLD | NEW |