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/code-stubs.h" | 5 #include "src/code-stubs.h" |
6 #include "src/compiler/change-lowering.h" | 6 #include "src/compiler/change-lowering.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/simplified-operator.h" | 10 #include "src/compiler/simplified-operator.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 TARGET_TEST_P(ChangeLoweringCommonTest, ChangeTaggedToUint32WithTaggedPointer) { | 170 TARGET_TEST_P(ChangeLoweringCommonTest, ChangeTaggedToUint32WithTaggedPointer) { |
171 Node* value = Parameter(Type::TaggedPointer()); | 171 Node* value = Parameter(Type::TaggedPointer()); |
172 Reduction r = | 172 Reduction r = |
173 Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(), value)); | 173 Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(), value)); |
174 ASSERT_TRUE(r.Changed()); | 174 ASSERT_TRUE(r.Changed()); |
175 EXPECT_THAT(r.replacement(), IsChangeFloat64ToUint32( | 175 EXPECT_THAT(r.replacement(), IsChangeFloat64ToUint32( |
176 IsLoadHeapNumber(value, graph()->start()))); | 176 IsLoadHeapNumber(value, graph()->start()))); |
177 } | 177 } |
178 | 178 |
179 | 179 |
| 180 TARGET_TEST_P(ChangeLoweringCommonTest, StoreFieldSmi) { |
| 181 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
| 182 Handle<Name>::null(), Type::Any(), kMachAnyTagged}; |
| 183 Node* p0 = Parameter(Type::TaggedPointer()); |
| 184 Node* p1 = Parameter(Type::TaggedSigned()); |
| 185 Node* store = graph()->NewNode(simplified()->StoreField(access), p0, p1, |
| 186 graph()->start(), graph()->start()); |
| 187 Reduction r = Reduce(store); |
| 188 |
| 189 ASSERT_TRUE(r.Changed()); |
| 190 EXPECT_THAT(r.replacement(), |
| 191 IsStore(StoreRepresentation(kMachAnyTagged, kNoWriteBarrier), p0, |
| 192 IsIntPtrConstant(access.offset - access.tag()), p1, |
| 193 graph()->start(), graph()->start())); |
| 194 } |
| 195 |
| 196 |
| 197 TARGET_TEST_P(ChangeLoweringCommonTest, StoreFieldTagged) { |
| 198 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
| 199 Handle<Name>::null(), Type::Any(), kMachAnyTagged}; |
| 200 Node* p0 = Parameter(Type::TaggedPointer()); |
| 201 Node* p1 = Parameter(Type::Tagged()); |
| 202 Node* store = graph()->NewNode(simplified()->StoreField(access), p0, p1, |
| 203 graph()->start(), graph()->start()); |
| 204 Reduction r = Reduce(store); |
| 205 |
| 206 ASSERT_TRUE(r.Changed()); |
| 207 EXPECT_THAT(r.replacement(), |
| 208 IsStore(StoreRepresentation(kMachAnyTagged, kFullWriteBarrier), |
| 209 p0, IsIntPtrConstant(access.offset - access.tag()), p1, |
| 210 graph()->start(), graph()->start())); |
| 211 } |
| 212 |
| 213 |
| 214 TARGET_TEST_P(ChangeLoweringCommonTest, LoadField) { |
| 215 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
| 216 Handle<Name>::null(), Type::Any(), kMachAnyTagged}; |
| 217 Node* p0 = Parameter(Type::TaggedPointer()); |
| 218 Node* load = graph()->NewNode(simplified()->LoadField(access), p0, |
| 219 graph()->start(), graph()->start()); |
| 220 Reduction r = Reduce(load); |
| 221 |
| 222 ASSERT_TRUE(r.Changed()); |
| 223 Matcher<Node*> index_match = IsIntPtrConstant(access.offset - access.tag()); |
| 224 EXPECT_THAT( |
| 225 r.replacement(), |
| 226 IsLoad(kMachAnyTagged, p0, IsIntPtrConstant(access.offset - access.tag()), |
| 227 graph()->start(), graph()->start())); |
| 228 } |
| 229 |
| 230 |
| 231 TARGET_TEST_P(ChangeLoweringCommonTest, StoreElementTagged) { |
| 232 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), |
| 233 kMachAnyTagged}; |
| 234 Node* p0 = Parameter(Type::TaggedPointer()); |
| 235 Node* p1 = Parameter(Type::Signed32()); |
| 236 Node* p2 = Parameter(Type::Tagged()); |
| 237 Node* store = graph()->NewNode(simplified()->StoreElement(access), p0, p1, p2, |
| 238 graph()->start(), graph()->start()); |
| 239 Reduction r = Reduce(store); |
| 240 |
| 241 const int element_size_shift = ElementSizeLog2Of(access.machine_type); |
| 242 ASSERT_TRUE(r.Changed()); |
| 243 Matcher<Node*> index_match = |
| 244 IsInt32Add(IsWord32Shl(p1, IsInt32Constant(element_size_shift)), |
| 245 IsInt32Constant(access.header_size - access.tag())); |
| 246 if (!Is32()) { |
| 247 index_match = IsChangeUint32ToUint64(index_match); |
| 248 } |
| 249 |
| 250 EXPECT_THAT(r.replacement(), |
| 251 IsStore(StoreRepresentation(kMachAnyTagged, kFullWriteBarrier), |
| 252 p0, index_match, p2, graph()->start(), graph()->start())); |
| 253 } |
| 254 |
| 255 |
| 256 TARGET_TEST_P(ChangeLoweringCommonTest, StoreElementUint8) { |
| 257 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
| 258 Type::Signed32(), kMachUint8}; |
| 259 Node* p0 = Parameter(Type::TaggedPointer()); |
| 260 Node* p1 = Parameter(Type::Signed32()); |
| 261 Node* p2 = Parameter(Type::Signed32()); |
| 262 Node* store = graph()->NewNode(simplified()->StoreElement(access), p0, p1, p2, |
| 263 graph()->start(), graph()->start()); |
| 264 Reduction r = Reduce(store); |
| 265 |
| 266 ASSERT_TRUE(r.Changed()); |
| 267 Matcher<Node*> index_match = |
| 268 IsInt32Add(p1, IsInt32Constant(access.header_size - access.tag())); |
| 269 if (!Is32()) { |
| 270 index_match = IsChangeUint32ToUint64(index_match); |
| 271 } |
| 272 |
| 273 EXPECT_THAT(r.replacement(), |
| 274 IsStore(StoreRepresentation(kMachUint8, kNoWriteBarrier), p0, |
| 275 index_match, p2, graph()->start(), graph()->start())); |
| 276 } |
| 277 |
| 278 |
| 279 TARGET_TEST_P(ChangeLoweringCommonTest, LoadElementTagged) { |
| 280 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), |
| 281 kMachAnyTagged}; |
| 282 Node* p0 = Parameter(Type::TaggedPointer()); |
| 283 Node* p1 = Parameter(Type::Signed32()); |
| 284 Node* load = graph()->NewNode(simplified()->LoadElement(access), p0, p1, |
| 285 graph()->start(), graph()->start()); |
| 286 Reduction r = Reduce(load); |
| 287 |
| 288 const int element_size_shift = ElementSizeLog2Of(access.machine_type); |
| 289 ASSERT_TRUE(r.Changed()); |
| 290 Matcher<Node*> index_match = |
| 291 IsInt32Add(IsWord32Shl(p1, IsInt32Constant(element_size_shift)), |
| 292 IsInt32Constant(access.header_size - access.tag())); |
| 293 if (!Is32()) { |
| 294 index_match = IsChangeUint32ToUint64(index_match); |
| 295 } |
| 296 |
| 297 EXPECT_THAT(r.replacement(), IsLoad(kMachAnyTagged, p0, index_match, |
| 298 graph()->start(), graph()->start())); |
| 299 } |
| 300 |
| 301 |
| 302 TARGET_TEST_P(ChangeLoweringCommonTest, LoadElementInt8) { |
| 303 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
| 304 Type::Signed32(), kMachInt8}; |
| 305 Node* p0 = Parameter(Type::TaggedPointer()); |
| 306 Node* p1 = Parameter(Type::Signed32()); |
| 307 Node* load = graph()->NewNode(simplified()->LoadElement(access), p0, p1, |
| 308 graph()->start(), graph()->start()); |
| 309 Reduction r = Reduce(load); |
| 310 |
| 311 ASSERT_TRUE(r.Changed()); |
| 312 Matcher<Node*> index_match = |
| 313 IsInt32Add(p1, IsInt32Constant(access.header_size - access.tag())); |
| 314 if (!Is32()) { |
| 315 index_match = IsChangeUint32ToUint64(index_match); |
| 316 } |
| 317 |
| 318 EXPECT_THAT(r.replacement(), IsLoad(kMachInt8, p0, index_match, |
| 319 graph()->start(), graph()->start())); |
| 320 } |
| 321 |
| 322 |
| 323 TARGET_TEST_P(ChangeLoweringCommonTest, Allocate) { |
| 324 Node* p0 = Parameter(Type::Signed32()); |
| 325 Node* alloc = graph()->NewNode(simplified()->Allocate(TENURED), p0, |
| 326 graph()->start(), graph()->start()); |
| 327 Reduction r = Reduce(alloc); |
| 328 |
| 329 // Only check that we lowered, but do not specify the exact form since |
| 330 // this is subject to change. |
| 331 ASSERT_TRUE(r.Changed()); |
| 332 } |
| 333 |
| 334 |
180 INSTANTIATE_TEST_CASE_P(ChangeLoweringTest, ChangeLoweringCommonTest, | 335 INSTANTIATE_TEST_CASE_P(ChangeLoweringTest, ChangeLoweringCommonTest, |
181 ::testing::Values(kRepWord32, kRepWord64)); | 336 ::testing::Values(kRepWord32, kRepWord64)); |
182 | 337 |
183 | 338 |
184 // ----------------------------------------------------------------------------- | 339 // ----------------------------------------------------------------------------- |
185 // 32-bit | 340 // 32-bit |
186 | 341 |
187 | 342 |
188 class ChangeLowering32Test : public ChangeLoweringTest { | 343 class ChangeLowering32Test : public ChangeLoweringTest { |
189 public: | 344 public: |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 CaptureEq(&branch), | 596 CaptureEq(&branch), |
442 IsBranch(IsUint32LessThanOrEqual( | 597 IsBranch(IsUint32LessThanOrEqual( |
443 value, IsInt32Constant(Smi::kMaxValue)), | 598 value, IsInt32Constant(Smi::kMaxValue)), |
444 graph()->start()))), | 599 graph()->start()))), |
445 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 600 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
446 } | 601 } |
447 | 602 |
448 } // namespace compiler | 603 } // namespace compiler |
449 } // namespace internal | 604 } // namespace internal |
450 } // namespace v8 | 605 } // namespace v8 |
OLD | NEW |