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

Side by Side Diff: test/unittests/compiler/machine-operator-unittest.cc

Issue 824243003: [turbofan] Fix missing MachineOperator unittest. (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/compiler/machine-operator.h ('k') | test/unittests/unittests.gyp » ('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/machine-operator.h" 5 #include "src/compiler/machine-operator.h"
6 #include "src/compiler/operator-properties-inl.h" 6 #include "src/compiler/opcodes.h"
7 #include "testing/gtest-support.h" 7 #include "src/compiler/operator.h"
8 #include "src/compiler/operator-properties.h"
9 #include "test/unittests/test-utils.h"
8 10
9 namespace v8 { 11 namespace v8 {
10 namespace internal { 12 namespace internal {
11 namespace compiler { 13 namespace compiler {
12 14
13 #if GTEST_HAS_COMBINE 15 #if GTEST_HAS_COMBINE
14 16
15 template <typename T> 17 template <typename T>
16 class MachineOperatorTestWithParam 18 class MachineOperatorTestWithParam
17 : public ::testing::TestWithParam< ::testing::tuple<MachineType, T> > { 19 : public TestWithZone,
20 public ::testing::WithParamInterface< ::testing::tuple<MachineType, T> > {
18 protected: 21 protected:
19 MachineType type() const { return ::testing::get<0>(B::GetParam()); } 22 MachineType type() const { return ::testing::get<0>(B::GetParam()); }
20 const T& GetParam() const { return ::testing::get<1>(B::GetParam()); } 23 const T& GetParam() const { return ::testing::get<1>(B::GetParam()); }
21 24
22 private: 25 private:
23 typedef ::testing::TestWithParam< ::testing::tuple<MachineType, T> > B; 26 typedef ::testing::WithParamInterface< ::testing::tuple<MachineType, T> > B;
24 }; 27 };
25 28
26 29
27 namespace { 30 namespace {
28 31
29 const MachineType kMachineReps[] = {kRepWord32, kRepWord64}; 32 const MachineType kMachineReps[] = {kRepWord32, kRepWord64};
30 33
31 34
32 const MachineType kMachineTypes[] = { 35 const MachineType kMachineTypes[] = {
33 kMachFloat32, kMachFloat64, kMachInt8, kMachUint8, kMachInt16, 36 kMachFloat32, kMachFloat64, kMachInt8, kMachUint8, kMachInt16,
34 kMachUint16, kMachInt32, kMachUint32, kMachInt64, kMachUint64, 37 kMachUint16, kMachInt32, kMachUint32, kMachInt64, kMachUint64,
35 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16, 38 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16,
36 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged}; 39 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged};
37 40
38 } // namespace 41 } // namespace
39 42
40 43
41 // ----------------------------------------------------------------------------- 44 // -----------------------------------------------------------------------------
42 // Load operator. 45 // Load operator.
43 46
44 47
45 typedef MachineOperatorTestWithParam<LoadRepresentation> 48 typedef MachineOperatorTestWithParam<LoadRepresentation>
46 MachineLoadOperatorTest; 49 MachineLoadOperatorTest;
47 50
48 51
49 TEST_P(MachineLoadOperatorTest, InstancesAreGloballyShared) { 52 TEST_P(MachineLoadOperatorTest, InstancesAreGloballyShared) {
50 MachineOperatorBuilder machine1(type()); 53 MachineOperatorBuilder machine1(zone(), type());
51 MachineOperatorBuilder machine2(type()); 54 MachineOperatorBuilder machine2(zone(), type());
52 EXPECT_EQ(machine1.Load(GetParam()), machine2.Load(GetParam())); 55 EXPECT_EQ(machine1.Load(GetParam()), machine2.Load(GetParam()));
53 } 56 }
54 57
55 58
56 TEST_P(MachineLoadOperatorTest, NumberOfInputsAndOutputs) { 59 TEST_P(MachineLoadOperatorTest, NumberOfInputsAndOutputs) {
57 MachineOperatorBuilder machine(type()); 60 MachineOperatorBuilder machine(zone(), type());
58 const Operator* op = machine.Load(GetParam()); 61 const Operator* op = machine.Load(GetParam());
59 62
60 EXPECT_EQ(2, op->ValueInputCount()); 63 EXPECT_EQ(2, op->ValueInputCount());
61 EXPECT_EQ(1, op->EffectInputCount()); 64 EXPECT_EQ(1, op->EffectInputCount());
62 EXPECT_EQ(1, op->ControlInputCount()); 65 EXPECT_EQ(1, op->ControlInputCount());
63 EXPECT_EQ(4, OperatorProperties::GetTotalInputCount(op)); 66 EXPECT_EQ(4, OperatorProperties::GetTotalInputCount(op));
64 67
65 EXPECT_EQ(1, op->ValueOutputCount()); 68 EXPECT_EQ(1, op->ValueOutputCount());
66 EXPECT_EQ(1, op->EffectOutputCount()); 69 EXPECT_EQ(1, op->EffectOutputCount());
67 EXPECT_EQ(0, op->ControlOutputCount()); 70 EXPECT_EQ(0, op->ControlOutputCount());
68 } 71 }
69 72
70 73
71 TEST_P(MachineLoadOperatorTest, OpcodeIsCorrect) { 74 TEST_P(MachineLoadOperatorTest, OpcodeIsCorrect) {
72 MachineOperatorBuilder machine(type()); 75 MachineOperatorBuilder machine(zone(), type());
73 EXPECT_EQ(IrOpcode::kLoad, machine.Load(GetParam())->opcode()); 76 EXPECT_EQ(IrOpcode::kLoad, machine.Load(GetParam())->opcode());
74 } 77 }
75 78
76 79
77 TEST_P(MachineLoadOperatorTest, ParameterIsCorrect) { 80 TEST_P(MachineLoadOperatorTest, ParameterIsCorrect) {
78 MachineOperatorBuilder machine(type()); 81 MachineOperatorBuilder machine(zone(), type());
79 EXPECT_EQ(GetParam(), 82 EXPECT_EQ(GetParam(),
80 OpParameter<LoadRepresentation>(machine.Load(GetParam()))); 83 OpParameter<LoadRepresentation>(machine.Load(GetParam())));
81 } 84 }
82 85
83 86
84 INSTANTIATE_TEST_CASE_P(MachineOperatorTest, MachineLoadOperatorTest, 87 INSTANTIATE_TEST_CASE_P(MachineOperatorTest, MachineLoadOperatorTest,
85 ::testing::Combine(::testing::ValuesIn(kMachineReps), 88 ::testing::Combine(::testing::ValuesIn(kMachineReps),
86 ::testing::ValuesIn(kMachineTypes))); 89 ::testing::ValuesIn(kMachineTypes)));
87 90
88 91
89 // ----------------------------------------------------------------------------- 92 // -----------------------------------------------------------------------------
90 // Store operator. 93 // Store operator.
91 94
92 95
93 class MachineStoreOperatorTest 96 class MachineStoreOperatorTest
94 : public MachineOperatorTestWithParam< 97 : public MachineOperatorTestWithParam<
95 ::testing::tuple<MachineType, WriteBarrierKind> > { 98 ::testing::tuple<MachineType, WriteBarrierKind> > {
96 protected: 99 protected:
97 StoreRepresentation GetParam() const { 100 StoreRepresentation GetParam() const {
98 return StoreRepresentation( 101 return StoreRepresentation(
99 ::testing::get<0>(MachineOperatorTestWithParam< 102 ::testing::get<0>(MachineOperatorTestWithParam<
100 ::testing::tuple<MachineType, WriteBarrierKind> >::GetParam()), 103 ::testing::tuple<MachineType, WriteBarrierKind> >::GetParam()),
101 ::testing::get<1>(MachineOperatorTestWithParam< 104 ::testing::get<1>(MachineOperatorTestWithParam<
102 ::testing::tuple<MachineType, WriteBarrierKind> >::GetParam())); 105 ::testing::tuple<MachineType, WriteBarrierKind> >::GetParam()));
103 } 106 }
104 }; 107 };
105 108
106 109
107 TEST_P(MachineStoreOperatorTest, InstancesAreGloballyShared) { 110 TEST_P(MachineStoreOperatorTest, InstancesAreGloballyShared) {
108 MachineOperatorBuilder machine1(type()); 111 MachineOperatorBuilder machine1(zone(), type());
109 MachineOperatorBuilder machine2(type()); 112 MachineOperatorBuilder machine2(zone(), type());
110 EXPECT_EQ(machine1.Store(GetParam()), machine2.Store(GetParam())); 113 EXPECT_EQ(machine1.Store(GetParam()), machine2.Store(GetParam()));
111 } 114 }
112 115
113 116
114 TEST_P(MachineStoreOperatorTest, NumberOfInputsAndOutputs) { 117 TEST_P(MachineStoreOperatorTest, NumberOfInputsAndOutputs) {
115 MachineOperatorBuilder machine(type()); 118 MachineOperatorBuilder machine(zone(), type());
116 const Operator* op = machine.Store(GetParam()); 119 const Operator* op = machine.Store(GetParam());
117 120
118 EXPECT_EQ(3, op->ValueInputCount()); 121 EXPECT_EQ(3, op->ValueInputCount());
119 EXPECT_EQ(1, op->EffectInputCount()); 122 EXPECT_EQ(1, op->EffectInputCount());
120 EXPECT_EQ(1, op->ControlInputCount()); 123 EXPECT_EQ(1, op->ControlInputCount());
121 EXPECT_EQ(5, OperatorProperties::GetTotalInputCount(op)); 124 EXPECT_EQ(5, OperatorProperties::GetTotalInputCount(op));
122 125
123 EXPECT_EQ(0, op->ValueOutputCount()); 126 EXPECT_EQ(0, op->ValueOutputCount());
124 EXPECT_EQ(1, op->EffectOutputCount()); 127 EXPECT_EQ(1, op->EffectOutputCount());
125 EXPECT_EQ(0, op->ControlOutputCount()); 128 EXPECT_EQ(0, op->ControlOutputCount());
126 } 129 }
127 130
128 131
129 TEST_P(MachineStoreOperatorTest, OpcodeIsCorrect) { 132 TEST_P(MachineStoreOperatorTest, OpcodeIsCorrect) {
130 MachineOperatorBuilder machine(type()); 133 MachineOperatorBuilder machine(zone(), type());
131 EXPECT_EQ(IrOpcode::kStore, machine.Store(GetParam())->opcode()); 134 EXPECT_EQ(IrOpcode::kStore, machine.Store(GetParam())->opcode());
132 } 135 }
133 136
134 137
135 TEST_P(MachineStoreOperatorTest, ParameterIsCorrect) { 138 TEST_P(MachineStoreOperatorTest, ParameterIsCorrect) {
136 MachineOperatorBuilder machine(type()); 139 MachineOperatorBuilder machine(zone(), type());
137 EXPECT_EQ(GetParam(), 140 EXPECT_EQ(GetParam(),
138 OpParameter<StoreRepresentation>(machine.Store(GetParam()))); 141 OpParameter<StoreRepresentation>(machine.Store(GetParam())));
139 } 142 }
140 143
141 144
142 INSTANTIATE_TEST_CASE_P( 145 INSTANTIATE_TEST_CASE_P(
143 MachineOperatorTest, MachineStoreOperatorTest, 146 MachineOperatorTest, MachineStoreOperatorTest,
144 ::testing::Combine( 147 ::testing::Combine(
145 ::testing::ValuesIn(kMachineReps), 148 ::testing::ValuesIn(kMachineReps),
146 ::testing::Combine(::testing::ValuesIn(kMachineTypes), 149 ::testing::Combine(::testing::ValuesIn(kMachineTypes),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 }; 211 };
209 212
210 213
211 typedef MachineOperatorTestWithParam<PureOperator> MachinePureOperatorTest; 214 typedef MachineOperatorTestWithParam<PureOperator> MachinePureOperatorTest;
212 215
213 } // namespace 216 } // namespace
214 217
215 218
216 TEST_P(MachinePureOperatorTest, InstancesAreGloballyShared) { 219 TEST_P(MachinePureOperatorTest, InstancesAreGloballyShared) {
217 const PureOperator& pop = GetParam(); 220 const PureOperator& pop = GetParam();
218 MachineOperatorBuilder machine1(type()); 221 MachineOperatorBuilder machine1(zone(), type());
219 MachineOperatorBuilder machine2(type()); 222 MachineOperatorBuilder machine2(zone(), type());
220 EXPECT_EQ((machine1.*pop.constructor)(), (machine2.*pop.constructor)()); 223 EXPECT_EQ((machine1.*pop.constructor)(), (machine2.*pop.constructor)());
221 } 224 }
222 225
223 226
224 TEST_P(MachinePureOperatorTest, NumberOfInputsAndOutputs) { 227 TEST_P(MachinePureOperatorTest, NumberOfInputsAndOutputs) {
225 MachineOperatorBuilder machine(type()); 228 MachineOperatorBuilder machine(zone(), type());
226 const PureOperator& pop = GetParam(); 229 const PureOperator& pop = GetParam();
227 const Operator* op = (machine.*pop.constructor)(); 230 const Operator* op = (machine.*pop.constructor)();
228 231
229 EXPECT_EQ(pop.value_input_count, op->ValueInputCount()); 232 EXPECT_EQ(pop.value_input_count, op->ValueInputCount());
230 EXPECT_EQ(0, op->EffectInputCount()); 233 EXPECT_EQ(0, op->EffectInputCount());
231 EXPECT_EQ(pop.control_input_count, op->ControlInputCount()); 234 EXPECT_EQ(pop.control_input_count, op->ControlInputCount());
232 EXPECT_EQ(pop.value_input_count + pop.control_input_count, 235 EXPECT_EQ(pop.value_input_count + pop.control_input_count,
233 OperatorProperties::GetTotalInputCount(op)); 236 OperatorProperties::GetTotalInputCount(op));
234 237
235 EXPECT_EQ(pop.value_output_count, op->ValueOutputCount()); 238 EXPECT_EQ(pop.value_output_count, op->ValueOutputCount());
236 EXPECT_EQ(0, op->EffectOutputCount()); 239 EXPECT_EQ(0, op->EffectOutputCount());
237 EXPECT_EQ(0, op->ControlOutputCount()); 240 EXPECT_EQ(0, op->ControlOutputCount());
238 } 241 }
239 242
240 243
241 TEST_P(MachinePureOperatorTest, MarkedAsPure) { 244 TEST_P(MachinePureOperatorTest, MarkedAsPure) {
242 MachineOperatorBuilder machine(type()); 245 MachineOperatorBuilder machine(zone(), type());
243 const PureOperator& pop = GetParam(); 246 const PureOperator& pop = GetParam();
244 const Operator* op = (machine.*pop.constructor)(); 247 const Operator* op = (machine.*pop.constructor)();
245 EXPECT_TRUE(op->HasProperty(Operator::kPure)); 248 EXPECT_TRUE(op->HasProperty(Operator::kPure));
246 } 249 }
247 250
248 251
249 TEST_P(MachinePureOperatorTest, OpcodeIsCorrect) { 252 TEST_P(MachinePureOperatorTest, OpcodeIsCorrect) {
250 MachineOperatorBuilder machine(type()); 253 MachineOperatorBuilder machine(zone(), type());
251 const PureOperator& pop = GetParam(); 254 const PureOperator& pop = GetParam();
252 const Operator* op = (machine.*pop.constructor)(); 255 const Operator* op = (machine.*pop.constructor)();
253 EXPECT_EQ(pop.opcode, op->opcode()); 256 EXPECT_EQ(pop.opcode, op->opcode());
254 } 257 }
255 258
256 259
257 INSTANTIATE_TEST_CASE_P( 260 INSTANTIATE_TEST_CASE_P(
258 MachineOperatorTest, MachinePureOperatorTest, 261 MachineOperatorTest, MachinePureOperatorTest,
259 ::testing::Combine(::testing::ValuesIn(kMachineReps), 262 ::testing::Combine(::testing::ValuesIn(kMachineReps),
260 ::testing::ValuesIn(kPureOperators))); 263 ::testing::ValuesIn(kPureOperators)));
261 264
262 #endif // GTEST_HAS_COMBINE 265 #endif // GTEST_HAS_COMBINE
263 266
264 267
265 // ----------------------------------------------------------------------------- 268 // -----------------------------------------------------------------------------
266 // Pseudo operators. 269 // Pseudo operators.
267 270
268 271
269 TEST(MachineOperatorTest, PseudoOperatorsWhenWordSizeIs32Bit) { 272 namespace {
270 MachineOperatorBuilder machine(kRepWord32); 273
274 typedef TestWithZone MachineOperatorTest;
275
276 } // namespace
277
278
279 TEST_F(MachineOperatorTest, PseudoOperatorsWhenWordSizeIs32Bit) {
280 MachineOperatorBuilder machine(zone(), kRepWord32);
271 EXPECT_EQ(machine.Word32And(), machine.WordAnd()); 281 EXPECT_EQ(machine.Word32And(), machine.WordAnd());
272 EXPECT_EQ(machine.Word32Or(), machine.WordOr()); 282 EXPECT_EQ(machine.Word32Or(), machine.WordOr());
273 EXPECT_EQ(machine.Word32Xor(), machine.WordXor()); 283 EXPECT_EQ(machine.Word32Xor(), machine.WordXor());
274 EXPECT_EQ(machine.Word32Shl(), machine.WordShl()); 284 EXPECT_EQ(machine.Word32Shl(), machine.WordShl());
275 EXPECT_EQ(machine.Word32Shr(), machine.WordShr()); 285 EXPECT_EQ(machine.Word32Shr(), machine.WordShr());
276 EXPECT_EQ(machine.Word32Sar(), machine.WordSar()); 286 EXPECT_EQ(machine.Word32Sar(), machine.WordSar());
277 EXPECT_EQ(machine.Word32Ror(), machine.WordRor()); 287 EXPECT_EQ(machine.Word32Ror(), machine.WordRor());
278 EXPECT_EQ(machine.Word32Equal(), machine.WordEqual()); 288 EXPECT_EQ(machine.Word32Equal(), machine.WordEqual());
279 EXPECT_EQ(machine.Int32Add(), machine.IntAdd()); 289 EXPECT_EQ(machine.Int32Add(), machine.IntAdd());
280 EXPECT_EQ(machine.Int32Sub(), machine.IntSub()); 290 EXPECT_EQ(machine.Int32Sub(), machine.IntSub());
281 EXPECT_EQ(machine.Int32Mul(), machine.IntMul()); 291 EXPECT_EQ(machine.Int32Mul(), machine.IntMul());
282 EXPECT_EQ(machine.Int32Div(), machine.IntDiv()); 292 EXPECT_EQ(machine.Int32Div(), machine.IntDiv());
283 EXPECT_EQ(machine.Uint32Div(), machine.UintDiv()); 293 EXPECT_EQ(machine.Uint32Div(), machine.UintDiv());
284 EXPECT_EQ(machine.Int32Mod(), machine.IntMod()); 294 EXPECT_EQ(machine.Int32Mod(), machine.IntMod());
285 EXPECT_EQ(machine.Uint32Mod(), machine.UintMod()); 295 EXPECT_EQ(machine.Uint32Mod(), machine.UintMod());
286 EXPECT_EQ(machine.Int32LessThan(), machine.IntLessThan()); 296 EXPECT_EQ(machine.Int32LessThan(), machine.IntLessThan());
287 EXPECT_EQ(machine.Int32LessThanOrEqual(), machine.IntLessThanOrEqual()); 297 EXPECT_EQ(machine.Int32LessThanOrEqual(), machine.IntLessThanOrEqual());
288 } 298 }
289 299
290 300
291 TEST(MachineOperatorTest, PseudoOperatorsWhenWordSizeIs64Bit) { 301 TEST_F(MachineOperatorTest, PseudoOperatorsWhenWordSizeIs64Bit) {
292 MachineOperatorBuilder machine(kRepWord64); 302 MachineOperatorBuilder machine(zone(), kRepWord64);
293 EXPECT_EQ(machine.Word64And(), machine.WordAnd()); 303 EXPECT_EQ(machine.Word64And(), machine.WordAnd());
294 EXPECT_EQ(machine.Word64Or(), machine.WordOr()); 304 EXPECT_EQ(machine.Word64Or(), machine.WordOr());
295 EXPECT_EQ(machine.Word64Xor(), machine.WordXor()); 305 EXPECT_EQ(machine.Word64Xor(), machine.WordXor());
296 EXPECT_EQ(machine.Word64Shl(), machine.WordShl()); 306 EXPECT_EQ(machine.Word64Shl(), machine.WordShl());
297 EXPECT_EQ(machine.Word64Shr(), machine.WordShr()); 307 EXPECT_EQ(machine.Word64Shr(), machine.WordShr());
298 EXPECT_EQ(machine.Word64Sar(), machine.WordSar()); 308 EXPECT_EQ(machine.Word64Sar(), machine.WordSar());
299 EXPECT_EQ(machine.Word64Ror(), machine.WordRor()); 309 EXPECT_EQ(machine.Word64Ror(), machine.WordRor());
300 EXPECT_EQ(machine.Word64Equal(), machine.WordEqual()); 310 EXPECT_EQ(machine.Word64Equal(), machine.WordEqual());
301 EXPECT_EQ(machine.Int64Add(), machine.IntAdd()); 311 EXPECT_EQ(machine.Int64Add(), machine.IntAdd());
302 EXPECT_EQ(machine.Int64Sub(), machine.IntSub()); 312 EXPECT_EQ(machine.Int64Sub(), machine.IntSub());
303 EXPECT_EQ(machine.Int64Mul(), machine.IntMul()); 313 EXPECT_EQ(machine.Int64Mul(), machine.IntMul());
304 EXPECT_EQ(machine.Int64Div(), machine.IntDiv()); 314 EXPECT_EQ(machine.Int64Div(), machine.IntDiv());
305 EXPECT_EQ(machine.Uint64Div(), machine.UintDiv()); 315 EXPECT_EQ(machine.Uint64Div(), machine.UintDiv());
306 EXPECT_EQ(machine.Int64Mod(), machine.IntMod()); 316 EXPECT_EQ(machine.Int64Mod(), machine.IntMod());
307 EXPECT_EQ(machine.Uint64Mod(), machine.UintMod()); 317 EXPECT_EQ(machine.Uint64Mod(), machine.UintMod());
308 EXPECT_EQ(machine.Int64LessThan(), machine.IntLessThan()); 318 EXPECT_EQ(machine.Int64LessThan(), machine.IntLessThan());
309 EXPECT_EQ(machine.Int64LessThanOrEqual(), machine.IntLessThanOrEqual()); 319 EXPECT_EQ(machine.Int64LessThanOrEqual(), machine.IntLessThanOrEqual());
310 } 320 }
311 321
312 } // namespace compiler 322 } // namespace compiler
313 } // namespace internal 323 } // namespace internal
314 } // namespace v8 324 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698