blob: f652db10957e74c2775159d6b887298805609f40 [file] [log] [blame]
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001/*
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
23namespace art {
24
25class HParallelMove;
26class MoveOperands;
27
28/**
29 * Helper class to resolve a set of parallel moves. Architecture dependent code
30 * generator must have their own subclass that implements the `EmitMove` and `EmitSwap`
31 * operations.
32 */
33class ParallelMoveResolver : public ValueObject {
34 public:
35 explicit ParallelMoveResolver(ArenaAllocator* allocator) : moves_(allocator, 32) {}
36
37 // Resolve a set of parallel moves, emitting assembler instructions.
38 void EmitNativeCode(HParallelMove* parallel_move);
39
40 protected:
41 // Emit a move.
42 virtual void EmitMove(size_t index) = 0;
43
44 // Execute a move by emitting a swap of two operands.
45 virtual void EmitSwap(size_t index) = 0;
46
47 // List of moves not yet resolved.
48 GrowableArray<MoveOperands*> moves_;
49
50 private:
51 // Build the initial list of moves.
52 void BuildInitialMoveList(HParallelMove* parallel_move);
53
54 // Perform the move at the moves_ index in question (possibly requiring
55 // other moves to satisfy dependencies).
56 void PerformMove(size_t index);
57
58 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolver);
59};
60
61} // namespace art
62
63#endif // ART_COMPILER_OPTIMIZING_PARALLEL_MOVE_RESOLVER_H_