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 "src/compiler/simplified-operator.h" | 5 #include "src/compiler/simplified-operator.h" |
6 | 6 |
7 #include "src/compiler/operator-properties-inl.h" | 7 #include "src/compiler/operator-properties-inl.h" |
8 #include "src/test/test-utils.h" | 8 #include "src/test/test-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace compiler { | 12 namespace compiler { |
13 | 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 |
14 // ----------------------------------------------------------------------------- | 22 // ----------------------------------------------------------------------------- |
15 // Pure operators. | 23 // Pure operators. |
16 | 24 |
17 | 25 |
18 namespace { | 26 namespace { |
19 | 27 |
20 struct PureOperator { | 28 struct PureOperator { |
21 const Operator* (SimplifiedOperatorBuilder::*constructor)(); | 29 const Operator* (SimplifiedOperatorBuilder::*constructor)(); |
22 IrOpcode::Value opcode; | 30 IrOpcode::Value opcode; |
23 Operator::Properties properties; | 31 Operator::Properties properties; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 TEST_P(SimplifiedPureOperatorTest, Properties) { | 113 TEST_P(SimplifiedPureOperatorTest, Properties) { |
106 SimplifiedOperatorBuilder simplified(zone()); | 114 SimplifiedOperatorBuilder simplified(zone()); |
107 const PureOperator& pop = GetParam(); | 115 const PureOperator& pop = GetParam(); |
108 const Operator* op = (simplified.*pop.constructor)(); | 116 const Operator* op = (simplified.*pop.constructor)(); |
109 EXPECT_EQ(pop.properties, op->properties() & pop.properties); | 117 EXPECT_EQ(pop.properties, op->properties() & pop.properties); |
110 } | 118 } |
111 | 119 |
112 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest, | 120 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest, |
113 ::testing::ValuesIn(kPureOperators)); | 121 ::testing::ValuesIn(kPureOperators)); |
114 | 122 |
| 123 |
| 124 // ----------------------------------------------------------------------------- |
| 125 // Element access operators. |
| 126 |
| 127 namespace { |
| 128 |
| 129 const ElementAccess kElementAccesses[] = { |
| 130 {kTaggedBase, FixedArray::kHeaderSize, Type::Any(), kMachAnyTagged}, |
| 131 {kUntaggedBase, kNonHeapObjectHeaderSize - kHeapObjectTag, Type::Any(), |
| 132 kMachInt8}, |
| 133 {kUntaggedBase, kNonHeapObjectHeaderSize - kHeapObjectTag, Type::Any(), |
| 134 kMachInt16}, |
| 135 {kUntaggedBase, kNonHeapObjectHeaderSize - kHeapObjectTag, Type::Any(), |
| 136 kMachInt32}, |
| 137 {kUntaggedBase, kNonHeapObjectHeaderSize - kHeapObjectTag, Type::Any(), |
| 138 kMachUint8}, |
| 139 {kUntaggedBase, kNonHeapObjectHeaderSize - kHeapObjectTag, Type::Any(), |
| 140 kMachUint16}, |
| 141 {kUntaggedBase, kNonHeapObjectHeaderSize - kHeapObjectTag, Type::Any(), |
| 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}, |
| 163 {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Number(), |
| 164 kRepFloat32}, |
| 165 {kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Number(), |
| 166 kRepFloat64}}; |
| 167 |
| 168 } // namespace |
| 169 |
| 170 |
| 171 class SimplifiedElementAccessOperatorTest |
| 172 : public TestWithZone, |
| 173 public ::testing::WithParamInterface<ElementAccess> {}; |
| 174 |
| 175 |
| 176 TEST_P(SimplifiedElementAccessOperatorTest, LoadElement) { |
| 177 SimplifiedOperatorBuilder simplified(zone()); |
| 178 const ElementAccess& access = GetParam(); |
| 179 const Operator* op = simplified.LoadElement(access); |
| 180 |
| 181 EXPECT_EQ(IrOpcode::kLoadElement, op->opcode()); |
| 182 EXPECT_EQ(Operator::kNoThrow | Operator::kNoWrite, op->properties()); |
| 183 EXPECT_EQ(access, ElementAccessOf(op)); |
| 184 |
| 185 EXPECT_EQ(3, OperatorProperties::GetValueInputCount(op)); |
| 186 EXPECT_EQ(1, OperatorProperties::GetEffectInputCount(op)); |
| 187 EXPECT_EQ(0, OperatorProperties::GetControlInputCount(op)); |
| 188 EXPECT_EQ(4, OperatorProperties::GetTotalInputCount(op)); |
| 189 |
| 190 EXPECT_EQ(1, OperatorProperties::GetValueOutputCount(op)); |
| 191 EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op)); |
| 192 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op)); |
| 193 } |
| 194 |
| 195 |
| 196 TEST_P(SimplifiedElementAccessOperatorTest, StoreElement) { |
| 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)); |
| 207 EXPECT_EQ(1, OperatorProperties::GetControlInputCount(op)); |
| 208 EXPECT_EQ(6, OperatorProperties::GetTotalInputCount(op)); |
| 209 |
| 210 EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op)); |
| 211 EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op)); |
| 212 EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op)); |
| 213 } |
| 214 |
| 215 |
| 216 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, |
| 217 SimplifiedElementAccessOperatorTest, |
| 218 ::testing::ValuesIn(kElementAccesses)); |
| 219 |
115 } // namespace compiler | 220 } // namespace compiler |
116 } // namespace internal | 221 } // namespace internal |
117 } // namespace v8 | 222 } // namespace v8 |
OLD | NEW |