| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 17 | #include "register_allocator.h" |
| 18 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 19 | #include "arch/x86/instruction_set_features_x86.h" |
| Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 20 | #include "base/arena_allocator.h" |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 21 | #include "builder.h" |
| 22 | #include "code_generator.h" |
| Nicolas Geoffray | 8a16d97 | 2014-09-11 10:30:02 +0100 | [diff] [blame] | 23 | #include "code_generator_x86.h" |
| David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 24 | #include "dex/dex_file.h" |
| 25 | #include "dex/dex_file_types.h" |
| 26 | #include "dex/dex_instruction.h" |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 27 | #include "driver/compiler_options.h" |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 28 | #include "nodes.h" |
| 29 | #include "optimizing_unit_test.h" |
| Matthew Gharrity | e928885 | 2016-07-14 14:08:16 -0700 | [diff] [blame] | 30 | #include "register_allocator_linear_scan.h" |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 31 | #include "ssa_liveness_analysis.h" |
| Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 32 | #include "ssa_phi_elimination.h" |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 33 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 34 | namespace art { |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 35 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 36 | using Strategy = RegisterAllocator::Strategy; |
| 37 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 38 | // Note: the register allocator tests rely on the fact that constants have live |
| 39 | // intervals and registers get allocated to them. |
| 40 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 41 | class RegisterAllocatorTest : public OptimizingUnitTest { |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 42 | protected: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 43 | void SetUp() override { |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 44 | OptimizingUnitTest::SetUp(); |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame^] | 45 | // This test is using the x86 ISA. |
| 46 | compiler_options_ = CommonCompilerTest::CreateCompilerOptions(InstructionSet::kX86, "default"); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 49 | // These functions need to access private variables of LocationSummary, so we declare it |
| 50 | // as a member of RegisterAllocatorTest, which we make a friend class. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 51 | void SameAsFirstInputHint(Strategy strategy); |
| 52 | void ExpectedInRegisterHint(Strategy strategy); |
| 53 | |
| 54 | // Helper functions that make use of the OptimizingUnitTest's members. |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 55 | bool Check(const std::vector<uint16_t>& data, Strategy strategy); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 56 | void CFG1(Strategy strategy); |
| 57 | void Loop1(Strategy strategy); |
| 58 | void Loop2(Strategy strategy); |
| 59 | void Loop3(Strategy strategy); |
| 60 | void DeadPhi(Strategy strategy); |
| 61 | HGraph* BuildIfElseWithPhi(HPhi** phi, HInstruction** input1, HInstruction** input2); |
| 62 | void PhiHint(Strategy strategy); |
| 63 | HGraph* BuildFieldReturn(HInstruction** field, HInstruction** ret); |
| 64 | HGraph* BuildTwoSubs(HInstruction** first_sub, HInstruction** second_sub); |
| 65 | HGraph* BuildDiv(HInstruction** div); |
| 66 | void ExpectedExactInRegisterAndSameOutputHint(Strategy strategy); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 67 | |
| 68 | bool ValidateIntervals(const ScopedArenaVector<LiveInterval*>& intervals, |
| 69 | const CodeGenerator& codegen) { |
| 70 | return RegisterAllocator::ValidateIntervals(ArrayRef<LiveInterval* const>(intervals), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 71 | /* number_of_spill_slots= */ 0u, |
| 72 | /* number_of_out_slots= */ 0u, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 73 | codegen, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 74 | /* processing_core_registers= */ true, |
| 75 | /* log_fatal_on_failure= */ false); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 76 | } |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame^] | 77 | |
| 78 | std::unique_ptr<CompilerOptions> compiler_options_; |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 79 | }; |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 80 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 81 | // This macro should include all register allocation strategies that should be tested. |
| 82 | #define TEST_ALL_STRATEGIES(test_name)\ |
| 83 | TEST_F(RegisterAllocatorTest, test_name##_LinearScan) {\ |
| 84 | test_name(Strategy::kRegisterAllocatorLinearScan);\ |
| 85 | }\ |
| 86 | TEST_F(RegisterAllocatorTest, test_name##_GraphColor) {\ |
| 87 | test_name(Strategy::kRegisterAllocatorGraphColor);\ |
| 88 | } |
| 89 | |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 90 | bool RegisterAllocatorTest::Check(const std::vector<uint16_t>& data, Strategy strategy) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 91 | HGraph* graph = CreateCFG(data); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 92 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 93 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 94 | liveness.Analyze(); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 95 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 96 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 97 | register_allocator->AllocateRegisters(); |
| 98 | return register_allocator->Validate(false); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Unit testing of RegisterAllocator::ValidateIntervals. Register allocator |
| 103 | * tests are based on this validation method. |
| 104 | */ |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 105 | TEST_F(RegisterAllocatorTest, ValidateIntervals) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 106 | HGraph* graph = CreateGraph(); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 107 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 108 | ScopedArenaVector<LiveInterval*> intervals(GetScopedAllocator()->Adapter()); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 109 | |
| 110 | // Test with two intervals of the same range. |
| 111 | { |
| 112 | static constexpr size_t ranges[][2] = {{0, 42}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 113 | intervals.push_back(BuildInterval(ranges, arraysize(ranges), GetScopedAllocator(), 0)); |
| 114 | intervals.push_back(BuildInterval(ranges, arraysize(ranges), GetScopedAllocator(), 1)); |
| 115 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 116 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 117 | intervals[1]->SetRegister(0); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 118 | ASSERT_FALSE(ValidateIntervals(intervals, codegen)); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 119 | intervals.clear(); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // Test with two non-intersecting intervals. |
| 123 | { |
| 124 | static constexpr size_t ranges1[][2] = {{0, 42}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 125 | intervals.push_back(BuildInterval(ranges1, arraysize(ranges1), GetScopedAllocator(), 0)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 126 | static constexpr size_t ranges2[][2] = {{42, 43}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 127 | intervals.push_back(BuildInterval(ranges2, arraysize(ranges2), GetScopedAllocator(), 1)); |
| 128 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 129 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 130 | intervals[1]->SetRegister(0); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 131 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 132 | intervals.clear(); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // Test with two non-intersecting intervals, with one with a lifetime hole. |
| 136 | { |
| 137 | static constexpr size_t ranges1[][2] = {{0, 42}, {45, 48}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 138 | intervals.push_back(BuildInterval(ranges1, arraysize(ranges1), GetScopedAllocator(), 0)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 139 | static constexpr size_t ranges2[][2] = {{42, 43}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 140 | intervals.push_back(BuildInterval(ranges2, arraysize(ranges2), GetScopedAllocator(), 1)); |
| 141 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 142 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 143 | intervals[1]->SetRegister(0); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 144 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 145 | intervals.clear(); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // Test with intersecting intervals. |
| 149 | { |
| 150 | static constexpr size_t ranges1[][2] = {{0, 42}, {44, 48}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 151 | intervals.push_back(BuildInterval(ranges1, arraysize(ranges1), GetScopedAllocator(), 0)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 152 | static constexpr size_t ranges2[][2] = {{42, 47}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 153 | intervals.push_back(BuildInterval(ranges2, arraysize(ranges2), GetScopedAllocator(), 1)); |
| 154 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 155 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 156 | intervals[1]->SetRegister(0); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 157 | ASSERT_FALSE(ValidateIntervals(intervals, codegen)); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 158 | intervals.clear(); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // Test with siblings. |
| 162 | { |
| 163 | static constexpr size_t ranges1[][2] = {{0, 42}, {44, 48}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 164 | intervals.push_back(BuildInterval(ranges1, arraysize(ranges1), GetScopedAllocator(), 0)); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 165 | intervals[0]->SplitAt(43); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 166 | static constexpr size_t ranges2[][2] = {{42, 47}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 167 | intervals.push_back(BuildInterval(ranges2, arraysize(ranges2), GetScopedAllocator(), 1)); |
| 168 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 169 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 170 | intervals[1]->SetRegister(0); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 171 | // Sibling of the first interval has no register allocated to it. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 172 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 173 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 174 | intervals[0]->GetNextSibling()->SetRegister(0); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 175 | ASSERT_FALSE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 179 | void RegisterAllocatorTest::CFG1(Strategy strategy) { |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 180 | /* |
| 181 | * Test the following snippet: |
| 182 | * return 0; |
| 183 | * |
| 184 | * Which becomes the following graph: |
| 185 | * constant0 |
| 186 | * goto |
| 187 | * | |
| 188 | * return |
| 189 | * | |
| 190 | * exit |
| 191 | */ |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 192 | const std::vector<uint16_t> data = ONE_REGISTER_CODE_ITEM( |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 193 | Instruction::CONST_4 | 0 | 0, |
| 194 | Instruction::RETURN); |
| 195 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 196 | ASSERT_TRUE(Check(data, strategy)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 199 | TEST_ALL_STRATEGIES(CFG1); |
| 200 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 201 | void RegisterAllocatorTest::Loop1(Strategy strategy) { |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 202 | /* |
| 203 | * Test the following snippet: |
| 204 | * int a = 0; |
| 205 | * while (a == a) { |
| 206 | * a = 4; |
| 207 | * } |
| 208 | * return 5; |
| 209 | * |
| 210 | * Which becomes the following graph: |
| 211 | * constant0 |
| 212 | * constant4 |
| 213 | * constant5 |
| 214 | * goto |
| 215 | * | |
| 216 | * goto |
| 217 | * | |
| 218 | * phi |
| 219 | * equal |
| 220 | * if +++++ |
| 221 | * | \ + |
| 222 | * | goto |
| 223 | * | |
| 224 | * return |
| 225 | * | |
| 226 | * exit |
| 227 | */ |
| 228 | |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 229 | const std::vector<uint16_t> data = TWO_REGISTERS_CODE_ITEM( |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 230 | Instruction::CONST_4 | 0 | 0, |
| 231 | Instruction::IF_EQ, 4, |
| 232 | Instruction::CONST_4 | 4 << 12 | 0, |
| 233 | Instruction::GOTO | 0xFD00, |
| 234 | Instruction::CONST_4 | 5 << 12 | 1 << 8, |
| 235 | Instruction::RETURN | 1 << 8); |
| 236 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 237 | ASSERT_TRUE(Check(data, strategy)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 238 | } |
| 239 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 240 | TEST_ALL_STRATEGIES(Loop1); |
| 241 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 242 | void RegisterAllocatorTest::Loop2(Strategy strategy) { |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 243 | /* |
| 244 | * Test the following snippet: |
| 245 | * int a = 0; |
| 246 | * while (a == 8) { |
| 247 | * a = 4 + 5; |
| 248 | * } |
| 249 | * return 6 + 7; |
| 250 | * |
| 251 | * Which becomes the following graph: |
| 252 | * constant0 |
| 253 | * constant4 |
| 254 | * constant5 |
| 255 | * constant6 |
| 256 | * constant7 |
| 257 | * constant8 |
| 258 | * goto |
| 259 | * | |
| 260 | * goto |
| 261 | * | |
| 262 | * phi |
| 263 | * equal |
| 264 | * if +++++ |
| 265 | * | \ + |
| 266 | * | 4 + 5 |
| 267 | * | goto |
| 268 | * | |
| 269 | * 6 + 7 |
| 270 | * return |
| 271 | * | |
| 272 | * exit |
| 273 | */ |
| 274 | |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 275 | const std::vector<uint16_t> data = TWO_REGISTERS_CODE_ITEM( |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 276 | Instruction::CONST_4 | 0 | 0, |
| 277 | Instruction::CONST_4 | 8 << 12 | 1 << 8, |
| 278 | Instruction::IF_EQ | 1 << 8, 7, |
| 279 | Instruction::CONST_4 | 4 << 12 | 0 << 8, |
| 280 | Instruction::CONST_4 | 5 << 12 | 1 << 8, |
| 281 | Instruction::ADD_INT, 1 << 8 | 0, |
| 282 | Instruction::GOTO | 0xFA00, |
| 283 | Instruction::CONST_4 | 6 << 12 | 1 << 8, |
| 284 | Instruction::CONST_4 | 7 << 12 | 1 << 8, |
| 285 | Instruction::ADD_INT, 1 << 8 | 0, |
| 286 | Instruction::RETURN | 1 << 8); |
| 287 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 288 | ASSERT_TRUE(Check(data, strategy)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 291 | TEST_ALL_STRATEGIES(Loop2); |
| 292 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 293 | void RegisterAllocatorTest::Loop3(Strategy strategy) { |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 294 | /* |
| 295 | * Test the following snippet: |
| 296 | * int a = 0 |
| 297 | * do { |
| 298 | * b = a; |
| 299 | * a++; |
| 300 | * } while (a != 5) |
| 301 | * return b; |
| 302 | * |
| 303 | * Which becomes the following graph: |
| 304 | * constant0 |
| 305 | * constant1 |
| 306 | * constant5 |
| 307 | * goto |
| 308 | * | |
| 309 | * goto |
| 310 | * |++++++++++++ |
| 311 | * phi + |
| 312 | * a++ + |
| 313 | * equals + |
| 314 | * if + |
| 315 | * |++++++++++++ |
| 316 | * return |
| 317 | * | |
| 318 | * exit |
| 319 | */ |
| 320 | |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 321 | const std::vector<uint16_t> data = THREE_REGISTERS_CODE_ITEM( |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 322 | Instruction::CONST_4 | 0 | 0, |
| 323 | Instruction::ADD_INT_LIT8 | 1 << 8, 1 << 8, |
| 324 | Instruction::CONST_4 | 5 << 12 | 2 << 8, |
| 325 | Instruction::IF_NE | 1 << 8 | 2 << 12, 3, |
| 326 | Instruction::RETURN | 0 << 8, |
| 327 | Instruction::MOVE | 1 << 12 | 0 << 8, |
| 328 | Instruction::GOTO | 0xF900); |
| 329 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 330 | HGraph* graph = CreateCFG(data); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 331 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 332 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 333 | liveness.Analyze(); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 334 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 335 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 336 | register_allocator->AllocateRegisters(); |
| 337 | ASSERT_TRUE(register_allocator->Validate(false)); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 338 | |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 339 | HBasicBlock* loop_header = graph->GetBlocks()[2]; |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 340 | HPhi* phi = loop_header->GetFirstPhi()->AsPhi(); |
| 341 | |
| 342 | LiveInterval* phi_interval = phi->GetLiveInterval(); |
| 343 | LiveInterval* loop_update = phi->InputAt(1)->GetLiveInterval(); |
| 344 | ASSERT_TRUE(phi_interval->HasRegister()); |
| 345 | ASSERT_TRUE(loop_update->HasRegister()); |
| 346 | ASSERT_NE(phi_interval->GetRegister(), loop_update->GetRegister()); |
| 347 | |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 348 | HBasicBlock* return_block = graph->GetBlocks()[3]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 349 | HReturn* ret = return_block->GetLastInstruction()->AsReturn(); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 350 | ASSERT_EQ(phi_interval->GetRegister(), ret->InputAt(0)->GetLiveInterval()->GetRegister()); |
| 351 | } |
| 352 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 353 | TEST_ALL_STRATEGIES(Loop3); |
| 354 | |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 355 | TEST_F(RegisterAllocatorTest, FirstRegisterUse) { |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 356 | const std::vector<uint16_t> data = THREE_REGISTERS_CODE_ITEM( |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 357 | Instruction::CONST_4 | 0 | 0, |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 358 | Instruction::XOR_INT_LIT8 | 1 << 8, 1 << 8, |
| 359 | Instruction::XOR_INT_LIT8 | 0 << 8, 1 << 8, |
| 360 | Instruction::XOR_INT_LIT8 | 1 << 8, 1 << 8 | 1, |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 361 | Instruction::RETURN_VOID); |
| 362 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 363 | HGraph* graph = CreateCFG(data); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 364 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 365 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 366 | liveness.Analyze(); |
| 367 | |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 368 | HXor* first_xor = graph->GetBlocks()[1]->GetFirstInstruction()->AsXor(); |
| 369 | HXor* last_xor = graph->GetBlocks()[1]->GetLastInstruction()->GetPrevious()->AsXor(); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 370 | ASSERT_EQ(last_xor->InputAt(0), first_xor); |
| 371 | LiveInterval* interval = first_xor->GetLiveInterval(); |
| 372 | ASSERT_EQ(interval->GetEnd(), last_xor->GetLifetimePosition()); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 373 | ASSERT_TRUE(interval->GetNextSibling() == nullptr); |
| 374 | |
| 375 | // We need a register for the output of the instruction. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 376 | ASSERT_EQ(interval->FirstRegisterUse(), first_xor->GetLifetimePosition()); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 377 | |
| 378 | // Split at the next instruction. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 379 | interval = interval->SplitAt(first_xor->GetLifetimePosition() + 2); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 380 | // The user of the split is the last add. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 381 | ASSERT_EQ(interval->FirstRegisterUse(), last_xor->GetLifetimePosition()); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 382 | |
| 383 | // Split before the last add. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 384 | LiveInterval* new_interval = interval->SplitAt(last_xor->GetLifetimePosition() - 1); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 385 | // Ensure the current interval has no register use... |
| 386 | ASSERT_EQ(interval->FirstRegisterUse(), kNoLifetime); |
| 387 | // And the new interval has it for the last add. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 388 | ASSERT_EQ(new_interval->FirstRegisterUse(), last_xor->GetLifetimePosition()); |
| Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 391 | void RegisterAllocatorTest::DeadPhi(Strategy strategy) { |
| Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 392 | /* Test for a dead loop phi taking as back-edge input a phi that also has |
| 393 | * this loop phi as input. Walking backwards in SsaDeadPhiElimination |
| 394 | * does not solve the problem because the loop phi will be visited last. |
| 395 | * |
| 396 | * Test the following snippet: |
| 397 | * int a = 0 |
| 398 | * do { |
| 399 | * if (true) { |
| 400 | * a = 2; |
| 401 | * } |
| 402 | * } while (true); |
| 403 | */ |
| 404 | |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 405 | const std::vector<uint16_t> data = TWO_REGISTERS_CODE_ITEM( |
| Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 406 | Instruction::CONST_4 | 0 | 0, |
| 407 | Instruction::CONST_4 | 1 << 8 | 0, |
| 408 | Instruction::IF_NE | 1 << 8 | 1 << 12, 3, |
| 409 | Instruction::CONST_4 | 2 << 12 | 0 << 8, |
| 410 | Instruction::GOTO | 0xFD00, |
| 411 | Instruction::RETURN_VOID); |
| 412 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 413 | HGraph* graph = CreateCFG(data); |
| Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 414 | SsaDeadPhiElimination(graph).Run(); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 415 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 416 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 417 | liveness.Analyze(); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 418 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 419 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 420 | register_allocator->AllocateRegisters(); |
| 421 | ASSERT_TRUE(register_allocator->Validate(false)); |
| Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 422 | } |
| 423 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 424 | TEST_ALL_STRATEGIES(DeadPhi); |
| 425 | |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 426 | /** |
| 427 | * Test that the TryAllocateFreeReg method works in the presence of inactive intervals |
| 428 | * that share the same register. It should split the interval it is currently |
| 429 | * allocating for at the minimum lifetime position between the two inactive intervals. |
| Matthew Gharrity | d9ffd0d | 2016-06-22 10:27:55 -0700 | [diff] [blame] | 430 | * This test only applies to the linear scan allocator. |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 431 | */ |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 432 | TEST_F(RegisterAllocatorTest, FreeUntil) { |
| Mathieu Chartier | fa3db3d | 2018-01-12 14:42:18 -0800 | [diff] [blame] | 433 | const std::vector<uint16_t> data = TWO_REGISTERS_CODE_ITEM( |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 434 | Instruction::CONST_4 | 0 | 0, |
| 435 | Instruction::RETURN); |
| 436 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 437 | HGraph* graph = CreateCFG(data); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 438 | SsaDeadPhiElimination(graph).Run(); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 439 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 440 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 441 | liveness.Analyze(); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 442 | RegisterAllocatorLinearScan register_allocator(GetScopedAllocator(), &codegen, liveness); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 443 | |
| 444 | // Add an artifical range to cover the temps that will be put in the unhandled list. |
| 445 | LiveInterval* unhandled = graph->GetEntryBlock()->GetFirstInstruction()->GetLiveInterval(); |
| 446 | unhandled->AddLoopRange(0, 60); |
| Nicolas Geoffray | 23a8188 | 2015-06-01 18:12:38 +0100 | [diff] [blame] | 447 | |
| Nicolas Geoffray | 30971d6 | 2015-06-01 18:37:24 +0100 | [diff] [blame] | 448 | // Populate the instructions in the liveness object, to please the register allocator. |
| Nicolas Geoffray | 23a8188 | 2015-06-01 18:12:38 +0100 | [diff] [blame] | 449 | for (size_t i = 0; i < 60; ++i) { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 450 | liveness.instructions_from_lifetime_position_.push_back( |
| Nicolas Geoffray | 23a8188 | 2015-06-01 18:12:38 +0100 | [diff] [blame] | 451 | graph->GetEntryBlock()->GetFirstInstruction()); |
| 452 | } |
| 453 | |
| Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 454 | // For SSA value intervals, only an interval resulted from a split may intersect |
| 455 | // with inactive intervals. |
| 456 | unhandled = register_allocator.Split(unhandled, 5); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 457 | |
| 458 | // Add three temps holding the same register, and starting at different positions. |
| 459 | // Put the one that should be picked in the middle of the inactive list to ensure |
| 460 | // we do not depend on an order. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 461 | LiveInterval* interval = |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 462 | LiveInterval::MakeFixedInterval(GetScopedAllocator(), 0, DataType::Type::kInt32); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 463 | interval->AddRange(40, 50); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 464 | register_allocator.inactive_.push_back(interval); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 465 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 466 | interval = LiveInterval::MakeFixedInterval(GetScopedAllocator(), 0, DataType::Type::kInt32); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 467 | interval->AddRange(20, 30); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 468 | register_allocator.inactive_.push_back(interval); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 469 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 470 | interval = LiveInterval::MakeFixedInterval(GetScopedAllocator(), 0, DataType::Type::kInt32); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 471 | interval->AddRange(60, 70); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 472 | register_allocator.inactive_.push_back(interval); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 473 | |
| 474 | register_allocator.number_of_registers_ = 1; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 475 | register_allocator.registers_array_ = GetAllocator()->AllocArray<size_t>(1); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 476 | register_allocator.processing_core_registers_ = true; |
| 477 | register_allocator.unhandled_ = ®ister_allocator.unhandled_core_intervals_; |
| 478 | |
| Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 479 | ASSERT_TRUE(register_allocator.TryAllocateFreeReg(unhandled)); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 480 | |
| 481 | // Check that we have split the interval. |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 482 | ASSERT_EQ(1u, register_allocator.unhandled_->size()); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 483 | // Check that we know need to find a new register where the next interval |
| 484 | // that uses the register starts. |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 485 | ASSERT_EQ(20u, register_allocator.unhandled_->front()->GetStart()); |
| Nicolas Geoffray | aac0f39 | 2014-09-16 14:11:14 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 488 | HGraph* RegisterAllocatorTest::BuildIfElseWithPhi(HPhi** phi, |
| 489 | HInstruction** input1, |
| 490 | HInstruction** input2) { |
| 491 | HGraph* graph = CreateGraph(); |
| 492 | HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 493 | graph->AddBlock(entry); |
| 494 | graph->SetEntryBlock(entry); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 495 | HInstruction* parameter = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 496 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kReference); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 497 | entry->AddInstruction(parameter); |
| 498 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 499 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 500 | graph->AddBlock(block); |
| 501 | entry->AddSuccessor(block); |
| 502 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 503 | HInstruction* test = new (GetAllocator()) HInstanceFieldGet(parameter, |
| 504 | nullptr, |
| 505 | DataType::Type::kBool, |
| 506 | MemberOffset(22), |
| 507 | false, |
| 508 | kUnknownFieldIndex, |
| 509 | kUnknownClassDefIndex, |
| 510 | graph->GetDexFile(), |
| 511 | 0); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 512 | block->AddInstruction(test); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 513 | block->AddInstruction(new (GetAllocator()) HIf(test)); |
| 514 | HBasicBlock* then = new (GetAllocator()) HBasicBlock(graph); |
| 515 | HBasicBlock* else_ = new (GetAllocator()) HBasicBlock(graph); |
| 516 | HBasicBlock* join = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 517 | graph->AddBlock(then); |
| 518 | graph->AddBlock(else_); |
| 519 | graph->AddBlock(join); |
| 520 | |
| 521 | block->AddSuccessor(then); |
| 522 | block->AddSuccessor(else_); |
| 523 | then->AddSuccessor(join); |
| 524 | else_->AddSuccessor(join); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 525 | then->AddInstruction(new (GetAllocator()) HGoto()); |
| 526 | else_->AddInstruction(new (GetAllocator()) HGoto()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 527 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 528 | *phi = new (GetAllocator()) HPhi(GetAllocator(), 0, 0, DataType::Type::kInt32); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 529 | join->AddPhi(*phi); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 530 | *input1 = new (GetAllocator()) HInstanceFieldGet(parameter, |
| 531 | nullptr, |
| 532 | DataType::Type::kInt32, |
| 533 | MemberOffset(42), |
| 534 | false, |
| 535 | kUnknownFieldIndex, |
| 536 | kUnknownClassDefIndex, |
| 537 | graph->GetDexFile(), |
| 538 | 0); |
| 539 | *input2 = new (GetAllocator()) HInstanceFieldGet(parameter, |
| 540 | nullptr, |
| 541 | DataType::Type::kInt32, |
| 542 | MemberOffset(42), |
| 543 | false, |
| 544 | kUnknownFieldIndex, |
| 545 | kUnknownClassDefIndex, |
| 546 | graph->GetDexFile(), |
| 547 | 0); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 548 | then->AddInstruction(*input1); |
| 549 | else_->AddInstruction(*input2); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 550 | join->AddInstruction(new (GetAllocator()) HExit()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 551 | (*phi)->AddInput(*input1); |
| 552 | (*phi)->AddInput(*input2); |
| 553 | |
| 554 | graph->BuildDominatorTree(); |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 555 | graph->AnalyzeLoops(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 556 | return graph; |
| 557 | } |
| 558 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 559 | void RegisterAllocatorTest::PhiHint(Strategy strategy) { |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 560 | HPhi *phi; |
| 561 | HInstruction *input1, *input2; |
| 562 | |
| 563 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 564 | HGraph* graph = BuildIfElseWithPhi(&phi, &input1, &input2); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 565 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 566 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 567 | liveness.Analyze(); |
| 568 | |
| 569 | // Check that the register allocator is deterministic. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 570 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 571 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 572 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 573 | |
| 574 | ASSERT_EQ(input1->GetLiveInterval()->GetRegister(), 0); |
| 575 | ASSERT_EQ(input2->GetLiveInterval()->GetRegister(), 0); |
| 576 | ASSERT_EQ(phi->GetLiveInterval()->GetRegister(), 0); |
| 577 | } |
| 578 | |
| 579 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 580 | HGraph* graph = BuildIfElseWithPhi(&phi, &input1, &input2); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 581 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 582 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 583 | liveness.Analyze(); |
| 584 | |
| 585 | // Set the phi to a specific register, and check that the inputs get allocated |
| 586 | // the same register. |
| Nicolas Geoffray | 18c219b | 2015-02-04 09:38:49 +0000 | [diff] [blame] | 587 | phi->GetLocations()->UpdateOut(Location::RegisterLocation(2)); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 588 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 589 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 590 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 591 | |
| 592 | ASSERT_EQ(input1->GetLiveInterval()->GetRegister(), 2); |
| 593 | ASSERT_EQ(input2->GetLiveInterval()->GetRegister(), 2); |
| 594 | ASSERT_EQ(phi->GetLiveInterval()->GetRegister(), 2); |
| 595 | } |
| 596 | |
| 597 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 598 | HGraph* graph = BuildIfElseWithPhi(&phi, &input1, &input2); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 599 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 600 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 601 | liveness.Analyze(); |
| 602 | |
| 603 | // Set input1 to a specific register, and check that the phi and other input get allocated |
| 604 | // the same register. |
| Nicolas Geoffray | 18c219b | 2015-02-04 09:38:49 +0000 | [diff] [blame] | 605 | input1->GetLocations()->UpdateOut(Location::RegisterLocation(2)); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 606 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 607 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 608 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 609 | |
| 610 | ASSERT_EQ(input1->GetLiveInterval()->GetRegister(), 2); |
| 611 | ASSERT_EQ(input2->GetLiveInterval()->GetRegister(), 2); |
| 612 | ASSERT_EQ(phi->GetLiveInterval()->GetRegister(), 2); |
| 613 | } |
| 614 | |
| 615 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 616 | HGraph* graph = BuildIfElseWithPhi(&phi, &input1, &input2); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 617 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 618 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 619 | liveness.Analyze(); |
| 620 | |
| 621 | // Set input2 to a specific register, and check that the phi and other input get allocated |
| 622 | // the same register. |
| Nicolas Geoffray | 18c219b | 2015-02-04 09:38:49 +0000 | [diff] [blame] | 623 | input2->GetLocations()->UpdateOut(Location::RegisterLocation(2)); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 624 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 625 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 626 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 627 | |
| 628 | ASSERT_EQ(input1->GetLiveInterval()->GetRegister(), 2); |
| 629 | ASSERT_EQ(input2->GetLiveInterval()->GetRegister(), 2); |
| 630 | ASSERT_EQ(phi->GetLiveInterval()->GetRegister(), 2); |
| 631 | } |
| 632 | } |
| 633 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 634 | // TODO: Enable this test for graph coloring register allocation when iterative move |
| 635 | // coalescing is merged. |
| 636 | TEST_F(RegisterAllocatorTest, PhiHint_LinearScan) { |
| 637 | PhiHint(Strategy::kRegisterAllocatorLinearScan); |
| 638 | } |
| 639 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 640 | HGraph* RegisterAllocatorTest::BuildFieldReturn(HInstruction** field, HInstruction** ret) { |
| 641 | HGraph* graph = CreateGraph(); |
| 642 | HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 643 | graph->AddBlock(entry); |
| 644 | graph->SetEntryBlock(entry); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 645 | HInstruction* parameter = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 646 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kReference); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 647 | entry->AddInstruction(parameter); |
| 648 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 649 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 650 | graph->AddBlock(block); |
| 651 | entry->AddSuccessor(block); |
| 652 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 653 | *field = new (GetAllocator()) HInstanceFieldGet(parameter, |
| 654 | nullptr, |
| 655 | DataType::Type::kInt32, |
| 656 | MemberOffset(42), |
| 657 | false, |
| 658 | kUnknownFieldIndex, |
| 659 | kUnknownClassDefIndex, |
| 660 | graph->GetDexFile(), |
| 661 | 0); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 662 | block->AddInstruction(*field); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 663 | *ret = new (GetAllocator()) HReturn(*field); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 664 | block->AddInstruction(*ret); |
| 665 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 666 | HBasicBlock* exit = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 667 | graph->AddBlock(exit); |
| 668 | block->AddSuccessor(exit); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 669 | exit->AddInstruction(new (GetAllocator()) HExit()); |
| David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 670 | |
| 671 | graph->BuildDominatorTree(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 672 | return graph; |
| 673 | } |
| 674 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 675 | void RegisterAllocatorTest::ExpectedInRegisterHint(Strategy strategy) { |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 676 | HInstruction *field, *ret; |
| 677 | |
| 678 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 679 | HGraph* graph = BuildFieldReturn(&field, &ret); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 680 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 681 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 682 | liveness.Analyze(); |
| 683 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 684 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 685 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 686 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 687 | |
| 688 | // Sanity check that in normal conditions, the register should be hinted to 0 (EAX). |
| 689 | ASSERT_EQ(field->GetLiveInterval()->GetRegister(), 0); |
| 690 | } |
| 691 | |
| 692 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 693 | HGraph* graph = BuildFieldReturn(&field, &ret); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 694 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 695 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 696 | liveness.Analyze(); |
| 697 | |
| 698 | // Check that the field gets put in the register expected by its use. |
| Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 699 | // Don't use SetInAt because we are overriding an already allocated location. |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 700 | ret->GetLocations()->inputs_[0] = Location::RegisterLocation(2); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 701 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 702 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 703 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 704 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 705 | |
| 706 | ASSERT_EQ(field->GetLiveInterval()->GetRegister(), 2); |
| 707 | } |
| 708 | } |
| 709 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 710 | // TODO: Enable this test for graph coloring register allocation when iterative move |
| 711 | // coalescing is merged. |
| 712 | TEST_F(RegisterAllocatorTest, ExpectedInRegisterHint_LinearScan) { |
| 713 | ExpectedInRegisterHint(Strategy::kRegisterAllocatorLinearScan); |
| 714 | } |
| 715 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 716 | HGraph* RegisterAllocatorTest::BuildTwoSubs(HInstruction** first_sub, HInstruction** second_sub) { |
| 717 | HGraph* graph = CreateGraph(); |
| 718 | HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 719 | graph->AddBlock(entry); |
| 720 | graph->SetEntryBlock(entry); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 721 | HInstruction* parameter = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 722 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 723 | entry->AddInstruction(parameter); |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 724 | |
| 725 | HInstruction* constant1 = graph->GetIntConstant(1); |
| 726 | HInstruction* constant2 = graph->GetIntConstant(2); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 727 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 728 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 729 | graph->AddBlock(block); |
| 730 | entry->AddSuccessor(block); |
| 731 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 732 | *first_sub = new (GetAllocator()) HSub(DataType::Type::kInt32, parameter, constant1); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 733 | block->AddInstruction(*first_sub); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 734 | *second_sub = new (GetAllocator()) HSub(DataType::Type::kInt32, *first_sub, constant2); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 735 | block->AddInstruction(*second_sub); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 736 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 737 | block->AddInstruction(new (GetAllocator()) HExit()); |
| David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 738 | |
| 739 | graph->BuildDominatorTree(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 740 | return graph; |
| 741 | } |
| 742 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 743 | void RegisterAllocatorTest::SameAsFirstInputHint(Strategy strategy) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 744 | HInstruction *first_sub, *second_sub; |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 745 | |
| 746 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 747 | HGraph* graph = BuildTwoSubs(&first_sub, &second_sub); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 748 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 749 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 750 | liveness.Analyze(); |
| 751 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 752 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 753 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 754 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 755 | |
| 756 | // Sanity check that in normal conditions, the registers are the same. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 757 | ASSERT_EQ(first_sub->GetLiveInterval()->GetRegister(), 1); |
| 758 | ASSERT_EQ(second_sub->GetLiveInterval()->GetRegister(), 1); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 762 | HGraph* graph = BuildTwoSubs(&first_sub, &second_sub); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 763 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 764 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 765 | liveness.Analyze(); |
| 766 | |
| 767 | // check that both adds get the same register. |
| Nicolas Geoffray | 18c219b | 2015-02-04 09:38:49 +0000 | [diff] [blame] | 768 | // Don't use UpdateOutput because output is already allocated. |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 769 | first_sub->InputAt(0)->GetLocations()->output_ = Location::RegisterLocation(2); |
| 770 | ASSERT_EQ(first_sub->GetLocations()->Out().GetPolicy(), Location::kSameAsFirstInput); |
| 771 | ASSERT_EQ(second_sub->GetLocations()->Out().GetPolicy(), Location::kSameAsFirstInput); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 772 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 773 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 774 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Matthew Gharrity | 8f49d4b | 2016-07-14 13:24:00 -0700 | [diff] [blame] | 775 | register_allocator->AllocateRegisters(); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 776 | |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 777 | ASSERT_EQ(first_sub->GetLiveInterval()->GetRegister(), 2); |
| 778 | ASSERT_EQ(second_sub->GetLiveInterval()->GetRegister(), 2); |
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 782 | // TODO: Enable this test for graph coloring register allocation when iterative move |
| 783 | // coalescing is merged. |
| 784 | TEST_F(RegisterAllocatorTest, SameAsFirstInputHint_LinearScan) { |
| 785 | SameAsFirstInputHint(Strategy::kRegisterAllocatorLinearScan); |
| 786 | } |
| 787 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 788 | HGraph* RegisterAllocatorTest::BuildDiv(HInstruction** div) { |
| 789 | HGraph* graph = CreateGraph(); |
| 790 | HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 791 | graph->AddBlock(entry); |
| 792 | graph->SetEntryBlock(entry); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 793 | HInstruction* first = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 794 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 795 | HInstruction* second = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 796 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 797 | entry->AddInstruction(first); |
| 798 | entry->AddInstruction(second); |
| 799 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 800 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 801 | graph->AddBlock(block); |
| 802 | entry->AddSuccessor(block); |
| 803 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 804 | *div = new (GetAllocator()) HDiv( |
| 805 | DataType::Type::kInt32, first, second, 0); // don't care about dex_pc. |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 806 | block->AddInstruction(*div); |
| 807 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 808 | block->AddInstruction(new (GetAllocator()) HExit()); |
| David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 809 | |
| 810 | graph->BuildDominatorTree(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 811 | return graph; |
| 812 | } |
| 813 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 814 | void RegisterAllocatorTest::ExpectedExactInRegisterAndSameOutputHint(Strategy strategy) { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 815 | HInstruction *div; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 816 | HGraph* graph = BuildDiv(&div); |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 817 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 818 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 819 | liveness.Analyze(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 820 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 821 | std::unique_ptr<RegisterAllocator> register_allocator = |
| 822 | RegisterAllocator::Create(GetScopedAllocator(), &codegen, liveness, strategy); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 823 | register_allocator->AllocateRegisters(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 824 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 825 | // div on x86 requires its first input in eax and the output be the same as the first input. |
| 826 | ASSERT_EQ(div->GetLiveInterval()->GetRegister(), 0); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 829 | // TODO: Enable this test for graph coloring register allocation when iterative move |
| 830 | // coalescing is merged. |
| 831 | TEST_F(RegisterAllocatorTest, ExpectedExactInRegisterAndSameOutputHint_LinearScan) { |
| 832 | ExpectedExactInRegisterAndSameOutputHint(Strategy::kRegisterAllocatorLinearScan); |
| 833 | } |
| 834 | |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 835 | // Test a bug in the register allocator, where allocating a blocked |
| 836 | // register would lead to spilling an inactive interval at the wrong |
| 837 | // position. |
| Matthew Gharrity | d9ffd0d | 2016-06-22 10:27:55 -0700 | [diff] [blame] | 838 | // This test only applies to the linear scan allocator. |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 839 | TEST_F(RegisterAllocatorTest, SpillInactive) { |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 840 | // Create a synthesized graph to please the register_allocator and |
| 841 | // ssa_liveness_analysis code. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 842 | HGraph* graph = CreateGraph(); |
| 843 | HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 844 | graph->AddBlock(entry); |
| 845 | graph->SetEntryBlock(entry); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 846 | HInstruction* one = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 847 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 848 | HInstruction* two = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 849 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 850 | HInstruction* three = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 851 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 852 | HInstruction* four = new (GetAllocator()) HParameterValue( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 853 | graph->GetDexFile(), dex::TypeIndex(0), 0, DataType::Type::kInt32); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 854 | entry->AddInstruction(one); |
| 855 | entry->AddInstruction(two); |
| 856 | entry->AddInstruction(three); |
| 857 | entry->AddInstruction(four); |
| 858 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 859 | HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 860 | graph->AddBlock(block); |
| 861 | entry->AddSuccessor(block); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 862 | block->AddInstruction(new (GetAllocator()) HExit()); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 863 | |
| 864 | // We create a synthesized user requesting a register, to avoid just spilling the |
| 865 | // intervals. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 866 | HPhi* user = new (GetAllocator()) HPhi(GetAllocator(), 0, 1, DataType::Type::kInt32); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 867 | user->AddInput(one); |
| 868 | user->SetBlock(block); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 869 | LocationSummary* locations = new (GetAllocator()) LocationSummary(user, LocationSummary::kNoCall); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 871 | static constexpr size_t phi_ranges[][2] = {{20, 30}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 872 | BuildInterval(phi_ranges, arraysize(phi_ranges), GetScopedAllocator(), -1, user); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 873 | |
| 874 | // Create an interval with lifetime holes. |
| 875 | static constexpr size_t ranges1[][2] = {{0, 2}, {4, 6}, {8, 10}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 876 | LiveInterval* first = BuildInterval(ranges1, arraysize(ranges1), GetScopedAllocator(), -1, one); |
| Andreas Gampe | 654698d | 2018-09-20 13:34:35 -0700 | [diff] [blame] | 877 | first->uses_.push_front(*new (GetScopedAllocator()) UsePosition(user, 0u, 8)); |
| 878 | first->uses_.push_front(*new (GetScopedAllocator()) UsePosition(user, 0u, 7)); |
| 879 | first->uses_.push_front(*new (GetScopedAllocator()) UsePosition(user, 0u, 6)); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 880 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 881 | locations = new (GetAllocator()) LocationSummary(first->GetDefinedBy(), LocationSummary::kNoCall); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 882 | locations->SetOut(Location::RequiresRegister()); |
| 883 | first = first->SplitAt(1); |
| 884 | |
| 885 | // Create an interval that conflicts with the next interval, to force the next |
| 886 | // interval to call `AllocateBlockedReg`. |
| 887 | static constexpr size_t ranges2[][2] = {{2, 4}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 888 | LiveInterval* second = BuildInterval(ranges2, arraysize(ranges2), GetScopedAllocator(), -1, two); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 889 | locations = |
| 890 | new (GetAllocator()) LocationSummary(second->GetDefinedBy(), LocationSummary::kNoCall); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 891 | locations->SetOut(Location::RequiresRegister()); |
| 892 | |
| 893 | // Create an interval that will lead to splitting the first interval. The bug occured |
| 894 | // by splitting at a wrong position, in this case at the next intersection between |
| 895 | // this interval and the first interval. We would have then put the interval with ranges |
| 896 | // "[0, 2(, [4, 6(" in the list of handled intervals, even though we haven't processed intervals |
| 897 | // before lifetime position 6 yet. |
| 898 | static constexpr size_t ranges3[][2] = {{2, 4}, {8, 10}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 899 | LiveInterval* third = BuildInterval(ranges3, arraysize(ranges3), GetScopedAllocator(), -1, three); |
| Andreas Gampe | 654698d | 2018-09-20 13:34:35 -0700 | [diff] [blame] | 900 | third->uses_.push_front(*new (GetScopedAllocator()) UsePosition(user, 0u, 8)); |
| 901 | third->uses_.push_front(*new (GetScopedAllocator()) UsePosition(user, 0u, 4)); |
| 902 | third->uses_.push_front(*new (GetScopedAllocator()) UsePosition(user, 0u, 3)); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 903 | locations = new (GetAllocator()) LocationSummary(third->GetDefinedBy(), LocationSummary::kNoCall); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 904 | locations->SetOut(Location::RequiresRegister()); |
| 905 | third = third->SplitAt(3); |
| 906 | |
| 907 | // Because the first part of the split interval was considered handled, this interval |
| 908 | // was free to allocate the same register, even though it conflicts with it. |
| 909 | static constexpr size_t ranges4[][2] = {{4, 6}}; |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 910 | LiveInterval* fourth = BuildInterval(ranges4, arraysize(ranges4), GetScopedAllocator(), -1, four); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 911 | locations = |
| 912 | new (GetAllocator()) LocationSummary(fourth->GetDefinedBy(), LocationSummary::kNoCall); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 913 | locations->SetOut(Location::RequiresRegister()); |
| 914 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 915 | x86::CodeGeneratorX86 codegen(graph, *compiler_options_); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 916 | SsaLivenessAnalysis liveness(graph, &codegen, GetScopedAllocator()); |
| Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 917 | // Populate the instructions in the liveness object, to please the register allocator. |
| 918 | for (size_t i = 0; i < 32; ++i) { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 919 | liveness.instructions_from_lifetime_position_.push_back(user); |
| Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 920 | } |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 921 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 922 | RegisterAllocatorLinearScan register_allocator(GetScopedAllocator(), &codegen, liveness); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 923 | register_allocator.unhandled_core_intervals_.push_back(fourth); |
| 924 | register_allocator.unhandled_core_intervals_.push_back(third); |
| 925 | register_allocator.unhandled_core_intervals_.push_back(second); |
| 926 | register_allocator.unhandled_core_intervals_.push_back(first); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 927 | |
| 928 | // Set just one register available to make all intervals compete for the same. |
| 929 | register_allocator.number_of_registers_ = 1; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 930 | register_allocator.registers_array_ = GetAllocator()->AllocArray<size_t>(1); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 931 | register_allocator.processing_core_registers_ = true; |
| 932 | register_allocator.unhandled_ = ®ister_allocator.unhandled_core_intervals_; |
| 933 | register_allocator.LinearScan(); |
| 934 | |
| 935 | // Test that there is no conflicts between intervals. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 936 | ScopedArenaVector<LiveInterval*> intervals(GetScopedAllocator()->Adapter()); |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 937 | intervals.push_back(first); |
| 938 | intervals.push_back(second); |
| 939 | intervals.push_back(third); |
| 940 | intervals.push_back(fourth); |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 941 | ASSERT_TRUE(ValidateIntervals(intervals, codegen)); |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 944 | } // namespace art |