Chromium Code Reviews| Index: test/unittests/compiler/js-operator-unittest.cc |
| diff --git a/test/unittests/compiler/js-operator-unittest.cc b/test/unittests/compiler/js-operator-unittest.cc |
| index e69a99c6193c7639cbf983cfbabda16e8b8dd499..be5930044d90203229ae099b49c8e5ff5be2c85e 100644 |
| --- a/test/unittests/compiler/js-operator-unittest.cc |
| +++ b/test/unittests/compiler/js-operator-unittest.cc |
| @@ -12,14 +12,10 @@ namespace v8 { |
| namespace internal { |
| namespace compiler { |
| -// ----------------------------------------------------------------------------- |
| -// Shared operators. |
| - |
| namespace { |
| -struct SharedOperator { |
| - const Operator* (JSOperatorBuilder::*constructor)(); |
| +struct OperatorParams { |
| IrOpcode::Value opcode; |
| Operator::Properties properties; |
| int value_input_count; |
| @@ -32,9 +28,21 @@ struct SharedOperator { |
| }; |
| -std::ostream& operator<<(std::ostream& os, const SharedOperator& sop) { |
| - return os << IrOpcode::Mnemonic(sop.opcode); |
| -} |
| +struct SharedOperator : OperatorParams { |
| + const Operator* (JSOperatorBuilder::*constructor)(); |
| + SharedOperator(const Operator* (JSOperatorBuilder::*cached)(), |
|
rossberg
2015/04/23 13:29:37
Are you ever using this constructor?
conradw
2015/04/23 14:51:55
Yes, my C++ is rusty about what exactly is going o
rossberg
2015/04/23 15:36:58
I think it would be much simpler to just parameter
conradw
2015/04/23 16:08:02
Done. It's beautiful.
|
| + IrOpcode::Value opcode, Operator::Properties properties, |
| + int value_input_count, int frame_state_input_count, |
| + int effect_input_count, int control_input_count, |
| + int value_output_count, int effect_output_count, |
| + int control_output_count) : OperatorParams({opcode, properties, |
| + value_input_count, |
| + frame_state_input_count, |
| + effect_input_count, control_input_count, |
|
rossberg
2015/04/23 13:29:37
Nit: weird indentation
conradw
2015/04/23 14:51:55
Made a stab at it.
|
| + value_output_count, effect_output_count, |
| + control_output_count}), |
| + constructor(cached) {} |
| +}; |
| const SharedOperator kSharedOperators[] = { |
| @@ -51,6 +59,53 @@ const SharedOperator kSharedOperators[] = { |
| SHARED(NotEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| SHARED(StrictEqual, Operator::kPure, 2, 0, 0, 0, 1, 0, 0), |
| SHARED(StrictNotEqual, Operator::kPure, 2, 0, 0, 0, 1, 0, 0), |
| + SHARED(ToBoolean, Operator::kPure, 1, 0, 0, 0, 1, 0, 0), |
| + SHARED(ToNumber, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), |
| + SHARED(ToString, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2), |
| + SHARED(ToName, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), |
| + SHARED(ToObject, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), |
| + SHARED(Yield, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2), |
| + SHARED(Create, Operator::kEliminatable, 0, 0, 1, 0, 1, 1, 0), |
| + SHARED(HasProperty, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| + SHARED(TypeOf, Operator::kPure, 1, 0, 0, 0, 1, 0, 0), |
| + SHARED(InstanceOf, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| + SHARED(CreateFunctionContext, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2), |
| + SHARED(CreateWithContext, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| + SHARED(CreateBlockContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1, 2), |
| + SHARED(CreateModuleContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1, 2), |
| + SHARED(CreateScriptContext, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2) |
| +#undef SHARED |
| +}; |
| + |
| + |
| +struct SharedOperatorWithLanguageMode : OperatorParams { |
| + const Operator* (JSOperatorBuilder::*constructor)(LanguageMode language_mode); |
| + SharedOperatorWithLanguageMode(const Operator* (JSOperatorBuilder::*cached) |
|
rossberg
2015/04/23 13:29:37
Or this one?
conradw
2015/04/23 14:51:55
Ditto for kSharedOperatorsWithlanguageMode[].
|
| + (LanguageMode language_mode), |
| + IrOpcode::Value opcode, Operator::Properties properties, |
| + int value_input_count, int frame_state_input_count, |
| + int effect_input_count, int control_input_count, |
| + int value_output_count, int effect_output_count, |
| + int control_output_count) : OperatorParams({opcode, properties, |
| + value_input_count, |
| + frame_state_input_count, |
| + effect_input_count, control_input_count, |
| + value_output_count, effect_output_count, |
| + control_output_count}), |
| + constructor(cached) {} |
| +}; |
| + |
| + |
| +const SharedOperatorWithLanguageMode kSharedOperatorsWithlanguageMode[] = { |
| +#define SHARED(Name, properties, value_input_count, frame_state_input_count, \ |
| + effect_input_count, control_input_count, value_output_count, \ |
| + effect_output_count, control_output_count) \ |
| + { \ |
| + &JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \ |
| + value_input_count, frame_state_input_count, effect_input_count, \ |
| + control_input_count, value_output_count, effect_output_count, \ |
| + control_output_count \ |
| + } |
| SHARED(LessThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| SHARED(GreaterThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| @@ -67,27 +122,46 @@ const SharedOperator kSharedOperators[] = { |
| SHARED(Divide, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), |
| SHARED(Modulus, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2), |
| SHARED(UnaryNot, Operator::kPure, 1, 0, 0, 0, 1, 0, 0), |
| - SHARED(ToBoolean, Operator::kPure, 1, 0, 0, 0, 1, 0, 0), |
| - SHARED(ToNumber, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), |
| - SHARED(ToString, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2), |
| - SHARED(ToName, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), |
| - SHARED(ToObject, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), |
| - SHARED(Yield, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2), |
| - SHARED(Create, Operator::kEliminatable, 0, 0, 1, 0, 1, 1, 0), |
| - SHARED(HasProperty, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| - SHARED(TypeOf, Operator::kPure, 1, 0, 0, 0, 1, 0, 0), |
| - SHARED(InstanceOf, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| - SHARED(CreateFunctionContext, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2), |
| - SHARED(CreateWithContext, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), |
| - SHARED(CreateBlockContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1, 2), |
| - SHARED(CreateModuleContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1, 2), |
| - SHARED(CreateScriptContext, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2) |
| #undef SHARED |
| }; |
| + |
| +void testNumberOfInputsAndOutputs(const OperatorParams& sop, |
| + const Operator* op) { |
| + const int context_input_count = 1; |
| + EXPECT_EQ(sop.value_input_count, op->ValueInputCount()); |
| + EXPECT_EQ(context_input_count, OperatorProperties::GetContextInputCount(op)); |
| + EXPECT_EQ(sop.frame_state_input_count, |
| + OperatorProperties::GetFrameStateInputCount(op)); |
| + EXPECT_EQ(sop.effect_input_count, op->EffectInputCount()); |
| + EXPECT_EQ(sop.control_input_count, op->ControlInputCount()); |
| + EXPECT_EQ(sop.value_input_count + context_input_count + |
| + sop.frame_state_input_count + sop.effect_input_count + |
| + sop.control_input_count, |
| + OperatorProperties::GetTotalInputCount(op)); |
| + |
| + EXPECT_EQ(sop.value_output_count, op->ValueOutputCount()); |
| + EXPECT_EQ(sop.effect_output_count, op->EffectOutputCount()); |
| + EXPECT_EQ(sop.control_output_count, op->ControlOutputCount()); |
| +} |
| + |
| + |
| +std::ostream& operator<<(std::ostream& os, const SharedOperator& sop) { |
| + return os << IrOpcode::Mnemonic(sop.opcode); |
| +} |
| + |
| +std::ostream& operator<<(std::ostream& os, |
| + const SharedOperatorWithLanguageMode& sop) { |
| + return os << IrOpcode::Mnemonic(sop.opcode); |
| +} |
| + |
| } // namespace |
| +// ----------------------------------------------------------------------------- |
| +// Shared operators. |
| + |
| + |
| class JSSharedOperatorTest |
| : public TestWithZone, |
| public ::testing::WithParamInterface<SharedOperator> {}; |
| @@ -105,22 +179,7 @@ TEST_P(JSSharedOperatorTest, NumberOfInputsAndOutputs) { |
| JSOperatorBuilder javascript(zone()); |
| const SharedOperator& sop = GetParam(); |
| const Operator* op = (javascript.*sop.constructor)(); |
| - |
| - const int context_input_count = 1; |
| - EXPECT_EQ(sop.value_input_count, op->ValueInputCount()); |
| - EXPECT_EQ(context_input_count, OperatorProperties::GetContextInputCount(op)); |
| - EXPECT_EQ(sop.frame_state_input_count, |
| - OperatorProperties::GetFrameStateInputCount(op)); |
| - EXPECT_EQ(sop.effect_input_count, op->EffectInputCount()); |
| - EXPECT_EQ(sop.control_input_count, op->ControlInputCount()); |
| - EXPECT_EQ(sop.value_input_count + context_input_count + |
| - sop.frame_state_input_count + sop.effect_input_count + |
| - sop.control_input_count, |
| - OperatorProperties::GetTotalInputCount(op)); |
| - |
| - EXPECT_EQ(sop.value_output_count, op->ValueOutputCount()); |
| - EXPECT_EQ(sop.effect_output_count, op->EffectOutputCount()); |
| - EXPECT_EQ(sop.control_output_count, op->ControlOutputCount()); |
| + testNumberOfInputsAndOutputs(sop, op); |
| } |
| @@ -143,6 +202,64 @@ TEST_P(JSSharedOperatorTest, Properties) { |
| INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest, |
| ::testing::ValuesIn(kSharedOperators)); |
| +// ----------------------------------------------------------------------------- |
| +// Shared operators which behave differently in strong mode |
| + |
| + |
| +class JSSharedOperatorWithStrongTest |
| + : public TestWithZone, |
| + public ::testing::WithParamInterface<SharedOperatorWithLanguageMode> {}; |
| + |
| + |
| +TEST_P(JSSharedOperatorWithStrongTest, InstancesAreGloballyShared) { |
| + const SharedOperatorWithLanguageMode& sop = GetParam(); |
| + JSOperatorBuilder javascript1(zone()); |
| + JSOperatorBuilder javascript2(zone()); |
| + EXPECT_EQ((javascript1.*sop.constructor)(LanguageMode::SLOPPY), |
| + (javascript2.*sop.constructor)(LanguageMode::SLOPPY)); |
| + EXPECT_EQ((javascript1.*sop.constructor)(LanguageMode::STRONG), |
| + (javascript2.*sop.constructor)(LanguageMode::STRONG)); |
| +} |
| + |
| + |
| +TEST_P(JSSharedOperatorWithStrongTest, NumberOfInputsAndOutputs) { |
| + JSOperatorBuilder javascript(zone()); |
| + const SharedOperatorWithLanguageMode& sop = GetParam(); |
| + const Operator* op_sloppy = (javascript.*sop.constructor) |
| + (LanguageMode::SLOPPY); |
| + testNumberOfInputsAndOutputs(sop, op_sloppy); |
| + const Operator* op_strong = (javascript.*sop.constructor) |
| + (LanguageMode::STRONG); |
| + testNumberOfInputsAndOutputs(sop, op_strong); |
| +} |
| + |
| + |
| +TEST_P(JSSharedOperatorWithStrongTest, OpcodeIsCorrect) { |
| + JSOperatorBuilder javascript(zone()); |
| + const SharedOperatorWithLanguageMode& sop = GetParam(); |
| + const Operator* op_sloppy = (javascript.*sop.constructor) |
| + (LanguageMode::SLOPPY); |
| + EXPECT_EQ(sop.opcode, op_sloppy->opcode()); |
| + const Operator* op_strong = (javascript.*sop.constructor) |
| + (LanguageMode::STRONG); |
| + EXPECT_EQ(sop.opcode, op_strong->opcode()); |
| +} |
| + |
| + |
| +TEST_P(JSSharedOperatorWithStrongTest, Properties) { |
| + JSOperatorBuilder javascript(zone()); |
| + const SharedOperatorWithLanguageMode& sop = GetParam(); |
| + const Operator* op_sloppy = (javascript.*sop.constructor) |
| + (LanguageMode::SLOPPY); |
| + EXPECT_EQ(sop.properties, op_sloppy->properties()); |
| + const Operator* op_strong = (javascript.*sop.constructor) |
| + (LanguageMode::STRONG); |
| + EXPECT_EQ(sop.properties, op_strong->properties()); |
| +} |
| + |
| + |
| +INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorWithStrongTest, |
| + ::testing::ValuesIn(kSharedOperatorsWithlanguageMode)); |
| // ----------------------------------------------------------------------------- |
| // JSStoreProperty. |