| 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/int64-lowering.h" | 5 #include "src/compiler/int64-lowering.h" |
| 6 #include "src/compiler/common-operator.h" | 6 #include "src/compiler/common-operator.h" |
| 7 #include "src/compiler/diamond.h" | 7 #include "src/compiler/diamond.h" |
| 8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
| 9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
| 10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 Signature<MachineRepresentation>* signature) { | 93 Signature<MachineRepresentation>* signature) { |
| 94 int result = static_cast<int>(signature->return_count()); | 94 int result = static_cast<int>(signature->return_count()); |
| 95 for (int i = 0; i < static_cast<int>(signature->return_count()); i++) { | 95 for (int i = 0; i < static_cast<int>(signature->return_count()); i++) { |
| 96 if (signature->GetReturn(i) == MachineRepresentation::kWord64) { | 96 if (signature->GetReturn(i) == MachineRepresentation::kWord64) { |
| 97 result++; | 97 result++; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return result; | 100 return result; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void Int64Lowering::GetIndexNodes(Node* index, Node*& index_low, |
| 104 Node*& index_high) { |
| 105 #if defined(V8_TARGET_LITTLE_ENDIAN) |
| 106 index_low = index; |
| 107 index_high = graph()->NewNode(machine()->Int32Add(), index, |
| 108 graph()->NewNode(common()->Int32Constant(4))); |
| 109 #elif defined(V8_TARGET_BIG_ENDIAN) |
| 110 index_low = graph()->NewNode(machine()->Int32Add(), index, |
| 111 graph()->NewNode(common()->Int32Constant(4))); |
| 112 index_high = index; |
| 113 #endif |
| 114 } |
| 115 |
| 116 #if defined(V8_TARGET_LITTLE_ENDIAN) |
| 117 const int Int64Lowering::kLowerWordOffset = 0; |
| 118 const int Int64Lowering::kHigherWordOffset = 4; |
| 119 #elif defined(V8_TARGET_BIG_ENDIAN) |
| 120 const int Int64Lowering::kLowerWordOffset = 4; |
| 121 const int Int64Lowering::kHigherWordOffset = 0; |
| 122 #endif |
| 123 |
| 103 void Int64Lowering::LowerNode(Node* node) { | 124 void Int64Lowering::LowerNode(Node* node) { |
| 104 switch (node->opcode()) { | 125 switch (node->opcode()) { |
| 105 case IrOpcode::kInt64Constant: { | 126 case IrOpcode::kInt64Constant: { |
| 106 int64_t value = OpParameter<int64_t>(node); | 127 int64_t value = OpParameter<int64_t>(node); |
| 107 Node* low_node = graph()->NewNode( | 128 Node* low_node = graph()->NewNode( |
| 108 common()->Int32Constant(static_cast<int32_t>(value & 0xFFFFFFFF))); | 129 common()->Int32Constant(static_cast<int32_t>(value & 0xFFFFFFFF))); |
| 109 Node* high_node = graph()->NewNode( | 130 Node* high_node = graph()->NewNode( |
| 110 common()->Int32Constant(static_cast<int32_t>(value >> 32))); | 131 common()->Int32Constant(static_cast<int32_t>(value >> 32))); |
| 111 ReplaceNode(node, low_node, high_node); | 132 ReplaceNode(node, low_node, high_node); |
| 112 break; | 133 break; |
| 113 } | 134 } |
| 114 case IrOpcode::kLoad: { | 135 case IrOpcode::kLoad: { |
| 115 LoadRepresentation load_rep = LoadRepresentationOf(node->op()); | 136 LoadRepresentation load_rep = LoadRepresentationOf(node->op()); |
| 116 | 137 |
| 117 if (load_rep.representation() == MachineRepresentation::kWord64) { | 138 if (load_rep.representation() == MachineRepresentation::kWord64) { |
| 118 Node* base = node->InputAt(0); | 139 Node* base = node->InputAt(0); |
| 119 Node* index = node->InputAt(1); | 140 Node* index = node->InputAt(1); |
| 120 Node* index_high = | 141 Node* index_low; |
| 121 graph()->NewNode(machine()->Int32Add(), index, | 142 Node* index_high; |
| 122 graph()->NewNode(common()->Int32Constant(4))); | 143 GetIndexNodes(index, index_low, index_high); |
| 123 | |
| 124 const Operator* load_op = machine()->Load(MachineType::Int32()); | 144 const Operator* load_op = machine()->Load(MachineType::Int32()); |
| 125 Node* high_node; | 145 Node* high_node; |
| 126 if (node->InputCount() > 2) { | 146 if (node->InputCount() > 2) { |
| 127 Node* effect_high = node->InputAt(2); | 147 Node* effect_high = node->InputAt(2); |
| 128 Node* control_high = node->InputAt(3); | 148 Node* control_high = node->InputAt(3); |
| 129 high_node = graph()->NewNode(load_op, base, index_high, effect_high, | 149 high_node = graph()->NewNode(load_op, base, index_high, effect_high, |
| 130 control_high); | 150 control_high); |
| 131 // change the effect change from old_node --> old_effect to | 151 // change the effect change from old_node --> old_effect to |
| 132 // old_node --> high_node --> old_effect. | 152 // old_node --> high_node --> old_effect. |
| 133 node->ReplaceInput(2, high_node); | 153 node->ReplaceInput(2, high_node); |
| 134 } else { | 154 } else { |
| 135 high_node = graph()->NewNode(load_op, base, index_high); | 155 high_node = graph()->NewNode(load_op, base, index_high); |
| 136 } | 156 } |
| 157 node->ReplaceInput(1, index_low); |
| 137 NodeProperties::ChangeOp(node, load_op); | 158 NodeProperties::ChangeOp(node, load_op); |
| 138 ReplaceNode(node, node, high_node); | 159 ReplaceNode(node, node, high_node); |
| 139 } else { | 160 } else { |
| 140 DefaultLowering(node); | 161 DefaultLowering(node); |
| 141 } | 162 } |
| 142 break; | 163 break; |
| 143 } | 164 } |
| 144 case IrOpcode::kStore: { | 165 case IrOpcode::kStore: { |
| 145 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); | 166 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); |
| 146 if (store_rep.representation() == MachineRepresentation::kWord64) { | 167 if (store_rep.representation() == MachineRepresentation::kWord64) { |
| 147 // We change the original store node to store the low word, and create | 168 // We change the original store node to store the low word, and create |
| 148 // a new store node to store the high word. The effect and control edges | 169 // a new store node to store the high word. The effect and control edges |
| 149 // are copied from the original store to the new store node, the effect | 170 // are copied from the original store to the new store node, the effect |
| 150 // edge of the original store is redirected to the new store. | 171 // edge of the original store is redirected to the new store. |
| 151 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind(); | 172 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind(); |
| 152 | 173 |
| 153 Node* base = node->InputAt(0); | 174 Node* base = node->InputAt(0); |
| 154 Node* index = node->InputAt(1); | 175 Node* index = node->InputAt(1); |
| 155 Node* index_high = | 176 Node* index_low; |
| 156 graph()->NewNode(machine()->Int32Add(), index, | 177 Node* index_high; |
| 157 graph()->NewNode(common()->Int32Constant(4))); | 178 GetIndexNodes(index, index_low, index_high); |
| 158 | |
| 159 Node* value = node->InputAt(2); | 179 Node* value = node->InputAt(2); |
| 160 DCHECK(HasReplacementLow(value)); | 180 DCHECK(HasReplacementLow(value)); |
| 161 DCHECK(HasReplacementHigh(value)); | 181 DCHECK(HasReplacementHigh(value)); |
| 162 | 182 |
| 163 const Operator* store_op = machine()->Store(StoreRepresentation( | 183 const Operator* store_op = machine()->Store(StoreRepresentation( |
| 164 MachineRepresentation::kWord32, write_barrier_kind)); | 184 MachineRepresentation::kWord32, write_barrier_kind)); |
| 165 | 185 |
| 166 Node* high_node; | 186 Node* high_node; |
| 167 if (node->InputCount() > 3) { | 187 if (node->InputCount() > 3) { |
| 168 Node* effect_high = node->InputAt(3); | 188 Node* effect_high = node->InputAt(3); |
| 169 Node* control_high = node->InputAt(4); | 189 Node* control_high = node->InputAt(4); |
| 170 high_node = graph()->NewNode(store_op, base, index_high, | 190 high_node = graph()->NewNode(store_op, base, index_high, |
| 171 GetReplacementHigh(value), effect_high, | 191 GetReplacementHigh(value), effect_high, |
| 172 control_high); | 192 control_high); |
| 173 node->ReplaceInput(3, high_node); | 193 node->ReplaceInput(3, high_node); |
| 174 | 194 |
| 175 } else { | 195 } else { |
| 176 high_node = graph()->NewNode(store_op, base, index_high, | 196 high_node = graph()->NewNode(store_op, base, index_high, |
| 177 GetReplacementHigh(value)); | 197 GetReplacementHigh(value)); |
| 178 } | 198 } |
| 179 | 199 |
| 200 node->ReplaceInput(1, index_low); |
| 180 node->ReplaceInput(2, GetReplacementLow(value)); | 201 node->ReplaceInput(2, GetReplacementLow(value)); |
| 181 NodeProperties::ChangeOp(node, store_op); | 202 NodeProperties::ChangeOp(node, store_op); |
| 182 ReplaceNode(node, node, high_node); | 203 ReplaceNode(node, node, high_node); |
| 183 } else { | 204 } else { |
| 184 if (HasReplacementLow(node->InputAt(2))) { | 205 if (HasReplacementLow(node->InputAt(2))) { |
| 185 node->ReplaceInput(2, GetReplacementLow(node->InputAt(2))); | 206 node->ReplaceInput(2, GetReplacementLow(node->InputAt(2))); |
| 186 } | 207 } |
| 187 } | 208 } |
| 188 break; | 209 break; |
| 189 } | 210 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 case IrOpcode::kBitcastInt64ToFloat64: { | 505 case IrOpcode::kBitcastInt64ToFloat64: { |
| 485 DCHECK(node->InputCount() == 1); | 506 DCHECK(node->InputCount() == 1); |
| 486 Node* input = node->InputAt(0); | 507 Node* input = node->InputAt(0); |
| 487 Node* stack_slot = graph()->NewNode( | 508 Node* stack_slot = graph()->NewNode( |
| 488 machine()->StackSlot(MachineRepresentation::kWord64)); | 509 machine()->StackSlot(MachineRepresentation::kWord64)); |
| 489 | 510 |
| 490 Node* store_high_word = graph()->NewNode( | 511 Node* store_high_word = graph()->NewNode( |
| 491 machine()->Store( | 512 machine()->Store( |
| 492 StoreRepresentation(MachineRepresentation::kWord32, | 513 StoreRepresentation(MachineRepresentation::kWord32, |
| 493 WriteBarrierKind::kNoWriteBarrier)), | 514 WriteBarrierKind::kNoWriteBarrier)), |
| 494 stack_slot, graph()->NewNode(common()->Int32Constant(4)), | 515 stack_slot, |
| 516 graph()->NewNode(common()->Int32Constant(kHigherWordOffset)), |
| 495 GetReplacementHigh(input), graph()->start(), graph()->start()); | 517 GetReplacementHigh(input), graph()->start(), graph()->start()); |
| 496 | 518 |
| 497 Node* store_low_word = graph()->NewNode( | 519 Node* store_low_word = graph()->NewNode( |
| 498 machine()->Store( | 520 machine()->Store( |
| 499 StoreRepresentation(MachineRepresentation::kWord32, | 521 StoreRepresentation(MachineRepresentation::kWord32, |
| 500 WriteBarrierKind::kNoWriteBarrier)), | 522 WriteBarrierKind::kNoWriteBarrier)), |
| 501 stack_slot, graph()->NewNode(common()->Int32Constant(0)), | 523 stack_slot, |
| 524 graph()->NewNode(common()->Int32Constant(kLowerWordOffset)), |
| 502 GetReplacementLow(input), store_high_word, graph()->start()); | 525 GetReplacementLow(input), store_high_word, graph()->start()); |
| 503 | 526 |
| 504 Node* load = | 527 Node* load = |
| 505 graph()->NewNode(machine()->Load(MachineType::Float64()), stack_slot, | 528 graph()->NewNode(machine()->Load(MachineType::Float64()), stack_slot, |
| 506 graph()->NewNode(common()->Int32Constant(0)), | 529 graph()->NewNode(common()->Int32Constant(0)), |
| 507 store_low_word, graph()->start()); | 530 store_low_word, graph()->start()); |
| 508 | 531 |
| 509 ReplaceNode(node, load, nullptr); | 532 ReplaceNode(node, load, nullptr); |
| 510 break; | 533 break; |
| 511 } | 534 } |
| 512 case IrOpcode::kBitcastFloat64ToInt64: { | 535 case IrOpcode::kBitcastFloat64ToInt64: { |
| 513 DCHECK(node->InputCount() == 1); | 536 DCHECK(node->InputCount() == 1); |
| 514 Node* input = node->InputAt(0); | 537 Node* input = node->InputAt(0); |
| 515 if (HasReplacementLow(input)) { | 538 if (HasReplacementLow(input)) { |
| 516 input = GetReplacementLow(input); | 539 input = GetReplacementLow(input); |
| 517 } | 540 } |
| 518 Node* stack_slot = graph()->NewNode( | 541 Node* stack_slot = graph()->NewNode( |
| 519 machine()->StackSlot(MachineRepresentation::kWord64)); | 542 machine()->StackSlot(MachineRepresentation::kWord64)); |
| 520 Node* store = graph()->NewNode( | 543 Node* store = graph()->NewNode( |
| 521 machine()->Store( | 544 machine()->Store( |
| 522 StoreRepresentation(MachineRepresentation::kFloat64, | 545 StoreRepresentation(MachineRepresentation::kFloat64, |
| 523 WriteBarrierKind::kNoWriteBarrier)), | 546 WriteBarrierKind::kNoWriteBarrier)), |
| 524 stack_slot, graph()->NewNode(common()->Int32Constant(0)), input, | 547 stack_slot, graph()->NewNode(common()->Int32Constant(0)), input, |
| 525 graph()->start(), graph()->start()); | 548 graph()->start(), graph()->start()); |
| 526 | 549 |
| 527 Node* high_node = | 550 Node* high_node = graph()->NewNode( |
| 528 graph()->NewNode(machine()->Load(MachineType::Int32()), stack_slot, | 551 machine()->Load(MachineType::Int32()), stack_slot, |
| 529 graph()->NewNode(common()->Int32Constant(4)), store, | 552 graph()->NewNode(common()->Int32Constant(kHigherWordOffset)), store, |
| 530 graph()->start()); | 553 graph()->start()); |
| 531 | 554 |
| 532 Node* low_node = | 555 Node* low_node = graph()->NewNode( |
| 533 graph()->NewNode(machine()->Load(MachineType::Int32()), stack_slot, | 556 machine()->Load(MachineType::Int32()), stack_slot, |
| 534 graph()->NewNode(common()->Int32Constant(0)), store, | 557 graph()->NewNode(common()->Int32Constant(kLowerWordOffset)), store, |
| 535 graph()->start()); | 558 graph()->start()); |
| 536 ReplaceNode(node, low_node, high_node); | 559 ReplaceNode(node, low_node, high_node); |
| 537 break; | 560 break; |
| 538 } | 561 } |
| 539 case IrOpcode::kWord64Ror: { | 562 case IrOpcode::kWord64Ror: { |
| 540 DCHECK(node->InputCount() == 2); | 563 DCHECK(node->InputCount() == 2); |
| 541 Node* input = node->InputAt(0); | 564 Node* input = node->InputAt(0); |
| 542 Node* shift = HasReplacementLow(node->InputAt(1)) | 565 Node* shift = HasReplacementLow(node->InputAt(1)) |
| 543 ? GetReplacementLow(node->InputAt(1)) | 566 ? GetReplacementLow(node->InputAt(1)) |
| 544 : node->InputAt(1); | 567 : node->InputAt(1); |
| 545 Int32Matcher m(shift); | 568 Int32Matcher m(shift); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 common()->Phi(MachineRepresentation::kWord32, value_count), | 823 common()->Phi(MachineRepresentation::kWord32, value_count), |
| 801 value_count + 1, inputs_low, false), | 824 value_count + 1, inputs_low, false), |
| 802 graph()->NewNode( | 825 graph()->NewNode( |
| 803 common()->Phi(MachineRepresentation::kWord32, value_count), | 826 common()->Phi(MachineRepresentation::kWord32, value_count), |
| 804 value_count + 1, inputs_high, false)); | 827 value_count + 1, inputs_high, false)); |
| 805 } | 828 } |
| 806 } | 829 } |
| 807 } // namespace compiler | 830 } // namespace compiler |
| 808 } // namespace internal | 831 } // namespace internal |
| 809 } // namespace v8 | 832 } // namespace v8 |
| OLD | NEW |