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

#ifndef RCC_CODEGEN_REGISTERBANKINFO_H
#define RCC_CODEGEN_REGISTERBANKINFO_H

#include "rcc/CodeGen/MachineIRTypes.h"
#include "rcc/CodeGen/Register.h"
#include "rcc/Support/Error.h"

#include <optional>
#include <vector>

namespace rcc {

class MachineFunction;
class MachineInstr;
class TargetDescription;
struct VirtualRegisterInfo;

struct RegisterBankSelection final {
  RegisterBankID Bank;
  bool IsConstrained = false;
};

using RegisterBankInstructionMapping = std::vector<std::optional<RegisterBankID>>;

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

  [[nodiscard]] virtual Expected<RegisterBankSelection>
  selectBank(const MachineFunction &Function, Register Reg, const VirtualRegisterInfo &Info,
             const MachineInstr *Context, const TargetDescription &Target) const = 0;

  [[nodiscard]] virtual Expected<RegisterBankInstructionMapping>
  getInstructionMapping(const MachineInstr &, const MachineFunction &,
                        const TargetDescription &) const {
    return RegisterBankInstructionMapping{};
  }

  // This hook rejects invalid mappings before register-bank state is published.
  [[nodiscard]] virtual Expected<void> validateInstruction(const MachineInstr &,
                                                           const MachineFunction &,
                                                           const TargetDescription &) const {
    return {};
  }
};

} // namespace rcc

#endif // RCC_CODEGEN_REGISTERBANKINFO_H