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

Side by Side Diff: src/compiler/common-operator-unittest.cc

Issue 565753004: [turbofan] Some common operators are globally shared singletons. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes2 Created 6 years, 3 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 | Annotate | Revision Log
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/common-operator.h" 5 #include "src/compiler/common-operator.h"
6
6 #include "src/compiler/operator-properties-inl.h" 7 #include "src/compiler/operator-properties-inl.h"
7 #include "src/test/test-utils.h" 8 #include "src/test/test-utils.h"
8 9
9 namespace v8 { 10 namespace v8 {
10 namespace internal { 11 namespace internal {
11 namespace compiler { 12 namespace compiler {
12 13
14
15 // -----------------------------------------------------------------------------
16 // Shared operators.
17
18
19 namespace {
20
21 struct SharedOperator {
22 const Operator* (CommonOperatorBuilder::*constructor)();
23 IrOpcode::Value opcode;
24 Operator::Properties properties;
25 int value_input_count;
26 int effect_input_count;
27 int control_input_count;
28 int effect_output_count;
29 int control_output_count;
30 };
31
32
33 std::ostream& operator<<(std::ostream& os, const SharedOperator& fop) {
34 return os << IrOpcode::Mnemonic(fop.opcode);
35 }
36
37
38 const SharedOperator kSharedOperators[] = {
39 #define SHARED(Name, properties, value_input_count, effect_input_count, \
40 control_input_count, effect_output_count, control_output_count) \
41 { \
42 &CommonOperatorBuilder::Name, IrOpcode::k##Name, properties, \
43 value_input_count, effect_input_count, control_input_count, \
44 effect_output_count, control_output_count \
45 }
46 SHARED(Dead, Operator::kFoldable, 0, 0, 0, 0, 1),
47 SHARED(End, Operator::kFoldable, 0, 0, 1, 0, 0),
48 SHARED(Branch, Operator::kFoldable, 1, 0, 1, 0, 2),
49 SHARED(IfTrue, Operator::kFoldable, 0, 0, 1, 0, 1),
50 SHARED(IfFalse, Operator::kFoldable, 0, 0, 1, 0, 1),
51 SHARED(Throw, Operator::kFoldable, 1, 0, 1, 0, 1),
52 SHARED(Return, Operator::kNoProperties, 1, 1, 1, 1, 1),
53 SHARED(ControlEffect, Operator::kPure, 0, 0, 1, 1, 0)
54 #undef SHARED
55 };
56
57
58 class CommonSharedOperatorTest
59 : public TestWithZone,
60 public ::testing::WithParamInterface<SharedOperator> {};
61
62 } // namespace
63
64
65 TEST_P(CommonSharedOperatorTest, InstancesAreGloballyShared) {
66 const SharedOperator& sop = GetParam();
67 CommonOperatorBuilder common1(zone());
68 CommonOperatorBuilder common2(zone());
69 EXPECT_EQ((common1.*sop.constructor)(), (common2.*sop.constructor)());
70 }
71
72
73 TEST_P(CommonSharedOperatorTest, NumberOfInputsAndOutputs) {
74 CommonOperatorBuilder common(zone());
75 const SharedOperator& sop = GetParam();
76 const Operator* op = (common.*sop.constructor)();
77
78 EXPECT_EQ(sop.value_input_count, OperatorProperties::GetValueInputCount(op));
79 EXPECT_EQ(sop.effect_input_count,
80 OperatorProperties::GetEffectInputCount(op));
81 EXPECT_EQ(sop.control_input_count,
82 OperatorProperties::GetControlInputCount(op));
83 EXPECT_EQ(
84 sop.value_input_count + sop.effect_input_count + sop.control_input_count,
85 OperatorProperties::GetTotalInputCount(op));
86
87 EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op));
88 EXPECT_EQ(sop.effect_output_count,
89 OperatorProperties::GetEffectOutputCount(op));
90 EXPECT_EQ(sop.control_output_count,
91 OperatorProperties::GetControlOutputCount(op));
92 }
93
94
95 TEST_P(CommonSharedOperatorTest, OpcodeIsCorrect) {
96 CommonOperatorBuilder common(zone());
97 const SharedOperator& sop = GetParam();
98 const Operator* op = (common.*sop.constructor)();
99 EXPECT_EQ(sop.opcode, op->opcode());
100 }
101
102
103 TEST_P(CommonSharedOperatorTest, Properties) {
104 CommonOperatorBuilder common(zone());
105 const SharedOperator& sop = GetParam();
106 const Operator* op = (common.*sop.constructor)();
107 EXPECT_EQ(sop.properties, op->properties());
108 }
109
110
111 INSTANTIATE_TEST_CASE_P(CommonOperatorTest, CommonSharedOperatorTest,
112 ::testing::ValuesIn(kSharedOperators));
113
114
115 // -----------------------------------------------------------------------------
116 // Other operators.
117
118
13 namespace { 119 namespace {
14 120
15 class CommonOperatorTest : public TestWithZone { 121 class CommonOperatorTest : public TestWithZone {
16 public: 122 public:
17 CommonOperatorTest() : common_(zone()) {} 123 CommonOperatorTest() : common_(zone()) {}
18 virtual ~CommonOperatorTest() {} 124 virtual ~CommonOperatorTest() {}
19 125
20 CommonOperatorBuilder* common() { return &common_; } 126 CommonOperatorBuilder* common() { return &common_; }
21 127
22 private: 128 private:
23 CommonOperatorBuilder common_; 129 CommonOperatorBuilder common_;
24 }; 130 };
25 131
26 132
27 const int kArguments[] = {1, 5, 6, 42, 100, 10000, kMaxInt}; 133 const int kArguments[] = {1, 5, 6, 42, 100, 10000, kMaxInt};
28 134
29 } // namespace 135 } // namespace
30 136
31 137
32 TEST_F(CommonOperatorTest, ControlEffect) {
33 const Operator* op = common()->ControlEffect();
34 EXPECT_EQ(1, OperatorProperties::GetControlInputCount(op));
35 EXPECT_EQ(1, OperatorProperties::GetTotalInputCount(op));
36 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op));
37 EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op));
38 EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op));
39 }
40
41
42 TEST_F(CommonOperatorTest, ValueEffect) { 138 TEST_F(CommonOperatorTest, ValueEffect) {
43 TRACED_FOREACH(int, arguments, kArguments) { 139 TRACED_FOREACH(int, arguments, kArguments) {
44 const Operator* op = common()->ValueEffect(arguments); 140 const Operator* op = common()->ValueEffect(arguments);
45 EXPECT_EQ(arguments, OperatorProperties::GetValueInputCount(op)); 141 EXPECT_EQ(arguments, OperatorProperties::GetValueInputCount(op));
46 EXPECT_EQ(arguments, OperatorProperties::GetTotalInputCount(op)); 142 EXPECT_EQ(arguments, OperatorProperties::GetTotalInputCount(op));
47 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op)); 143 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op));
48 EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op)); 144 EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op));
49 EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op)); 145 EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op));
50 } 146 }
51 } 147 }
52 148
53 149
54 TEST_F(CommonOperatorTest, Finish) { 150 TEST_F(CommonOperatorTest, Finish) {
55 TRACED_FOREACH(int, arguments, kArguments) { 151 TRACED_FOREACH(int, arguments, kArguments) {
56 const Operator* op = common()->Finish(arguments); 152 const Operator* op = common()->Finish(arguments);
57 EXPECT_EQ(1, OperatorProperties::GetValueInputCount(op)); 153 EXPECT_EQ(1, OperatorProperties::GetValueInputCount(op));
58 EXPECT_EQ(arguments, OperatorProperties::GetEffectInputCount(op)); 154 EXPECT_EQ(arguments, OperatorProperties::GetEffectInputCount(op));
59 EXPECT_EQ(arguments + 1, OperatorProperties::GetTotalInputCount(op)); 155 EXPECT_EQ(arguments + 1, OperatorProperties::GetTotalInputCount(op));
60 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op)); 156 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op));
61 EXPECT_EQ(0, OperatorProperties::GetEffectOutputCount(op)); 157 EXPECT_EQ(0, OperatorProperties::GetEffectOutputCount(op));
62 EXPECT_EQ(1, OperatorProperties::GetValueOutputCount(op)); 158 EXPECT_EQ(1, OperatorProperties::GetValueOutputCount(op));
63 } 159 }
64 } 160 }
65 161
66 } // namespace compiler 162 } // namespace compiler
67 } // namespace internal 163 } // namespace internal
68 } // namespace v8 164 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698