| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 Node* context = jsgraph()->SmiConstant(0); | 87 Node* context = jsgraph()->SmiConstant(0); |
| 88 | 88 |
| 89 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); | 89 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); |
| 90 Node* ovf = graph()->NewNode(common()->Projection(1), add); | 90 Node* ovf = graph()->NewNode(common()->Projection(1), add); |
| 91 | 91 |
| 92 Node* branch = graph()->NewNode(common()->Branch(), ovf, control); | 92 Node* branch = graph()->NewNode(common()->Branch(), ovf, control); |
| 93 | 93 |
| 94 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 94 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 95 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), val); | 95 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), val); |
| 96 | 96 |
| 97 // TODO(bmeurer): Inline allocation if possible. | |
| 98 const Runtime::Function* fn = | 97 const Runtime::Function* fn = |
| 99 Runtime::FunctionForId(Runtime::kAllocateHeapNumber); | 98 Runtime::FunctionForId(Runtime::kAllocateHeapNumber); |
| 100 DCHECK_EQ(0, fn->nargs); | 99 DCHECK_EQ(0, fn->nargs); |
| 101 CallDescriptor* desc = linkage()->GetRuntimeCallDescriptor( | 100 CallDescriptor* desc = linkage()->GetRuntimeCallDescriptor( |
| 102 fn->function_id, 0, Operator::kNoProperties); | 101 fn->function_id, 0, Operator::kNoProperties); |
| 103 Node* heap_number = graph()->NewNode( | 102 Node* heap_number = graph()->NewNode( |
| 104 common()->Call(desc), jsgraph()->CEntryStubConstant(), | 103 common()->Call(desc), jsgraph()->CEntryStubConstant(), |
| 105 jsgraph()->ExternalConstant(ExternalReference(fn, isolate())), | 104 jsgraph()->ExternalConstant(ExternalReference(fn, isolate())), |
| 106 jsgraph()->ZeroConstant(), context, effect, if_true); | 105 jsgraph()->Int32Constant(fn->nargs), context, effect, if_true); |
| 107 | |
| 108 Node* store = graph()->NewNode( | 106 Node* store = graph()->NewNode( |
| 109 machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number, | 107 machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number, |
| 110 HeapNumberValueIndexConstant(), number, effect, heap_number); | 108 HeapNumberValueIndexConstant(), number, heap_number, if_true); |
| 109 Node* finish = graph()->NewNode(common()->Finish(1), heap_number, store); |
| 111 | 110 |
| 112 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 111 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 113 Node* smi = graph()->NewNode(common()->Projection(0), add); | 112 Node* smi = graph()->NewNode(common()->Projection(0), add); |
| 114 | 113 |
| 115 Node* merge = graph()->NewNode(common()->Merge(2), store, if_false); | 114 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 116 Node* phi = graph()->NewNode(common()->Phi(2), heap_number, smi, merge); | 115 Node* phi = graph()->NewNode(common()->Phi(2), finish, smi, merge); |
| 117 | 116 |
| 118 return Replace(phi); | 117 return Replace(phi); |
| 119 } | 118 } |
| 120 | 119 |
| 121 | 120 |
| 122 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* effect, | 121 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* effect, |
| 123 Node* control) { | 122 Node* control) { |
| 124 STATIC_ASSERT(kSmiTagMask == 1); | 123 STATIC_ASSERT(kSmiTagMask == 1); |
| 125 | 124 |
| 126 Node* tag = graph()->NewNode(machine()->WordAnd(), val, | 125 Node* tag = graph()->NewNode(machine()->WordAnd(), val, |
| 127 jsgraph()->Int32Constant(kSmiTagMask)); | 126 jsgraph()->Int32Constant(kSmiTagMask)); |
| 128 Node* branch = graph()->NewNode(common()->Branch(), tag, control); | 127 Node* branch = graph()->NewNode(common()->Branch(), tag, control); |
| 129 | 128 |
| 130 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 129 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 131 Node* load = graph()->NewNode(machine()->Load(kMachFloat64), val, | 130 Node* load = graph()->NewNode( |
| 132 HeapNumberValueIndexConstant(), if_true); | 131 machine()->Load(kMachFloat64), val, HeapNumberValueIndexConstant(), |
| 132 graph()->NewNode(common()->ControlEffect(), if_true)); |
| 133 | 133 |
| 134 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 134 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 135 Node* integer = | 135 Node* integer = |
| 136 graph()->NewNode(machine()->WordSar(), val, SmiShiftBitsConstant()); | 136 graph()->NewNode(machine()->WordSar(), val, SmiShiftBitsConstant()); |
| 137 Node* number = graph()->NewNode( | 137 Node* number = graph()->NewNode( |
| 138 machine()->ChangeInt32ToFloat64(), | 138 machine()->ChangeInt32ToFloat64(), |
| 139 machine()->is64() | 139 machine()->is64() |
| 140 ? graph()->NewNode(machine()->ConvertInt64ToInt32(), integer) | 140 ? graph()->NewNode(machine()->ConvertInt64ToInt32(), integer) |
| 141 : integer); | 141 : integer); |
| 142 | 142 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 153 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } | 153 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } |
| 154 | 154 |
| 155 | 155 |
| 156 CommonOperatorBuilder* ChangeLowering::common() const { | 156 CommonOperatorBuilder* ChangeLowering::common() const { |
| 157 return jsgraph()->common(); | 157 return jsgraph()->common(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace compiler | 160 } // namespace compiler |
| 161 } // namespace internal | 161 } // namespace internal |
| 162 } // namespace v8 | 162 } // namespace v8 |
| OLD | NEW |