| 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/instruction-selector.h" | 5 #include "src/compiler/instruction-selector.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "src/compiler/instruction-selector-impl.h" | 9 #include "src/compiler/instruction-selector-impl.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| 11 #include "src/compiler/node-properties.h" | 11 #include "src/compiler/node-properties.h" |
| 12 #include "src/compiler/pipeline.h" | 12 #include "src/compiler/pipeline.h" |
| 13 #include "src/compiler/schedule.h" |
| 13 | 14 |
| 14 namespace v8 { | 15 namespace v8 { |
| 15 namespace internal { | 16 namespace internal { |
| 16 namespace compiler { | 17 namespace compiler { |
| 17 | 18 |
| 18 InstructionSelector::InstructionSelector(Zone* zone, size_t node_count, | 19 InstructionSelector::InstructionSelector(Zone* zone, size_t node_count, |
| 19 Linkage* linkage, | 20 Linkage* linkage, |
| 20 InstructionSequence* sequence, | 21 InstructionSequence* sequence, |
| 21 Schedule* schedule, | 22 Schedule* schedule, |
| 22 SourcePositionTable* source_positions, | 23 SourcePositionTable* source_positions, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Visit each basic block in post order. | 57 // Visit each basic block in post order. |
| 57 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { | 58 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { |
| 58 VisitBlock(*i); | 59 VisitBlock(*i); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Schedule the selected instructions. | 62 // Schedule the selected instructions. |
| 62 for (auto const block : *blocks) { | 63 for (auto const block : *blocks) { |
| 63 InstructionBlock* instruction_block = | 64 InstructionBlock* instruction_block = |
| 64 sequence()->InstructionBlockAt(block->GetRpoNumber()); | 65 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
| 65 size_t end = instruction_block->code_end(); | 66 size_t end = instruction_block->code_end(); |
| 66 size_t start = instruction_block->code_start(); | 67 size_t start = instruction_block->code_start(); |
| 67 DCHECK_LE(end, start); | 68 DCHECK_LE(end, start); |
| 68 sequence()->StartBlock(block->GetRpoNumber()); | 69 sequence()->StartBlock(RpoNumber::FromInt(block->rpo_number())); |
| 69 while (start-- > end) { | 70 while (start-- > end) { |
| 70 sequence()->AddInstruction(instructions_[start]); | 71 sequence()->AddInstruction(instructions_[start]); |
| 71 } | 72 } |
| 72 sequence()->EndBlock(block->GetRpoNumber()); | 73 sequence()->EndBlock(RpoNumber::FromInt(block->rpo_number())); |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 | 76 |
| 76 | 77 |
| 77 Instruction* InstructionSelector::Emit(InstructionCode opcode, | 78 Instruction* InstructionSelector::Emit(InstructionCode opcode, |
| 78 InstructionOperand output, | 79 InstructionOperand output, |
| 79 size_t temp_count, | 80 size_t temp_count, |
| 80 InstructionOperand* temps) { | 81 InstructionOperand* temps) { |
| 81 size_t output_count = output.IsInvalid() ? 0 : 1; | 82 size_t output_count = output.IsInvalid() ? 0 : 1; |
| 82 return Emit(opcode, output_count, &output, 0, NULL, temp_count, temps); | 83 return Emit(opcode, output_count, &output, 0, NULL, temp_count, temps); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 if (!IsUsed(node) || IsDefined(node)) continue; | 471 if (!IsUsed(node) || IsDefined(node)) continue; |
| 471 // Generate code for this node "top down", but schedule the code "bottom | 472 // Generate code for this node "top down", but schedule the code "bottom |
| 472 // up". | 473 // up". |
| 473 size_t current_node_end = instructions_.size(); | 474 size_t current_node_end = instructions_.size(); |
| 474 VisitNode(node); | 475 VisitNode(node); |
| 475 std::reverse(instructions_.begin() + current_node_end, instructions_.end()); | 476 std::reverse(instructions_.begin() + current_node_end, instructions_.end()); |
| 476 } | 477 } |
| 477 | 478 |
| 478 // We're done with the block. | 479 // We're done with the block. |
| 479 InstructionBlock* instruction_block = | 480 InstructionBlock* instruction_block = |
| 480 sequence()->InstructionBlockAt(block->GetRpoNumber()); | 481 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
| 481 instruction_block->set_code_start(static_cast<int>(instructions_.size())); | 482 instruction_block->set_code_start(static_cast<int>(instructions_.size())); |
| 482 instruction_block->set_code_end(current_block_end); | 483 instruction_block->set_code_end(current_block_end); |
| 483 | 484 |
| 484 current_block_ = NULL; | 485 current_block_ = NULL; |
| 485 } | 486 } |
| 486 | 487 |
| 487 | 488 |
| 488 void InstructionSelector::VisitControl(BasicBlock* block) { | 489 void InstructionSelector::VisitControl(BasicBlock* block) { |
| 489 #ifdef DEBUG | 490 #ifdef DEBUG |
| 490 // SSA deconstruction requires targets of branches not to have phis. | 491 // SSA deconstruction requires targets of branches not to have phis. |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 Emit(kArchNop, g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index), | 1026 Emit(kArchNop, g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index), |
| 1026 kMachAnyTagged)); | 1027 kMachAnyTagged)); |
| 1027 } | 1028 } |
| 1028 | 1029 |
| 1029 | 1030 |
| 1030 void InstructionSelector::VisitPhi(Node* node) { | 1031 void InstructionSelector::VisitPhi(Node* node) { |
| 1031 const int input_count = node->op()->ValueInputCount(); | 1032 const int input_count = node->op()->ValueInputCount(); |
| 1032 PhiInstruction* phi = new (instruction_zone()) | 1033 PhiInstruction* phi = new (instruction_zone()) |
| 1033 PhiInstruction(instruction_zone(), GetVirtualRegister(node), | 1034 PhiInstruction(instruction_zone(), GetVirtualRegister(node), |
| 1034 static_cast<size_t>(input_count)); | 1035 static_cast<size_t>(input_count)); |
| 1035 sequence()->InstructionBlockAt(current_block_->GetRpoNumber())->AddPhi(phi); | 1036 sequence() |
| 1037 ->InstructionBlockAt(RpoNumber::FromInt(current_block_->rpo_number())) |
| 1038 ->AddPhi(phi); |
| 1036 for (int i = 0; i < input_count; ++i) { | 1039 for (int i = 0; i < input_count; ++i) { |
| 1037 Node* const input = node->InputAt(i); | 1040 Node* const input = node->InputAt(i); |
| 1038 MarkAsUsed(input); | 1041 MarkAsUsed(input); |
| 1039 phi->SetInput(static_cast<size_t>(i), GetVirtualRegister(input)); | 1042 phi->SetInput(static_cast<size_t>(i), GetVirtualRegister(input)); |
| 1040 } | 1043 } |
| 1041 } | 1044 } |
| 1042 | 1045 |
| 1043 | 1046 |
| 1044 void InstructionSelector::VisitProjection(Node* node) { | 1047 void InstructionSelector::VisitProjection(Node* node) { |
| 1045 OperandGenerator g(this); | 1048 OperandGenerator g(this); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 MachineOperatorBuilder::Flags | 1216 MachineOperatorBuilder::Flags |
| 1214 InstructionSelector::SupportedMachineOperatorFlags() { | 1217 InstructionSelector::SupportedMachineOperatorFlags() { |
| 1215 return MachineOperatorBuilder::Flag::kNoFlags; | 1218 return MachineOperatorBuilder::Flag::kNoFlags; |
| 1216 } | 1219 } |
| 1217 | 1220 |
| 1218 #endif // !V8_TURBOFAN_BACKEND | 1221 #endif // !V8_TURBOFAN_BACKEND |
| 1219 | 1222 |
| 1220 } // namespace compiler | 1223 } // namespace compiler |
| 1221 } // namespace internal | 1224 } // namespace internal |
| 1222 } // namespace v8 | 1225 } // namespace v8 |
| OLD | NEW |