Index: src/compiler/common-operator-unittest.cc |
diff --git a/src/compiler/common-operator-unittest.cc b/src/compiler/common-operator-unittest.cc |
index 41c74b5d37b688917a439ab9e24259fd2ccf6cbf..128f8ddede541c214f4dfd3779f19c5abf445293 100644 |
--- a/src/compiler/common-operator-unittest.cc |
+++ b/src/compiler/common-operator-unittest.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include "src/compiler/common-operator.h" |
+ |
#include "src/compiler/operator-properties-inl.h" |
#include "src/test/test-utils.h" |
@@ -10,6 +11,111 @@ namespace v8 { |
namespace internal { |
namespace compiler { |
+ |
+// ----------------------------------------------------------------------------- |
+// Shared operators. |
+ |
+ |
+namespace { |
+ |
+struct SharedOperator { |
+ const Operator* (CommonOperatorBuilder::*constructor)(); |
+ IrOpcode::Value opcode; |
+ Operator::Properties properties; |
+ int value_input_count; |
+ int effect_input_count; |
+ int control_input_count; |
+ int effect_output_count; |
+ int control_output_count; |
+}; |
+ |
+ |
+std::ostream& operator<<(std::ostream& os, const SharedOperator& fop) { |
+ return os << IrOpcode::Mnemonic(fop.opcode); |
+} |
+ |
+ |
+const SharedOperator kSharedOperators[] = { |
+#define SHARED(Name, properties, value_input_count, effect_input_count, \ |
+ control_input_count, effect_output_count, control_output_count) \ |
+ { \ |
+ &CommonOperatorBuilder::Name, IrOpcode::k##Name, properties, \ |
+ value_input_count, effect_input_count, control_input_count, \ |
+ effect_output_count, control_output_count \ |
+ } |
+ SHARED(Dead, Operator::kFoldable, 0, 0, 0, 0, 1), |
+ SHARED(End, Operator::kFoldable, 0, 0, 1, 0, 0), |
+ SHARED(Branch, Operator::kFoldable, 1, 0, 1, 0, 2), |
+ SHARED(IfTrue, Operator::kFoldable, 0, 0, 1, 0, 1), |
+ SHARED(IfFalse, Operator::kFoldable, 0, 0, 1, 0, 1), |
+ SHARED(Throw, Operator::kFoldable, 1, 0, 1, 0, 1), |
+ SHARED(Return, Operator::kNoProperties, 1, 1, 1, 1, 1), |
+ SHARED(ControlEffect, Operator::kPure, 0, 0, 1, 1, 0) |
+#undef SHARED |
+}; |
+ |
+ |
+class CommonSharedOperatorTest |
+ : public TestWithZone, |
+ public ::testing::WithParamInterface<SharedOperator> {}; |
+ |
+} // namespace |
+ |
+ |
+TEST_P(CommonSharedOperatorTest, InstancesAreGloballyShared) { |
+ const SharedOperator& sop = GetParam(); |
+ CommonOperatorBuilder common1(zone()); |
+ CommonOperatorBuilder common2(zone()); |
+ EXPECT_EQ((common1.*sop.constructor)(), (common2.*sop.constructor)()); |
+} |
+ |
+ |
+TEST_P(CommonSharedOperatorTest, NumberOfInputsAndOutputs) { |
+ CommonOperatorBuilder common(zone()); |
+ const SharedOperator& sop = GetParam(); |
+ const Operator* op = (common.*sop.constructor)(); |
+ |
+ EXPECT_EQ(sop.value_input_count, OperatorProperties::GetValueInputCount(op)); |
+ EXPECT_EQ(sop.effect_input_count, |
+ OperatorProperties::GetEffectInputCount(op)); |
+ EXPECT_EQ(sop.control_input_count, |
+ OperatorProperties::GetControlInputCount(op)); |
+ EXPECT_EQ( |
+ sop.value_input_count + sop.effect_input_count + sop.control_input_count, |
+ OperatorProperties::GetTotalInputCount(op)); |
+ |
+ EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op)); |
+ EXPECT_EQ(sop.effect_output_count, |
+ OperatorProperties::GetEffectOutputCount(op)); |
+ EXPECT_EQ(sop.control_output_count, |
+ OperatorProperties::GetControlOutputCount(op)); |
+} |
+ |
+ |
+TEST_P(CommonSharedOperatorTest, OpcodeIsCorrect) { |
+ CommonOperatorBuilder common(zone()); |
+ const SharedOperator& sop = GetParam(); |
+ const Operator* op = (common.*sop.constructor)(); |
+ EXPECT_EQ(sop.opcode, op->opcode()); |
+} |
+ |
+ |
+TEST_P(CommonSharedOperatorTest, Properties) { |
+ CommonOperatorBuilder common(zone()); |
+ const SharedOperator& sop = GetParam(); |
+ const Operator* op = (common.*sop.constructor)(); |
+ EXPECT_EQ(sop.properties, op->properties()); |
+} |
+ |
+ |
+INSTANTIATE_TEST_CASE_P(CommonOperatorTest, CommonSharedOperatorTest, |
+ ::testing::ValuesIn(kSharedOperators)); |
+ |
+ |
+// ----------------------------------------------------------------------------- |
+// Other operators. |
+ |
+ |
namespace { |
class CommonOperatorTest : public TestWithZone { |
@@ -29,16 +135,6 @@ const int kArguments[] = {1, 5, 6, 42, 100, 10000, kMaxInt}; |
} // namespace |
-TEST_F(CommonOperatorTest, ControlEffect) { |
- const Operator* op = common()->ControlEffect(); |
- EXPECT_EQ(1, OperatorProperties::GetControlInputCount(op)); |
- EXPECT_EQ(1, OperatorProperties::GetTotalInputCount(op)); |
- EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op)); |
- EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op)); |
- EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op)); |
-} |
- |
- |
TEST_F(CommonOperatorTest, ValueEffect) { |
TRACED_FOREACH(int, arguments, kArguments) { |
const Operator* op = common()->ValueEffect(arguments); |