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

Side by Side Diff: test/unittests/compiler/graph-unittest.h

Issue 816053002: [turbofan] First version of loop peeling. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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 | « src/flag-definitions.h ('k') | test/unittests/compiler/loop-peeling-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
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 #ifndef V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ 5 #ifndef V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
6 #define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ 6 #define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
7 7
8 #include "src/compiler/common-operator.h" 8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/graph.h" 9 #include "src/compiler/graph.h"
10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/node.h"
10 #include "src/compiler/typer.h" 12 #include "src/compiler/typer.h"
11 #include "test/unittests/test-utils.h" 13 #include "test/unittests/test-utils.h"
12 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
13 15
14 namespace v8 { 16 namespace v8 {
15 namespace internal { 17 namespace internal {
16 18
17 // Forward declarations. 19 // Forward declarations.
18 template <class T> 20 template <class T>
19 class Handle; 21 class Handle;
20 class HeapObject; 22 class HeapObject;
21 template <class T> 23 template <class T>
22 class Unique; 24 class Unique;
23 25
24 namespace compiler { 26 namespace compiler {
25 27
26 using ::testing::Matcher; 28 using ::testing::Matcher;
27 29
28 30
29 class GraphTest : public TestWithContext, public TestWithZone { 31 class GraphTest : public TestWithContext, public TestWithZone {
30 public: 32 public:
31 explicit GraphTest(int num_parameters = 1); 33 explicit GraphTest(int num_parameters = 1);
32 ~GraphTest() OVERRIDE; 34 ~GraphTest() OVERRIDE;
33 35
34 protected:
35 Node* Parameter(int32_t index = 0); 36 Node* Parameter(int32_t index = 0);
36 Node* Float32Constant(volatile float value); 37 Node* Float32Constant(volatile float value);
37 Node* Float64Constant(volatile double value); 38 Node* Float64Constant(volatile double value);
38 Node* Int32Constant(int32_t value); 39 Node* Int32Constant(int32_t value);
39 Node* Uint32Constant(uint32_t value) { 40 Node* Uint32Constant(uint32_t value) {
40 return Int32Constant(bit_cast<int32_t>(value)); 41 return Int32Constant(bit_cast<int32_t>(value));
41 } 42 }
42 Node* Int64Constant(int64_t value); 43 Node* Int64Constant(int64_t value);
43 Node* NumberConstant(volatile double value); 44 Node* NumberConstant(volatile double value);
44 Node* HeapConstant(const Handle<HeapObject>& value); 45 Node* HeapConstant(const Handle<HeapObject>& value);
45 Node* HeapConstant(const Unique<HeapObject>& value); 46 Node* HeapConstant(const Unique<HeapObject>& value);
46 Node* FalseConstant(); 47 Node* FalseConstant();
47 Node* TrueConstant(); 48 Node* TrueConstant();
48 Node* UndefinedConstant(); 49 Node* UndefinedConstant();
49 50
50 Matcher<Node*> IsFalseConstant(); 51 Matcher<Node*> IsFalseConstant();
51 Matcher<Node*> IsTrueConstant(); 52 Matcher<Node*> IsTrueConstant();
52 53
54 Node* start() { return graph()->start(); }
53 CommonOperatorBuilder* common() { return &common_; } 55 CommonOperatorBuilder* common() { return &common_; }
54 Graph* graph() { return &graph_; } 56 Graph* graph() { return &graph_; }
55 57
56 private: 58 private:
57 CommonOperatorBuilder common_; 59 CommonOperatorBuilder common_;
58 Graph graph_; 60 Graph graph_;
59 }; 61 };
60 62
61 63
62 class TypedGraphTest : public GraphTest { 64 class TypedGraphTest : public GraphTest {
63 public: 65 public:
64 explicit TypedGraphTest(int num_parameters = 1); 66 explicit TypedGraphTest(int num_parameters = 1);
65 ~TypedGraphTest() OVERRIDE; 67 ~TypedGraphTest() OVERRIDE;
66 68
67 protected:
68 Node* Parameter(int32_t index = 0) { return GraphTest::Parameter(index); } 69 Node* Parameter(int32_t index = 0) { return GraphTest::Parameter(index); }
69 Node* Parameter(Type* type, int32_t index = 0); 70 Node* Parameter(Type* type, int32_t index = 0);
70 71
71 Typer* typer() { return &typer_; } 72 Typer* typer() { return &typer_; }
72 73
73 private: 74 private:
74 Typer typer_; 75 Typer typer_;
75 }; 76 };
76 77
78
Benedikt Meurer 2015/01/15 13:16:16 Move these helpers to loop-peeling-unittest.cc. Al
titzer 2015/01/15 13:36:51 The plan is to use them in other tests, so maybe a
Benedikt Meurer 2015/01/15 13:43:09 Well this kind of goes against the purpose of Grap
titzer 2015/01/16 16:15:37 PTAL, I've made these utilities into standalone st
Benedikt Meurer 2015/01/16 17:55:36 Thanks. Now you can undo the changes to graph-unit
titzer 2015/01/19 09:47:11 Done.
79 // A helper for building while loops.
80 struct While {
Benedikt Meurer 2015/01/15 13:16:16 According to the style guide "structs should be us
titzer 2015/01/15 13:36:51 I'd prefer to keep these as structs to avoid acces
Benedikt Meurer 2015/01/15 13:43:09 Personally I don't like these helper structs at al
81 GraphTest* t;
82 Node* branch;
83 Node* if_true;
84 Node* exit;
85 Node* loop;
86
87 While(GraphTest* R, Node* cond, Node* control = nullptr) : t(R) {
88 if (control == nullptr) control = R->start();
89 loop = t->graph()->NewNode(t->common()->Loop(2), control, control);
90 branch = t->graph()->NewNode(t->common()->Branch(), cond, loop);
91 if_true = t->graph()->NewNode(t->common()->IfTrue(), branch);
92 exit = t->graph()->NewNode(t->common()->IfFalse(), branch);
93 loop->ReplaceInput(1, if_true);
94 }
95
96 void Chain(Node* control) { loop->ReplaceInput(0, control); }
97 void Nest(While* that) {
98 that->loop->ReplaceInput(1, exit);
99 this->loop->ReplaceInput(0, that->if_true);
100 }
101 Node* Phi(Node* a, Node* b) {
102 return t->graph()->NewNode(t->common()->Phi(kMachAnyTagged, 2), a, b, loop);
103 }
104 };
105
106
107 // A helper for building branches.
108 struct Branch {
Benedikt Meurer 2015/01/15 13:16:16 See above.
109 Node* branch;
110 Node* if_true;
111 Node* if_false;
112
113 Branch(GraphTest* R, Node* cond, Node* control = nullptr) {
114 if (control == nullptr) control = R->start();
115 branch = R->graph()->NewNode(R->common()->Branch(), cond, control);
116 if_true = R->graph()->NewNode(R->common()->IfTrue(), branch);
117 if_false = R->graph()->NewNode(R->common()->IfFalse(), branch);
118 }
119 };
120
121
122 // A helper for building counters attached to loops.
123 struct Counter {
Benedikt Meurer 2015/01/15 13:16:16 See above.
124 Node* base;
125 Node* inc;
126 Node* phi;
127 Node* add;
128
129 Counter(While& w, MachineOperatorBuilder* machine, int32_t b, int32_t k)
Benedikt Meurer 2015/01/15 13:16:16 According to the google style guide: All parameter
titzer 2015/01/15 13:36:51 Done.
130 : base(w.t->Int32Constant(b)), inc(w.t->Int32Constant(k)) {
131 Build(w, machine);
132 }
133
134 Counter(While& w, MachineOperatorBuilder* machine, Node* b, Node* k)
Benedikt Meurer 2015/01/15 13:16:16 According to the google style guide: All parameter
titzer 2015/01/15 13:36:51 Done.
135 : base(b), inc(k) {
136 Build(w, machine);
137 }
138
139 void Build(While& w, MachineOperatorBuilder* machine) {
Benedikt Meurer 2015/01/15 13:16:16 According to the google style guide: All parameter
titzer 2015/01/15 13:36:51 Done.
140 phi = w.t->graph()->NewNode(w.t->common()->Phi(kMachAnyTagged, 2), base,
141 base, w.loop);
142 add = w.t->graph()->NewNode(machine->Int32Add(), phi, inc);
143 phi->ReplaceInput(1, add);
144 }
145 };
146
147
77 } // namespace compiler 148 } // namespace compiler
78 } // namespace internal 149 } // namespace internal
79 } // namespace v8 150 } // namespace v8
80 151
81 #endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ 152 #endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | test/unittests/compiler/loop-peeling-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698