Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: test/cctest/compiler/test-multiple-return.cc

Issue 1391333003: Adding support for multiple returns in compiled functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: formatting Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/unittests/compiler/common-operator-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cmath>
6 #include <functional>
7 #include <limits>
8
9 #include "src/assembler.h"
10 #include "src/base/bits.h"
11 #include "src/base/utils/random-number-generator.h"
12 #include "src/codegen.h"
13 #include "src/compiler.h"
14 #include "src/compiler/linkage.h"
15 #include "src/macro-assembler.h"
16 #include "test/cctest/cctest.h"
17 #include "test/cctest/compiler/codegen-tester.h"
18 #include "test/cctest/compiler/value-helper.h"
19
20
21 using namespace v8::base;
22 using namespace v8::internal;
23 using namespace v8::internal::compiler;
24
25
26 namespace {
27
28 CallDescriptor* GetCallDescriptor(Zone* zone, int return_count,
29 int param_count) {
30 MachineSignature::Builder msig(zone, return_count, param_count);
31 LocationSignature::Builder locations(zone, return_count, param_count);
32
33 // Add return location(s).
34 for (int i = 0; i < return_count; i++) {
35 msig.AddReturn(compiler::kMachInt32);
36 locations.AddReturn(LinkageLocation::ForRegister(i));
MTBrandyberry 2015/10/08 21:37:54 The set of register eligible for assignment as ret
37 }
38
39 // Add register and/or stack parameter(s).
40 for (int i = 0; i < param_count; i++) {
41 msig.AddParam(compiler::kMachInt32);
42 locations.AddParam(LinkageLocation::ForRegister(i));
43 }
44
45 const RegList kCalleeSaveRegisters = 0;
46 const RegList kCalleeSaveFPRegisters = 0;
47
48 // The target for WASM calls is always a code object.
49 MachineType target_type = compiler::kMachAnyTagged;
50 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
51 return new (zone) CallDescriptor( // --
52 CallDescriptor::kCallCodeObject, // kind
53 target_type, // target MachineType
54 target_loc, // target location
55 msig.Build(), // machine_sig
56 locations.Build(), // location_sig
57 0, // js_parameter_count
58 compiler::Operator::kNoProperties, // properties
59 kCalleeSaveRegisters, // callee-saved registers
60 kCalleeSaveFPRegisters, // callee-saved fp regs
61 CallDescriptor::kNoFlags, // flags
62 "c-call");
63 }
64 } // namespace
65
66
67 TEST(ReturnThreeValues) {
68 Zone zone;
69 CallDescriptor* desc = GetCallDescriptor(&zone, 3, 2);
70 HandleAndZoneScope handles;
71 RawMachineAssembler m(handles.main_isolate(),
72 new (handles.main_zone()) Graph(handles.main_zone()),
73 desc, kMachPtr,
74 InstructionSelector::SupportedMachineOperatorFlags());
75
76 Node* p0 = m.Parameter(0);
77 Node* p1 = m.Parameter(1);
78 Node* add = m.Int32Add(p0, p1);
79 Node* sub = m.Int32Sub(p0, p1);
80 Node* mul = m.Int32Mul(p0, p1);
81 m.Return(add, sub, mul);
82
83 CompilationInfo info("testing", handles.main_isolate(), handles.main_zone());
84 Handle<Code> code =
85 Pipeline::GenerateCodeForTesting(&info, desc, m.graph(), m.Export());
86 #ifdef ENABLE_DISASSEMBLER
87 if (FLAG_print_code) {
88 OFStream os(stdout);
89 code->Disassemble("three_value", os);
90 }
91 #endif
92
93 RawMachineAssemblerTester<int32_t> mt;
94 Node* a = mt.Int32Constant(123);
95 Node* b = mt.Int32Constant(456);
96 Node* ret3 = mt.AddNode(mt.common()->Call(desc), mt.HeapConstant(code), a, b);
97 Node* x = mt.AddNode(mt.common()->Projection(0), ret3);
98 Node* y = mt.AddNode(mt.common()->Projection(1), ret3);
99 Node* z = mt.AddNode(mt.common()->Projection(2), ret3);
100 Node* ret = mt.Int32Add(mt.Int32Add(x, y), z);
101 mt.Return(ret);
102 #ifdef ENABLE_DISASSEMBLER
103 Handle<Code> code2 = mt.GetCode();
104 if (FLAG_print_code) {
105 OFStream os(stdout);
106 code2->Disassemble("three_value_call", os);
107 }
108 #endif
109 CHECK_EQ((123 + 456) + (123 - 456) + (123 * 456), mt.Call());
110 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/unittests/compiler/common-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698