diff options
Diffstat (limited to 'deps/v8/test/cctest/compiler/test-multiple-return.cc')
-rw-r--r-- | deps/v8/test/cctest/compiler/test-multiple-return.cc | 173 |
1 files changed, 73 insertions, 100 deletions
diff --git a/deps/v8/test/cctest/compiler/test-multiple-return.cc b/deps/v8/test/cctest/compiler/test-multiple-return.cc index 1f46e87077..3e30ed2776 100644 --- a/deps/v8/test/cctest/compiler/test-multiple-return.cc +++ b/deps/v8/test/cctest/compiler/test-multiple-return.cc @@ -12,9 +12,13 @@ #include "src/codegen.h" #include "src/compiler.h" #include "src/compiler/linkage.h" +#include "src/compiler/wasm-compiler.h" #include "src/machine-type.h" #include "src/macro-assembler.h" #include "src/objects-inl.h" +#include "src/wasm/wasm-engine.h" +#include "src/wasm/wasm-objects-inl.h" +#include "src/wasm/wasm-opcodes.h" #include "test/cctest/cctest.h" #include "test/cctest/compiler/codegen-tester.h" #include "test/cctest/compiler/value-helper.h" @@ -25,89 +29,18 @@ namespace compiler { namespace { -int size(MachineType type) { - return 1 << ElementSizeLog2Of(type.representation()); -} - -int num_registers(MachineType type) { - const RegisterConfiguration* config = RegisterConfiguration::Default(); - switch (type.representation()) { - case MachineRepresentation::kWord32: - case MachineRepresentation::kWord64: - return config->num_allocatable_general_registers(); - case MachineRepresentation::kFloat32: - return config->num_allocatable_float_registers(); - case MachineRepresentation::kFloat64: - return config->num_allocatable_double_registers(); - default: - UNREACHABLE(); - } -} - -const int* codes(MachineType type) { - const RegisterConfiguration* config = RegisterConfiguration::Default(); - switch (type.representation()) { - case MachineRepresentation::kWord32: - case MachineRepresentation::kWord64: - return config->allocatable_general_codes(); - case MachineRepresentation::kFloat32: - return config->allocatable_float_codes(); - case MachineRepresentation::kFloat64: - return config->allocatable_double_codes(); - default: - UNREACHABLE(); - } -} +CallDescriptor* CreateCallDescriptor(Zone* zone, int return_count, + int param_count, MachineType type) { + wasm::FunctionSig::Builder builder(zone, return_count, param_count); -CallDescriptor* CreateMonoCallDescriptor(Zone* zone, int return_count, - int param_count, MachineType type) { - LocationSignature::Builder locations(zone, return_count, param_count); - - int span = std::max(1, size(type) / kPointerSize); - int stack_params = 0; for (int i = 0; i < param_count; i++) { - LinkageLocation location = LinkageLocation::ForAnyRegister(); - if (i < num_registers(type)) { - location = LinkageLocation::ForRegister(codes(type)[i], type); - } else { - int slot = span * (i - param_count); - location = LinkageLocation::ForCallerFrameSlot(slot, type); - stack_params += span; - } - locations.AddParam(location); + builder.AddParam(type.representation()); } - int stack_returns = 0; for (int i = 0; i < return_count; i++) { - LinkageLocation location = LinkageLocation::ForAnyRegister(); - if (i < num_registers(type)) { - location = LinkageLocation::ForRegister(codes(type)[i], type); - } else { - int slot = span * (num_registers(type) - i) - stack_params - 1; - location = LinkageLocation::ForCallerFrameSlot(slot, type); - stack_returns += span; - } - locations.AddReturn(location); + builder.AddReturn(type.representation()); } - - const RegList kCalleeSaveRegisters = 0; - const RegList kCalleeSaveFPRegisters = 0; - - MachineType target_type = MachineType::AnyTagged(); - LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type); - return new (zone) CallDescriptor( // -- - CallDescriptor::kCallCodeObject, // kind - target_type, // target MachineType - target_loc, // target location - locations.Build(), // location_sig - stack_params, // on-stack parameter count - compiler::Operator::kNoProperties, // properties - kCalleeSaveRegisters, // callee-saved registers - kCalleeSaveFPRegisters, // callee-saved fp regs - CallDescriptor::kNoFlags, // flags - "c-call", // debug name - 0, // allocatable registers - stack_returns); // on-stack return count + return compiler::GetWasmCallDescriptor(zone, builder.Build()); } } // namespace @@ -187,6 +120,17 @@ Node* ToInt32(RawMachineAssembler& m, MachineType type, Node* a) { } } +std::unique_ptr<wasm::NativeModule> AllocateNativeModule(Isolate* isolate, + size_t code_size) { + // We have to add the code object to a NativeModule, because the + // WasmCallDescriptor assumes that code is on the native heap and not + // within a code object. + std::unique_ptr<wasm::NativeModule> module = + isolate->wasm_engine()->code_manager()->NewNativeModule(code_size, 1, 0, + false); + return module; +} + void TestReturnMultipleValues(MachineType type) { const int kMaxCount = 20; for (int count = 0; count < kMaxCount; ++count) { @@ -194,15 +138,16 @@ void TestReturnMultipleValues(MachineType type) { MachineReprToString(type.representation()), count); v8::internal::AccountingAllocator allocator; Zone zone(&allocator, ZONE_NAME); - CallDescriptor* desc = CreateMonoCallDescriptor(&zone, count, 2, type); + CallDescriptor* desc = CreateCallDescriptor(&zone, count, 2, type); HandleAndZoneScope handles; RawMachineAssembler m(handles.main_isolate(), new (handles.main_zone()) Graph(handles.main_zone()), desc, MachineType::PointerRepresentation(), InstructionSelector::SupportedMachineOperatorFlags()); - Node* p0 = m.Parameter(0); - Node* p1 = m.Parameter(1); + // m.Parameter(0) is the WasmContext. + Node* p0 = m.Parameter(1); + Node* p1 = m.Parameter(2); typedef Node* Node_ptr; std::unique_ptr<Node_ptr[]> returns(new Node_ptr[count]); for (int i = 0; i < count; ++i) { @@ -212,8 +157,8 @@ void TestReturnMultipleValues(MachineType type) { } m.Return(count, returns.get()); - CompilationInfo info(ArrayVector("testing"), handles.main_zone(), - Code::STUB); + OptimizedCompilationInfo info(ArrayVector("testing"), handles.main_zone(), + Code::STUB); Handle<Code> code = Pipeline::GenerateCodeForTesting( &info, handles.main_isolate(), desc, m.graph(), m.Export()); #ifdef ENABLE_DISASSEMBLER @@ -232,11 +177,21 @@ void TestReturnMultipleValues(MachineType type) { if (i % 4 == 0) sign = -sign; } + std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule( + handles.main_isolate(), code->raw_instruction_size()); + byte* code_start = module->AddCodeCopy(code, wasm::WasmCode::kFunction, 0) + ->instructions() + .start(); + RawMachineAssemblerTester<int32_t> mt; - Node* na = Constant(mt, type, a); - Node* nb = Constant(mt, type, b); - Node* ret_multi = - mt.AddNode(mt.common()->Call(desc), mt.HeapConstant(code), na, nb); + Node* call_inputs[] = {mt.PointerConstant(code_start), + // WasmContext dummy + mt.PointerConstant(nullptr), + // Inputs + Constant(mt, type, a), Constant(mt, type, b)}; + + Node* ret_multi = mt.AddNode(mt.common()->Call(desc), + arraysize(call_inputs), call_inputs); Node* ret = Constant(mt, type, 0); bool sign = false; for (int i = 0; i < count; ++i) { @@ -275,10 +230,11 @@ void ReturnLastValue(MachineType type) { for (auto slot_count : slot_counts) { v8::internal::AccountingAllocator allocator; Zone zone(&allocator, ZONE_NAME); - const int return_count = num_registers(type) + slot_count; + // The wasm-linkage provides 2 return registers at the moment, on all + // platforms. + const int return_count = 2 + slot_count; - CallDescriptor* desc = - CreateMonoCallDescriptor(&zone, return_count, 0, type); + CallDescriptor* desc = CreateCallDescriptor(&zone, return_count, 0, type); HandleAndZoneScope handles; RawMachineAssembler m(handles.main_isolate(), @@ -294,17 +250,25 @@ void ReturnLastValue(MachineType type) { m.Return(return_count, returns.get()); - CompilationInfo info(ArrayVector("testing"), handles.main_zone(), - Code::STUB); + OptimizedCompilationInfo info(ArrayVector("testing"), handles.main_zone(), + Code::STUB); Handle<Code> code = Pipeline::GenerateCodeForTesting( &info, handles.main_isolate(), desc, m.graph(), m.Export()); + std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule( + handles.main_isolate(), code->raw_instruction_size()); + byte* code_start = module->AddCodeCopy(code, wasm::WasmCode::kFunction, 0) + ->instructions() + .start(); + // Generate caller. int expect = return_count - 1; RawMachineAssemblerTester<int32_t> mt; - Node* code_node = mt.HeapConstant(code); + Node* inputs[] = {mt.PointerConstant(code_start), + // WasmContext dummy + mt.PointerConstant(nullptr)}; - Node* call = mt.AddNode(mt.common()->Call(desc), 1, &code_node); + Node* call = mt.AddNode(mt.common()->Call(desc), 2, inputs); mt.Return(ToInt32( mt, type, mt.AddNode(mt.common()->Projection(return_count - 1), call))); @@ -326,10 +290,11 @@ void ReturnSumOfReturns(MachineType type) { v8::internal::AccountingAllocator allocator; Zone zone(&allocator, ZONE_NAME); // Let {unused_stack_slots + 1} returns be on the stack. - const int return_count = num_registers(type) + unused_stack_slots + 1; + // The wasm-linkage provides 2 return registers at the moment, on all + // platforms. + const int return_count = 2 + unused_stack_slots + 1; - CallDescriptor* desc = - CreateMonoCallDescriptor(&zone, return_count, 0, type); + CallDescriptor* desc = CreateCallDescriptor(&zone, return_count, 0, type); HandleAndZoneScope handles; RawMachineAssembler m(handles.main_isolate(), @@ -345,16 +310,24 @@ void ReturnSumOfReturns(MachineType type) { m.Return(return_count, returns.get()); - CompilationInfo info(ArrayVector("testing"), handles.main_zone(), - Code::STUB); + OptimizedCompilationInfo info(ArrayVector("testing"), handles.main_zone(), + Code::STUB); Handle<Code> code = Pipeline::GenerateCodeForTesting( &info, handles.main_isolate(), desc, m.graph(), m.Export()); + std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule( + handles.main_isolate(), code->raw_instruction_size()); + byte* code_start = module->AddCodeCopy(code, wasm::WasmCode::kFunction, 0) + ->instructions() + .start(); + // Generate caller. RawMachineAssemblerTester<int32_t> mt; - Node* code_node = mt.HeapConstant(code); + Node* call_inputs[] = {mt.PointerConstant(code_start), + // WasmContext dummy + mt.PointerConstant(nullptr)}; - Node* call = mt.AddNode(mt.common()->Call(desc), 1, &code_node); + Node* call = mt.AddNode(mt.common()->Call(desc), 2, call_inputs); uint32_t expect = 0; Node* result = mt.Int32Constant(0); |