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