xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/RegisterBank.h (revision bdcfeac3e1cb8ce3f05c32d8a7ad3597deb48bdf)
1 //==-- llvm/CodeGen/RegisterBank.h - Register Bank ---------------*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file This file declares the API of register banks.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_REGISTERBANK_H
14 #define LLVM_CODEGEN_REGISTERBANK_H
15 
16 #include "llvm/Support/Compiler.h"
17 #include <cstdint>
18 
19 namespace llvm {
20 // Forward declarations.
21 class RegisterBankInfo;
22 class raw_ostream;
23 class TargetRegisterClass;
24 class TargetRegisterInfo;
25 
26 /// This class implements the register bank concept.
27 /// Two instances of RegisterBank must have different ID.
28 /// This property is enforced by the RegisterBankInfo class.
29 class RegisterBank {
30 private:
31   unsigned ID;
32   unsigned NumRegClasses;
33   const char *Name;
34   const uint32_t *CoveredClasses;
35 
36   /// Only the RegisterBankInfo can initialize RegisterBank properly.
37   friend RegisterBankInfo;
38 
39 public:
40   constexpr RegisterBank(unsigned ID, const char *Name,
41                          const uint32_t *CoveredClasses, unsigned NumRegClasses)
42       : ID(ID), NumRegClasses(NumRegClasses), Name(Name),
43         CoveredClasses(CoveredClasses) {}
44 
45   /// Get the identifier of this register bank.
46   unsigned getID() const { return ID; }
47 
48   /// Get a user friendly name of this register bank.
49   /// Should be used only for debugging purposes.
50   const char *getName() const { return Name; }
51 
52   /// Check if this register bank is valid. In other words,
53   /// if it has been properly constructed.
54   ///
55   /// \note This method does not check anything when assertions are disabled.
56   ///
57   /// \return True is the check was successful.
58   LLVM_ABI bool verify(const RegisterBankInfo &RBI,
59                        const TargetRegisterInfo &TRI) const;
60 
61   /// Check whether this register bank covers \p RC.
62   /// In other words, check if this register bank fully covers
63   /// the registers that \p RC contains.
64   LLVM_ABI bool covers(const TargetRegisterClass &RC) const;
65 
66   /// Check whether \p OtherRB is the same as this.
67   LLVM_ABI bool operator==(const RegisterBank &OtherRB) const;
68   bool operator!=(const RegisterBank &OtherRB) const {
69     return !this->operator==(OtherRB);
70   }
71 
72   /// Dump the register mask on dbgs() stream.
73   /// The dump is verbose.
74   LLVM_ABI void dump(const TargetRegisterInfo *TRI = nullptr) const;
75 
76   /// Print the register mask on OS.
77   /// If IsForDebug is false, then only the name of the register bank
78   /// is printed. Otherwise, all the fields are printing.
79   /// TRI is then used to print the name of the register classes that
80   /// this register bank covers.
81   LLVM_ABI void print(raw_ostream &OS, bool IsForDebug = false,
82                       const TargetRegisterInfo *TRI = nullptr) const;
83 };
84 
85 inline raw_ostream &operator<<(raw_ostream &OS, const RegisterBank &RegBank) {
86   RegBank.print(OS);
87   return OS;
88 }
89 } // End namespace llvm.
90 
91 #endif
92