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/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.h" |
6 #include "src/compiler/register-allocator.h" | 6 #include "src/compiler/instruction.h" |
7 #include "src/compiler/register-allocator-verifier.h" | 7 #include "src/compiler/pipeline.h" |
8 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
15 typedef BasicBlock::RpoNumber Rpo; | 15 typedef BasicBlock::RpoNumber Rpo; |
16 | 16 |
17 static const char* | 17 static const char* |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 InstructionSequence* sequence() { | 162 InstructionSequence* sequence() { |
163 if (sequence_ == nullptr) { | 163 if (sequence_ == nullptr) { |
164 sequence_ = | 164 sequence_ = |
165 new (zone()) InstructionSequence(zone(), &instruction_blocks_); | 165 new (zone()) InstructionSequence(zone(), &instruction_blocks_); |
166 } | 166 } |
167 return sequence_; | 167 return sequence_; |
168 } | 168 } |
169 | 169 |
170 RegisterAllocator* allocator() { | |
171 if (allocator_.is_empty()) { | |
172 allocator_.Reset( | |
173 new RegisterAllocator(config(), zone(), frame(), sequence())); | |
174 } | |
175 return allocator_.get(); | |
176 } | |
177 | |
178 void StartLoop(int loop_blocks) { | 170 void StartLoop(int loop_blocks) { |
179 CHECK(current_block_ == nullptr); | 171 CHECK(current_block_ == nullptr); |
180 if (!loop_blocks_.empty()) { | 172 if (!loop_blocks_.empty()) { |
181 CHECK(!loop_blocks_.back().loop_header_.IsValid()); | 173 CHECK(!loop_blocks_.back().loop_header_.IsValid()); |
182 } | 174 } |
183 LoopData loop_data = {Rpo::Invalid(), loop_blocks}; | 175 LoopData loop_data = {Rpo::Invalid(), loop_blocks}; |
184 loop_blocks_.push_back(loop_data); | 176 loop_blocks_.push_back(loop_data); |
185 } | 177 } |
186 | 178 |
187 void EndLoop() { | 179 void EndLoop() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 completions_.push_back(completion); | 212 completions_.push_back(completion); |
221 CHECK(current_block_ != nullptr); | 213 CHECK(current_block_ != nullptr); |
222 sequence()->EndBlock(current_block_->rpo_number()); | 214 sequence()->EndBlock(current_block_->rpo_number()); |
223 current_block_ = nullptr; | 215 current_block_ = nullptr; |
224 return instruction_index; | 216 return instruction_index; |
225 } | 217 } |
226 | 218 |
227 void Allocate() { | 219 void Allocate() { |
228 CHECK_EQ(nullptr, current_block_); | 220 CHECK_EQ(nullptr, current_block_); |
229 WireBlocks(); | 221 WireBlocks(); |
230 RegisterAllocatorVerifier verifier(zone(), config(), sequence()); | 222 Pipeline::AllocateRegisters(config(), sequence(), true); |
231 if (FLAG_trace_alloc || FLAG_trace_turbo) { | |
232 OFStream os(stdout); | |
233 PrintableInstructionSequence printable = {config(), sequence()}; | |
234 os << "Before: " << std::endl << printable << std::endl; | |
235 } | |
236 allocator()->Allocate(); | |
237 if (FLAG_trace_alloc || FLAG_trace_turbo) { | |
238 OFStream os(stdout); | |
239 PrintableInstructionSequence printable = {config(), sequence()}; | |
240 os << "After: " << std::endl << printable << std::endl; | |
241 } | |
242 verifier.VerifyAssignment(); | |
243 verifier.VerifyGapMoves(); | |
244 } | 223 } |
245 | 224 |
246 TestOperand Imm(int32_t imm = 0) { | 225 TestOperand Imm(int32_t imm = 0) { |
247 int index = sequence()->AddImmediate(Constant(imm)); | 226 int index = sequence()->AddImmediate(Constant(imm)); |
248 return TestOperand(kImmediate, index); | 227 return TestOperand(kImmediate, index); |
249 } | 228 } |
250 | 229 |
251 VReg Parameter(TestOperand output_op = Reg()) { | 230 VReg Parameter(TestOperand output_op = Reg()) { |
252 VReg vreg = NewReg(); | 231 VReg vreg = NewReg(); |
253 InstructionOperand* outputs[1]{ConvertOutputOp(vreg, output_op)}; | 232 InstructionOperand* outputs[1]{ConvertOutputOp(vreg, output_op)}; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 Rpo loop_header_; | 492 Rpo loop_header_; |
514 int expected_blocks_; | 493 int expected_blocks_; |
515 }; | 494 }; |
516 | 495 |
517 typedef std::vector<LoopData> LoopBlocks; | 496 typedef std::vector<LoopData> LoopBlocks; |
518 typedef std::map<int, const Instruction*> Instructions; | 497 typedef std::map<int, const Instruction*> Instructions; |
519 typedef std::vector<BlockCompletion> Completions; | 498 typedef std::vector<BlockCompletion> Completions; |
520 | 499 |
521 SmartPointer<RegisterConfiguration> config_; | 500 SmartPointer<RegisterConfiguration> config_; |
522 Frame* frame_; | 501 Frame* frame_; |
523 SmartPointer<RegisterAllocator> allocator_; | |
524 InstructionSequence* sequence_; | 502 InstructionSequence* sequence_; |
525 int num_general_registers_; | 503 int num_general_registers_; |
526 int num_double_registers_; | 504 int num_double_registers_; |
527 | 505 |
528 // Block building state. | 506 // Block building state. |
529 InstructionBlocks instruction_blocks_; | 507 InstructionBlocks instruction_blocks_; |
530 Instructions instructions_; | 508 Instructions instructions_; |
531 int current_instruction_index_; | 509 int current_instruction_index_; |
532 Completions completions_; | 510 Completions completions_; |
533 LoopBlocks loop_blocks_; | 511 LoopBlocks loop_blocks_; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 StartBlock(); | 724 StartBlock(); |
747 Return(DefineConstant()); | 725 Return(DefineConstant()); |
748 EndBlock(); | 726 EndBlock(); |
749 | 727 |
750 Allocate(); | 728 Allocate(); |
751 } | 729 } |
752 | 730 |
753 } // namespace compiler | 731 } // namespace compiler |
754 } // namespace internal | 732 } // namespace internal |
755 } // namespace v8 | 733 } // namespace v8 |
OLD | NEW |