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/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/compiler/code-generator.h" | 8 #include "src/compiler/code-generator.h" |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 int NewInstr() { | 86 int NewInstr() { |
87 InstructionCode opcode = static_cast<InstructionCode>(110); | 87 InstructionCode opcode = static_cast<InstructionCode>(110); |
88 TestInstr* instr = TestInstr::New(zone(), opcode); | 88 TestInstr* instr = TestInstr::New(zone(), opcode); |
89 return code->AddInstruction(instr); | 89 return code->AddInstruction(instr); |
90 } | 90 } |
91 | 91 |
92 UnallocatedOperand* NewUnallocated(int vreg) { | 92 UnallocatedOperand* NewUnallocated(int vreg) { |
93 return UnallocatedOperand(UnallocatedOperand::ANY, vreg).Copy(zone()); | 93 return UnallocatedOperand(UnallocatedOperand::ANY, vreg).Copy(zone()); |
94 } | 94 } |
95 | 95 |
| 96 RpoNumber RpoFor(BasicBlock* block) { |
| 97 return RpoNumber::FromInt(block->rpo_number()); |
| 98 } |
| 99 |
96 InstructionBlock* BlockAt(BasicBlock* block) { | 100 InstructionBlock* BlockAt(BasicBlock* block) { |
97 return code->InstructionBlockAt(block->GetRpoNumber()); | 101 return code->InstructionBlockAt(RpoFor(block)); |
98 } | 102 } |
99 BasicBlock* GetBasicBlock(int instruction_index) { | 103 BasicBlock* GetBasicBlock(int instruction_index) { |
100 const InstructionBlock* block = | 104 const InstructionBlock* block = |
101 code->GetInstructionBlock(instruction_index); | 105 code->GetInstructionBlock(instruction_index); |
102 return schedule.rpo_order()->at(block->rpo_number().ToSize()); | 106 return schedule.rpo_order()->at(block->rpo_number().ToSize()); |
103 } | 107 } |
104 int first_instruction_index(BasicBlock* block) { | 108 int first_instruction_index(BasicBlock* block) { |
105 return BlockAt(block)->first_instruction_index(); | 109 return BlockAt(block)->first_instruction_index(); |
106 } | 110 } |
107 int last_instruction_index(BasicBlock* block) { | 111 int last_instruction_index(BasicBlock* block) { |
(...skipping 16 matching lines...) Expand all Loading... |
124 last = block; | 128 last = block; |
125 } | 129 } |
126 | 130 |
127 R.allocCode(); | 131 R.allocCode(); |
128 | 132 |
129 BasicBlockVector* blocks = R.schedule.rpo_order(); | 133 BasicBlockVector* blocks = R.schedule.rpo_order(); |
130 CHECK_EQ(static_cast<int>(blocks->size()), R.code->InstructionBlockCount()); | 134 CHECK_EQ(static_cast<int>(blocks->size()), R.code->InstructionBlockCount()); |
131 | 135 |
132 for (auto block : *blocks) { | 136 for (auto block : *blocks) { |
133 CHECK_EQ(block->rpo_number(), R.BlockAt(block)->rpo_number().ToInt()); | 137 CHECK_EQ(block->rpo_number(), R.BlockAt(block)->rpo_number().ToInt()); |
134 CHECK_EQ(block->id().ToInt(), R.BlockAt(block)->id().ToInt()); | |
135 CHECK(!block->loop_end()); | 138 CHECK(!block->loop_end()); |
136 } | 139 } |
137 } | 140 } |
138 | 141 |
139 | 142 |
140 TEST(InstructionGetBasicBlock) { | 143 TEST(InstructionGetBasicBlock) { |
141 InstructionTester R; | 144 InstructionTester R; |
142 | 145 |
143 BasicBlock* b0 = R.schedule.start(); | 146 BasicBlock* b0 = R.schedule.start(); |
144 BasicBlock* b1 = R.schedule.NewBasicBlock(); | 147 BasicBlock* b1 = R.schedule.NewBasicBlock(); |
145 BasicBlock* b2 = R.schedule.NewBasicBlock(); | 148 BasicBlock* b2 = R.schedule.NewBasicBlock(); |
146 BasicBlock* b3 = R.schedule.end(); | 149 BasicBlock* b3 = R.schedule.end(); |
147 | 150 |
148 R.schedule.AddGoto(b0, b1); | 151 R.schedule.AddGoto(b0, b1); |
149 R.schedule.AddGoto(b1, b2); | 152 R.schedule.AddGoto(b1, b2); |
150 R.schedule.AddGoto(b2, b3); | 153 R.schedule.AddGoto(b2, b3); |
151 | 154 |
152 R.allocCode(); | 155 R.allocCode(); |
153 | 156 |
154 R.code->StartBlock(b0->GetRpoNumber()); | 157 R.code->StartBlock(R.RpoFor(b0)); |
155 int i0 = R.NewInstr(); | 158 int i0 = R.NewInstr(); |
156 int i1 = R.NewInstr(); | 159 int i1 = R.NewInstr(); |
157 R.code->EndBlock(b0->GetRpoNumber()); | 160 R.code->EndBlock(R.RpoFor(b0)); |
158 R.code->StartBlock(b1->GetRpoNumber()); | 161 R.code->StartBlock(R.RpoFor(b1)); |
159 int i2 = R.NewInstr(); | 162 int i2 = R.NewInstr(); |
160 int i3 = R.NewInstr(); | 163 int i3 = R.NewInstr(); |
161 int i4 = R.NewInstr(); | 164 int i4 = R.NewInstr(); |
162 int i5 = R.NewInstr(); | 165 int i5 = R.NewInstr(); |
163 R.code->EndBlock(b1->GetRpoNumber()); | 166 R.code->EndBlock(R.RpoFor(b1)); |
164 R.code->StartBlock(b2->GetRpoNumber()); | 167 R.code->StartBlock(R.RpoFor(b2)); |
165 int i6 = R.NewInstr(); | 168 int i6 = R.NewInstr(); |
166 int i7 = R.NewInstr(); | 169 int i7 = R.NewInstr(); |
167 int i8 = R.NewInstr(); | 170 int i8 = R.NewInstr(); |
168 R.code->EndBlock(b2->GetRpoNumber()); | 171 R.code->EndBlock(R.RpoFor(b2)); |
169 R.code->StartBlock(b3->GetRpoNumber()); | 172 R.code->StartBlock(R.RpoFor(b3)); |
170 R.code->EndBlock(b3->GetRpoNumber()); | 173 R.code->EndBlock(R.RpoFor(b3)); |
171 | 174 |
172 CHECK_EQ(b0, R.GetBasicBlock(i0)); | 175 CHECK_EQ(b0, R.GetBasicBlock(i0)); |
173 CHECK_EQ(b0, R.GetBasicBlock(i1)); | 176 CHECK_EQ(b0, R.GetBasicBlock(i1)); |
174 | 177 |
175 CHECK_EQ(b1, R.GetBasicBlock(i2)); | 178 CHECK_EQ(b1, R.GetBasicBlock(i2)); |
176 CHECK_EQ(b1, R.GetBasicBlock(i3)); | 179 CHECK_EQ(b1, R.GetBasicBlock(i3)); |
177 CHECK_EQ(b1, R.GetBasicBlock(i4)); | 180 CHECK_EQ(b1, R.GetBasicBlock(i4)); |
178 CHECK_EQ(b1, R.GetBasicBlock(i5)); | 181 CHECK_EQ(b1, R.GetBasicBlock(i5)); |
179 | 182 |
180 CHECK_EQ(b2, R.GetBasicBlock(i6)); | 183 CHECK_EQ(b2, R.GetBasicBlock(i6)); |
(...skipping 16 matching lines...) Expand all Loading... |
197 | 200 |
198 TEST(InstructionIsGapAt) { | 201 TEST(InstructionIsGapAt) { |
199 InstructionTester R; | 202 InstructionTester R; |
200 | 203 |
201 BasicBlock* b0 = R.schedule.start(); | 204 BasicBlock* b0 = R.schedule.start(); |
202 R.schedule.AddReturn(b0, R.Int32Constant(1)); | 205 R.schedule.AddReturn(b0, R.Int32Constant(1)); |
203 | 206 |
204 R.allocCode(); | 207 R.allocCode(); |
205 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 208 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
206 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 209 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
207 R.code->StartBlock(b0->GetRpoNumber()); | 210 R.code->StartBlock(R.RpoFor(b0)); |
208 R.code->AddInstruction(i0); | 211 R.code->AddInstruction(i0); |
209 R.code->AddInstruction(g); | 212 R.code->AddInstruction(g); |
210 R.code->EndBlock(b0->GetRpoNumber()); | 213 R.code->EndBlock(R.RpoFor(b0)); |
211 | 214 |
212 CHECK(R.code->instructions().size() == 4); | 215 CHECK(R.code->instructions().size() == 4); |
213 for (size_t i = 0; i < R.code->instructions().size(); ++i) { | 216 for (size_t i = 0; i < R.code->instructions().size(); ++i) { |
214 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); | 217 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); |
215 } | 218 } |
216 } | 219 } |
217 | 220 |
218 | 221 |
219 TEST(InstructionIsGapAt2) { | 222 TEST(InstructionIsGapAt2) { |
220 InstructionTester R; | 223 InstructionTester R; |
221 | 224 |
222 BasicBlock* b0 = R.schedule.start(); | 225 BasicBlock* b0 = R.schedule.start(); |
223 BasicBlock* b1 = R.schedule.end(); | 226 BasicBlock* b1 = R.schedule.end(); |
224 R.schedule.AddGoto(b0, b1); | 227 R.schedule.AddGoto(b0, b1); |
225 R.schedule.AddReturn(b1, R.Int32Constant(1)); | 228 R.schedule.AddReturn(b1, R.Int32Constant(1)); |
226 | 229 |
227 R.allocCode(); | 230 R.allocCode(); |
228 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 231 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
229 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 232 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
230 R.code->StartBlock(b0->GetRpoNumber()); | 233 R.code->StartBlock(R.RpoFor(b0)); |
231 R.code->AddInstruction(i0); | 234 R.code->AddInstruction(i0); |
232 R.code->AddInstruction(g); | 235 R.code->AddInstruction(g); |
233 R.code->EndBlock(b0->GetRpoNumber()); | 236 R.code->EndBlock(R.RpoFor(b0)); |
234 | 237 |
235 TestInstr* i1 = TestInstr::New(R.zone(), 102); | 238 TestInstr* i1 = TestInstr::New(R.zone(), 102); |
236 TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); | 239 TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); |
237 R.code->StartBlock(b1->GetRpoNumber()); | 240 R.code->StartBlock(R.RpoFor(b1)); |
238 R.code->AddInstruction(i1); | 241 R.code->AddInstruction(i1); |
239 R.code->AddInstruction(g1); | 242 R.code->AddInstruction(g1); |
240 R.code->EndBlock(b1->GetRpoNumber()); | 243 R.code->EndBlock(R.RpoFor(b1)); |
241 | 244 |
242 CHECK(R.code->instructions().size() == 8); | 245 CHECK(R.code->instructions().size() == 8); |
243 for (size_t i = 0; i < R.code->instructions().size(); ++i) { | 246 for (size_t i = 0; i < R.code->instructions().size(); ++i) { |
244 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); | 247 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); |
245 } | 248 } |
246 } | 249 } |
247 | 250 |
248 | 251 |
249 TEST(InstructionAddGapMove) { | 252 TEST(InstructionAddGapMove) { |
250 InstructionTester R; | 253 InstructionTester R; |
251 | 254 |
252 BasicBlock* b0 = R.schedule.start(); | 255 BasicBlock* b0 = R.schedule.start(); |
253 R.schedule.AddReturn(b0, R.Int32Constant(1)); | 256 R.schedule.AddReturn(b0, R.Int32Constant(1)); |
254 | 257 |
255 R.allocCode(); | 258 R.allocCode(); |
256 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 259 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
257 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 260 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
258 R.code->StartBlock(b0->GetRpoNumber()); | 261 R.code->StartBlock(R.RpoFor(b0)); |
259 R.code->AddInstruction(i0); | 262 R.code->AddInstruction(i0); |
260 R.code->AddInstruction(g); | 263 R.code->AddInstruction(g); |
261 R.code->EndBlock(b0->GetRpoNumber()); | 264 R.code->EndBlock(R.RpoFor(b0)); |
262 | 265 |
263 CHECK(R.code->instructions().size() == 4); | 266 CHECK(R.code->instructions().size() == 4); |
264 for (size_t i = 0; i < R.code->instructions().size(); ++i) { | 267 for (size_t i = 0; i < R.code->instructions().size(); ++i) { |
265 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); | 268 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); |
266 } | 269 } |
267 | 270 |
268 int indexes[] = {0, 2, -1}; | 271 int indexes[] = {0, 2, -1}; |
269 for (int i = 0; indexes[i] >= 0; i++) { | 272 for (int i = 0; indexes[i] >= 0; i++) { |
270 int index = indexes[i]; | 273 int index = indexes[i]; |
271 | 274 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 CHECK(inputs[z].Equals(m->InputAt(z))); | 334 CHECK(inputs[z].Equals(m->InputAt(z))); |
332 } | 335 } |
333 | 336 |
334 for (size_t z = 0; z < k; z++) { | 337 for (size_t z = 0; z < k; z++) { |
335 CHECK(temps[z].Equals(m->TempAt(z))); | 338 CHECK(temps[z].Equals(m->TempAt(z))); |
336 } | 339 } |
337 } | 340 } |
338 } | 341 } |
339 } | 342 } |
340 } | 343 } |
OLD | NEW |