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

Side by Side Diff: test/unittests/compiler/int64-lowering-unittest.cc

Issue 1714793003: [wasm] Unittest for Int64Lowering. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added tests for the other operators we already lower. Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "src/compiler/int64-lowering.h"
6 #include "src/compiler/common-operator.h"
7 #include "src/compiler/linkage.h"
8 #include "src/compiler/machine-operator.h"
9 #include "src/compiler/node.h"
10
11 #include "src/compiler/node-properties.h"
12
13 #include "src/signature.h"
14
15 #include "src/wasm/wasm-module.h"
16
17 #include "test/unittests/compiler/graph-unittest.h"
18 #include "test/unittests/compiler/node-test-utils.h"
19
20 namespace v8 {
21 namespace internal {
22 namespace compiler {
23
24 class Int64LoweringTest : public GraphTest {
25 public:
26 Int64LoweringTest() : GraphTest(), machine_(zone()) {}
27
28 MachineOperatorBuilder* machine() { return &machine_; }
29
30 void LowerGraph(Node* node, Signature<MachineRepresentation>* signature) {
31 Node* ret = graph()->NewNode(common()->Return(), node, graph()->start(),
32 graph()->start());
33 NodeProperties::MergeControlToEnd(graph(), common(), ret);
34
35 Int64Lowering lowering(graph(), machine(), common(), zone(), signature);
36 lowering.LowerGraph();
37 }
38
39 void LowerGraph(Node* node, MachineRepresentation return_type,
40 MachineRepresentation rep = MachineRepresentation::kWord32,
41 int num_params = 0) {
42 Signature<MachineRepresentation>::Builder sig_builder(zone(), 1,
43 num_params);
44 sig_builder.AddReturn(return_type);
45 for (int i = 0; i < num_params; i++) {
46 sig_builder.AddParam(rep);
47 }
48 LowerGraph(node, sig_builder.Build());
49 }
50
51 void CompareCallDescriptors(const CallDescriptor* lhs,
52 const CallDescriptor* rhs) {
53 EXPECT_THAT(lhs->CalleeSavedFPRegisters(), rhs->CalleeSavedFPRegisters());
54 EXPECT_THAT(lhs->CalleeSavedRegisters(), rhs->CalleeSavedRegisters());
55 EXPECT_THAT(lhs->FrameStateCount(), rhs->FrameStateCount());
56 EXPECT_THAT(lhs->InputCount(), rhs->InputCount());
57 for (size_t i = 0; i < lhs->InputCount(); i++) {
58 EXPECT_THAT(lhs->GetInputLocation(i), rhs->GetInputLocation(i));
59 EXPECT_THAT(lhs->GetInputType(i), rhs->GetInputType(i));
60 }
61 EXPECT_THAT(lhs->ReturnCount(), rhs->ReturnCount());
62 for (size_t i = 0; i < lhs->ReturnCount(); i++) {
63 EXPECT_THAT(lhs->GetReturnLocation(i), rhs->GetReturnLocation(i));
64 EXPECT_THAT(lhs->GetReturnType(i), rhs->GetReturnType(i));
65 }
66 EXPECT_THAT(lhs->flags(), rhs->flags());
67 EXPECT_THAT(lhs->kind(), rhs->kind());
68 }
69
70 int64_t value(int i) { return value_[i]; }
71
72 int32_t low_word_value(int i) {
73 return static_cast<int32_t>(value_[i] & 0xffffffff);
74 }
75
76 int32_t high_word_value(int i) {
77 return static_cast<int32_t>(value_[i] >> 32);
78 }
79
80 private:
81 MachineOperatorBuilder machine_;
82 int64_t value_[3] = {0x1234567890abcdef, 0x1edcba098765432f,
83 0x1133557799886644};
84 };
85
86 TEST_F(Int64LoweringTest, Int64Constant) {
87 if (4 != kPointerSize) return;
88
89 LowerGraph(Int64Constant(value(0)), MachineRepresentation::kWord64);
90 EXPECT_THAT(graph()->end()->InputAt(1),
91 IsReturn2(IsInt32Constant(low_word_value(0)),
92 IsInt32Constant(high_word_value(0)), start(), start()));
93 }
94
95 TEST_F(Int64LoweringTest, Int64Load) {
96 if (4 != kPointerSize) return;
97
98 int32_t base = 0x1234;
99 int32_t index = 0x5678;
100
101 LowerGraph(graph()->NewNode(machine()->Load(MachineType::Int64()),
102 Int32Constant(base), Int32Constant(index),
103 start(), start()),
104 MachineRepresentation::kWord64);
105
106 Matcher<Node*> high_word_load_matcher =
107 IsLoad(MachineType::Int32(), IsInt32Constant(base),
108 IsInt32Add(IsInt32Constant(index), IsInt32Constant(0x4)), start(),
109 start());
110
111 EXPECT_THAT(
112 graph()->end()->InputAt(1),
113 IsReturn2(IsLoad(MachineType::Int32(), IsInt32Constant(base),
114 IsInt32Constant(index), high_word_load_matcher, start()),
115 high_word_load_matcher, start(), start()));
116 }
117
118 TEST_F(Int64LoweringTest, Int64Store) {
119 if (4 != kPointerSize) return;
120
121 // We have to build the TF graph explicitly here because Store does not return
122 // a value.
123
124 int32_t base = 1111;
125 int32_t index = 2222;
126 int32_t return_value = 0x5555;
127
128 Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 0);
129 sig_builder.AddReturn(MachineRepresentation::kWord32);
130
131 Node* store = graph()->NewNode(
132 machine()->Store(StoreRepresentation(MachineRepresentation::kWord64,
133 WriteBarrierKind::kNoWriteBarrier)),
134 Int32Constant(base), Int32Constant(index), Int64Constant(value(0)),
135 start(), start());
136
137 Node* ret = graph()->NewNode(common()->Return(), Int32Constant(return_value),
138 store, start());
139
140 NodeProperties::MergeControlToEnd(graph(), common(), ret);
141
142 Int64Lowering lowering(graph(), machine(), common(), zone(),
143 sig_builder.Build());
144 lowering.LowerGraph();
145
146 const StoreRepresentation rep(MachineRepresentation::kWord32,
147 kNoWriteBarrier);
148
149 EXPECT_THAT(
150 graph()->end()->InputAt(1),
151 IsReturn(
152 IsInt32Constant(return_value),
153 IsStore(
154 rep, IsInt32Constant(base), IsInt32Constant(index),
155 IsInt32Constant(low_word_value(0)),
156 IsStore(rep, IsInt32Constant(base),
157 IsInt32Add(IsInt32Constant(index), IsInt32Constant(4)),
158 IsInt32Constant(high_word_value(0)), start(), start()),
159 start()),
160 start()));
161 }
162
163 TEST_F(Int64LoweringTest, Int64And) {
164 if (4 != kPointerSize) return;
165
166 LowerGraph(graph()->NewNode(machine()->Word64And(), Int64Constant(value(0)),
167 Int64Constant(value(1))),
168 MachineRepresentation::kWord64);
169 EXPECT_THAT(graph()->end()->InputAt(1),
170 IsReturn2(IsWord32And(IsInt32Constant(low_word_value(0)),
171 IsInt32Constant(low_word_value(1))),
172 IsWord32And(IsInt32Constant(high_word_value(0)),
173 IsInt32Constant(high_word_value(1))),
174 start(), start()));
175 }
176
177 TEST_F(Int64LoweringTest, TruncateInt64ToInt32) {
178 if (4 != kPointerSize) return;
179
180 LowerGraph(graph()->NewNode(machine()->TruncateInt64ToInt32(),
181 Int64Constant(value(0))),
182 MachineRepresentation::kWord32);
183 EXPECT_THAT(graph()->end()->InputAt(1),
184 IsReturn(IsInt32Constant(low_word_value(0)), start(), start()));
185 }
186
187 TEST_F(Int64LoweringTest, Parameter) {
188 if (4 != kPointerSize) return;
189
190 LowerGraph(Parameter(0), MachineRepresentation::kWord64,
191 MachineRepresentation::kWord64, 1);
192
193 EXPECT_THAT(graph()->end()->InputAt(1),
194 IsReturn2(IsParameter(0), IsParameter(1), start(), start()));
195 }
196
197 TEST_F(Int64LoweringTest, Parameter2) {
198 if (4 != kPointerSize) return;
199
200 Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 5);
201 sig_builder.AddReturn(MachineRepresentation::kWord32);
202
203 sig_builder.AddParam(MachineRepresentation::kWord32);
204 sig_builder.AddParam(MachineRepresentation::kWord64);
205 sig_builder.AddParam(MachineRepresentation::kFloat64);
206 sig_builder.AddParam(MachineRepresentation::kWord64);
207 sig_builder.AddParam(MachineRepresentation::kWord32);
208
209 int start_parameter = start()->op()->ValueOutputCount();
210 LowerGraph(Parameter(4), sig_builder.Build());
211
212 EXPECT_THAT(graph()->end()->InputAt(1),
213 IsReturn(IsParameter(6), start(), start()));
214 // The parameter of the start node should increase by 2, because we lowered
215 // two parameter nodes.
216 EXPECT_THAT(start()->op()->ValueOutputCount(), start_parameter + 2);
217 }
218
219 TEST_F(Int64LoweringTest, CallI64Return) {
220 if (4 != kPointerSize) return;
221
222 int32_t function = 0x9999;
223
224 Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 0);
225 sig_builder.AddReturn(MachineRepresentation::kWord64);
226
227 compiler::CallDescriptor* desc =
228 wasm::ModuleEnv::GetWasmCallDescriptor(zone(), sig_builder.Build());
229
230 LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function),
231 start(), start()),
232 MachineRepresentation::kWord64);
233
234 Matcher<Node*> call_matcher =
235 IsCall(testing::_, IsInt32Constant(function), start(), start());
236
237 EXPECT_THAT(graph()->end()->InputAt(1),
238 IsReturn2(IsProjection(0, call_matcher),
239 IsProjection(1, call_matcher), start(), start()));
240
241 CompareCallDescriptors(
242 OpParameter<const CallDescriptor*>(
243 graph()->end()->InputAt(1)->InputAt(0)->InputAt(0)),
244 wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc));
245 }
246
247 TEST_F(Int64LoweringTest, CallI64Parameter) {
248 if (4 != kPointerSize) return;
249
250 int32_t function = 0x9999;
251
252 Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 3);
253 sig_builder.AddReturn(MachineRepresentation::kWord32);
254 sig_builder.AddParam(MachineRepresentation::kWord64);
255 sig_builder.AddParam(MachineRepresentation::kWord32);
256 sig_builder.AddParam(MachineRepresentation::kWord64);
257
258 compiler::CallDescriptor* desc =
259 wasm::ModuleEnv::GetWasmCallDescriptor(zone(), sig_builder.Build());
260
261 LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function),
262 Int64Constant(value(0)),
263 Int32Constant(low_word_value(1)),
264 Int64Constant(value(2)), start(), start()),
265 MachineRepresentation::kWord32);
266
267 EXPECT_THAT(
268 graph()->end()->InputAt(1),
269 IsReturn(IsCall(testing::_, IsInt32Constant(function),
270 IsInt32Constant(low_word_value(0)),
271 IsInt32Constant(high_word_value(0)),
272 IsInt32Constant(low_word_value(1)),
273 IsInt32Constant(low_word_value(2)),
274 IsInt32Constant(high_word_value(2)), start(), start()),
275 start(), start()));
276
277 CompareCallDescriptors(
278 OpParameter<const CallDescriptor*>(
279 graph()->end()->InputAt(1)->InputAt(0)),
280 wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc));
281 }
282
283 } // namespace compiler
284 } // namespace internal
285 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698