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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 2358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2369 case wasm::kAstF64: | 2369 case wasm::kAstF64: |
2370 return BuildChangeFloat64ToTagged(node); | 2370 return BuildChangeFloat64ToTagged(node); |
2371 case wasm::kAstStmt: | 2371 case wasm::kAstStmt: |
2372 return jsgraph()->UndefinedConstant(); | 2372 return jsgraph()->UndefinedConstant(); |
2373 default: | 2373 default: |
2374 UNREACHABLE(); | 2374 UNREACHABLE(); |
2375 return nullptr; | 2375 return nullptr; |
2376 } | 2376 } |
2377 } | 2377 } |
2378 | 2378 |
2379 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context, | 2379 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context) { |
2380 Node* effect, Node* control) { | |
2381 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); | 2380 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); |
2382 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 2381 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
2383 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, | 2382 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, |
2384 CallDescriptor::kNoFlags, Operator::kNoProperties); | 2383 CallDescriptor::kNoFlags, Operator::kNoProperties); |
2385 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | 2384 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
2386 | 2385 |
2387 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, | 2386 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, |
2388 node, context, effect, control); | 2387 node, context, *effect_, *control_); |
2389 | 2388 |
2390 *effect_ = result; | 2389 *effect_ = result; |
2391 | 2390 |
2392 return result; | 2391 return result; |
2393 } | 2392 } |
2394 | 2393 |
2395 bool CanCover(Node* value, IrOpcode::Value opcode) { | 2394 bool CanCover(Node* value, IrOpcode::Value opcode) { |
2396 if (value->opcode() != opcode) return false; | 2395 if (value->opcode() != opcode) return false; |
2397 bool first = true; | 2396 bool first = true; |
2398 for (Edge const edge : value->use_edges()) { | 2397 for (Edge const edge : value->use_edges()) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2498 | 2497 |
2499 Node* merge = graph()->NewNode(common->Merge(2), if_not_smi, if_smi); | 2498 Node* merge = graph()->NewNode(common->Merge(2), if_not_smi, if_smi); |
2500 Node* phi = graph()->NewNode(common->Phi(MachineRepresentation::kFloat64, 2), | 2499 Node* phi = graph()->NewNode(common->Phi(MachineRepresentation::kFloat64, 2), |
2501 vnot_smi, vfrom_smi, merge); | 2500 vnot_smi, vfrom_smi, merge); |
2502 | 2501 |
2503 return phi; | 2502 return phi; |
2504 } | 2503 } |
2505 | 2504 |
2506 Node* WasmGraphBuilder::FromJS(Node* node, Node* context, | 2505 Node* WasmGraphBuilder::FromJS(Node* node, Node* context, |
2507 wasm::LocalType type) { | 2506 wasm::LocalType type) { |
| 2507 DCHECK_NE(wasm::kAstStmt, type); |
| 2508 |
2508 // Do a JavaScript ToNumber. | 2509 // Do a JavaScript ToNumber. |
2509 Node* num = BuildJavaScriptToNumber(node, context, *effect_, *control_); | 2510 Node* num = BuildJavaScriptToNumber(node, context); |
2510 | 2511 |
2511 // Change representation. | 2512 // Change representation. |
2512 SimplifiedOperatorBuilder simplified(jsgraph()->zone()); | 2513 SimplifiedOperatorBuilder simplified(jsgraph()->zone()); |
2513 num = BuildChangeTaggedToFloat64(num); | 2514 num = BuildChangeTaggedToFloat64(num); |
2514 | 2515 |
2515 switch (type) { | 2516 switch (type) { |
2516 case wasm::kAstI32: { | 2517 case wasm::kAstI32: { |
2517 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToWord32(), | 2518 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToWord32(), |
2518 num); | 2519 num); |
2519 break; | 2520 break; |
2520 } | 2521 } |
2521 case wasm::kAstS128: | 2522 case wasm::kAstS128: |
2522 case wasm::kAstI64: | 2523 case wasm::kAstI64: |
2523 // Throw a TypeError. The native context is good enough here because we | 2524 // Throw a TypeError. The native context is good enough here because we |
2524 // only throw a TypeError. | 2525 // only throw a TypeError. |
2525 return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), | 2526 return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), |
2526 jsgraph()->isolate()->native_context(), nullptr, | 2527 jsgraph()->isolate()->native_context(), nullptr, |
2527 0, effect_, *control_); | 2528 0, effect_, *control_); |
2528 case wasm::kAstF32: | 2529 case wasm::kAstF32: |
2529 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToFloat32(), | 2530 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToFloat32(), |
2530 num); | 2531 num); |
2531 break; | 2532 break; |
2532 case wasm::kAstF64: | 2533 case wasm::kAstF64: |
2533 break; | 2534 break; |
2534 case wasm::kAstStmt: | |
2535 num = jsgraph()->Int32Constant(0); | |
2536 break; | |
2537 default: | 2535 default: |
2538 UNREACHABLE(); | 2536 UNREACHABLE(); |
2539 return nullptr; | 2537 return nullptr; |
2540 } | 2538 } |
2541 return num; | 2539 return num; |
2542 } | 2540 } |
2543 | 2541 |
2544 Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { | 2542 Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { |
2545 if (jsgraph()->machine()->Is64()) { | 2543 if (jsgraph()->machine()->Is64()) { |
2546 value = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), value); | 2544 value = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), value); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2779 // is only needed if the target is a constructor to throw a TypeError, if | 2777 // is only needed if the target is a constructor to throw a TypeError, if |
2780 // the target is a native function, or if the target is a callable JSObject, | 2778 // the target is a native function, or if the target is a callable JSObject, |
2781 // which can only be constructed by the runtime. | 2779 // which can only be constructed by the runtime. |
2782 args[pos++] = HeapConstant(isolate->native_context()); | 2780 args[pos++] = HeapConstant(isolate->native_context()); |
2783 args[pos++] = *effect_; | 2781 args[pos++] = *effect_; |
2784 args[pos++] = *control_; | 2782 args[pos++] = *control_; |
2785 | 2783 |
2786 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); | 2784 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); |
2787 } | 2785 } |
2788 | 2786 |
| 2787 *effect_ = call; |
| 2788 |
2789 // Convert the return value back. | 2789 // Convert the return value back. |
2790 Node* ret; | 2790 Node* i32_zero = jsgraph()->Int32Constant(0); |
2791 Node* val = | 2791 Node* val = sig->return_count() == 0 |
2792 FromJS(call, HeapConstant(isolate->native_context()), | 2792 ? i32_zero |
2793 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); | 2793 : FromJS(call, HeapConstant(isolate->native_context()), |
2794 Node* pop_size = jsgraph()->Int32Constant(0); | 2794 sig->GetReturn()); |
2795 ret = graph()->NewNode(jsgraph()->common()->Return(), pop_size, val, call, | 2795 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), i32_zero, val, |
2796 start); | 2796 *effect_, start); |
2797 | 2797 |
2798 MergeControlToEnd(jsgraph(), ret); | 2798 MergeControlToEnd(jsgraph(), ret); |
2799 } | 2799 } |
2800 | 2800 |
2801 Node* WasmGraphBuilder::MemBuffer(uint32_t offset) { | 2801 Node* WasmGraphBuilder::MemBuffer(uint32_t offset) { |
2802 DCHECK(module_ && module_->instance); | 2802 DCHECK(module_ && module_->instance); |
2803 if (offset == 0) { | 2803 if (offset == 0) { |
2804 if (!mem_buffer_) { | 2804 if (!mem_buffer_) { |
2805 mem_buffer_ = jsgraph()->RelocatableIntPtrConstant( | 2805 mem_buffer_ = jsgraph()->RelocatableIntPtrConstant( |
2806 reinterpret_cast<uintptr_t>(module_->instance->mem_start), | 2806 reinterpret_cast<uintptr_t>(module_->instance->mem_start), |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3535 Smi::FromInt(instruction.instr_offset)); | 3535 Smi::FromInt(instruction.instr_offset)); |
3536 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3536 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
3537 Smi::FromInt(instruction.landing_offset)); | 3537 Smi::FromInt(instruction.landing_offset)); |
3538 } | 3538 } |
3539 return fn_protected; | 3539 return fn_protected; |
3540 } | 3540 } |
3541 | 3541 |
3542 } // namespace compiler | 3542 } // namespace compiler |
3543 } // namespace internal | 3543 } // namespace internal |
3544 } // namespace v8 | 3544 } // namespace v8 |
OLD | NEW |