| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
| 6 #include "src/compiler/diamond.h" | 6 #include "src/compiler/diamond.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/js-intrinsic-lowering.h" | 8 #include "src/compiler/js-intrinsic-lowering.h" |
| 9 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
| 10 #include "src/types-inl.h" | 10 #include "src/types-inl.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace compiler { | 25 namespace compiler { |
| 26 | 26 |
| 27 class JSIntrinsicLoweringTest : public TypedGraphTest { | 27 class JSIntrinsicLoweringTest : public TypedGraphTest { |
| 28 public: | 28 public: |
| 29 JSIntrinsicLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} | 29 JSIntrinsicLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
| 30 ~JSIntrinsicLoweringTest() override {} | 30 ~JSIntrinsicLoweringTest() override {} |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = | 33 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
| 34 MachineOperatorBuilder::kNoFlags) { | 34 MachineOperatorBuilder::kNoFlags) { |
| 35 MachineOperatorBuilder machine(zone(), kMachPtr, flags); | 35 MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(), |
| 36 flags); |
| 36 SimplifiedOperatorBuilder simplified(zone()); | 37 SimplifiedOperatorBuilder simplified(zone()); |
| 37 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, | 38 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, |
| 38 &machine); | 39 &machine); |
| 39 // TODO(titzer): mock the GraphReducer here for better unit testing. | 40 // TODO(titzer): mock the GraphReducer here for better unit testing. |
| 40 GraphReducer graph_reducer(zone(), graph()); | 41 GraphReducer graph_reducer(zone(), graph()); |
| 41 JSIntrinsicLowering reducer(&graph_reducer, &jsgraph, | 42 JSIntrinsicLowering reducer(&graph_reducer, &jsgraph, |
| 42 JSIntrinsicLowering::kDeoptimizationEnabled); | 43 JSIntrinsicLowering::kDeoptimizationEnabled); |
| 43 return reducer.Reduce(node); | 44 return reducer.Reduce(node); |
| 44 } | 45 } |
| 45 | 46 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 Reduction const r = Reduce( | 142 Reduction const r = Reduce( |
| 142 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsArray, 1), | 143 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsArray, 1), |
| 143 input, context, effect, control)); | 144 input, context, effect, control)); |
| 144 ASSERT_TRUE(r.Changed()); | 145 ASSERT_TRUE(r.Changed()); |
| 145 | 146 |
| 146 Node* phi = r.replacement(); | 147 Node* phi = r.replacement(); |
| 147 Capture<Node*> branch, if_false; | 148 Capture<Node*> branch, if_false; |
| 148 EXPECT_THAT( | 149 EXPECT_THAT( |
| 149 phi, | 150 phi, |
| 150 IsPhi( | 151 IsPhi( |
| 151 static_cast<MachineType>(kTypeBool | kRepTagged), IsFalseConstant(), | 152 MachineRepresentation::kTagged, IsFalseConstant(), |
| 152 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), | 153 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), |
| 153 IsLoadField(AccessBuilder::ForMap(), input, | 154 IsLoadField(AccessBuilder::ForMap(), input, |
| 154 effect, CaptureEq(&if_false)), | 155 effect, CaptureEq(&if_false)), |
| 155 effect, _), | 156 effect, _), |
| 156 IsInt32Constant(JS_ARRAY_TYPE)), | 157 IsInt32Constant(JS_ARRAY_TYPE)), |
| 157 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 158 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
| 158 IsBranch(IsObjectIsSmi(input), control))), | 159 IsBranch(IsObjectIsSmi(input), control))), |
| 159 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 160 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
| 160 } | 161 } |
| 161 | 162 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 Reduction const r = Reduce( | 173 Reduction const r = Reduce( |
| 173 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsDate, 1), | 174 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsDate, 1), |
| 174 input, context, effect, control)); | 175 input, context, effect, control)); |
| 175 ASSERT_TRUE(r.Changed()); | 176 ASSERT_TRUE(r.Changed()); |
| 176 | 177 |
| 177 Node* phi = r.replacement(); | 178 Node* phi = r.replacement(); |
| 178 Capture<Node*> branch, if_false; | 179 Capture<Node*> branch, if_false; |
| 179 EXPECT_THAT( | 180 EXPECT_THAT( |
| 180 phi, | 181 phi, |
| 181 IsPhi( | 182 IsPhi( |
| 182 static_cast<MachineType>(kTypeBool | kRepTagged), IsFalseConstant(), | 183 MachineRepresentation::kTagged, IsFalseConstant(), |
| 183 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), | 184 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), |
| 184 IsLoadField(AccessBuilder::ForMap(), input, | 185 IsLoadField(AccessBuilder::ForMap(), input, |
| 185 effect, CaptureEq(&if_false)), | 186 effect, CaptureEq(&if_false)), |
| 186 effect, _), | 187 effect, _), |
| 187 IsInt32Constant(JS_DATE_TYPE)), | 188 IsInt32Constant(JS_DATE_TYPE)), |
| 188 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 189 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
| 189 IsBranch(IsObjectIsSmi(input), control))), | 190 IsBranch(IsObjectIsSmi(input), control))), |
| 190 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 191 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
| 191 } | 192 } |
| 192 | 193 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 203 Reduction const r = Reduce(graph()->NewNode( | 204 Reduction const r = Reduce(graph()->NewNode( |
| 204 javascript()->CallRuntime(Runtime::kInlineIsTypedArray, 1), input, | 205 javascript()->CallRuntime(Runtime::kInlineIsTypedArray, 1), input, |
| 205 context, effect, control)); | 206 context, effect, control)); |
| 206 ASSERT_TRUE(r.Changed()); | 207 ASSERT_TRUE(r.Changed()); |
| 207 | 208 |
| 208 Node* phi = r.replacement(); | 209 Node* phi = r.replacement(); |
| 209 Capture<Node*> branch, if_false; | 210 Capture<Node*> branch, if_false; |
| 210 EXPECT_THAT( | 211 EXPECT_THAT( |
| 211 phi, | 212 phi, |
| 212 IsPhi( | 213 IsPhi( |
| 213 static_cast<MachineType>(kTypeBool | kRepTagged), IsFalseConstant(), | 214 MachineRepresentation::kTagged, IsFalseConstant(), |
| 214 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), | 215 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), |
| 215 IsLoadField(AccessBuilder::ForMap(), input, | 216 IsLoadField(AccessBuilder::ForMap(), input, |
| 216 effect, CaptureEq(&if_false)), | 217 effect, CaptureEq(&if_false)), |
| 217 effect, _), | 218 effect, _), |
| 218 IsInt32Constant(JS_TYPED_ARRAY_TYPE)), | 219 IsInt32Constant(JS_TYPED_ARRAY_TYPE)), |
| 219 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 220 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
| 220 IsBranch(IsObjectIsSmi(input), control))), | 221 IsBranch(IsObjectIsSmi(input), control))), |
| 221 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 222 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
| 222 } | 223 } |
| 223 | 224 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 234 Reduction const r = Reduce( | 235 Reduction const r = Reduce( |
| 235 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsFunction, 1), | 236 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsFunction, 1), |
| 236 input, context, effect, control)); | 237 input, context, effect, control)); |
| 237 ASSERT_TRUE(r.Changed()); | 238 ASSERT_TRUE(r.Changed()); |
| 238 | 239 |
| 239 Node* phi = r.replacement(); | 240 Node* phi = r.replacement(); |
| 240 Capture<Node*> branch, if_false; | 241 Capture<Node*> branch, if_false; |
| 241 EXPECT_THAT( | 242 EXPECT_THAT( |
| 242 phi, | 243 phi, |
| 243 IsPhi( | 244 IsPhi( |
| 244 static_cast<MachineType>(kTypeBool | kRepTagged), IsFalseConstant(), | 245 MachineRepresentation::kTagged, IsFalseConstant(), |
| 245 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), | 246 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), |
| 246 IsLoadField(AccessBuilder::ForMap(), input, | 247 IsLoadField(AccessBuilder::ForMap(), input, |
| 247 effect, CaptureEq(&if_false)), | 248 effect, CaptureEq(&if_false)), |
| 248 effect, _), | 249 effect, _), |
| 249 IsInt32Constant(JS_FUNCTION_TYPE)), | 250 IsInt32Constant(JS_FUNCTION_TYPE)), |
| 250 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 251 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
| 251 IsBranch(IsObjectIsSmi(input), control))), | 252 IsBranch(IsObjectIsSmi(input), control))), |
| 252 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 253 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
| 253 } | 254 } |
| 254 | 255 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 265 Reduction const r = Reduce( | 266 Reduction const r = Reduce( |
| 266 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsRegExp, 1), | 267 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsRegExp, 1), |
| 267 input, context, effect, control)); | 268 input, context, effect, control)); |
| 268 ASSERT_TRUE(r.Changed()); | 269 ASSERT_TRUE(r.Changed()); |
| 269 | 270 |
| 270 Node* phi = r.replacement(); | 271 Node* phi = r.replacement(); |
| 271 Capture<Node*> branch, if_false; | 272 Capture<Node*> branch, if_false; |
| 272 EXPECT_THAT( | 273 EXPECT_THAT( |
| 273 phi, | 274 phi, |
| 274 IsPhi( | 275 IsPhi( |
| 275 static_cast<MachineType>(kTypeBool | kRepTagged), IsFalseConstant(), | 276 MachineRepresentation::kTagged, IsFalseConstant(), |
| 276 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), | 277 IsWord32Equal(IsLoadField(AccessBuilder::ForMapInstanceType(), |
| 277 IsLoadField(AccessBuilder::ForMap(), input, | 278 IsLoadField(AccessBuilder::ForMap(), input, |
| 278 effect, CaptureEq(&if_false)), | 279 effect, CaptureEq(&if_false)), |
| 279 effect, _), | 280 effect, _), |
| 280 IsInt32Constant(JS_REGEXP_TYPE)), | 281 IsInt32Constant(JS_REGEXP_TYPE)), |
| 281 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 282 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
| 282 IsBranch(IsObjectIsSmi(input), control))), | 283 IsBranch(IsObjectIsSmi(input), control))), |
| 283 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 284 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
| 284 } | 285 } |
| 285 | 286 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 296 Reduction const r = Reduce(graph()->NewNode( | 297 Reduction const r = Reduce(graph()->NewNode( |
| 297 javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input, | 298 javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input, |
| 298 context, effect, control)); | 299 context, effect, control)); |
| 299 ASSERT_TRUE(r.Changed()); | 300 ASSERT_TRUE(r.Changed()); |
| 300 | 301 |
| 301 Node* phi = r.replacement(); | 302 Node* phi = r.replacement(); |
| 302 Capture<Node *> branch, if_false; | 303 Capture<Node *> branch, if_false; |
| 303 EXPECT_THAT( | 304 EXPECT_THAT( |
| 304 phi, | 305 phi, |
| 305 IsPhi( | 306 IsPhi( |
| 306 kMachAnyTagged, IsFalseConstant(), | 307 MachineRepresentation::kTagged, IsFalseConstant(), |
| 307 IsUint32LessThanOrEqual( | 308 IsUint32LessThanOrEqual( |
| 308 IsInt32Constant(FIRST_JS_RECEIVER_TYPE), | 309 IsInt32Constant(FIRST_JS_RECEIVER_TYPE), |
| 309 IsLoadField(AccessBuilder::ForMapInstanceType(), | 310 IsLoadField(AccessBuilder::ForMapInstanceType(), |
| 310 IsLoadField(AccessBuilder::ForMap(), input, effect, | 311 IsLoadField(AccessBuilder::ForMap(), input, effect, |
| 311 CaptureEq(&if_false)), | 312 CaptureEq(&if_false)), |
| 312 effect, _)), | 313 effect, _)), |
| 313 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 314 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
| 314 IsBranch(IsObjectIsSmi(input), control))), | 315 IsBranch(IsObjectIsSmi(input), control))), |
| 315 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 316 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
| 316 } | 317 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 Reduction const r = Reduce( | 443 Reduction const r = Reduce( |
| 443 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineValueOf, 1), | 444 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineValueOf, 1), |
| 444 input, context, effect, control)); | 445 input, context, effect, control)); |
| 445 ASSERT_TRUE(r.Changed()); | 446 ASSERT_TRUE(r.Changed()); |
| 446 | 447 |
| 447 Node* phi = r.replacement(); | 448 Node* phi = r.replacement(); |
| 448 Capture<Node*> branch0, if_false0, branch1, if_true1; | 449 Capture<Node*> branch0, if_false0, branch1, if_true1; |
| 449 EXPECT_THAT( | 450 EXPECT_THAT( |
| 450 phi, | 451 phi, |
| 451 IsPhi( | 452 IsPhi( |
| 452 kMachAnyTagged, input, | 453 MachineRepresentation::kTagged, input, |
| 453 IsPhi(kMachAnyTagged, IsLoadField(AccessBuilder::ForValue(), input, | 454 IsPhi(MachineRepresentation::kTagged, |
| 454 effect, CaptureEq(&if_true1)), | 455 IsLoadField(AccessBuilder::ForValue(), input, effect, |
| 456 CaptureEq(&if_true1)), |
| 455 input, | 457 input, |
| 456 IsMerge( | 458 IsMerge( |
| 457 AllOf(CaptureEq(&if_true1), IsIfTrue(CaptureEq(&branch1))), | 459 AllOf(CaptureEq(&if_true1), IsIfTrue(CaptureEq(&branch1))), |
| 458 IsIfFalse(AllOf( | 460 IsIfFalse(AllOf( |
| 459 CaptureEq(&branch1), | 461 CaptureEq(&branch1), |
| 460 IsBranch( | 462 IsBranch( |
| 461 IsWord32Equal( | 463 IsWord32Equal( |
| 462 IsLoadField( | 464 IsLoadField( |
| 463 AccessBuilder::ForMapInstanceType(), | 465 AccessBuilder::ForMapInstanceType(), |
| 464 IsLoadField(AccessBuilder::ForMap(), input, | 466 IsLoadField(AccessBuilder::ForMap(), input, |
| 465 effect, CaptureEq(&if_false0)), | 467 effect, CaptureEq(&if_false0)), |
| 466 effect, _), | 468 effect, _), |
| 467 IsInt32Constant(JS_VALUE_TYPE)), | 469 IsInt32Constant(JS_VALUE_TYPE)), |
| 468 CaptureEq(&if_false0)))))), | 470 CaptureEq(&if_false0)))))), |
| 469 IsMerge( | 471 IsMerge( |
| 470 IsIfTrue(AllOf(CaptureEq(&branch0), | 472 IsIfTrue(AllOf(CaptureEq(&branch0), |
| 471 IsBranch(IsObjectIsSmi(input), control))), | 473 IsBranch(IsObjectIsSmi(input), control))), |
| 472 AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0)))))); | 474 AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0)))))); |
| 473 } | 475 } |
| 474 | 476 |
| 475 } // namespace compiler | 477 } // namespace compiler |
| 476 } // namespace internal | 478 } // namespace internal |
| 477 } // namespace v8 | 479 } // namespace v8 |
| OLD | NEW |