| 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-lowering.h" | 5 #include "src/compiler/simplified-lowering.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 ProcessInput(node, 2, | 1234 ProcessInput(node, 2, |
| 1235 TruncatingUseInfoFromRepresentation( | 1235 TruncatingUseInfoFromRepresentation( |
| 1236 access.machine_type.representation())); // value | 1236 access.machine_type.representation())); // value |
| 1237 ProcessRemainingInputs(node, 3); | 1237 ProcessRemainingInputs(node, 3); |
| 1238 SetOutput(node, NodeOutputInfo::None()); | 1238 SetOutput(node, NodeOutputInfo::None()); |
| 1239 break; | 1239 break; |
| 1240 } | 1240 } |
| 1241 case IrOpcode::kObjectIsNumber: { | 1241 case IrOpcode::kObjectIsNumber: { |
| 1242 ProcessInput(node, 0, UseInfo::AnyTagged()); | 1242 ProcessInput(node, 0, UseInfo::AnyTagged()); |
| 1243 SetOutput(node, NodeOutputInfo::Bool()); | 1243 SetOutput(node, NodeOutputInfo::Bool()); |
| 1244 if (lower()) lowering->DoObjectIsNumber(node); | |
| 1245 break; | 1244 break; |
| 1246 } | 1245 } |
| 1247 case IrOpcode::kObjectIsReceiver: { | 1246 case IrOpcode::kObjectIsReceiver: { |
| 1248 ProcessInput(node, 0, UseInfo::AnyTagged()); | 1247 ProcessInput(node, 0, UseInfo::AnyTagged()); |
| 1249 SetOutput(node, NodeOutputInfo::Bool()); | 1248 SetOutput(node, NodeOutputInfo::Bool()); |
| 1250 if (lower()) lowering->DoObjectIsReceiver(node); | |
| 1251 break; | 1249 break; |
| 1252 } | 1250 } |
| 1253 case IrOpcode::kObjectIsSmi: { | 1251 case IrOpcode::kObjectIsSmi: { |
| 1254 ProcessInput(node, 0, UseInfo::AnyTagged()); | 1252 ProcessInput(node, 0, UseInfo::AnyTagged()); |
| 1255 SetOutput(node, NodeOutputInfo::Bool()); | 1253 SetOutput(node, NodeOutputInfo::Bool()); |
| 1256 if (lower()) lowering->DoObjectIsSmi(node); | |
| 1257 break; | 1254 break; |
| 1258 } | 1255 } |
| 1259 | 1256 |
| 1260 //------------------------------------------------------------------ | 1257 //------------------------------------------------------------------ |
| 1261 // Machine-level operators. | 1258 // Machine-level operators. |
| 1262 //------------------------------------------------------------------ | 1259 //------------------------------------------------------------------ |
| 1263 case IrOpcode::kLoad: { | 1260 case IrOpcode::kLoad: { |
| 1264 // TODO(jarin) Eventually, we should get rid of all machine stores | 1261 // TODO(jarin) Eventually, we should get rid of all machine stores |
| 1265 // from the high-level phases, then this becomes UNREACHABLE. | 1262 // from the high-level phases, then this becomes UNREACHABLE. |
| 1266 LoadRepresentation rep = LoadRepresentationOf(node->op()); | 1263 LoadRepresentation rep = LoadRepresentationOf(node->op()); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 | 1581 |
| 1585 | 1582 |
| 1586 void SimplifiedLowering::DoStoreBuffer(Node* node) { | 1583 void SimplifiedLowering::DoStoreBuffer(Node* node) { |
| 1587 DCHECK_EQ(IrOpcode::kStoreBuffer, node->opcode()); | 1584 DCHECK_EQ(IrOpcode::kStoreBuffer, node->opcode()); |
| 1588 MachineRepresentation const rep = | 1585 MachineRepresentation const rep = |
| 1589 BufferAccessOf(node->op()).machine_type().representation(); | 1586 BufferAccessOf(node->op()).machine_type().representation(); |
| 1590 NodeProperties::ChangeOp(node, machine()->CheckedStore(rep)); | 1587 NodeProperties::ChangeOp(node, machine()->CheckedStore(rep)); |
| 1591 } | 1588 } |
| 1592 | 1589 |
| 1593 | 1590 |
| 1594 void SimplifiedLowering::DoObjectIsNumber(Node* node) { | |
| 1595 Node* input = NodeProperties::GetValueInput(node, 0); | |
| 1596 // TODO(bmeurer): Optimize somewhat based on input type. | |
| 1597 Node* check = IsSmi(input); | |
| 1598 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | |
| 1599 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | |
| 1600 Node* vtrue = jsgraph()->Int32Constant(1); | |
| 1601 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 1602 Node* vfalse = graph()->NewNode( | |
| 1603 machine()->WordEqual(), LoadHeapObjectMap(input, if_false), | |
| 1604 jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); | |
| 1605 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 1606 node->ReplaceInput(0, vtrue); | |
| 1607 node->AppendInput(graph()->zone(), vfalse); | |
| 1608 node->AppendInput(graph()->zone(), control); | |
| 1609 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); | |
| 1610 } | |
| 1611 | |
| 1612 | |
| 1613 void SimplifiedLowering::DoObjectIsReceiver(Node* node) { | |
| 1614 Node* input = NodeProperties::GetValueInput(node, 0); | |
| 1615 // TODO(bmeurer): Optimize somewhat based on input type. | |
| 1616 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); | |
| 1617 Node* check = IsSmi(input); | |
| 1618 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | |
| 1619 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | |
| 1620 Node* vtrue = jsgraph()->Int32Constant(0); | |
| 1621 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 1622 Node* vfalse = | |
| 1623 graph()->NewNode(machine()->Uint32LessThanOrEqual(), | |
| 1624 jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), | |
| 1625 LoadMapInstanceType(LoadHeapObjectMap(input, if_false))); | |
| 1626 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 1627 node->ReplaceInput(0, vtrue); | |
| 1628 node->AppendInput(graph()->zone(), vfalse); | |
| 1629 node->AppendInput(graph()->zone(), control); | |
| 1630 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); | |
| 1631 } | |
| 1632 | |
| 1633 | |
| 1634 void SimplifiedLowering::DoObjectIsSmi(Node* node) { | |
| 1635 node->ReplaceInput(0, | |
| 1636 graph()->NewNode(machine()->WordAnd(), node->InputAt(0), | |
| 1637 jsgraph()->IntPtrConstant(kSmiTagMask))); | |
| 1638 node->AppendInput(graph()->zone(), jsgraph()->IntPtrConstant(kSmiTag)); | |
| 1639 NodeProperties::ChangeOp(node, machine()->WordEqual()); | |
| 1640 } | |
| 1641 | |
| 1642 | |
| 1643 Node* SimplifiedLowering::IsSmi(Node* value) { | |
| 1644 return graph()->NewNode( | |
| 1645 machine()->WordEqual(), | |
| 1646 graph()->NewNode(machine()->WordAnd(), value, | |
| 1647 jsgraph()->IntPtrConstant(kSmiTagMask)), | |
| 1648 jsgraph()->IntPtrConstant(kSmiTag)); | |
| 1649 } | |
| 1650 | |
| 1651 | |
| 1652 Node* SimplifiedLowering::LoadHeapObjectMap(Node* object, Node* control) { | |
| 1653 return graph()->NewNode( | |
| 1654 machine()->Load(MachineType::AnyTagged()), object, | |
| 1655 jsgraph()->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag), | |
| 1656 graph()->start(), control); | |
| 1657 } | |
| 1658 | |
| 1659 | |
| 1660 Node* SimplifiedLowering::LoadMapInstanceType(Node* map) { | |
| 1661 return graph()->NewNode( | |
| 1662 machine()->Load(MachineType::Uint8()), map, | |
| 1663 jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), | |
| 1664 graph()->start(), graph()->start()); | |
| 1665 } | |
| 1666 | |
| 1667 | |
| 1668 Node* SimplifiedLowering::StringComparison(Node* node) { | 1591 Node* SimplifiedLowering::StringComparison(Node* node) { |
| 1669 Operator::Properties properties = node->op()->properties(); | 1592 Operator::Properties properties = node->op()->properties(); |
| 1670 Callable callable = CodeFactory::StringCompare(isolate()); | 1593 Callable callable = CodeFactory::StringCompare(isolate()); |
| 1671 CallDescriptor::Flags flags = CallDescriptor::kNoFlags; | 1594 CallDescriptor::Flags flags = CallDescriptor::kNoFlags; |
| 1672 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 1595 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 1673 isolate(), zone(), callable.descriptor(), 0, flags, properties); | 1596 isolate(), zone(), callable.descriptor(), 0, flags, properties); |
| 1674 return graph()->NewNode( | 1597 return graph()->NewNode( |
| 1675 common()->Call(desc), jsgraph()->HeapConstant(callable.code()), | 1598 common()->Call(desc), jsgraph()->HeapConstant(callable.code()), |
| 1676 NodeProperties::GetValueInput(node, 0), | 1599 NodeProperties::GetValueInput(node, 0), |
| 1677 NodeProperties::GetValueInput(node, 1), jsgraph()->NoContextConstant(), | 1600 NodeProperties::GetValueInput(node, 1), jsgraph()->NoContextConstant(), |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 ReplaceEffectUses(node, comparison); | 1908 ReplaceEffectUses(node, comparison); |
| 1986 node->ReplaceInput(0, comparison); | 1909 node->ReplaceInput(0, comparison); |
| 1987 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); | 1910 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); |
| 1988 node->TrimInputCount(2); | 1911 node->TrimInputCount(2); |
| 1989 NodeProperties::ChangeOp(node, machine()->IntLessThanOrEqual()); | 1912 NodeProperties::ChangeOp(node, machine()->IntLessThanOrEqual()); |
| 1990 } | 1913 } |
| 1991 | 1914 |
| 1992 } // namespace compiler | 1915 } // namespace compiler |
| 1993 } // namespace internal | 1916 } // namespace internal |
| 1994 } // namespace v8 | 1917 } // namespace v8 |
| OLD | NEW |