Home | History | Annotate | Download | only in GlobalISel
      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 create RegisterBank.
     41   /// The default constructor will leave the object in
     42   /// an invalid state. I.e. isValid() == false.
     43   /// The field must be updated to fix that.
     44   RegisterBank();
     45 
     46   friend RegisterBankInfo;
     47 
     48 public:
     49   /// Get the identifier of this register bank.
     50   unsigned getID() const { return ID; }
     51 
     52   /// Get a user friendly name of this register bank.
     53   /// Should be used only for debugging purposes.
     54   const char *getName() const { return Name; }
     55 
     56   /// Get the maximal size in bits that fits in this register bank.
     57   unsigned getSize() const { return Size; }
     58 
     59   /// Check whether this instance is ready to be used.
     60   bool isValid() const;
     61 
     62   /// Check if this register bank is valid. In other words,
     63   /// if it has been properly constructed.
     64   ///
     65   /// \note This method does not check anything when assertions are disabled.
     66   ///
     67   /// \return True is the check was successful.
     68   bool verify(const TargetRegisterInfo &TRI) const;
     69 
     70   /// Check whether this register bank covers \p RC.
     71   /// In other words, check if this register bank fully covers
     72   /// the registers that \p RC contains.
     73   /// \pre isValid()
     74   bool covers(const TargetRegisterClass &RC) const;
     75 
     76   /// Check whether \p OtherRB is the same as this.
     77   bool operator==(const RegisterBank &OtherRB) const;
     78   bool operator!=(const RegisterBank &OtherRB) const {
     79     return !this->operator==(OtherRB);
     80   }
     81 
     82   /// Dump the register mask on dbgs() stream.
     83   /// The dump is verbose.
     84   void dump(const TargetRegisterInfo *TRI = nullptr) const;
     85 
     86   /// Print the register mask on OS.
     87   /// If IsForDebug is false, then only the name of the register bank
     88   /// is printed. Otherwise, all the fields are printing.
     89   /// TRI is then used to print the name of the register classes that
     90   /// this register bank covers.
     91   void print(raw_ostream &OS, bool IsForDebug = false,
     92              const TargetRegisterInfo *TRI = nullptr) const;
     93 };
     94 
     95 inline raw_ostream &operator<<(raw_ostream &OS, const RegisterBank &RegBank) {
     96   RegBank.print(OS);
     97   return OS;
     98 }
     99 } // End namespace llvm.
    100 
    101 #endif
    102