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

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

Issue 515433003: Remove old changes lowering code and convert test to use new changes lowering code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | « src/compiler/simplified-lowering.cc ('k') | no next file » | 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/change-lowering.h"
7 #include "src/compiler/control-builders.h" 8 #include "src/compiler/control-builders.h"
8 #include "src/compiler/generic-node-inl.h" 9 #include "src/compiler/generic-node-inl.h"
10 #include "src/compiler/js-graph.h"
9 #include "src/compiler/node-properties-inl.h" 11 #include "src/compiler/node-properties-inl.h"
10 #include "src/compiler/pipeline.h" 12 #include "src/compiler/pipeline.h"
11 #include "src/compiler/simplified-lowering.h"
12 #include "src/compiler/simplified-node-factory.h" 13 #include "src/compiler/simplified-node-factory.h"
13 #include "src/compiler/typer.h" 14 #include "src/compiler/typer.h"
14 #include "src/compiler/verifier.h" 15 #include "src/compiler/verifier.h"
15 #include "src/execution.h" 16 #include "src/execution.h"
16 #include "src/parser.h" 17 #include "src/parser.h"
17 #include "src/rewriter.h" 18 #include "src/rewriter.h"
18 #include "src/scopes.h" 19 #include "src/scopes.h"
19 #include "test/cctest/cctest.h" 20 #include "test/cctest/cctest.h"
20 #include "test/cctest/compiler/codegen-tester.h" 21 #include "test/cctest/compiler/codegen-tester.h"
21 #include "test/cctest/compiler/graph-builder-tester.h" 22 #include "test/cctest/compiler/graph-builder-tester.h"
22 #include "test/cctest/compiler/value-helper.h" 23 #include "test/cctest/compiler/value-helper.h"
23 24
24 using namespace v8::internal; 25 using namespace v8::internal;
25 using namespace v8::internal::compiler; 26 using namespace v8::internal::compiler;
26 27
27 template <typename ReturnType> 28 template <typename ReturnType>
28 class ChangesLoweringTester : public GraphBuilderTester<ReturnType> { 29 class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
29 public: 30 public:
30 explicit ChangesLoweringTester(MachineType p0 = kMachNone) 31 explicit ChangesLoweringTester(MachineType p0 = kMachNone)
31 : GraphBuilderTester<ReturnType>(p0), 32 : GraphBuilderTester<ReturnType>(p0),
32 typer(this->zone()), 33 typer(this->zone()),
33 jsgraph(this->graph(), this->common(), &typer), 34 jsgraph(this->graph(), this->common(), &typer),
34 lowering(&jsgraph),
35 function(Handle<JSFunction>::null()) {} 35 function(Handle<JSFunction>::null()) {}
36 36
37 Typer typer; 37 Typer typer;
38 JSGraph jsgraph; 38 JSGraph jsgraph;
39 SimplifiedLowering lowering;
40 Handle<JSFunction> function; 39 Handle<JSFunction> function;
41 40
42 Node* start() { return this->graph()->start(); } 41 Node* start() { return this->graph()->start(); }
43 42
44 template <typename T> 43 template <typename T>
45 T* CallWithPotentialGC() { 44 T* CallWithPotentialGC() {
46 // TODO(titzer): we need to wrap the code in a JSFunction and call it via 45 // TODO(titzer): we need to wrap the code in a JSFunction and call it via
47 // Execution::Call() so that the GC knows about the frame, can walk it, 46 // Execution::Call() so that the GC knows about the frame, can walk it,
48 // relocate the code object if necessary, etc. 47 // relocate the code object if necessary, etc.
49 // This is pretty ugly and at the least should be moved up to helpers. 48 // This is pretty ugly and at the least should be moved up to helpers.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 101
103 void BuildAndLower(Operator* op) { 102 void BuildAndLower(Operator* op) {
104 // 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
105 // does not add the correct control and effect nodes. 104 // does not add the correct control and effect nodes.
106 Node* p0 = this->Parameter(0); 105 Node* p0 = this->Parameter(0);
107 Node* change = this->graph()->NewNode(op, p0); 106 Node* change = this->graph()->NewNode(op, p0);
108 Node* ret = this->graph()->NewNode(this->common()->Return(), change, 107 Node* ret = this->graph()->NewNode(this->common()->Return(), change,
109 this->start(), this->start()); 108 this->start(), this->start());
110 Node* end = this->graph()->NewNode(this->common()->End(), ret); 109 Node* end = this->graph()->NewNode(this->common()->End(), ret);
111 this->graph()->SetEnd(end); 110 this->graph()->SetEnd(end);
112 this->lowering.LowerChange(change, this->start(), this->start()); 111 LowerChange(change);
113 Verifier::Run(this->graph());
114 } 112 }
115 113
116 void BuildStoreAndLower(Operator* op, Operator* store_op, void* location) { 114 void BuildStoreAndLower(Operator* op, Operator* store_op, void* location) {
117 // We build a graph by hand here, because the raw machine assembler 115 // We build a graph by hand here, because the raw machine assembler
118 // does not add the correct control and effect nodes. 116 // does not add the correct control and effect nodes.
119 Node* p0 = this->Parameter(0); 117 Node* p0 = this->Parameter(0);
120 Node* change = this->graph()->NewNode(op, p0); 118 Node* change = this->graph()->NewNode(op, p0);
121 Node* store = this->graph()->NewNode( 119 Node* store = this->graph()->NewNode(
122 store_op, this->PointerConstant(location), this->Int32Constant(0), 120 store_op, this->PointerConstant(location), this->Int32Constant(0),
123 change, this->start(), this->start()); 121 change, this->start(), this->start());
124 Node* ret = this->graph()->NewNode( 122 Node* ret = this->graph()->NewNode(
125 this->common()->Return(), this->Int32Constant(0), store, this->start()); 123 this->common()->Return(), this->Int32Constant(0), store, this->start());
126 Node* end = this->graph()->NewNode(this->common()->End(), ret); 124 Node* end = this->graph()->NewNode(this->common()->End(), ret);
127 this->graph()->SetEnd(end); 125 this->graph()->SetEnd(end);
128 this->lowering.LowerChange(change, this->start(), this->start()); 126 LowerChange(change);
129 Verifier::Run(this->graph());
130 } 127 }
131 128
132 void BuildLoadAndLower(Operator* op, Operator* load_op, void* location) { 129 void BuildLoadAndLower(Operator* op, Operator* load_op, void* location) {
133 // We build a graph by hand here, because the raw machine assembler 130 // We build a graph by hand here, because the raw machine assembler
134 // does not add the correct control and effect nodes. 131 // does not add the correct control and effect nodes.
135 Node* load = 132 Node* load =
136 this->graph()->NewNode(load_op, this->PointerConstant(location), 133 this->graph()->NewNode(load_op, this->PointerConstant(location),
137 this->Int32Constant(0), this->start()); 134 this->Int32Constant(0), this->start());
138 Node* change = this->graph()->NewNode(op, load); 135 Node* change = this->graph()->NewNode(op, load);
139 Node* ret = this->graph()->NewNode(this->common()->Return(), change, 136 Node* ret = this->graph()->NewNode(this->common()->Return(), change,
140 this->start(), this->start()); 137 this->start(), this->start());
141 Node* end = this->graph()->NewNode(this->common()->End(), ret); 138 Node* end = this->graph()->NewNode(this->common()->End(), ret);
142 this->graph()->SetEnd(end); 139 this->graph()->SetEnd(end);
143 this->lowering.LowerChange(change, this->start(), this->start()); 140 LowerChange(change);
141 }
142
143 void LowerChange(Node* change) {
144 // Run the graph reducer with changes lowering on a single node.
145 CompilationInfo info(this->isolate(), this->zone());
146 Linkage linkage(&info);
147 ChangeLowering lowering(&jsgraph, &linkage, this->machine());
148 GraphReducer reducer(this->graph());
149 reducer.AddReducer(&lowering);
150 reducer.ReduceNode(change);
144 Verifier::Run(this->graph()); 151 Verifier::Run(this->graph());
145 } 152 }
146 153
147 Factory* factory() { return this->isolate()->factory(); } 154 Factory* factory() { return this->isolate()->factory(); }
148 Heap* heap() { return this->isolate()->heap(); } 155 Heap* heap() { return this->isolate()->heap(); }
149 }; 156 };
150 157
151 158
152 TEST(RunChangeTaggedToInt32) { 159 TEST(RunChangeTaggedToInt32) {
153 // Build and lower a graph by hand. 160 // Build and lower a graph by hand.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 295 }
289 296
290 if (Pipeline::SupportedTarget()) { 297 if (Pipeline::SupportedTarget()) {
291 Object* result = t.Call(0); 298 Object* result = t.Call(0);
292 Object* false_obj = t.heap()->false_value(); 299 Object* false_obj = t.heap()->false_value();
293 CHECK_EQ(false_obj, result); 300 CHECK_EQ(false_obj, result);
294 } 301 }
295 } 302 }
296 303
297 304
298 bool TODO_INT32_TO_TAGGED_WILL_WORK(int32_t v) {
299 // TODO(titzer): enable all UI32 -> Tagged checking when inline allocation
300 // works.
301 return Smi::IsValid(v);
302 }
303
304
305 bool TODO_UINT32_TO_TAGGED_WILL_WORK(uint32_t v) {
306 // TODO(titzer): enable all UI32 -> Tagged checking when inline allocation
307 // works.
308 return v <= static_cast<uint32_t>(Smi::kMaxValue);
309 }
310
311
312 TEST(RunChangeInt32ToTagged) { 305 TEST(RunChangeInt32ToTagged) {
313 ChangesLoweringTester<Object*> t; 306 ChangesLoweringTester<Object*> t;
314 int32_t input; 307 int32_t input;
315 t.BuildLoadAndLower(t.simplified()->ChangeInt32ToTagged(), 308 t.BuildLoadAndLower(t.simplified()->ChangeInt32ToTagged(),
316 t.machine()->Load(kMachInt32), &input); 309 t.machine()->Load(kMachInt32), &input);
317 310
318 if (Pipeline::SupportedTarget()) { 311 if (Pipeline::SupportedTarget()) {
319 FOR_INT32_INPUTS(i) { 312 FOR_INT32_INPUTS(i) {
320 input = *i; 313 input = *i;
321 Object* result = t.CallWithPotentialGC<Object>(); 314 Object* result = t.CallWithPotentialGC<Object>();
322 if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) { 315 t.CheckNumber(static_cast<double>(input), result);
323 t.CheckNumber(static_cast<double>(input), result);
324 }
325 } 316 }
326 } 317 }
327 318
328 if (Pipeline::SupportedTarget()) { 319 if (Pipeline::SupportedTarget()) {
329 FOR_INT32_INPUTS(i) { 320 FOR_INT32_INPUTS(i) {
330 input = *i; 321 input = *i;
331 SimulateFullSpace(CcTest::heap()->new_space()); 322 CcTest::heap()->DisableInlineAllocation();
332 Object* result = t.CallWithPotentialGC<Object>(); 323 Object* result = t.CallWithPotentialGC<Object>();
333 if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) { 324 t.CheckNumber(static_cast<double>(input), result);
334 t.CheckNumber(static_cast<double>(input), result);
335 }
336 } 325 }
337 } 326 }
338 } 327 }
339 328
340 329
341 TEST(RunChangeUint32ToTagged) { 330 TEST(RunChangeUint32ToTagged) {
342 ChangesLoweringTester<Object*> t; 331 ChangesLoweringTester<Object*> t;
343 uint32_t input; 332 uint32_t input;
344 t.BuildLoadAndLower(t.simplified()->ChangeUint32ToTagged(), 333 t.BuildLoadAndLower(t.simplified()->ChangeUint32ToTagged(),
345 t.machine()->Load(kMachUint32), &input); 334 t.machine()->Load(kMachUint32), &input);
346 335
347 if (Pipeline::SupportedTarget()) { 336 if (Pipeline::SupportedTarget()) {
348 FOR_UINT32_INPUTS(i) { 337 FOR_UINT32_INPUTS(i) {
349 input = *i; 338 input = *i;
350 Object* result = t.CallWithPotentialGC<Object>(); 339 Object* result = t.CallWithPotentialGC<Object>();
351 double expected = static_cast<double>(input); 340 double expected = static_cast<double>(input);
352 if (TODO_UINT32_TO_TAGGED_WILL_WORK(input)) { 341 t.CheckNumber(expected, result);
353 t.CheckNumber(expected, result);
354 }
355 } 342 }
356 } 343 }
357 344
358 if (Pipeline::SupportedTarget()) { 345 if (Pipeline::SupportedTarget()) {
359 FOR_UINT32_INPUTS(i) { 346 FOR_UINT32_INPUTS(i) {
360 input = *i; 347 input = *i;
361 SimulateFullSpace(CcTest::heap()->new_space()); 348 CcTest::heap()->DisableInlineAllocation();
362 Object* result = t.CallWithPotentialGC<Object>(); 349 Object* result = t.CallWithPotentialGC<Object>();
363 double expected = static_cast<double>(static_cast<uint32_t>(input)); 350 double expected = static_cast<double>(static_cast<uint32_t>(input));
364 if (TODO_UINT32_TO_TAGGED_WILL_WORK(input)) { 351 t.CheckNumber(expected, result);
365 t.CheckNumber(expected, result);
366 }
367 } 352 }
368 } 353 }
369 } 354 }
370 355
371 356
372 // TODO(titzer): lowering of Float64->Tagged needs inline allocation.
373 #define TODO_FLOAT64_TO_TAGGED false
374
375 TEST(RunChangeFloat64ToTagged) { 357 TEST(RunChangeFloat64ToTagged) {
376 ChangesLoweringTester<Object*> t; 358 ChangesLoweringTester<Object*> t;
377 double input; 359 double input;
378 t.BuildLoadAndLower(t.simplified()->ChangeFloat64ToTagged(), 360 t.BuildLoadAndLower(t.simplified()->ChangeFloat64ToTagged(),
379 t.machine()->Load(kMachFloat64), &input); 361 t.machine()->Load(kMachFloat64), &input);
380 362
381 // TODO(titzer): need inline allocation to change float to tagged. 363 {
382 if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) {
383 FOR_FLOAT64_INPUTS(i) { 364 FOR_FLOAT64_INPUTS(i) {
384 input = *i; 365 input = *i;
385 Object* result = t.CallWithPotentialGC<Object>(); 366 Object* result = t.CallWithPotentialGC<Object>();
386 t.CheckNumber(input, result); 367 t.CheckNumber(input, result);
387 } 368 }
388 } 369 }
389 370
390 if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) { 371 {
391 FOR_FLOAT64_INPUTS(i) { 372 FOR_FLOAT64_INPUTS(i) {
392 input = *i; 373 input = *i;
393 SimulateFullSpace(CcTest::heap()->new_space()); 374 CcTest::heap()->DisableInlineAllocation();
394 Object* result = t.CallWithPotentialGC<Object>(); 375 Object* result = t.CallWithPotentialGC<Object>();
395 t.CheckNumber(input, result); 376 t.CheckNumber(input, result);
396 } 377 }
397 } 378 }
398 } 379 }
OLDNEW
« no previous file with comments | « src/compiler/simplified-lowering.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698