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 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 break; | 1039 break; |
1040 } | 1040 } |
1041 case IrOpcode::kNumberBitwiseOr: | 1041 case IrOpcode::kNumberBitwiseOr: |
1042 case IrOpcode::kNumberBitwiseXor: | 1042 case IrOpcode::kNumberBitwiseXor: |
1043 case IrOpcode::kNumberBitwiseAnd: { | 1043 case IrOpcode::kNumberBitwiseAnd: { |
1044 VisitInt32Binop(node); | 1044 VisitInt32Binop(node); |
1045 if (lower()) NodeProperties::ChangeOp(node, Int32Op(node)); | 1045 if (lower()) NodeProperties::ChangeOp(node, Int32Op(node)); |
1046 break; | 1046 break; |
1047 } | 1047 } |
1048 case IrOpcode::kNumberShiftLeft: { | 1048 case IrOpcode::kNumberShiftLeft: { |
| 1049 Type* rhs_type = GetInfo(node->InputAt(1))->output_type(); |
1049 VisitBinop(node, UseInfo::TruncatingWord32(), | 1050 VisitBinop(node, UseInfo::TruncatingWord32(), |
1050 UseInfo::TruncatingWord32(), NodeOutputInfo::Int32()); | 1051 UseInfo::TruncatingWord32(), NodeOutputInfo::Int32()); |
1051 if (lower()) lowering->DoShift(node, lowering->machine()->Word32Shl()); | 1052 if (lower()) { |
| 1053 lowering->DoShift(node, lowering->machine()->Word32Shl(), rhs_type); |
| 1054 } |
1052 break; | 1055 break; |
1053 } | 1056 } |
1054 case IrOpcode::kNumberShiftRight: { | 1057 case IrOpcode::kNumberShiftRight: { |
| 1058 Type* rhs_type = GetInfo(node->InputAt(1))->output_type(); |
1055 VisitBinop(node, UseInfo::TruncatingWord32(), | 1059 VisitBinop(node, UseInfo::TruncatingWord32(), |
1056 UseInfo::TruncatingWord32(), NodeOutputInfo::Int32()); | 1060 UseInfo::TruncatingWord32(), NodeOutputInfo::Int32()); |
1057 if (lower()) lowering->DoShift(node, lowering->machine()->Word32Sar()); | 1061 if (lower()) { |
| 1062 lowering->DoShift(node, lowering->machine()->Word32Sar(), rhs_type); |
| 1063 } |
1058 break; | 1064 break; |
1059 } | 1065 } |
1060 case IrOpcode::kNumberShiftRightLogical: { | 1066 case IrOpcode::kNumberShiftRightLogical: { |
| 1067 Type* rhs_type = GetInfo(node->InputAt(1))->output_type(); |
1061 VisitBinop(node, UseInfo::TruncatingWord32(), | 1068 VisitBinop(node, UseInfo::TruncatingWord32(), |
1062 UseInfo::TruncatingWord32(), NodeOutputInfo::Uint32()); | 1069 UseInfo::TruncatingWord32(), NodeOutputInfo::Uint32()); |
1063 if (lower()) lowering->DoShift(node, lowering->machine()->Word32Shr()); | 1070 if (lower()) { |
| 1071 lowering->DoShift(node, lowering->machine()->Word32Shr(), rhs_type); |
| 1072 } |
1064 break; | 1073 break; |
1065 } | 1074 } |
1066 case IrOpcode::kNumberToInt32: { | 1075 case IrOpcode::kNumberToInt32: { |
1067 // Just change representation if necessary. | 1076 // Just change representation if necessary. |
1068 VisitUnop(node, UseInfo::TruncatingWord32(), NodeOutputInfo::Int32()); | 1077 VisitUnop(node, UseInfo::TruncatingWord32(), NodeOutputInfo::Int32()); |
1069 if (lower()) DeferReplacement(node, node->InputAt(0)); | 1078 if (lower()) DeferReplacement(node, node->InputAt(0)); |
1070 break; | 1079 break; |
1071 } | 1080 } |
1072 case IrOpcode::kNumberToUint32: { | 1081 case IrOpcode::kNumberToUint32: { |
1073 // Just change representation if necessary. | 1082 // Just change representation if necessary. |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 break; | 1408 break; |
1400 } | 1409 } |
1401 } | 1410 } |
1402 | 1411 |
1403 void DeferReplacement(Node* node, Node* replacement) { | 1412 void DeferReplacement(Node* node, Node* replacement) { |
1404 TRACE("defer replacement #%d:%s with #%d:%s\n", node->id(), | 1413 TRACE("defer replacement #%d:%s with #%d:%s\n", node->id(), |
1405 node->op()->mnemonic(), replacement->id(), | 1414 node->op()->mnemonic(), replacement->id(), |
1406 replacement->op()->mnemonic()); | 1415 replacement->op()->mnemonic()); |
1407 | 1416 |
1408 if (replacement->id() < count_ && | 1417 if (replacement->id() < count_ && |
1409 GetInfo(replacement)->output_type() == GetInfo(node)->output_type()) { | 1418 GetInfo(node)->output_type()->Is(GetInfo(replacement)->output_type())) { |
1410 // Replace with a previously existing node eagerly only if the type is the | 1419 // Replace with a previously existing node eagerly only if the type is the |
1411 // same. | 1420 // same. |
1412 node->ReplaceUses(replacement); | 1421 node->ReplaceUses(replacement); |
1413 } else { | 1422 } else { |
1414 // Otherwise, we are replacing a node with a representation change. | 1423 // Otherwise, we are replacing a node with a representation change. |
1415 // Such a substitution must be done after all lowering is done, because | 1424 // Such a substitution must be done after all lowering is done, because |
1416 // changing the type could confuse the representation change | 1425 // changing the type could confuse the representation change |
1417 // insertion for uses of the node. | 1426 // insertion for uses of the node. |
1418 replacements_.push_back(node); | 1427 replacements_.push_back(node); |
1419 replacements_.push_back(replacement); | 1428 replacements_.push_back(replacement); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 } | 1870 } |
1862 | 1871 |
1863 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); | 1872 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); |
1864 Node* false0 = zero; | 1873 Node* false0 = zero; |
1865 | 1874 |
1866 Node* merge0 = graph()->NewNode(merge_op, if_true0, if_false0); | 1875 Node* merge0 = graph()->NewNode(merge_op, if_true0, if_false0); |
1867 return graph()->NewNode(phi_op, true0, false0, merge0); | 1876 return graph()->NewNode(phi_op, true0, false0, merge0); |
1868 } | 1877 } |
1869 | 1878 |
1870 | 1879 |
1871 void SimplifiedLowering::DoShift(Node* node, Operator const* op) { | 1880 void SimplifiedLowering::DoShift(Node* node, Operator const* op, |
| 1881 Type* rhs_type) { |
1872 Node* const rhs = NodeProperties::GetValueInput(node, 1); | 1882 Node* const rhs = NodeProperties::GetValueInput(node, 1); |
1873 Type* const rhs_type = NodeProperties::GetType(rhs); | |
1874 if (!rhs_type->Is(type_cache_.kZeroToThirtyOne)) { | 1883 if (!rhs_type->Is(type_cache_.kZeroToThirtyOne)) { |
1875 node->ReplaceInput(1, graph()->NewNode(machine()->Word32And(), rhs, | 1884 node->ReplaceInput(1, graph()->NewNode(machine()->Word32And(), rhs, |
1876 jsgraph()->Int32Constant(0x1f))); | 1885 jsgraph()->Int32Constant(0x1f))); |
1877 } | 1886 } |
1878 NodeProperties::ChangeOp(node, op); | 1887 NodeProperties::ChangeOp(node, op); |
1879 } | 1888 } |
1880 | 1889 |
1881 | 1890 |
1882 namespace { | 1891 namespace { |
1883 | 1892 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1921 ReplaceEffectUses(node, comparison); | 1930 ReplaceEffectUses(node, comparison); |
1922 node->ReplaceInput(0, comparison); | 1931 node->ReplaceInput(0, comparison); |
1923 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); | 1932 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); |
1924 node->TrimInputCount(2); | 1933 node->TrimInputCount(2); |
1925 NodeProperties::ChangeOp(node, machine()->IntLessThanOrEqual()); | 1934 NodeProperties::ChangeOp(node, machine()->IntLessThanOrEqual()); |
1926 } | 1935 } |
1927 | 1936 |
1928 } // namespace compiler | 1937 } // namespace compiler |
1929 } // namespace internal | 1938 } // namespace internal |
1930 } // namespace v8 | 1939 } // namespace v8 |
OLD | NEW |