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/register-allocator.h" |
7 #include "src/compiler/register-allocator-verifier.h" | 7 #include "src/compiler/register-allocator-verifier.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 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 BlockCompletion completion = {kBranch, op, left_offset, right_offset}; | 117 BlockCompletion completion = {kBranch, op, left_offset, right_offset}; |
118 return completion; | 118 return completion; |
119 } | 119 } |
120 | 120 |
121 static BlockCompletion Last() { | 121 static BlockCompletion Last() { |
122 BlockCompletion completion = {kBlockEnd, TestOperand(), kNoValue, kNoValue}; | 122 BlockCompletion completion = {kBlockEnd, TestOperand(), kNoValue, kNoValue}; |
123 return completion; | 123 return completion; |
124 } | 124 } |
125 | 125 |
126 RegisterAllocatorTest() | 126 RegisterAllocatorTest() |
127 : num_general_registers_(kDefaultNRegs), | 127 : frame_(nullptr), |
| 128 sequence_(nullptr), |
| 129 num_general_registers_(kDefaultNRegs), |
128 num_double_registers_(kDefaultNRegs), | 130 num_double_registers_(kDefaultNRegs), |
129 instruction_blocks_(zone()), | 131 instruction_blocks_(zone()), |
130 current_instruction_index_(-1), | 132 current_instruction_index_(-1), |
131 current_block_(nullptr), | 133 current_block_(nullptr), |
132 block_returns_(false) { | 134 block_returns_(false) { |
133 InitializeRegisterNames(); | 135 InitializeRegisterNames(); |
134 } | 136 } |
135 | 137 |
136 void SetNumRegs(int num_general_registers, int num_double_registers) { | 138 void SetNumRegs(int num_general_registers, int num_double_registers) { |
137 CHECK(config_.is_empty()); | 139 CHECK(config_.is_empty()); |
138 CHECK(instructions_.empty()); | 140 CHECK(instructions_.empty()); |
139 CHECK(instruction_blocks_.empty()); | 141 CHECK(instruction_blocks_.empty()); |
140 num_general_registers_ = num_general_registers; | 142 num_general_registers_ = num_general_registers; |
141 num_double_registers_ = num_double_registers; | 143 num_double_registers_ = num_double_registers; |
142 } | 144 } |
143 | 145 |
144 RegisterConfiguration* config() { | 146 RegisterConfiguration* config() { |
145 if (config_.is_empty()) { | 147 if (config_.is_empty()) { |
146 config_.Reset(new RegisterConfiguration( | 148 config_.Reset(new RegisterConfiguration( |
147 num_general_registers_, num_double_registers_, num_double_registers_, | 149 num_general_registers_, num_double_registers_, num_double_registers_, |
148 general_register_names_, double_register_names_)); | 150 general_register_names_, double_register_names_)); |
149 } | 151 } |
150 return config_.get(); | 152 return config_.get(); |
151 } | 153 } |
152 | 154 |
153 Frame* frame() { | 155 Frame* frame() { |
154 if (frame_.is_empty()) { | 156 if (frame_ == nullptr) { |
155 frame_.Reset(new Frame()); | 157 frame_ = new (zone()) Frame(); |
156 } | 158 } |
157 return frame_.get(); | 159 return frame_; |
158 } | 160 } |
159 | 161 |
160 InstructionSequence* sequence() { | 162 InstructionSequence* sequence() { |
161 if (sequence_.is_empty()) { | 163 if (sequence_ == nullptr) { |
162 sequence_.Reset(new InstructionSequence(zone(), &instruction_blocks_)); | 164 sequence_ = |
| 165 new (zone()) InstructionSequence(zone(), &instruction_blocks_); |
163 } | 166 } |
164 return sequence_.get(); | 167 return sequence_; |
165 } | 168 } |
166 | 169 |
167 RegisterAllocator* allocator() { | 170 RegisterAllocator* allocator() { |
168 if (allocator_.is_empty()) { | 171 if (allocator_.is_empty()) { |
169 allocator_.Reset( | 172 allocator_.Reset( |
170 new RegisterAllocator(config(), zone(), frame(), sequence())); | 173 new RegisterAllocator(config(), zone(), frame(), sequence())); |
171 } | 174 } |
172 return allocator_.get(); | 175 return allocator_.get(); |
173 } | 176 } |
174 | 177 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 struct LoopData { | 512 struct LoopData { |
510 Rpo loop_header_; | 513 Rpo loop_header_; |
511 int expected_blocks_; | 514 int expected_blocks_; |
512 }; | 515 }; |
513 | 516 |
514 typedef std::vector<LoopData> LoopBlocks; | 517 typedef std::vector<LoopData> LoopBlocks; |
515 typedef std::map<int, const Instruction*> Instructions; | 518 typedef std::map<int, const Instruction*> Instructions; |
516 typedef std::vector<BlockCompletion> Completions; | 519 typedef std::vector<BlockCompletion> Completions; |
517 | 520 |
518 SmartPointer<RegisterConfiguration> config_; | 521 SmartPointer<RegisterConfiguration> config_; |
519 SmartPointer<Frame> frame_; | 522 Frame* frame_; |
520 SmartPointer<RegisterAllocator> allocator_; | 523 SmartPointer<RegisterAllocator> allocator_; |
521 SmartPointer<InstructionSequence> sequence_; | 524 InstructionSequence* sequence_; |
522 int num_general_registers_; | 525 int num_general_registers_; |
523 int num_double_registers_; | 526 int num_double_registers_; |
524 | 527 |
525 // Block building state. | 528 // Block building state. |
526 InstructionBlocks instruction_blocks_; | 529 InstructionBlocks instruction_blocks_; |
527 Instructions instructions_; | 530 Instructions instructions_; |
528 int current_instruction_index_; | 531 int current_instruction_index_; |
529 Completions completions_; | 532 Completions completions_; |
530 LoopBlocks loop_blocks_; | 533 LoopBlocks loop_blocks_; |
531 InstructionBlock* current_block_; | 534 InstructionBlock* current_block_; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 StartBlock(); | 746 StartBlock(); |
744 Return(DefineConstant()); | 747 Return(DefineConstant()); |
745 EndBlock(); | 748 EndBlock(); |
746 | 749 |
747 Allocate(); | 750 Allocate(); |
748 } | 751 } |
749 | 752 |
750 } // namespace compiler | 753 } // namespace compiler |
751 } // namespace internal | 754 } // namespace internal |
752 } // namespace v8 | 755 } // namespace v8 |
OLD | NEW |