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 | 6 |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 10 matching lines...) Expand all Loading... |
21 case IrOpcode::kChangeBoolToBit: | 21 case IrOpcode::kChangeBoolToBit: |
22 return ChangeBoolToBit(node->InputAt(0)); | 22 return ChangeBoolToBit(node->InputAt(0)); |
23 case IrOpcode::kChangeFloat64ToTagged: | 23 case IrOpcode::kChangeFloat64ToTagged: |
24 return ChangeFloat64ToTagged(node->InputAt(0), control); | 24 return ChangeFloat64ToTagged(node->InputAt(0), control); |
25 case IrOpcode::kChangeInt32ToTagged: | 25 case IrOpcode::kChangeInt32ToTagged: |
26 return ChangeInt32ToTagged(node->InputAt(0), control); | 26 return ChangeInt32ToTagged(node->InputAt(0), control); |
27 case IrOpcode::kChangeTaggedToFloat64: | 27 case IrOpcode::kChangeTaggedToFloat64: |
28 return ChangeTaggedToFloat64(node->InputAt(0), control); | 28 return ChangeTaggedToFloat64(node->InputAt(0), control); |
29 case IrOpcode::kChangeTaggedToInt32: | 29 case IrOpcode::kChangeTaggedToInt32: |
30 return ChangeTaggedToInt32(node->InputAt(0), control); | 30 return ChangeTaggedToInt32(node->InputAt(0), control); |
| 31 case IrOpcode::kChangeUint32ToTagged: |
| 32 return ChangeUint32ToTagged(node->InputAt(0), control); |
31 default: | 33 default: |
32 return NoChange(); | 34 return NoChange(); |
33 } | 35 } |
34 UNREACHABLE(); | 36 UNREACHABLE(); |
35 return NoChange(); | 37 return NoChange(); |
36 } | 38 } |
37 | 39 |
38 | 40 |
39 Node* ChangeLowering::HeapNumberValueIndexConstant() { | 41 Node* ChangeLowering::HeapNumberValueIndexConstant() { |
40 STATIC_ASSERT(HeapNumber::kValueOffset % kPointerSize == 0); | 42 STATIC_ASSERT(HeapNumber::kValueOffset % kPointerSize == 0); |
41 const int heap_number_value_offset = | 43 const int heap_number_value_offset = |
42 ((HeapNumber::kValueOffset / kPointerSize) * (machine()->is64() ? 8 : 4)); | 44 ((HeapNumber::kValueOffset / kPointerSize) * (machine()->is64() ? 8 : 4)); |
43 return jsgraph()->Int32Constant(heap_number_value_offset - kHeapObjectTag); | 45 return jsgraph()->Int32Constant(heap_number_value_offset - kHeapObjectTag); |
44 } | 46 } |
45 | 47 |
46 | 48 |
| 49 Node* ChangeLowering::SmiMaxValueConstant() { |
| 50 // TODO(turbofan): Work-around for weird GCC 4.6 linker issue: |
| 51 // src/compiler/change-lowering.cc:46: undefined reference to |
| 52 // `v8::internal::SmiTagging<4u>::kSmiValueSize' |
| 53 // src/compiler/change-lowering.cc:46: undefined reference to |
| 54 // `v8::internal::SmiTagging<8u>::kSmiValueSize' |
| 55 STATIC_ASSERT(SmiTagging<4>::kSmiValueSize == 31); |
| 56 STATIC_ASSERT(SmiTagging<8>::kSmiValueSize == 32); |
| 57 const int smi_value_size = machine()->is64() ? 32 : 31; |
| 58 return jsgraph()->Int32Constant( |
| 59 -(static_cast<int>(0xffffffffu << (smi_value_size - 1)) + 1)); |
| 60 } |
| 61 |
| 62 |
47 Node* ChangeLowering::SmiShiftBitsConstant() { | 63 Node* ChangeLowering::SmiShiftBitsConstant() { |
48 // TODO(turbofan): Work-around for weird GCC 4.6 linker issue: | 64 // TODO(turbofan): Work-around for weird GCC 4.6 linker issue: |
49 // src/compiler/change-lowering.cc:46: undefined reference to | 65 // src/compiler/change-lowering.cc:46: undefined reference to |
50 // `v8::internal::SmiTagging<4u>::kSmiShiftSize' | 66 // `v8::internal::SmiTagging<4u>::kSmiShiftSize' |
51 // src/compiler/change-lowering.cc:46: undefined reference to | 67 // src/compiler/change-lowering.cc:46: undefined reference to |
52 // `v8::internal::SmiTagging<8u>::kSmiShiftSize' | 68 // `v8::internal::SmiTagging<8u>::kSmiShiftSize' |
53 STATIC_ASSERT(SmiTagging<4>::kSmiShiftSize == 0); | 69 STATIC_ASSERT(SmiTagging<4>::kSmiShiftSize == 0); |
54 STATIC_ASSERT(SmiTagging<8>::kSmiShiftSize == 31); | 70 STATIC_ASSERT(SmiTagging<8>::kSmiShiftSize == 31); |
55 const int smi_shift_size = machine()->is64() ? 31 : 0; | 71 const int smi_shift_size = machine()->is64() ? 31 : 0; |
56 return jsgraph()->Int32Constant(smi_shift_size + kSmiTagSize); | 72 return jsgraph()->Int32Constant(smi_shift_size + kSmiTagSize); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 ? graph()->NewNode(machine()->TruncateInt64ToInt32(), integer) | 179 ? graph()->NewNode(machine()->TruncateInt64ToInt32(), integer) |
164 : integer); | 180 : integer); |
165 | 181 |
166 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 182 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
167 Node* phi = graph()->NewNode(common()->Phi(2), load, number, merge); | 183 Node* phi = graph()->NewNode(common()->Phi(2), load, number, merge); |
168 | 184 |
169 return Replace(phi); | 185 return Replace(phi); |
170 } | 186 } |
171 | 187 |
172 | 188 |
| 189 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) { |
| 190 STATIC_ASSERT(kSmiTag == 0); |
| 191 STATIC_ASSERT(kSmiTagMask == 1); |
| 192 |
| 193 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, |
| 194 SmiMaxValueConstant()); |
| 195 Node* branch = graph()->NewNode(common()->Branch(), cmp, control); |
| 196 |
| 197 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 198 Node* smi = graph()->NewNode( |
| 199 machine()->WordShl(), |
| 200 machine()->is64() |
| 201 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) |
| 202 : val, |
| 203 SmiShiftBitsConstant()); |
| 204 |
| 205 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 206 Node* heap_number = AllocateHeapNumberWithValue( |
| 207 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); |
| 208 |
| 209 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 210 Node* phi = graph()->NewNode(common()->Phi(2), smi, heap_number, merge); |
| 211 |
| 212 return Replace(phi); |
| 213 } |
| 214 |
| 215 |
173 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } | 216 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } |
174 | 217 |
175 | 218 |
176 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } | 219 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } |
177 | 220 |
178 | 221 |
179 CommonOperatorBuilder* ChangeLowering::common() const { | 222 CommonOperatorBuilder* ChangeLowering::common() const { |
180 return jsgraph()->common(); | 223 return jsgraph()->common(); |
181 } | 224 } |
182 | 225 |
(...skipping 14 matching lines...) Expand all Loading... |
197 jsgraph()->Int32Constant(function->nargs), context, effect, control); | 240 jsgraph()->Int32Constant(function->nargs), context, effect, control); |
198 Node* store = graph()->NewNode( | 241 Node* store = graph()->NewNode( |
199 machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number, | 242 machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number, |
200 HeapNumberValueIndexConstant(), value, heap_number, control); | 243 HeapNumberValueIndexConstant(), value, heap_number, control); |
201 return graph()->NewNode(common()->Finish(1), heap_number, store); | 244 return graph()->NewNode(common()->Finish(1), heap_number, store); |
202 } | 245 } |
203 | 246 |
204 } // namespace compiler | 247 } // namespace compiler |
205 } // namespace internal | 248 } // namespace internal |
206 } // namespace v8 | 249 } // namespace v8 |
OLD | NEW |