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