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 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_PARALLEL_MOVE_RESOLVER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_PARALLEL_MOVE_RESOLVER_H_ |
| 19 | |
| 20 | #include "utils/allocation.h" |
| 21 | #include "utils/growable_array.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class HParallelMove; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 26 | class Location; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 27 | class MoveOperands; |
| 28 | |
| 29 | /** |
| 30 | * Helper class to resolve a set of parallel moves. Architecture dependent code |
| 31 | * generator must have their own subclass that implements the `EmitMove` and `EmitSwap` |
| 32 | * operations. |
| 33 | */ |
| 34 | class ParallelMoveResolver : public ValueObject { |
| 35 | public: |
| 36 | explicit ParallelMoveResolver(ArenaAllocator* allocator) : moves_(allocator, 32) {} |
Nicolas Geoffray | aa037b5 | 2014-05-23 10:40:42 +0100 | [diff] [blame] | 37 | virtual ~ParallelMoveResolver() {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 38 | |
| 39 | // Resolve a set of parallel moves, emitting assembler instructions. |
| 40 | void EmitNativeCode(HParallelMove* parallel_move); |
| 41 | |
| 42 | protected: |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 43 | class ScratchRegisterScope : public ValueObject { |
| 44 | public: |
| 45 | ScratchRegisterScope(ParallelMoveResolver* resolver, int blocked, int number_of_registers); |
| 46 | ~ScratchRegisterScope(); |
| 47 | |
| 48 | int GetRegister() const { return reg_; } |
| 49 | bool IsSpilled() const { return spilled_; } |
| 50 | |
| 51 | private: |
| 52 | ParallelMoveResolver* resolver_; |
| 53 | int reg_; |
| 54 | bool spilled_; |
| 55 | }; |
| 56 | |
| 57 | bool IsScratchLocation(Location loc); |
| 58 | int AllocateScratchRegister(int blocked, int register_count, bool* spilled); |
| 59 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 60 | // Emit a move. |
| 61 | virtual void EmitMove(size_t index) = 0; |
| 62 | |
| 63 | // Execute a move by emitting a swap of two operands. |
| 64 | virtual void EmitSwap(size_t index) = 0; |
| 65 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 66 | virtual void SpillScratch(int reg) = 0; |
| 67 | virtual void RestoreScratch(int reg) = 0; |
| 68 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 69 | // List of moves not yet resolved. |
| 70 | GrowableArray<MoveOperands*> moves_; |
| 71 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 72 | static constexpr int kNoRegister = -1; |
| 73 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 74 | private: |
| 75 | // Build the initial list of moves. |
| 76 | void BuildInitialMoveList(HParallelMove* parallel_move); |
| 77 | |
| 78 | // Perform the move at the moves_ index in question (possibly requiring |
| 79 | // other moves to satisfy dependencies). |
| 80 | void PerformMove(size_t index); |
| 81 | |
| 82 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolver); |
| 83 | }; |
| 84 | |
| 85 | } // namespace art |
| 86 | |
| 87 | #endif // ART_COMPILER_OPTIMIZING_PARALLEL_MOVE_RESOLVER_H_ |