V8 Project
simplified-operator-unittest.cc
Go to the documentation of this file.
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 
6 
8 #include "src/test/test-utils.h"
9 
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13 
14 // TODO(bmeurer): Drop once we use std::ostream instead of our OStream.
15 inline std::ostream& operator<<(std::ostream& os, const ElementAccess& access) {
16  OStringStream ost;
17  ost << access;
18  return os << ost.c_str();
19 }
20 
21 
22 // -----------------------------------------------------------------------------
23 // Pure operators.
24 
25 
26 namespace {
27 
28 struct PureOperator {
29  const Operator* (SimplifiedOperatorBuilder::*constructor)();
33 };
34 
35 
36 std::ostream& operator<<(std::ostream& os, const PureOperator& pop) {
37  return os << IrOpcode::Mnemonic(pop.opcode);
38 }
39 
40 
42 #define PURE(Name, properties, input_count) \
43  { \
44  &SimplifiedOperatorBuilder::Name, IrOpcode::k##Name, \
45  Operator::kPure | properties, input_count \
46  }
47  PURE(BooleanNot, Operator::kNoProperties, 1),
48  PURE(NumberEqual, Operator::kCommutative, 2),
49  PURE(NumberLessThan, Operator::kNoProperties, 2),
50  PURE(NumberLessThanOrEqual, Operator::kNoProperties, 2),
51  PURE(NumberAdd, Operator::kCommutative, 2),
52  PURE(NumberSubtract, Operator::kNoProperties, 2),
53  PURE(NumberMultiply, Operator::kCommutative, 2),
54  PURE(NumberDivide, Operator::kNoProperties, 2),
55  PURE(NumberModulus, Operator::kNoProperties, 2),
58  PURE(StringEqual, Operator::kCommutative, 2),
59  PURE(StringLessThan, Operator::kNoProperties, 2),
60  PURE(StringLessThanOrEqual, Operator::kNoProperties, 2),
61  PURE(StringAdd, Operator::kNoProperties, 2),
62  PURE(ChangeTaggedToInt32, Operator::kNoProperties, 1),
63  PURE(ChangeTaggedToUint32, Operator::kNoProperties, 1),
64  PURE(ChangeTaggedToFloat64, Operator::kNoProperties, 1),
65  PURE(ChangeInt32ToTagged, Operator::kNoProperties, 1),
66  PURE(ChangeUint32ToTagged, Operator::kNoProperties, 1),
67  PURE(ChangeFloat64ToTagged, Operator::kNoProperties, 1),
68  PURE(ChangeBoolToBit, Operator::kNoProperties, 1),
69  PURE(ChangeBitToBool, Operator::kNoProperties, 1)
70 #undef PURE
71 };
72 
73 } // namespace
74 
75 
77  : public TestWithZone,
78  public ::testing::WithParamInterface<PureOperator> {};
79 
80 
81 TEST_P(SimplifiedPureOperatorTest, InstancesAreGloballyShared) {
82  const PureOperator& pop = GetParam();
83  SimplifiedOperatorBuilder simplified1(zone());
84  SimplifiedOperatorBuilder simplified2(zone());
85  EXPECT_EQ((simplified1.*pop.constructor)(), (simplified2.*pop.constructor)());
86 }
87 
88 
89 TEST_P(SimplifiedPureOperatorTest, NumberOfInputsAndOutputs) {
90  SimplifiedOperatorBuilder simplified(zone());
91  const PureOperator& pop = GetParam();
92  const Operator* op = (simplified.*pop.constructor)();
93 
94  EXPECT_EQ(pop.value_input_count, OperatorProperties::GetValueInputCount(op));
97  EXPECT_EQ(pop.value_input_count, OperatorProperties::GetTotalInputCount(op));
98 
102 }
103 
104 
106  SimplifiedOperatorBuilder simplified(zone());
107  const PureOperator& pop = GetParam();
108  const Operator* op = (simplified.*pop.constructor)();
109  EXPECT_EQ(pop.opcode, op->opcode());
110 }
111 
112 
114  SimplifiedOperatorBuilder simplified(zone());
115  const PureOperator& pop = GetParam();
116  const Operator* op = (simplified.*pop.constructor)();
117  EXPECT_EQ(pop.properties, op->properties() & pop.properties);
118 }
119 
121  ::testing::ValuesIn(kPureOperators));
122 
123 
124 // -----------------------------------------------------------------------------
125 // Element access operators.
126 
127 namespace {
128 
132  kMachInt8},
134  kMachInt16},
136  kMachInt32},
138  kMachUint8},
140  kMachUint16},
142  kMachUint32},
143  {kUntaggedBase, 0, Type::Signed32(), kMachInt8},
144  {kUntaggedBase, 0, Type::Unsigned32(), kMachUint8},
145  {kUntaggedBase, 0, Type::Signed32(), kMachInt16},
146  {kUntaggedBase, 0, Type::Unsigned32(), kMachUint16},
147  {kUntaggedBase, 0, Type::Signed32(), kMachInt32},
148  {kUntaggedBase, 0, Type::Unsigned32(), kMachUint32},
149  {kUntaggedBase, 0, Type::Number(), kRepFloat32},
150  {kUntaggedBase, 0, Type::Number(), kRepFloat64},
151  {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Signed32(),
152  kMachInt8},
153  {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Unsigned32(),
154  kMachUint8},
155  {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Signed32(),
156  kMachInt16},
157  {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Unsigned32(),
158  kMachUint16},
159  {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Signed32(),
160  kMachInt32},
161  {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Unsigned32(),
162  kMachUint32},
164  kRepFloat32},
166  kRepFloat64}};
167 
168 } // namespace
169 
170 
172  : public TestWithZone,
173  public ::testing::WithParamInterface<ElementAccess> {};
174 
175 
177  SimplifiedOperatorBuilder simplified(zone());
178  const ElementAccess& access = GetParam();
179  const Operator* op = simplified.LoadElement(access);
180 
181  EXPECT_EQ(IrOpcode::kLoadElement, op->opcode());
183  EXPECT_EQ(access, ElementAccessOf(op));
184 
185  EXPECT_EQ(3, OperatorProperties::GetValueInputCount(op));
186  EXPECT_EQ(1, OperatorProperties::GetEffectInputCount(op));
188  EXPECT_EQ(4, OperatorProperties::GetTotalInputCount(op));
189 
190  EXPECT_EQ(1, OperatorProperties::GetValueOutputCount(op));
193 }
194 
195 
197  SimplifiedOperatorBuilder simplified(zone());
198  const ElementAccess& access = GetParam();
199  const Operator* op = simplified.StoreElement(access);
200 
201  EXPECT_EQ(IrOpcode::kStoreElement, op->opcode());
202  EXPECT_EQ(Operator::kNoRead | Operator::kNoThrow, op->properties());
203  EXPECT_EQ(access, ElementAccessOf(op));
204 
205  EXPECT_EQ(4, OperatorProperties::GetValueInputCount(op));
206  EXPECT_EQ(1, OperatorProperties::GetEffectInputCount(op));
208  EXPECT_EQ(6, OperatorProperties::GetTotalInputCount(op));
209 
210  EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op));
213 }
214 
215 
216 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest,
218  ::testing::ValuesIn(kElementAccesses));
219 
220 } // namespace compiler
221 } // namespace internal
222 } // namespace v8
static const int kHeaderSize
Definition: objects.h:2393
static const int kDataOffset
Definition: objects.h:4716
const char * c_str() const
Definition: ostreams.h:84
static const char * Mnemonic(Value val)
Definition: opcodes.h:256
static int GetTotalInputCount(const Operator *op)
static int GetEffectInputCount(const Operator *op)
static int GetEffectOutputCount(const Operator *op)
static int GetValueInputCount(const Operator *op)
static int GetControlOutputCount(const Operator *op)
static int GetValueOutputCount(const Operator *op)
static int GetControlInputCount(const Operator *op)
Properties properties() const
Definition: operator.h:84
base::Flags< Property, uint8_t > Properties
Definition: operator.h:48
const ElementAccess & ElementAccessOf(const Operator *op)
std::ostream & operator<<(std::ostream &os, const MachineType &type)
TEST_P(InstructionSelectorDPITest, Parameters)
INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorDPITest, ::testing::ValuesIn(kDPIs))
static const int kNonHeapObjectHeaderSize
int32_t NumberToInt32(Object *number)
Definition: conversions.h:189
const int kHeapObjectTag
Definition: v8.h:5737
uint32_t NumberToUint32(Object *number)
Definition: conversions.h:195
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define PURE(Name, properties, input_count)