| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 203 } | 203 } | 
| 204 | 204 | 
| 205 | 205 | 
| 206 Reduction JSIntrinsicLowering::ReduceIsInstanceType( | 206 Reduction JSIntrinsicLowering::ReduceIsInstanceType( | 
| 207     Node* node, InstanceType instance_type) { | 207     Node* node, InstanceType instance_type) { | 
| 208   // if (%_IsSmi(value)) { | 208   // if (%_IsSmi(value)) { | 
| 209   //   return false; | 209   //   return false; | 
| 210   // } else { | 210   // } else { | 
| 211   //   return %_GetInstanceType(%_GetMap(value)) == instance_type; | 211   //   return %_GetInstanceType(%_GetMap(value)) == instance_type; | 
| 212   // } | 212   // } | 
| 213   MachineType const type = static_cast<MachineType>(kTypeBool | kRepTagged); |  | 
| 214 |  | 
| 215   Node* value = NodeProperties::GetValueInput(node, 0); | 213   Node* value = NodeProperties::GetValueInput(node, 0); | 
| 216   Node* effect = NodeProperties::GetEffectInput(node); | 214   Node* effect = NodeProperties::GetEffectInput(node); | 
| 217   Node* control = NodeProperties::GetControlInput(node); | 215   Node* control = NodeProperties::GetControlInput(node); | 
| 218 | 216 | 
| 219   Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), value); | 217   Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), value); | 
| 220   Node* branch = graph()->NewNode(common()->Branch(), check, control); | 218   Node* branch = graph()->NewNode(common()->Branch(), check, control); | 
| 221 | 219 | 
| 222   Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 220   Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 
| 223   Node* etrue = effect; | 221   Node* etrue = effect; | 
| 224   Node* vtrue = jsgraph()->FalseConstant(); | 222   Node* vtrue = jsgraph()->FalseConstant(); | 
| 225 | 223 | 
| 226   Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 224   Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 
| 227   Node* efalse = graph()->NewNode( | 225   Node* efalse = graph()->NewNode( | 
| 228       simplified()->LoadField(AccessBuilder::ForMapInstanceType()), | 226       simplified()->LoadField(AccessBuilder::ForMapInstanceType()), | 
| 229       graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), value, | 227       graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), value, | 
| 230                        effect, if_false), | 228                        effect, if_false), | 
| 231       effect, if_false); | 229       effect, if_false); | 
| 232   Node* vfalse = graph()->NewNode(machine()->Word32Equal(), efalse, | 230   Node* vfalse = graph()->NewNode(machine()->Word32Equal(), efalse, | 
| 233                                   jsgraph()->Int32Constant(instance_type)); | 231                                   jsgraph()->Int32Constant(instance_type)); | 
| 234 | 232 | 
| 235   Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 233   Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 
| 236 | 234 | 
| 237   // Replace all effect uses of {node} with the {ephi}. | 235   // Replace all effect uses of {node} with the {ephi}. | 
| 238   Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); | 236   Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); | 
| 239   ReplaceWithValue(node, node, ephi); | 237   ReplaceWithValue(node, node, ephi); | 
| 240 | 238 | 
| 241   // Turn the {node} into a Phi. | 239   // Turn the {node} into a Phi. | 
| 242   return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); | 240   return Change(node, common()->Phi(MachineRepresentation::kTagged, 2), vtrue, | 
|  | 241                 vfalse, merge); | 
| 243 } | 242 } | 
| 244 | 243 | 
| 245 | 244 | 
| 246 Reduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) { | 245 Reduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) { | 
| 247   Node* value = NodeProperties::GetValueInput(node, 0); | 246   Node* value = NodeProperties::GetValueInput(node, 0); | 
| 248   Type* value_type = NodeProperties::GetType(value); | 247   Type* value_type = NodeProperties::GetType(value); | 
| 249   Node* effect = NodeProperties::GetEffectInput(node); | 248   Node* effect = NodeProperties::GetEffectInput(node); | 
| 250   Node* control = NodeProperties::GetControlInput(node); | 249   Node* control = NodeProperties::GetControlInput(node); | 
| 251   if (value_type->Is(Type::Receiver())) { | 250   if (value_type->Is(Type::Receiver())) { | 
| 252     value = jsgraph()->TrueConstant(); | 251     value = jsgraph()->TrueConstant(); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 272         simplified()->LoadField(AccessBuilder::ForMapInstanceType()), | 271         simplified()->LoadField(AccessBuilder::ForMapInstanceType()), | 
| 273         graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), | 272         graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), | 
| 274                          value, effect, if_false), | 273                          value, effect, if_false), | 
| 275         effect, if_false); | 274         effect, if_false); | 
| 276     Node* vfalse = graph()->NewNode( | 275     Node* vfalse = graph()->NewNode( | 
| 277         machine()->Uint32LessThanOrEqual(), | 276         machine()->Uint32LessThanOrEqual(), | 
| 278         jsgraph()->Int32Constant(FIRST_JS_RECEIVER_TYPE), efalse); | 277         jsgraph()->Int32Constant(FIRST_JS_RECEIVER_TYPE), efalse); | 
| 279 | 278 | 
| 280     control = graph()->NewNode(common()->Merge(2), if_true, if_false); | 279     control = graph()->NewNode(common()->Merge(2), if_true, if_false); | 
| 281     effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); | 280     effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); | 
| 282     value = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), vtrue, vfalse, | 281     value = graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2), | 
| 283                              control); | 282                              vtrue, vfalse, control); | 
| 284   } | 283   } | 
| 285   ReplaceWithValue(node, node, effect, control); | 284   ReplaceWithValue(node, node, effect, control); | 
| 286   return Replace(value); | 285   return Replace(value); | 
| 287 } | 286 } | 
| 288 | 287 | 
| 289 | 288 | 
| 290 Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { | 289 Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { | 
| 291   return Change(node, simplified()->ObjectIsSmi()); | 290   return Change(node, simplified()->ObjectIsSmi()); | 
| 292 } | 291 } | 
| 293 | 292 | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 339 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { | 338 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { | 
| 340   // if (%_IsSmi(value)) { | 339   // if (%_IsSmi(value)) { | 
| 341   //   return value; | 340   //   return value; | 
| 342   // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { | 341   // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { | 
| 343   //   return %_GetValue(value); | 342   //   return %_GetValue(value); | 
| 344   // } else { | 343   // } else { | 
| 345   //   return value; | 344   //   return value; | 
| 346   // } | 345   // } | 
| 347   const Operator* const merge_op = common()->Merge(2); | 346   const Operator* const merge_op = common()->Merge(2); | 
| 348   const Operator* const ephi_op = common()->EffectPhi(2); | 347   const Operator* const ephi_op = common()->EffectPhi(2); | 
| 349   const Operator* const phi_op = common()->Phi(kMachAnyTagged, 2); | 348   const Operator* const phi_op = | 
|  | 349       common()->Phi(MachineRepresentation::kTagged, 2); | 
| 350 | 350 | 
| 351   Node* value = NodeProperties::GetValueInput(node, 0); | 351   Node* value = NodeProperties::GetValueInput(node, 0); | 
| 352   Node* effect = NodeProperties::GetEffectInput(node); | 352   Node* effect = NodeProperties::GetEffectInput(node); | 
| 353   Node* control = NodeProperties::GetControlInput(node); | 353   Node* control = NodeProperties::GetControlInput(node); | 
| 354 | 354 | 
| 355   Node* check0 = graph()->NewNode(simplified()->ObjectIsSmi(), value); | 355   Node* check0 = graph()->NewNode(simplified()->ObjectIsSmi(), value); | 
| 356   Node* branch0 = graph()->NewNode(common()->Branch(), check0, control); | 356   Node* branch0 = graph()->NewNode(common()->Branch(), check0, control); | 
| 357 | 357 | 
| 358   Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); | 358   Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); | 
| 359   Node* etrue0 = effect; | 359   Node* etrue0 = effect; | 
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 504   Node* value = NodeProperties::GetValueInput(node, 0); | 504   Node* value = NodeProperties::GetValueInput(node, 0); | 
| 505   Type* value_type = NodeProperties::GetType(value); | 505   Type* value_type = NodeProperties::GetType(value); | 
| 506   if (value_type->Is(type_cache().kIntegerOrMinusZero)) { | 506   if (value_type->Is(type_cache().kIntegerOrMinusZero)) { | 
| 507     if (value_type->Max() <= 0.0) { | 507     if (value_type->Max() <= 0.0) { | 
| 508       value = jsgraph()->ZeroConstant(); | 508       value = jsgraph()->ZeroConstant(); | 
| 509     } else if (value_type->Min() >= kMaxSafeInteger) { | 509     } else if (value_type->Min() >= kMaxSafeInteger) { | 
| 510       value = jsgraph()->Constant(kMaxSafeInteger); | 510       value = jsgraph()->Constant(kMaxSafeInteger); | 
| 511     } else { | 511     } else { | 
| 512       if (value_type->Min() <= 0.0) { | 512       if (value_type->Min() <= 0.0) { | 
| 513         value = graph()->NewNode( | 513         value = graph()->NewNode( | 
| 514             common()->Select(kMachAnyTagged), | 514             common()->Select(MachineRepresentation::kTagged), | 
| 515             graph()->NewNode(simplified()->NumberLessThanOrEqual(), value, | 515             graph()->NewNode(simplified()->NumberLessThanOrEqual(), value, | 
| 516                              jsgraph()->ZeroConstant()), | 516                              jsgraph()->ZeroConstant()), | 
| 517             jsgraph()->ZeroConstant(), value); | 517             jsgraph()->ZeroConstant(), value); | 
| 518         value_type = Type::Range(0.0, value_type->Max(), graph()->zone()); | 518         value_type = Type::Range(0.0, value_type->Max(), graph()->zone()); | 
| 519         NodeProperties::SetType(value, value_type); | 519         NodeProperties::SetType(value, value_type); | 
| 520       } | 520       } | 
| 521       if (value_type->Max() > kMaxSafeInteger) { | 521       if (value_type->Max() > kMaxSafeInteger) { | 
| 522         value = graph()->NewNode( | 522         value = graph()->NewNode( | 
| 523             common()->Select(kMachAnyTagged), | 523             common()->Select(MachineRepresentation::kTagged), | 
| 524             graph()->NewNode(simplified()->NumberLessThanOrEqual(), | 524             graph()->NewNode(simplified()->NumberLessThanOrEqual(), | 
| 525                              jsgraph()->Constant(kMaxSafeInteger), value), | 525                              jsgraph()->Constant(kMaxSafeInteger), value), | 
| 526             jsgraph()->Constant(kMaxSafeInteger), value); | 526             jsgraph()->Constant(kMaxSafeInteger), value); | 
| 527         value_type = | 527         value_type = | 
| 528             Type::Range(value_type->Min(), kMaxSafeInteger, graph()->zone()); | 528             Type::Range(value_type->Min(), kMaxSafeInteger, graph()->zone()); | 
| 529         NodeProperties::SetType(value, value_type); | 529         NodeProperties::SetType(value, value_type); | 
| 530       } | 530       } | 
| 531     } | 531     } | 
| 532     ReplaceWithValue(node, value); | 532     ReplaceWithValue(node, value); | 
| 533     return Replace(value); | 533     return Replace(value); | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 648 } | 648 } | 
| 649 | 649 | 
| 650 | 650 | 
| 651 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { | 651 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { | 
| 652   return jsgraph()->simplified(); | 652   return jsgraph()->simplified(); | 
| 653 } | 653 } | 
| 654 | 654 | 
| 655 }  // namespace compiler | 655 }  // namespace compiler | 
| 656 }  // namespace internal | 656 }  // namespace internal | 
| 657 }  // namespace v8 | 657 }  // namespace v8 | 
| OLD | NEW | 
|---|