Chromium Code Reviews| 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 int Int64Lowering::GetLowerWordOffset() { | |
|
titzer
2016/06/22 16:03:09
Can you go all the way and make these simple stati
ivica.bogosavljevic
2016/06/23 10:56:54
Acknowledged.
| |
| 117 #if defined(V8_TARGET_LITTLE_ENDIAN) | |
| 118 return 0; | |
| 119 #elif defined(V8_TARGET_BIG_ENDIAN) | |
| 120 return 4; | |
| 121 #endif | |
| 122 } | |
| 123 | |
| 124 int Int64Lowering::GetHigherWordOffset() { | |
| 125 #if defined(V8_TARGET_LITTLE_ENDIAN) | |
| 126 return 4; | |
| 127 #elif defined(V8_TARGET_BIG_ENDIAN) | |
| 128 return 0; | |
| 129 #endif | |
| 130 } | |
| 131 | |
| 103 void Int64Lowering::LowerNode(Node* node) { | 132 void Int64Lowering::LowerNode(Node* node) { |
| 104 switch (node->opcode()) { | 133 switch (node->opcode()) { |
| 105 case IrOpcode::kInt64Constant: { | 134 case IrOpcode::kInt64Constant: { |
| 106 int64_t value = OpParameter<int64_t>(node); | 135 int64_t value = OpParameter<int64_t>(node); |
| 107 Node* low_node = graph()->NewNode( | 136 Node* low_node = graph()->NewNode( |
| 108 common()->Int32Constant(static_cast<int32_t>(value & 0xFFFFFFFF))); | 137 common()->Int32Constant(static_cast<int32_t>(value & 0xFFFFFFFF))); |
| 109 Node* high_node = graph()->NewNode( | 138 Node* high_node = graph()->NewNode( |
| 110 common()->Int32Constant(static_cast<int32_t>(value >> 32))); | 139 common()->Int32Constant(static_cast<int32_t>(value >> 32))); |
| 111 ReplaceNode(node, low_node, high_node); | 140 ReplaceNode(node, low_node, high_node); |
| 112 break; | 141 break; |
| 113 } | 142 } |
| 114 case IrOpcode::kLoad: { | 143 case IrOpcode::kLoad: { |
| 115 LoadRepresentation load_rep = LoadRepresentationOf(node->op()); | 144 LoadRepresentation load_rep = LoadRepresentationOf(node->op()); |
| 116 | 145 |
| 117 if (load_rep.representation() == MachineRepresentation::kWord64) { | 146 if (load_rep.representation() == MachineRepresentation::kWord64) { |
| 118 Node* base = node->InputAt(0); | 147 Node* base = node->InputAt(0); |
| 119 Node* index = node->InputAt(1); | 148 Node* index = node->InputAt(1); |
| 120 Node* index_high = | 149 Node* index_low; |
| 121 graph()->NewNode(machine()->Int32Add(), index, | 150 Node* index_high; |
| 122 graph()->NewNode(common()->Int32Constant(4))); | 151 GetIndexNodes(index, index_low, index_high); |
| 123 | |
| 124 const Operator* load_op = machine()->Load(MachineType::Int32()); | 152 const Operator* load_op = machine()->Load(MachineType::Int32()); |
| 125 Node* high_node; | 153 Node* high_node; |
| 126 if (node->InputCount() > 2) { | 154 if (node->InputCount() > 2) { |
| 127 Node* effect_high = node->InputAt(2); | 155 Node* effect_high = node->InputAt(2); |
| 128 Node* control_high = node->InputAt(3); | 156 Node* control_high = node->InputAt(3); |
| 129 high_node = graph()->NewNode(load_op, base, index_high, effect_high, | 157 high_node = graph()->NewNode(load_op, base, index_high, effect_high, |
| 130 control_high); | 158 control_high); |
| 131 // change the effect change from old_node --> old_effect to | 159 // change the effect change from old_node --> old_effect to |
| 132 // old_node --> high_node --> old_effect. | 160 // old_node --> high_node --> old_effect. |
| 133 node->ReplaceInput(2, high_node); | 161 node->ReplaceInput(2, high_node); |
| 134 } else { | 162 } else { |
| 135 high_node = graph()->NewNode(load_op, base, index_high); | 163 high_node = graph()->NewNode(load_op, base, index_high); |
| 136 } | 164 } |
| 165 node->ReplaceInput(1, index_low); | |
| 137 NodeProperties::ChangeOp(node, load_op); | 166 NodeProperties::ChangeOp(node, load_op); |
| 138 ReplaceNode(node, node, high_node); | 167 ReplaceNode(node, node, high_node); |
| 139 } else { | 168 } else { |
| 140 DefaultLowering(node); | 169 DefaultLowering(node); |
| 141 } | 170 } |
| 142 break; | 171 break; |
| 143 } | 172 } |
| 144 case IrOpcode::kStore: { | 173 case IrOpcode::kStore: { |
| 145 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); | 174 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); |
| 146 if (store_rep.representation() == MachineRepresentation::kWord64) { | 175 if (store_rep.representation() == MachineRepresentation::kWord64) { |
| 147 // We change the original store node to store the low word, and create | 176 // 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 | 177 // 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 | 178 // 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. | 179 // edge of the original store is redirected to the new store. |
| 151 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind(); | 180 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind(); |
| 152 | 181 |
| 153 Node* base = node->InputAt(0); | 182 Node* base = node->InputAt(0); |
| 154 Node* index = node->InputAt(1); | 183 Node* index = node->InputAt(1); |
| 155 Node* index_high = | 184 Node* index_low; |
| 156 graph()->NewNode(machine()->Int32Add(), index, | 185 Node* index_high; |
| 157 graph()->NewNode(common()->Int32Constant(4))); | 186 GetIndexNodes(index, index_low, index_high); |
| 158 | |
| 159 Node* value = node->InputAt(2); | 187 Node* value = node->InputAt(2); |
| 160 DCHECK(HasReplacementLow(value)); | 188 DCHECK(HasReplacementLow(value)); |
| 161 DCHECK(HasReplacementHigh(value)); | 189 DCHECK(HasReplacementHigh(value)); |
| 162 | 190 |
| 163 const Operator* store_op = machine()->Store(StoreRepresentation( | 191 const Operator* store_op = machine()->Store(StoreRepresentation( |
| 164 MachineRepresentation::kWord32, write_barrier_kind)); | 192 MachineRepresentation::kWord32, write_barrier_kind)); |
| 165 | 193 |
| 166 Node* high_node; | 194 Node* high_node; |
| 167 if (node->InputCount() > 3) { | 195 if (node->InputCount() > 3) { |
| 168 Node* effect_high = node->InputAt(3); | 196 Node* effect_high = node->InputAt(3); |
| 169 Node* control_high = node->InputAt(4); | 197 Node* control_high = node->InputAt(4); |
| 170 high_node = graph()->NewNode(store_op, base, index_high, | 198 high_node = graph()->NewNode(store_op, base, index_high, |
| 171 GetReplacementHigh(value), effect_high, | 199 GetReplacementHigh(value), effect_high, |
| 172 control_high); | 200 control_high); |
| 173 node->ReplaceInput(3, high_node); | 201 node->ReplaceInput(3, high_node); |
| 174 | 202 |
| 175 } else { | 203 } else { |
| 176 high_node = graph()->NewNode(store_op, base, index_high, | 204 high_node = graph()->NewNode(store_op, base, index_high, |
| 177 GetReplacementHigh(value)); | 205 GetReplacementHigh(value)); |
| 178 } | 206 } |
| 179 | 207 |
| 208 node->ReplaceInput(1, index_low); | |
| 180 node->ReplaceInput(2, GetReplacementLow(value)); | 209 node->ReplaceInput(2, GetReplacementLow(value)); |
| 181 NodeProperties::ChangeOp(node, store_op); | 210 NodeProperties::ChangeOp(node, store_op); |
| 182 ReplaceNode(node, node, high_node); | 211 ReplaceNode(node, node, high_node); |
| 183 } else { | 212 } else { |
| 184 if (HasReplacementLow(node->InputAt(2))) { | 213 if (HasReplacementLow(node->InputAt(2))) { |
| 185 node->ReplaceInput(2, GetReplacementLow(node->InputAt(2))); | 214 node->ReplaceInput(2, GetReplacementLow(node->InputAt(2))); |
| 186 } | 215 } |
| 187 } | 216 } |
| 188 break; | 217 break; |
| 189 } | 218 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 case IrOpcode::kBitcastInt64ToFloat64: { | 513 case IrOpcode::kBitcastInt64ToFloat64: { |
| 485 DCHECK(node->InputCount() == 1); | 514 DCHECK(node->InputCount() == 1); |
| 486 Node* input = node->InputAt(0); | 515 Node* input = node->InputAt(0); |
| 487 Node* stack_slot = graph()->NewNode( | 516 Node* stack_slot = graph()->NewNode( |
| 488 machine()->StackSlot(MachineRepresentation::kWord64)); | 517 machine()->StackSlot(MachineRepresentation::kWord64)); |
| 489 | 518 |
| 490 Node* store_high_word = graph()->NewNode( | 519 Node* store_high_word = graph()->NewNode( |
| 491 machine()->Store( | 520 machine()->Store( |
| 492 StoreRepresentation(MachineRepresentation::kWord32, | 521 StoreRepresentation(MachineRepresentation::kWord32, |
| 493 WriteBarrierKind::kNoWriteBarrier)), | 522 WriteBarrierKind::kNoWriteBarrier)), |
| 494 stack_slot, graph()->NewNode(common()->Int32Constant(4)), | 523 stack_slot, |
| 524 graph()->NewNode(common()->Int32Constant(GetHigherWordOffset())), | |
| 495 GetReplacementHigh(input), graph()->start(), graph()->start()); | 525 GetReplacementHigh(input), graph()->start(), graph()->start()); |
| 496 | 526 |
| 497 Node* store_low_word = graph()->NewNode( | 527 Node* store_low_word = graph()->NewNode( |
| 498 machine()->Store( | 528 machine()->Store( |
| 499 StoreRepresentation(MachineRepresentation::kWord32, | 529 StoreRepresentation(MachineRepresentation::kWord32, |
| 500 WriteBarrierKind::kNoWriteBarrier)), | 530 WriteBarrierKind::kNoWriteBarrier)), |
| 501 stack_slot, graph()->NewNode(common()->Int32Constant(0)), | 531 stack_slot, |
| 532 graph()->NewNode(common()->Int32Constant(GetLowerWordOffset())), | |
| 502 GetReplacementLow(input), store_high_word, graph()->start()); | 533 GetReplacementLow(input), store_high_word, graph()->start()); |
| 503 | 534 |
| 504 Node* load = | 535 Node* load = |
| 505 graph()->NewNode(machine()->Load(MachineType::Float64()), stack_slot, | 536 graph()->NewNode(machine()->Load(MachineType::Float64()), stack_slot, |
| 506 graph()->NewNode(common()->Int32Constant(0)), | 537 graph()->NewNode(common()->Int32Constant(0)), |
| 507 store_low_word, graph()->start()); | 538 store_low_word, graph()->start()); |
| 508 | 539 |
| 509 ReplaceNode(node, load, nullptr); | 540 ReplaceNode(node, load, nullptr); |
| 510 break; | 541 break; |
| 511 } | 542 } |
| 512 case IrOpcode::kBitcastFloat64ToInt64: { | 543 case IrOpcode::kBitcastFloat64ToInt64: { |
| 513 DCHECK(node->InputCount() == 1); | 544 DCHECK(node->InputCount() == 1); |
| 514 Node* input = node->InputAt(0); | 545 Node* input = node->InputAt(0); |
| 515 if (HasReplacementLow(input)) { | 546 if (HasReplacementLow(input)) { |
| 516 input = GetReplacementLow(input); | 547 input = GetReplacementLow(input); |
| 517 } | 548 } |
| 518 Node* stack_slot = graph()->NewNode( | 549 Node* stack_slot = graph()->NewNode( |
| 519 machine()->StackSlot(MachineRepresentation::kWord64)); | 550 machine()->StackSlot(MachineRepresentation::kWord64)); |
| 520 Node* store = graph()->NewNode( | 551 Node* store = graph()->NewNode( |
| 521 machine()->Store( | 552 machine()->Store( |
| 522 StoreRepresentation(MachineRepresentation::kFloat64, | 553 StoreRepresentation(MachineRepresentation::kFloat64, |
| 523 WriteBarrierKind::kNoWriteBarrier)), | 554 WriteBarrierKind::kNoWriteBarrier)), |
| 524 stack_slot, graph()->NewNode(common()->Int32Constant(0)), input, | 555 stack_slot, graph()->NewNode(common()->Int32Constant(0)), input, |
| 525 graph()->start(), graph()->start()); | 556 graph()->start(), graph()->start()); |
| 526 | 557 |
| 527 Node* high_node = | 558 Node* high_node = graph()->NewNode( |
| 528 graph()->NewNode(machine()->Load(MachineType::Int32()), stack_slot, | 559 machine()->Load(MachineType::Int32()), stack_slot, |
| 529 graph()->NewNode(common()->Int32Constant(4)), store, | 560 graph()->NewNode(common()->Int32Constant(GetHigherWordOffset())), |
| 530 graph()->start()); | 561 store, graph()->start()); |
| 531 | 562 |
| 532 Node* low_node = | 563 Node* low_node = graph()->NewNode( |
| 533 graph()->NewNode(machine()->Load(MachineType::Int32()), stack_slot, | 564 machine()->Load(MachineType::Int32()), stack_slot, |
| 534 graph()->NewNode(common()->Int32Constant(0)), store, | 565 graph()->NewNode(common()->Int32Constant(GetLowerWordOffset())), |
| 535 graph()->start()); | 566 store, graph()->start()); |
| 536 ReplaceNode(node, low_node, high_node); | 567 ReplaceNode(node, low_node, high_node); |
| 537 break; | 568 break; |
| 538 } | 569 } |
| 539 case IrOpcode::kWord64Ror: { | 570 case IrOpcode::kWord64Ror: { |
| 540 DCHECK(node->InputCount() == 2); | 571 DCHECK(node->InputCount() == 2); |
| 541 Node* input = node->InputAt(0); | 572 Node* input = node->InputAt(0); |
| 542 Node* shift = HasReplacementLow(node->InputAt(1)) | 573 Node* shift = HasReplacementLow(node->InputAt(1)) |
| 543 ? GetReplacementLow(node->InputAt(1)) | 574 ? GetReplacementLow(node->InputAt(1)) |
| 544 : node->InputAt(1); | 575 : node->InputAt(1); |
| 545 Int32Matcher m(shift); | 576 Int32Matcher m(shift); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 common()->Phi(MachineRepresentation::kWord32, value_count), | 831 common()->Phi(MachineRepresentation::kWord32, value_count), |
| 801 value_count + 1, inputs_low, false), | 832 value_count + 1, inputs_low, false), |
| 802 graph()->NewNode( | 833 graph()->NewNode( |
| 803 common()->Phi(MachineRepresentation::kWord32, value_count), | 834 common()->Phi(MachineRepresentation::kWord32, value_count), |
| 804 value_count + 1, inputs_high, false)); | 835 value_count + 1, inputs_high, false)); |
| 805 } | 836 } |
| 806 } | 837 } |
| 807 } // namespace compiler | 838 } // namespace compiler |
| 808 } // namespace internal | 839 } // namespace internal |
| 809 } // namespace v8 | 840 } // namespace v8 |
| OLD | NEW |