| 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 26 matching lines...) Expand all Loading... |
| 37 return NoChange(); | 37 return NoChange(); |
| 38 } | 38 } |
| 39 UNREACHABLE(); | 39 UNREACHABLE(); |
| 40 return NoChange(); | 40 return NoChange(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 Node* ChangeLowering::HeapNumberValueIndexConstant() { | 44 Node* ChangeLowering::HeapNumberValueIndexConstant() { |
| 45 STATIC_ASSERT(HeapNumber::kValueOffset % kPointerSize == 0); | 45 STATIC_ASSERT(HeapNumber::kValueOffset % kPointerSize == 0); |
| 46 const int heap_number_value_offset = | 46 const int heap_number_value_offset = |
| 47 ((HeapNumber::kValueOffset / kPointerSize) * (machine()->is64() ? 8 : 4)); | 47 ((HeapNumber::kValueOffset / kPointerSize) * (machine()->Is64() ? 8 : 4)); |
| 48 return jsgraph()->Int32Constant(heap_number_value_offset - kHeapObjectTag); | 48 return jsgraph()->Int32Constant(heap_number_value_offset - kHeapObjectTag); |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 Node* ChangeLowering::SmiMaxValueConstant() { | 52 Node* ChangeLowering::SmiMaxValueConstant() { |
| 53 const int smi_value_size = machine()->is32() ? SmiTagging<4>::SmiValueSize() | 53 const int smi_value_size = machine()->Is32() ? SmiTagging<4>::SmiValueSize() |
| 54 : SmiTagging<8>::SmiValueSize(); | 54 : SmiTagging<8>::SmiValueSize(); |
| 55 return jsgraph()->Int32Constant( | 55 return jsgraph()->Int32Constant( |
| 56 -(static_cast<int>(0xffffffffu << (smi_value_size - 1)) + 1)); | 56 -(static_cast<int>(0xffffffffu << (smi_value_size - 1)) + 1)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 Node* ChangeLowering::SmiShiftBitsConstant() { | 60 Node* ChangeLowering::SmiShiftBitsConstant() { |
| 61 const int smi_shift_size = machine()->is32() ? SmiTagging<4>::SmiShiftSize() | 61 const int smi_shift_size = machine()->Is32() ? SmiTagging<4>::SmiShiftSize() |
| 62 : SmiTagging<8>::SmiShiftSize(); | 62 : SmiTagging<8>::SmiShiftSize(); |
| 63 return jsgraph()->Int32Constant(smi_shift_size + kSmiTagSize); | 63 return jsgraph()->Int32Constant(smi_shift_size + kSmiTagSize); |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 Node* ChangeLowering::AllocateHeapNumberWithValue(Node* value, Node* control) { | 67 Node* ChangeLowering::AllocateHeapNumberWithValue(Node* value, Node* control) { |
| 68 // The AllocateHeapNumber() runtime function does not use the context, so we | 68 // The AllocateHeapNumber() runtime function does not use the context, so we |
| 69 // can safely pass in Smi zero here. | 69 // can safely pass in Smi zero here. |
| 70 Node* context = jsgraph()->ZeroConstant(); | 70 Node* context = jsgraph()->ZeroConstant(); |
| 71 Node* effect = graph()->NewNode(common()->ValueEffect(1), value); | 71 Node* effect = graph()->NewNode(common()->ValueEffect(1), value); |
| 72 const Runtime::Function* function = | 72 const Runtime::Function* function = |
| 73 Runtime::FunctionForId(Runtime::kAllocateHeapNumber); | 73 Runtime::FunctionForId(Runtime::kAllocateHeapNumber); |
| 74 DCHECK_EQ(0, function->nargs); | 74 DCHECK_EQ(0, function->nargs); |
| 75 CallDescriptor* desc = linkage()->GetRuntimeCallDescriptor( | 75 CallDescriptor* desc = linkage()->GetRuntimeCallDescriptor( |
| 76 function->function_id, 0, Operator::kNoProperties); | 76 function->function_id, 0, Operator::kNoProperties); |
| 77 Node* heap_number = graph()->NewNode( | 77 Node* heap_number = graph()->NewNode( |
| 78 common()->Call(desc), jsgraph()->CEntryStubConstant(), | 78 common()->Call(desc), jsgraph()->CEntryStubConstant(), |
| 79 jsgraph()->ExternalConstant(ExternalReference(function, isolate())), | 79 jsgraph()->ExternalConstant(ExternalReference(function, isolate())), |
| 80 jsgraph()->Int32Constant(function->nargs), context, effect, control); | 80 jsgraph()->Int32Constant(function->nargs), context, effect, control); |
| 81 Node* store = graph()->NewNode( | 81 Node* store = graph()->NewNode( |
| 82 machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number, | 82 machine()->Store(StoreRepresentation(kMachFloat64, kNoWriteBarrier)), |
| 83 HeapNumberValueIndexConstant(), value, heap_number, control); | 83 heap_number, HeapNumberValueIndexConstant(), value, heap_number, control); |
| 84 return graph()->NewNode(common()->Finish(1), heap_number, store); | 84 return graph()->NewNode(common()->Finish(1), heap_number, store); |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 Node* ChangeLowering::ChangeSmiToInt32(Node* value) { | 88 Node* ChangeLowering::ChangeSmiToInt32(Node* value) { |
| 89 value = graph()->NewNode(machine()->WordSar(), value, SmiShiftBitsConstant()); | 89 value = graph()->NewNode(machine()->WordSar(), value, SmiShiftBitsConstant()); |
| 90 if (machine()->is64()) { | 90 if (machine()->Is64()) { |
| 91 value = graph()->NewNode(machine()->TruncateInt64ToInt32(), value); | 91 value = graph()->NewNode(machine()->TruncateInt64ToInt32(), value); |
| 92 } | 92 } |
| 93 return value; | 93 return value; |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) { | 97 Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) { |
| 98 return graph()->NewNode(machine()->Load(kMachFloat64), value, | 98 return graph()->NewNode(machine()->Load(kMachFloat64), value, |
| 99 HeapNumberValueIndexConstant(), | 99 HeapNumberValueIndexConstant(), |
| 100 graph()->NewNode(common()->ControlEffect(), control)); | 100 graph()->NewNode(common()->ControlEffect(), control)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); | 124 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) { | 128 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) { |
| 129 return Replace(AllocateHeapNumberWithValue(val, control)); | 129 return Replace(AllocateHeapNumberWithValue(val, control)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) { | 133 Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) { |
| 134 if (machine()->is64()) { | 134 if (machine()->Is64()) { |
| 135 return Replace( | 135 return Replace( |
| 136 graph()->NewNode(machine()->Word64Shl(), | 136 graph()->NewNode(machine()->Word64Shl(), |
| 137 graph()->NewNode(machine()->ChangeInt32ToInt64(), val), | 137 graph()->NewNode(machine()->ChangeInt32ToInt64(), val), |
| 138 SmiShiftBitsConstant())); | 138 SmiShiftBitsConstant())); |
| 139 } | 139 } |
| 140 | 140 |
| 141 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); | 141 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); |
| 142 Node* ovf = graph()->NewNode(common()->Projection(1), add); | 142 Node* ovf = graph()->NewNode(common()->Projection(1), add); |
| 143 | 143 |
| 144 Node* branch = graph()->NewNode(common()->Branch(), ovf, control); | 144 Node* branch = graph()->NewNode(common()->Branch(), ovf, control); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 STATIC_ASSERT(kSmiTag == 0); | 212 STATIC_ASSERT(kSmiTag == 0); |
| 213 STATIC_ASSERT(kSmiTagMask == 1); | 213 STATIC_ASSERT(kSmiTagMask == 1); |
| 214 | 214 |
| 215 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, | 215 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, |
| 216 SmiMaxValueConstant()); | 216 SmiMaxValueConstant()); |
| 217 Node* branch = graph()->NewNode(common()->Branch(), cmp, control); | 217 Node* branch = graph()->NewNode(common()->Branch(), cmp, control); |
| 218 | 218 |
| 219 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 219 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 220 Node* smi = graph()->NewNode( | 220 Node* smi = graph()->NewNode( |
| 221 machine()->WordShl(), | 221 machine()->WordShl(), |
| 222 machine()->is64() | 222 machine()->Is64() |
| 223 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) | 223 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) |
| 224 : val, | 224 : val, |
| 225 SmiShiftBitsConstant()); | 225 SmiShiftBitsConstant()); |
| 226 | 226 |
| 227 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 227 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 228 Node* heap_number = AllocateHeapNumberWithValue( | 228 Node* heap_number = AllocateHeapNumberWithValue( |
| 229 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); | 229 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); |
| 230 | 230 |
| 231 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 231 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 232 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), smi, | 232 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), smi, |
| 233 heap_number, merge); | 233 heap_number, merge); |
| 234 | 234 |
| 235 return Replace(phi); | 235 return Replace(phi); |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| 239 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } | 239 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } |
| 240 | 240 |
| 241 | 241 |
| 242 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } | 242 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } |
| 243 | 243 |
| 244 | 244 |
| 245 CommonOperatorBuilder* ChangeLowering::common() const { | 245 CommonOperatorBuilder* ChangeLowering::common() const { |
| 246 return jsgraph()->common(); | 246 return jsgraph()->common(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 } // namespace compiler | 249 } // namespace compiler |
| 250 } // namespace internal | 250 } // namespace internal |
| 251 } // namespace v8 | 251 } // namespace v8 |
| OLD | NEW |