Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 1991143002: Convert SIMD wasm ops to runtime function calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review changes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 SetHasSimdOps(true);
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 case wasm::kExprI64SConvertF32: 882 case wasm::kExprI64SConvertF32:
878 return BuildI64SConvertF32(input, position); 883 return BuildI64SConvertF32(input, position);
879 case wasm::kExprI64SConvertF64: 884 case wasm::kExprI64SConvertF64:
880 return BuildI64SConvertF64(input, position); 885 return BuildI64SConvertF64(input, position);
881 case wasm::kExprI64UConvertF32: 886 case wasm::kExprI64UConvertF32:
882 return BuildI64UConvertF32(input, position); 887 return BuildI64UConvertF32(input, position);
883 case wasm::kExprI64UConvertF64: 888 case wasm::kExprI64UConvertF64:
884 return BuildI64UConvertF64(input, position); 889 return BuildI64UConvertF64(input, position);
885 case wasm::kExprGrowMemory: 890 case wasm::kExprGrowMemory:
886 return BuildGrowMemory(input); 891 return BuildGrowMemory(input);
892 case wasm::kExprI32x4Splat:
893 SetHasSimdOps(true);
894 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), input,
895 input, input, input);
887 case wasm::kExprI32AsmjsLoadMem8S: 896 case wasm::kExprI32AsmjsLoadMem8S:
888 return BuildAsmjsLoadMem(MachineType::Int8(), input); 897 return BuildAsmjsLoadMem(MachineType::Int8(), input);
889 case wasm::kExprI32AsmjsLoadMem8U: 898 case wasm::kExprI32AsmjsLoadMem8U:
890 return BuildAsmjsLoadMem(MachineType::Uint8(), input); 899 return BuildAsmjsLoadMem(MachineType::Uint8(), input);
891 case wasm::kExprI32AsmjsLoadMem16S: 900 case wasm::kExprI32AsmjsLoadMem16S:
892 return BuildAsmjsLoadMem(MachineType::Int16(), input); 901 return BuildAsmjsLoadMem(MachineType::Int16(), input);
893 case wasm::kExprI32AsmjsLoadMem16U: 902 case wasm::kExprI32AsmjsLoadMem16U:
894 return BuildAsmjsLoadMem(MachineType::Uint16(), input); 903 return BuildAsmjsLoadMem(MachineType::Uint16(), input);
895 case wasm::kExprI32AsmjsLoadMem: 904 case wasm::kExprI32AsmjsLoadMem:
896 return BuildAsmjsLoadMem(MachineType::Int32(), input); 905 return BuildAsmjsLoadMem(MachineType::Int32(), input);
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 case wasm::kAstF64: 2248 case wasm::kAstF64:
2240 return BuildChangeFloat64ToTagged(node); 2249 return BuildChangeFloat64ToTagged(node);
2241 case wasm::kAstStmt: 2250 case wasm::kAstStmt:
2242 return jsgraph()->UndefinedConstant(); 2251 return jsgraph()->UndefinedConstant();
2243 default: 2252 default:
2244 UNREACHABLE(); 2253 UNREACHABLE();
2245 return nullptr; 2254 return nullptr;
2246 } 2255 }
2247 } 2256 }
2248 2257
2258 Node* WasmGraphBuilder::BuildChangeTaggedToInt32(Node* value) {
2259 value = BuildChangeTaggedToFloat64(value);
2260 value = graph()->NewNode(jsgraph()->machine()->ChangeFloat64ToInt32(), value);
2261 return value;
2262 }
2263
2249 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, 2264 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context,
2250 Node* effect, Node* control) { 2265 Node* effect, Node* control) {
2251 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); 2266 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate());
2252 CallDescriptor* desc = Linkage::GetStubCallDescriptor( 2267 CallDescriptor* desc = Linkage::GetStubCallDescriptor(
2253 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, 2268 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0,
2254 CallDescriptor::kNoFlags, Operator::kNoProperties); 2269 CallDescriptor::kNoFlags, Operator::kNoProperties);
2255 Node* stub_code = jsgraph()->HeapConstant(callable.code()); 2270 Node* stub_code = jsgraph()->HeapConstant(callable.code());
2256 2271
2257 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, 2272 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code,
2258 node, context, effect, control); 2273 node, context, effect, control);
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 if (!mem_size_) 2690 if (!mem_size_)
2676 mem_size_ = jsgraph()->RelocatableInt32Constant( 2691 mem_size_ = jsgraph()->RelocatableInt32Constant(
2677 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 2692 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2678 return mem_size_; 2693 return mem_size_;
2679 } else { 2694 } else {
2680 return jsgraph()->RelocatableInt32Constant( 2695 return jsgraph()->RelocatableInt32Constant(
2681 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 2696 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2682 } 2697 }
2683 } 2698 }
2684 2699
2700 Node* WasmGraphBuilder::DefaultS128Value() {
2701 Node* zero = jsgraph()->Int32Constant(0);
2702 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), zero, zero,
2703 zero, zero);
2704 }
2705
2685 Node* WasmGraphBuilder::FunctionTable() { 2706 Node* WasmGraphBuilder::FunctionTable() {
2686 DCHECK(module_ && module_->instance && 2707 DCHECK(module_ && module_->instance &&
2687 !module_->instance->function_table.is_null()); 2708 !module_->instance->function_table.is_null());
2688 if (!function_table_) { 2709 if (!function_table_) {
2689 function_table_ = HeapConstant(module_->instance->function_table); 2710 function_table_ = HeapConstant(module_->instance->function_table);
2690 } 2711 }
2691 return function_table_; 2712 return function_table_;
2692 } 2713 }
2693 2714
2694 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { 2715 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) {
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
3313 } 3334 }
3314 return nullptr; 3335 return nullptr;
3315 } 3336 }
3316 3337
3317 if (machine->Is32()) { 3338 if (machine->Is32()) {
3318 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig); 3339 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig);
3319 r.LowerGraph(); 3340 r.LowerGraph();
3320 } 3341 }
3321 3342
3322 int index = static_cast<int>(function_->func_index); 3343 int index = static_cast<int>(function_->func_index);
3344
3345 // Run lowering pass if SIMD ops are present in the function
3346 if (builder.HasSimdOps()) {
3347 SimdLowering simd(jsgraph_, &builder, module_env_->instance->context);
3348 GraphReducer graph_reducer(jsgraph_->zone(), graph);
3349 graph_reducer.AddReducer(&simd);
3350 graph_reducer.ReduceGraph();
3351
3352 if (FLAG_trace_turbo_graph) { // Simple textual RPO.
3353 OFStream os(stdout);
3354 os << "-- Graph after simd lowering -- " << std::endl;
3355 os << AsRPO(*graph);
3356 }
3357 }
3358
3323 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { 3359 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) {
3324 OFStream os(stdout); 3360 OFStream os(stdout);
3325 PrintAst(isolate_->allocator(), body, os, nullptr); 3361 PrintAst(isolate_->allocator(), body, os, nullptr);
3326 } 3362 }
3327 if (FLAG_trace_wasm_decode_time) { 3363 if (FLAG_trace_wasm_decode_time) {
3328 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); 3364 *decode_ms = decode_timer.Elapsed().InMillisecondsF();
3329 } 3365 }
3330 return source_position_table; 3366 return source_position_table;
3331 } 3367 }
3332 3368
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3459 function_->code_start_offset), 3495 function_->code_start_offset),
3460 compile_ms); 3496 compile_ms);
3461 } 3497 }
3462 3498
3463 return code; 3499 return code;
3464 } 3500 }
3465 3501
3466 } // namespace compiler 3502 } // namespace compiler
3467 } // namespace internal 3503 } // namespace internal
3468 } // namespace v8 3504 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698