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/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
6 #include "src/compiler/machine-operator.h" | 6 #include "src/compiler/machine-operator.h" |
7 | 7 |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) { | 104 Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) { |
105 Node* branch = graph()->NewNode(common()->Branch(), val, control); | 105 Node* branch = graph()->NewNode(common()->Branch(), val, control); |
106 | 106 |
107 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 107 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
108 Node* true_value = jsgraph()->TrueConstant(); | 108 Node* true_value = jsgraph()->TrueConstant(); |
109 | 109 |
110 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 110 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
111 Node* false_value = jsgraph()->FalseConstant(); | 111 Node* false_value = jsgraph()->FalseConstant(); |
112 | 112 |
113 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 113 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
114 Node* phi = | 114 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), true_value, |
titzer
2014/09/05 10:26:08
kTypeBool | kRepTagged
... not that it matters th
Benedikt Meurer
2014/09/05 10:50:49
Done.
| |
115 graph()->NewNode(common()->Phi(2), true_value, false_value, merge); | 115 false_value, merge); |
116 | 116 |
117 return Replace(phi); | 117 return Replace(phi); |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 Reduction ChangeLowering::ChangeBoolToBit(Node* val) { | 121 Reduction ChangeLowering::ChangeBoolToBit(Node* val) { |
122 return Replace( | 122 return Replace( |
123 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); | 123 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); |
124 } | 124 } |
125 | 125 |
(...skipping 17 matching lines...) Expand all Loading... | |
143 Node* branch = graph()->NewNode(common()->Branch(), ovf, control); | 143 Node* branch = graph()->NewNode(common()->Branch(), ovf, control); |
144 | 144 |
145 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 145 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
146 Node* heap_number = AllocateHeapNumberWithValue( | 146 Node* heap_number = AllocateHeapNumberWithValue( |
147 graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), if_true); | 147 graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), if_true); |
148 | 148 |
149 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 149 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
150 Node* smi = graph()->NewNode(common()->Projection(0), add); | 150 Node* smi = graph()->NewNode(common()->Projection(0), add); |
151 | 151 |
152 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 152 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
153 Node* phi = graph()->NewNode(common()->Phi(2), heap_number, smi, merge); | 153 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), heap_number, |
154 smi, merge); | |
154 | 155 |
155 return Replace(phi); | 156 return Replace(phi); |
156 } | 157 } |
157 | 158 |
158 | 159 |
159 Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control, | 160 Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control, |
160 Signedness signedness) { | 161 Signedness signedness) { |
161 STATIC_ASSERT(kSmiTag == 0); | 162 STATIC_ASSERT(kSmiTag == 0); |
162 STATIC_ASSERT(kSmiTagMask == 1); | 163 STATIC_ASSERT(kSmiTagMask == 1); |
163 | 164 |
164 Node* tag = graph()->NewNode(machine()->WordAnd(), val, | 165 Node* tag = graph()->NewNode(machine()->WordAnd(), val, |
165 jsgraph()->Int32Constant(kSmiTagMask)); | 166 jsgraph()->Int32Constant(kSmiTagMask)); |
166 Node* branch = graph()->NewNode(common()->Branch(), tag, control); | 167 Node* branch = graph()->NewNode(common()->Branch(), tag, control); |
167 | 168 |
168 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 169 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
169 Operator* op = (signedness == kSigned) ? machine()->ChangeFloat64ToInt32() | 170 Operator* op = (signedness == kSigned) ? machine()->ChangeFloat64ToInt32() |
170 : machine()->ChangeFloat64ToUint32(); | 171 : machine()->ChangeFloat64ToUint32(); |
171 Node* change = graph()->NewNode(op, LoadHeapNumberValue(val, if_true)); | 172 Node* change = graph()->NewNode(op, LoadHeapNumberValue(val, if_true)); |
172 | 173 |
173 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 174 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
174 Node* number = ChangeSmiToInt32(val); | 175 Node* number = ChangeSmiToInt32(val); |
175 | 176 |
176 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 177 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
177 Node* phi = graph()->NewNode(common()->Phi(2), change, number, merge); | 178 Node* phi = graph()->NewNode( |
179 common()->Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, 2), | |
180 change, number, merge); | |
178 | 181 |
179 return Replace(phi); | 182 return Replace(phi); |
180 } | 183 } |
181 | 184 |
182 | 185 |
183 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) { | 186 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) { |
184 STATIC_ASSERT(kSmiTag == 0); | 187 STATIC_ASSERT(kSmiTag == 0); |
185 STATIC_ASSERT(kSmiTagMask == 1); | 188 STATIC_ASSERT(kSmiTagMask == 1); |
186 | 189 |
187 Node* tag = graph()->NewNode(machine()->WordAnd(), val, | 190 Node* tag = graph()->NewNode(machine()->WordAnd(), val, |
188 jsgraph()->Int32Constant(kSmiTagMask)); | 191 jsgraph()->Int32Constant(kSmiTagMask)); |
189 Node* branch = graph()->NewNode(common()->Branch(), tag, control); | 192 Node* branch = graph()->NewNode(common()->Branch(), tag, control); |
190 | 193 |
191 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 194 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
192 Node* load = LoadHeapNumberValue(val, if_true); | 195 Node* load = LoadHeapNumberValue(val, if_true); |
193 | 196 |
194 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 197 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
195 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), | 198 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), |
196 ChangeSmiToInt32(val)); | 199 ChangeSmiToInt32(val)); |
197 | 200 |
198 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 201 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
199 Node* phi = graph()->NewNode(common()->Phi(2), load, number, merge); | 202 Node* phi = |
203 graph()->NewNode(common()->Phi(kMachFloat64, 2), load, number, merge); | |
200 | 204 |
201 return Replace(phi); | 205 return Replace(phi); |
202 } | 206 } |
203 | 207 |
204 | 208 |
205 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) { | 209 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) { |
206 STATIC_ASSERT(kSmiTag == 0); | 210 STATIC_ASSERT(kSmiTag == 0); |
207 STATIC_ASSERT(kSmiTagMask == 1); | 211 STATIC_ASSERT(kSmiTagMask == 1); |
208 | 212 |
209 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, | 213 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, |
210 SmiMaxValueConstant()); | 214 SmiMaxValueConstant()); |
211 Node* branch = graph()->NewNode(common()->Branch(), cmp, control); | 215 Node* branch = graph()->NewNode(common()->Branch(), cmp, control); |
212 | 216 |
213 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 217 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
214 Node* smi = graph()->NewNode( | 218 Node* smi = graph()->NewNode( |
215 machine()->WordShl(), | 219 machine()->WordShl(), |
216 machine()->is64() | 220 machine()->is64() |
217 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) | 221 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) |
218 : val, | 222 : val, |
219 SmiShiftBitsConstant()); | 223 SmiShiftBitsConstant()); |
220 | 224 |
221 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 225 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
222 Node* heap_number = AllocateHeapNumberWithValue( | 226 Node* heap_number = AllocateHeapNumberWithValue( |
223 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); | 227 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); |
224 | 228 |
225 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 229 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
226 Node* phi = graph()->NewNode(common()->Phi(2), smi, heap_number, merge); | 230 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), smi, |
231 heap_number, merge); | |
227 | 232 |
228 return Replace(phi); | 233 return Replace(phi); |
229 } | 234 } |
230 | 235 |
231 | 236 |
232 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } | 237 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } |
233 | 238 |
234 | 239 |
235 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } | 240 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } |
236 | 241 |
237 | 242 |
238 CommonOperatorBuilder* ChangeLowering::common() const { | 243 CommonOperatorBuilder* ChangeLowering::common() const { |
239 return jsgraph()->common(); | 244 return jsgraph()->common(); |
240 } | 245 } |
241 | 246 |
242 } // namespace compiler | 247 } // namespace compiler |
243 } // namespace internal | 248 } // namespace internal |
244 } // namespace v8 | 249 } // namespace v8 |
OLD | NEW |