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

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: Addressed issues and add support for a few other platforms. Created 5 years, 1 month 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 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 instruction_zone()); 1454 instruction_zone());
1420 1455
1421 DCHECK_EQ(args.size(), arg_count); 1456 DCHECK_EQ(args.size(), arg_count);
1422 1457
1423 Emit(kArchDeoptimize, 0, nullptr, arg_count, &args.front(), 0, nullptr); 1458 Emit(kArchDeoptimize, 0, nullptr, arg_count, &args.front(), 0, nullptr);
1424 } 1459 }
1425 1460
1426 1461
1427 void InstructionSelector::VisitThrow(Node* value) { 1462 void InstructionSelector::VisitThrow(Node* value) {
1428 OperandGenerator g(this); 1463 OperandGenerator g(this);
1429 Emit(kArchNop, g.NoOutput()); // TODO(titzer) 1464 Emit(kArchThrowTerminator, g.NoOutput()); // TODO(titzer)
1430 } 1465 }
1431 1466
1432 1467
1433 FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor( 1468 FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
1434 Node* state) { 1469 Node* state) {
1435 DCHECK(state->opcode() == IrOpcode::kFrameState); 1470 DCHECK(state->opcode() == IrOpcode::kFrameState);
1436 DCHECK_EQ(kFrameStateInputCount, state->InputCount()); 1471 DCHECK_EQ(kFrameStateInputCount, state->InputCount());
1437 FrameStateInfo state_info = OpParameter<FrameStateInfo>(state); 1472 FrameStateInfo state_info = OpParameter<FrameStateInfo>(state);
1438 1473
1439 int parameters = static_cast<int>( 1474 int parameters = static_cast<int>(
(...skipping 15 matching lines...) Expand all
1455 return new (instruction_zone()) FrameStateDescriptor( 1490 return new (instruction_zone()) FrameStateDescriptor(
1456 instruction_zone(), state_info.type(), state_info.bailout_id(), 1491 instruction_zone(), state_info.type(), state_info.bailout_id(),
1457 state_info.state_combine(), parameters, locals, stack, 1492 state_info.state_combine(), parameters, locals, stack,
1458 state_info.shared_info(), outer_state); 1493 state_info.shared_info(), outer_state);
1459 } 1494 }
1460 1495
1461 1496
1462 } // namespace compiler 1497 } // namespace compiler
1463 } // namespace internal 1498 } // namespace internal
1464 } // namespace v8 1499 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698