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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 16077015: Rip-off the backend type inferrer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of ssa; 5 part of ssa;
6 6
7 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to override [Element.computeType] because our 9 * methods. We need to override [Element.computeType] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 assert(!element.isInstanceMember()); 47 assert(!element.isInstanceMember());
48 graph = builder.buildLazyInitializer(element); 48 graph = builder.buildLazyInitializer(element);
49 } else { 49 } else {
50 compiler.internalErrorOnElement(element, 50 compiler.internalErrorOnElement(element,
51 'unexpected element kind $kind'); 51 'unexpected element kind $kind');
52 } 52 }
53 assert(graph.isValid()); 53 assert(graph.isValid());
54 if (!identical(kind, ElementKind.FIELD)) { 54 if (!identical(kind, ElementKind.FIELD)) {
55 FunctionElement function = element; 55 FunctionElement function = element;
56 graph.calledInLoop = compiler.world.isCalledInLoop(function); 56 graph.calledInLoop = compiler.world.isCalledInLoop(function);
57 OptionalParameterTypes defaultValueTypes = null;
58 FunctionSignature signature = function.computeSignature(compiler); 57 FunctionSignature signature = function.computeSignature(compiler);
59 if (signature.optionalParameterCount > 0) { 58 signature.forEachOptionalParameter((Element parameter) {
60 defaultValueTypes = 59 // This ensures the default value will be computed.
61 new OptionalParameterTypes(signature.optionalParameterCount); 60 builder.compileVariable(parameter);
62 int index = 0; 61 });
63 signature.forEachOptionalParameter((Element parameter) {
64 Constant defaultValue = builder.compileVariable(parameter);
65 HType type = HGraph.mapConstantTypeToSsaType(defaultValue);
66 defaultValueTypes.update(index, parameter.name, type);
67 index++;
68 });
69 } else {
70 // BUG(10938): the types are stored in the wrong order.
71 // order.
72 HTypeList parameterTypes =
73 backend.optimisticParameterTypes(element.declaration,
74 defaultValueTypes);
75 if (!parameterTypes.allUnknown) {
76 int i = 0;
77 signature.forEachParameter((Element param) {
78 builder.parameters[param].instructionType = parameterTypes[i++];
79 });
80 }
81 backend.registerParameterTypesOptimization(
82 element.declaration, parameterTypes, defaultValueTypes);
83 }
84 } 62 }
85 63
86 if (compiler.tracer.enabled) { 64 if (compiler.tracer.enabled) {
87 String name; 65 String name;
88 if (element.isMember()) { 66 if (element.isMember()) {
89 String className = element.getEnclosingClass().name.slowToString(); 67 String className = element.getEnclosingClass().name.slowToString();
90 String memberName = element.name.slowToString(); 68 String memberName = element.name.slowToString();
91 name = "$className.$memberName"; 69 name = "$className.$memberName";
92 if (element.isGenerativeConstructorBody()) { 70 if (element.isGenerativeConstructorBody()) {
93 name = "$name (body)"; 71 name = "$name (body)";
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 */ 1112 */
1135 InliningState enterInlinedMethod(FunctionElement function, 1113 InliningState enterInlinedMethod(FunctionElement function,
1136 Selector selector, 1114 Selector selector,
1137 List<HInstruction> providedArguments, 1115 List<HInstruction> providedArguments,
1138 Node currentNode) { 1116 Node currentNode) {
1139 assert(invariant(function, function.isImplementation)); 1117 assert(invariant(function, function.isImplementation));
1140 1118
1141 List<HInstruction> compiledArguments; 1119 List<HInstruction> compiledArguments;
1142 bool isInstanceMember = function.isInstanceMember(); 1120 bool isInstanceMember = function.isInstanceMember();
1143 1121
1144 if (function.isGenerativeConstructor()) {
1145 // The optimistic field type optimization requires
1146 // to know all generative constructors seen in codegen.
1147 backend.registerConstructor(function);
1148 }
1149
1150 if (currentNode == null 1122 if (currentNode == null
1151 || currentNode.asForIn() != null 1123 || currentNode.asForIn() != null
1152 || !isInstanceMember 1124 || !isInstanceMember
1153 || function.isGenerativeConstructorBody()) { 1125 || function.isGenerativeConstructorBody()) {
1154 // For these cases, the provided arguments must match the 1126 // For these cases, the provided arguments must match the
1155 // expected parameters. 1127 // expected parameters.
1156 assert(providedArguments != null); 1128 assert(providedArguments != null);
1157 compiledArguments = providedArguments; 1129 compiledArguments = providedArguments;
1158 } else { 1130 } else {
1159 Send send = currentNode.asSend(); 1131 Send send = currentNode.asSend();
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
3783 void pushInvokeStatic(Node location, 3755 void pushInvokeStatic(Node location,
3784 Element element, 3756 Element element,
3785 List<HInstruction> arguments, 3757 List<HInstruction> arguments,
3786 [HType type = null]) { 3758 [HType type = null]) {
3787 if (tryInlineMethod(element, null, arguments, location)) { 3759 if (tryInlineMethod(element, null, arguments, location)) {
3788 return; 3760 return;
3789 } 3761 }
3790 3762
3791 if (type == null) { 3763 if (type == null) {
3792 type = new HType.inferredReturnTypeForElement(element, compiler); 3764 type = new HType.inferredReturnTypeForElement(element, compiler);
3793 if (type.isUnknown()) {
3794 // TODO(ngeoffray): Only do this if knowing the return type is
3795 // useful.
3796 type =
3797 builder.backend.optimisticReturnTypesWithRecompilationOnTypeChange(
3798 currentElement, element);
3799 if (type == null) type = HType.UNKNOWN;
3800 }
3801 } 3765 }
3802 // TODO(5346): Try to avoid the need for calling [declaration] before 3766 // TODO(5346): Try to avoid the need for calling [declaration] before
3803 // creating an [HInvokeStatic]. 3767 // creating an [HInvokeStatic].
3804 HInstruction instruction = 3768 HInstruction instruction =
3805 new HInvokeStatic(element.declaration, arguments, type); 3769 new HInvokeStatic(element.declaration, arguments, type);
3806 instruction.sideEffects = compiler.world.getSideEffectsOfElement(element); 3770 instruction.sideEffects = compiler.world.getSideEffectsOfElement(element);
3807 if (location == null) { 3771 if (location == null) {
3808 push(instruction); 3772 push(instruction);
3809 } else { 3773 } else {
3810 pushWithPosition(instruction, location); 3774 pushWithPosition(instruction, location);
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
5419 new HSubGraphBlockInformation(elseBranch.graph)); 5383 new HSubGraphBlockInformation(elseBranch.graph));
5420 5384
5421 HBasicBlock conditionStartBlock = conditionBranch.block; 5385 HBasicBlock conditionStartBlock = conditionBranch.block;
5422 conditionStartBlock.setBlockFlow(info, joinBlock); 5386 conditionStartBlock.setBlockFlow(info, joinBlock);
5423 SubGraph conditionGraph = conditionBranch.graph; 5387 SubGraph conditionGraph = conditionBranch.graph;
5424 HIf branch = conditionGraph.end.last; 5388 HIf branch = conditionGraph.end.last;
5425 assert(branch is HIf); 5389 assert(branch is HIf);
5426 branch.blockInformation = conditionStartBlock.blockFlow; 5390 branch.blockInformation = conditionStartBlock.blockFlow;
5427 } 5391 }
5428 } 5392 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698