| 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/js-intrinsic-lowering.h" | 5 #include "src/compiler/js-intrinsic-lowering.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // Replace all effect uses of {node} with the {ephi}. | 236 // Replace all effect uses of {node} with the {ephi}. |
| 237 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); | 237 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); |
| 238 ReplaceWithValue(node, node, ephi); | 238 ReplaceWithValue(node, node, ephi); |
| 239 | 239 |
| 240 // Turn the {node} into a Phi. | 240 // Turn the {node} into a Phi. |
| 241 return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); | 241 return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); |
| 242 } | 242 } |
| 243 | 243 |
| 244 | 244 |
| 245 Reduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) { | 245 Reduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) { |
| 246 // if (%_IsSmi(value)) { | |
| 247 // return false; | |
| 248 // } else { | |
| 249 // return FIRST_JS_RECEIVER_TYPE <= %_GetInstanceType(%_GetMap(value)) | |
| 250 // } | |
| 251 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); | |
| 252 MachineType const type = static_cast<MachineType>(kTypeBool | kRepTagged); | |
| 253 | |
| 254 Node* value = NodeProperties::GetValueInput(node, 0); | 246 Node* value = NodeProperties::GetValueInput(node, 0); |
| 247 Type* value_type = NodeProperties::GetType(value); |
| 255 Node* effect = NodeProperties::GetEffectInput(node); | 248 Node* effect = NodeProperties::GetEffectInput(node); |
| 256 Node* control = NodeProperties::GetControlInput(node); | 249 Node* control = NodeProperties::GetControlInput(node); |
| 250 if (value_type->Is(Type::Receiver())) { |
| 251 value = jsgraph()->TrueConstant(); |
| 252 } else if (!value_type->Maybe(Type::Receiver())) { |
| 253 value = jsgraph()->FalseConstant(); |
| 254 } else { |
| 255 // if (%_IsSmi(value)) { |
| 256 // return false; |
| 257 // } else { |
| 258 // return FIRST_JS_RECEIVER_TYPE <= %_GetInstanceType(%_GetMap(value)) |
| 259 // } |
| 260 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| 257 | 261 |
| 258 Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), value); | 262 Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), value); |
| 259 Node* branch = graph()->NewNode(common()->Branch(), check, control); | 263 Node* branch = graph()->NewNode(common()->Branch(), check, control); |
| 260 | 264 |
| 261 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 265 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 262 Node* etrue = effect; | 266 Node* etrue = effect; |
| 263 Node* vtrue = jsgraph()->FalseConstant(); | 267 Node* vtrue = jsgraph()->FalseConstant(); |
| 264 | 268 |
| 265 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 269 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 266 Node* efalse = graph()->NewNode( | 270 Node* efalse = graph()->NewNode( |
| 267 simplified()->LoadField(AccessBuilder::ForMapInstanceType()), | 271 simplified()->LoadField(AccessBuilder::ForMapInstanceType()), |
| 268 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), value, | 272 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), |
| 269 effect, if_false), | 273 value, effect, if_false), |
| 270 effect, if_false); | 274 effect, if_false); |
| 271 Node* vfalse = graph()->NewNode( | 275 Node* vfalse = graph()->NewNode( |
| 272 machine()->Uint32LessThanOrEqual(), | 276 machine()->Uint32LessThanOrEqual(), |
| 273 jsgraph()->Int32Constant(FIRST_JS_RECEIVER_TYPE), efalse); | 277 jsgraph()->Int32Constant(FIRST_JS_RECEIVER_TYPE), efalse); |
| 274 | 278 |
| 275 control = graph()->NewNode(common()->Merge(2), if_true, if_false); | 279 control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 276 | 280 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
| 277 // Replace all effect uses of {node} with the {ephi}. | 281 value = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), vtrue, vfalse, |
| 278 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); | 282 control); |
| 283 } |
| 279 ReplaceWithValue(node, node, effect, control); | 284 ReplaceWithValue(node, node, effect, control); |
| 280 | 285 return Replace(value); |
| 281 // Turn the {node} into a Phi. | |
| 282 return Change(node, common()->Phi(type, 2), vtrue, vfalse, control); | |
| 283 } | 286 } |
| 284 | 287 |
| 285 | 288 |
| 286 Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { | 289 Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { |
| 287 return Change(node, simplified()->ObjectIsSmi()); | 290 return Change(node, simplified()->ObjectIsSmi()); |
| 288 } | 291 } |
| 289 | 292 |
| 290 | 293 |
| 291 Reduction JSIntrinsicLowering::ReduceJSValueGetValue(Node* node) { | 294 Reduction JSIntrinsicLowering::ReduceJSValueGetValue(Node* node) { |
| 292 Node* value = NodeProperties::GetValueInput(node, 0); | 295 Node* value = NodeProperties::GetValueInput(node, 0); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 } | 646 } |
| 644 | 647 |
| 645 | 648 |
| 646 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { | 649 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { |
| 647 return jsgraph()->simplified(); | 650 return jsgraph()->simplified(); |
| 648 } | 651 } |
| 649 | 652 |
| 650 } // namespace compiler | 653 } // namespace compiler |
| 651 } // namespace internal | 654 } // namespace internal |
| 652 } // namespace v8 | 655 } // namespace v8 |
| OLD | NEW |