1 //==-- llvm/CodeGen/GlobalISel/RegisterBank.h - Register Bank ----*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file This file declares the API of register banks.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_GLOBALISEL_REGBANK_H
15 #define LLVM_CODEGEN_GLOBALISEL_REGBANK_H
16 
17 #include "llvm/ADT/BitVector.h"
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   const char *Name;
33   unsigned Size;
34   BitVector ContainedRegClasses;
35 
36   /// Sentinel value used to recognize register bank not properly
37   /// initialized yet.
38   static const unsigned InvalidID;
39 
40   /// Only the RegisterBankInfo can initialize RegisterBank properly.
41   friend RegisterBankInfo;
42 
43 public:
44   RegisterBank(unsigned ID, const char *Name, unsigned Size,
45                const uint32_t *CoveredClasses, unsigned NumRegClasses);
46 
47   /// Get the identifier of this register bank.
getID()48   unsigned getID() const { return ID; }
49 
50   /// Get a user friendly name of this register bank.
51   /// Should be used only for debugging purposes.
getName()52   const char *getName() const { return Name; }
53 
54   /// Get the maximal size in bits that fits in this register bank.
getSize()55   unsigned getSize() const { return Size; }
56 
57   /// Check whether this instance is ready to be used.
58   bool isValid() const;
59 
60   /// Check if this register bank is valid. In other words,
61   /// if it has been properly constructed.
62   ///
63   /// \note This method does not check anything when assertions are disabled.
64   ///
65   /// \return True is the check was successful.
66   bool verify(const TargetRegisterInfo &TRI) const;
67 
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.
71   /// \pre isValid()
72   bool covers(const TargetRegisterClass &RC) const;
73 
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);
78   }
79 
80   /// Dump the register mask on dbgs() stream.
81   /// The dump is verbose.
82   void dump(const TargetRegisterInfo *TRI = nullptr) const;
83 
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;
91 };
92 
93 inline raw_ostream &operator<<(raw_ostream &OS, const RegisterBank &RegBank) {
94   RegBank.print(OS);
95   return OS;
96 }
97 } // End namespace llvm.
98 
99 #endif
100