summaryrefslogtreecommitdiff
path: root/compiler/optimizing/register_allocation_resolver.h
blob: 6ceb9bc955388ae7241c34ed041adb404de94d84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_
#define ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_

#include "base/arena_containers.h"
#include "base/value_object.h"
#include "primitive.h"

namespace art {

class ArenaAllocator;
class CodeGenerator;
class HBasicBlock;
class HInstruction;
class HParallelMove;
class LiveInterval;
class Location;
class SsaLivenessAnalysis;

/**
 * Reconciles the locations assigned to live intervals with the location
 * summary of each instruction, and inserts moves to resolve split intervals,
 * nonlinear control flow, and phi inputs.
 */
class RegisterAllocationResolver : ValueObject {
 public:
  RegisterAllocationResolver(ArenaAllocator* allocator,
                             CodeGenerator* codegen,
                             const SsaLivenessAnalysis& liveness);

  void Resolve(size_t max_safepoint_live_core_regs,
               size_t max_safepoint_live_fp_regs,
               size_t reserved_out_slots,  // Includes slot(s) for the art method.
               size_t int_spill_slots,
               size_t long_spill_slots,
               size_t float_spill_slots,
               size_t double_spill_slots,
               size_t catch_phi_spill_slots,
               const ArenaVector<LiveInterval*>& temp_intervals);

 private:
  // Connect adjacent siblings within blocks, and resolve inputs along the way.
  // Uses max_safepoint_live_regs to check that we did not underestimate the
  // number of live registers at safepoints.
  void ConnectSiblings(LiveInterval* interval, size_t max_safepoint_live_regs);

  // Connect siblings between block entries and exits.
  void ConnectSplitSiblings(LiveInterval* interval, HBasicBlock* from, HBasicBlock* to) const;

  // Helper methods for inserting parallel moves in the graph.
  void InsertParallelMoveAtExitOf(HBasicBlock* block,
                                  HInstruction* instruction,
                                  Location source,
                                  Location destination) const;
  void InsertParallelMoveAtEntryOf(HBasicBlock* block,
                                   HInstruction* instruction,
                                   Location source,
                                   Location destination) const;
  void InsertMoveAfter(HInstruction* instruction, Location source, Location destination) const;
  void AddInputMoveFor(HInstruction* input,
                       HInstruction* user,
                       Location source,
                       Location destination) const;
  void InsertParallelMoveAt(size_t position,
                            HInstruction* instruction,
                            Location source,
                            Location destination) const;
  void AddMove(HParallelMove* move,
               Location source,
               Location destination,
               HInstruction* instruction,
               Primitive::Type type) const;

  ArenaAllocator* const allocator_;
  CodeGenerator* const codegen_;
  const SsaLivenessAnalysis& liveness_;

  DISALLOW_COPY_AND_ASSIGN(RegisterAllocationResolver);
};

}  // namespace art

#endif  // ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_