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

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

Issue 1144183004: [strong] Refactor ObjectStrength into a replacement for strong boolean args (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 6 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
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/js-operator.h" 5 #include "src/compiler/js-operator.h"
6 #include "src/compiler/opcodes.h" 6 #include "src/compiler/opcodes.h"
7 #include "src/compiler/operator.h" 7 #include "src/compiler/operator.h"
8 #include "src/compiler/operator-properties.h" 8 #include "src/compiler/operator-properties.h"
9 #include "test/unittests/test-utils.h" 9 #include "test/unittests/test-utils.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace compiler { 13 namespace compiler {
14 14
15 namespace { 15 namespace {
16 16
17 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; 17
18 const LanguageMode kLanguageModes[] = {
19 LanguageMode::SLOPPY, LanguageMode::STRICT, LanguageMode::STRONG};
20
21
22 const LanguageMode kLanguageModesForStrength[] = {LanguageMode::SLOPPY,
23 LanguageMode::STRONG};
18 24
19 25
20 #if GTEST_HAS_COMBINE 26 #if GTEST_HAS_COMBINE
21 27
22 template <typename T> 28 template <typename T>
23 class JSOperatorTestWithLanguageModeAndParam 29 class JSOperatorTestWithLanguageModeAndParam
24 : public TestWithZone, 30 : public TestWithZone,
25 public ::testing::WithParamInterface<::testing::tuple<LanguageMode, T>> { 31 public ::testing::WithParamInterface<::testing::tuple<LanguageMode, T>> {
26 protected: 32 protected:
27 LanguageMode language_mode() const { 33 LanguageMode language_mode() const {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const Operator* op = (javascript.*sop.constructor)(); 154 const Operator* op = (javascript.*sop.constructor)();
149 EXPECT_EQ(sop.properties, op->properties()); 155 EXPECT_EQ(sop.properties, op->properties());
150 } 156 }
151 157
152 158
153 INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest, 159 INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest,
154 ::testing::ValuesIn(kSharedOperators)); 160 ::testing::ValuesIn(kSharedOperators));
155 161
156 162
157 // ----------------------------------------------------------------------------- 163 // -----------------------------------------------------------------------------
158 // Shared operators with language mode. 164 // Shared operators with strength.
159
160 165
161 #if GTEST_HAS_COMBINE 166 #if GTEST_HAS_COMBINE
162 167
163 namespace { 168 namespace {
164 169
165 struct SharedOperatorWithLanguageMode { 170 struct SharedOperatorWithStrength {
166 const Operator* (JSOperatorBuilder::*constructor)(LanguageMode); 171 const Operator* (JSOperatorBuilder::*constructor)(Strength);
167 IrOpcode::Value opcode; 172 IrOpcode::Value opcode;
168 Operator::Properties properties; 173 Operator::Properties properties;
169 int value_input_count; 174 int value_input_count;
170 int frame_state_input_count; 175 int frame_state_input_count;
171 int effect_input_count; 176 int effect_input_count;
172 int control_input_count; 177 int control_input_count;
173 int value_output_count; 178 int value_output_count;
174 int effect_output_count; 179 int effect_output_count;
175 int control_output_count; 180 int control_output_count;
176 }; 181 };
177 182
178 183
179 const SharedOperatorWithLanguageMode kSharedOperatorsWithLanguageMode[] = { 184 const SharedOperatorWithStrength kSharedOperatorsWithStrength[] = {
180 #define SHARED(Name, properties, value_input_count, frame_state_input_count, \ 185 #define SHARED(Name, properties, value_input_count, frame_state_input_count, \
181 effect_input_count, control_input_count, value_output_count, \ 186 effect_input_count, control_input_count, value_output_count, \
182 effect_output_count, control_output_count) \ 187 effect_output_count, control_output_count) \
183 { \ 188 { \
184 &JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \ 189 &JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \
185 value_input_count, frame_state_input_count, effect_input_count, \ 190 value_input_count, frame_state_input_count, effect_input_count, \
186 control_input_count, value_output_count, effect_output_count, \ 191 control_input_count, value_output_count, effect_output_count, \
187 control_output_count \ 192 control_output_count \
188 } 193 }
189 SHARED(LessThan, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 194 SHARED(LessThan, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
190 SHARED(GreaterThan, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 195 SHARED(GreaterThan, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
191 SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 196 SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
192 SHARED(GreaterThanOrEqual, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 197 SHARED(GreaterThanOrEqual, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
193 SHARED(BitwiseOr, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 198 SHARED(BitwiseOr, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
194 SHARED(BitwiseXor, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 199 SHARED(BitwiseXor, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
195 SHARED(BitwiseAnd, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 200 SHARED(BitwiseAnd, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
196 SHARED(ShiftLeft, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 201 SHARED(ShiftLeft, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
197 SHARED(ShiftRight, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 202 SHARED(ShiftRight, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
198 SHARED(ShiftRightLogical, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 203 SHARED(ShiftRightLogical, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
199 SHARED(Add, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 204 SHARED(Add, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
200 SHARED(Subtract, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 205 SHARED(Subtract, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
201 SHARED(Multiply, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 206 SHARED(Multiply, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
202 SHARED(Divide, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 207 SHARED(Divide, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
203 SHARED(Modulus, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), 208 SHARED(Modulus, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2)
204 SHARED(StoreProperty, Operator::kNoProperties, 3, 2, 1, 1, 0, 1, 2),
205 #undef SHARED 209 #undef SHARED
206 }; 210 };
207 211
212
213 std::ostream& operator<<(std::ostream& os,
214 const SharedOperatorWithStrength& sop) {
215 return os << IrOpcode::Mnemonic(sop.opcode);
216 }
217
218 } // namespace
219
220
221 class JSSharedOperatorWithStrengthTest
222 : public JSOperatorTestWithLanguageModeAndParam<
223 SharedOperatorWithStrength> {};
224
225
226 TEST_P(JSSharedOperatorWithStrengthTest, InstancesAreGloballyShared) {
227 const SharedOperatorWithStrength& sop = GetParam();
228 JSOperatorBuilder javascript1(zone());
229 JSOperatorBuilder javascript2(zone());
230 EXPECT_EQ((javascript1.*sop.constructor)(strength(language_mode())),
231 (javascript2.*sop.constructor)(strength(language_mode())));
232 }
233
234
235 TEST_P(JSSharedOperatorWithStrengthTest, NumberOfInputsAndOutputs) {
236 JSOperatorBuilder javascript(zone());
237 const SharedOperatorWithStrength& sop = GetParam();
238 const Operator* op = (javascript.*sop.constructor)(strength(language_mode()));
239
240 const int context_input_count = 1;
241 EXPECT_EQ(sop.value_input_count, op->ValueInputCount());
242 EXPECT_EQ(context_input_count, OperatorProperties::GetContextInputCount(op));
243 EXPECT_EQ(sop.frame_state_input_count,
244 OperatorProperties::GetFrameStateInputCount(op));
245 EXPECT_EQ(sop.effect_input_count, op->EffectInputCount());
246 EXPECT_EQ(sop.control_input_count, op->ControlInputCount());
247 EXPECT_EQ(sop.value_input_count + context_input_count +
248 sop.frame_state_input_count + sop.effect_input_count +
249 sop.control_input_count,
250 OperatorProperties::GetTotalInputCount(op));
251
252 EXPECT_EQ(sop.value_output_count, op->ValueOutputCount());
253 EXPECT_EQ(sop.effect_output_count, op->EffectOutputCount());
254 EXPECT_EQ(sop.control_output_count, op->ControlOutputCount());
255 }
256
257
258 TEST_P(JSSharedOperatorWithStrengthTest, OpcodeIsCorrect) {
259 JSOperatorBuilder javascript(zone());
260 const SharedOperatorWithStrength& sop = GetParam();
261 const Operator* op = (javascript.*sop.constructor)(strength(language_mode()));
262 EXPECT_EQ(sop.opcode, op->opcode());
263 }
264
265
266 TEST_P(JSSharedOperatorWithStrengthTest, Parameter) {
267 JSOperatorBuilder javascript(zone());
268 const SharedOperatorWithStrength& sop = GetParam();
269 const Operator* op = (javascript.*sop.constructor)(strength(language_mode()));
270 EXPECT_EQ(strength(language_mode()), OpParameter<Strength>(op));
271 }
272
273
274 TEST_P(JSSharedOperatorWithStrengthTest, Properties) {
275 JSOperatorBuilder javascript(zone());
276 const SharedOperatorWithStrength& sop = GetParam();
277 const Operator* op = (javascript.*sop.constructor)(strength(language_mode()));
278 EXPECT_EQ(sop.properties, op->properties());
279 }
280
281
282 INSTANTIATE_TEST_CASE_P(
283 JSOperatorTest, JSSharedOperatorWithStrengthTest,
284 ::testing::Combine(::testing::ValuesIn(kLanguageModesForStrength),
285 ::testing::ValuesIn(kSharedOperatorsWithStrength)));
286
287
288 // -----------------------------------------------------------------------------
289 // Shared operators with language mode.
290
291 namespace {
292
293 struct SharedOperatorWithLanguageMode {
294 const Operator* (JSOperatorBuilder::*constructor)(LanguageMode);
295 IrOpcode::Value opcode;
296 Operator::Properties properties;
297 int value_input_count;
298 int frame_state_input_count;
299 int effect_input_count;
300 int control_input_count;
301 int value_output_count;
302 int effect_output_count;
303 int control_output_count;
304 };
305
306
307 const SharedOperatorWithLanguageMode kSharedOperatorsWithLanguageMode[] = {
308 #define SHARED(Name, properties, value_input_count, frame_state_input_count, \
309 effect_input_count, control_input_count, value_output_count, \
310 effect_output_count, control_output_count) \
311 { \
312 &JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \
313 value_input_count, frame_state_input_count, effect_input_count, \
314 control_input_count, value_output_count, effect_output_count, \
315 control_output_count \
316 }
317 SHARED(StoreProperty, Operator::kNoProperties, 3, 2, 1, 1, 0, 1, 2)
318 #undef SHARED
319 };
320
208 321
209 std::ostream& operator<<(std::ostream& os, 322 std::ostream& operator<<(std::ostream& os,
210 const SharedOperatorWithLanguageMode& sop) { 323 const SharedOperatorWithLanguageMode& sop) {
211 return os << IrOpcode::Mnemonic(sop.opcode); 324 return os << IrOpcode::Mnemonic(sop.opcode);
212 } 325 }
213 326
214 } // namespace 327 } // namespace
215 328
216 329
217 class JSSharedOperatorWithLanguageModeTest 330 class JSSharedOperatorWithLanguageModeTest
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 const Operator* op = (javascript.*sop.constructor)(language_mode()); 386 const Operator* op = (javascript.*sop.constructor)(language_mode());
274 EXPECT_EQ(sop.properties, op->properties()); 387 EXPECT_EQ(sop.properties, op->properties());
275 } 388 }
276 389
277 390
278 INSTANTIATE_TEST_CASE_P( 391 INSTANTIATE_TEST_CASE_P(
279 JSOperatorTest, JSSharedOperatorWithLanguageModeTest, 392 JSOperatorTest, JSSharedOperatorWithLanguageModeTest,
280 ::testing::Combine(::testing::ValuesIn(kLanguageModes), 393 ::testing::Combine(::testing::ValuesIn(kLanguageModes),
281 ::testing::ValuesIn(kSharedOperatorsWithLanguageMode))); 394 ::testing::ValuesIn(kSharedOperatorsWithLanguageMode)));
282 395
396
283 #endif // GTEST_HAS_COMBINE 397 #endif // GTEST_HAS_COMBINE
284 398
285 } // namespace compiler 399 } // namespace compiler
286 } // namespace internal 400 } // namespace internal
287 } // namespace v8 401 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698