| 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/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/compiler/diamond.h" |
| 8 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
| 10 #include "src/compiler/machine-operator.h" | 11 #include "src/compiler/machine-operator.h" |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 namespace compiler { | 15 namespace compiler { |
| 15 | 16 |
| 16 ChangeLowering::~ChangeLowering() {} | 17 ChangeLowering::~ChangeLowering() {} |
| 17 | 18 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 95 |
| 95 | 96 |
| 96 Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) { | 97 Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) { |
| 97 return graph()->NewNode(machine()->Load(kMachFloat64), value, | 98 return graph()->NewNode(machine()->Load(kMachFloat64), value, |
| 98 HeapNumberValueIndexConstant(), graph()->start(), | 99 HeapNumberValueIndexConstant(), graph()->start(), |
| 99 control); | 100 control); |
| 100 } | 101 } |
| 101 | 102 |
| 102 | 103 |
| 103 Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) { | 104 Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) { |
| 104 Node* branch = graph()->NewNode(common()->Branch(), val, control); | 105 Diamond d(graph(), common(), val); |
| 105 | 106 d.Chain(control); |
| 106 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 107 MachineType machine_type = static_cast<MachineType>(kTypeBool | kRepTagged); |
| 107 Node* true_value = jsgraph()->TrueConstant(); | 108 return Replace(d.Phi(machine_type, jsgraph()->TrueConstant(), |
| 108 | 109 jsgraph()->FalseConstant())); |
| 109 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 110 Node* false_value = jsgraph()->FalseConstant(); | |
| 111 | |
| 112 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 113 Node* phi = graph()->NewNode( | |
| 114 common()->Phi(static_cast<MachineType>(kTypeBool | kRepTagged), 2), | |
| 115 true_value, false_value, merge); | |
| 116 | |
| 117 return Replace(phi); | |
| 118 } | 110 } |
| 119 | 111 |
| 120 | 112 |
| 121 Reduction ChangeLowering::ChangeBoolToBit(Node* val) { | 113 Reduction ChangeLowering::ChangeBoolToBit(Node* val) { |
| 122 return Replace( | 114 return Replace( |
| 123 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); | 115 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); |
| 124 } | 116 } |
| 125 | 117 |
| 126 | 118 |
| 127 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) { | 119 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) { |
| 128 return Replace(AllocateHeapNumberWithValue(val, control)); | 120 return Replace(AllocateHeapNumberWithValue(val, control)); |
| 129 } | 121 } |
| 130 | 122 |
| 131 | 123 |
| 132 Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) { | 124 Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) { |
| 133 if (machine()->Is64()) { | 125 if (machine()->Is64()) { |
| 134 return Replace( | 126 return Replace( |
| 135 graph()->NewNode(machine()->Word64Shl(), | 127 graph()->NewNode(machine()->Word64Shl(), |
| 136 graph()->NewNode(machine()->ChangeInt32ToInt64(), val), | 128 graph()->NewNode(machine()->ChangeInt32ToInt64(), val), |
| 137 SmiShiftBitsConstant())); | 129 SmiShiftBitsConstant())); |
| 138 } | 130 } |
| 139 | 131 |
| 140 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); | 132 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); |
| 141 Node* ovf = graph()->NewNode(common()->Projection(1), add); | 133 Node* ovf = graph()->NewNode(common()->Projection(1), add); |
| 142 | 134 |
| 143 Node* branch = | 135 Diamond d(graph(), common(), ovf, BranchHint::kFalse); |
| 144 graph()->NewNode(common()->Branch(BranchHint::kFalse), ovf, control); | 136 d.Chain(control); |
| 145 | |
| 146 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | |
| 147 Node* heap_number = AllocateHeapNumberWithValue( | 137 Node* heap_number = AllocateHeapNumberWithValue( |
| 148 graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), if_true); | 138 graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), d.if_true); |
| 149 | |
| 150 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 151 Node* smi = graph()->NewNode(common()->Projection(0), add); | 139 Node* smi = graph()->NewNode(common()->Projection(0), add); |
| 152 | 140 return Replace(d.Phi(kMachAnyTagged, heap_number, smi)); |
| 153 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 154 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), heap_number, | |
| 155 smi, merge); | |
| 156 | |
| 157 return Replace(phi); | |
| 158 } | 141 } |
| 159 | 142 |
| 160 | 143 |
| 161 Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control, | 144 Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control, |
| 162 Signedness signedness) { | 145 Signedness signedness) { |
| 163 STATIC_ASSERT(kSmiTag == 0); | 146 STATIC_ASSERT(kSmiTag == 0); |
| 164 STATIC_ASSERT(kSmiTagMask == 1); | 147 STATIC_ASSERT(kSmiTagMask == 1); |
| 165 | 148 |
| 166 Node* tag = graph()->NewNode(machine()->WordAnd(), val, | 149 Node* tag = graph()->NewNode(machine()->WordAnd(), val, |
| 167 jsgraph()->IntPtrConstant(kSmiTagMask)); | 150 jsgraph()->IntPtrConstant(kSmiTagMask)); |
| 168 Node* branch = | |
| 169 graph()->NewNode(common()->Branch(BranchHint::kFalse), tag, control); | |
| 170 | 151 |
| 171 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 152 Diamond d(graph(), common(), tag, BranchHint::kFalse); |
| 153 d.Chain(control); |
| 172 const Operator* op = (signedness == kSigned) | 154 const Operator* op = (signedness == kSigned) |
| 173 ? machine()->ChangeFloat64ToInt32() | 155 ? machine()->ChangeFloat64ToInt32() |
| 174 : machine()->ChangeFloat64ToUint32(); | 156 : machine()->ChangeFloat64ToUint32(); |
| 175 Node* change = graph()->NewNode(op, LoadHeapNumberValue(val, if_true)); | 157 Node* load = graph()->NewNode(op, LoadHeapNumberValue(val, d.if_true)); |
| 176 | |
| 177 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 178 Node* number = ChangeSmiToInt32(val); | 158 Node* number = ChangeSmiToInt32(val); |
| 179 | 159 |
| 180 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 160 return Replace( |
| 181 Node* phi = graph()->NewNode( | 161 d.Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, load, number)); |
| 182 common()->Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, 2), | |
| 183 change, number, merge); | |
| 184 | |
| 185 return Replace(phi); | |
| 186 } | 162 } |
| 187 | 163 |
| 188 | 164 |
| 189 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) { | 165 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) { |
| 190 STATIC_ASSERT(kSmiTag == 0); | 166 STATIC_ASSERT(kSmiTag == 0); |
| 191 STATIC_ASSERT(kSmiTagMask == 1); | 167 STATIC_ASSERT(kSmiTagMask == 1); |
| 192 | 168 |
| 193 Node* tag = graph()->NewNode(machine()->WordAnd(), val, | 169 Node* tag = graph()->NewNode(machine()->WordAnd(), val, |
| 194 jsgraph()->IntPtrConstant(kSmiTagMask)); | 170 jsgraph()->IntPtrConstant(kSmiTagMask)); |
| 195 Node* branch = graph()->NewNode(common()->Branch(), tag, control); | 171 Diamond d(graph(), common(), tag, BranchHint::kFalse); |
| 196 | 172 d.Chain(control); |
| 197 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 173 Node* load = LoadHeapNumberValue(val, d.if_true); |
| 198 Node* load = LoadHeapNumberValue(val, if_true); | |
| 199 | |
| 200 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 201 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), | 174 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), |
| 202 ChangeSmiToInt32(val)); | 175 ChangeSmiToInt32(val)); |
| 203 | 176 |
| 204 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 177 return Replace(d.Phi(kMachFloat64, load, number)); |
| 205 Node* phi = | |
| 206 graph()->NewNode(common()->Phi(kMachFloat64, 2), load, number, merge); | |
| 207 | |
| 208 return Replace(phi); | |
| 209 } | 178 } |
| 210 | 179 |
| 211 | 180 |
| 212 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) { | 181 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) { |
| 213 STATIC_ASSERT(kSmiTag == 0); | 182 STATIC_ASSERT(kSmiTag == 0); |
| 214 STATIC_ASSERT(kSmiTagMask == 1); | 183 STATIC_ASSERT(kSmiTagMask == 1); |
| 215 | 184 |
| 216 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, | 185 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, |
| 217 SmiMaxValueConstant()); | 186 SmiMaxValueConstant()); |
| 218 Node* branch = | 187 Diamond d(graph(), common(), cmp, BranchHint::kTrue); |
| 219 graph()->NewNode(common()->Branch(BranchHint::kTrue), cmp, control); | 188 d.Chain(control); |
| 220 | |
| 221 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | |
| 222 Node* smi = graph()->NewNode( | 189 Node* smi = graph()->NewNode( |
| 223 machine()->WordShl(), | 190 machine()->WordShl(), |
| 224 machine()->Is64() | 191 machine()->Is64() |
| 225 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) | 192 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) |
| 226 : val, | 193 : val, |
| 227 SmiShiftBitsConstant()); | 194 SmiShiftBitsConstant()); |
| 228 | 195 |
| 229 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 230 Node* heap_number = AllocateHeapNumberWithValue( | 196 Node* heap_number = AllocateHeapNumberWithValue( |
| 231 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); | 197 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), d.if_false); |
| 232 | 198 |
| 233 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 199 return Replace(d.Phi(kMachAnyTagged, smi, heap_number)); |
| 234 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), smi, | |
| 235 heap_number, merge); | |
| 236 | |
| 237 return Replace(phi); | |
| 238 } | 200 } |
| 239 | 201 |
| 240 | 202 |
| 241 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } | 203 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } |
| 242 | 204 |
| 243 | 205 |
| 244 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } | 206 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } |
| 245 | 207 |
| 246 | 208 |
| 247 CommonOperatorBuilder* ChangeLowering::common() const { | 209 CommonOperatorBuilder* ChangeLowering::common() const { |
| 248 return jsgraph()->common(); | 210 return jsgraph()->common(); |
| 249 } | 211 } |
| 250 | 212 |
| 251 | 213 |
| 252 MachineOperatorBuilder* ChangeLowering::machine() const { | 214 MachineOperatorBuilder* ChangeLowering::machine() const { |
| 253 return jsgraph()->machine(); | 215 return jsgraph()->machine(); |
| 254 } | 216 } |
| 255 | 217 |
| 256 } // namespace compiler | 218 } // namespace compiler |
| 257 } // namespace internal | 219 } // namespace internal |
| 258 } // namespace v8 | 220 } // namespace v8 |
| OLD | NEW |