| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 if (false) { | 275 if (false) { |
| 276 // End the control flow with a throw | 276 // End the control flow with a throw |
| 277 Node* thrw = | 277 Node* thrw = |
| 278 graph()->NewNode(common()->Throw(), jsgraph()->ZeroConstant(), | 278 graph()->NewNode(common()->Throw(), jsgraph()->ZeroConstant(), |
| 279 *effect_ptr, *control_ptr); | 279 *effect_ptr, *control_ptr); |
| 280 end = thrw; | 280 end = thrw; |
| 281 } else { | 281 } else { |
| 282 // End the control flow with returning 0xdeadbeef | 282 // End the control flow with returning 0xdeadbeef |
| 283 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); | 283 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); |
| 284 end = graph()->NewNode(jsgraph()->common()->Return(), | 284 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value, |
| 285 jsgraph()->Int32Constant(0), ret_value, | |
| 286 *effect_ptr, *control_ptr); | 285 *effect_ptr, *control_ptr); |
| 287 } | 286 } |
| 288 | 287 |
| 289 MergeControlToEnd(jsgraph(), end); | 288 MergeControlToEnd(jsgraph(), end); |
| 290 } | 289 } |
| 291 }; | 290 }; |
| 292 | 291 |
| 293 WasmGraphBuilder::WasmGraphBuilder( | 292 WasmGraphBuilder::WasmGraphBuilder( |
| 294 Zone* zone, JSGraph* jsgraph, wasm::FunctionSig* function_signature, | 293 Zone* zone, JSGraph* jsgraph, wasm::FunctionSig* function_signature, |
| 295 compiler::SourcePositionTable* source_position_table) | 294 compiler::SourcePositionTable* source_position_table) |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 | 1033 |
| 1035 Node* WasmGraphBuilder::IfDefault(Node* sw) { | 1034 Node* WasmGraphBuilder::IfDefault(Node* sw) { |
| 1036 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); | 1035 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); |
| 1037 return graph()->NewNode(jsgraph()->common()->IfDefault(), sw); | 1036 return graph()->NewNode(jsgraph()->common()->IfDefault(), sw); |
| 1038 } | 1037 } |
| 1039 | 1038 |
| 1040 Node* WasmGraphBuilder::Return(unsigned count, Node** vals) { | 1039 Node* WasmGraphBuilder::Return(unsigned count, Node** vals) { |
| 1041 DCHECK_NOT_NULL(*control_); | 1040 DCHECK_NOT_NULL(*control_); |
| 1042 DCHECK_NOT_NULL(*effect_); | 1041 DCHECK_NOT_NULL(*effect_); |
| 1043 | 1042 |
| 1044 Node** buf = Realloc(vals, count, count + 3); | 1043 Node** buf = Realloc(vals, count, count + 2); |
| 1045 memmove(buf + 1, buf, sizeof(void*) * count); | 1044 buf[count] = *effect_; |
| 1046 buf[0] = jsgraph()->Int32Constant(0); | 1045 buf[count + 1] = *control_; |
| 1047 buf[count + 1] = *effect_; | |
| 1048 buf[count + 2] = *control_; | |
| 1049 Node* ret = | 1046 Node* ret = |
| 1050 graph()->NewNode(jsgraph()->common()->Return(count), count + 3, buf); | 1047 graph()->NewNode(jsgraph()->common()->Return(count), count + 2, vals); |
| 1051 | 1048 |
| 1052 MergeControlToEnd(jsgraph(), ret); | 1049 MergeControlToEnd(jsgraph(), ret); |
| 1053 return ret; | 1050 return ret; |
| 1054 } | 1051 } |
| 1055 | 1052 |
| 1056 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } | 1053 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } |
| 1057 | 1054 |
| 1058 Node* WasmGraphBuilder::Unreachable(wasm::WasmCodePosition position) { | 1055 Node* WasmGraphBuilder::Unreachable(wasm::WasmCodePosition position) { |
| 1059 trap_->Unreachable(position); | 1056 trap_->Unreachable(position); |
| 1060 return nullptr; | 1057 return nullptr; |
| (...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2671 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); | 2668 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); |
| 2672 Node* retval = call; | 2669 Node* retval = call; |
| 2673 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && | 2670 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && |
| 2674 sig->GetReturn(0) == wasm::kAstI64) { | 2671 sig->GetReturn(0) == wasm::kAstI64) { |
| 2675 // The return values comes as two values, we pick the low word. | 2672 // The return values comes as two values, we pick the low word. |
| 2676 retval = graph()->NewNode(jsgraph()->common()->Projection(0), retval, | 2673 retval = graph()->NewNode(jsgraph()->common()->Projection(0), retval, |
| 2677 graph()->start()); | 2674 graph()->start()); |
| 2678 } | 2675 } |
| 2679 Node* jsval = ToJS( | 2676 Node* jsval = ToJS( |
| 2680 retval, sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); | 2677 retval, sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); |
| 2681 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), | 2678 Node* ret = |
| 2682 jsgraph()->Int32Constant(0), jsval, call, start); | 2679 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start); |
| 2683 | 2680 |
| 2684 MergeControlToEnd(jsgraph(), ret); | 2681 MergeControlToEnd(jsgraph(), ret); |
| 2685 } | 2682 } |
| 2686 | 2683 |
| 2687 int WasmGraphBuilder::AddParameterNodes(Node** args, int pos, int param_count, | 2684 int WasmGraphBuilder::AddParameterNodes(Node** args, int pos, int param_count, |
| 2688 wasm::FunctionSig* sig) { | 2685 wasm::FunctionSig* sig) { |
| 2689 // Convert WASM numbers to JS values. | 2686 // Convert WASM numbers to JS values. |
| 2690 int param_index = 0; | 2687 int param_index = 0; |
| 2691 for (int i = 0; i < param_count; ++i) { | 2688 for (int i = 0; i < param_count; ++i) { |
| 2692 Node* param = graph()->NewNode( | 2689 Node* param = graph()->NewNode( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2783 args[pos++] = *control_; | 2780 args[pos++] = *control_; |
| 2784 | 2781 |
| 2785 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); | 2782 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); |
| 2786 } | 2783 } |
| 2787 | 2784 |
| 2788 // Convert the return value back. | 2785 // Convert the return value back. |
| 2789 Node* ret; | 2786 Node* ret; |
| 2790 Node* val = | 2787 Node* val = |
| 2791 FromJS(call, HeapConstant(isolate->native_context()), | 2788 FromJS(call, HeapConstant(isolate->native_context()), |
| 2792 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); | 2789 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); |
| 2793 Node* pop_size = jsgraph()->Int32Constant(0); | |
| 2794 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && | 2790 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && |
| 2795 sig->GetReturn() == wasm::kAstI64) { | 2791 sig->GetReturn() == wasm::kAstI64) { |
| 2796 ret = graph()->NewNode(jsgraph()->common()->Return(), pop_size, val, | 2792 ret = graph()->NewNode(jsgraph()->common()->Return(), val, |
| 2797 graph()->NewNode(jsgraph()->machine()->Word32Sar(), | 2793 graph()->NewNode(jsgraph()->machine()->Word32Sar(), |
| 2798 val, jsgraph()->Int32Constant(31)), | 2794 val, jsgraph()->Int32Constant(31)), |
| 2799 call, start); | 2795 call, start); |
| 2800 } else { | 2796 } else { |
| 2801 ret = graph()->NewNode(jsgraph()->common()->Return(), pop_size, val, call, | 2797 ret = graph()->NewNode(jsgraph()->common()->Return(), val, call, start); |
| 2802 start); | |
| 2803 } | 2798 } |
| 2804 | 2799 |
| 2805 MergeControlToEnd(jsgraph(), ret); | 2800 MergeControlToEnd(jsgraph(), ret); |
| 2806 } | 2801 } |
| 2807 | 2802 |
| 2808 Node* WasmGraphBuilder::MemBuffer(uint32_t offset) { | 2803 Node* WasmGraphBuilder::MemBuffer(uint32_t offset) { |
| 2809 DCHECK(module_ && module_->instance); | 2804 DCHECK(module_ && module_->instance); |
| 2810 if (offset == 0) { | 2805 if (offset == 0) { |
| 2811 if (!mem_buffer_) { | 2806 if (!mem_buffer_) { |
| 2812 mem_buffer_ = jsgraph()->RelocatableIntPtrConstant( | 2807 mem_buffer_ = jsgraph()->RelocatableIntPtrConstant( |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3487 function_->code_start_offset), | 3482 function_->code_start_offset), |
| 3488 compile_ms); | 3483 compile_ms); |
| 3489 } | 3484 } |
| 3490 | 3485 |
| 3491 return code; | 3486 return code; |
| 3492 } | 3487 } |
| 3493 | 3488 |
| 3494 } // namespace compiler | 3489 } // namespace compiler |
| 3495 } // namespace internal | 3490 } // namespace internal |
| 3496 } // namespace v8 | 3491 } // namespace v8 |
| OLD | NEW |