OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
11 | 11 |
12 #include "src/compiler/access-builder.h" | 12 #include "src/compiler/access-builder.h" |
13 #include "src/compiler/common-operator.h" | 13 #include "src/compiler/common-operator.h" |
14 #include "src/compiler/diamond.h" | 14 #include "src/compiler/diamond.h" |
15 #include "src/compiler/graph-visualizer.h" | 15 #include "src/compiler/graph-visualizer.h" |
16 #include "src/compiler/graph.h" | 16 #include "src/compiler/graph.h" |
17 #include "src/compiler/instruction-selector.h" | 17 #include "src/compiler/instruction-selector.h" |
18 #include "src/compiler/int64-lowering.h" | 18 #include "src/compiler/int64-lowering.h" |
19 #include "src/compiler/js-generic-lowering.h" | 19 #include "src/compiler/js-generic-lowering.h" |
20 #include "src/compiler/js-graph.h" | 20 #include "src/compiler/js-graph.h" |
21 #include "src/compiler/js-operator.h" | 21 #include "src/compiler/js-operator.h" |
22 #include "src/compiler/linkage.h" | 22 #include "src/compiler/linkage.h" |
23 #include "src/compiler/machine-operator.h" | 23 #include "src/compiler/machine-operator.h" |
24 #include "src/compiler/node-matchers.h" | 24 #include "src/compiler/node-matchers.h" |
25 #include "src/compiler/pipeline.h" | 25 #include "src/compiler/pipeline.h" |
| 26 #include "src/compiler/simd-lowering.h" |
26 #include "src/compiler/source-position.h" | 27 #include "src/compiler/source-position.h" |
27 #include "src/compiler/zone-pool.h" | 28 #include "src/compiler/zone-pool.h" |
28 | 29 |
29 #include "src/code-factory.h" | 30 #include "src/code-factory.h" |
30 #include "src/code-stubs.h" | 31 #include "src/code-stubs.h" |
31 #include "src/factory.h" | 32 #include "src/factory.h" |
32 #include "src/log-inl.h" | 33 #include "src/log-inl.h" |
33 #include "src/profiler/cpu-profiler.h" | 34 #include "src/profiler/cpu-profiler.h" |
34 | 35 |
35 #include "src/wasm/ast-decoder.h" | 36 #include "src/wasm/ast-decoder.h" |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 case wasm::kExprF32Max: | 604 case wasm::kExprF32Max: |
604 return BuildF32Max(left, right); | 605 return BuildF32Max(left, right); |
605 case wasm::kExprF64Max: | 606 case wasm::kExprF64Max: |
606 return BuildF64Max(left, right); | 607 return BuildF64Max(left, right); |
607 case wasm::kExprF64Pow: | 608 case wasm::kExprF64Pow: |
608 return BuildF64Pow(left, right); | 609 return BuildF64Pow(left, right); |
609 case wasm::kExprF64Atan2: | 610 case wasm::kExprF64Atan2: |
610 return BuildF64Atan2(left, right); | 611 return BuildF64Atan2(left, right); |
611 case wasm::kExprF64Mod: | 612 case wasm::kExprF64Mod: |
612 return BuildF64Mod(left, right); | 613 return BuildF64Mod(left, right); |
| 614 case wasm::kExprInt32x4ExtractLane: |
| 615 return graph()->NewNode(jsgraph()->machine()->Int32x4ExtractLane(), left, |
| 616 right); |
613 case wasm::kExprI32AsmjsDivS: | 617 case wasm::kExprI32AsmjsDivS: |
614 return BuildI32AsmjsDivS(left, right); | 618 return BuildI32AsmjsDivS(left, right); |
615 case wasm::kExprI32AsmjsDivU: | 619 case wasm::kExprI32AsmjsDivU: |
616 return BuildI32AsmjsDivU(left, right); | 620 return BuildI32AsmjsDivU(left, right); |
617 case wasm::kExprI32AsmjsRemS: | 621 case wasm::kExprI32AsmjsRemS: |
618 return BuildI32AsmjsRemS(left, right); | 622 return BuildI32AsmjsRemS(left, right); |
619 case wasm::kExprI32AsmjsRemU: | 623 case wasm::kExprI32AsmjsRemU: |
620 return BuildI32AsmjsRemU(left, right); | 624 return BuildI32AsmjsRemU(left, right); |
621 case wasm::kExprI32AsmjsStoreMem8: | 625 case wasm::kExprI32AsmjsStoreMem8: |
622 return BuildAsmjsStoreMem(MachineType::Int8(), left, right); | 626 return BuildAsmjsStoreMem(MachineType::Int8(), left, right); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 op = m->RoundUint64ToFloat64(); | 862 op = m->RoundUint64ToFloat64(); |
859 break; | 863 break; |
860 case wasm::kExprI64SConvertF32: | 864 case wasm::kExprI64SConvertF32: |
861 return BuildI64SConvertF32(input, position); | 865 return BuildI64SConvertF32(input, position); |
862 case wasm::kExprI64SConvertF64: | 866 case wasm::kExprI64SConvertF64: |
863 return BuildI64SConvertF64(input, position); | 867 return BuildI64SConvertF64(input, position); |
864 case wasm::kExprI64UConvertF32: | 868 case wasm::kExprI64UConvertF32: |
865 return BuildI64UConvertF32(input, position); | 869 return BuildI64UConvertF32(input, position); |
866 case wasm::kExprI64UConvertF64: | 870 case wasm::kExprI64UConvertF64: |
867 return BuildI64UConvertF64(input, position); | 871 return BuildI64UConvertF64(input, position); |
| 872 case wasm::kExprInt32x4Splat: |
| 873 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), input, |
| 874 input, input, input); |
868 case wasm::kExprI32AsmjsLoadMem8S: | 875 case wasm::kExprI32AsmjsLoadMem8S: |
869 return BuildAsmjsLoadMem(MachineType::Int8(), input); | 876 return BuildAsmjsLoadMem(MachineType::Int8(), input); |
870 case wasm::kExprI32AsmjsLoadMem8U: | 877 case wasm::kExprI32AsmjsLoadMem8U: |
871 return BuildAsmjsLoadMem(MachineType::Uint8(), input); | 878 return BuildAsmjsLoadMem(MachineType::Uint8(), input); |
872 case wasm::kExprI32AsmjsLoadMem16S: | 879 case wasm::kExprI32AsmjsLoadMem16S: |
873 return BuildAsmjsLoadMem(MachineType::Int16(), input); | 880 return BuildAsmjsLoadMem(MachineType::Int16(), input); |
874 case wasm::kExprI32AsmjsLoadMem16U: | 881 case wasm::kExprI32AsmjsLoadMem16U: |
875 return BuildAsmjsLoadMem(MachineType::Uint16(), input); | 882 return BuildAsmjsLoadMem(MachineType::Uint16(), input); |
876 case wasm::kExprI32AsmjsLoadMem: | 883 case wasm::kExprI32AsmjsLoadMem: |
877 return BuildAsmjsLoadMem(MachineType::Int32(), input); | 884 return BuildAsmjsLoadMem(MachineType::Int32(), input); |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 case wasm::kAstF64: | 2123 case wasm::kAstF64: |
2117 return BuildChangeFloat64ToTagged(node); | 2124 return BuildChangeFloat64ToTagged(node); |
2118 case wasm::kAstStmt: | 2125 case wasm::kAstStmt: |
2119 return jsgraph()->UndefinedConstant(); | 2126 return jsgraph()->UndefinedConstant(); |
2120 default: | 2127 default: |
2121 UNREACHABLE(); | 2128 UNREACHABLE(); |
2122 return nullptr; | 2129 return nullptr; |
2123 } | 2130 } |
2124 } | 2131 } |
2125 | 2132 |
| 2133 Node* WasmGraphBuilder::BuildChangeTaggedToInt32(Node* value) { |
| 2134 value = BuildChangeTaggedToFloat64(value); |
| 2135 value = graph()->NewNode(jsgraph()->machine()->ChangeFloat64ToInt32(), value); |
| 2136 return value; |
| 2137 } |
| 2138 |
2126 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, | 2139 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, |
2127 Node* effect, Node* control) { | 2140 Node* effect, Node* control) { |
2128 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); | 2141 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); |
2129 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 2142 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
2130 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, | 2143 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, |
2131 CallDescriptor::kNoFlags, Operator::kNoProperties); | 2144 CallDescriptor::kNoFlags, Operator::kNoProperties); |
2132 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | 2145 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
2133 | 2146 |
2134 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, | 2147 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, |
2135 node, context, effect, control); | 2148 node, context, effect, control); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2537 DCHECK(module_ && module_->instance); | 2550 DCHECK(module_ && module_->instance); |
2538 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); | 2551 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); |
2539 if (offset == 0) { | 2552 if (offset == 0) { |
2540 if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); | 2553 if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); |
2541 return mem_size_; | 2554 return mem_size_; |
2542 } else { | 2555 } else { |
2543 return jsgraph()->Int32Constant(size + offset); | 2556 return jsgraph()->Int32Constant(size + offset); |
2544 } | 2557 } |
2545 } | 2558 } |
2546 | 2559 |
| 2560 Node* WasmGraphBuilder::DefaultS128Value() { |
| 2561 Node* zero = jsgraph()->Int32Constant(0); |
| 2562 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), zero, zero, |
| 2563 zero, zero); |
| 2564 } |
| 2565 |
2547 Node* WasmGraphBuilder::FunctionTable() { | 2566 Node* WasmGraphBuilder::FunctionTable() { |
2548 DCHECK(module_ && module_->instance && | 2567 DCHECK(module_ && module_->instance && |
2549 !module_->instance->function_table.is_null()); | 2568 !module_->instance->function_table.is_null()); |
2550 if (!function_table_) { | 2569 if (!function_table_) { |
2551 function_table_ = HeapConstant(module_->instance->function_table); | 2570 function_table_ = HeapConstant(module_->instance->function_table); |
2552 } | 2571 } |
2553 return function_table_; | 2572 return function_table_; |
2554 } | 2573 } |
2555 | 2574 |
2556 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { | 2575 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2922 } | 2941 } |
2923 // Add the function as another context for the exception | 2942 // Add the function as another context for the exception |
2924 ScopedVector<char> buffer(128); | 2943 ScopedVector<char> buffer(128); |
2925 wasm::WasmName name = module_env->module->GetName(function->name_offset, | 2944 wasm::WasmName name = module_env->module->GetName(function->name_offset, |
2926 function->name_length); | 2945 function->name_length); |
2927 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", | 2946 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", |
2928 function->func_index, name.length(), name.start()); | 2947 function->func_index, name.length(), name.start()); |
2929 thrower->Failed(buffer.start(), result); | 2948 thrower->Failed(buffer.start(), result); |
2930 return std::make_pair(nullptr, nullptr); | 2949 return std::make_pair(nullptr, nullptr); |
2931 } | 2950 } |
| 2951 |
| 2952 // Run lowering pass if SIMD ops are present in the function |
| 2953 if (builder.is_simd_function()) { |
| 2954 SimdLowering simd(jsgraph, &builder, module_env->instance->context); |
| 2955 GraphReducer graph_reducer(jsgraph->zone(), jsgraph->graph()); |
| 2956 graph_reducer.AddReducer(&simd); |
| 2957 graph_reducer.ReduceGraph(); |
| 2958 |
| 2959 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
| 2960 OFStream os(stdout); |
| 2961 os << "-- Graph after simd lowering -- " << std::endl; |
| 2962 os << AsRPO(*graph); |
| 2963 } |
| 2964 } |
| 2965 |
2932 int index = static_cast<int>(function->func_index); | 2966 int index = static_cast<int>(function->func_index); |
2933 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { | 2967 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { |
2934 PrintAst(isolate->allocator(), body); | 2968 PrintAst(isolate->allocator(), body); |
2935 } | 2969 } |
2936 if (FLAG_trace_wasm_decode_time) { | 2970 if (FLAG_trace_wasm_decode_time) { |
2937 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); | 2971 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); |
2938 } | 2972 } |
2939 return std::make_pair(jsgraph, source_position_table); | 2973 return std::make_pair(jsgraph, source_position_table); |
2940 } | 2974 } |
2941 | 2975 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 const wasm::WasmFunction* function) { | 3145 const wasm::WasmFunction* function) { |
3112 WasmCompilationUnit* unit = | 3146 WasmCompilationUnit* unit = |
3113 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); | 3147 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); |
3114 ExecuteCompilation(unit); | 3148 ExecuteCompilation(unit); |
3115 return FinishCompilation(unit); | 3149 return FinishCompilation(unit); |
3116 } | 3150 } |
3117 | 3151 |
3118 } // namespace compiler | 3152 } // namespace compiler |
3119 } // namespace internal | 3153 } // namespace internal |
3120 } // namespace v8 | 3154 } // namespace v8 |
OLD | NEW |