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

Side by Side Diff: runtime/vm/intermediate_language.cc

Issue 10399051: First shot at static type propagation and type test elimination. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | « runtime/vm/intermediate_language.h ('k') | runtime/vm/object.h » ('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 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 #include "vm/scopes.h" 10 #include "vm/scopes.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // nonoptimizing compiler. 281 // nonoptimizing compiler.
282 ASSERT(true_successor_ != NULL); 282 ASSERT(true_successor_ != NULL);
283 ASSERT(false_successor_ != NULL); 283 ASSERT(false_successor_ != NULL);
284 false_successor_->DiscoverBlocks(current_block, preorder, postorder, parent, 284 false_successor_->DiscoverBlocks(current_block, preorder, postorder, parent,
285 assigned_vars, variable_count); 285 assigned_vars, variable_count);
286 true_successor_->DiscoverBlocks(current_block, preorder, postorder, parent, 286 true_successor_->DiscoverBlocks(current_block, preorder, postorder, parent,
287 assigned_vars, variable_count); 287 assigned_vars, variable_count);
288 } 288 }
289 289
290 290
291 // ==== Support for propagating static type.
292 RawAbstractType* ConstantVal::StaticType() const {
293 if (value().IsInstance()) {
294 Instance& instance = Instance::Handle();
295 instance ^= value().raw();
296 return instance.GetType();
297 } else {
298 UNREACHABLE();
299 return AbstractType::null();
300 }
301 }
302
303
304 RawAbstractType* UseVal::StaticType() const {
305 return definition()->StaticType();
306 }
307
308
309 RawAbstractType* AssertAssignableComp::StaticType() const {
310 return dst_type().raw();
311 }
312
313
314 RawAbstractType* AssertBooleanComp::StaticType() const {
315 return Type::BoolInterface();
316 }
317
318
319 RawAbstractType* CurrentContextComp::StaticType() const {
320 UNREACHABLE();
321 return AbstractType::null();
322 }
323
324
325 RawAbstractType* StoreContextComp::StaticType() const {
326 UNREACHABLE();
327 return AbstractType::null();
328 }
329
330
331 RawAbstractType* ClosureCallComp::StaticType() const {
332 // The closure is the first argument to the call.
333 const AbstractType& function_type =
334 AbstractType::Handle(ArgumentAt(0)->StaticType());
335 if (function_type.IsDynamicType() || function_type.IsFunctionInterface()) {
336 // The function type is not statically known or simply Function.
337 return Type::DynamicType();
338 }
339 const Class& signature_class = Class::Handle(function_type.type_class());
340 ASSERT(signature_class.IsSignatureClass());
341 const Function& signature_function =
342 Function::Handle(signature_class.signature_function());
343 // TODO(regis): The result type may be generic.
344 return signature_function.result_type();
345 }
346
347
348 RawAbstractType* InstanceCallComp::StaticType() const {
349 return Type::DynamicType();
350 }
351
352
353 RawAbstractType* StaticCallComp::StaticType() const {
354 return function().result_type();
355 }
356
357
358 RawAbstractType* LoadLocalComp::StaticType() const {
359 return local().type().raw();
360 }
361
362
363 RawAbstractType* StoreLocalComp::StaticType() const {
364 const AbstractType& assigned_value_type =
365 AbstractType::Handle(value()->StaticType());
366 if (assigned_value_type.IsDynamicType()) {
367 // Static type of assigned value is unknown, return static type of local.
368 return local().type().raw();
369 }
370 return assigned_value_type.raw();
371 }
372
373
374 RawAbstractType* StrictCompareComp::StaticType() const {
375 return Type::BoolInterface();
376 }
377
378
379 RawAbstractType* EqualityCompareComp::StaticType() const {
380 return Type::BoolInterface();
381 }
382
383
384 RawAbstractType* NativeCallComp::StaticType() const {
385 // The result type of the native function is identical to the result type of
386 // the enclosing native Dart function.
387 // TODO(regis): Can we trust it or should we check anyway? Check for now.
388 return Type::DynamicType();
389 }
390
391
392 RawAbstractType* StoreIndexedComp::StaticType() const {
393 return value()->StaticType();
394 }
395
396
397 RawAbstractType* InstanceSetterComp::StaticType() const {
398 // TODO(regis): Would it be correct to return value()->StaticType()?
399 return Type::DynamicType();
400 }
401
402
403 RawAbstractType* StaticSetterComp::StaticType() const {
404 // TODO(regis): Would it be correct/better to return value()->StaticType()?
405 return setter_function().result_type();
406 }
407
408
409 RawAbstractType* LoadInstanceFieldComp::StaticType() const {
410 return field().type();
411 }
412
413
414 RawAbstractType* StoreInstanceFieldComp::StaticType() const {
415 const AbstractType& assigned_value_type =
416 AbstractType::Handle(value()->StaticType());
417 if (assigned_value_type.IsDynamicType()) {
418 // Static type of assigned value is unknown, return static type of field.
419 return field().type();
420 }
421 return assigned_value_type.raw();
422 }
423
424
425 RawAbstractType* LoadStaticFieldComp::StaticType() const {
426 return field().type();
427 }
428
429
430 RawAbstractType* StoreStaticFieldComp::StaticType() const {
431 const AbstractType& assigned_value_type =
432 AbstractType::Handle(value()->StaticType());
433 if (assigned_value_type.IsDynamicType()) {
434 // Static type of assigned value is unknown, return static type of field.
435 return field().type();
436 }
437 return assigned_value_type.raw();
438 }
439
440
441 RawAbstractType* BooleanNegateComp::StaticType() const {
442 return Type::BoolInterface();
443 }
444
445
446 RawAbstractType* InstanceOfComp::StaticType() const {
447 return Type::BoolInterface();
448 }
449
450
451 RawAbstractType* CreateArrayComp::StaticType() const {
452 UNREACHABLE();
453 return AbstractType::null();
454 }
455
456
457 RawAbstractType* CreateClosureComp::StaticType() const {
458 const Function& fun = function();
459 const Class& signature_class = Class::Handle(fun.signature_class());
460 // TODO(regis): Can we take (constant) type_arguments() into consideration?
461 // For now, we return Dynamic (no type test elimination) if the signature
462 // class is parameterized, or a non-parameterized finalized type otherwise.
463 if (signature_class.HasTypeArguments()) {
464 return Type::DynamicType();
465 }
466 // Make sure we use the canonical signature class.
467 const Type& type = Type::Handle(signature_class.SignatureType());
468 const Class& canonical_signature_class = Class::Handle(type.type_class());
469 return Type::NewNonParameterizedType(canonical_signature_class);
470 }
471
472
473 RawAbstractType* AllocateObjectComp::StaticType() const {
474 UNREACHABLE();
475 return AbstractType::null();
476 }
477
478
479 RawAbstractType* AllocateObjectWithBoundsCheckComp::StaticType() const {
480 UNREACHABLE();
481 return AbstractType::null();
482 }
483
484
485 RawAbstractType* NativeLoadFieldComp::StaticType() const {
486 ASSERT(!type().IsNull());
487 return type().raw();
488 }
489
490
491 RawAbstractType* NativeStoreFieldComp::StaticType() const {
492 return value()->StaticType();
493 }
494
495
496 RawAbstractType* InstantiateTypeArgumentsComp::StaticType() const {
497 UNREACHABLE();
498 return AbstractType::null();
499 }
500
501
502 RawAbstractType* ExtractConstructorTypeArgumentsComp::StaticType() const {
503 UNREACHABLE();
504 return AbstractType::null();
505 }
506
507
508 RawAbstractType* ExtractConstructorInstantiatorComp::StaticType() const {
509 UNREACHABLE();
510 return AbstractType::null();
511 }
512
513
514 RawAbstractType* AllocateContextComp::StaticType() const {
515 UNREACHABLE();
516 return AbstractType::null();
517 }
518
519
520 RawAbstractType* ChainContextComp::StaticType() const {
521 UNREACHABLE();
522 return AbstractType::null();
523 }
524
525
526 RawAbstractType* CloneContextComp::StaticType() const {
527 UNREACHABLE();
528 return AbstractType::null();
529 }
530
531
532 RawAbstractType* CatchEntryComp::StaticType() const {
533 UNREACHABLE();
534 return AbstractType::null();
535 }
536
537
291 } // namespace dart 538 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698