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

Side by Side Diff: test/cctest/compiler/test-changes-lowering.cc

Issue 470593002: Unify MachineType and RepType. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/compiler/test-branch-combine.cc ('k') | test/cctest/compiler/test-codegen-deopt.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 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 <limits> 5 #include <limits>
6 6
7 #include "src/compiler/control-builders.h" 7 #include "src/compiler/control-builders.h"
8 #include "src/compiler/generic-node-inl.h" 8 #include "src/compiler/generic-node-inl.h"
9 #include "src/compiler/node-properties-inl.h" 9 #include "src/compiler/node-properties-inl.h"
10 #include "src/compiler/pipeline.h" 10 #include "src/compiler/pipeline.h"
11 #include "src/compiler/simplified-lowering.h" 11 #include "src/compiler/simplified-lowering.h"
12 #include "src/compiler/simplified-node-factory.h" 12 #include "src/compiler/simplified-node-factory.h"
13 #include "src/compiler/typer.h" 13 #include "src/compiler/typer.h"
14 #include "src/compiler/verifier.h" 14 #include "src/compiler/verifier.h"
15 #include "src/execution.h" 15 #include "src/execution.h"
16 #include "src/parser.h" 16 #include "src/parser.h"
17 #include "src/rewriter.h" 17 #include "src/rewriter.h"
18 #include "src/scopes.h" 18 #include "src/scopes.h"
19 #include "test/cctest/cctest.h" 19 #include "test/cctest/cctest.h"
20 #include "test/cctest/compiler/codegen-tester.h" 20 #include "test/cctest/compiler/codegen-tester.h"
21 #include "test/cctest/compiler/graph-builder-tester.h" 21 #include "test/cctest/compiler/graph-builder-tester.h"
22 #include "test/cctest/compiler/value-helper.h" 22 #include "test/cctest/compiler/value-helper.h"
23 23
24 using namespace v8::internal; 24 using namespace v8::internal;
25 using namespace v8::internal::compiler; 25 using namespace v8::internal::compiler;
26 26
27 template <typename ReturnType> 27 template <typename ReturnType>
28 class ChangesLoweringTester : public GraphBuilderTester<ReturnType> { 28 class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
29 public: 29 public:
30 explicit ChangesLoweringTester(MachineType p0 = kMachineLast) 30 explicit ChangesLoweringTester(MachineType p0 = kMachNone)
31 : GraphBuilderTester<ReturnType>(p0), 31 : GraphBuilderTester<ReturnType>(p0),
32 typer(this->zone()), 32 typer(this->zone()),
33 source_positions(this->graph()), 33 source_positions(this->graph()),
34 jsgraph(this->graph(), this->common(), &typer), 34 jsgraph(this->graph(), this->common(), &typer),
35 lowering(&jsgraph, &source_positions), 35 lowering(&jsgraph, &source_positions),
36 function(Handle<JSFunction>::null()) {} 36 function(Handle<JSFunction>::null()) {}
37 37
38 Typer typer; 38 Typer typer;
39 SourcePositionTable source_positions; 39 SourcePositionTable source_positions;
40 JSGraph jsgraph; 40 JSGraph jsgraph;
(...skipping 29 matching lines...) Expand all
70 } 70 }
71 Handle<Object>* args = NULL; 71 Handle<Object>* args = NULL;
72 MaybeHandle<Object> result = 72 MaybeHandle<Object> result =
73 Execution::Call(this->isolate(), function, factory()->undefined_value(), 73 Execution::Call(this->isolate(), function, factory()->undefined_value(),
74 0, args, false); 74 0, args, false);
75 return T::cast(*result.ToHandleChecked()); 75 return T::cast(*result.ToHandleChecked());
76 } 76 }
77 77
78 void StoreFloat64(Node* node, double* ptr) { 78 void StoreFloat64(Node* node, double* ptr) {
79 Node* ptr_node = this->PointerConstant(ptr); 79 Node* ptr_node = this->PointerConstant(ptr);
80 this->Store(kMachineFloat64, ptr_node, node); 80 this->Store(kMachFloat64, ptr_node, node);
81 } 81 }
82 82
83 Node* LoadInt32(int32_t* ptr) { 83 Node* LoadInt32(int32_t* ptr) {
84 Node* ptr_node = this->PointerConstant(ptr); 84 Node* ptr_node = this->PointerConstant(ptr);
85 return this->Load(kMachineWord32, ptr_node); 85 return this->Load(kMachInt32, ptr_node);
86 } 86 }
87 87
88 Node* LoadUint32(uint32_t* ptr) { 88 Node* LoadUint32(uint32_t* ptr) {
89 Node* ptr_node = this->PointerConstant(ptr); 89 Node* ptr_node = this->PointerConstant(ptr);
90 return this->Load(kMachineWord32, ptr_node); 90 return this->Load(kMachUint32, ptr_node);
91 } 91 }
92 92
93 Node* LoadFloat64(double* ptr) { 93 Node* LoadFloat64(double* ptr) {
94 Node* ptr_node = this->PointerConstant(ptr); 94 Node* ptr_node = this->PointerConstant(ptr);
95 return this->Load(kMachineFloat64, ptr_node); 95 return this->Load(kMachFloat64, ptr_node);
96 } 96 }
97 97
98 void CheckNumber(double expected, Object* number) { 98 void CheckNumber(double expected, Object* number) {
99 CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number)); 99 CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number));
100 } 100 }
101 101
102 void BuildAndLower(Operator* op) { 102 void BuildAndLower(Operator* op) {
103 // We build a graph by hand here, because the raw machine assembler 103 // We build a graph by hand here, because the raw machine assembler
104 // does not add the correct control and effect nodes. 104 // does not add the correct control and effect nodes.
105 Node* p0 = this->Parameter(0); 105 Node* p0 = this->Parameter(0);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 Verifier::Run(this->graph()); 143 Verifier::Run(this->graph());
144 } 144 }
145 145
146 Factory* factory() { return this->isolate()->factory(); } 146 Factory* factory() { return this->isolate()->factory(); }
147 Heap* heap() { return this->isolate()->heap(); } 147 Heap* heap() { return this->isolate()->heap(); }
148 }; 148 };
149 149
150 150
151 TEST(RunChangeTaggedToInt32) { 151 TEST(RunChangeTaggedToInt32) {
152 // Build and lower a graph by hand. 152 // Build and lower a graph by hand.
153 ChangesLoweringTester<int32_t> t(kMachineTagged); 153 ChangesLoweringTester<int32_t> t(kMachAnyTagged);
154 t.BuildAndLower(t.simplified()->ChangeTaggedToInt32()); 154 t.BuildAndLower(t.simplified()->ChangeTaggedToInt32());
155 155
156 if (Pipeline::SupportedTarget()) { 156 if (Pipeline::SupportedTarget()) {
157 FOR_INT32_INPUTS(i) { 157 FOR_INT32_INPUTS(i) {
158 int32_t input = *i; 158 int32_t input = *i;
159 159
160 if (Smi::IsValid(input)) { 160 if (Smi::IsValid(input)) {
161 int32_t result = t.Call(Smi::FromInt(input)); 161 int32_t result = t.Call(Smi::FromInt(input));
162 CHECK_EQ(input, result); 162 CHECK_EQ(input, result);
163 } 163 }
164 164
165 { 165 {
166 Handle<Object> number = t.factory()->NewNumber(input); 166 Handle<Object> number = t.factory()->NewNumber(input);
167 int32_t result = t.Call(*number); 167 int32_t result = t.Call(*number);
168 CHECK_EQ(input, result); 168 CHECK_EQ(input, result);
169 } 169 }
170 170
171 { 171 {
172 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); 172 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
173 int32_t result = t.Call(*number); 173 int32_t result = t.Call(*number);
174 CHECK_EQ(input, result); 174 CHECK_EQ(input, result);
175 } 175 }
176 } 176 }
177 } 177 }
178 } 178 }
179 179
180 180
181 TEST(RunChangeTaggedToUint32) { 181 TEST(RunChangeTaggedToUint32) {
182 // Build and lower a graph by hand. 182 // Build and lower a graph by hand.
183 ChangesLoweringTester<uint32_t> t(kMachineTagged); 183 ChangesLoweringTester<uint32_t> t(kMachAnyTagged);
184 t.BuildAndLower(t.simplified()->ChangeTaggedToUint32()); 184 t.BuildAndLower(t.simplified()->ChangeTaggedToUint32());
185 185
186 if (Pipeline::SupportedTarget()) { 186 if (Pipeline::SupportedTarget()) {
187 FOR_UINT32_INPUTS(i) { 187 FOR_UINT32_INPUTS(i) {
188 uint32_t input = *i; 188 uint32_t input = *i;
189 189
190 if (Smi::IsValid(input)) { 190 if (Smi::IsValid(input)) {
191 uint32_t result = t.Call(Smi::FromInt(input)); 191 uint32_t result = t.Call(Smi::FromInt(input));
192 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); 192 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result));
193 } 193 }
194 194
195 { 195 {
196 Handle<Object> number = t.factory()->NewNumber(input); 196 Handle<Object> number = t.factory()->NewNumber(input);
197 uint32_t result = t.Call(*number); 197 uint32_t result = t.Call(*number);
198 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); 198 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result));
199 } 199 }
200 200
201 { 201 {
202 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); 202 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
203 uint32_t result = t.Call(*number); 203 uint32_t result = t.Call(*number);
204 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); 204 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result));
205 } 205 }
206 } 206 }
207 } 207 }
208 } 208 }
209 209
210 210
211 TEST(RunChangeTaggedToFloat64) { 211 TEST(RunChangeTaggedToFloat64) {
212 ChangesLoweringTester<int32_t> t(kMachineTagged); 212 ChangesLoweringTester<int32_t> t(kMachAnyTagged);
213 double result; 213 double result;
214 214
215 t.BuildStoreAndLower(t.simplified()->ChangeTaggedToFloat64(), 215 t.BuildStoreAndLower(t.simplified()->ChangeTaggedToFloat64(),
216 t.machine()->Store(kMachineFloat64, kNoWriteBarrier), 216 t.machine()->Store(kMachFloat64, kNoWriteBarrier),
217 &result); 217 &result);
218 218
219 if (Pipeline::SupportedTarget()) { 219 if (Pipeline::SupportedTarget()) {
220 FOR_INT32_INPUTS(i) { 220 FOR_INT32_INPUTS(i) {
221 int32_t input = *i; 221 int32_t input = *i;
222 222
223 if (Smi::IsValid(input)) { 223 if (Smi::IsValid(input)) {
224 t.Call(Smi::FromInt(input)); 224 t.Call(Smi::FromInt(input));
225 CHECK_EQ(input, static_cast<int32_t>(result)); 225 CHECK_EQ(input, static_cast<int32_t>(result));
226 } 226 }
(...skipping 25 matching lines...) Expand all
252 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); 252 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
253 t.Call(*number); 253 t.Call(*number);
254 CHECK_EQ(input, result); 254 CHECK_EQ(input, result);
255 } 255 }
256 } 256 }
257 } 257 }
258 } 258 }
259 259
260 260
261 TEST(RunChangeBoolToBit) { 261 TEST(RunChangeBoolToBit) {
262 ChangesLoweringTester<int32_t> t(kMachineTagged); 262 ChangesLoweringTester<int32_t> t(kMachAnyTagged);
263 t.BuildAndLower(t.simplified()->ChangeBoolToBit()); 263 t.BuildAndLower(t.simplified()->ChangeBoolToBit());
264 264
265 if (Pipeline::SupportedTarget()) { 265 if (Pipeline::SupportedTarget()) {
266 Object* true_obj = t.heap()->true_value(); 266 Object* true_obj = t.heap()->true_value();
267 int32_t result = t.Call(true_obj); 267 int32_t result = t.Call(true_obj);
268 CHECK_EQ(1, result); 268 CHECK_EQ(1, result);
269 } 269 }
270 270
271 if (Pipeline::SupportedTarget()) { 271 if (Pipeline::SupportedTarget()) {
272 Object* false_obj = t.heap()->false_value(); 272 Object* false_obj = t.heap()->false_value();
273 int32_t result = t.Call(false_obj); 273 int32_t result = t.Call(false_obj);
274 CHECK_EQ(0, result); 274 CHECK_EQ(0, result);
275 } 275 }
276 } 276 }
277 277
278 278
279 TEST(RunChangeBitToBool) { 279 TEST(RunChangeBitToBool) {
280 ChangesLoweringTester<Object*> t(kMachineWord32); 280 ChangesLoweringTester<Object*> t(kMachInt32);
281 t.BuildAndLower(t.simplified()->ChangeBitToBool()); 281 t.BuildAndLower(t.simplified()->ChangeBitToBool());
282 282
283 if (Pipeline::SupportedTarget()) { 283 if (Pipeline::SupportedTarget()) {
284 Object* result = t.Call(1); 284 Object* result = t.Call(1);
285 Object* true_obj = t.heap()->true_value(); 285 Object* true_obj = t.heap()->true_value();
286 CHECK_EQ(true_obj, result); 286 CHECK_EQ(true_obj, result);
287 } 287 }
288 288
289 if (Pipeline::SupportedTarget()) { 289 if (Pipeline::SupportedTarget()) {
290 Object* result = t.Call(0); 290 Object* result = t.Call(0);
(...skipping 14 matching lines...) Expand all
305 // TODO(titzer): enable all UI32 -> Tagged checking when inline allocation 305 // TODO(titzer): enable all UI32 -> Tagged checking when inline allocation
306 // works. 306 // works.
307 return v <= static_cast<uint32_t>(Smi::kMaxValue); 307 return v <= static_cast<uint32_t>(Smi::kMaxValue);
308 } 308 }
309 309
310 310
311 TEST(RunChangeInt32ToTagged) { 311 TEST(RunChangeInt32ToTagged) {
312 ChangesLoweringTester<Object*> t; 312 ChangesLoweringTester<Object*> t;
313 int32_t input; 313 int32_t input;
314 t.BuildLoadAndLower(t.simplified()->ChangeInt32ToTagged(), 314 t.BuildLoadAndLower(t.simplified()->ChangeInt32ToTagged(),
315 t.machine()->Load(kMachineWord32), &input); 315 t.machine()->Load(kMachInt32), &input);
316 316
317 if (Pipeline::SupportedTarget()) { 317 if (Pipeline::SupportedTarget()) {
318 FOR_INT32_INPUTS(i) { 318 FOR_INT32_INPUTS(i) {
319 input = *i; 319 input = *i;
320 Object* result = t.CallWithPotentialGC<Object>(); 320 Object* result = t.CallWithPotentialGC<Object>();
321 if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) { 321 if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) {
322 t.CheckNumber(static_cast<double>(input), result); 322 t.CheckNumber(static_cast<double>(input), result);
323 } 323 }
324 } 324 }
325 } 325 }
326 326
327 if (Pipeline::SupportedTarget()) { 327 if (Pipeline::SupportedTarget()) {
328 FOR_INT32_INPUTS(i) { 328 FOR_INT32_INPUTS(i) {
329 input = *i; 329 input = *i;
330 SimulateFullSpace(CcTest::heap()->new_space()); 330 SimulateFullSpace(CcTest::heap()->new_space());
331 Object* result = t.CallWithPotentialGC<Object>(); 331 Object* result = t.CallWithPotentialGC<Object>();
332 if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) { 332 if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) {
333 t.CheckNumber(static_cast<double>(input), result); 333 t.CheckNumber(static_cast<double>(input), result);
334 } 334 }
335 } 335 }
336 } 336 }
337 } 337 }
338 338
339 339
340 TEST(RunChangeUint32ToTagged) { 340 TEST(RunChangeUint32ToTagged) {
341 ChangesLoweringTester<Object*> t; 341 ChangesLoweringTester<Object*> t;
342 uint32_t input; 342 uint32_t input;
343 t.BuildLoadAndLower(t.simplified()->ChangeUint32ToTagged(), 343 t.BuildLoadAndLower(t.simplified()->ChangeUint32ToTagged(),
344 t.machine()->Load(kMachineWord32), &input); 344 t.machine()->Load(kMachUint32), &input);
345 345
346 if (Pipeline::SupportedTarget()) { 346 if (Pipeline::SupportedTarget()) {
347 FOR_UINT32_INPUTS(i) { 347 FOR_UINT32_INPUTS(i) {
348 input = *i; 348 input = *i;
349 Object* result = t.CallWithPotentialGC<Object>(); 349 Object* result = t.CallWithPotentialGC<Object>();
350 double expected = static_cast<double>(input); 350 double expected = static_cast<double>(input);
351 if (TODO_UINT32_TO_TAGGED_WILL_WORK(input)) { 351 if (TODO_UINT32_TO_TAGGED_WILL_WORK(input)) {
352 t.CheckNumber(expected, result); 352 t.CheckNumber(expected, result);
353 } 353 }
354 } 354 }
(...skipping 13 matching lines...) Expand all
368 } 368 }
369 369
370 370
371 // TODO(titzer): lowering of Float64->Tagged needs inline allocation. 371 // TODO(titzer): lowering of Float64->Tagged needs inline allocation.
372 #define TODO_FLOAT64_TO_TAGGED false 372 #define TODO_FLOAT64_TO_TAGGED false
373 373
374 TEST(RunChangeFloat64ToTagged) { 374 TEST(RunChangeFloat64ToTagged) {
375 ChangesLoweringTester<Object*> t; 375 ChangesLoweringTester<Object*> t;
376 double input; 376 double input;
377 t.BuildLoadAndLower(t.simplified()->ChangeFloat64ToTagged(), 377 t.BuildLoadAndLower(t.simplified()->ChangeFloat64ToTagged(),
378 t.machine()->Load(kMachineFloat64), &input); 378 t.machine()->Load(kMachFloat64), &input);
379 379
380 // TODO(titzer): need inline allocation to change float to tagged. 380 // TODO(titzer): need inline allocation to change float to tagged.
381 if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) { 381 if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) {
382 FOR_FLOAT64_INPUTS(i) { 382 FOR_FLOAT64_INPUTS(i) {
383 input = *i; 383 input = *i;
384 Object* result = t.CallWithPotentialGC<Object>(); 384 Object* result = t.CallWithPotentialGC<Object>();
385 t.CheckNumber(input, result); 385 t.CheckNumber(input, result);
386 } 386 }
387 } 387 }
388 388
389 if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) { 389 if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) {
390 FOR_FLOAT64_INPUTS(i) { 390 FOR_FLOAT64_INPUTS(i) {
391 input = *i; 391 input = *i;
392 SimulateFullSpace(CcTest::heap()->new_space()); 392 SimulateFullSpace(CcTest::heap()->new_space());
393 Object* result = t.CallWithPotentialGC<Object>(); 393 Object* result = t.CallWithPotentialGC<Object>();
394 t.CheckNumber(input, result); 394 t.CheckNumber(input, result);
395 } 395 }
396 } 396 }
397 } 397 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-branch-combine.cc ('k') | test/cctest/compiler/test-codegen-deopt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698