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

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: Fix bot fails 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
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 case wasm::kAstF64: 2340 case wasm::kAstF64:
2340 return BuildChangeFloat64ToTagged(node); 2341 return BuildChangeFloat64ToTagged(node);
2341 case wasm::kAstStmt: 2342 case wasm::kAstStmt:
2342 return jsgraph()->UndefinedConstant(); 2343 return jsgraph()->UndefinedConstant();
2343 default: 2344 default:
2344 UNREACHABLE(); 2345 UNREACHABLE();
2345 return nullptr; 2346 return nullptr;
2346 } 2347 }
2347 } 2348 }
2348 2349
2350 Node* WasmGraphBuilder::BuildChangeTaggedToInt32(Node* value) {
2351 value = BuildChangeTaggedToFloat64(value);
2352 value = graph()->NewNode(jsgraph()->machine()->ChangeFloat64ToInt32(), value);
2353 return value;
2354 }
2355
2349 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, 2356 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context,
2350 Node* effect, Node* control) { 2357 Node* effect, Node* control) {
2351 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); 2358 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate());
2352 CallDescriptor* desc = Linkage::GetStubCallDescriptor( 2359 CallDescriptor* desc = Linkage::GetStubCallDescriptor(
2353 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, 2360 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0,
2354 CallDescriptor::kNoFlags, Operator::kNoProperties); 2361 CallDescriptor::kNoFlags, Operator::kNoProperties);
2355 Node* stub_code = jsgraph()->HeapConstant(callable.code()); 2362 Node* stub_code = jsgraph()->HeapConstant(callable.code());
2356 2363
2357 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, 2364 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code,
2358 node, context, effect, control); 2365 node, context, effect, control);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2778 if (!mem_size_) 2785 if (!mem_size_)
2779 mem_size_ = jsgraph()->RelocatableInt32Constant( 2786 mem_size_ = jsgraph()->RelocatableInt32Constant(
2780 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 2787 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2781 return mem_size_; 2788 return mem_size_;
2782 } else { 2789 } else {
2783 return jsgraph()->RelocatableInt32Constant( 2790 return jsgraph()->RelocatableInt32Constant(
2784 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 2791 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2785 } 2792 }
2786 } 2793 }
2787 2794
2795 Node* WasmGraphBuilder::DefaultS128Value() {
2796 Node* zero = jsgraph()->Int32Constant(0);
2797 return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), zero, zero,
2798 zero, zero);
2799 }
2800
2788 Node* WasmGraphBuilder::FunctionTable() { 2801 Node* WasmGraphBuilder::FunctionTable() {
2789 DCHECK(module_ && module_->instance && 2802 DCHECK(module_ && module_->instance &&
2790 !module_->instance->function_table.is_null()); 2803 !module_->instance->function_table.is_null());
2791 if (!function_table_) { 2804 if (!function_table_) {
2792 function_table_ = HeapConstant(module_->instance->function_table); 2805 function_table_ = HeapConstant(module_->instance->function_table);
2793 } 2806 }
2794 return function_table_; 2807 return function_table_;
2795 } 2808 }
2796 2809
2810 Node* WasmGraphBuilder::ChangeToRuntimeCall(Node* node,
2811 Runtime::FunctionId function_id,
2812 Signature<Conversion>* signature) {
2813 SimplifiedOperatorBuilder simplified(jsgraph()->zone());
2814 const Runtime::Function* function = Runtime::FunctionForId(function_id);
2815 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
2816 jsgraph()->zone(), function_id, function->nargs, Operator::kNoProperties,
2817 CallDescriptor::kNoFlags);
2818 const int kInputSize = 16;
2819 const int kDefaultFunctionParams = 6;
2820 Node* inputs[kInputSize + kDefaultFunctionParams];
2821 DCHECK_LE(function->nargs + kDefaultFunctionParams,
2822 static_cast<int>(arraysize(inputs)));
2823 // Either there are control + effect or not.
2824 DCHECK(node->InputCount() == function->nargs ||
2825 node->InputCount() == function->nargs + 2);
2826 int index = 0;
2827 inputs[index++] = jsgraph()->CEntryStubConstant(function->result_size);
2828 for (int i = 0; i < function->nargs; ++i) {
2829 Node* arg = node->InputAt(i);
2830 switch (signature->GetParam(i)) {
2831 case Conversion::kInt32:
2832 arg = BuildChangeInt32ToTagged(arg);
2833 break;
2834 case Conversion::kFloat32:
2835 arg = jsgraph()->graph()->NewNode(
2836 jsgraph()->machine()->ChangeFloat32ToFloat64(), arg);
2837 arg = BuildChangeFloat64ToTagged(arg);
2838 break;
2839 case Conversion::kFloat64:
2840 arg = BuildChangeFloat64ToTagged(arg);
2841 break;
2842 default:
2843 break;
2844 }
2845 inputs[index++] = arg;
2846 }
2847 inputs[index++] = jsgraph()->ExternalConstant(
2848 ExternalReference(function_id, jsgraph()->isolate()));
2849 inputs[index++] = jsgraph()->Int32Constant(function->nargs);
2850 inputs[index++] = jsgraph()->Constant(module_->instance->context);
2851 // Loads and stores have control and effect, others do not and use
2852 // the start node instead.
2853 if (node->InputCount() == function->nargs + 2) {
2854 inputs[index++] = node->InputAt(function->nargs + 1); // effect
2855 inputs[index++] = node->InputAt(function->nargs + 2); // control
2856 } else {
2857 inputs[index++] = jsgraph()->graph()->start(); // effect
2858 inputs[index++] = jsgraph()->graph()->start(); // control
2859 }
2860 Node* ret = jsgraph()->graph()->NewNode(jsgraph()->common()->Call(desc),
2861 index, inputs);
2862
2863 Conversion return_type = signature->GetReturn();
2864 switch (return_type) {
2865 case Conversion::kInt32:
2866 ret = BuildChangeTaggedToInt32(ret);
2867 break;
2868 case Conversion::kFloat32:
2869 NodeProperties::SetType(ret, Type::Number());
2870 ret = BuildChangeTaggedToFloat64(ret);
2871 ret = jsgraph()->graph()->NewNode(
2872 jsgraph()->machine()->TruncateInt64ToInt32(), ret);
2873 break;
2874 case Conversion::kFloat64:
2875 ret = BuildChangeTaggedToFloat64(ret);
2876 break;
2877 default:
2878 break;
2879 }
2880 return ret;
2881 }
2882
2797 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) { 2883 Node* WasmGraphBuilder::LoadGlobal(uint32_t index) {
2798 MachineType mem_type = module_->GetGlobalType(index); 2884 MachineType mem_type = module_->GetGlobalType(index);
2799 Node* addr = jsgraph()->RelocatableIntPtrConstant( 2885 Node* addr = jsgraph()->RelocatableIntPtrConstant(
2800 reinterpret_cast<uintptr_t>(module_->instance->globals_start + 2886 reinterpret_cast<uintptr_t>(module_->instance->globals_start +
2801 module_->module->globals[index].offset), 2887 module_->module->globals[index].offset),
2802 RelocInfo::WASM_GLOBAL_REFERENCE); 2888 RelocInfo::WASM_GLOBAL_REFERENCE);
2803 const Operator* op = jsgraph()->machine()->Load(mem_type); 2889 const Operator* op = jsgraph()->machine()->Load(mem_type);
2804 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_, 2890 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_,
2805 *control_); 2891 *control_);
2806 *effect_ = node; 2892 *effect_ = node;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
3183 } 3269 }
3184 3270
3185 void WasmGraphBuilder::SetSourcePosition(Node* node, 3271 void WasmGraphBuilder::SetSourcePosition(Node* node,
3186 wasm::WasmCodePosition position) { 3272 wasm::WasmCodePosition position) {
3187 DCHECK_NE(position, wasm::kNoCodePosition); 3273 DCHECK_NE(position, wasm::kNoCodePosition);
3188 compiler::SourcePosition pos(position); 3274 compiler::SourcePosition pos(position);
3189 if (source_position_table_) 3275 if (source_position_table_)
3190 source_position_table_->SetSourcePosition(node, pos); 3276 source_position_table_->SetSourcePosition(node, pos);
3191 } 3277 }
3192 3278
3279 MachineOperatorBuilder* WasmGraphBuilder::simd() {
3280 has_simd_ops_ = true;
3281 return jsgraph()->machine();
3282 }
3283
3284 Node* WasmGraphBuilder::SimdOp(wasm::WasmOpcode opcode,
3285 const NodeVector& inputs) {
3286 switch (opcode) {
3287 case wasm::kExprI32x4ExtractLane:
3288 return graph()->NewNode(simd()->Int32x4ExtractLane(), inputs[0],
3289 inputs[1]);
3290 case wasm::kExprI32x4Splat:
3291 return graph()->NewNode(simd()->CreateInt32x4(), inputs[0], inputs[0],
3292 inputs[0], inputs[0]);
3293 default:
3294 return graph()->NewNode(UnsupportedOpcode(opcode), nullptr);
3295 }
3296 }
3297
3193 static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag, 3298 static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
3194 Isolate* isolate, Handle<Code> code, 3299 Isolate* isolate, Handle<Code> code,
3195 const char* message, uint32_t index, 3300 const char* message, uint32_t index,
3196 const wasm::WasmName& module_name, 3301 const wasm::WasmName& module_name,
3197 const wasm::WasmName& func_name) { 3302 const wasm::WasmName& func_name) {
3198 DCHECK(isolate->logger()->is_logging_code_events() || 3303 DCHECK(isolate->logger()->is_logging_code_events() ||
3199 isolate->is_profiling()); 3304 isolate->is_profiling());
3200 3305
3201 ScopedVector<char> buffer(128); 3306 ScopedVector<char> buffer(128);
3202 SNPrintF(buffer, "%s#%d:%.*s:%.*s", message, index, module_name.length(), 3307 SNPrintF(buffer, "%s#%d:%.*s:%.*s", message, index, module_name.length(),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
3395 } 3500 }
3396 return nullptr; 3501 return nullptr;
3397 } 3502 }
3398 3503
3399 if (machine->Is32()) { 3504 if (machine->Is32()) {
3400 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig); 3505 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig);
3401 r.LowerGraph(); 3506 r.LowerGraph();
3402 } 3507 }
3403 3508
3404 int index = static_cast<int>(function_->func_index); 3509 int index = static_cast<int>(function_->func_index);
3510
3511 // Run lowering pass if SIMD ops are present in the function
3512 if (builder.has_simd_ops()) {
3513 SimdLowering simd(jsgraph_->zone(), &builder);
3514 GraphReducer graph_reducer(jsgraph_->zone(), graph);
3515 graph_reducer.AddReducer(&simd);
3516 graph_reducer.ReduceGraph();
3517
3518 if (FLAG_trace_turbo_graph) { // Simple textual RPO.
3519 OFStream os(stdout);
3520 os << "-- Graph after simd lowering -- " << std::endl;
3521 os << AsRPO(*graph);
3522 }
3523 }
3524
3405 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { 3525 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) {
3406 OFStream os(stdout); 3526 OFStream os(stdout);
3407 PrintAst(isolate_->allocator(), body, os, nullptr); 3527 PrintAst(isolate_->allocator(), body, os, nullptr);
3408 } 3528 }
3409 if (FLAG_trace_wasm_decode_time) { 3529 if (FLAG_trace_wasm_decode_time) {
3410 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); 3530 *decode_ms = decode_timer.Elapsed().InMillisecondsF();
3411 } 3531 }
3412 return source_position_table; 3532 return source_position_table;
3413 } 3533 }
3414 3534
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 function_->code_start_offset), 3661 function_->code_start_offset),
3542 compile_ms); 3662 compile_ms);
3543 } 3663 }
3544 3664
3545 return code; 3665 return code;
3546 } 3666 }
3547 3667
3548 } // namespace compiler 3668 } // namespace compiler
3549 } // namespace internal 3669 } // namespace internal
3550 } // namespace v8 3670 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698