1 //==-- llvm/CodeGen/GlobalISel/RegisterBank.h - Register Bank ----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \file This file declares the API of register banks.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_GLOBALISEL_REGBANK_H
15 #define LLVM_CODEGEN_GLOBALISEL_REGBANK_H
17 #include "llvm/ADT/BitVector.h"
20 // Forward declarations.
21 class RegisterBankInfo;
23 class TargetRegisterClass;
24 class TargetRegisterInfo;
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.
34 BitVector ContainedRegClasses;
36 /// Sentinel value used to recognize register bank not properly
38 static const unsigned InvalidID;
40 /// Only the RegisterBankInfo can initialize RegisterBank properly.
41 friend RegisterBankInfo;
44 RegisterBank(unsigned ID, const char *Name, unsigned Size,
45 const uint32_t *CoveredClasses, unsigned NumRegClasses);
47 /// Get the identifier of this register bank.
48 unsigned getID() const { return ID; }
50 /// Get a user friendly name of this register bank.
51 /// Should be used only for debugging purposes.
52 const char *getName() const { return Name; }
54 /// Get the maximal size in bits that fits in this register bank.
55 unsigned getSize() const { return Size; }
57 /// Check whether this instance is ready to be used.
60 /// Check if this register bank is valid. In other words,
61 /// if it has been properly constructed.
63 /// \note This method does not check anything when assertions are disabled.
65 /// \return True is the check was successful.
66 bool verify(const TargetRegisterInfo &TRI) const;
68 /// Check whether this register bank covers \p RC.
69 /// In other words, check if this register bank fully covers
70 /// the registers that \p RC contains.
72 bool covers(const TargetRegisterClass &RC) const;
74 /// Check whether \p OtherRB is the same as this.
75 bool operator==(const RegisterBank &OtherRB) const;
76 bool operator!=(const RegisterBank &OtherRB) const {
77 return !this->operator==(OtherRB);
80 /// Dump the register mask on dbgs() stream.
81 /// The dump is verbose.
82 void dump(const TargetRegisterInfo *TRI = nullptr) const;
84 /// Print the register mask on OS.
85 /// If IsForDebug is false, then only the name of the register bank
86 /// is printed. Otherwise, all the fields are printing.
87 /// TRI is then used to print the name of the register classes that
88 /// this register bank covers.
89 void print(raw_ostream &OS, bool IsForDebug = false,
90 const TargetRegisterInfo *TRI = nullptr) const;
93 inline raw_ostream &operator<<(raw_ostream &OS, const RegisterBank &RegBank) {
97 } // End namespace llvm.