OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/compiler/simplified-operator.h" |
| 6 |
| 7 #include "src/compiler/operator-properties-inl.h" |
| 8 #include "src/test/test-utils.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 namespace compiler { |
| 13 |
| 14 // ----------------------------------------------------------------------------- |
| 15 // Pure operators. |
| 16 |
| 17 |
| 18 namespace { |
| 19 |
| 20 struct PureOperator { |
| 21 const Operator* (SimplifiedOperatorBuilder::*constructor)() const; |
| 22 IrOpcode::Value opcode; |
| 23 Operator::Properties properties; |
| 24 int value_input_count; |
| 25 }; |
| 26 |
| 27 |
| 28 std::ostream& operator<<(std::ostream& os, const PureOperator& pop) { |
| 29 return os << IrOpcode::Mnemonic(pop.opcode); |
| 30 } |
| 31 |
| 32 |
| 33 const PureOperator kPureOperators[] = { |
| 34 #define PURE(Name, properties, input_count) \ |
| 35 { \ |
| 36 &SimplifiedOperatorBuilder::Name, IrOpcode::k##Name, \ |
| 37 Operator::kPure | properties, input_count \ |
| 38 } |
| 39 PURE(BooleanNot, Operator::kNoProperties, 1), |
| 40 PURE(NumberEqual, Operator::kCommutative, 2), |
| 41 PURE(NumberLessThan, Operator::kNoProperties, 2), |
| 42 PURE(NumberLessThanOrEqual, Operator::kNoProperties, 2), |
| 43 PURE(NumberAdd, Operator::kCommutative, 2), |
| 44 PURE(NumberSubtract, Operator::kNoProperties, 2), |
| 45 PURE(NumberMultiply, Operator::kCommutative, 2), |
| 46 PURE(NumberDivide, Operator::kNoProperties, 2), |
| 47 PURE(NumberModulus, Operator::kNoProperties, 2), |
| 48 PURE(NumberToInt32, Operator::kNoProperties, 1), |
| 49 PURE(NumberToUint32, Operator::kNoProperties, 1), |
| 50 PURE(StringEqual, Operator::kCommutative, 2), |
| 51 PURE(StringLessThan, Operator::kNoProperties, 2), |
| 52 PURE(StringLessThanOrEqual, Operator::kNoProperties, 2), |
| 53 PURE(StringAdd, Operator::kNoProperties, 2), |
| 54 PURE(ChangeTaggedToInt32, Operator::kNoProperties, 1), |
| 55 PURE(ChangeTaggedToUint32, Operator::kNoProperties, 1), |
| 56 PURE(ChangeTaggedToFloat64, Operator::kNoProperties, 1), |
| 57 PURE(ChangeInt32ToTagged, Operator::kNoProperties, 1), |
| 58 PURE(ChangeUint32ToTagged, Operator::kNoProperties, 1), |
| 59 PURE(ChangeFloat64ToTagged, Operator::kNoProperties, 1), |
| 60 PURE(ChangeBoolToBit, Operator::kNoProperties, 1), |
| 61 PURE(ChangeBitToBool, Operator::kNoProperties, 1) |
| 62 #undef PURE |
| 63 }; |
| 64 |
| 65 } // namespace |
| 66 |
| 67 |
| 68 class SimplifiedPureOperatorTest |
| 69 : public TestWithZone, |
| 70 public ::testing::WithParamInterface<PureOperator> {}; |
| 71 |
| 72 |
| 73 TEST_P(SimplifiedPureOperatorTest, InstancesAreGloballyShared) { |
| 74 const PureOperator& pop = GetParam(); |
| 75 SimplifiedOperatorBuilder simplified1(zone()); |
| 76 SimplifiedOperatorBuilder simplified2(zone()); |
| 77 EXPECT_EQ((simplified1.*pop.constructor)(), (simplified2.*pop.constructor)()); |
| 78 } |
| 79 |
| 80 |
| 81 TEST_P(SimplifiedPureOperatorTest, NumberOfInputsAndOutputs) { |
| 82 SimplifiedOperatorBuilder simplified(zone()); |
| 83 const PureOperator& pop = GetParam(); |
| 84 const Operator* op = (simplified.*pop.constructor)(); |
| 85 |
| 86 EXPECT_EQ(pop.value_input_count, OperatorProperties::GetValueInputCount(op)); |
| 87 EXPECT_EQ(0, OperatorProperties::GetEffectInputCount(op)); |
| 88 EXPECT_EQ(0, OperatorProperties::GetControlInputCount(op)); |
| 89 EXPECT_EQ(pop.value_input_count, OperatorProperties::GetTotalInputCount(op)); |
| 90 |
| 91 EXPECT_EQ(1, OperatorProperties::GetValueOutputCount(op)); |
| 92 EXPECT_EQ(0, OperatorProperties::GetEffectOutputCount(op)); |
| 93 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op)); |
| 94 } |
| 95 |
| 96 |
| 97 TEST_P(SimplifiedPureOperatorTest, OpcodeIsCorrect) { |
| 98 SimplifiedOperatorBuilder simplified(zone()); |
| 99 const PureOperator& pop = GetParam(); |
| 100 const Operator* op = (simplified.*pop.constructor)(); |
| 101 EXPECT_EQ(pop.opcode, op->opcode()); |
| 102 } |
| 103 |
| 104 |
| 105 TEST_P(SimplifiedPureOperatorTest, Properties) { |
| 106 SimplifiedOperatorBuilder simplified(zone()); |
| 107 const PureOperator& pop = GetParam(); |
| 108 const Operator* op = (simplified.*pop.constructor)(); |
| 109 EXPECT_EQ(pop.properties, op->properties() & pop.properties); |
| 110 } |
| 111 |
| 112 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest, |
| 113 ::testing::ValuesIn(kPureOperators)); |
| 114 |
| 115 } // namespace compiler |
| 116 } // namespace internal |
| 117 } // namespace v8 |
OLD | NEW |