| 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 import '../common/codegen.dart' show | 5 import '../common/codegen.dart' show |
| 6 CodegenRegistry, | 6 CodegenRegistry, |
| 7 CodegenWorkItem; | 7 CodegenWorkItem; |
| 8 import '../common/tasks.dart' show | 8 import '../common/tasks.dart' show |
| 9 CompilerTask; | 9 CompilerTask; |
| 10 import '../compiler.dart' show | 10 import '../compiler.dart' show |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 void optimize(CodegenWorkItem work, HGraph graph) { | 55 void optimize(CodegenWorkItem work, HGraph graph) { |
| 56 void runPhase(OptimizationPhase phase) { | 56 void runPhase(OptimizationPhase phase) { |
| 57 measureSubtask(phase.name, () => phase.visitGraph(graph)); | 57 measureSubtask(phase.name, () => phase.visitGraph(graph)); |
| 58 compiler.tracer.traceGraph(phase.name, graph); | 58 compiler.tracer.traceGraph(phase.name, graph); |
| 59 assert(graph.isValid()); | 59 assert(graph.isValid()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 ConstantSystem constantSystem = compiler.backend.constantSystem; | 62 ConstantSystem constantSystem = compiler.backend.constantSystem; |
| 63 JavaScriptItemCompilationContext context = work.compilationContext; | 63 JavaScriptItemCompilationContext context = work.compilationContext; |
| 64 bool trustPrimitives = compiler.trustPrimitives; | 64 bool trustPrimitives = compiler.options.trustPrimitives; |
| 65 measure(() { | 65 measure(() { |
| 66 List<OptimizationPhase> phases = <OptimizationPhase>[ | 66 List<OptimizationPhase> phases = <OptimizationPhase>[ |
| 67 // Run trivial instruction simplification first to optimize | 67 // Run trivial instruction simplification first to optimize |
| 68 // some patterns useful for type conversion. | 68 // some patterns useful for type conversion. |
| 69 new SsaInstructionSimplifier(constantSystem, backend, this, work), | 69 new SsaInstructionSimplifier(constantSystem, backend, this, work), |
| 70 new SsaTypeConversionInserter(compiler), | 70 new SsaTypeConversionInserter(compiler), |
| 71 new SsaRedundantPhiEliminator(), | 71 new SsaRedundantPhiEliminator(), |
| 72 new SsaDeadPhiEliminator(), | 72 new SsaDeadPhiEliminator(), |
| 73 new SsaTypePropagator(compiler), | 73 new SsaTypePropagator(compiler), |
| 74 // After type propagation, more instructions can be | 74 // After type propagation, more instructions can be |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 386 } |
| 387 | 387 |
| 388 if (selector.isCall || selector.isOperator) { | 388 if (selector.isCall || selector.isOperator) { |
| 389 Element target; | 389 Element target; |
| 390 if (input.isExtendableArray(compiler)) { | 390 if (input.isExtendableArray(compiler)) { |
| 391 if (applies(helpers.jsArrayRemoveLast)) { | 391 if (applies(helpers.jsArrayRemoveLast)) { |
| 392 target = helpers.jsArrayRemoveLast; | 392 target = helpers.jsArrayRemoveLast; |
| 393 } else if (applies(helpers.jsArrayAdd)) { | 393 } else if (applies(helpers.jsArrayAdd)) { |
| 394 // The codegen special cases array calls, but does not | 394 // The codegen special cases array calls, but does not |
| 395 // inline argument type checks. | 395 // inline argument type checks. |
| 396 if (!compiler.enableTypeAssertions) { | 396 if (!compiler.options.enableTypeAssertions) { |
| 397 target = helpers.jsArrayAdd; | 397 target = helpers.jsArrayAdd; |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 } else if (input.isStringOrNull(compiler)) { | 400 } else if (input.isStringOrNull(compiler)) { |
| 401 if (applies(helpers.jsStringSplit)) { | 401 if (applies(helpers.jsStringSplit)) { |
| 402 HInstruction argument = node.inputs[2]; | 402 HInstruction argument = node.inputs[2]; |
| 403 if (argument.isString(compiler)) { | 403 if (argument.isString(compiler)) { |
| 404 target = helpers.jsStringSplit; | 404 target = helpers.jsStringSplit; |
| 405 } | 405 } |
| 406 } else if (applies(helpers.jsStringOperatorAdd)) { | 406 } else if (applies(helpers.jsStringOperatorAdd)) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 506 |
| 507 List<HInstruction> inputs = node.inputs.sublist(1); | 507 List<HInstruction> inputs = node.inputs.sublist(1); |
| 508 int inputPosition = 1; // Skip receiver. | 508 int inputPosition = 1; // Skip receiver. |
| 509 bool canInline = true; | 509 bool canInline = true; |
| 510 signature.forEachParameter((ParameterElement element) { | 510 signature.forEachParameter((ParameterElement element) { |
| 511 if (inputPosition++ < inputs.length && canInline) { | 511 if (inputPosition++ < inputs.length && canInline) { |
| 512 DartType type = element.type.unaliased; | 512 DartType type = element.type.unaliased; |
| 513 if (type is FunctionType) { | 513 if (type is FunctionType) { |
| 514 canInline = false; | 514 canInline = false; |
| 515 } | 515 } |
| 516 if (compiler.enableTypeAssertions) { | 516 if (compiler.options.enableTypeAssertions) { |
| 517 // TODO(sra): Check if [input] is guaranteed to pass the parameter | 517 // TODO(sra): Check if [input] is guaranteed to pass the parameter |
| 518 // type check. Consider using a strengthened type check to avoid | 518 // type check. Consider using a strengthened type check to avoid |
| 519 // passing `null` to primitive types since the native methods usually | 519 // passing `null` to primitive types since the native methods usually |
| 520 // have non-nullable primitive parameter types. | 520 // have non-nullable primitive parameter types. |
| 521 canInline = false; | 521 canInline = false; |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 }); | 524 }); |
| 525 | 525 |
| 526 if (!canInline) return null; | 526 if (!canInline) return null; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 } | 911 } |
| 912 | 912 |
| 913 HInstruction receiver = node.getDartReceiver(compiler); | 913 HInstruction receiver = node.getDartReceiver(compiler); |
| 914 VariableElement field = | 914 VariableElement field = |
| 915 findConcreteFieldForDynamicAccess(receiver, node.selector); | 915 findConcreteFieldForDynamicAccess(receiver, node.selector); |
| 916 if (field == null || !field.isAssignable) return node; | 916 if (field == null || !field.isAssignable) return node; |
| 917 // Use [:node.inputs.last:] in case the call follows the | 917 // Use [:node.inputs.last:] in case the call follows the |
| 918 // interceptor calling convention, but is not a call on an | 918 // interceptor calling convention, but is not a call on an |
| 919 // interceptor. | 919 // interceptor. |
| 920 HInstruction value = node.inputs.last; | 920 HInstruction value = node.inputs.last; |
| 921 if (compiler.enableTypeAssertions) { | 921 if (compiler.options.enableTypeAssertions) { |
| 922 DartType type = field.type; | 922 DartType type = field.type; |
| 923 if (!type.treatAsRaw || type.isTypeVariable) { | 923 if (!type.treatAsRaw || type.isTypeVariable) { |
| 924 // We cannot generate the correct type representation here, so don't | 924 // We cannot generate the correct type representation here, so don't |
| 925 // inline this access. | 925 // inline this access. |
| 926 return node; | 926 return node; |
| 927 } | 927 } |
| 928 HInstruction other = value.convertType( | 928 HInstruction other = value.convertType( |
| 929 compiler, | 929 compiler, |
| 930 type, | 930 type, |
| 931 HTypeConversion.CHECKED_MODE_CHECK); | 931 HTypeConversion.CHECKED_MODE_CHECK); |
| (...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 | 2430 |
| 2431 keyedValues.forEach((receiver, values) { | 2431 keyedValues.forEach((receiver, values) { |
| 2432 result.keyedValues[receiver] = | 2432 result.keyedValues[receiver] = |
| 2433 new Map<HInstruction, HInstruction>.from(values); | 2433 new Map<HInstruction, HInstruction>.from(values); |
| 2434 }); | 2434 }); |
| 2435 | 2435 |
| 2436 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2436 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 2437 return result; | 2437 return result; |
| 2438 } | 2438 } |
| 2439 } | 2439 } |
| OLD | NEW |