aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h
blob: 3fd0e55c9f9600a012f91388466af721ccc9bb35 (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
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_TARGETREGISTERALLOCATIONINFO_H
#define RCC_CODEGEN_TARGETREGISTERALLOCATIONINFO_H

#include "rcc/CodeGen/LiveInterval.h"
#include "rcc/CodeGen/MachineFrameInfo.h"
#include "rcc/CodeGen/TargetRegisterInfo.h"

#include <cstdint>

namespace rcc {

class MachineIRBuilder;
class MachineInstr;
class TargetDescription;

class TargetRegisterAllocationInfo {
public:
  virtual ~TargetRegisterAllocationInfo() = default;

  [[nodiscard]] virtual Expected<void>
  validateSpillReload(RegisterClassID Class, const TargetDescription &Target) const = 0;
  [[nodiscard]] virtual Expected<MachineInstr *>
  emitReload(MachineIRBuilder &Builder, Register Destination, RegisterClassID Class,
             FrameIndex StackSlot, LaneMask Lanes) const = 0;
  [[nodiscard]] virtual Expected<MachineInstr *> emitSpill(MachineIRBuilder &Builder,
                                                           Register Source, RegisterClassID Class,
                                                           FrameIndex StackSlot,
                                                           LaneMask Lanes) const = 0;

  [[nodiscard]] virtual Expected<bool> isRematerializable(const MachineInstr &, Register,
                                                          const MachineFunction &,
                                                          const TargetDescription &) const {
    return false;
  }
  [[nodiscard]] virtual Expected<MachineInstr *> rematerialize(MachineIRBuilder &,
                                                               const MachineInstr &, Register,
                                                               Register,
                                                               const TargetDescription &) const {
    return makeUnexpected(ErrorCode::InternalError,
                          "target accepted rematerialization without implementing it");
  }

  [[nodiscard]] virtual std::uint64_t physicalRegisterCost(const MachineFunction &, Register,
                                                           PhysicalRegister, RegisterClassID,
                                                           bool) const noexcept {
    return 0;
  }
  [[nodiscard]] virtual std::uint64_t spillCost(const MachineFunction &, const LiveInterval &,
                                                RegisterClassID) const noexcept {
    return 1;
  }

  [[nodiscard]] virtual bool isReservedForFunction(const MachineFunction &, PhysicalRegister,
                                                   const TargetDescription &) const noexcept {
    return false;
  }
};

} // namespace rcc

#endif // RCC_CODEGEN_TARGETREGISTERALLOCATIONINFO_H