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 "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" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 345 |
346 | 346 |
347 Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { | 347 Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { |
348 return graph()->NewNode(jsgraph()->common()->Merge(count), count, controls); | 348 return graph()->NewNode(jsgraph()->common()->Merge(count), count, controls); |
349 } | 349 } |
350 | 350 |
351 | 351 |
352 Node* WasmGraphBuilder::Phi(wasm::LocalType type, unsigned count, Node** vals, | 352 Node* WasmGraphBuilder::Phi(wasm::LocalType type, unsigned count, Node** vals, |
353 Node* control) { | 353 Node* control) { |
354 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); | 354 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); |
355 Node** buf = Realloc(vals, count); | 355 Node** buf = Realloc(vals, count, count + 1); |
356 buf = Realloc(buf, count + 1); | |
357 buf[count] = control; | 356 buf[count] = control; |
358 return graph()->NewNode(jsgraph()->common()->Phi(type, count), count + 1, | 357 return graph()->NewNode(jsgraph()->common()->Phi(type, count), count + 1, |
359 buf); | 358 buf); |
360 } | 359 } |
361 | 360 |
362 | 361 |
363 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, | 362 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, |
364 Node* control) { | 363 Node* control) { |
365 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); | 364 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); |
366 Node** buf = Realloc(effects, count); | 365 Node** buf = Realloc(effects, count, count + 1); |
367 buf = Realloc(buf, count + 1); | |
368 buf[count] = control; | 366 buf[count] = control; |
369 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, | 367 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, |
370 buf); | 368 buf); |
371 } | 369 } |
372 | 370 |
373 | 371 |
374 Node* WasmGraphBuilder::Int32Constant(int32_t value) { | 372 Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
375 return jsgraph()->Int32Constant(value); | 373 return jsgraph()->Int32Constant(value); |
376 } | 374 } |
377 | 375 |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 Node* WasmGraphBuilder::Return(unsigned count, Node** vals) { | 967 Node* WasmGraphBuilder::Return(unsigned count, Node** vals) { |
970 DCHECK_NOT_NULL(*control_); | 968 DCHECK_NOT_NULL(*control_); |
971 DCHECK_NOT_NULL(*effect_); | 969 DCHECK_NOT_NULL(*effect_); |
972 | 970 |
973 if (count == 0) { | 971 if (count == 0) { |
974 // Handle a return of void. | 972 // Handle a return of void. |
975 vals[0] = jsgraph()->Int32Constant(0); | 973 vals[0] = jsgraph()->Int32Constant(0); |
976 count = 1; | 974 count = 1; |
977 } | 975 } |
978 | 976 |
979 Node** buf = Realloc(vals, count); | 977 Node** buf = Realloc(vals, count, count + 2); |
980 buf = Realloc(buf, count + 2); | |
981 buf[count] = *effect_; | 978 buf[count] = *effect_; |
982 buf[count + 1] = *control_; | 979 buf[count + 1] = *control_; |
983 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), count + 2, vals); | 980 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), count + 2, vals); |
984 | 981 |
985 MergeControlToEnd(jsgraph(), ret); | 982 MergeControlToEnd(jsgraph(), ret); |
986 return ret; | 983 return ret; |
987 } | 984 } |
988 | 985 |
989 | 986 |
990 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } | 987 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 Node* stack_slot_param0 = | 1559 Node* stack_slot_param0 = |
1563 graph()->NewNode(jsgraph()->machine()->StackSlot(type.representation())); | 1560 graph()->NewNode(jsgraph()->machine()->StackSlot(type.representation())); |
1564 | 1561 |
1565 const Operator* store_op0 = jsgraph()->machine()->Store( | 1562 const Operator* store_op0 = jsgraph()->machine()->Store( |
1566 StoreRepresentation(type.representation(), kNoWriteBarrier)); | 1563 StoreRepresentation(type.representation(), kNoWriteBarrier)); |
1567 *effect_ = graph()->NewNode(store_op0, stack_slot_param0, | 1564 *effect_ = graph()->NewNode(store_op0, stack_slot_param0, |
1568 jsgraph()->Int32Constant(0), input0, *effect_, | 1565 jsgraph()->Int32Constant(0), input0, *effect_, |
1569 *control_); | 1566 *control_); |
1570 | 1567 |
1571 Node* function = graph()->NewNode(jsgraph()->common()->ExternalConstant(ref)); | 1568 Node* function = graph()->NewNode(jsgraph()->common()->ExternalConstant(ref)); |
1572 Node** args = Buffer(4); | 1569 Node** args = Buffer(5); |
1573 args[0] = function; | 1570 args[0] = function; |
1574 args[1] = stack_slot_param0; | 1571 args[1] = stack_slot_param0; |
1575 int input_count = 1; | 1572 int input_count = 1; |
1576 | 1573 |
1577 if (input1 != nullptr) { | 1574 if (input1 != nullptr) { |
1578 Node* stack_slot_param1 = graph()->NewNode( | 1575 Node* stack_slot_param1 = graph()->NewNode( |
1579 jsgraph()->machine()->StackSlot(type.representation())); | 1576 jsgraph()->machine()->StackSlot(type.representation())); |
1580 const Operator* store_op1 = jsgraph()->machine()->Store( | 1577 const Operator* store_op1 = jsgraph()->machine()->Store( |
1581 StoreRepresentation(type.representation(), kNoWriteBarrier)); | 1578 StoreRepresentation(type.representation(), kNoWriteBarrier)); |
1582 *effect_ = graph()->NewNode(store_op1, stack_slot_param1, | 1579 *effect_ = graph()->NewNode(store_op1, stack_slot_param1, |
1583 jsgraph()->Int32Constant(0), input1, *effect_, | 1580 jsgraph()->Int32Constant(0), input1, *effect_, |
1584 *control_); | 1581 *control_); |
1585 args = Realloc(args, 5); | |
1586 args[2] = stack_slot_param1; | 1582 args[2] = stack_slot_param1; |
1587 ++input_count; | 1583 ++input_count; |
1588 } | 1584 } |
1589 | 1585 |
1590 Signature<MachineType>::Builder sig_builder(jsgraph()->zone(), 0, | 1586 Signature<MachineType>::Builder sig_builder(jsgraph()->zone(), 0, |
1591 input_count); | 1587 input_count); |
1592 sig_builder.AddParam(MachineType::Pointer()); | 1588 sig_builder.AddParam(MachineType::Pointer()); |
1593 if (input1 != nullptr) { | 1589 if (input1 != nullptr) { |
1594 sig_builder.AddParam(MachineType::Pointer()); | 1590 sig_builder.AddParam(MachineType::Pointer()); |
1595 } | 1591 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 *effect_ = load; | 1844 *effect_ = load; |
1849 return load; | 1845 return load; |
1850 } | 1846 } |
1851 | 1847 |
1852 Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node** args) { | 1848 Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node** args) { |
1853 const size_t params = sig->parameter_count(); | 1849 const size_t params = sig->parameter_count(); |
1854 const size_t extra = 2; // effect and control inputs. | 1850 const size_t extra = 2; // effect and control inputs. |
1855 const size_t count = 1 + params + extra; | 1851 const size_t count = 1 + params + extra; |
1856 | 1852 |
1857 // Reallocate the buffer to make space for extra inputs. | 1853 // Reallocate the buffer to make space for extra inputs. |
1858 args = Realloc(args, count); | 1854 args = Realloc(args, 1 + params, count); |
1859 | 1855 |
1860 // Add effect and control inputs. | 1856 // Add effect and control inputs. |
1861 args[params + 1] = *effect_; | 1857 args[params + 1] = *effect_; |
1862 args[params + 2] = *control_; | 1858 args[params + 2] = *control_; |
1863 | 1859 |
1864 CallDescriptor* desc = | 1860 CallDescriptor* desc = |
1865 Linkage::GetSimplifiedCDescriptor(jsgraph()->zone(), sig); | 1861 Linkage::GetSimplifiedCDescriptor(jsgraph()->zone(), sig); |
1866 | 1862 |
1867 const Operator* op = jsgraph()->common()->Call(desc); | 1863 const Operator* op = jsgraph()->common()->Call(desc); |
1868 Node* call = graph()->NewNode(op, static_cast<int>(count), args); | 1864 Node* call = graph()->NewNode(op, static_cast<int>(count), args); |
1869 *effect_ = call; | 1865 *effect_ = call; |
1870 return call; | 1866 return call; |
1871 } | 1867 } |
1872 | 1868 |
1873 Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args) { | 1869 Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args) { |
1874 const size_t params = sig->parameter_count(); | 1870 const size_t params = sig->parameter_count(); |
1875 const size_t extra = 2; // effect and control inputs. | 1871 const size_t extra = 2; // effect and control inputs. |
1876 const size_t count = 1 + params + extra; | 1872 const size_t count = 1 + params + extra; |
1877 | 1873 |
1878 // Reallocate the buffer to make space for extra inputs. | 1874 // Reallocate the buffer to make space for extra inputs. |
1879 args = Realloc(args, count); | 1875 args = Realloc(args, 1 + params, count); |
1880 | 1876 |
1881 // Add effect and control inputs. | 1877 // Add effect and control inputs. |
1882 args[params + 1] = *effect_; | 1878 args[params + 1] = *effect_; |
1883 args[params + 2] = *control_; | 1879 args[params + 2] = *control_; |
1884 | 1880 |
1885 CallDescriptor* descriptor = | 1881 CallDescriptor* descriptor = |
1886 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); | 1882 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); |
1887 const Operator* op = jsgraph()->common()->Call(descriptor); | 1883 const Operator* op = jsgraph()->common()->Call(descriptor); |
1888 Node* call = graph()->NewNode(op, static_cast<int>(count), args); | 1884 Node* call = graph()->NewNode(op, static_cast<int>(count), args); |
1889 | 1885 |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2658 static_cast<int>(function.code_end_offset - function.code_start_offset), | 2654 static_cast<int>(function.code_end_offset - function.code_start_offset), |
2659 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); | 2655 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); |
2660 } | 2656 } |
2661 return code; | 2657 return code; |
2662 } | 2658 } |
2663 | 2659 |
2664 | 2660 |
2665 } // namespace compiler | 2661 } // namespace compiler |
2666 } // namespace internal | 2662 } // namespace internal |
2667 } // namespace v8 | 2663 } // namespace v8 |
OLD | NEW |