| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 schedule.AddNode(schedule.start(), node); | 74 schedule.AddNode(schedule.start(), node); |
| 75 return node; | 75 return node; |
| 76 } | 76 } |
| 77 | 77 |
| 78 Node* NewNode(BasicBlock* block) { | 78 Node* NewNode(BasicBlock* block) { |
| 79 Node* node = graph.NewNode(common.Int32Constant(111)); | 79 Node* node = graph.NewNode(common.Int32Constant(111)); |
| 80 schedule.AddNode(block, node); | 80 schedule.AddNode(block, node); |
| 81 return node; | 81 return node; |
| 82 } | 82 } |
| 83 | 83 |
| 84 int NewInstr(BasicBlock* block) { | 84 int NewInstr() { |
| 85 InstructionCode opcode = static_cast<InstructionCode>(110); | 85 InstructionCode opcode = static_cast<InstructionCode>(110); |
| 86 TestInstr* instr = TestInstr::New(zone(), opcode); | 86 TestInstr* instr = TestInstr::New(zone(), opcode); |
| 87 return code->AddInstruction(instr, block); | 87 return code->AddInstruction(instr); |
| 88 } | 88 } |
| 89 | 89 |
| 90 UnallocatedOperand* NewUnallocated(int vreg) { | 90 UnallocatedOperand* NewUnallocated(int vreg) { |
| 91 UnallocatedOperand* unallocated = | 91 UnallocatedOperand* unallocated = |
| 92 new (zone()) UnallocatedOperand(UnallocatedOperand::ANY); | 92 new (zone()) UnallocatedOperand(UnallocatedOperand::ANY); |
| 93 unallocated->set_virtual_register(vreg); | 93 unallocated->set_virtual_register(vreg); |
| 94 return unallocated; | 94 return unallocated; |
| 95 } | 95 } |
| 96 }; | 96 }; |
| 97 | 97 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 115 CHECK_EQ(R.graph.NodeCount(), R.code->node_count()); | 115 CHECK_EQ(R.graph.NodeCount(), R.code->node_count()); |
| 116 | 116 |
| 117 BasicBlockVector* blocks = R.schedule.rpo_order(); | 117 BasicBlockVector* blocks = R.schedule.rpo_order(); |
| 118 CHECK_EQ(static_cast<int>(blocks->size()), R.code->BasicBlockCount()); | 118 CHECK_EQ(static_cast<int>(blocks->size()), R.code->BasicBlockCount()); |
| 119 | 119 |
| 120 int index = 0; | 120 int index = 0; |
| 121 for (BasicBlockVectorIter i = blocks->begin(); i != blocks->end(); | 121 for (BasicBlockVectorIter i = blocks->begin(); i != blocks->end(); |
| 122 i++, index++) { | 122 i++, index++) { |
| 123 BasicBlock* block = *i; | 123 BasicBlock* block = *i; |
| 124 CHECK_EQ(block, R.code->BlockAt(index)); | 124 CHECK_EQ(block, R.code->BlockAt(index)); |
| 125 CHECK_EQ(-1, R.code->GetLoopEnd(block)); | 125 CHECK_EQ(-1, block->loop_end()); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 TEST(InstructionGetBasicBlock) { | 130 TEST(InstructionGetBasicBlock) { |
| 131 InstructionTester R; | 131 InstructionTester R; |
| 132 | 132 |
| 133 BasicBlock* b0 = R.schedule.start(); | 133 BasicBlock* b0 = R.schedule.start(); |
| 134 BasicBlock* b1 = R.schedule.NewBasicBlock(); | 134 BasicBlock* b1 = R.schedule.NewBasicBlock(); |
| 135 BasicBlock* b2 = R.schedule.NewBasicBlock(); | 135 BasicBlock* b2 = R.schedule.NewBasicBlock(); |
| 136 BasicBlock* b3 = R.schedule.end(); | 136 BasicBlock* b3 = R.schedule.end(); |
| 137 | 137 |
| 138 R.schedule.AddGoto(b0, b1); | 138 R.schedule.AddGoto(b0, b1); |
| 139 R.schedule.AddGoto(b1, b2); | 139 R.schedule.AddGoto(b1, b2); |
| 140 R.schedule.AddGoto(b2, b3); | 140 R.schedule.AddGoto(b2, b3); |
| 141 | 141 |
| 142 R.allocCode(); | 142 R.allocCode(); |
| 143 | 143 |
| 144 R.code->StartBlock(b0); | 144 R.code->StartBlock(b0); |
| 145 int i0 = R.NewInstr(b0); | 145 int i0 = R.NewInstr(); |
| 146 int i1 = R.NewInstr(b0); | 146 int i1 = R.NewInstr(); |
| 147 R.code->EndBlock(b0); | 147 R.code->EndBlock(b0); |
| 148 R.code->StartBlock(b1); | 148 R.code->StartBlock(b1); |
| 149 int i2 = R.NewInstr(b1); | 149 int i2 = R.NewInstr(); |
| 150 int i3 = R.NewInstr(b1); | 150 int i3 = R.NewInstr(); |
| 151 int i4 = R.NewInstr(b1); | 151 int i4 = R.NewInstr(); |
| 152 int i5 = R.NewInstr(b1); | 152 int i5 = R.NewInstr(); |
| 153 R.code->EndBlock(b1); | 153 R.code->EndBlock(b1); |
| 154 R.code->StartBlock(b2); | 154 R.code->StartBlock(b2); |
| 155 int i6 = R.NewInstr(b2); | 155 int i6 = R.NewInstr(); |
| 156 int i7 = R.NewInstr(b2); | 156 int i7 = R.NewInstr(); |
| 157 int i8 = R.NewInstr(b2); | 157 int i8 = R.NewInstr(); |
| 158 R.code->EndBlock(b2); | 158 R.code->EndBlock(b2); |
| 159 R.code->StartBlock(b3); | 159 R.code->StartBlock(b3); |
| 160 R.code->EndBlock(b3); | 160 R.code->EndBlock(b3); |
| 161 | 161 |
| 162 CHECK_EQ(b0, R.code->GetBasicBlock(i0)); | 162 CHECK_EQ(b0, R.code->GetBasicBlock(i0)); |
| 163 CHECK_EQ(b0, R.code->GetBasicBlock(i1)); | 163 CHECK_EQ(b0, R.code->GetBasicBlock(i1)); |
| 164 | 164 |
| 165 CHECK_EQ(b1, R.code->GetBasicBlock(i2)); | 165 CHECK_EQ(b1, R.code->GetBasicBlock(i2)); |
| 166 CHECK_EQ(b1, R.code->GetBasicBlock(i3)); | 166 CHECK_EQ(b1, R.code->GetBasicBlock(i3)); |
| 167 CHECK_EQ(b1, R.code->GetBasicBlock(i4)); | 167 CHECK_EQ(b1, R.code->GetBasicBlock(i4)); |
| 168 CHECK_EQ(b1, R.code->GetBasicBlock(i5)); | 168 CHECK_EQ(b1, R.code->GetBasicBlock(i5)); |
| 169 | 169 |
| 170 CHECK_EQ(b2, R.code->GetBasicBlock(i6)); | 170 CHECK_EQ(b2, R.code->GetBasicBlock(i6)); |
| 171 CHECK_EQ(b2, R.code->GetBasicBlock(i7)); | 171 CHECK_EQ(b2, R.code->GetBasicBlock(i7)); |
| 172 CHECK_EQ(b2, R.code->GetBasicBlock(i8)); | 172 CHECK_EQ(b2, R.code->GetBasicBlock(i8)); |
| 173 | 173 |
| 174 CHECK_EQ(b0, R.code->GetBasicBlock(b0->first_instruction_index())); | 174 CHECK_EQ(b0, R.code->GetBasicBlock(R.code->first_instruction_index(b0))); |
| 175 CHECK_EQ(b0, R.code->GetBasicBlock(b0->last_instruction_index())); | 175 CHECK_EQ(b0, R.code->GetBasicBlock(R.code->last_instruction_index(b0))); |
| 176 | 176 |
| 177 CHECK_EQ(b1, R.code->GetBasicBlock(b1->first_instruction_index())); | 177 CHECK_EQ(b1, R.code->GetBasicBlock(R.code->first_instruction_index(b1))); |
| 178 CHECK_EQ(b1, R.code->GetBasicBlock(b1->last_instruction_index())); | 178 CHECK_EQ(b1, R.code->GetBasicBlock(R.code->last_instruction_index(b1))); |
| 179 | 179 |
| 180 CHECK_EQ(b2, R.code->GetBasicBlock(b2->first_instruction_index())); | 180 CHECK_EQ(b2, R.code->GetBasicBlock(R.code->first_instruction_index(b2))); |
| 181 CHECK_EQ(b2, R.code->GetBasicBlock(b2->last_instruction_index())); | 181 CHECK_EQ(b2, R.code->GetBasicBlock(R.code->last_instruction_index(b2))); |
| 182 | 182 |
| 183 CHECK_EQ(b3, R.code->GetBasicBlock(b3->first_instruction_index())); | 183 CHECK_EQ(b3, R.code->GetBasicBlock(R.code->first_instruction_index(b3))); |
| 184 CHECK_EQ(b3, R.code->GetBasicBlock(b3->last_instruction_index())); | 184 CHECK_EQ(b3, R.code->GetBasicBlock(R.code->last_instruction_index(b3))); |
| 185 } | 185 } |
| 186 | 186 |
| 187 | 187 |
| 188 TEST(InstructionIsGapAt) { | 188 TEST(InstructionIsGapAt) { |
| 189 InstructionTester R; | 189 InstructionTester R; |
| 190 | 190 |
| 191 BasicBlock* b0 = R.schedule.start(); | 191 BasicBlock* b0 = R.schedule.start(); |
| 192 R.schedule.AddReturn(b0, R.Int32Constant(1)); | 192 R.schedule.AddReturn(b0, R.Int32Constant(1)); |
| 193 | 193 |
| 194 R.allocCode(); | 194 R.allocCode(); |
| 195 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 195 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
| 196 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 196 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
| 197 R.code->StartBlock(b0); | 197 R.code->StartBlock(b0); |
| 198 R.code->AddInstruction(i0, b0); | 198 R.code->AddInstruction(i0); |
| 199 R.code->AddInstruction(g, b0); | 199 R.code->AddInstruction(g); |
| 200 R.code->EndBlock(b0); | 200 R.code->EndBlock(b0); |
| 201 | 201 |
| 202 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); | 202 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); |
| 203 | 203 |
| 204 CHECK_EQ(true, R.code->IsGapAt(0)); // Label | 204 CHECK_EQ(true, R.code->IsGapAt(0)); // Label |
| 205 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap | 205 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap |
| 206 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 | 206 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 |
| 207 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap | 207 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap |
| 208 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap | 208 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap |
| 209 CHECK_EQ(false, R.code->IsGapAt(5)); // g | 209 CHECK_EQ(false, R.code->IsGapAt(5)); // g |
| 210 } | 210 } |
| 211 | 211 |
| 212 | 212 |
| 213 TEST(InstructionIsGapAt2) { | 213 TEST(InstructionIsGapAt2) { |
| 214 InstructionTester R; | 214 InstructionTester R; |
| 215 | 215 |
| 216 BasicBlock* b0 = R.schedule.start(); | 216 BasicBlock* b0 = R.schedule.start(); |
| 217 BasicBlock* b1 = R.schedule.end(); | 217 BasicBlock* b1 = R.schedule.end(); |
| 218 R.schedule.AddGoto(b0, b1); | 218 R.schedule.AddGoto(b0, b1); |
| 219 R.schedule.AddReturn(b1, R.Int32Constant(1)); | 219 R.schedule.AddReturn(b1, R.Int32Constant(1)); |
| 220 | 220 |
| 221 R.allocCode(); | 221 R.allocCode(); |
| 222 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 222 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
| 223 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 223 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
| 224 R.code->StartBlock(b0); | 224 R.code->StartBlock(b0); |
| 225 R.code->AddInstruction(i0, b0); | 225 R.code->AddInstruction(i0); |
| 226 R.code->AddInstruction(g, b0); | 226 R.code->AddInstruction(g); |
| 227 R.code->EndBlock(b0); | 227 R.code->EndBlock(b0); |
| 228 | 228 |
| 229 TestInstr* i1 = TestInstr::New(R.zone(), 102); | 229 TestInstr* i1 = TestInstr::New(R.zone(), 102); |
| 230 TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); | 230 TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); |
| 231 R.code->StartBlock(b1); | 231 R.code->StartBlock(b1); |
| 232 R.code->AddInstruction(i1, b1); | 232 R.code->AddInstruction(i1); |
| 233 R.code->AddInstruction(g1, b1); | 233 R.code->AddInstruction(g1); |
| 234 R.code->EndBlock(b1); | 234 R.code->EndBlock(b1); |
| 235 | 235 |
| 236 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); | 236 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); |
| 237 | 237 |
| 238 CHECK_EQ(true, R.code->IsGapAt(0)); // Label | 238 CHECK_EQ(true, R.code->IsGapAt(0)); // Label |
| 239 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap | 239 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap |
| 240 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 | 240 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 |
| 241 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap | 241 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap |
| 242 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap | 242 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap |
| 243 CHECK_EQ(false, R.code->IsGapAt(5)); // g | 243 CHECK_EQ(false, R.code->IsGapAt(5)); // g |
| (...skipping 12 matching lines...) Expand all Loading... |
| 256 TEST(InstructionAddGapMove) { | 256 TEST(InstructionAddGapMove) { |
| 257 InstructionTester R; | 257 InstructionTester R; |
| 258 | 258 |
| 259 BasicBlock* b0 = R.schedule.start(); | 259 BasicBlock* b0 = R.schedule.start(); |
| 260 R.schedule.AddReturn(b0, R.Int32Constant(1)); | 260 R.schedule.AddReturn(b0, R.Int32Constant(1)); |
| 261 | 261 |
| 262 R.allocCode(); | 262 R.allocCode(); |
| 263 TestInstr* i0 = TestInstr::New(R.zone(), 100); | 263 TestInstr* i0 = TestInstr::New(R.zone(), 100); |
| 264 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); | 264 TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); |
| 265 R.code->StartBlock(b0); | 265 R.code->StartBlock(b0); |
| 266 R.code->AddInstruction(i0, b0); | 266 R.code->AddInstruction(i0); |
| 267 R.code->AddInstruction(g, b0); | 267 R.code->AddInstruction(g); |
| 268 R.code->EndBlock(b0); | 268 R.code->EndBlock(b0); |
| 269 | 269 |
| 270 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); | 270 CHECK_EQ(true, R.code->InstructionAt(0)->IsBlockStart()); |
| 271 | 271 |
| 272 CHECK_EQ(true, R.code->IsGapAt(0)); // Label | 272 CHECK_EQ(true, R.code->IsGapAt(0)); // Label |
| 273 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap | 273 CHECK_EQ(true, R.code->IsGapAt(1)); // Gap |
| 274 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 | 274 CHECK_EQ(false, R.code->IsGapAt(2)); // i0 |
| 275 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap | 275 CHECK_EQ(true, R.code->IsGapAt(3)); // Gap |
| 276 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap | 276 CHECK_EQ(true, R.code->IsGapAt(4)); // Gap |
| 277 CHECK_EQ(false, R.code->IsGapAt(5)); // g | 277 CHECK_EQ(false, R.code->IsGapAt(5)); // g |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 CHECK_EQ(inputs[z], m->InputAt(z)); | 341 CHECK_EQ(inputs[z], m->InputAt(z)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 for (size_t z = 0; z < k; z++) { | 344 for (size_t z = 0; z < k; z++) { |
| 345 CHECK_EQ(temps[z], m->TempAt(z)); | 345 CHECK_EQ(temps[z], m->TempAt(z)); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 } | 350 } |
| OLD | NEW |