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

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

Issue 613683002: [turbofan] Some javascript operators are globally shared singletons. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 6 years, 2 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
« no previous file with comments | « src/compiler/js-operator.cc ('k') | src/compiler/machine-operator-reducer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/js-operator.h"
6 #include "src/compiler/operator-properties-inl.h"
7 #include "src/test/test-utils.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace compiler {
12
13 // -----------------------------------------------------------------------------
14 // Shared operators.
15
16 namespace {
17
18 struct SharedOperator {
19 const Operator* (JSOperatorBuilder::*constructor)();
20 IrOpcode::Value opcode;
21 Operator::Properties properties;
22 int value_input_count;
23 int frame_state_input_count;
24 int effect_input_count;
25 int control_input_count;
26 int value_output_count;
27 int effect_output_count;
28 };
29
30
31 std::ostream& operator<<(std::ostream& os, const SharedOperator& sop) {
32 return os << IrOpcode::Mnemonic(sop.opcode);
33 }
34
35
36 const SharedOperator kSharedOperators[] = {
37 #define SHARED(Name, properties, value_input_count, frame_state_input_count, \
38 effect_input_count, control_input_count, value_output_count, \
39 effect_output_count) \
40 { \
41 &JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \
42 value_input_count, frame_state_input_count, effect_input_count, \
43 control_input_count, value_output_count, effect_output_count \
44 }
45 SHARED(Equal, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
46 SHARED(NotEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
47 SHARED(StrictEqual, Operator::kPure, 2, 0, 0, 0, 1, 0),
48 SHARED(StrictNotEqual, Operator::kPure, 2, 0, 0, 0, 1, 0),
49 SHARED(LessThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
50 SHARED(GreaterThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
51 SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
52 SHARED(GreaterThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
53 SHARED(BitwiseOr, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
54 SHARED(BitwiseXor, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
55 SHARED(BitwiseAnd, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
56 SHARED(ShiftLeft, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
57 SHARED(ShiftRight, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
58 SHARED(ShiftRightLogical, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
59 SHARED(Add, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
60 SHARED(Subtract, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
61 SHARED(Multiply, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
62 SHARED(Divide, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
63 SHARED(Modulus, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
64 SHARED(UnaryNot, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
65 SHARED(ToBoolean, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
66 SHARED(ToNumber, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
67 SHARED(ToString, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
68 SHARED(ToName, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
69 SHARED(ToObject, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
70 SHARED(Yield, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
71 SHARED(Create, Operator::kEliminatable, 0, 0, 1, 0, 1, 1),
72 SHARED(LoadProperty, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
73 SHARED(HasProperty, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
74 SHARED(TypeOf, Operator::kPure, 1, 0, 0, 0, 1, 0),
75 SHARED(InstanceOf, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
76 SHARED(Debugger, Operator::kNoProperties, 0, 0, 1, 1, 0, 1),
77 SHARED(CreateFunctionContext, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
78 SHARED(CreateWithContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
79 SHARED(CreateBlockContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
80 SHARED(CreateModuleContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
81 SHARED(CreateGlobalContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1)
82 #undef SHARED
83 };
84
85 } // namespace
86
87
88 class JSSharedOperatorTest
89 : public TestWithZone,
90 public ::testing::WithParamInterface<SharedOperator> {};
91
92
93 TEST_P(JSSharedOperatorTest, InstancesAreGloballyShared) {
94 const SharedOperator& sop = GetParam();
95 JSOperatorBuilder javascript1(zone());
96 JSOperatorBuilder javascript2(zone());
97 EXPECT_EQ((javascript1.*sop.constructor)(), (javascript2.*sop.constructor)());
98 }
99
100
101 TEST_P(JSSharedOperatorTest, NumberOfInputsAndOutputs) {
102 JSOperatorBuilder javascript(zone());
103 const SharedOperator& sop = GetParam();
104 const Operator* op = (javascript.*sop.constructor)();
105
106 const int context_input_count = 1;
107 // TODO(jarin): Get rid of this hack.
108 const int frame_state_input_count =
109 FLAG_turbo_deoptimization ? sop.frame_state_input_count : 0;
110 EXPECT_EQ(sop.value_input_count, OperatorProperties::GetValueInputCount(op));
111 EXPECT_EQ(context_input_count, OperatorProperties::GetContextInputCount(op));
112 EXPECT_EQ(frame_state_input_count,
113 OperatorProperties::GetFrameStateInputCount(op));
114 EXPECT_EQ(sop.effect_input_count,
115 OperatorProperties::GetEffectInputCount(op));
116 EXPECT_EQ(sop.control_input_count,
117 OperatorProperties::GetControlInputCount(op));
118 EXPECT_EQ(sop.value_input_count + context_input_count +
119 frame_state_input_count + sop.effect_input_count +
120 sop.control_input_count,
121 OperatorProperties::GetTotalInputCount(op));
122
123 EXPECT_EQ(sop.value_output_count,
124 OperatorProperties::GetValueOutputCount(op));
125 EXPECT_EQ(sop.effect_output_count,
126 OperatorProperties::GetEffectOutputCount(op));
127 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op));
128 }
129
130
131 TEST_P(JSSharedOperatorTest, OpcodeIsCorrect) {
132 JSOperatorBuilder javascript(zone());
133 const SharedOperator& sop = GetParam();
134 const Operator* op = (javascript.*sop.constructor)();
135 EXPECT_EQ(sop.opcode, op->opcode());
136 }
137
138
139 TEST_P(JSSharedOperatorTest, Properties) {
140 JSOperatorBuilder javascript(zone());
141 const SharedOperator& sop = GetParam();
142 const Operator* op = (javascript.*sop.constructor)();
143 EXPECT_EQ(sop.properties, op->properties());
144 }
145
146
147 INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest,
148 ::testing::ValuesIn(kSharedOperators));
149
150 } // namespace compiler
151 } // namespace internal
152 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-operator.cc ('k') | src/compiler/machine-operator-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698