Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: src/compiler/effect-control-linearizer.cc

Issue 2138633002: [turbofan] Introduce CheckedInt32Div and CheckedInt32Mod operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/effect-control-linearizer.h ('k') | src/compiler/js-typed-lowering.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/effect-control-linearizer.h" 5 #include "src/compiler/effect-control-linearizer.h"
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/compiler/access-builder.h" 8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/js-graph.h" 9 #include "src/compiler/js-graph.h"
10 #include "src/compiler/linkage.h" 10 #include "src/compiler/linkage.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 break; 442 break;
443 case IrOpcode::kCheckTaggedSigned: 443 case IrOpcode::kCheckTaggedSigned:
444 state = LowerCheckTaggedSigned(node, frame_state, *effect, *control); 444 state = LowerCheckTaggedSigned(node, frame_state, *effect, *control);
445 break; 445 break;
446 case IrOpcode::kCheckedInt32Add: 446 case IrOpcode::kCheckedInt32Add:
447 state = LowerCheckedInt32Add(node, frame_state, *effect, *control); 447 state = LowerCheckedInt32Add(node, frame_state, *effect, *control);
448 break; 448 break;
449 case IrOpcode::kCheckedInt32Sub: 449 case IrOpcode::kCheckedInt32Sub:
450 state = LowerCheckedInt32Sub(node, frame_state, *effect, *control); 450 state = LowerCheckedInt32Sub(node, frame_state, *effect, *control);
451 break; 451 break;
452 case IrOpcode::kCheckedInt32Div:
453 state = LowerCheckedInt32Div(node, frame_state, *effect, *control);
454 break;
455 case IrOpcode::kCheckedInt32Mod:
456 state = LowerCheckedInt32Mod(node, frame_state, *effect, *control);
457 break;
452 case IrOpcode::kCheckedUint32ToInt32: 458 case IrOpcode::kCheckedUint32ToInt32:
453 state = LowerCheckedUint32ToInt32(node, frame_state, *effect, *control); 459 state = LowerCheckedUint32ToInt32(node, frame_state, *effect, *control);
454 break; 460 break;
455 case IrOpcode::kCheckedFloat64ToInt32: 461 case IrOpcode::kCheckedFloat64ToInt32:
456 state = LowerCheckedFloat64ToInt32(node, frame_state, *effect, *control); 462 state = LowerCheckedFloat64ToInt32(node, frame_state, *effect, *control);
457 break; 463 break;
458 case IrOpcode::kCheckedTaggedToInt32: 464 case IrOpcode::kCheckedTaggedToInt32:
459 state = LowerCheckedTaggedToInt32(node, frame_state, *effect, *control); 465 state = LowerCheckedTaggedToInt32(node, frame_state, *effect, *control);
460 break; 466 break;
461 case IrOpcode::kCheckedTaggedToFloat64: 467 case IrOpcode::kCheckedTaggedToFloat64:
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 924
919 value = graph()->NewNode(common()->Projection(0), value, control); 925 value = graph()->NewNode(common()->Projection(0), value, control);
920 926
921 // Make sure the lowered node does not appear in any use lists. 927 // Make sure the lowered node does not appear in any use lists.
922 node->TrimInputCount(0); 928 node->TrimInputCount(0);
923 929
924 return ValueEffectControl(value, effect, control); 930 return ValueEffectControl(value, effect, control);
925 } 931 }
926 932
927 EffectControlLinearizer::ValueEffectControl 933 EffectControlLinearizer::ValueEffectControl
934 EffectControlLinearizer::LowerCheckedInt32Div(Node* node, Node* frame_state,
935 Node* effect, Node* control) {
936 Node* zero = jsgraph()->Int32Constant(0);
937 Node* minusone = jsgraph()->Int32Constant(-1);
938 Node* minint = jsgraph()->Int32Constant(std::numeric_limits<int32_t>::min());
939
940 Node* lhs = node->InputAt(0);
941 Node* rhs = node->InputAt(1);
942
943 // Check if {rhs} is positive (and not zero).
944 Node* check0 = graph()->NewNode(machine()->Int32LessThan(), zero, rhs);
945 Node* branch0 =
946 graph()->NewNode(common()->Branch(BranchHint::kTrue), check0, control);
947
948 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
949 Node* etrue0 = effect;
950 Node* vtrue0;
951 {
952 // Fast case, no additional checking required.
953 vtrue0 = graph()->NewNode(machine()->Int32Div(), lhs, rhs, if_true0);
954 }
955
956 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
957 Node* efalse0 = effect;
958 Node* vfalse0;
959 {
960 // Check if {rhs} is zero.
961 Node* check = graph()->NewNode(machine()->Word32Equal(), rhs, zero);
962 if_false0 = efalse0 = graph()->NewNode(common()->DeoptimizeIf(), check,
963 frame_state, efalse0, if_false0);
964
965 // Check if {lhs} is zero, as that would produce minus zero.
966 check = graph()->NewNode(machine()->Word32Equal(), lhs, zero);
967 if_false0 = efalse0 = graph()->NewNode(common()->DeoptimizeIf(), check,
968 frame_state, efalse0, if_false0);
969
970 // Check if {lhs} is kMinInt and {rhs} is -1, in which case we'd have
971 // to return -kMinInt, which is not representable.
972 Node* check1 = graph()->NewNode(machine()->Word32Equal(), lhs, minint);
973 Node* branch1 = graph()->NewNode(common()->Branch(BranchHint::kFalse),
974 check1, if_false0);
975
976 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
977 Node* etrue1 = efalse0;
978 {
979 // Check if {rhs} is -1.
980 Node* check = graph()->NewNode(machine()->Word32Equal(), rhs, minusone);
981 if_true1 = etrue1 = graph()->NewNode(common()->DeoptimizeIf(), check,
982 frame_state, etrue1, if_true1);
983 }
984
985 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
986 Node* efalse1 = efalse0;
987
988 if_false0 = graph()->NewNode(common()->Merge(2), if_true1, if_false1);
989 efalse0 =
990 graph()->NewNode(common()->EffectPhi(2), etrue1, efalse1, if_false0);
991
992 // Perform the actual integer division.
993 vfalse0 = graph()->NewNode(machine()->Int32Div(), lhs, rhs, if_false0);
994 }
995
996 control = graph()->NewNode(common()->Merge(2), if_true0, if_false0);
997 effect = graph()->NewNode(common()->EffectPhi(2), etrue0, efalse0, control);
998 Node* value =
999 graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), vtrue0,
1000 vfalse0, control);
1001
1002 // Check if the remainder is non-zero.
1003 Node* check =
1004 graph()->NewNode(machine()->Word32Equal(), lhs,
1005 graph()->NewNode(machine()->Int32Mul(), rhs, value));
1006 control = effect = graph()->NewNode(common()->DeoptimizeUnless(), check,
1007 frame_state, effect, control);
1008
1009 // Make sure the lowered node does not appear in any use lists.
1010 node->TrimInputCount(0);
1011
1012 return ValueEffectControl(value, effect, control);
1013 }
1014
1015 EffectControlLinearizer::ValueEffectControl
1016 EffectControlLinearizer::LowerCheckedInt32Mod(Node* node, Node* frame_state,
1017 Node* effect, Node* control) {
1018 Node* zero = jsgraph()->Int32Constant(0);
1019 Node* minusone = jsgraph()->Int32Constant(-1);
1020 Node* minint = jsgraph()->Int32Constant(std::numeric_limits<int32_t>::min());
1021
1022 Node* lhs = node->InputAt(0);
1023 Node* rhs = node->InputAt(1);
1024
1025 // Ensure that {rhs} is not zero, otherwise we'd have to return NaN.
1026 Node* check = graph()->NewNode(machine()->Word32Equal(), rhs, zero);
1027 control = effect = graph()->NewNode(common()->DeoptimizeIf(), check,
1028 frame_state, effect, control);
1029
1030 // Check if {lhs} is positive or zero.
1031 Node* check0 = graph()->NewNode(machine()->Int32LessThanOrEqual(), zero, lhs);
1032 Node* branch0 =
1033 graph()->NewNode(common()->Branch(BranchHint::kTrue), check0, control);
1034
1035 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
1036 Node* etrue0 = effect;
1037 Node* vtrue0;
1038 {
1039 // Fast case, no additional checking required.
1040 vtrue0 = graph()->NewNode(machine()->Int32Mod(), lhs, rhs, if_true0);
1041 }
1042
1043 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
1044 Node* efalse0 = effect;
1045 Node* vfalse0;
1046 {
1047 // Check if {lhs} is kMinInt and {rhs} is -1, in which case we'd have
1048 // to return -0.
1049 Node* check1 = graph()->NewNode(machine()->Word32Equal(), lhs, minint);
1050 Node* branch1 = graph()->NewNode(common()->Branch(BranchHint::kFalse),
1051 check1, if_false0);
1052
1053 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
1054 Node* etrue1 = efalse0;
1055 {
1056 // Check if {rhs} is -1.
1057 Node* check = graph()->NewNode(machine()->Word32Equal(), rhs, minusone);
1058 if_true1 = etrue1 = graph()->NewNode(common()->DeoptimizeIf(), check,
1059 frame_state, etrue1, if_true1);
1060 }
1061
1062 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
1063 Node* efalse1 = efalse0;
1064
1065 if_false0 = graph()->NewNode(common()->Merge(2), if_true1, if_false1);
1066 efalse0 =
1067 graph()->NewNode(common()->EffectPhi(2), etrue1, efalse1, if_false0);
1068
1069 // Perform the actual integer modulos.
1070 vfalse0 = graph()->NewNode(machine()->Int32Mod(), lhs, rhs, if_false0);
1071
1072 // Check if the result is zero, because in that case we'd have to return
1073 // -0 here since we always take the signe of the {lhs} which is negative.
1074 Node* check = graph()->NewNode(machine()->Word32Equal(), vfalse0, zero);
1075 if_false0 = efalse0 = graph()->NewNode(common()->DeoptimizeIf(), check,
1076 frame_state, efalse0, if_false0);
1077 }
1078
1079 control = graph()->NewNode(common()->Merge(2), if_true0, if_false0);
1080 effect = graph()->NewNode(common()->EffectPhi(2), etrue0, efalse0, control);
1081 Node* value =
1082 graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), vtrue0,
1083 vfalse0, control);
1084
1085 // Make sure the lowered node does not appear in any use lists.
1086 node->TrimInputCount(0);
1087
1088 return ValueEffectControl(value, effect, control);
1089 }
1090
1091 EffectControlLinearizer::ValueEffectControl
928 EffectControlLinearizer::LowerCheckedUint32ToInt32(Node* node, 1092 EffectControlLinearizer::LowerCheckedUint32ToInt32(Node* node,
929 Node* frame_state, 1093 Node* frame_state,
930 Node* effect, 1094 Node* effect,
931 Node* control) { 1095 Node* control) {
932 Node* value = node->InputAt(0); 1096 Node* value = node->InputAt(0);
933 Node* max_int = jsgraph()->Int32Constant(std::numeric_limits<int32_t>::max()); 1097 Node* max_int = jsgraph()->Int32Constant(std::numeric_limits<int32_t>::max());
934 Node* is_safe = 1098 Node* is_safe =
935 graph()->NewNode(machine()->Uint32LessThanOrEqual(), value, max_int); 1099 graph()->NewNode(machine()->Uint32LessThanOrEqual(), value, max_int);
936 control = effect = graph()->NewNode(common()->DeoptimizeUnless(), is_safe, 1100 control = effect = graph()->NewNode(common()->DeoptimizeUnless(), is_safe,
937 frame_state, effect, control); 1101 frame_state, effect, control);
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 isolate(), graph()->zone(), callable.descriptor(), 0, flags, 1868 isolate(), graph()->zone(), callable.descriptor(), 0, flags,
1705 Operator::kNoThrow); 1869 Operator::kNoThrow);
1706 to_number_operator_.set(common()->Call(desc)); 1870 to_number_operator_.set(common()->Call(desc));
1707 } 1871 }
1708 return to_number_operator_.get(); 1872 return to_number_operator_.get();
1709 } 1873 }
1710 1874
1711 } // namespace compiler 1875 } // namespace compiler
1712 } // namespace internal 1876 } // namespace internal
1713 } // namespace v8 1877 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/effect-control-linearizer.h ('k') | src/compiler/js-typed-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698