Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +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 | |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 17 | #include "base/arena_allocator.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 18 | #include "nodes.h" |
| 19 | #include "parallel_move_resolver.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 20 | |
| 21 | #include "gtest/gtest.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class TestParallelMoveResolver : public ParallelMoveResolver { |
| 26 | public: |
| 27 | explicit TestParallelMoveResolver(ArenaAllocator* allocator) : ParallelMoveResolver(allocator) {} |
| 28 | |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 29 | void Dump(Location location) { |
| 30 | if (location.IsConstant()) { |
| 31 | message_ << "C"; |
| 32 | } else if (location.IsPair()) { |
| 33 | message_ << location.low() << "," << location.high(); |
Nicolas Geoffray | a2d15b5 | 2015-03-31 18:13:51 +0100 | [diff] [blame] | 34 | } else if (location.IsRegister()) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 35 | message_ << location.reg(); |
Nicolas Geoffray | a2d15b5 | 2015-03-31 18:13:51 +0100 | [diff] [blame] | 36 | } else if (location.IsStackSlot()) { |
| 37 | message_ << location.GetStackIndex() << "(sp)"; |
| 38 | } else { |
| 39 | message_ << "2x" << location.GetStackIndex() << "(sp)"; |
| 40 | DCHECK(location.IsDoubleStackSlot()) << location; |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 44 | void EmitMove(size_t index) OVERRIDE { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 45 | MoveOperands* move = moves_.Get(index); |
| 46 | if (!message_.str().empty()) { |
| 47 | message_ << " "; |
| 48 | } |
Nicolas Geoffray | 48c310c | 2015-01-14 10:45:05 +0000 | [diff] [blame] | 49 | message_ << "("; |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 50 | Dump(move->GetSource()); |
| 51 | message_ << " -> "; |
| 52 | Dump(move->GetDestination()); |
| 53 | message_ << ")"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 56 | void EmitSwap(size_t index) OVERRIDE { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 57 | MoveOperands* move = moves_.Get(index); |
| 58 | if (!message_.str().empty()) { |
| 59 | message_ << " "; |
| 60 | } |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 61 | message_ << "("; |
| 62 | Dump(move->GetSource()); |
| 63 | message_ << " <-> "; |
| 64 | Dump(move->GetDestination()); |
| 65 | message_ << ")"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 68 | void SpillScratch(int reg ATTRIBUTE_UNUSED) OVERRIDE {} |
| 69 | void RestoreScratch(int reg ATTRIBUTE_UNUSED) OVERRIDE {} |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 70 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 71 | std::string GetMessage() const { |
| 72 | return message_.str(); |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | std::ostringstream message_; |
| 77 | |
| 78 | |
| 79 | DISALLOW_COPY_AND_ASSIGN(TestParallelMoveResolver); |
| 80 | }; |
| 81 | |
| 82 | static HParallelMove* BuildParallelMove(ArenaAllocator* allocator, |
| 83 | const size_t operands[][2], |
| 84 | size_t number_of_moves) { |
| 85 | HParallelMove* moves = new (allocator) HParallelMove(allocator); |
| 86 | for (size_t i = 0; i < number_of_moves; ++i) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 87 | moves->AddMove( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 88 | Location::RegisterLocation(operands[i][0]), |
| 89 | Location::RegisterLocation(operands[i][1]), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 90 | Primitive::kPrimInt, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 91 | nullptr); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 92 | } |
| 93 | return moves; |
| 94 | } |
| 95 | |
| 96 | TEST(ParallelMoveTest, Dependency) { |
| 97 | ArenaPool pool; |
| 98 | ArenaAllocator allocator(&pool); |
| 99 | |
| 100 | { |
| 101 | TestParallelMoveResolver resolver(&allocator); |
| 102 | static constexpr size_t moves[][2] = {{0, 1}, {1, 2}}; |
| 103 | resolver.EmitNativeCode(BuildParallelMove(&allocator, moves, arraysize(moves))); |
| 104 | ASSERT_STREQ("(1 -> 2) (0 -> 1)", resolver.GetMessage().c_str()); |
| 105 | } |
| 106 | |
| 107 | { |
| 108 | TestParallelMoveResolver resolver(&allocator); |
| 109 | static constexpr size_t moves[][2] = {{0, 1}, {1, 2}, {2, 3}, {1, 4}}; |
| 110 | resolver.EmitNativeCode(BuildParallelMove(&allocator, moves, arraysize(moves))); |
| 111 | ASSERT_STREQ("(2 -> 3) (1 -> 2) (1 -> 4) (0 -> 1)", resolver.GetMessage().c_str()); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | TEST(ParallelMoveTest, Swap) { |
| 116 | ArenaPool pool; |
| 117 | ArenaAllocator allocator(&pool); |
| 118 | |
| 119 | { |
| 120 | TestParallelMoveResolver resolver(&allocator); |
| 121 | static constexpr size_t moves[][2] = {{0, 1}, {1, 0}}; |
| 122 | resolver.EmitNativeCode(BuildParallelMove(&allocator, moves, arraysize(moves))); |
| 123 | ASSERT_STREQ("(1 <-> 0)", resolver.GetMessage().c_str()); |
| 124 | } |
| 125 | |
| 126 | { |
| 127 | TestParallelMoveResolver resolver(&allocator); |
| 128 | static constexpr size_t moves[][2] = {{0, 1}, {1, 2}, {1, 0}}; |
| 129 | resolver.EmitNativeCode(BuildParallelMove(&allocator, moves, arraysize(moves))); |
| 130 | ASSERT_STREQ("(1 -> 2) (1 <-> 0)", resolver.GetMessage().c_str()); |
| 131 | } |
| 132 | |
| 133 | { |
| 134 | TestParallelMoveResolver resolver(&allocator); |
Nicolas Geoffray | 6450d14 | 2015-01-16 09:04:49 +0000 | [diff] [blame] | 135 | static constexpr size_t moves[][2] = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0}}; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 136 | resolver.EmitNativeCode(BuildParallelMove(&allocator, moves, arraysize(moves))); |
Nicolas Geoffray | 6450d14 | 2015-01-16 09:04:49 +0000 | [diff] [blame] | 137 | ASSERT_STREQ("(4 <-> 0) (3 <-> 4) (2 <-> 3) (1 <-> 2)", resolver.GetMessage().c_str()); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Nicolas Geoffray | 48c310c | 2015-01-14 10:45:05 +0000 | [diff] [blame] | 141 | TEST(ParallelMoveTest, ConstantLast) { |
| 142 | ArenaPool pool; |
| 143 | ArenaAllocator allocator(&pool); |
| 144 | TestParallelMoveResolver resolver(&allocator); |
| 145 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 146 | moves->AddMove( |
Nicolas Geoffray | 48c310c | 2015-01-14 10:45:05 +0000 | [diff] [blame] | 147 | Location::ConstantLocation(new (&allocator) HIntConstant(0)), |
| 148 | Location::RegisterLocation(0), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 149 | Primitive::kPrimInt, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 150 | nullptr); |
| 151 | moves->AddMove( |
Nicolas Geoffray | 48c310c | 2015-01-14 10:45:05 +0000 | [diff] [blame] | 152 | Location::RegisterLocation(1), |
| 153 | Location::RegisterLocation(2), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 154 | Primitive::kPrimInt, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 155 | nullptr); |
Nicolas Geoffray | 48c310c | 2015-01-14 10:45:05 +0000 | [diff] [blame] | 156 | resolver.EmitNativeCode(moves); |
| 157 | ASSERT_STREQ("(1 -> 2) (C -> 0)", resolver.GetMessage().c_str()); |
| 158 | } |
| 159 | |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 160 | TEST(ParallelMoveTest, Pairs) { |
| 161 | ArenaPool pool; |
| 162 | ArenaAllocator allocator(&pool); |
| 163 | |
| 164 | { |
| 165 | TestParallelMoveResolver resolver(&allocator); |
| 166 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 167 | moves->AddMove( |
| 168 | Location::RegisterLocation(2), |
| 169 | Location::RegisterLocation(4), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 170 | Primitive::kPrimInt, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 171 | nullptr); |
| 172 | moves->AddMove( |
| 173 | Location::RegisterPairLocation(0, 1), |
| 174 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 175 | Primitive::kPrimLong, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 176 | nullptr); |
| 177 | resolver.EmitNativeCode(moves); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 178 | ASSERT_STREQ("(2 -> 4) (0,1 -> 2,3)", resolver.GetMessage().c_str()); |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | { |
| 182 | TestParallelMoveResolver resolver(&allocator); |
| 183 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 184 | moves->AddMove( |
| 185 | Location::RegisterPairLocation(0, 1), |
| 186 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 187 | Primitive::kPrimLong, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 188 | nullptr); |
| 189 | moves->AddMove( |
| 190 | Location::RegisterLocation(2), |
| 191 | Location::RegisterLocation(4), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 192 | Primitive::kPrimInt, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 193 | nullptr); |
| 194 | resolver.EmitNativeCode(moves); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 195 | ASSERT_STREQ("(2 -> 4) (0,1 -> 2,3)", resolver.GetMessage().c_str()); |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | { |
| 199 | TestParallelMoveResolver resolver(&allocator); |
| 200 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 201 | moves->AddMove( |
| 202 | Location::RegisterPairLocation(0, 1), |
| 203 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 204 | Primitive::kPrimLong, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 205 | nullptr); |
| 206 | moves->AddMove( |
| 207 | Location::RegisterLocation(2), |
| 208 | Location::RegisterLocation(0), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 209 | Primitive::kPrimInt, |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 210 | nullptr); |
| 211 | resolver.EmitNativeCode(moves); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 212 | ASSERT_STREQ("(0,1 <-> 2,3)", resolver.GetMessage().c_str()); |
| 213 | } |
| 214 | { |
| 215 | TestParallelMoveResolver resolver(&allocator); |
| 216 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 217 | moves->AddMove( |
| 218 | Location::RegisterLocation(2), |
| 219 | Location::RegisterLocation(7), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 220 | Primitive::kPrimInt, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 221 | nullptr); |
| 222 | moves->AddMove( |
| 223 | Location::RegisterLocation(7), |
| 224 | Location::RegisterLocation(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 225 | Primitive::kPrimInt, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 226 | nullptr); |
| 227 | moves->AddMove( |
| 228 | Location::RegisterPairLocation(0, 1), |
| 229 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 230 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 231 | nullptr); |
| 232 | resolver.EmitNativeCode(moves); |
| 233 | ASSERT_STREQ("(0,1 <-> 2,3) (7 -> 1) (0 -> 7)", resolver.GetMessage().c_str()); |
| 234 | } |
| 235 | { |
| 236 | TestParallelMoveResolver resolver(&allocator); |
| 237 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 238 | moves->AddMove( |
| 239 | Location::RegisterLocation(2), |
| 240 | Location::RegisterLocation(7), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 241 | Primitive::kPrimInt, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 242 | nullptr); |
| 243 | moves->AddMove( |
| 244 | Location::RegisterPairLocation(0, 1), |
| 245 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 246 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 247 | nullptr); |
| 248 | moves->AddMove( |
| 249 | Location::RegisterLocation(7), |
| 250 | Location::RegisterLocation(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 251 | Primitive::kPrimInt, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 252 | nullptr); |
| 253 | resolver.EmitNativeCode(moves); |
| 254 | ASSERT_STREQ("(0,1 <-> 2,3) (7 -> 1) (0 -> 7)", resolver.GetMessage().c_str()); |
| 255 | } |
| 256 | { |
| 257 | TestParallelMoveResolver resolver(&allocator); |
| 258 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 259 | moves->AddMove( |
| 260 | Location::RegisterPairLocation(0, 1), |
| 261 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 262 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 263 | nullptr); |
| 264 | moves->AddMove( |
| 265 | Location::RegisterLocation(2), |
| 266 | Location::RegisterLocation(7), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 267 | Primitive::kPrimInt, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 268 | nullptr); |
| 269 | moves->AddMove( |
| 270 | Location::RegisterLocation(7), |
| 271 | Location::RegisterLocation(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 272 | Primitive::kPrimInt, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 273 | nullptr); |
| 274 | resolver.EmitNativeCode(moves); |
| 275 | ASSERT_STREQ("(0,1 <-> 2,3) (7 -> 1) (0 -> 7)", resolver.GetMessage().c_str()); |
| 276 | } |
| 277 | { |
| 278 | TestParallelMoveResolver resolver(&allocator); |
| 279 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 280 | moves->AddMove( |
| 281 | Location::RegisterPairLocation(0, 1), |
| 282 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 283 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 284 | nullptr); |
| 285 | moves->AddMove( |
| 286 | Location::RegisterPairLocation(2, 3), |
| 287 | Location::RegisterPairLocation(0, 1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 288 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 289 | nullptr); |
| 290 | resolver.EmitNativeCode(moves); |
| 291 | ASSERT_STREQ("(2,3 <-> 0,1)", resolver.GetMessage().c_str()); |
| 292 | } |
| 293 | { |
| 294 | TestParallelMoveResolver resolver(&allocator); |
| 295 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 296 | moves->AddMove( |
| 297 | Location::RegisterPairLocation(2, 3), |
| 298 | Location::RegisterPairLocation(0, 1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 299 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 300 | nullptr); |
| 301 | moves->AddMove( |
| 302 | Location::RegisterPairLocation(0, 1), |
| 303 | Location::RegisterPairLocation(2, 3), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 304 | Primitive::kPrimLong, |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 305 | nullptr); |
| 306 | resolver.EmitNativeCode(moves); |
| 307 | ASSERT_STREQ("(0,1 <-> 2,3)", resolver.GetMessage().c_str()); |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 308 | } |
Nicolas Geoffray | a2d15b5 | 2015-03-31 18:13:51 +0100 | [diff] [blame] | 309 | |
| 310 | { |
| 311 | // Test involving registers used in single context and pair context. |
| 312 | TestParallelMoveResolver resolver(&allocator); |
| 313 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 314 | moves->AddMove( |
| 315 | Location::RegisterLocation(10), |
| 316 | Location::RegisterLocation(5), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 317 | Primitive::kPrimInt, |
Nicolas Geoffray | a2d15b5 | 2015-03-31 18:13:51 +0100 | [diff] [blame] | 318 | nullptr); |
| 319 | moves->AddMove( |
| 320 | Location::RegisterPairLocation(4, 5), |
| 321 | Location::DoubleStackSlot(32), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 322 | Primitive::kPrimLong, |
Nicolas Geoffray | a2d15b5 | 2015-03-31 18:13:51 +0100 | [diff] [blame] | 323 | nullptr); |
| 324 | moves->AddMove( |
| 325 | Location::DoubleStackSlot(32), |
| 326 | Location::RegisterPairLocation(10, 11), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 327 | Primitive::kPrimLong, |
Nicolas Geoffray | a2d15b5 | 2015-03-31 18:13:51 +0100 | [diff] [blame] | 328 | nullptr); |
| 329 | resolver.EmitNativeCode(moves); |
| 330 | ASSERT_STREQ("(2x32(sp) <-> 10,11) (4,5 <-> 2x32(sp)) (4 -> 5)", resolver.GetMessage().c_str()); |
| 331 | } |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 334 | // Test that we do 64bits moves before 32bits moves. |
| 335 | TEST(ParallelMoveTest, CyclesWith64BitsMoves) { |
| 336 | ArenaPool pool; |
| 337 | ArenaAllocator allocator(&pool); |
| 338 | |
| 339 | { |
| 340 | TestParallelMoveResolver resolver(&allocator); |
| 341 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 342 | moves->AddMove( |
| 343 | Location::RegisterLocation(0), |
| 344 | Location::RegisterLocation(1), |
| 345 | Primitive::kPrimLong, |
| 346 | nullptr); |
| 347 | moves->AddMove( |
| 348 | Location::RegisterLocation(1), |
| 349 | Location::StackSlot(48), |
| 350 | Primitive::kPrimInt, |
| 351 | nullptr); |
| 352 | moves->AddMove( |
| 353 | Location::StackSlot(48), |
| 354 | Location::RegisterLocation(0), |
| 355 | Primitive::kPrimInt, |
| 356 | nullptr); |
| 357 | resolver.EmitNativeCode(moves); |
| 358 | ASSERT_STREQ("(0 <-> 1) (48(sp) <-> 0)", resolver.GetMessage().c_str()); |
| 359 | } |
| 360 | |
| 361 | { |
| 362 | TestParallelMoveResolver resolver(&allocator); |
| 363 | HParallelMove* moves = new (&allocator) HParallelMove(&allocator); |
| 364 | moves->AddMove( |
| 365 | Location::RegisterPairLocation(0, 1), |
| 366 | Location::RegisterPairLocation(2, 3), |
| 367 | Primitive::kPrimLong, |
| 368 | nullptr); |
| 369 | moves->AddMove( |
| 370 | Location::RegisterPairLocation(2, 3), |
| 371 | Location::DoubleStackSlot(32), |
| 372 | Primitive::kPrimLong, |
| 373 | nullptr); |
| 374 | moves->AddMove( |
| 375 | Location::DoubleStackSlot(32), |
| 376 | Location::RegisterPairLocation(0, 1), |
| 377 | Primitive::kPrimLong, |
| 378 | nullptr); |
| 379 | resolver.EmitNativeCode(moves); |
| 380 | ASSERT_STREQ("(2x32(sp) <-> 0,1) (2,3 <-> 2x32(sp))", resolver.GetMessage().c_str()); |
| 381 | } |
| 382 | } |
| 383 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 384 | } // namespace art |