| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 Node* GetTrapValue(wasm::FunctionSig* sig) { | 246 Node* GetTrapValue(wasm::FunctionSig* sig) { |
| 247 if (sig->return_count() > 0) { | 247 if (sig->return_count() > 0) { |
| 248 return GetTrapValue(sig->GetReturn()); | 248 return GetTrapValue(sig->GetReturn()); |
| 249 } else { | 249 } else { |
| 250 return jsgraph()->Int32Constant(0xdeadbeef); | 250 return jsgraph()->Int32Constant(0xdeadbeef); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 Node* GetTrapValue(wasm::LocalType type) { | 254 Node* GetTrapValue(wasm::ValueType type) { |
| 255 switch (type) { | 255 switch (type) { |
| 256 case wasm::kAstI32: | 256 case wasm::kWasmI32: |
| 257 return jsgraph()->Int32Constant(0xdeadbeef); | 257 return jsgraph()->Int32Constant(0xdeadbeef); |
| 258 case wasm::kAstI64: | 258 case wasm::kWasmI64: |
| 259 return jsgraph()->Int64Constant(0xdeadbeefdeadbeef); | 259 return jsgraph()->Int64Constant(0xdeadbeefdeadbeef); |
| 260 case wasm::kAstF32: | 260 case wasm::kWasmF32: |
| 261 return jsgraph()->Float32Constant(bit_cast<float>(0xdeadbeef)); | 261 return jsgraph()->Float32Constant(bit_cast<float>(0xdeadbeef)); |
| 262 case wasm::kAstF64: | 262 case wasm::kWasmF64: |
| 263 return jsgraph()->Float64Constant(bit_cast<double>(0xdeadbeefdeadbeef)); | 263 return jsgraph()->Float64Constant(bit_cast<double>(0xdeadbeefdeadbeef)); |
| 264 break; | 264 break; |
| 265 case wasm::kAstS128: | 265 case wasm::kWasmS128: |
| 266 return builder_->CreateS128Value(0xdeadbeef); | 266 return builder_->CreateS128Value(0xdeadbeef); |
| 267 break; | 267 break; |
| 268 default: | 268 default: |
| 269 UNREACHABLE(); | 269 UNREACHABLE(); |
| 270 return nullptr; | 270 return nullptr; |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 | 273 |
| 274 private: | 274 private: |
| 275 WasmGraphBuilder* builder_; | 275 WasmGraphBuilder* builder_; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 : zone_(zone), | 346 : zone_(zone), |
| 347 jsgraph_(jsgraph), | 347 jsgraph_(jsgraph), |
| 348 function_tables_(zone), | 348 function_tables_(zone), |
| 349 function_table_sizes_(zone), | 349 function_table_sizes_(zone), |
| 350 cur_buffer_(def_buffer_), | 350 cur_buffer_(def_buffer_), |
| 351 cur_bufsize_(kDefaultBufferSize), | 351 cur_bufsize_(kDefaultBufferSize), |
| 352 trap_(new (zone) WasmTrapHelper(this)), | 352 trap_(new (zone) WasmTrapHelper(this)), |
| 353 sig_(sig), | 353 sig_(sig), |
| 354 source_position_table_(source_position_table) { | 354 source_position_table_(source_position_table) { |
| 355 for (size_t i = 0; i < sig->parameter_count(); i++) { | 355 for (size_t i = 0; i < sig->parameter_count(); i++) { |
| 356 if (sig->GetParam(i) == wasm::kAstS128) has_simd_ = true; | 356 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true; |
| 357 } | 357 } |
| 358 for (size_t i = 0; i < sig->return_count(); i++) { | 358 for (size_t i = 0; i < sig->return_count(); i++) { |
| 359 if (sig->GetReturn(i) == wasm::kAstS128) has_simd_ = true; | 359 if (sig->GetReturn(i) == wasm::kWasmS128) has_simd_ = true; |
| 360 } | 360 } |
| 361 DCHECK_NOT_NULL(jsgraph_); | 361 DCHECK_NOT_NULL(jsgraph_); |
| 362 } | 362 } |
| 363 | 363 |
| 364 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } | 364 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } |
| 365 | 365 |
| 366 Node* WasmGraphBuilder::Start(unsigned params) { | 366 Node* WasmGraphBuilder::Start(unsigned params) { |
| 367 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); | 367 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); |
| 368 graph()->SetStart(start); | 368 graph()->SetStart(start); |
| 369 return start; | 369 return start; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 int new_size = phi->InputCount(); | 420 int new_size = phi->InputCount(); |
| 421 phi->InsertInput(jsgraph()->zone(), phi->InputCount() - 1, from); | 421 phi->InsertInput(jsgraph()->zone(), phi->InputCount() - 1, from); |
| 422 NodeProperties::ChangeOp( | 422 NodeProperties::ChangeOp( |
| 423 phi, jsgraph()->common()->ResizeMergeOrPhi(phi->op(), new_size)); | 423 phi, jsgraph()->common()->ResizeMergeOrPhi(phi->op(), new_size)); |
| 424 } | 424 } |
| 425 | 425 |
| 426 Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { | 426 Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { |
| 427 return graph()->NewNode(jsgraph()->common()->Merge(count), count, controls); | 427 return graph()->NewNode(jsgraph()->common()->Merge(count), count, controls); |
| 428 } | 428 } |
| 429 | 429 |
| 430 Node* WasmGraphBuilder::Phi(wasm::LocalType type, unsigned count, Node** vals, | 430 Node* WasmGraphBuilder::Phi(wasm::ValueType type, unsigned count, Node** vals, |
| 431 Node* control) { | 431 Node* control) { |
| 432 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); | 432 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); |
| 433 Node** buf = Realloc(vals, count, count + 1); | 433 Node** buf = Realloc(vals, count, count + 1); |
| 434 buf[count] = control; | 434 buf[count] = control; |
| 435 return graph()->NewNode(jsgraph()->common()->Phi(type, count), count + 1, | 435 return graph()->NewNode(jsgraph()->common()->Phi(type, count), count + 1, |
| 436 buf); | 436 buf); |
| 437 } | 437 } |
| 438 | 438 |
| 439 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, | 439 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, |
| 440 Node* control) { | 440 Node* control) { |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 return m->Word32ReverseBytes().IsSupported(); | 1161 return m->Word32ReverseBytes().IsSupported(); |
| 1162 case 8: | 1162 case 8: |
| 1163 return m->Word64ReverseBytes().IsSupported(); | 1163 return m->Word64ReverseBytes().IsSupported(); |
| 1164 default: | 1164 default: |
| 1165 break; | 1165 break; |
| 1166 } | 1166 } |
| 1167 return false; | 1167 return false; |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 Node* WasmGraphBuilder::BuildChangeEndianness(Node* node, MachineType memtype, | 1170 Node* WasmGraphBuilder::BuildChangeEndianness(Node* node, MachineType memtype, |
| 1171 wasm::LocalType wasmtype) { | 1171 wasm::ValueType wasmtype) { |
| 1172 Node* result; | 1172 Node* result; |
| 1173 Node* value = node; | 1173 Node* value = node; |
| 1174 MachineOperatorBuilder* m = jsgraph()->machine(); | 1174 MachineOperatorBuilder* m = jsgraph()->machine(); |
| 1175 int valueSizeInBytes = 1 << ElementSizeLog2Of(memtype.representation()); | 1175 int valueSizeInBytes = 1 << ElementSizeLog2Of(memtype.representation()); |
| 1176 int valueSizeInBits = 8 * valueSizeInBytes; | 1176 int valueSizeInBits = 8 * valueSizeInBytes; |
| 1177 bool isFloat = false; | 1177 bool isFloat = false; |
| 1178 | 1178 |
| 1179 switch (memtype.representation()) { | 1179 switch (memtype.representation()) { |
| 1180 case MachineRepresentation::kFloat64: | 1180 case MachineRepresentation::kFloat64: |
| 1181 value = graph()->NewNode(m->BitcastFloat64ToInt64(), node); | 1181 value = graph()->NewNode(m->BitcastFloat64ToInt64(), node); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 } | 1277 } |
| 1278 | 1278 |
| 1279 // We need to sign extend the value | 1279 // We need to sign extend the value |
| 1280 if (memtype.IsSigned()) { | 1280 if (memtype.IsSigned()) { |
| 1281 DCHECK(!isFloat); | 1281 DCHECK(!isFloat); |
| 1282 if (valueSizeInBits < 32) { | 1282 if (valueSizeInBits < 32) { |
| 1283 Node* shiftBitCount; | 1283 Node* shiftBitCount; |
| 1284 // Perform sign extension using following trick | 1284 // Perform sign extension using following trick |
| 1285 // result = (x << machine_width - type_width) >> (machine_width - | 1285 // result = (x << machine_width - type_width) >> (machine_width - |
| 1286 // type_width) | 1286 // type_width) |
| 1287 if (wasmtype == wasm::kAstI64) { | 1287 if (wasmtype == wasm::kWasmI64) { |
| 1288 shiftBitCount = jsgraph()->Int32Constant(64 - valueSizeInBits); | 1288 shiftBitCount = jsgraph()->Int32Constant(64 - valueSizeInBits); |
| 1289 result = graph()->NewNode( | 1289 result = graph()->NewNode( |
| 1290 m->Word64Sar(), | 1290 m->Word64Sar(), |
| 1291 graph()->NewNode(m->Word64Shl(), | 1291 graph()->NewNode(m->Word64Shl(), |
| 1292 graph()->NewNode(m->ChangeInt32ToInt64(), result), | 1292 graph()->NewNode(m->ChangeInt32ToInt64(), result), |
| 1293 shiftBitCount), | 1293 shiftBitCount), |
| 1294 shiftBitCount); | 1294 shiftBitCount); |
| 1295 } else if (wasmtype == wasm::kAstI32) { | 1295 } else if (wasmtype == wasm::kWasmI32) { |
| 1296 shiftBitCount = jsgraph()->Int32Constant(32 - valueSizeInBits); | 1296 shiftBitCount = jsgraph()->Int32Constant(32 - valueSizeInBits); |
| 1297 result = graph()->NewNode( | 1297 result = graph()->NewNode( |
| 1298 m->Word32Sar(), | 1298 m->Word32Sar(), |
| 1299 graph()->NewNode(m->Word32Shl(), result, shiftBitCount), | 1299 graph()->NewNode(m->Word32Shl(), result, shiftBitCount), |
| 1300 shiftBitCount); | 1300 shiftBitCount); |
| 1301 } | 1301 } |
| 1302 } | 1302 } |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 return result; | 1305 return result; |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2462 | 2462 |
| 2463 // Allocate the box for the {value}. | 2463 // Allocate the box for the {value}. |
| 2464 vbox = BuildAllocateHeapNumberWithValue(value, if_box); | 2464 vbox = BuildAllocateHeapNumberWithValue(value, if_box); |
| 2465 | 2465 |
| 2466 Node* control = graph()->NewNode(common->Merge(2), if_smi, if_box); | 2466 Node* control = graph()->NewNode(common->Merge(2), if_smi, if_box); |
| 2467 value = graph()->NewNode(common->Phi(MachineRepresentation::kTagged, 2), vsmi, | 2467 value = graph()->NewNode(common->Phi(MachineRepresentation::kTagged, 2), vsmi, |
| 2468 vbox, control); | 2468 vbox, control); |
| 2469 return value; | 2469 return value; |
| 2470 } | 2470 } |
| 2471 | 2471 |
| 2472 Node* WasmGraphBuilder::ToJS(Node* node, wasm::LocalType type) { | 2472 Node* WasmGraphBuilder::ToJS(Node* node, wasm::ValueType type) { |
| 2473 switch (type) { | 2473 switch (type) { |
| 2474 case wasm::kAstI32: | 2474 case wasm::kWasmI32: |
| 2475 return BuildChangeInt32ToTagged(node); | 2475 return BuildChangeInt32ToTagged(node); |
| 2476 case wasm::kAstS128: | 2476 case wasm::kWasmS128: |
| 2477 case wasm::kAstI64: | 2477 case wasm::kWasmI64: |
| 2478 // Throw a TypeError. The native context is good enough here because we | 2478 // Throw a TypeError. The native context is good enough here because we |
| 2479 // only throw a TypeError. | 2479 // only throw a TypeError. |
| 2480 return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), | 2480 return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), |
| 2481 jsgraph()->isolate()->native_context(), nullptr, | 2481 jsgraph()->isolate()->native_context(), nullptr, |
| 2482 0, effect_, *control_); | 2482 0, effect_, *control_); |
| 2483 case wasm::kAstF32: | 2483 case wasm::kWasmF32: |
| 2484 node = graph()->NewNode(jsgraph()->machine()->ChangeFloat32ToFloat64(), | 2484 node = graph()->NewNode(jsgraph()->machine()->ChangeFloat32ToFloat64(), |
| 2485 node); | 2485 node); |
| 2486 return BuildChangeFloat64ToTagged(node); | 2486 return BuildChangeFloat64ToTagged(node); |
| 2487 case wasm::kAstF64: | 2487 case wasm::kWasmF64: |
| 2488 return BuildChangeFloat64ToTagged(node); | 2488 return BuildChangeFloat64ToTagged(node); |
| 2489 case wasm::kAstStmt: | 2489 case wasm::kWasmStmt: |
| 2490 return jsgraph()->UndefinedConstant(); | 2490 return jsgraph()->UndefinedConstant(); |
| 2491 default: | 2491 default: |
| 2492 UNREACHABLE(); | 2492 UNREACHABLE(); |
| 2493 return nullptr; | 2493 return nullptr; |
| 2494 } | 2494 } |
| 2495 } | 2495 } |
| 2496 | 2496 |
| 2497 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context) { | 2497 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context) { |
| 2498 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); | 2498 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); |
| 2499 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 2499 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2616 Node* vfrom_smi = BuildChangeSmiToFloat64(value); | 2616 Node* vfrom_smi = BuildChangeSmiToFloat64(value); |
| 2617 | 2617 |
| 2618 Node* merge = graph()->NewNode(common->Merge(2), if_not_smi, if_smi); | 2618 Node* merge = graph()->NewNode(common->Merge(2), if_not_smi, if_smi); |
| 2619 Node* phi = graph()->NewNode(common->Phi(MachineRepresentation::kFloat64, 2), | 2619 Node* phi = graph()->NewNode(common->Phi(MachineRepresentation::kFloat64, 2), |
| 2620 vnot_smi, vfrom_smi, merge); | 2620 vnot_smi, vfrom_smi, merge); |
| 2621 | 2621 |
| 2622 return phi; | 2622 return phi; |
| 2623 } | 2623 } |
| 2624 | 2624 |
| 2625 Node* WasmGraphBuilder::FromJS(Node* node, Node* context, | 2625 Node* WasmGraphBuilder::FromJS(Node* node, Node* context, |
| 2626 wasm::LocalType type) { | 2626 wasm::ValueType type) { |
| 2627 DCHECK_NE(wasm::kAstStmt, type); | 2627 DCHECK_NE(wasm::kWasmStmt, type); |
| 2628 | 2628 |
| 2629 // Do a JavaScript ToNumber. | 2629 // Do a JavaScript ToNumber. |
| 2630 Node* num = BuildJavaScriptToNumber(node, context); | 2630 Node* num = BuildJavaScriptToNumber(node, context); |
| 2631 | 2631 |
| 2632 // Change representation. | 2632 // Change representation. |
| 2633 SimplifiedOperatorBuilder simplified(jsgraph()->zone()); | 2633 SimplifiedOperatorBuilder simplified(jsgraph()->zone()); |
| 2634 num = BuildChangeTaggedToFloat64(num); | 2634 num = BuildChangeTaggedToFloat64(num); |
| 2635 | 2635 |
| 2636 switch (type) { | 2636 switch (type) { |
| 2637 case wasm::kAstI32: { | 2637 case wasm::kWasmI32: { |
| 2638 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToWord32(), | 2638 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToWord32(), |
| 2639 num); | 2639 num); |
| 2640 break; | 2640 break; |
| 2641 } | 2641 } |
| 2642 case wasm::kAstS128: | 2642 case wasm::kWasmS128: |
| 2643 case wasm::kAstI64: | 2643 case wasm::kWasmI64: |
| 2644 // Throw a TypeError. The native context is good enough here because we | 2644 // Throw a TypeError. The native context is good enough here because we |
| 2645 // only throw a TypeError. | 2645 // only throw a TypeError. |
| 2646 return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), | 2646 return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), |
| 2647 jsgraph()->isolate()->native_context(), nullptr, | 2647 jsgraph()->isolate()->native_context(), nullptr, |
| 2648 0, effect_, *control_); | 2648 0, effect_, *control_); |
| 2649 case wasm::kAstF32: | 2649 case wasm::kWasmF32: |
| 2650 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToFloat32(), | 2650 num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToFloat32(), |
| 2651 num); | 2651 num); |
| 2652 break; | 2652 break; |
| 2653 case wasm::kAstF64: | 2653 case wasm::kWasmF64: |
| 2654 break; | 2654 break; |
| 2655 default: | 2655 default: |
| 2656 UNREACHABLE(); | 2656 UNREACHABLE(); |
| 2657 return nullptr; | 2657 return nullptr; |
| 2658 } | 2658 } |
| 2659 return num; | 2659 return num; |
| 2660 } | 2660 } |
| 2661 | 2661 |
| 2662 Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { | 2662 Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { |
| 2663 if (jsgraph()->machine()->Is64()) { | 2663 if (jsgraph()->machine()->Is64()) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2763 graph()->start()); | 2763 graph()->start()); |
| 2764 | 2764 |
| 2765 int pos = 0; | 2765 int pos = 0; |
| 2766 args[pos++] = HeapConstant(wasm_code); | 2766 args[pos++] = HeapConstant(wasm_code); |
| 2767 | 2767 |
| 2768 // Convert JS parameters to WASM numbers. | 2768 // Convert JS parameters to WASM numbers. |
| 2769 for (int i = 0; i < wasm_count; ++i) { | 2769 for (int i = 0; i < wasm_count; ++i) { |
| 2770 Node* param = Param(i + 1); | 2770 Node* param = Param(i + 1); |
| 2771 Node* wasm_param = FromJS(param, context, sig->GetParam(i)); | 2771 Node* wasm_param = FromJS(param, context, sig->GetParam(i)); |
| 2772 args[pos++] = wasm_param; | 2772 args[pos++] = wasm_param; |
| 2773 if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kAstI64) { | 2773 if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kWasmI64) { |
| 2774 // We make up the high word with SAR to get the proper sign extension. | 2774 // We make up the high word with SAR to get the proper sign extension. |
| 2775 args[pos++] = graph()->NewNode(jsgraph()->machine()->Word32Sar(), | 2775 args[pos++] = graph()->NewNode(jsgraph()->machine()->Word32Sar(), |
| 2776 wasm_param, jsgraph()->Int32Constant(31)); | 2776 wasm_param, jsgraph()->Int32Constant(31)); |
| 2777 } | 2777 } |
| 2778 } | 2778 } |
| 2779 | 2779 |
| 2780 args[pos++] = *effect_; | 2780 args[pos++] = *effect_; |
| 2781 args[pos++] = *control_; | 2781 args[pos++] = *control_; |
| 2782 | 2782 |
| 2783 // Call the WASM code. | 2783 // Call the WASM code. |
| 2784 CallDescriptor* desc = | 2784 CallDescriptor* desc = |
| 2785 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); | 2785 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); |
| 2786 if (jsgraph()->machine()->Is32()) { | 2786 if (jsgraph()->machine()->Is32()) { |
| 2787 desc = wasm::ModuleEnv::GetI32WasmCallDescriptor(jsgraph()->zone(), desc); | 2787 desc = wasm::ModuleEnv::GetI32WasmCallDescriptor(jsgraph()->zone(), desc); |
| 2788 } | 2788 } |
| 2789 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); | 2789 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); |
| 2790 *effect_ = call; | 2790 *effect_ = call; |
| 2791 Node* retval = call; | 2791 Node* retval = call; |
| 2792 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && | 2792 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && |
| 2793 sig->GetReturn(0) == wasm::kAstI64) { | 2793 sig->GetReturn(0) == wasm::kWasmI64) { |
| 2794 // The return values comes as two values, we pick the low word. | 2794 // The return values comes as two values, we pick the low word. |
| 2795 retval = graph()->NewNode(jsgraph()->common()->Projection(0), retval, | 2795 retval = graph()->NewNode(jsgraph()->common()->Projection(0), retval, |
| 2796 graph()->start()); | 2796 graph()->start()); |
| 2797 } | 2797 } |
| 2798 Node* jsval = ToJS( | 2798 Node* jsval = ToJS( |
| 2799 retval, sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); | 2799 retval, sig->return_count() == 0 ? wasm::kWasmStmt : sig->GetReturn()); |
| 2800 Return(jsval); | 2800 Return(jsval); |
| 2801 } | 2801 } |
| 2802 | 2802 |
| 2803 int WasmGraphBuilder::AddParameterNodes(Node** args, int pos, int param_count, | 2803 int WasmGraphBuilder::AddParameterNodes(Node** args, int pos, int param_count, |
| 2804 wasm::FunctionSig* sig) { | 2804 wasm::FunctionSig* sig) { |
| 2805 // Convert WASM numbers to JS values. | 2805 // Convert WASM numbers to JS values. |
| 2806 int param_index = 0; | 2806 int param_index = 0; |
| 2807 for (int i = 0; i < param_count; ++i) { | 2807 for (int i = 0; i < param_count; ++i) { |
| 2808 Node* param = Param(param_index++); | 2808 Node* param = Param(param_index++); |
| 2809 args[pos++] = ToJS(param, sig->GetParam(i)); | 2809 args[pos++] = ToJS(param, sig->GetParam(i)); |
| 2810 if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kAstI64) { | 2810 if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kWasmI64) { |
| 2811 // On 32 bit platforms we have to skip the high word of int64 | 2811 // On 32 bit platforms we have to skip the high word of int64 |
| 2812 // parameters. | 2812 // parameters. |
| 2813 param_index++; | 2813 param_index++; |
| 2814 } | 2814 } |
| 2815 } | 2815 } |
| 2816 return pos; | 2816 return pos; |
| 2817 } | 2817 } |
| 2818 | 2818 |
| 2819 void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target, | 2819 void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target, |
| 2820 wasm::FunctionSig* sig) { | 2820 wasm::FunctionSig* sig) { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3054 } | 3054 } |
| 3055 } | 3055 } |
| 3056 | 3056 |
| 3057 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, | 3057 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
| 3058 jsgraph()->RelocatableInt32Constant( | 3058 jsgraph()->RelocatableInt32Constant( |
| 3059 static_cast<uint32_t>(effective_size), | 3059 static_cast<uint32_t>(effective_size), |
| 3060 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 3060 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 3061 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 3061 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
| 3062 } | 3062 } |
| 3063 | 3063 |
| 3064 | 3064 Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype, |
| 3065 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, | |
| 3066 Node* index, uint32_t offset, | 3065 Node* index, uint32_t offset, |
| 3067 uint32_t alignment, | 3066 uint32_t alignment, |
| 3068 wasm::WasmCodePosition position) { | 3067 wasm::WasmCodePosition position) { |
| 3069 Node* load; | 3068 Node* load; |
| 3070 | 3069 |
| 3071 // WASM semantics throw on OOB. Introduce explicit bounds check. | 3070 // WASM semantics throw on OOB. Introduce explicit bounds check. |
| 3072 if (!FLAG_wasm_trap_handler || !kTrapHandlerSupported) { | 3071 if (!FLAG_wasm_trap_handler || !kTrapHandlerSupported) { |
| 3073 BoundsCheckMem(memtype, index, offset, position); | 3072 BoundsCheckMem(memtype, index, offset, position); |
| 3074 } | 3073 } |
| 3075 bool aligned = static_cast<int>(alignment) >= | 3074 bool aligned = static_cast<int>(alignment) >= |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3094 load = graph()->NewNode(jsgraph()->machine()->UnalignedLoad(memtype), | 3093 load = graph()->NewNode(jsgraph()->machine()->UnalignedLoad(memtype), |
| 3095 MemBuffer(offset), index, *effect_, *control_); | 3094 MemBuffer(offset), index, *effect_, *control_); |
| 3096 } | 3095 } |
| 3097 | 3096 |
| 3098 *effect_ = load; | 3097 *effect_ = load; |
| 3099 | 3098 |
| 3100 #if defined(V8_TARGET_BIG_ENDIAN) | 3099 #if defined(V8_TARGET_BIG_ENDIAN) |
| 3101 load = BuildChangeEndianness(load, memtype, type); | 3100 load = BuildChangeEndianness(load, memtype, type); |
| 3102 #endif | 3101 #endif |
| 3103 | 3102 |
| 3104 if (type == wasm::kAstI64 && | 3103 if (type == wasm::kWasmI64 && |
| 3105 ElementSizeLog2Of(memtype.representation()) < 3) { | 3104 ElementSizeLog2Of(memtype.representation()) < 3) { |
| 3106 // TODO(titzer): TF zeroes the upper bits of 64-bit loads for subword sizes. | 3105 // TODO(titzer): TF zeroes the upper bits of 64-bit loads for subword sizes. |
| 3107 if (memtype.IsSigned()) { | 3106 if (memtype.IsSigned()) { |
| 3108 // sign extend | 3107 // sign extend |
| 3109 load = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), load); | 3108 load = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), load); |
| 3110 } else { | 3109 } else { |
| 3111 // zero extend | 3110 // zero extend |
| 3112 load = | 3111 load = |
| 3113 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), load); | 3112 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), load); |
| 3114 } | 3113 } |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3690 Smi::FromInt(instruction.instr_offset)); | 3689 Smi::FromInt(instruction.instr_offset)); |
| 3691 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3690 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
| 3692 Smi::FromInt(instruction.landing_offset)); | 3691 Smi::FromInt(instruction.landing_offset)); |
| 3693 } | 3692 } |
| 3694 return fn_protected; | 3693 return fn_protected; |
| 3695 } | 3694 } |
| 3696 | 3695 |
| 3697 } // namespace compiler | 3696 } // namespace compiler |
| 3698 } // namespace internal | 3697 } // namespace internal |
| 3699 } // namespace v8 | 3698 } // namespace v8 |
| OLD | NEW |