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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 if (schedule.rpo_order()->size() == 0) { | 52 if (schedule.rpo_order()->size() == 0) { |
53 // Compute the RPO order. | 53 // Compute the RPO order. |
54 Scheduler::ComputeSpecialRPO(&schedule); | 54 Scheduler::ComputeSpecialRPO(&schedule); |
55 DCHECK(schedule.rpo_order()->size() > 0); | 55 DCHECK(schedule.rpo_order()->size() > 0); |
56 } | 56 } |
57 code = new TestInstrSeq(&linkage, &graph, &schedule); | 57 code = new TestInstrSeq(&linkage, &graph, &schedule); |
58 } | 58 } |
59 | 59 |
60 Node* Int32Constant(int32_t val) { | 60 Node* Int32Constant(int32_t val) { |
61 Node* node = graph.NewNode(common.Int32Constant(val)); | 61 Node* node = graph.NewNode(common.Int32Constant(val)); |
62 schedule.AddNode(schedule.entry(), node); | 62 schedule.AddNode(schedule.start(), node); |
63 return node; | 63 return node; |
64 } | 64 } |
65 | 65 |
66 Node* Float64Constant(double val) { | 66 Node* Float64Constant(double val) { |
67 Node* node = graph.NewNode(common.Float64Constant(val)); | 67 Node* node = graph.NewNode(common.Float64Constant(val)); |
68 schedule.AddNode(schedule.entry(), node); | 68 schedule.AddNode(schedule.start(), node); |
69 return node; | 69 return node; |
70 } | 70 } |
71 | 71 |
72 Node* Parameter(int32_t which) { | 72 Node* Parameter(int32_t which) { |
73 Node* node = graph.NewNode(common.Parameter(which)); | 73 Node* node = graph.NewNode(common.Parameter(which)); |
74 schedule.AddNode(schedule.entry(), 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(BasicBlock* block) { |
(...skipping 11 matching lines...) Expand all Loading... |
96 }; | 96 }; |
97 | 97 |
98 | 98 |
99 TEST(InstructionBasic) { | 99 TEST(InstructionBasic) { |
100 InstructionTester R; | 100 InstructionTester R; |
101 | 101 |
102 for (int i = 0; i < 10; i++) { | 102 for (int i = 0; i < 10; i++) { |
103 R.Int32Constant(i); // Add some nodes to the graph. | 103 R.Int32Constant(i); // Add some nodes to the graph. |
104 } | 104 } |
105 | 105 |
106 BasicBlock* last = R.schedule.entry(); | 106 BasicBlock* last = R.schedule.start(); |
107 for (int i = 0; i < 5; i++) { | 107 for (int i = 0; i < 5; i++) { |
108 BasicBlock* block = R.schedule.NewBasicBlock(); | 108 BasicBlock* block = R.schedule.NewBasicBlock(); |
109 R.schedule.AddGoto(last, block); | 109 R.schedule.AddGoto(last, block); |
110 last = block; | 110 last = block; |
111 } | 111 } |
112 | 112 |
113 R.allocCode(); | 113 R.allocCode(); |
114 | 114 |
115 CHECK_EQ(R.graph.NodeCount(), R.code->ValueCount()); | 115 CHECK_EQ(R.graph.NodeCount(), R.code->ValueCount()); |
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, R.code->GetLoopEnd(block)); |
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.entry(); | 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.exit(); | 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(b0); |
146 int i1 = R.NewInstr(b0); | 146 int i1 = R.NewInstr(b0); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 CHECK_EQ(b2, R.code->GetBasicBlock(b2->last_instruction_index())); | 181 CHECK_EQ(b2, R.code->GetBasicBlock(b2->last_instruction_index())); |
182 | 182 |
183 CHECK_EQ(b3, R.code->GetBasicBlock(b3->first_instruction_index())); | 183 CHECK_EQ(b3, R.code->GetBasicBlock(b3->first_instruction_index())); |
184 CHECK_EQ(b3, R.code->GetBasicBlock(b3->last_instruction_index())); | 184 CHECK_EQ(b3, R.code->GetBasicBlock(b3->last_instruction_index())); |
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.entry(); | 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, b0); |
199 R.code->AddInstruction(g, b0); | 199 R.code->AddInstruction(g, b0); |
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.entry(); | 216 BasicBlock* b0 = R.schedule.start(); |
217 BasicBlock* b1 = R.schedule.exit(); | 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, b0); |
226 R.code->AddInstruction(g, b0); | 226 R.code->AddInstruction(g, b0); |
227 R.code->EndBlock(b0); | 227 R.code->EndBlock(b0); |
(...skipping 21 matching lines...) Expand all Loading... |
249 CHECK_EQ(false, R.code->IsGapAt(8)); // i1 | 249 CHECK_EQ(false, R.code->IsGapAt(8)); // i1 |
250 CHECK_EQ(true, R.code->IsGapAt(9)); // Gap | 250 CHECK_EQ(true, R.code->IsGapAt(9)); // Gap |
251 CHECK_EQ(true, R.code->IsGapAt(10)); // Gap | 251 CHECK_EQ(true, R.code->IsGapAt(10)); // Gap |
252 CHECK_EQ(false, R.code->IsGapAt(11)); // g1 | 252 CHECK_EQ(false, R.code->IsGapAt(11)); // g1 |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 TEST(InstructionAddGapMove) { | 256 TEST(InstructionAddGapMove) { |
257 InstructionTester R; | 257 InstructionTester R; |
258 | 258 |
259 BasicBlock* b0 = R.schedule.entry(); | 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, b0); |
267 R.code->AddInstruction(g, b0); | 267 R.code->AddInstruction(g, b0); |
268 R.code->EndBlock(b0); | 268 R.code->EndBlock(b0); |
269 | 269 |
(...skipping 71 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 |