| OLD | NEW |
| 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
| 8 #include "src/compiler/opcodes.h" | 8 #include "src/compiler/opcodes.h" |
| 9 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
| 10 #include "src/compiler/operator-properties.h" | 10 #include "src/compiler/operator-properties.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 struct SharedOperator { | 24 struct SharedOperator { |
| 25 const Operator* (CommonOperatorBuilder::*constructor)(); | 25 const Operator* (CommonOperatorBuilder::*constructor)(); |
| 26 IrOpcode::Value opcode; | 26 IrOpcode::Value opcode; |
| 27 Operator::Properties properties; | 27 Operator::Properties properties; |
| 28 int value_input_count; | 28 int value_input_count; |
| 29 int effect_input_count; | 29 int effect_input_count; |
| 30 int control_input_count; | 30 int control_input_count; |
| 31 int value_output_count; |
| 31 int effect_output_count; | 32 int effect_output_count; |
| 32 int control_output_count; | 33 int control_output_count; |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 | 36 |
| 36 std::ostream& operator<<(std::ostream& os, const SharedOperator& fop) { | 37 std::ostream& operator<<(std::ostream& os, const SharedOperator& fop) { |
| 37 return os << IrOpcode::Mnemonic(fop.opcode); | 38 return os << IrOpcode::Mnemonic(fop.opcode); |
| 38 } | 39 } |
| 39 | 40 |
| 40 | 41 |
| 41 const SharedOperator kSharedOperators[] = { | 42 const SharedOperator kSharedOperators[] = { |
| 42 #define SHARED(Name, properties, value_input_count, effect_input_count, \ | 43 #define SHARED(Name, properties, value_input_count, effect_input_count, \ |
| 43 control_input_count, effect_output_count, control_output_count) \ | 44 control_input_count, value_output_count, effect_output_count, \ |
| 44 { \ | 45 control_output_count) \ |
| 45 &CommonOperatorBuilder::Name, IrOpcode::k##Name, properties, \ | 46 { \ |
| 46 value_input_count, effect_input_count, control_input_count, \ | 47 &CommonOperatorBuilder::Name, IrOpcode::k##Name, properties, \ |
| 47 effect_output_count, control_output_count \ | 48 value_input_count, effect_input_count, control_input_count, \ |
| 49 value_output_count, effect_output_count, control_output_count \ |
| 48 } | 50 } |
| 49 SHARED(Dead, Operator::kFoldable, 0, 0, 0, 0, 1), | 51 SHARED(Always, Operator::kPure, 0, 0, 0, 1, 0, 0), |
| 50 SHARED(End, Operator::kFoldable, 0, 0, 1, 0, 0), | 52 SHARED(Dead, Operator::kFoldable, 0, 0, 0, 0, 0, 1), |
| 51 SHARED(IfTrue, Operator::kFoldable, 0, 0, 1, 0, 1), | 53 SHARED(End, Operator::kFoldable, 0, 0, 1, 0, 0, 0), |
| 52 SHARED(IfFalse, Operator::kFoldable, 0, 0, 1, 0, 1), | 54 SHARED(IfTrue, Operator::kFoldable, 0, 0, 1, 0, 0, 1), |
| 53 SHARED(Throw, Operator::kFoldable, 1, 1, 1, 0, 1), | 55 SHARED(IfFalse, Operator::kFoldable, 0, 0, 1, 0, 0, 1), |
| 54 SHARED(Return, Operator::kNoProperties, 1, 1, 1, 0, 1) | 56 SHARED(Throw, Operator::kFoldable, 1, 1, 1, 0, 0, 1), |
| 57 SHARED(Return, Operator::kNoProperties, 1, 1, 1, 0, 0, 1) |
| 55 #undef SHARED | 58 #undef SHARED |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 | 61 |
| 59 class CommonSharedOperatorTest | 62 class CommonSharedOperatorTest |
| 60 : public TestWithZone, | 63 : public TestWithZone, |
| 61 public ::testing::WithParamInterface<SharedOperator> {}; | 64 public ::testing::WithParamInterface<SharedOperator> {}; |
| 62 | 65 |
| 63 } // namespace | 66 } // namespace |
| 64 | 67 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 76 const SharedOperator& sop = GetParam(); | 79 const SharedOperator& sop = GetParam(); |
| 77 const Operator* op = (common.*sop.constructor)(); | 80 const Operator* op = (common.*sop.constructor)(); |
| 78 | 81 |
| 79 EXPECT_EQ(sop.value_input_count, op->ValueInputCount()); | 82 EXPECT_EQ(sop.value_input_count, op->ValueInputCount()); |
| 80 EXPECT_EQ(sop.effect_input_count, op->EffectInputCount()); | 83 EXPECT_EQ(sop.effect_input_count, op->EffectInputCount()); |
| 81 EXPECT_EQ(sop.control_input_count, op->ControlInputCount()); | 84 EXPECT_EQ(sop.control_input_count, op->ControlInputCount()); |
| 82 EXPECT_EQ( | 85 EXPECT_EQ( |
| 83 sop.value_input_count + sop.effect_input_count + sop.control_input_count, | 86 sop.value_input_count + sop.effect_input_count + sop.control_input_count, |
| 84 OperatorProperties::GetTotalInputCount(op)); | 87 OperatorProperties::GetTotalInputCount(op)); |
| 85 | 88 |
| 86 EXPECT_EQ(0, op->ValueOutputCount()); | 89 EXPECT_EQ(sop.value_output_count, op->ValueOutputCount()); |
| 87 EXPECT_EQ(sop.effect_output_count, op->EffectOutputCount()); | 90 EXPECT_EQ(sop.effect_output_count, op->EffectOutputCount()); |
| 88 EXPECT_EQ(sop.control_output_count, op->ControlOutputCount()); | 91 EXPECT_EQ(sop.control_output_count, op->ControlOutputCount()); |
| 89 } | 92 } |
| 90 | 93 |
| 91 | 94 |
| 92 TEST_P(CommonSharedOperatorTest, OpcodeIsCorrect) { | 95 TEST_P(CommonSharedOperatorTest, OpcodeIsCorrect) { |
| 93 CommonOperatorBuilder common(zone()); | 96 CommonOperatorBuilder common(zone()); |
| 94 const SharedOperator& sop = GetParam(); | 97 const SharedOperator& sop = GetParam(); |
| 95 const Operator* op = (common.*sop.constructor)(); | 98 const Operator* op = (common.*sop.constructor)(); |
| 96 EXPECT_EQ(sop.opcode, op->opcode()); | 99 EXPECT_EQ(sop.opcode, op->opcode()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 EXPECT_EQ(arguments + 1, OperatorProperties::GetTotalInputCount(op)); | 287 EXPECT_EQ(arguments + 1, OperatorProperties::GetTotalInputCount(op)); |
| 285 EXPECT_EQ(0, op->ControlOutputCount()); | 288 EXPECT_EQ(0, op->ControlOutputCount()); |
| 286 EXPECT_EQ(0, op->EffectOutputCount()); | 289 EXPECT_EQ(0, op->EffectOutputCount()); |
| 287 EXPECT_EQ(1, op->ValueOutputCount()); | 290 EXPECT_EQ(1, op->ValueOutputCount()); |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 | 293 |
| 291 } // namespace compiler | 294 } // namespace compiler |
| 292 } // namespace internal | 295 } // namespace internal |
| 293 } // namespace v8 | 296 } // namespace v8 |
| OLD | NEW |