OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (current->IsChange()) { | 38 if (current->IsChange()) { |
39 HChange* change = HChange::cast(current); | 39 HChange* change = HChange::cast(current); |
40 // Propagate flags for negative zero checks upwards from conversions | 40 // Propagate flags for negative zero checks upwards from conversions |
41 // int32-to-tagged and int32-to-double. | 41 // int32-to-tagged and int32-to-double. |
42 Representation from = change->value()->representation(); | 42 Representation from = change->value()->representation(); |
43 ASSERT(from.Equals(change->from())); | 43 ASSERT(from.Equals(change->from())); |
44 if (from.IsSmiOrInteger32()) { | 44 if (from.IsSmiOrInteger32()) { |
45 ASSERT(change->to().IsTagged() || | 45 ASSERT(change->to().IsTagged() || |
46 change->to().IsDouble() || | 46 change->to().IsDouble() || |
47 change->to().IsSmiOrInteger32()); | 47 change->to().IsSmiOrInteger32()); |
48 ASSERT(visited_.IsEmpty()); | |
49 PropagateMinusZeroChecks(change->value()); | 48 PropagateMinusZeroChecks(change->value()); |
50 visited_.Clear(); | |
51 } | 49 } |
52 } else if (current->IsCompareMinusZeroAndBranch()) { | 50 } else if (current->IsCompareMinusZeroAndBranch()) { |
53 HCompareMinusZeroAndBranch* check = | 51 HCompareMinusZeroAndBranch* check = |
54 HCompareMinusZeroAndBranch::cast(current); | 52 HCompareMinusZeroAndBranch::cast(current); |
55 if (check->value()->representation().IsSmiOrInteger32()) { | 53 if (check->value()->representation().IsSmiOrInteger32()) { |
56 ASSERT(visited_.IsEmpty()); | |
57 PropagateMinusZeroChecks(check->value()); | 54 PropagateMinusZeroChecks(check->value()); |
58 visited_.Clear(); | |
59 } | 55 } |
60 } | 56 } |
61 } | 57 } |
62 } | 58 } |
63 } | 59 } |
64 | 60 |
65 | 61 |
66 void HComputeMinusZeroChecksPhase::PropagateMinusZeroChecks(HValue* value) { | 62 void HComputeMinusZeroChecksPhase::PropagateMinusZeroChecks(HValue* value) { |
67 for (HValue* current = value; | 63 ASSERT(worklist_.is_empty()); |
68 current != NULL && !visited_.Contains(current->id()); | 64 ASSERT(in_worklist_.IsEmpty()); |
69 current = current->EnsureAndPropagateNotMinusZero(&visited_)) { | 65 |
70 // For phis, we must propagate the check to all of its inputs. | 66 AddToWorklist(value); |
71 if (current->IsPhi()) { | 67 while (!worklist_.is_empty()) { |
72 visited_.Add(current->id()); | 68 value = worklist_.RemoveLast(); |
73 HPhi* phi = HPhi::cast(current); | 69 |
| 70 if (value->IsPhi()) { |
| 71 // For phis, we must propagate the check to all of its inputs. |
| 72 HPhi* phi = HPhi::cast(value); |
74 for (int i = 0; i < phi->OperandCount(); ++i) { | 73 for (int i = 0; i < phi->OperandCount(); ++i) { |
75 PropagateMinusZeroChecks(phi->OperandAt(i)); | 74 AddToWorklist(phi->OperandAt(i)); |
76 } | 75 } |
77 break; | 76 } else if (value->IsUnaryMathOperation()) { |
78 } | 77 HUnaryMathOperation* instr = HUnaryMathOperation::cast(value); |
79 | 78 if (instr->representation().IsSmiOrInteger32() && |
80 // For multiplication, division, and Math.min/max(), we must propagate | 79 !instr->value()->representation().Equals(instr->representation())) { |
81 // to the left and the right side. | 80 if (instr->value()->range() == NULL || |
82 if (current->IsMul() || current->IsDiv() || current->IsMathMinMax()) { | 81 instr->value()->range()->CanBeMinusZero()) { |
83 HBinaryOperation* operation = HBinaryOperation::cast(current); | 82 instr->SetFlag(HValue::kBailoutOnMinusZero); |
84 operation->EnsureAndPropagateNotMinusZero(&visited_); | 83 } |
85 PropagateMinusZeroChecks(operation->left()); | 84 } |
86 PropagateMinusZeroChecks(operation->right()); | 85 if (instr->RequiredInputRepresentation(0).IsSmiOrInteger32() && |
| 86 instr->representation().Equals( |
| 87 instr->RequiredInputRepresentation(0))) { |
| 88 AddToWorklist(instr->value()); |
| 89 } |
| 90 } else if (value->IsChange()) { |
| 91 HChange* instr = HChange::cast(value); |
| 92 if (!instr->from().IsSmiOrInteger32() && |
| 93 !instr->CanTruncateToInt32() && |
| 94 (instr->value()->range() == NULL || |
| 95 instr->value()->range()->CanBeMinusZero())) { |
| 96 instr->SetFlag(HValue::kBailoutOnMinusZero); |
| 97 } |
| 98 } else if (value->IsForceRepresentation()) { |
| 99 HForceRepresentation* instr = HForceRepresentation::cast(value); |
| 100 AddToWorklist(instr->value()); |
| 101 } else if (value->IsMod()) { |
| 102 HMod* instr = HMod::cast(value); |
| 103 if (instr->range() == NULL || instr->range()->CanBeMinusZero()) { |
| 104 instr->SetFlag(HValue::kBailoutOnMinusZero); |
| 105 AddToWorklist(instr->left()); |
| 106 } |
| 107 } else if (value->IsDiv() || value->IsMul()) { |
| 108 HBinaryOperation* instr = HBinaryOperation::cast(value); |
| 109 if (instr->range() == NULL || instr->range()->CanBeMinusZero()) { |
| 110 instr->SetFlag(HValue::kBailoutOnMinusZero); |
| 111 } |
| 112 AddToWorklist(instr->right()); |
| 113 AddToWorklist(instr->left()); |
| 114 } else if (value->IsMathFloorOfDiv()) { |
| 115 HMathFloorOfDiv* instr = HMathFloorOfDiv::cast(value); |
| 116 instr->SetFlag(HValue::kBailoutOnMinusZero); |
| 117 } else if (value->IsAdd() || value->IsSub()) { |
| 118 HBinaryOperation* instr = HBinaryOperation::cast(value); |
| 119 if (instr->range() == NULL || instr->range()->CanBeMinusZero()) { |
| 120 // Propagate to the left argument. If the left argument cannot be -0, |
| 121 // then the result of the add/sub operation cannot be either. |
| 122 AddToWorklist(instr->left()); |
| 123 } |
| 124 } else if (value->IsMathMinMax()) { |
| 125 HMathMinMax* instr = HMathMinMax::cast(value); |
| 126 AddToWorklist(instr->right()); |
| 127 AddToWorklist(instr->left()); |
87 } | 128 } |
88 } | 129 } |
| 130 |
| 131 in_worklist_.Clear(); |
| 132 ASSERT(in_worklist_.IsEmpty()); |
| 133 ASSERT(worklist_.is_empty()); |
89 } | 134 } |
90 | 135 |
91 } } // namespace v8::internal | 136 } } // namespace v8::internal |
OLD | NEW |