blob: 278371777d2e2bdaa120cd78719b9c0a13ad3d0e [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
David Brazdild9c90372016-09-14 16:53:55 +010020#include "base/array_ref.h"
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070021#include "base/value_object.h"
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010022#include "data_type.h"
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070023
24namespace art {
25
26class ArenaAllocator;
27class CodeGenerator;
28class HBasicBlock;
29class HInstruction;
30class HParallelMove;
31class LiveInterval;
32class Location;
33class SsaLivenessAnalysis;
34
35/**
36 * Reconciles the locations assigned to live intervals with the location
37 * summary of each instruction, and inserts moves to resolve split intervals,
38 * nonlinear control flow, and phi inputs.
39 */
40class RegisterAllocationResolver : ValueObject {
41 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +010042 RegisterAllocationResolver(CodeGenerator* codegen, const SsaLivenessAnalysis& liveness);
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070043
Vladimir Marko70e97462016-08-09 11:04:26 +010044 void Resolve(ArrayRef<HInstruction* const> safepoints,
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070045 size_t reserved_out_slots, // Includes slot(s) for the art method.
46 size_t int_spill_slots,
47 size_t long_spill_slots,
48 size_t float_spill_slots,
49 size_t double_spill_slots,
50 size_t catch_phi_spill_slots,
Vladimir Markoe764d2e2017-10-05 14:35:55 +010051 ArrayRef<LiveInterval* const> temp_intervals);
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070052
53 private:
Vladimir Marko70e97462016-08-09 11:04:26 +010054 // Update live registers of safepoint location summary.
55 void UpdateSafepointLiveRegisters();
56
57 // Calculate the maximum size of the spill area for safepoints.
58 size_t CalculateMaximumSafepointSpillSize(ArrayRef<HInstruction* const> safepoints);
59
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070060 // Connect adjacent siblings within blocks, and resolve inputs along the way.
Vladimir Marko70e97462016-08-09 11:04:26 +010061 void ConnectSiblings(LiveInterval* interval);
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070062
63 // Connect siblings between block entries and exits.
64 void ConnectSplitSiblings(LiveInterval* interval, HBasicBlock* from, HBasicBlock* to) const;
65
66 // Helper methods for inserting parallel moves in the graph.
67 void InsertParallelMoveAtExitOf(HBasicBlock* block,
68 HInstruction* instruction,
69 Location source,
70 Location destination) const;
71 void InsertParallelMoveAtEntryOf(HBasicBlock* block,
72 HInstruction* instruction,
73 Location source,
74 Location destination) const;
75 void InsertMoveAfter(HInstruction* instruction, Location source, Location destination) const;
76 void AddInputMoveFor(HInstruction* input,
77 HInstruction* user,
78 Location source,
79 Location destination) const;
80 void InsertParallelMoveAt(size_t position,
81 HInstruction* instruction,
82 Location source,
83 Location destination) const;
84 void AddMove(HParallelMove* move,
85 Location source,
86 Location destination,
87 HInstruction* instruction,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010088 DataType::Type type) const;
Matthew Gharrity5d6e27d2016-07-18 13:38:44 -070089
90 ArenaAllocator* const allocator_;
91 CodeGenerator* const codegen_;
92 const SsaLivenessAnalysis& liveness_;
93
94 DISALLOW_COPY_AND_ASSIGN(RegisterAllocationResolver);
95};
96
97} // namespace art
98
99#endif // ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_