OLD | NEW |
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 js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 574 } |
575 | 575 |
576 static Namer determineNamer(Compiler compiler) { | 576 static Namer determineNamer(Compiler compiler) { |
577 return compiler.enableMinification ? | 577 return compiler.enableMinification ? |
578 compiler.useFrequencyNamer ? | 578 compiler.useFrequencyNamer ? |
579 new FrequencyBasedNamer(compiler) : | 579 new FrequencyBasedNamer(compiler) : |
580 new MinifyNamer(compiler) : | 580 new MinifyNamer(compiler) : |
581 new Namer(compiler); | 581 new Namer(compiler); |
582 } | 582 } |
583 | 583 |
| 584 /// The backend must *always* call this method when enqueuing an |
| 585 /// element. Calls done by the backend are not seen by global |
| 586 /// optimizations, so they would make these optimizations unsound. |
| 587 /// Therefore we need to collect the list of helpers the backend may |
| 588 /// use. |
| 589 // TODO(johnniwinther): Replace this with a more precise modelling; type |
| 590 // inference of these elements is disabled. |
| 591 Element registerBackendUse(Element element) { |
| 592 if (element != null) { |
| 593 bool registerUse = false; |
| 594 if (element == helpers.streamIteratorConstructor || |
| 595 element == helpers.compiler.symbolConstructor || |
| 596 element == helpers.compiler.symbolValidatedConstructor || |
| 597 element == helpers.syncCompleterConstructor || |
| 598 element == coreClasses.symbolClass || |
| 599 element == helpers.objectNoSuchMethod) { |
| 600 // TODO(johnniwinther): These are valid but we could be more precise. |
| 601 registerUse = true; |
| 602 } else if (element.implementationLibrary.isPatch || |
| 603 element.library == helpers.jsHelperLibrary || |
| 604 element.library == helpers.interceptorsLibrary || |
| 605 element.library == helpers.isolateHelperLibrary) { |
| 606 // TODO(johnniwinther): We should be more precise about these. |
| 607 registerUse = true; |
| 608 } else if (element == coreClasses.listClass || |
| 609 element == helpers.mapLiteralClass || |
| 610 element == coreClasses.functionClass || |
| 611 element == coreClasses.stringClass) { |
| 612 // TODO(johnniwinther): Avoid these. |
| 613 registerUse = true; |
| 614 } |
| 615 if (!registerUse) { |
| 616 assert(invariant(element, false, |
| 617 message: "Backend use of $element is not allowed.")); |
| 618 return element; |
| 619 } |
| 620 helpersUsed.add(element.declaration); |
| 621 if (element.isClass && element.isPatched) { |
| 622 // Both declaration and implementation may declare fields, so we |
| 623 // add both to the list of helpers. |
| 624 helpersUsed.add(element.implementation); |
| 625 } |
| 626 } |
| 627 return element; |
| 628 } |
| 629 |
584 bool usedByBackend(Element element) { | 630 bool usedByBackend(Element element) { |
585 if (element.isParameter | 631 if (element.isParameter |
586 || element.isInitializingFormal | 632 || element.isInitializingFormal |
587 || element.isField) { | 633 || element.isField) { |
588 if (usedByBackend(element.enclosingElement)) return true; | 634 if (usedByBackend(element.enclosingElement)) return true; |
589 } | 635 } |
590 return helpersUsed.contains(element.declaration); | 636 return helpersUsed.contains(element.declaration); |
591 } | 637 } |
592 | 638 |
593 bool invokedReflectively(Element element) { | 639 bool invokedReflectively(Element element) { |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 return classElement == coreClasses.objectClass | 1518 return classElement == coreClasses.objectClass |
1473 || classElement == helpers.jsInterceptorClass | 1519 || classElement == helpers.jsInterceptorClass |
1474 || classElement == helpers.jsNullClass; | 1520 || classElement == helpers.jsNullClass; |
1475 } | 1521 } |
1476 | 1522 |
1477 bool methodNeedsRti(FunctionElement function) { | 1523 bool methodNeedsRti(FunctionElement function) { |
1478 return rti.methodsNeedingRti.contains(function) || | 1524 return rti.methodsNeedingRti.contains(function) || |
1479 compiler.enabledRuntimeType; | 1525 compiler.enabledRuntimeType; |
1480 } | 1526 } |
1481 | 1527 |
1482 /// The backend must *always* call this method when enqueuing an | |
1483 /// element. Calls done by the backend are not seen by global | |
1484 /// optimizations, so they would make these optimizations unsound. | |
1485 /// Therefore we need to collect the list of helpers the backend may | |
1486 /// use. | |
1487 Element registerBackendUse(Element element) { | |
1488 if (element != null) { | |
1489 helpersUsed.add(element.declaration); | |
1490 if (element.isClass && element.isPatched) { | |
1491 // Both declaration and implementation may declare fields, so we | |
1492 // add both to the list of helpers. | |
1493 helpersUsed.add(element.implementation); | |
1494 } | |
1495 } | |
1496 return element; | |
1497 } | |
1498 | |
1499 /// Enqueue [e] in [enqueuer]. | 1528 /// Enqueue [e] in [enqueuer]. |
1500 /// | 1529 /// |
1501 /// This method calls [registerBackendUse]. | 1530 /// This method calls [registerBackendUse]. |
1502 void enqueue(Enqueuer enqueuer, Element e, Registry registry) { | 1531 void enqueue(Enqueuer enqueuer, Element e, Registry registry) { |
1503 if (e == null) return; | 1532 if (e == null) return; |
1504 registerBackendUse(e); | 1533 registerBackendUse(e); |
1505 enqueuer.addToWorkList(e); | 1534 enqueuer.addToWorkList(e); |
1506 registry.registerDependency(e); | 1535 registry.registerDependency(e); |
1507 } | 1536 } |
1508 | 1537 |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3129 } | 3158 } |
3130 } | 3159 } |
3131 | 3160 |
3132 @override | 3161 @override |
3133 void onImpactUsed(ImpactUseCase impactUse) { | 3162 void onImpactUsed(ImpactUseCase impactUse) { |
3134 if (impactUse == DeferredLoadTask.IMPACT_USE) { | 3163 if (impactUse == DeferredLoadTask.IMPACT_USE) { |
3135 resolution.emptyCache(); | 3164 resolution.emptyCache(); |
3136 } | 3165 } |
3137 } | 3166 } |
3138 } | 3167 } |
OLD | NEW |