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 | 34 |
34 #include "src/wasm/ast-decoder.h" | 35 #include "src/wasm/ast-decoder.h" |
35 #include "src/wasm/wasm-module.h" | 36 #include "src/wasm/wasm-module.h" |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 case wasm::kExprF64Max: | 605 case wasm::kExprF64Max: |
605 return BuildF64Max(left, right); | 606 return BuildF64Max(left, right); |
606 case wasm::kExprF64Pow: | 607 case wasm::kExprF64Pow: |
607 op = m->Float64Pow(); | 608 op = m->Float64Pow(); |
608 break; | 609 break; |
609 case wasm::kExprF64Atan2: | 610 case wasm::kExprF64Atan2: |
610 op = m->Float64Atan2(); | 611 op = m->Float64Atan2(); |
611 break; | 612 break; |
612 case wasm::kExprF64Mod: | 613 case wasm::kExprF64Mod: |
613 return BuildF64Mod(left, right); | 614 return BuildF64Mod(left, right); |
615 case wasm::kExprI32x4ExtractLane: | |
616 set_has_simd_ops(true); | |
titzer
2016/07/08 14:16:03
Can you add a helper method called simd() that ret
gdeepti
2016/07/11 09:50:34
Added simd() helper method, a little fuzzy on what
| |
617 return graph()->NewNode(jsgraph()->machine()->Int32x4ExtractLane(), left, | |
618 right); | |
614 case wasm::kExprI32AsmjsDivS: | 619 case wasm::kExprI32AsmjsDivS: |
615 return BuildI32AsmjsDivS(left, right); | 620 return BuildI32AsmjsDivS(left, right); |
616 case wasm::kExprI32AsmjsDivU: | 621 case wasm::kExprI32AsmjsDivU: |
617 return BuildI32AsmjsDivU(left, right); | 622 return BuildI32AsmjsDivU(left, right); |
618 case wasm::kExprI32AsmjsRemS: | 623 case wasm::kExprI32AsmjsRemS: |
619 return BuildI32AsmjsRemS(left, right); | 624 return BuildI32AsmjsRemS(left, right); |
620 case wasm::kExprI32AsmjsRemU: | 625 case wasm::kExprI32AsmjsRemU: |
621 return BuildI32AsmjsRemU(left, right); | 626 return BuildI32AsmjsRemU(left, right); |
622 case wasm::kExprI32AsmjsStoreMem8: | 627 case wasm::kExprI32AsmjsStoreMem8: |
623 return BuildAsmjsStoreMem(MachineType::Int8(), left, right); | 628 return BuildAsmjsStoreMem(MachineType::Int8(), left, right); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 case wasm::kExprI64SConvertF32: | 884 case wasm::kExprI64SConvertF32: |
880 return BuildI64SConvertF32(input, position); | 885 return BuildI64SConvertF32(input, position); |
881 case wasm::kExprI64SConvertF64: | 886 case wasm::kExprI64SConvertF64: |
882 return BuildI64SConvertF64(input, position); | 887 return BuildI64SConvertF64(input, position); |
883 case wasm::kExprI64UConvertF32: | 888 case wasm::kExprI64UConvertF32: |
884 return BuildI64UConvertF32(input, position); | 889 return BuildI64UConvertF32(input, position); |
885 case wasm::kExprI64UConvertF64: | 890 case wasm::kExprI64UConvertF64: |
886 return BuildI64UConvertF64(input, position); | 891 return BuildI64UConvertF64(input, position); |
887 case wasm::kExprGrowMemory: | 892 case wasm::kExprGrowMemory: |
888 return BuildGrowMemory(input); | 893 return BuildGrowMemory(input); |
894 case wasm::kExprI32x4Splat: | |
895 set_has_simd_ops(true); | |
896 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), input, | |
897 input, input, input); | |
889 case wasm::kExprI32AsmjsLoadMem8S: | 898 case wasm::kExprI32AsmjsLoadMem8S: |
890 return BuildAsmjsLoadMem(MachineType::Int8(), input); | 899 return BuildAsmjsLoadMem(MachineType::Int8(), input); |
891 case wasm::kExprI32AsmjsLoadMem8U: | 900 case wasm::kExprI32AsmjsLoadMem8U: |
892 return BuildAsmjsLoadMem(MachineType::Uint8(), input); | 901 return BuildAsmjsLoadMem(MachineType::Uint8(), input); |
893 case wasm::kExprI32AsmjsLoadMem16S: | 902 case wasm::kExprI32AsmjsLoadMem16S: |
894 return BuildAsmjsLoadMem(MachineType::Int16(), input); | 903 return BuildAsmjsLoadMem(MachineType::Int16(), input); |
895 case wasm::kExprI32AsmjsLoadMem16U: | 904 case wasm::kExprI32AsmjsLoadMem16U: |
896 return BuildAsmjsLoadMem(MachineType::Uint16(), input); | 905 return BuildAsmjsLoadMem(MachineType::Uint16(), input); |
897 case wasm::kExprI32AsmjsLoadMem: | 906 case wasm::kExprI32AsmjsLoadMem: |
898 return BuildAsmjsLoadMem(MachineType::Int32(), input); | 907 return BuildAsmjsLoadMem(MachineType::Int32(), input); |
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2241 case wasm::kAstF64: | 2250 case wasm::kAstF64: |
2242 return BuildChangeFloat64ToTagged(node); | 2251 return BuildChangeFloat64ToTagged(node); |
2243 case wasm::kAstStmt: | 2252 case wasm::kAstStmt: |
2244 return jsgraph()->UndefinedConstant(); | 2253 return jsgraph()->UndefinedConstant(); |
2245 default: | 2254 default: |
2246 UNREACHABLE(); | 2255 UNREACHABLE(); |
2247 return nullptr; | 2256 return nullptr; |
2248 } | 2257 } |
2249 } | 2258 } |
2250 | 2259 |
2260 Node* WasmGraphBuilder::BuildChangeTaggedToInt32(Node* value) { | |
2261 value = BuildChangeTaggedToFloat64(value); | |
2262 value = graph()->NewNode(jsgraph()->machine()->ChangeFloat64ToInt32(), value); | |
2263 return value; | |
2264 } | |
2265 | |
2251 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, | 2266 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, |
2252 Node* effect, Node* control) { | 2267 Node* effect, Node* control) { |
2253 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); | 2268 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); |
2254 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 2269 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
2255 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, | 2270 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, |
2256 CallDescriptor::kNoFlags, Operator::kNoProperties); | 2271 CallDescriptor::kNoFlags, Operator::kNoProperties); |
2257 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | 2272 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
2258 | 2273 |
2259 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, | 2274 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, |
2260 node, context, effect, control); | 2275 node, context, effect, control); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2680 if (!mem_size_) | 2695 if (!mem_size_) |
2681 mem_size_ = jsgraph()->RelocatableInt32Constant( | 2696 mem_size_ = jsgraph()->RelocatableInt32Constant( |
2682 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 2697 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2683 return mem_size_; | 2698 return mem_size_; |
2684 } else { | 2699 } else { |
2685 return jsgraph()->RelocatableInt32Constant( | 2700 return jsgraph()->RelocatableInt32Constant( |
2686 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 2701 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2687 } | 2702 } |
2688 } | 2703 } |
2689 | 2704 |
2705 Node* WasmGraphBuilder::DefaultS128Value() { | |
2706 Node* zero = jsgraph()->Int32Constant(0); | |
2707 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), zero, zero, | |
2708 zero, zero); | |
2709 } | |
2710 | |
2690 Node* WasmGraphBuilder::FunctionTable() { | 2711 Node* WasmGraphBuilder::FunctionTable() { |
2691 DCHECK(module_ && module_->instance && | 2712 DCHECK(module_ && module_->instance && |
2692 !module_->instance->function_table.is_null()); | 2713 !module_->instance->function_table.is_null()); |
2693 if (!function_table_) { | 2714 if (!function_table_) { |
2694 function_table_ = HeapConstant(module_->instance->function_table); | 2715 function_table_ = HeapConstant(module_->instance->function_table); |
2695 } | 2716 } |
2696 return function_table_; | 2717 return function_table_; |
2697 } | 2718 } |
2698 | 2719 |
2720 Node* WasmGraphBuilder::ChangeToRuntimeCall(Node* node, | |
2721 Runtime::FunctionId function_id, | |
2722 const Conversion* signature) { | |
2723 SimplifiedOperatorBuilder simplified(jsgraph()->zone()); | |
2724 const Runtime::Function* function = Runtime::FunctionForId(function_id); | |
2725 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
2726 jsgraph()->zone(), function_id, function->nargs, Operator::kNoProperties, | |
2727 CallDescriptor::kNoFlags); | |
2728 const int kInputSize = 16; | |
2729 const int kDefaultFunctionParams = 6; | |
2730 Node* inputs[kInputSize + kDefaultFunctionParams]; | |
2731 DCHECK_LE(function->nargs + kDefaultFunctionParams, | |
2732 static_cast<int>(arraysize(inputs))); | |
2733 // Either there are control + effect or not. | |
titzer
2016/07/08 14:16:03
When do runtime calls not have effect and control
gdeepti
2016/07/11 09:50:34
Runtime calls always have effect and control, this
| |
2734 DCHECK(node->InputCount() == function->nargs || | |
2735 node->InputCount() == function->nargs + 2); | |
2736 int index = 0; | |
2737 inputs[index++] = jsgraph()->CEntryStubConstant(function->result_size); | |
2738 for (int i = 0; i < function->nargs; ++i) { | |
2739 Node* arg = node->InputAt(i); | |
2740 switch (signature[i + 1]) { | |
2741 case Conversion::kInt32: | |
2742 arg = BuildChangeInt32ToTagged(arg); | |
2743 break; | |
2744 case Conversion::kFloat32: | |
2745 arg = jsgraph()->graph()->NewNode( | |
2746 jsgraph()->machine()->ChangeFloat32ToFloat64(), arg); | |
2747 arg = BuildChangeFloat64ToTagged(arg); | |
2748 break; | |
2749 case Conversion::kFloat64: | |
2750 arg = BuildChangeFloat64ToTagged(arg); | |
2751 break; | |
2752 default: | |
2753 break; | |
2754 } | |
2755 inputs[index++] = arg; | |
2756 } | |
2757 inputs[index++] = jsgraph()->ExternalConstant( | |
2758 ExternalReference(function_id, jsgraph()->isolate())); | |
2759 inputs[index++] = jsgraph()->Int32Constant(function->nargs); | |
2760 inputs[index++] = jsgraph()->Constant(module_->instance->context); | |
2761 // Loads and stores have control and effect, others do not and use | |
2762 // the start node instead. | |
2763 if (node->InputCount() == function->nargs + 2) { | |
2764 inputs[index++] = node->InputAt(function->nargs + 1); // effect | |
2765 inputs[index++] = node->InputAt(function->nargs + 2); // control | |
2766 } else { | |
2767 inputs[index++] = jsgraph()->graph()->start(); // effect | |
2768 inputs[index++] = jsgraph()->graph()->start(); // control | |
2769 } | |
2770 Node* ret = jsgraph()->graph()->NewNode(jsgraph()->common()->Call(desc), | |
2771 index, inputs); | |
2772 | |
2773 Conversion return_type = signature[0]; | |
2774 switch (return_type) { | |
2775 case Conversion::kInt32: | |
2776 ret = BuildChangeTaggedToInt32(ret); | |
2777 break; | |
2778 case Conversion::kFloat32: | |
2779 NodeProperties::SetType(ret, Type::Number()); | |
2780 ret = BuildChangeTaggedToFloat64(ret); | |
2781 ret = jsgraph()->graph()->NewNode( | |
2782 jsgraph()->machine()->TruncateInt64ToInt32(), ret); | |
2783 break; | |
2784 case Conversion::kFloat64: | |
2785 ret = BuildChangeTaggedToFloat64(ret); | |
2786 break; | |
2787 default: | |
2788 break; | |
2789 } | |
2790 return ret; | |
2791 } | |
2792 | |
2699 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { | 2793 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { |
2700 MachineType mem_type = module_->GetGlobalType(index); | 2794 MachineType mem_type = module_->GetGlobalType(index); |
2701 Node* addr = jsgraph()->RelocatableIntPtrConstant( | 2795 Node* addr = jsgraph()->RelocatableIntPtrConstant( |
2702 reinterpret_cast<uintptr_t>(module_->instance->globals_start + | 2796 reinterpret_cast<uintptr_t>(module_->instance->globals_start + |
2703 module_->module->globals[index].offset), | 2797 module_->module->globals[index].offset), |
2704 RelocInfo::WASM_GLOBAL_REFERENCE); | 2798 RelocInfo::WASM_GLOBAL_REFERENCE); |
2705 const Operator* op = jsgraph()->machine()->Load(mem_type); | 2799 const Operator* op = jsgraph()->machine()->Load(mem_type); |
2706 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_, | 2800 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_, |
2707 *control_); | 2801 *control_); |
2708 *effect_ = node; | 2802 *effect_ = node; |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3318 } | 3412 } |
3319 return nullptr; | 3413 return nullptr; |
3320 } | 3414 } |
3321 | 3415 |
3322 if (machine->Is32()) { | 3416 if (machine->Is32()) { |
3323 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig); | 3417 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig); |
3324 r.LowerGraph(); | 3418 r.LowerGraph(); |
3325 } | 3419 } |
3326 | 3420 |
3327 int index = static_cast<int>(function_->func_index); | 3421 int index = static_cast<int>(function_->func_index); |
3422 | |
3423 // Run lowering pass if SIMD ops are present in the function | |
3424 if (builder.has_simd_ops()) { | |
3425 SimdLowering simd(&builder); | |
3426 GraphReducer graph_reducer(jsgraph_->zone(), graph); | |
3427 graph_reducer.AddReducer(&simd); | |
3428 graph_reducer.ReduceGraph(); | |
3429 | |
3430 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | |
3431 OFStream os(stdout); | |
3432 os << "-- Graph after simd lowering -- " << std::endl; | |
3433 os << AsRPO(*graph); | |
3434 } | |
3435 } | |
3436 | |
3328 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { | 3437 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { |
3329 OFStream os(stdout); | 3438 OFStream os(stdout); |
3330 PrintAst(isolate_->allocator(), body, os, nullptr); | 3439 PrintAst(isolate_->allocator(), body, os, nullptr); |
3331 } | 3440 } |
3332 if (FLAG_trace_wasm_decode_time) { | 3441 if (FLAG_trace_wasm_decode_time) { |
3333 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); | 3442 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); |
3334 } | 3443 } |
3335 return source_position_table; | 3444 return source_position_table; |
3336 } | 3445 } |
3337 | 3446 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3464 function_->code_start_offset), | 3573 function_->code_start_offset), |
3465 compile_ms); | 3574 compile_ms); |
3466 } | 3575 } |
3467 | 3576 |
3468 return code; | 3577 return code; |
3469 } | 3578 } |
3470 | 3579 |
3471 } // namespace compiler | 3580 } // namespace compiler |
3472 } // namespace internal | 3581 } // namespace internal |
3473 } // namespace v8 | 3582 } // namespace v8 |
OLD | NEW |