| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 R.schedule.AddReturn(b0, R.Int32Constant(1)); | 207 R.schedule.AddReturn(b0, R.Int32Constant(1)); |
| 208 | 208 |
| 209 R.allocCode(); | 209 R.allocCode(); |
| 210 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 210 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
| 211 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 211 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
| 212 R.code->StartBlock(b0->GetRpoNumber()); | 212 R.code->StartBlock(b0->GetRpoNumber()); |
| 213 R.code->AddInstruction(i0); | 213 R.code->AddInstruction(i0); |
| 214 R.code->AddInstruction(g); | 214 R.code->AddInstruction(g); |
| 215 R.code->EndBlock(b0->GetRpoNumber()); | 215 R.code->EndBlock(b0->GetRpoNumber()); |
| 216 | 216 |
| 217 CHECK(R.code->instructions().size() == 4); | 217 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); |
| 218 for (size_t i = 0; i < R.code->instructions().size(); ++i) { | 218 |
| 219 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); | 219 CHECK_EQ(true, R.code->IsGapAt(0)); // Label |
| 220 } | 220 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap |
| 221 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 |
| 222 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap |
| 223 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap |
| 224 CHECK_EQ(false, R.code->IsGapAt(5)); // g |
| 221 } | 225 } |
| 222 | 226 |
| 223 | 227 |
| 224 TEST(InstructionIsGapAt2) { | 228 TEST(InstructionIsGapAt2) { |
| 225 InstructionTester R; | 229 InstructionTester R; |
| 226 | 230 |
| 227 BasicBlock* b0 = R.schedule.start(); | 231 BasicBlock* b0 = R.schedule.start(); |
| 228 BasicBlock* b1 = R.schedule.end(); | 232 BasicBlock* b1 = R.schedule.end(); |
| 229 R.schedule.AddGoto(b0, b1); | 233 R.schedule.AddGoto(b0, b1); |
| 230 R.schedule.AddReturn(b1, R.Int32Constant(1)); | 234 R.schedule.AddReturn(b1, R.Int32Constant(1)); |
| 231 | 235 |
| 232 R.allocCode(); | 236 R.allocCode(); |
| 233 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 237 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
| 234 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 238 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
| 235 R.code->StartBlock(b0->GetRpoNumber()); | 239 R.code->StartBlock(b0->GetRpoNumber()); |
| 236 R.code->AddInstruction(i0); | 240 R.code->AddInstruction(i0); |
| 237 R.code->AddInstruction(g); | 241 R.code->AddInstruction(g); |
| 238 R.code->EndBlock(b0->GetRpoNumber()); | 242 R.code->EndBlock(b0->GetRpoNumber()); |
| 239 | 243 |
| 240 TestInstr* i1 = TestInstr::New(R.zone(), 102); | 244 TestInstr* i1 = TestInstr::New(R.zone(), 102); |
| 241 TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); | 245 TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); |
| 242 R.code->StartBlock(b1->GetRpoNumber()); | 246 R.code->StartBlock(b1->GetRpoNumber()); |
| 243 R.code->AddInstruction(i1); | 247 R.code->AddInstruction(i1); |
| 244 R.code->AddInstruction(g1); | 248 R.code->AddInstruction(g1); |
| 245 R.code->EndBlock(b1->GetRpoNumber()); | 249 R.code->EndBlock(b1->GetRpoNumber()); |
| 246 | 250 |
| 247 CHECK(R.code->instructions().size() == 8); | 251 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); |
| 248 for (size_t i = 0; i < R.code->instructions().size(); ++i) { | 252 |
| 249 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); | 253 CHECK_EQ(true, R.code->IsGapAt(0)); // Label |
| 250 } | 254 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap |
| 255 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 |
| 256 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap |
| 257 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap |
| 258 CHECK_EQ(false, R.code->IsGapAt(5)); // g |
| 259 |
| 260 CHECK_EQ(true, R.code->InstructionAt(6)->IsBlockStart()); |
| 261 |
| 262 CHECK_EQ(true, R.code->IsGapAt(6)); // Label |
| 263 CHECK_EQ(true, R.code->IsGapAt(7)); // Gap |
| 264 CHECK_EQ(false, R.code->IsGapAt(8)); // i1 |
| 265 CHECK_EQ(true, R.code->IsGapAt(9)); // Gap |
| 266 CHECK_EQ(true, R.code->IsGapAt(10)); // Gap |
| 267 CHECK_EQ(false, R.code->IsGapAt(11)); // g1 |
| 251 } | 268 } |
| 252 | 269 |
| 253 | 270 |
| 254 TEST(InstructionAddGapMove) { | 271 TEST(InstructionAddGapMove) { |
| 255 InstructionTester R; | 272 InstructionTester R; |
| 256 | 273 |
| 257 BasicBlock* b0 = R.schedule.start(); | 274 BasicBlock* b0 = R.schedule.start(); |
| 258 R.schedule.AddReturn(b0, R.Int32Constant(1)); | 275 R.schedule.AddReturn(b0, R.Int32Constant(1)); |
| 259 | 276 |
| 260 R.allocCode(); | 277 R.allocCode(); |
| 261 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 278 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
| 262 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 279 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
| 263 R.code->StartBlock(b0->GetRpoNumber()); | 280 R.code->StartBlock(b0->GetRpoNumber()); |
| 264 R.code->AddInstruction(i0); | 281 R.code->AddInstruction(i0); |
| 265 R.code->AddInstruction(g); | 282 R.code->AddInstruction(g); |
| 266 R.code->EndBlock(b0->GetRpoNumber()); | 283 R.code->EndBlock(b0->GetRpoNumber()); |
| 267 | 284 |
| 268 CHECK(R.code->instructions().size() == 4); | 285 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); |
| 269 for (size_t i = 0; i < R.code->instructions().size(); ++i) { | |
| 270 CHECK_EQ(i % 2 == 0, R.code->instructions()[i]->IsGapMoves()); | |
| 271 } | |
| 272 | 286 |
| 273 int indexes[] = {0, 2, -1}; | 287 CHECK_EQ(true, R.code->IsGapAt(0)); // Label |
| 288 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap |
| 289 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 |
| 290 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap |
| 291 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap |
| 292 CHECK_EQ(false, R.code->IsGapAt(5)); // g |
| 293 |
| 294 int indexes[] = {0, 1, 3, 4, -1}; |
| 274 for (int i = 0; indexes[i] >= 0; i++) { | 295 for (int i = 0; indexes[i] >= 0; i++) { |
| 275 int index = indexes[i]; | 296 int index = indexes[i]; |
| 276 | 297 |
| 277 UnallocatedOperand* op1 = R.NewUnallocated(index + 6); | 298 UnallocatedOperand* op1 = R.NewUnallocated(index + 6); |
| 278 UnallocatedOperand* op2 = R.NewUnallocated(index + 12); | 299 UnallocatedOperand* op2 = R.NewUnallocated(index + 12); |
| 279 | 300 |
| 280 R.code->AddGapMove(index, op1, op2); | 301 R.code->AddGapMove(index, op1, op2); |
| 281 GapInstruction* gap = R.code->GapAt(index); | 302 GapInstruction* gap = R.code->GapAt(index); |
| 282 ParallelMove* move = gap->GetParallelMove(GapInstruction::START); | 303 ParallelMove* move = gap->GetParallelMove(GapInstruction::START); |
| 283 CHECK_NE(NULL, move); | 304 CHECK_NE(NULL, move); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 CHECK_EQ(inputs[z], m->InputAt(z)); | 356 CHECK_EQ(inputs[z], m->InputAt(z)); |
| 336 } | 357 } |
| 337 | 358 |
| 338 for (size_t z = 0; z < k; z++) { | 359 for (size_t z = 0; z < k; z++) { |
| 339 CHECK_EQ(temps[z], m->TempAt(z)); | 360 CHECK_EQ(temps[z], m->TempAt(z)); |
| 340 } | 361 } |
| 341 } | 362 } |
| 342 } | 363 } |
| 343 } | 364 } |
| 344 } | 365 } |
| OLD | NEW |