| 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/address-map.h" | 9 #include "src/address-map.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 node->AppendInput(jsgraph_->zone(), jsgraph_->FalseConstant()); | 1238 node->AppendInput(jsgraph_->zone(), jsgraph_->FalseConstant()); |
| 1239 NodeProperties::ChangeOp(node, lowering->machine()->WordEqual()); | 1239 NodeProperties::ChangeOp(node, lowering->machine()->WordEqual()); |
| 1240 } | 1240 } |
| 1241 } else { | 1241 } else { |
| 1242 // No input representation requirement; adapt during lowering. | 1242 // No input representation requirement; adapt during lowering. |
| 1243 ProcessInput(node, 0, UseInfo::AnyTruncatingToBool()); | 1243 ProcessInput(node, 0, UseInfo::AnyTruncatingToBool()); |
| 1244 SetOutput(node, MachineRepresentation::kBit); | 1244 SetOutput(node, MachineRepresentation::kBit); |
| 1245 } | 1245 } |
| 1246 return; | 1246 return; |
| 1247 } | 1247 } |
| 1248 case IrOpcode::kBooleanToNumber: { | |
| 1249 if (lower()) { | |
| 1250 NodeInfo* input_info = GetInfo(node->InputAt(0)); | |
| 1251 if (input_info->representation() == MachineRepresentation::kBit) { | |
| 1252 // BooleanToNumber(x: kRepBit) => x | |
| 1253 DeferReplacement(node, node->InputAt(0)); | |
| 1254 } else { | |
| 1255 // BooleanToNumber(x: kRepTagged) => WordEqual(x, #true) | |
| 1256 node->AppendInput(jsgraph_->zone(), jsgraph_->TrueConstant()); | |
| 1257 NodeProperties::ChangeOp(node, lowering->machine()->WordEqual()); | |
| 1258 } | |
| 1259 } else { | |
| 1260 // No input representation requirement; adapt during lowering. | |
| 1261 ProcessInput(node, 0, UseInfo::AnyTruncatingToBool()); | |
| 1262 SetOutput(node, MachineRepresentation::kWord32); | |
| 1263 } | |
| 1264 return; | |
| 1265 } | |
| 1266 case IrOpcode::kNumberEqual: | 1248 case IrOpcode::kNumberEqual: |
| 1267 case IrOpcode::kNumberLessThan: | 1249 case IrOpcode::kNumberLessThan: |
| 1268 case IrOpcode::kNumberLessThanOrEqual: { | 1250 case IrOpcode::kNumberLessThanOrEqual: { |
| 1269 // Number comparisons reduce to integer comparisons for integer inputs. | 1251 // Number comparisons reduce to integer comparisons for integer inputs. |
| 1270 if (TypeOf(node->InputAt(0))->Is(Type::Unsigned32()) && | 1252 if (TypeOf(node->InputAt(0))->Is(Type::Unsigned32()) && |
| 1271 TypeOf(node->InputAt(1))->Is(Type::Unsigned32())) { | 1253 TypeOf(node->InputAt(1))->Is(Type::Unsigned32())) { |
| 1272 // => unsigned Int32Cmp | 1254 // => unsigned Int32Cmp |
| 1273 VisitUint32Cmp(node); | 1255 VisitUint32Cmp(node); |
| 1274 if (lower()) NodeProperties::ChangeOp(node, Uint32Op(node)); | 1256 if (lower()) NodeProperties::ChangeOp(node, Uint32Op(node)); |
| 1275 } else if (TypeOf(node->InputAt(0))->Is(Type::Signed32()) && | 1257 } else if (TypeOf(node->InputAt(0))->Is(Type::Signed32()) && |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 node->AppendInput(jsgraph_->zone(), jsgraph_->graph()->start()); | 1765 node->AppendInput(jsgraph_->zone(), jsgraph_->graph()->start()); |
| 1784 NodeProperties::ChangeOp(node, jsgraph_->common()->Call(desc)); | 1766 NodeProperties::ChangeOp(node, jsgraph_->common()->Call(desc)); |
| 1785 } | 1767 } |
| 1786 return; | 1768 return; |
| 1787 } | 1769 } |
| 1788 case IrOpcode::kStringFromCharCode: { | 1770 case IrOpcode::kStringFromCharCode: { |
| 1789 VisitUnop(node, UseInfo::TruncatingWord32(), | 1771 VisitUnop(node, UseInfo::TruncatingWord32(), |
| 1790 MachineRepresentation::kTagged); | 1772 MachineRepresentation::kTagged); |
| 1791 return; | 1773 return; |
| 1792 } | 1774 } |
| 1793 case IrOpcode::kStringToNumber: { | |
| 1794 VisitUnop(node, UseInfo::AnyTagged(), MachineRepresentation::kTagged); | |
| 1795 if (lower()) { | |
| 1796 // StringToNumber(x) => Call(StringToNumber, x, no-context) | |
| 1797 Operator::Properties properties = Operator::kEliminatable; | |
| 1798 Callable callable = CodeFactory::StringToNumber(jsgraph_->isolate()); | |
| 1799 CallDescriptor::Flags flags = CallDescriptor::kNoFlags; | |
| 1800 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
| 1801 jsgraph_->isolate(), jsgraph_->zone(), callable.descriptor(), 0, | |
| 1802 flags, properties); | |
| 1803 node->InsertInput(jsgraph_->zone(), 0, | |
| 1804 jsgraph_->HeapConstant(callable.code())); | |
| 1805 node->AppendInput(jsgraph_->zone(), jsgraph_->NoContextConstant()); | |
| 1806 node->AppendInput(jsgraph_->zone(), jsgraph_->graph()->start()); | |
| 1807 NodeProperties::ChangeOp(node, jsgraph_->common()->Call(desc)); | |
| 1808 } | |
| 1809 return; | |
| 1810 } | |
| 1811 | 1775 |
| 1812 case IrOpcode::kCheckBounds: { | 1776 case IrOpcode::kCheckBounds: { |
| 1813 if (TypeOf(node->InputAt(0))->Is(Type::Unsigned32())) { | 1777 if (TypeOf(node->InputAt(0))->Is(Type::Unsigned32())) { |
| 1814 VisitBinop(node, UseInfo::TruncatingWord32(), | 1778 VisitBinop(node, UseInfo::TruncatingWord32(), |
| 1815 MachineRepresentation::kWord32); | 1779 MachineRepresentation::kWord32); |
| 1816 } else { | 1780 } else { |
| 1817 VisitBinop(node, UseInfo::CheckedSigned32AsWord32(), | 1781 VisitBinop(node, UseInfo::CheckedSigned32AsWord32(), |
| 1818 UseInfo::TruncatingWord32(), | 1782 UseInfo::TruncatingWord32(), |
| 1819 MachineRepresentation::kWord32); | 1783 MachineRepresentation::kWord32); |
| 1820 } | 1784 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 SetOutput(node, MachineRepresentation::kNone); | 1952 SetOutput(node, MachineRepresentation::kNone); |
| 1989 if (lower()) { | 1953 if (lower()) { |
| 1990 if (write_barrier_kind < access.write_barrier_kind) { | 1954 if (write_barrier_kind < access.write_barrier_kind) { |
| 1991 access.write_barrier_kind = write_barrier_kind; | 1955 access.write_barrier_kind = write_barrier_kind; |
| 1992 NodeProperties::ChangeOp( | 1956 NodeProperties::ChangeOp( |
| 1993 node, jsgraph_->simplified()->StoreElement(access)); | 1957 node, jsgraph_->simplified()->StoreElement(access)); |
| 1994 } | 1958 } |
| 1995 } | 1959 } |
| 1996 return; | 1960 return; |
| 1997 } | 1961 } |
| 1998 case IrOpcode::kPlainPrimitiveToNumber: | 1962 case IrOpcode::kPlainPrimitiveToNumber: { |
| 1999 if (truncation.TruncatesToWord32()) { | 1963 if (InputIs(node, Type::Boolean())) { |
| 1964 VisitUnop(node, UseInfo::Bool(), MachineRepresentation::kWord32); |
| 1965 if (lower()) DeferReplacement(node, node->InputAt(0)); |
| 1966 } else if (InputIs(node, Type::String())) { |
| 1967 VisitUnop(node, UseInfo::AnyTagged(), MachineRepresentation::kTagged); |
| 1968 if (lower()) lowering->DoStringToNumber(node); |
| 1969 } else if (truncation.TruncatesToWord32()) { |
| 2000 // TODO(jarin): Extend this to Number \/ Oddball | 1970 // TODO(jarin): Extend this to Number \/ Oddball |
| 2001 if (InputIs(node, Type::NumberOrUndefined())) { | 1971 if (InputIs(node, Type::NumberOrUndefined())) { |
| 2002 VisitUnop(node, UseInfo::TruncatingWord32(), | 1972 VisitUnop(node, UseInfo::TruncatingWord32(), |
| 2003 MachineRepresentation::kWord32); | 1973 MachineRepresentation::kWord32); |
| 2004 if (lower()) DeferReplacement(node, node->InputAt(0)); | 1974 if (lower()) DeferReplacement(node, node->InputAt(0)); |
| 2005 } else { | 1975 } else { |
| 2006 VisitUnop(node, UseInfo::AnyTagged(), | 1976 VisitUnop(node, UseInfo::AnyTagged(), |
| 2007 MachineRepresentation::kWord32); | 1977 MachineRepresentation::kWord32); |
| 2008 if (lower()) { | 1978 if (lower()) { |
| 2009 NodeProperties::ChangeOp(node, | 1979 NodeProperties::ChangeOp(node, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2021 MachineRepresentation::kFloat64); | 1991 MachineRepresentation::kFloat64); |
| 2022 if (lower()) { | 1992 if (lower()) { |
| 2023 NodeProperties::ChangeOp(node, | 1993 NodeProperties::ChangeOp(node, |
| 2024 simplified()->PlainPrimitiveToFloat64()); | 1994 simplified()->PlainPrimitiveToFloat64()); |
| 2025 } | 1995 } |
| 2026 } | 1996 } |
| 2027 } else { | 1997 } else { |
| 2028 VisitUnop(node, UseInfo::AnyTagged(), MachineRepresentation::kTagged); | 1998 VisitUnop(node, UseInfo::AnyTagged(), MachineRepresentation::kTagged); |
| 2029 } | 1999 } |
| 2030 return; | 2000 return; |
| 2001 } |
| 2031 case IrOpcode::kObjectIsCallable: | 2002 case IrOpcode::kObjectIsCallable: |
| 2032 case IrOpcode::kObjectIsNumber: | 2003 case IrOpcode::kObjectIsNumber: |
| 2033 case IrOpcode::kObjectIsReceiver: | 2004 case IrOpcode::kObjectIsReceiver: |
| 2034 case IrOpcode::kObjectIsSmi: | 2005 case IrOpcode::kObjectIsSmi: |
| 2035 case IrOpcode::kObjectIsString: | 2006 case IrOpcode::kObjectIsString: |
| 2036 case IrOpcode::kObjectIsUndetectable: { | 2007 case IrOpcode::kObjectIsUndetectable: { |
| 2037 ProcessInput(node, 0, UseInfo::AnyTagged()); | 2008 ProcessInput(node, 0, UseInfo::AnyTagged()); |
| 2038 SetOutput(node, MachineRepresentation::kBit); | 2009 SetOutput(node, MachineRepresentation::kBit); |
| 2039 return; | 2010 return; |
| 2040 } | 2011 } |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3263 void SimplifiedLowering::DoShift(Node* node, Operator const* op, | 3234 void SimplifiedLowering::DoShift(Node* node, Operator const* op, |
| 3264 Type* rhs_type) { | 3235 Type* rhs_type) { |
| 3265 Node* const rhs = NodeProperties::GetValueInput(node, 1); | 3236 Node* const rhs = NodeProperties::GetValueInput(node, 1); |
| 3266 if (!rhs_type->Is(type_cache_.kZeroToThirtyOne)) { | 3237 if (!rhs_type->Is(type_cache_.kZeroToThirtyOne)) { |
| 3267 node->ReplaceInput(1, graph()->NewNode(machine()->Word32And(), rhs, | 3238 node->ReplaceInput(1, graph()->NewNode(machine()->Word32And(), rhs, |
| 3268 jsgraph()->Int32Constant(0x1f))); | 3239 jsgraph()->Int32Constant(0x1f))); |
| 3269 } | 3240 } |
| 3270 NodeProperties::ChangeOp(node, op); | 3241 NodeProperties::ChangeOp(node, op); |
| 3271 } | 3242 } |
| 3272 | 3243 |
| 3244 void SimplifiedLowering::DoStringToNumber(Node* node) { |
| 3245 Operator::Properties properties = Operator::kEliminatable; |
| 3246 Callable callable = CodeFactory::StringToNumber(isolate()); |
| 3247 CallDescriptor::Flags flags = CallDescriptor::kNoFlags; |
| 3248 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 3249 isolate(), graph()->zone(), callable.descriptor(), 0, flags, properties); |
| 3250 node->InsertInput(graph()->zone(), 0, |
| 3251 jsgraph()->HeapConstant(callable.code())); |
| 3252 node->AppendInput(graph()->zone(), jsgraph()->NoContextConstant()); |
| 3253 node->AppendInput(graph()->zone(), graph()->start()); |
| 3254 NodeProperties::ChangeOp(node, common()->Call(desc)); |
| 3255 } |
| 3256 |
| 3273 Node* SimplifiedLowering::ToNumberCode() { | 3257 Node* SimplifiedLowering::ToNumberCode() { |
| 3274 if (!to_number_code_.is_set()) { | 3258 if (!to_number_code_.is_set()) { |
| 3275 Callable callable = CodeFactory::ToNumber(isolate()); | 3259 Callable callable = CodeFactory::ToNumber(isolate()); |
| 3276 to_number_code_.set(jsgraph()->HeapConstant(callable.code())); | 3260 to_number_code_.set(jsgraph()->HeapConstant(callable.code())); |
| 3277 } | 3261 } |
| 3278 return to_number_code_.get(); | 3262 return to_number_code_.get(); |
| 3279 } | 3263 } |
| 3280 | 3264 |
| 3281 Operator const* SimplifiedLowering::ToNumberOperator() { | 3265 Operator const* SimplifiedLowering::ToNumberOperator() { |
| 3282 if (!to_number_operator_.is_set()) { | 3266 if (!to_number_operator_.is_set()) { |
| 3283 Callable callable = CodeFactory::ToNumber(isolate()); | 3267 Callable callable = CodeFactory::ToNumber(isolate()); |
| 3284 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState; | 3268 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState; |
| 3285 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 3269 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 3286 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 3270 isolate(), graph()->zone(), callable.descriptor(), 0, flags, |
| 3287 Operator::kNoProperties); | 3271 Operator::kNoProperties); |
| 3288 to_number_operator_.set(common()->Call(desc)); | 3272 to_number_operator_.set(common()->Call(desc)); |
| 3289 } | 3273 } |
| 3290 return to_number_operator_.get(); | 3274 return to_number_operator_.get(); |
| 3291 } | 3275 } |
| 3292 | 3276 |
| 3293 } // namespace compiler | 3277 } // namespace compiler |
| 3294 } // namespace internal | 3278 } // namespace internal |
| 3295 } // namespace v8 | 3279 } // namespace v8 |
| OLD | NEW |