blob: 981fcc42a7fca86830d69d8154819ccd4e7753ba [file] [log] [blame]
Alexandre Rames22aa54b2016-10-18 09:32:29 +01001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070017#include "scheduler.h"
18
Alexandre Rames22aa54b2016-10-18 09:32:29 +010019#include "base/arena_allocator.h"
20#include "builder.h"
21#include "codegen_test_utils.h"
22#include "common_compiler_test.h"
xueliang.zhong2a3471f2017-05-08 18:36:40 +010023#include "load_store_analysis.h"
Alexandre Rames22aa54b2016-10-18 09:32:29 +010024#include "nodes.h"
25#include "optimizing_unit_test.h"
26#include "pc_relative_fixups_x86.h"
27#include "register_allocator.h"
Alexandre Rames22aa54b2016-10-18 09:32:29 +010028
29#ifdef ART_ENABLE_CODEGEN_arm64
30#include "scheduler_arm64.h"
31#endif
32
xueliang.zhongf7caf682017-03-01 16:07:02 +000033#ifdef ART_ENABLE_CODEGEN_arm
34#include "scheduler_arm.h"
35#endif
36
Alexandre Rames22aa54b2016-10-18 09:32:29 +010037namespace art {
38
39// Return all combinations of ISA and code generator that are executable on
40// hardware, or on simulator, and that we'd like to test.
41static ::std::vector<CodegenTargetConfig> GetTargetConfigs() {
42 ::std::vector<CodegenTargetConfig> v;
43 ::std::vector<CodegenTargetConfig> test_config_candidates = {
44#ifdef ART_ENABLE_CODEGEN_arm
Roland Levillain9983e302017-07-14 14:34:22 +010045 // TODO: Should't this be `kThumb2` instead of `kArm` here?
Vladimir Marko33bff252017-11-01 14:35:42 +000046 CodegenTargetConfig(InstructionSet::kArm, create_codegen_arm_vixl32),
Alexandre Rames22aa54b2016-10-18 09:32:29 +010047#endif
48#ifdef ART_ENABLE_CODEGEN_arm64
Vladimir Marko33bff252017-11-01 14:35:42 +000049 CodegenTargetConfig(InstructionSet::kArm64, create_codegen_arm64),
Alexandre Rames22aa54b2016-10-18 09:32:29 +010050#endif
51#ifdef ART_ENABLE_CODEGEN_x86
Vladimir Marko33bff252017-11-01 14:35:42 +000052 CodegenTargetConfig(InstructionSet::kX86, create_codegen_x86),
Alexandre Rames22aa54b2016-10-18 09:32:29 +010053#endif
54#ifdef ART_ENABLE_CODEGEN_x86_64
Vladimir Marko33bff252017-11-01 14:35:42 +000055 CodegenTargetConfig(InstructionSet::kX86_64, create_codegen_x86_64),
Alexandre Rames22aa54b2016-10-18 09:32:29 +010056#endif
57#ifdef ART_ENABLE_CODEGEN_mips
Vladimir Marko33bff252017-11-01 14:35:42 +000058 CodegenTargetConfig(InstructionSet::kMips, create_codegen_mips),
Alexandre Rames22aa54b2016-10-18 09:32:29 +010059#endif
60#ifdef ART_ENABLE_CODEGEN_mips64
Vladimir Marko33bff252017-11-01 14:35:42 +000061 CodegenTargetConfig(InstructionSet::kMips64, create_codegen_mips64)
Alexandre Rames22aa54b2016-10-18 09:32:29 +010062#endif
63 };
64
Vladimir Marko7d157fc2017-05-10 16:29:23 +010065 for (const CodegenTargetConfig& test_config : test_config_candidates) {
Alexandre Rames22aa54b2016-10-18 09:32:29 +010066 if (CanExecute(test_config.GetInstructionSet())) {
67 v.push_back(test_config);
68 }
69 }
70
71 return v;
72}
73
Vladimir Markoca6fff82017-10-03 14:49:14 +010074class SchedulerTest : public OptimizingUnitTest {
xueliang.zhongf7caf682017-03-01 16:07:02 +000075 public:
Vladimir Markoca6fff82017-10-03 14:49:14 +010076 SchedulerTest() : graph_(CreateGraph()) { }
Alexandre Rames22aa54b2016-10-18 09:32:29 +010077
xueliang.zhongf7caf682017-03-01 16:07:02 +000078 // Build scheduling graph, and run target specific scheduling on it.
79 void TestBuildDependencyGraphAndSchedule(HScheduler* scheduler) {
Vladimir Markoca6fff82017-10-03 14:49:14 +010080 HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph_);
81 HBasicBlock* block1 = new (GetAllocator()) HBasicBlock(graph_);
xueliang.zhongf7caf682017-03-01 16:07:02 +000082 graph_->AddBlock(entry);
83 graph_->AddBlock(block1);
84 graph_->SetEntryBlock(entry);
85
86 // entry:
87 // array ParameterValue
88 // c1 IntConstant
89 // c2 IntConstant
90 // block1:
91 // add1 Add [c1, c2]
92 // add2 Add [add1, c2]
93 // mul Mul [add1, add2]
94 // div_check DivZeroCheck [add2] (env: add2, mul)
95 // div Div [add1, div_check]
96 // array_get1 ArrayGet [array, add1]
97 // array_set1 ArraySet [array, add1, add2]
98 // array_get2 ArrayGet [array, add1]
99 // array_set2 ArraySet [array, add1, add2]
100
Vladimir Markoca6fff82017-10-03 14:49:14 +0100101 HInstruction* array = new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
102 dex::TypeIndex(0),
103 0,
104 DataType::Type::kReference);
xueliang.zhongf7caf682017-03-01 16:07:02 +0000105 HInstruction* c1 = graph_->GetIntConstant(1);
106 HInstruction* c2 = graph_->GetIntConstant(10);
Vladimir Markoca6fff82017-10-03 14:49:14 +0100107 HInstruction* add1 = new (GetAllocator()) HAdd(DataType::Type::kInt32, c1, c2);
108 HInstruction* add2 = new (GetAllocator()) HAdd(DataType::Type::kInt32, add1, c2);
109 HInstruction* mul = new (GetAllocator()) HMul(DataType::Type::kInt32, add1, add2);
110 HInstruction* div_check = new (GetAllocator()) HDivZeroCheck(add2, 0);
111 HInstruction* div = new (GetAllocator()) HDiv(DataType::Type::kInt32, add1, div_check, 0);
112 HInstruction* array_get1 =
113 new (GetAllocator()) HArrayGet(array, add1, DataType::Type::kInt32, 0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100114 HInstruction* array_set1 =
Vladimir Markoca6fff82017-10-03 14:49:14 +0100115 new (GetAllocator()) HArraySet(array, add1, add2, DataType::Type::kInt32, 0);
116 HInstruction* array_get2 =
117 new (GetAllocator()) HArrayGet(array, add1, DataType::Type::kInt32, 0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100118 HInstruction* array_set2 =
Vladimir Markoca6fff82017-10-03 14:49:14 +0100119 new (GetAllocator()) HArraySet(array, add1, add2, DataType::Type::kInt32, 0);
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100120
xueliang.zhongf7caf682017-03-01 16:07:02 +0000121 DCHECK(div_check->CanThrow());
122
123 entry->AddInstruction(array);
124
125 HInstruction* block_instructions[] = {add1,
126 add2,
127 mul,
128 div_check,
129 div,
130 array_get1,
131 array_set1,
132 array_get2,
133 array_set2};
Vladimir Marko7d157fc2017-05-10 16:29:23 +0100134 for (HInstruction* instr : block_instructions) {
xueliang.zhongf7caf682017-03-01 16:07:02 +0000135 block1->AddInstruction(instr);
136 }
137
Vladimir Markoca6fff82017-10-03 14:49:14 +0100138 HEnvironment* environment = new (GetAllocator()) HEnvironment(GetAllocator(),
139 2,
140 graph_->GetArtMethod(),
141 0,
142 div_check);
xueliang.zhongf7caf682017-03-01 16:07:02 +0000143 div_check->SetRawEnvironment(environment);
144 environment->SetRawEnvAt(0, add2);
145 add2->AddEnvUseAt(div_check->GetEnvironment(), 0);
146 environment->SetRawEnvAt(1, mul);
147 mul->AddEnvUseAt(div_check->GetEnvironment(), 1);
148
Vladimir Markoced04832018-07-26 14:42:17 +0100149 SchedulingGraph scheduling_graph(scheduler,
150 GetScopedAllocator(),
151 /* heap_location_collector */ nullptr);
xueliang.zhongf7caf682017-03-01 16:07:02 +0000152 // Instructions must be inserted in reverse order into the scheduling graph.
Vladimir Marko7d157fc2017-05-10 16:29:23 +0100153 for (HInstruction* instr : ReverseRange(block_instructions)) {
xueliang.zhongf7caf682017-03-01 16:07:02 +0000154 scheduling_graph.AddNode(instr);
155 }
156
157 // Should not have dependencies cross basic blocks.
158 ASSERT_FALSE(scheduling_graph.HasImmediateDataDependency(add1, c1));
159 ASSERT_FALSE(scheduling_graph.HasImmediateDataDependency(add2, c2));
160
161 // Define-use dependency.
162 ASSERT_TRUE(scheduling_graph.HasImmediateDataDependency(add2, add1));
163 ASSERT_FALSE(scheduling_graph.HasImmediateDataDependency(add1, add2));
164 ASSERT_TRUE(scheduling_graph.HasImmediateDataDependency(div_check, add2));
165 ASSERT_FALSE(scheduling_graph.HasImmediateDataDependency(div_check, add1));
166 ASSERT_TRUE(scheduling_graph.HasImmediateDataDependency(div, div_check));
167 ASSERT_TRUE(scheduling_graph.HasImmediateDataDependency(array_set1, add1));
168 ASSERT_TRUE(scheduling_graph.HasImmediateDataDependency(array_set1, add2));
169
170 // Read and write dependencies
171 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(array_set1, array_get1));
172 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(array_set2, array_get2));
173 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(array_get2, array_set1));
Vladimir Marko09d041b2018-07-30 12:51:59 +0100174 // Unnecessary dependency is not stored, we rely on transitive dependencies.
175 // The array_set2 -> array_get2 -> array_set1 dependencies are tested above.
176 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(array_set2, array_set1));
xueliang.zhongf7caf682017-03-01 16:07:02 +0000177
178 // Env dependency.
179 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(div_check, mul));
180 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(mul, div_check));
181
182 // CanThrow.
183 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(array_set1, div_check));
184
185 // Exercise the code path of target specific scheduler and SchedulingLatencyVisitor.
186 scheduler->Schedule(graph_);
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100187 }
188
Mathieu Chartierfa3db3d2018-01-12 14:42:18 -0800189 void CompileWithRandomSchedulerAndRun(const std::vector<uint16_t>& data,
190 bool has_result,
191 int expected) {
xueliang.zhongf7caf682017-03-01 16:07:02 +0000192 for (CodegenTargetConfig target_config : GetTargetConfigs()) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100193 HGraph* graph = CreateCFG(data);
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100194
xueliang.zhongf7caf682017-03-01 16:07:02 +0000195 // Schedule the graph randomly.
196 HInstructionScheduling scheduling(graph, target_config.GetInstructionSet());
197 scheduling.Run(/*only_optimize_loop_blocks*/ false, /*schedule_randomly*/ true);
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100198
Vladimir Markoa0431112018-06-25 09:32:54 +0100199 OverrideInstructionSetFeatures(target_config.GetInstructionSet(), "default");
xueliang.zhongf7caf682017-03-01 16:07:02 +0000200 RunCode(target_config,
Vladimir Markoa0431112018-06-25 09:32:54 +0100201 *compiler_options_,
xueliang.zhongf7caf682017-03-01 16:07:02 +0000202 graph,
203 [](HGraph* graph_arg) { RemoveSuspendChecks(graph_arg); },
204 has_result, expected);
205 }
206 }
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100207
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100208 void TestDependencyGraphOnAliasingArrayAccesses(HScheduler* scheduler) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100209 HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph_);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100210 graph_->AddBlock(entry);
211 graph_->SetEntryBlock(entry);
212 graph_->BuildDominatorTree();
213
Vladimir Markoca6fff82017-10-03 14:49:14 +0100214 HInstruction* arr = new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100215 dex::TypeIndex(0),
216 0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100217 DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +0100218 HInstruction* i = new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
219 dex::TypeIndex(1),
220 1,
221 DataType::Type::kInt32);
222 HInstruction* j = new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
223 dex::TypeIndex(1),
224 1,
225 DataType::Type::kInt32);
226 HInstruction* object = new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
227 dex::TypeIndex(0),
228 0,
229 DataType::Type::kReference);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100230 HInstruction* c0 = graph_->GetIntConstant(0);
231 HInstruction* c1 = graph_->GetIntConstant(1);
Vladimir Markoca6fff82017-10-03 14:49:14 +0100232 HInstruction* add0 = new (GetAllocator()) HAdd(DataType::Type::kInt32, i, c0);
233 HInstruction* add1 = new (GetAllocator()) HAdd(DataType::Type::kInt32, i, c1);
234 HInstruction* sub0 = new (GetAllocator()) HSub(DataType::Type::kInt32, i, c0);
235 HInstruction* sub1 = new (GetAllocator()) HSub(DataType::Type::kInt32, i, c1);
236 HInstruction* arr_set_0 =
237 new (GetAllocator()) HArraySet(arr, c0, c0, DataType::Type::kInt32, 0);
238 HInstruction* arr_set_1 =
239 new (GetAllocator()) HArraySet(arr, c1, c0, DataType::Type::kInt32, 0);
240 HInstruction* arr_set_i = new (GetAllocator()) HArraySet(arr, i, c0, DataType::Type::kInt32, 0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100241 HInstruction* arr_set_add0 =
Vladimir Markoca6fff82017-10-03 14:49:14 +0100242 new (GetAllocator()) HArraySet(arr, add0, c0, DataType::Type::kInt32, 0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100243 HInstruction* arr_set_add1 =
Vladimir Markoca6fff82017-10-03 14:49:14 +0100244 new (GetAllocator()) HArraySet(arr, add1, c0, DataType::Type::kInt32, 0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100245 HInstruction* arr_set_sub0 =
Vladimir Markoca6fff82017-10-03 14:49:14 +0100246 new (GetAllocator()) HArraySet(arr, sub0, c0, DataType::Type::kInt32, 0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100247 HInstruction* arr_set_sub1 =
Vladimir Markoca6fff82017-10-03 14:49:14 +0100248 new (GetAllocator()) HArraySet(arr, sub1, c0, DataType::Type::kInt32, 0);
249 HInstruction* arr_set_j = new (GetAllocator()) HArraySet(arr, j, c0, DataType::Type::kInt32, 0);
250 HInstanceFieldSet* set_field10 = new (GetAllocator()) HInstanceFieldSet(object,
251 c1,
252 nullptr,
253 DataType::Type::kInt32,
254 MemberOffset(10),
255 false,
256 kUnknownFieldIndex,
257 kUnknownClassDefIndex,
258 graph_->GetDexFile(),
259 0);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100260
261 HInstruction* block_instructions[] = {arr,
262 i,
263 j,
264 object,
265 add0,
266 add1,
267 sub0,
268 sub1,
269 arr_set_0,
270 arr_set_1,
271 arr_set_i,
272 arr_set_add0,
273 arr_set_add1,
274 arr_set_sub0,
275 arr_set_sub1,
276 arr_set_j,
277 set_field10};
278
279 for (HInstruction* instr : block_instructions) {
280 entry->AddInstruction(instr);
281 }
282
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100283 HeapLocationCollector heap_location_collector(graph_);
284 heap_location_collector.VisitBasicBlock(entry);
285 heap_location_collector.BuildAliasingMatrix();
Vladimir Markoced04832018-07-26 14:42:17 +0100286 SchedulingGraph scheduling_graph(scheduler, GetScopedAllocator(), &heap_location_collector);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100287
288 for (HInstruction* instr : ReverseRange(block_instructions)) {
289 // Build scheduling graph with memory access aliasing information
290 // from LSA/heap_location_collector.
291 scheduling_graph.AddNode(instr);
292 }
293
294 // LSA/HeapLocationCollector should see those ArraySet instructions.
295 ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 9U);
296 ASSERT_TRUE(heap_location_collector.HasHeapStores());
297
298 // Test queries on HeapLocationCollector's aliasing matrix after load store analysis.
299 // HeapLocationCollector and SchedulingGraph should report consistent relationships.
300 size_t loc1 = HeapLocationCollector::kHeapLocationNotFound;
301 size_t loc2 = HeapLocationCollector::kHeapLocationNotFound;
302
303 // Test side effect dependency: array[0] and array[1]
Aart Bikb765a3f2018-05-10 14:47:48 -0700304 loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_0);
305 loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_1);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100306 ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
307 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_1, arr_set_0));
308
309 // Test side effect dependency based on LSA analysis: array[i] and array[j]
Aart Bikb765a3f2018-05-10 14:47:48 -0700310 loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
311 loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_j);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100312 ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
Vladimir Marko09d041b2018-07-30 12:51:59 +0100313 // Unnecessary dependency is not stored, we rely on transitive dependencies.
314 // The arr_set_j -> arr_set_sub0 -> arr_set_add0 -> arr_set_i dependencies are tested below.
315 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, arr_set_i));
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100316
317 // Test side effect dependency based on LSA analysis: array[i] and array[i+0]
Aart Bikb765a3f2018-05-10 14:47:48 -0700318 loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
319 loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_add0);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100320 ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
321 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(arr_set_add0, arr_set_i));
322
323 // Test side effect dependency based on LSA analysis: array[i] and array[i-0]
Aart Bikb765a3f2018-05-10 14:47:48 -0700324 loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
325 loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_sub0);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100326 ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
Vladimir Marko09d041b2018-07-30 12:51:59 +0100327 // Unnecessary dependency is not stored, we rely on transitive dependencies.
328 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_sub0, arr_set_i));
329 // Instead, we rely on arr_set_sub0 -> arr_set_add0 -> arr_set_i, the latter is tested above.
330 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(arr_set_sub0, arr_set_add0));
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100331
332 // Test side effect dependency based on LSA analysis: array[i] and array[i+1]
Aart Bikb765a3f2018-05-10 14:47:48 -0700333 loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
334 loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_add1);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100335 ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
336 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_add1, arr_set_i));
337
338 // Test side effect dependency based on LSA analysis: array[i+1] and array[i-1]
Aart Bikb765a3f2018-05-10 14:47:48 -0700339 loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_add1);
340 loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_sub1);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100341 ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
342 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_sub1, arr_set_add1));
343
344 // Test side effect dependency based on LSA analysis: array[j] and all others array accesses
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100345 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, arr_set_sub0));
346 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, arr_set_add1));
347 ASSERT_TRUE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, arr_set_sub1));
Vladimir Marko09d041b2018-07-30 12:51:59 +0100348 // Unnecessary dependencies are not stored, we rely on transitive dependencies.
349 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, arr_set_i));
350 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, arr_set_add0));
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100351
352 // Test that ArraySet and FieldSet should not have side effect dependency
353 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_i, set_field10));
354 ASSERT_FALSE(scheduling_graph.HasImmediateOtherDependency(arr_set_j, set_field10));
355
356 // Exercise target specific scheduler and SchedulingLatencyVisitor.
357 scheduler->Schedule(graph_);
358 }
359
xueliang.zhongf7caf682017-03-01 16:07:02 +0000360 HGraph* graph_;
361};
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100362
xueliang.zhongf7caf682017-03-01 16:07:02 +0000363#if defined(ART_ENABLE_CODEGEN_arm64)
364TEST_F(SchedulerTest, DependencyGraphAndSchedulerARM64) {
365 CriticalPathSchedulingNodeSelector critical_path_selector;
Vladimir Markoced04832018-07-26 14:42:17 +0100366 arm64::HSchedulerARM64 scheduler(&critical_path_selector);
xueliang.zhongf7caf682017-03-01 16:07:02 +0000367 TestBuildDependencyGraphAndSchedule(&scheduler);
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100368}
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100369
370TEST_F(SchedulerTest, ArrayAccessAliasingARM64) {
371 CriticalPathSchedulingNodeSelector critical_path_selector;
Vladimir Markoced04832018-07-26 14:42:17 +0100372 arm64::HSchedulerARM64 scheduler(&critical_path_selector);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100373 TestDependencyGraphOnAliasingArrayAccesses(&scheduler);
374}
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100375#endif
376
xueliang.zhongf7caf682017-03-01 16:07:02 +0000377#if defined(ART_ENABLE_CODEGEN_arm)
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100378TEST_F(SchedulerTest, DependencyGraphAndSchedulerARM) {
xueliang.zhongf7caf682017-03-01 16:07:02 +0000379 CriticalPathSchedulingNodeSelector critical_path_selector;
380 arm::SchedulingLatencyVisitorARM arm_latency_visitor(/*CodeGenerator*/ nullptr);
Vladimir Markoced04832018-07-26 14:42:17 +0100381 arm::HSchedulerARM scheduler(&critical_path_selector, &arm_latency_visitor);
xueliang.zhongf7caf682017-03-01 16:07:02 +0000382 TestBuildDependencyGraphAndSchedule(&scheduler);
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100383}
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100384
385TEST_F(SchedulerTest, ArrayAccessAliasingARM) {
386 CriticalPathSchedulingNodeSelector critical_path_selector;
387 arm::SchedulingLatencyVisitorARM arm_latency_visitor(/*CodeGenerator*/ nullptr);
Vladimir Markoced04832018-07-26 14:42:17 +0100388 arm::HSchedulerARM scheduler(&critical_path_selector, &arm_latency_visitor);
xueliang.zhong2a3471f2017-05-08 18:36:40 +0100389 TestDependencyGraphOnAliasingArrayAccesses(&scheduler);
390}
xueliang.zhongf7caf682017-03-01 16:07:02 +0000391#endif
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100392
393TEST_F(SchedulerTest, RandomScheduling) {
394 //
395 // Java source: crafted code to make sure (random) scheduling should get correct result.
396 //
397 // int result = 0;
398 // float fr = 10.0f;
399 // for (int i = 1; i < 10; i++) {
400 // fr ++;
401 // int t1 = result >> i;
402 // int t2 = result * i;
403 // result = result + t1 - t2;
404 // fr = fr / i;
405 // result += (int)fr;
406 // }
407 // return result;
408 //
Mathieu Chartierfa3db3d2018-01-12 14:42:18 -0800409 const std::vector<uint16_t> data = SIX_REGISTERS_CODE_ITEM(
Alexandre Rames22aa54b2016-10-18 09:32:29 +0100410 Instruction::CONST_4 | 0 << 12 | 2 << 8, // const/4 v2, #int 0
411 Instruction::CONST_HIGH16 | 0 << 8, 0x4120, // const/high16 v0, #float 10.0 // #41200000
412 Instruction::CONST_4 | 1 << 12 | 1 << 8, // const/4 v1, #int 1
413 Instruction::CONST_16 | 5 << 8, 0x000a, // const/16 v5, #int 10
414 Instruction::IF_GE | 5 << 12 | 1 << 8, 0x0014, // if-ge v1, v5, 001a // +0014
415 Instruction::CONST_HIGH16 | 5 << 8, 0x3f80, // const/high16 v5, #float 1.0 // #3f800000
416 Instruction::ADD_FLOAT_2ADDR | 5 << 12 | 0 << 8, // add-float/2addr v0, v5
417 Instruction::SHR_INT | 3 << 8, 1 << 8 | 2 , // shr-int v3, v2, v1
418 Instruction::MUL_INT | 4 << 8, 1 << 8 | 2, // mul-int v4, v2, v1
419 Instruction::ADD_INT | 5 << 8, 3 << 8 | 2, // add-int v5, v2, v3
420 Instruction::SUB_INT | 2 << 8, 4 << 8 | 5, // sub-int v2, v5, v4
421 Instruction::INT_TO_FLOAT | 1 << 12 | 5 << 8, // int-to-float v5, v1
422 Instruction::DIV_FLOAT_2ADDR | 5 << 12 | 0 << 8, // div-float/2addr v0, v5
423 Instruction::FLOAT_TO_INT | 0 << 12 | 5 << 8, // float-to-int v5, v0
424 Instruction::ADD_INT_2ADDR | 5 << 12 | 2 << 8, // add-int/2addr v2, v5
425 Instruction::ADD_INT_LIT8 | 1 << 8, 1 << 8 | 1, // add-int/lit8 v1, v1, #int 1 // #01
426 Instruction::GOTO | 0xeb << 8, // goto 0004 // -0015
427 Instruction::RETURN | 2 << 8); // return v2
428
429 constexpr int kNumberOfRuns = 10;
430 for (int i = 0; i < kNumberOfRuns; ++i) {
431 CompileWithRandomSchedulerAndRun(data, true, 138774);
432 }
433}
434
435} // namespace art