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

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

Issue 480863002: Refactor ChangeLowering class to avoid template specialization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix 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/compiler-unittests/DEPS ('k') | test/compiler-unittests/common-operator-unittest.h » ('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 "src/compiler/change-lowering.h" 5 #include "src/compiler/change-lowering.h"
6 #include "src/compiler/common-operator.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/graph.h"
8 #include "src/compiler/node-properties-inl.h" 7 #include "src/compiler/node-properties-inl.h"
9 #include "src/compiler/simplified-operator.h" 8 #include "src/compiler/simplified-operator.h"
10 #include "src/factory.h" 9 #include "src/compiler/typer.h"
11 #include "test/compiler-unittests/compiler-unittests.h" 10 #include "test/compiler-unittests/graph-unittest.h"
12 #include "test/compiler-unittests/node-matchers.h" 11 #include "testing/gmock-support.h"
13 12
14 using testing::_; 13 using testing::_;
14 using testing::AllOf;
15 using testing::Capture;
16 using testing::CaptureEq;
15 17
16 namespace v8 { 18 namespace v8 {
17 namespace internal { 19 namespace internal {
18 namespace compiler { 20 namespace compiler {
19 21
20 template <typename T> 22 template <typename T>
21 class ChangeLoweringTest : public CompilerTest { 23 class ChangeLoweringTest : public GraphTest {
22 public: 24 public:
23 static const size_t kPointerSize = sizeof(T); 25 static const size_t kPointerSize = sizeof(T);
26 static const MachineType kWordRepresentation =
27 (kPointerSize == 4) ? kRepWord32 : kRepWord64;
28 STATIC_ASSERT(HeapNumber::kValueOffset % kApiPointerSize == 0);
29 static const int kHeapNumberValueOffset = static_cast<int>(
30 (HeapNumber::kValueOffset / kApiPointerSize) * kPointerSize);
24 31
25 explicit ChangeLoweringTest(int num_parameters = 1) 32 ChangeLoweringTest() : simplified_(zone()) {}
26 : graph_(zone()), common_(zone()), simplified_(zone()) {
27 graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
28 }
29 virtual ~ChangeLoweringTest() {} 33 virtual ~ChangeLoweringTest() {}
30 34
31 protected: 35 protected:
32 Node* Parameter(int32_t index = 0) { 36 Node* Parameter(int32_t index = 0) {
33 return graph()->NewNode(common()->Parameter(index), graph()->start()); 37 return graph()->NewNode(common()->Parameter(index), graph()->start());
34 } 38 }
35 39
36 Reduction Reduce(Node* node) { 40 Reduction Reduce(Node* node) {
41 Typer typer(zone());
42 JSGraph jsgraph(graph(), common(), &typer);
37 CompilationInfo info(isolate(), zone()); 43 CompilationInfo info(isolate(), zone());
38 Linkage linkage(&info); 44 Linkage linkage(&info);
39 ChangeLowering<kPointerSize> reducer(graph(), &linkage); 45 MachineOperatorBuilder machine(zone(), kWordRepresentation);
46 ChangeLowering reducer(&jsgraph, &linkage, &machine);
40 return reducer.Reduce(node); 47 return reducer.Reduce(node);
41 } 48 }
42 49
43 Graph* graph() { return &graph_; }
44 Factory* factory() const { return isolate()->factory(); }
45 CommonOperatorBuilder* common() { return &common_; }
46 SimplifiedOperatorBuilder* simplified() { return &simplified_; } 50 SimplifiedOperatorBuilder* simplified() { return &simplified_; }
47 51
48 PrintableUnique<HeapObject> true_unique() { 52 PrintableUnique<HeapObject> true_unique() {
49 return PrintableUnique<HeapObject>::CreateImmovable( 53 return PrintableUnique<HeapObject>::CreateImmovable(
50 zone(), factory()->true_value()); 54 zone(), factory()->true_value());
51 } 55 }
52 PrintableUnique<HeapObject> false_unique() { 56 PrintableUnique<HeapObject> false_unique() {
53 return PrintableUnique<HeapObject>::CreateImmovable( 57 return PrintableUnique<HeapObject>::CreateImmovable(
54 zone(), factory()->false_value()); 58 zone(), factory()->false_value());
55 } 59 }
56 60
57 private: 61 private:
58 Graph graph_;
59 CommonOperatorBuilder common_;
60 SimplifiedOperatorBuilder simplified_; 62 SimplifiedOperatorBuilder simplified_;
61 }; 63 };
62 64
63 65
64 typedef ::testing::Types<int32_t, int64_t> ChangeLoweringTypes; 66 typedef ::testing::Types<int32_t, int64_t> ChangeLoweringTypes;
65 TYPED_TEST_CASE(ChangeLoweringTest, ChangeLoweringTypes); 67 TYPED_TEST_CASE(ChangeLoweringTest, ChangeLoweringTypes);
66 68
67 69
68 TARGET_TYPED_TEST(ChangeLoweringTest, ChangeBitToBool) { 70 TARGET_TYPED_TEST(ChangeLoweringTest, ChangeBitToBool) {
69 Node* val = this->Parameter(0); 71 Node* val = this->Parameter(0);
70 Node* node = 72 Node* node =
71 this->graph()->NewNode(this->simplified()->ChangeBitToBool(), val); 73 this->graph()->NewNode(this->simplified()->ChangeBitToBool(), val);
72 Reduction reduction = this->Reduce(node); 74 Reduction reduction = this->Reduce(node);
73 ASSERT_TRUE(reduction.Changed()); 75 ASSERT_TRUE(reduction.Changed());
74 76
75 Node* phi = reduction.replacement(); 77 Node* phi = reduction.replacement();
76 EXPECT_THAT(phi, IsPhi(IsHeapConstant(this->true_unique()), 78 Capture<Node*> branch;
77 IsHeapConstant(this->false_unique()), _)); 79 EXPECT_THAT(
78 80 phi, IsPhi(IsHeapConstant(this->true_unique()),
79 Node* merge = NodeProperties::GetControlInput(phi); 81 IsHeapConstant(this->false_unique()),
80 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); 82 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch),
81 83 IsBranch(val, this->graph()->start()))),
82 Node* if_true = NodeProperties::GetControlInput(merge, 0); 84 IsIfFalse(CaptureEq(&branch)))));
83 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode());
84
85 Node* if_false = NodeProperties::GetControlInput(merge, 1);
86 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode());
87
88 Node* branch = NodeProperties::GetControlInput(if_true);
89 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false));
90 EXPECT_THAT(branch, IsBranch(val, this->graph()->start()));
91 } 85 }
92 86
93 87
94 TARGET_TYPED_TEST(ChangeLoweringTest, StringAdd) { 88 TARGET_TYPED_TEST(ChangeLoweringTest, StringAdd) {
95 Node* node = this->graph()->NewNode(this->simplified()->StringAdd(), 89 Node* node = this->graph()->NewNode(this->simplified()->StringAdd(),
96 this->Parameter(0), this->Parameter(1)); 90 this->Parameter(0), this->Parameter(1));
97 Reduction reduction = this->Reduce(node); 91 Reduction reduction = this->Reduce(node);
98 EXPECT_FALSE(reduction.Changed()); 92 EXPECT_FALSE(reduction.Changed());
99 } 93 }
100 94
(...skipping 26 matching lines...) Expand all
127 121
128 Node* smi = NodeProperties::GetValueInput(phi, 1); 122 Node* smi = NodeProperties::GetValueInput(phi, 1);
129 ASSERT_THAT(smi, IsProjection(0, IsInt32AddWithOverflow(val, val))); 123 ASSERT_THAT(smi, IsProjection(0, IsInt32AddWithOverflow(val, val)));
130 124
131 Node* heap_number = NodeProperties::GetValueInput(phi, 0); 125 Node* heap_number = NodeProperties::GetValueInput(phi, 0);
132 ASSERT_EQ(IrOpcode::kCall, heap_number->opcode()); 126 ASSERT_EQ(IrOpcode::kCall, heap_number->opcode());
133 127
134 Node* merge = NodeProperties::GetControlInput(phi); 128 Node* merge = NodeProperties::GetControlInput(phi);
135 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); 129 ASSERT_EQ(IrOpcode::kMerge, merge->opcode());
136 130
137 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; 131 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag;
138 EXPECT_THAT(NodeProperties::GetControlInput(merge, 0), 132 EXPECT_THAT(NodeProperties::GetControlInput(merge, 0),
139 IsStore(kMachFloat64, kNoWriteBarrier, heap_number, 133 IsStore(kMachFloat64, kNoWriteBarrier, heap_number,
140 IsInt32Constant(kValueOffset), 134 IsInt32Constant(kValueOffset),
141 IsChangeInt32ToFloat64(val), _, heap_number)); 135 IsChangeInt32ToFloat64(val), _, heap_number));
142 136
143 Node* if_true = NodeProperties::GetControlInput(heap_number); 137 Node* if_true = NodeProperties::GetControlInput(heap_number);
144 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode()); 138 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode());
145 139
146 Node* if_false = NodeProperties::GetControlInput(merge, 1); 140 Node* if_false = NodeProperties::GetControlInput(merge, 1);
147 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode()); 141 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode());
148 142
149 Node* branch = NodeProperties::GetControlInput(if_true); 143 Node* branch = NodeProperties::GetControlInput(if_true);
150 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); 144 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false));
151 EXPECT_THAT(branch, 145 EXPECT_THAT(branch,
152 IsBranch(IsProjection(1, IsInt32AddWithOverflow(val, val)), 146 IsBranch(IsProjection(1, IsInt32AddWithOverflow(val, val)),
153 graph()->start())); 147 graph()->start()));
154 } 148 }
155 149
156 150
157 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { 151 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) {
152 STATIC_ASSERT(kSmiTag == 0);
153 STATIC_ASSERT(kSmiTagSize == 1);
154
158 Node* val = Parameter(0); 155 Node* val = Parameter(0);
159 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); 156 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val);
160 Reduction reduction = Reduce(node); 157 Reduction reduction = Reduce(node);
161 ASSERT_TRUE(reduction.Changed()); 158 ASSERT_TRUE(reduction.Changed());
162 159
163 const int32_t kShiftAmount = 160 const int32_t kShiftAmount =
164 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; 161 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize;
165 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; 162 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag;
166 Node* phi = reduction.replacement(); 163 Node* phi = reduction.replacement();
167 ASSERT_THAT(phi, 164 Capture<Node*> branch;
168 IsPhi(IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), _), 165 EXPECT_THAT(
169 IsChangeInt32ToFloat64( 166 phi,
170 IsWord32Sar(val, IsInt32Constant(kShiftAmount))), 167 IsPhi(IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), _),
171 _)); 168 IsChangeInt32ToFloat64(
172 169 IsWord32Sar(val, IsInt32Constant(kShiftAmount))),
173 Node* merge = NodeProperties::GetControlInput(phi); 170 IsMerge(IsIfTrue(AllOf(
174 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); 171 CaptureEq(&branch),
175 172 IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)),
176 Node* if_true = NodeProperties::GetControlInput(merge, 0); 173 graph()->start()))),
177 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode()); 174 IsIfFalse(CaptureEq(&branch)))));
178
179 Node* if_false = NodeProperties::GetControlInput(merge, 1);
180 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode());
181
182 Node* branch = NodeProperties::GetControlInput(if_true);
183 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false));
184 STATIC_ASSERT(kSmiTag == 0);
185 STATIC_ASSERT(kSmiTagSize == 1);
186 EXPECT_THAT(branch, IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)),
187 graph()->start()));
188 } 175 }
189 176
190 177
191 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> { 178 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> {
192 public: 179 public:
193 virtual ~ChangeLowering64Test() {} 180 virtual ~ChangeLowering64Test() {}
194 }; 181 };
195 182
196 183
197 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) { 184 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) {
(...skipping 14 matching lines...) Expand all
212 ASSERT_TRUE(reduction.Changed()); 199 ASSERT_TRUE(reduction.Changed());
213 200
214 const int32_t kShiftAmount = 201 const int32_t kShiftAmount =
215 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; 202 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize;
216 EXPECT_THAT(reduction.replacement(), 203 EXPECT_THAT(reduction.replacement(),
217 IsWord64Shl(val, IsInt32Constant(kShiftAmount))); 204 IsWord64Shl(val, IsInt32Constant(kShiftAmount)));
218 } 205 }
219 206
220 207
221 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { 208 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) {
209 STATIC_ASSERT(kSmiTag == 0);
210 STATIC_ASSERT(kSmiTagSize == 1);
211
222 Node* val = Parameter(0); 212 Node* val = Parameter(0);
223 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); 213 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val);
224 Reduction reduction = Reduce(node); 214 Reduction reduction = Reduce(node);
225 ASSERT_TRUE(reduction.Changed()); 215 ASSERT_TRUE(reduction.Changed());
226 216
227 const int32_t kShiftAmount = 217 const int32_t kShiftAmount =
228 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; 218 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize;
229 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; 219 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag;
230 Node* phi = reduction.replacement(); 220 Node* phi = reduction.replacement();
231 ASSERT_THAT(phi, 221 Capture<Node*> branch;
232 IsPhi(IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), _), 222 EXPECT_THAT(
233 IsChangeInt32ToFloat64(IsConvertInt64ToInt32( 223 phi,
234 IsWord64Sar(val, IsInt32Constant(kShiftAmount)))), 224 IsPhi(IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), _),
235 _)); 225 IsChangeInt32ToFloat64(IsConvertInt64ToInt32(
236 226 IsWord64Sar(val, IsInt32Constant(kShiftAmount)))),
237 Node* merge = NodeProperties::GetControlInput(phi); 227 IsMerge(IsIfTrue(AllOf(
238 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); 228 CaptureEq(&branch),
239 229 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)),
240 Node* if_true = NodeProperties::GetControlInput(merge, 0); 230 graph()->start()))),
241 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode()); 231 IsIfFalse(CaptureEq(&branch)))));
242
243 Node* if_false = NodeProperties::GetControlInput(merge, 1);
244 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode());
245
246 Node* branch = NodeProperties::GetControlInput(if_true);
247 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false));
248 STATIC_ASSERT(kSmiTag == 0);
249 STATIC_ASSERT(kSmiTagSize == 1);
250 EXPECT_THAT(branch, IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)),
251 graph()->start()));
252 } 232 }
253 233
254 } // namespace compiler 234 } // namespace compiler
255 } // namespace internal 235 } // namespace internal
256 } // namespace v8 236 } // namespace v8
OLDNEW
« no previous file with comments | « test/compiler-unittests/DEPS ('k') | test/compiler-unittests/common-operator-unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698