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

Side by Side Diff: lib/compiler/implementation/ssa/optimize.dart

Issue 11024003: Add a fixed array type. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « lib/compiler/implementation/ssa/nodes.dart ('k') | lib/compiler/implementation/ssa/types.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 abstract class OptimizationPhase { 5 abstract class OptimizationPhase {
6 String get name; 6 String get name;
7 void visitGraph(HGraph graph); 7 void visitGraph(HGraph graph);
8 } 8 }
9 9
10 class SsaOptimizerTask extends CompilerTask { 10 class SsaOptimizerTask extends CompilerTask {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Constant folded = operation.fold(receiver.constant); 196 Constant folded = operation.fold(receiver.constant);
197 if (folded !== null) return graph.addConstant(folded); 197 if (folded !== null) return graph.addConstant(folded);
198 } 198 }
199 return node; 199 return node;
200 } 200 }
201 201
202 HInstruction visitInvokeInterceptor(HInvokeInterceptor node) { 202 HInstruction visitInvokeInterceptor(HInvokeInterceptor node) {
203 // Try to recognize the length interceptor with input [:new List(int):]. 203 // Try to recognize the length interceptor with input [:new List(int):].
204 if (node.isLengthGetter() && node.inputs[1] is HInvokeStatic) { 204 if (node.isLengthGetter() && node.inputs[1] is HInvokeStatic) {
205 HInvokeStatic call = node.inputs[1]; 205 HInvokeStatic call = node.inputs[1];
206 Element element = call.target.element; 206 if (isFixedSizeListConstructor(call)) {
207 if (element.isConstructor() && 207 return call.inputs[1];
208 element.enclosingElement.declaration ==
209 compiler.listClass.defaultClass.element) {
210 if (call.inputs.length == 2 && call.inputs[1].isInteger(types)) {
211 return call.inputs[1];
212 }
213 } 208 }
214 } 209 }
215 HInstruction input = node.inputs[1]; 210 HInstruction input = node.inputs[1];
216 if (node.isLengthGetter()) { 211 if (node.isLengthGetter()) {
217 if (input.isConstantString()) { 212 if (input.isConstantString()) {
218 HConstant constantInput = input; 213 HConstant constantInput = input;
219 StringConstant constant = constantInput.constant; 214 StringConstant constant = constantInput.constant;
220 return graph.addConstantInt(constant.length, constantSystem); 215 return graph.addConstantInt(constant.length, constantSystem);
221 } else if (input.isConstantList()) { 216 } else if (input.isConstantList()) {
222 HConstant constantInput = input; 217 HConstant constantInput = input;
(...skipping 21 matching lines...) Expand all
244 transformToDynamicInvocation = false; 239 transformToDynamicInvocation = false;
245 } 240 }
246 if (transformToDynamicInvocation) { 241 if (transformToDynamicInvocation) {
247 return fromInterceptorToDynamicInvocation(node, node.selector); 242 return fromInterceptorToDynamicInvocation(node, node.selector);
248 } 243 }
249 } 244 }
250 245
251 return node; 246 return node;
252 } 247 }
253 248
249 bool isFixedSizeListConstructor(HInvokeStatic node) {
250 Element element = node.inputs[0].element;
251 return element.isConstructor()
252 && element.enclosingElement == compiler.listClass.defaultClass.element
253 && node.inputs.length == 2
254 && node.inputs[1].isInteger(types);
255 }
256
257 HInstruction visitInvokeStatic(HInvokeStatic node) {
258 if (isFixedSizeListConstructor(node)) {
259 node.guaranteedType = HType.FIXED_ARRAY;
260 }
261 return node;
262 }
263
254 HInstruction visitInvokeDynamic(HInvokeDynamic node) { 264 HInstruction visitInvokeDynamic(HInvokeDynamic node) {
255 HType receiverType = types[node.receiver]; 265 HType receiverType = types[node.receiver];
256 if (receiverType.isExact()) { 266 if (receiverType.isExact()) {
257 HBoundedType type = receiverType; 267 HBoundedType type = receiverType;
258 Element element = type.lookupMember(node.selector.name); 268 Element element = type.lookupMember(node.selector.name);
259 // TODO(ngeoffray): Also fold if it's a getter or variable. 269 // TODO(ngeoffray): Also fold if it's a getter or variable.
260 if (element != null && element.isFunction()) { 270 if (element != null && element.isFunction()) {
261 if (node.selector.applies(element, compiler)) { 271 if (node.selector.applies(element, compiler)) {
262 FunctionElement method = element; 272 FunctionElement method = element;
263 FunctionSignature parameters = method.computeSignature(compiler); 273 FunctionSignature parameters = method.computeSignature(compiler);
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 } 1333 }
1324 1334
1325 // For other fields having setters in the generative constructor body, set 1335 // For other fields having setters in the generative constructor body, set
1326 // the type to UNKNOWN to avoid relying on the type set in the initializer 1336 // the type to UNKNOWN to avoid relying on the type set in the initializer
1327 // list. 1337 // list.
1328 allSetters.forEach((Element element) { 1338 allSetters.forEach((Element element) {
1329 backend.registerFieldConstructor(element, HType.UNKNOWN); 1339 backend.registerFieldConstructor(element, HType.UNKNOWN);
1330 }); 1340 });
1331 } 1341 }
1332 } 1342 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/nodes.dart ('k') | lib/compiler/implementation/ssa/types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698