blob: d48b1a0bb93ed5b5a2cbb7717105a31b70048e7b [file] [log] [blame]
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_
18#define ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_
19
20#include "base/arena_containers.h"
David Brazdild9c90372016-09-14 16:53:55 +010021#include "base/array_ref.h"
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070022#include "base/value_object.h"
23#include "primitive.h"
24
25namespace art {
26
27class ArenaAllocator;
28class CodeGenerator;
29class HBasicBlock;
30class HInstruction;
31class HParallelMove;
32class LiveInterval;
33class Location;
34class SsaLivenessAnalysis;
35
36/**
37 * Reconciles the locations assigned to live intervals with the location
38 * summary of each instruction, and inserts moves to resolve split intervals,
39 * nonlinear control flow, and phi inputs.
40 */
41class RegisterAllocationResolver : ValueObject {
42 public:
43 RegisterAllocationResolver(ArenaAllocator* allocator,
44 CodeGenerator* codegen,
45 const SsaLivenessAnalysis& liveness);
46
Vladimir Marko70e97462016-08-09 11:04:26 +010047 void Resolve(ArrayRef<HInstruction* const> safepoints,
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070048 size_t reserved_out_slots, // Includes slot(s) for the art method.
49 size_t int_spill_slots,
50 size_t long_spill_slots,
51 size_t float_spill_slots,
52 size_t double_spill_slots,
53 size_t catch_phi_spill_slots,
Matthew Gharrity0b110f42016-07-20 10:13:45 -070054 const ArenaVector<LiveInterval*>& temp_intervals);
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070055
56 private:
Vladimir Marko70e97462016-08-09 11:04:26 +010057 // Update live registers of safepoint location summary.
58 void UpdateSafepointLiveRegisters();
59
60 // Calculate the maximum size of the spill area for safepoints.
61 size_t CalculateMaximumSafepointSpillSize(ArrayRef<HInstruction* const> safepoints);
62
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070063 // Connect adjacent siblings within blocks, and resolve inputs along the way.
Vladimir Marko70e97462016-08-09 11:04:26 +010064 void ConnectSiblings(LiveInterval* interval);
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070065
66 // Connect siblings between block entries and exits.
67 void ConnectSplitSiblings(LiveInterval* interval, HBasicBlock* from, HBasicBlock* to) const;
68
69 // Helper methods for inserting parallel moves in the graph.
70 void InsertParallelMoveAtExitOf(HBasicBlock* block,
71 HInstruction* instruction,
72 Location source,
73 Location destination) const;
74 void InsertParallelMoveAtEntryOf(HBasicBlock* block,
75 HInstruction* instruction,
76 Location source,
77 Location destination) const;
78 void InsertMoveAfter(HInstruction* instruction, Location source, Location destination) const;
79 void AddInputMoveFor(HInstruction* input,
80 HInstruction* user,
81 Location source,
82 Location destination) const;
83 void InsertParallelMoveAt(size_t position,
84 HInstruction* instruction,
85 Location source,
86 Location destination) const;
87 void AddMove(HParallelMove* move,
88 Location source,
89 Location destination,
90 HInstruction* instruction,
91 Primitive::Type type) const;
92
93 ArenaAllocator* const allocator_;
94 CodeGenerator* const codegen_;
95 const SsaLivenessAnalysis& liveness_;
96
97 DISALLOW_COPY_AND_ASSIGN(RegisterAllocationResolver);
98};
99
100} // namespace art
101
102#endif // ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_