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