131921Sbrian//==-- llvm/CodeGen/RegisterBank.h - Register Bank ---------------*- C++ -*-==// 231921Sbrian// 331921Sbrian// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 431921Sbrian// See https://llvm.org/LICENSE.txt for license information. 531921Sbrian// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 631921Sbrian// 731921Sbrian//===----------------------------------------------------------------------===// 831921Sbrian// 931921Sbrian/// \file This file declares the API of register banks. 1031921Sbrian// 1131921Sbrian//===----------------------------------------------------------------------===// 1231921Sbrian 1331921Sbrian#ifndef LLVM_CODEGEN_REGISTERBANK_H 1431921Sbrian#define LLVM_CODEGEN_REGISTERBANK_H 1531921Sbrian 1631921Sbrian#include <cstdint> 1731921Sbrian 1831921Sbriannamespace llvm { 1931921Sbrian// Forward declarations. 2031921Sbrianclass RegisterBankInfo; 2131921Sbrianclass raw_ostream; 2231921Sbrianclass TargetRegisterClass; 2331921Sbrianclass TargetRegisterInfo; 2431921Sbrian 2531921Sbrian/// This class implements the register bank concept. 2650479Speter/// Two instances of RegisterBank must have different ID. 2730715Sbrian/// This property is enforced by the RegisterBankInfo class. 2830715Sbrianclass RegisterBank { 2931196Sbrianprivate: 3044279Sbrian unsigned ID; 3144279Sbrian unsigned NumRegClasses; 3244279Sbrian const char *Name; 3344279Sbrian const uint32_t *CoveredClasses; 3444279Sbrian 3544279Sbrian /// Only the RegisterBankInfo can initialize RegisterBank properly. 3644279Sbrian friend RegisterBankInfo; 3746085Sbrian 3830715Sbrianpublic: 3931121Sbrian constexpr RegisterBank(unsigned ID, const char *Name, 4046686Sbrian const uint32_t *CoveredClasses, unsigned NumRegClasses) 4137192Sbrian : ID(ID), NumRegClasses(NumRegClasses), Name(Name), 4234539Sbrian CoveredClasses(CoveredClasses) {} 4337192Sbrian 4431196Sbrian /// Get the identifier of this register bank. 4530715Sbrian unsigned getID() const { return ID; } 4630715Sbrian 4730715Sbrian /// Get a user friendly name of this register bank. 4846686Sbrian /// Should be used only for debugging purposes. 4946686Sbrian const char *getName() const { return Name; } 5030715Sbrian 5130715Sbrian /// Check if this register bank is valid. In other words, 5230715Sbrian /// if it has been properly constructed. 5336453Sbrian /// 5437010Sbrian /// \note This method does not check anything when assertions are disabled. 5530715Sbrian /// 5630715Sbrian /// \return True is the check was successful. 5730715Sbrian bool verify(const RegisterBankInfo &RBI, const TargetRegisterInfo &TRI) const; 5830715Sbrian 5930715Sbrian /// Check whether this register bank covers \p RC. 6031343Sbrian /// In other words, check if this register bank fully covers 6136285Sbrian /// the registers that \p RC contains. 6231343Sbrian bool covers(const TargetRegisterClass &RC) const; 6330715Sbrian 6431196Sbrian /// Check whether \p OtherRB is the same as this. 6536285Sbrian bool operator==(const RegisterBank &OtherRB) const; 6636285Sbrian bool operator!=(const RegisterBank &OtherRB) const { 6736285Sbrian return !this->operator==(OtherRB); 6836285Sbrian } 6931196Sbrian 7036285Sbrian /// Dump the register mask on dbgs() stream. 7136285Sbrian /// The dump is verbose. 7236285Sbrian void dump(const TargetRegisterInfo *TRI = nullptr) const; 7336285Sbrian 7436285Sbrian /// Print the register mask on OS. 7536285Sbrian /// If IsForDebug is false, then only the name of the register bank 7636285Sbrian /// is printed. Otherwise, all the fields are printing. 7736285Sbrian /// TRI is then used to print the name of the register classes that 7836285Sbrian /// this register bank covers. 7936285Sbrian void print(raw_ostream &OS, bool IsForDebug = false, 8036285Sbrian const TargetRegisterInfo *TRI = nullptr) const; 8136285Sbrian}; 8236285Sbrian 8336285Sbrianinline raw_ostream &operator<<(raw_ostream &OS, const RegisterBank &RegBank) { 8436285Sbrian RegBank.print(OS); 8536285Sbrian return OS; 8636285Sbrian} 8736465Sbrian} // End namespace llvm. 8836465Sbrian 8936285Sbrian#endif 9036285Sbrian