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 (use_value->IsPhi()) { | 38 if (use_value->IsPhi()) { |
39 next = use_value->block()->predecessors()->at(use_index)->end(); | 39 next = use_value->block()->predecessors()->at(use_index)->end(); |
40 } else { | 40 } else { |
41 next = HInstruction::cast(use_value); | 41 next = HInstruction::cast(use_value); |
42 } | 42 } |
43 // For constants we try to make the representation change at compile | 43 // For constants we try to make the representation change at compile |
44 // time. When a representation change is not possible without loss of | 44 // time. When a representation change is not possible without loss of |
45 // information we treat constants like normal instructions and insert the | 45 // information we treat constants like normal instructions and insert the |
46 // change instructions for them. | 46 // change instructions for them. |
47 HInstruction* new_value = NULL; | 47 HInstruction* new_value = NULL; |
48 bool is_truncating = use_value->CheckFlag(HValue::kTruncatingToInt32); | 48 bool is_truncating_to_smi = use_value->CheckFlag(HValue::kTruncatingToSmi); |
| 49 bool is_truncating_to_int = use_value->CheckFlag(HValue::kTruncatingToInt32); |
49 bool allow_undefined_as_nan = | 50 bool allow_undefined_as_nan = |
50 use_value->CheckFlag(HValue::kAllowUndefinedAsNaN); | 51 use_value->CheckFlag(HValue::kAllowUndefinedAsNaN); |
51 if (value->IsConstant()) { | 52 if (value->IsConstant()) { |
52 HConstant* constant = HConstant::cast(value); | 53 HConstant* constant = HConstant::cast(value); |
53 // Try to create a new copy of the constant with the new representation. | 54 // Try to create a new copy of the constant with the new representation. |
54 new_value = (is_truncating && to.IsInteger32()) | 55 if (is_truncating_to_int && to.IsInteger32()) { |
55 ? constant->CopyToTruncatedInt32(graph()->zone()) | 56 Maybe<HConstant*> res = constant->CopyToTruncatedInt32(graph()->zone()); |
56 : constant->CopyToRepresentation(to, graph()->zone()); | 57 if (res.has_value) new_value = res.value; |
| 58 } else { |
| 59 new_value = constant->CopyToRepresentation(to, graph()->zone()); |
| 60 } |
57 } | 61 } |
58 | 62 |
59 if (new_value == NULL) { | 63 if (new_value == NULL) { |
60 new_value = new(graph()->zone()) HChange(value, to, | 64 new_value = new(graph()->zone()) HChange(value, to, |
61 is_truncating, | 65 is_truncating_to_smi, |
| 66 is_truncating_to_int, |
62 allow_undefined_as_nan); | 67 allow_undefined_as_nan); |
63 } | 68 } |
64 | 69 |
65 new_value->InsertBefore(next); | 70 new_value->InsertBefore(next); |
66 use_value->SetOperandAt(use_index, new_value); | 71 use_value->SetOperandAt(use_index, new_value); |
67 } | 72 } |
68 | 73 |
69 | 74 |
70 void HRepresentationChangesPhase::InsertRepresentationChangesForValue( | 75 void HRepresentationChangesPhase::InsertRepresentationChangesForValue( |
71 HValue* value) { | 76 HValue* value) { |
(...skipping 26 matching lines...) Expand all Loading... |
98 // int32-phis allow truncation and iteratively remove the ones that | 103 // int32-phis allow truncation and iteratively remove the ones that |
99 // are used in an operation that does not allow a truncating | 104 // are used in an operation that does not allow a truncating |
100 // conversion. | 105 // conversion. |
101 ZoneList<HPhi*> worklist(8, zone()); | 106 ZoneList<HPhi*> worklist(8, zone()); |
102 | 107 |
103 const ZoneList<HPhi*>* phi_list(graph()->phi_list()); | 108 const ZoneList<HPhi*>* phi_list(graph()->phi_list()); |
104 for (int i = 0; i < phi_list->length(); i++) { | 109 for (int i = 0; i < phi_list->length(); i++) { |
105 HPhi* phi = phi_list->at(i); | 110 HPhi* phi = phi_list->at(i); |
106 if (phi->representation().IsInteger32()) { | 111 if (phi->representation().IsInteger32()) { |
107 phi->SetFlag(HValue::kTruncatingToInt32); | 112 phi->SetFlag(HValue::kTruncatingToInt32); |
| 113 } else if (phi->representation().IsSmi()) { |
| 114 phi->SetFlag(HValue::kTruncatingToSmi); |
108 } | 115 } |
109 } | 116 } |
110 | 117 |
111 for (int i = 0; i < phi_list->length(); i++) { | 118 for (int i = 0; i < phi_list->length(); i++) { |
112 HPhi* phi = phi_list->at(i); | 119 HPhi* phi = phi_list->at(i); |
113 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { | 120 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { |
114 // If a Phi is used as a non-truncating int32 or as a double, | 121 // If a Phi is used as a non-truncating int32 or as a double, |
115 // clear its "truncating" flag. | 122 // clear its "truncating" flag. |
116 HValue* use = it.value(); | 123 HValue* use = it.value(); |
117 Representation input_representation = | 124 Representation input_representation = |
118 use->RequiredInputRepresentation(it.index()); | 125 use->RequiredInputRepresentation(it.index()); |
119 if (!input_representation.IsInteger32() || | 126 if ((phi->representation().IsInteger32() && |
120 !use->CheckFlag(HValue::kTruncatingToInt32)) { | 127 !(input_representation.IsInteger32() && |
| 128 use->CheckFlag(HValue::kTruncatingToInt32))) || |
| 129 (phi->representation().IsSmi() && |
| 130 !(input_representation.IsSmi() || |
| 131 use->CheckFlag(HValue::kTruncatingToSmi)))) { |
121 if (FLAG_trace_representation) { | 132 if (FLAG_trace_representation) { |
122 PrintF("#%d Phi is not truncating because of #%d %s\n", | 133 PrintF("#%d Phi is not truncating because of #%d %s\n", |
123 phi->id(), it.value()->id(), it.value()->Mnemonic()); | 134 phi->id(), it.value()->id(), it.value()->Mnemonic()); |
124 } | 135 } |
125 phi->ClearFlag(HValue::kTruncatingToInt32); | 136 phi->ClearFlag(HValue::kTruncatingToInt32); |
| 137 phi->ClearFlag(HValue::kTruncatingToSmi); |
126 worklist.Add(phi, zone()); | 138 worklist.Add(phi, zone()); |
127 break; | 139 break; |
128 } | 140 } |
129 } | 141 } |
130 } | 142 } |
131 | 143 |
132 while (!worklist.is_empty()) { | 144 while (!worklist.is_empty()) { |
133 HPhi* current = worklist.RemoveLast(); | 145 HPhi* current = worklist.RemoveLast(); |
134 for (int i = 0; i < current->OperandCount(); ++i) { | 146 for (int i = 0; i < current->OperandCount(); ++i) { |
135 HValue* input = current->OperandAt(i); | 147 HValue* input = current->OperandAt(i); |
136 if (input->IsPhi() && | 148 if (input->IsPhi() && |
137 input->representation().IsInteger32() && | 149 ((input->representation().IsInteger32() && |
138 input->CheckFlag(HValue::kTruncatingToInt32)) { | 150 input->CheckFlag(HValue::kTruncatingToInt32)) || |
| 151 (input->representation().IsSmi() && |
| 152 input->CheckFlag(HValue::kTruncatingToSmi)))) { |
139 if (FLAG_trace_representation) { | 153 if (FLAG_trace_representation) { |
140 PrintF("#%d Phi is not truncating because of #%d %s\n", | 154 PrintF("#%d Phi is not truncating because of #%d %s\n", |
141 input->id(), current->id(), current->Mnemonic()); | 155 input->id(), current->id(), current->Mnemonic()); |
142 } | 156 } |
143 input->ClearFlag(HValue::kTruncatingToInt32); | 157 input->ClearFlag(HValue::kTruncatingToInt32); |
| 158 input->ClearFlag(HValue::kTruncatingToSmi); |
144 worklist.Add(HPhi::cast(input), zone()); | 159 worklist.Add(HPhi::cast(input), zone()); |
145 } | 160 } |
146 } | 161 } |
147 } | 162 } |
148 | 163 |
149 const ZoneList<HBasicBlock*>* blocks(graph()->blocks()); | 164 const ZoneList<HBasicBlock*>* blocks(graph()->blocks()); |
150 for (int i = 0; i < blocks->length(); ++i) { | 165 for (int i = 0; i < blocks->length(); ++i) { |
151 // Process phi instructions first. | 166 // Process phi instructions first. |
152 const HBasicBlock* block(blocks->at(i)); | 167 const HBasicBlock* block(blocks->at(i)); |
153 const ZoneList<HPhi*>* phis = block->phis(); | 168 const ZoneList<HPhi*>* phis = block->phis(); |
154 for (int j = 0; j < phis->length(); j++) { | 169 for (int j = 0; j < phis->length(); j++) { |
155 InsertRepresentationChangesForValue(phis->at(j)); | 170 InsertRepresentationChangesForValue(phis->at(j)); |
156 } | 171 } |
157 | 172 |
158 // Process normal instructions. | 173 // Process normal instructions. |
159 for (HInstruction* current = block->first(); current != NULL; ) { | 174 for (HInstruction* current = block->first(); current != NULL; ) { |
160 HInstruction* next = current->next(); | 175 HInstruction* next = current->next(); |
161 InsertRepresentationChangesForValue(current); | 176 InsertRepresentationChangesForValue(current); |
162 current = next; | 177 current = next; |
163 } | 178 } |
164 } | 179 } |
165 } | 180 } |
166 | 181 |
167 } } // namespace v8::internal | 182 } } // namespace v8::internal |
OLD | NEW |