Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: src/compiler/instruction-selector.cc

Issue 1375253002: [WIP][turbofan] Instruction scheduler for Turbofan. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/base/adapters.h" 9 #include "src/base/adapters.h"
10 #include "src/compiler/instruction-selector-impl.h" 10 #include "src/compiler/instruction-selector-impl.h"
(...skipping 11 matching lines...) Expand all
22 InstructionSequence* sequence, Schedule* schedule, 22 InstructionSequence* sequence, Schedule* schedule,
23 SourcePositionTable* source_positions, 23 SourcePositionTable* source_positions,
24 SourcePositionMode source_position_mode, Features features) 24 SourcePositionMode source_position_mode, Features features)
25 : zone_(zone), 25 : zone_(zone),
26 linkage_(linkage), 26 linkage_(linkage),
27 sequence_(sequence), 27 sequence_(sequence),
28 source_positions_(source_positions), 28 source_positions_(source_positions),
29 source_position_mode_(source_position_mode), 29 source_position_mode_(source_position_mode),
30 features_(features), 30 features_(features),
31 schedule_(schedule), 31 schedule_(schedule),
32 current_block_(NULL), 32 current_block_(nullptr),
33 instructions_(zone), 33 instructions_(zone),
34 defined_(node_count, false, zone), 34 defined_(node_count, false, zone),
35 used_(node_count, false, zone), 35 used_(node_count, false, zone),
36 virtual_registers_(node_count, 36 virtual_registers_(node_count,
37 InstructionOperand::kInvalidVirtualRegister, zone) { 37 InstructionOperand::kInvalidVirtualRegister, zone),
38 scheduler_(nullptr) {
38 instructions_.reserve(node_count); 39 instructions_.reserve(node_count);
39 } 40 }
40 41
41 42
42 void InstructionSelector::SelectInstructions() { 43 void InstructionSelector::SelectInstructions() {
43 // Mark the inputs of all phis in loop headers as used. 44 // Mark the inputs of all phis in loop headers as used.
44 BasicBlockVector* blocks = schedule()->rpo_order(); 45 BasicBlockVector* blocks = schedule()->rpo_order();
45 for (auto const block : *blocks) { 46 for (auto const block : *blocks) {
46 if (!block->IsLoopHeader()) continue; 47 if (!block->IsLoopHeader()) continue;
47 DCHECK_LE(2u, block->PredecessorCount()); 48 DCHECK_LE(2u, block->PredecessorCount());
48 for (Node* const phi : *block) { 49 for (Node* const phi : *block) {
49 if (phi->opcode() != IrOpcode::kPhi) continue; 50 if (phi->opcode() != IrOpcode::kPhi) continue;
50 51
51 // Mark all inputs as used. 52 // Mark all inputs as used.
52 for (Node* const input : phi->inputs()) { 53 for (Node* const input : phi->inputs()) {
53 MarkAsUsed(input); 54 MarkAsUsed(input);
54 } 55 }
55 } 56 }
56 } 57 }
57 58
58 // Visit each basic block in post order. 59 // Visit each basic block in post order.
59 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { 60 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) {
60 VisitBlock(*i); 61 VisitBlock(*i);
61 } 62 }
62 63
63 // Schedule the selected instructions. 64 // Schedule the selected instructions.
65 if (FLAG_turbo_instruction_scheduling) {
66 scheduler_ = new (zone()) InstructionScheduler(zone(), sequence());
67 }
68
64 for (auto const block : *blocks) { 69 for (auto const block : *blocks) {
65 InstructionBlock* instruction_block = 70 InstructionBlock* instruction_block =
66 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); 71 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
67 size_t end = instruction_block->code_end(); 72 size_t end = instruction_block->code_end();
68 size_t start = instruction_block->code_start(); 73 size_t start = instruction_block->code_start();
69 DCHECK_LE(end, start); 74 DCHECK_LE(end, start);
70 sequence()->StartBlock(RpoNumber::FromInt(block->rpo_number())); 75 StartBlock(RpoNumber::FromInt(block->rpo_number()));
71 while (start-- > end) { 76 while (start-- > end) {
72 sequence()->AddInstruction(instructions_[start]); 77 AddInstruction(instructions_[start]);
73 } 78 }
74 sequence()->EndBlock(RpoNumber::FromInt(block->rpo_number())); 79 EndBlock(RpoNumber::FromInt(block->rpo_number()));
75 } 80 }
76 } 81 }
77 82
83
84 void InstructionSelector::StartBlock(RpoNumber rpo) {
85 if (FLAG_turbo_instruction_scheduling) {
86 DCHECK(scheduler_ != nullptr);
87 scheduler_->StartBlock(rpo);
88 } else {
89 sequence()->StartBlock(rpo);
90 }
91 }
92
93
94 void InstructionSelector::EndBlock(RpoNumber rpo) {
95 if (FLAG_turbo_instruction_scheduling) {
96 DCHECK(scheduler_ != nullptr);
97 scheduler_->EndBlock(rpo);
98 } else {
99 sequence()->EndBlock(rpo);
100 }
101 }
102
103
104 void InstructionSelector::AddInstruction(Instruction* instr) {
105 if (FLAG_turbo_instruction_scheduling) {
106 DCHECK(scheduler_ != nullptr);
107 scheduler_->AddInstruction(instr);
108 } else {
109 sequence()->AddInstruction(instr);
110 }
111 }
112
78 113
79 Instruction* InstructionSelector::Emit(InstructionCode opcode, 114 Instruction* InstructionSelector::Emit(InstructionCode opcode,
80 InstructionOperand output, 115 InstructionOperand output,
81 size_t temp_count, 116 size_t temp_count,
82 InstructionOperand* temps) { 117 InstructionOperand* temps) {
83 size_t output_count = output.IsInvalid() ? 0 : 1; 118 size_t output_count = output.IsInvalid() ? 0 : 1;
84 return Emit(opcode, output_count, &output, 0, NULL, temp_count, temps); 119 return Emit(opcode, output_count, &output, 0, NULL, temp_count, temps);
85 } 120 }
86 121
87 122
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 instruction_zone()); 1462 instruction_zone());
1428 1463
1429 DCHECK_EQ(args.size(), arg_count); 1464 DCHECK_EQ(args.size(), arg_count);
1430 1465
1431 Emit(kArchDeoptimize, 0, nullptr, arg_count, &args.front(), 0, nullptr); 1466 Emit(kArchDeoptimize, 0, nullptr, arg_count, &args.front(), 0, nullptr);
1432 } 1467 }
1433 1468
1434 1469
1435 void InstructionSelector::VisitThrow(Node* value) { 1470 void InstructionSelector::VisitThrow(Node* value) {
1436 OperandGenerator g(this); 1471 OperandGenerator g(this);
1437 Emit(kArchNop, g.NoOutput()); // TODO(titzer) 1472 Emit(kArchThrowTerminator, g.NoOutput()); // TODO(titzer)
1438 } 1473 }
1439 1474
1440 1475
1441 FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor( 1476 FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
1442 Node* state) { 1477 Node* state) {
1443 DCHECK(state->opcode() == IrOpcode::kFrameState); 1478 DCHECK(state->opcode() == IrOpcode::kFrameState);
1444 DCHECK_EQ(kFrameStateInputCount, state->InputCount()); 1479 DCHECK_EQ(kFrameStateInputCount, state->InputCount());
1445 FrameStateInfo state_info = OpParameter<FrameStateInfo>(state); 1480 FrameStateInfo state_info = OpParameter<FrameStateInfo>(state);
1446 1481
1447 int parameters = static_cast<int>( 1482 int parameters = static_cast<int>(
(...skipping 15 matching lines...) Expand all
1463 return new (instruction_zone()) FrameStateDescriptor( 1498 return new (instruction_zone()) FrameStateDescriptor(
1464 instruction_zone(), state_info.type(), state_info.bailout_id(), 1499 instruction_zone(), state_info.type(), state_info.bailout_id(),
1465 state_info.state_combine(), parameters, locals, stack, 1500 state_info.state_combine(), parameters, locals, stack,
1466 state_info.shared_info(), outer_state); 1501 state_info.shared_info(), outer_state);
1467 } 1502 }
1468 1503
1469 1504
1470 } // namespace compiler 1505 } // namespace compiler
1471 } // namespace internal 1506 } // namespace internal
1472 } // namespace v8 1507 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698