| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/aot_optimizer.h" | 5 #include "vm/aot_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/branch_optimizer.h" | 8 #include "vm/branch_optimizer.h" |
| 9 #include "vm/cha.h" | 9 #include "vm/cha.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "vm/object_store.h" | 22 #include "vm/object_store.h" |
| 23 #include "vm/parser.h" | 23 #include "vm/parser.h" |
| 24 #include "vm/precompiler.h" | 24 #include "vm/precompiler.h" |
| 25 #include "vm/resolver.h" | 25 #include "vm/resolver.h" |
| 26 #include "vm/scopes.h" | 26 #include "vm/scopes.h" |
| 27 #include "vm/stack_frame.h" | 27 #include "vm/stack_frame.h" |
| 28 #include "vm/symbols.h" | 28 #include "vm/symbols.h" |
| 29 | 29 |
| 30 namespace dart { | 30 namespace dart { |
| 31 | 31 |
| 32 DECLARE_FLAG(bool, precompilation); |
| 33 |
| 32 // Quick access to the current isolate and zone. | 34 // Quick access to the current isolate and zone. |
| 33 #define I (isolate()) | 35 #define I (isolate()) |
| 34 #define Z (zone()) | 36 #define Z (zone()) |
| 35 | 37 |
| 36 static bool ShouldInlineSimd() { | 38 static bool ShouldInlineSimd() { |
| 37 return FlowGraphCompiler::SupportsUnboxedSimd128(); | 39 return FlowGraphCompiler::SupportsUnboxedSimd128(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 | 42 |
| 41 static bool CanUnboxDouble() { | 43 static bool CanUnboxDouble() { |
| (...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 } | 2027 } |
| 2026 } | 2028 } |
| 2027 return false; | 2029 return false; |
| 2028 } | 2030 } |
| 2029 | 2031 |
| 2030 | 2032 |
| 2031 bool AotOptimizer::TryInlineFloat32x4Constructor( | 2033 bool AotOptimizer::TryInlineFloat32x4Constructor( |
| 2032 StaticCallInstr* call, | 2034 StaticCallInstr* call, |
| 2033 MethodRecognizer::Kind recognized_kind) { | 2035 MethodRecognizer::Kind recognized_kind) { |
| 2034 // Cannot handle unboxed instructions. | 2036 // Cannot handle unboxed instructions. |
| 2035 ASSERT(FLAG_precompiled_mode); | 2037 ASSERT(FLAG_precompilation); |
| 2036 return false; | 2038 return false; |
| 2037 } | 2039 } |
| 2038 | 2040 |
| 2039 | 2041 |
| 2040 bool AotOptimizer::TryInlineFloat64x2Constructor( | 2042 bool AotOptimizer::TryInlineFloat64x2Constructor( |
| 2041 StaticCallInstr* call, | 2043 StaticCallInstr* call, |
| 2042 MethodRecognizer::Kind recognized_kind) { | 2044 MethodRecognizer::Kind recognized_kind) { |
| 2043 // Cannot handle unboxed instructions. | 2045 // Cannot handle unboxed instructions. |
| 2044 ASSERT(FLAG_precompiled_mode); | 2046 ASSERT(FLAG_precompilation); |
| 2045 return false; | 2047 return false; |
| 2046 } | 2048 } |
| 2047 | 2049 |
| 2048 | 2050 |
| 2049 bool AotOptimizer::TryInlineInt32x4Constructor( | 2051 bool AotOptimizer::TryInlineInt32x4Constructor( |
| 2050 StaticCallInstr* call, | 2052 StaticCallInstr* call, |
| 2051 MethodRecognizer::Kind recognized_kind) { | 2053 MethodRecognizer::Kind recognized_kind) { |
| 2052 // Cannot handle unboxed instructions. | 2054 // Cannot handle unboxed instructions. |
| 2053 ASSERT(FLAG_precompiled_mode); | 2055 ASSERT(FLAG_precompilation); |
| 2054 return false; | 2056 return false; |
| 2055 } | 2057 } |
| 2056 | 2058 |
| 2057 | 2059 |
| 2058 bool AotOptimizer::TryInlineFloat32x4Method( | 2060 bool AotOptimizer::TryInlineFloat32x4Method( |
| 2059 InstanceCallInstr* call, | 2061 InstanceCallInstr* call, |
| 2060 MethodRecognizer::Kind recognized_kind) { | 2062 MethodRecognizer::Kind recognized_kind) { |
| 2061 // Cannot handle unboxed instructions. | 2063 // Cannot handle unboxed instructions. |
| 2062 return false; | 2064 return false; |
| 2063 } | 2065 } |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2540 /* with_checks = */ false); | 2542 /* with_checks = */ false); |
| 2541 instr->ReplaceWith(call, current_iterator()); | 2543 instr->ReplaceWith(call, current_iterator()); |
| 2542 return; | 2544 return; |
| 2543 } | 2545 } |
| 2544 } | 2546 } |
| 2545 | 2547 |
| 2546 | 2548 |
| 2547 // Tries to optimize instance call by replacing it with a faster instruction | 2549 // Tries to optimize instance call by replacing it with a faster instruction |
| 2548 // (e.g, binary op, field load, ..). | 2550 // (e.g, binary op, field load, ..). |
| 2549 void AotOptimizer::VisitInstanceCall(InstanceCallInstr* instr) { | 2551 void AotOptimizer::VisitInstanceCall(InstanceCallInstr* instr) { |
| 2550 ASSERT(FLAG_precompiled_mode); | 2552 ASSERT(FLAG_precompilation); |
| 2551 InstanceCallNoopt(instr); | 2553 InstanceCallNoopt(instr); |
| 2552 } | 2554 } |
| 2553 | 2555 |
| 2554 | 2556 |
| 2555 void AotOptimizer::VisitStaticCall(StaticCallInstr* call) { | 2557 void AotOptimizer::VisitStaticCall(StaticCallInstr* call) { |
| 2556 if (!CanUnboxDouble()) { | 2558 if (!CanUnboxDouble()) { |
| 2557 return; | 2559 return; |
| 2558 } | 2560 } |
| 2559 MethodRecognizer::Kind recognized_kind = | 2561 MethodRecognizer::Kind recognized_kind = |
| 2560 MethodRecognizer::RecognizeKind(call->function()); | 2562 MethodRecognizer::RecognizeKind(call->function()); |
| 2561 MathUnaryInstr::MathUnaryKind unary_kind; | 2563 MathUnaryInstr::MathUnaryKind unary_kind; |
| 2562 switch (recognized_kind) { | 2564 switch (recognized_kind) { |
| 2563 case MethodRecognizer::kMathSqrt: | 2565 case MethodRecognizer::kMathSqrt: |
| 2564 unary_kind = MathUnaryInstr::kSqrt; | 2566 unary_kind = MathUnaryInstr::kSqrt; |
| 2565 break; | 2567 break; |
| 2566 case MethodRecognizer::kMathSin: | 2568 case MethodRecognizer::kMathSin: |
| 2567 unary_kind = MathUnaryInstr::kSin; | 2569 unary_kind = MathUnaryInstr::kSin; |
| 2568 break; | 2570 break; |
| 2569 case MethodRecognizer::kMathCos: | 2571 case MethodRecognizer::kMathCos: |
| 2570 unary_kind = MathUnaryInstr::kCos; | 2572 unary_kind = MathUnaryInstr::kCos; |
| 2571 break; | 2573 break; |
| 2572 default: | 2574 default: |
| 2573 unary_kind = MathUnaryInstr::kIllegal; | 2575 unary_kind = MathUnaryInstr::kIllegal; |
| 2574 break; | 2576 break; |
| 2575 } | 2577 } |
| 2576 if (unary_kind != MathUnaryInstr::kIllegal) { | 2578 if (unary_kind != MathUnaryInstr::kIllegal) { |
| 2577 ASSERT(FLAG_precompiled_mode); | 2579 ASSERT(FLAG_precompilation); |
| 2578 // TODO(srdjan): Adapt MathUnaryInstr to allow tagged inputs as well. | 2580 // TODO(srdjan): Adapt MathUnaryInstr to allow tagged inputs as well. |
| 2579 return; | 2581 return; |
| 2580 } | 2582 } |
| 2581 | 2583 |
| 2582 switch (recognized_kind) { | 2584 switch (recognized_kind) { |
| 2583 case MethodRecognizer::kFloat32x4Zero: | 2585 case MethodRecognizer::kFloat32x4Zero: |
| 2584 case MethodRecognizer::kFloat32x4Splat: | 2586 case MethodRecognizer::kFloat32x4Splat: |
| 2585 case MethodRecognizer::kFloat32x4Constructor: | 2587 case MethodRecognizer::kFloat32x4Constructor: |
| 2586 case MethodRecognizer::kFloat32x4FromFloat64x2: | 2588 case MethodRecognizer::kFloat32x4FromFloat64x2: |
| 2587 TryInlineFloat32x4Constructor(call, recognized_kind); | 2589 TryInlineFloat32x4Constructor(call, recognized_kind); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2647 } | 2649 } |
| 2648 } | 2650 } |
| 2649 break; | 2651 break; |
| 2650 } | 2652 } |
| 2651 case MethodRecognizer::kMathDoublePow: | 2653 case MethodRecognizer::kMathDoublePow: |
| 2652 case MethodRecognizer::kMathTan: | 2654 case MethodRecognizer::kMathTan: |
| 2653 case MethodRecognizer::kMathAsin: | 2655 case MethodRecognizer::kMathAsin: |
| 2654 case MethodRecognizer::kMathAcos: | 2656 case MethodRecognizer::kMathAcos: |
| 2655 case MethodRecognizer::kMathAtan: | 2657 case MethodRecognizer::kMathAtan: |
| 2656 case MethodRecognizer::kMathAtan2: { | 2658 case MethodRecognizer::kMathAtan2: { |
| 2657 ASSERT(FLAG_precompiled_mode); | 2659 ASSERT(FLAG_precompilation); |
| 2658 // No UnboxDouble instructions allowed. | 2660 // No UnboxDouble instructions allowed. |
| 2659 return; | 2661 return; |
| 2660 } | 2662 } |
| 2661 case MethodRecognizer::kDoubleFromInteger: { | 2663 case MethodRecognizer::kDoubleFromInteger: { |
| 2662 if (call->HasICData() && (call->ic_data()->NumberOfChecks() == 1)) { | 2664 if (call->HasICData() && (call->ic_data()->NumberOfChecks() == 1)) { |
| 2663 const ICData& ic_data = *call->ic_data(); | 2665 const ICData& ic_data = *call->ic_data(); |
| 2664 if (CanUnboxDouble()) { | 2666 if (CanUnboxDouble()) { |
| 2665 if (ArgIsAlways(kSmiCid, ic_data, 1)) { | 2667 if (ArgIsAlways(kSmiCid, ic_data, 1)) { |
| 2666 Definition* arg = call->ArgumentAt(1); | 2668 Definition* arg = call->ArgumentAt(1); |
| 2667 AddCheckSmi(arg, call->deopt_id(), call->env(), call); | 2669 AddCheckSmi(arg, call->deopt_id(), call->env(), call); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2807 | 2809 |
| 2808 // Discard the environment from the original instruction because the store | 2810 // Discard the environment from the original instruction because the store |
| 2809 // can't deoptimize. | 2811 // can't deoptimize. |
| 2810 instr->RemoveEnvironment(); | 2812 instr->RemoveEnvironment(); |
| 2811 ReplaceCall(instr, store); | 2813 ReplaceCall(instr, store); |
| 2812 return true; | 2814 return true; |
| 2813 } | 2815 } |
| 2814 | 2816 |
| 2815 | 2817 |
| 2816 } // namespace dart | 2818 } // namespace dart |
| OLD | NEW |