diff options
| -rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h | 68 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp | 39 | 
3 files changed, 108 insertions, 0 deletions
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h new file mode 100644 index 00000000000..9c1d25d5e0e --- /dev/null +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h @@ -0,0 +1,68 @@ +//==-- llvm/CodeGen/GlobalISel/RegisterBank.h - Register Bank ----*- C++ -*-==// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +/// \file This file declares the API of register banks. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_GLOBALISEL_REGBANK_H +#define LLVM_CODEGEN_GLOBALISEL_REGBANK_H + +#include "llvm/ADT/BitVector.h" + +namespace llvm { +// Forward declarations. +class RegisterBankInfo; +class TargetRegisterClass; +class TargetRegisterInfo; + +/// This class implements the register bank concept. +/// Two instances of RegisterBank must have different ID. +/// This property is enforced by the RegisterBankInfo class. +class RegisterBank { +private: +  unsigned ID; +  const char *Name; +  unsigned Size; +  BitVector ContainedRegClass; + +  /// Only the RegisterBankInfo can create RegisterBank. +  RegisterBank() = default; + +  friend RegisterBankInfo; + +public: +  /// Get the identifier of this register bank. +  unsigned getID() const { return ID; } + +  /// Get a user friendly name of this register bank. +  /// Should be used only for debugging purposes. +  const char *getName() const { return Name; } + +  /// Get the maximal size in bits that fits in this register bank. +  unsigned getSize() const { return Size; } + +  /// Check if this register bank is valid. In other words, +  /// if it has been properly constructed. +  void verify(const TargetRegisterInfo &TRI) const; + +  /// Check whether this register bank contains \p RC. +  /// In other words, check if this register bank fully covers +  /// the registers that \p RC contains. +  bool contains(const TargetRegisterClass &RC) const; + +  /// Check whether \p OtherRB is the same as this. +  bool operator==(const RegisterBank &OtherRB) const; +  bool operator!=(const RegisterBank &OtherRB) const { +    return !this->operator==(OtherRB); +  } +}; +} // End namespace llvm. + +#endif diff --git a/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt b/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt index bb6225f031a..162c8197e95 100644 --- a/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt +++ b/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt @@ -3,6 +3,7 @@ set(GLOBAL_ISEL_FILES        IRTranslator.cpp        MachineIRBuilder.cpp        RegBankSelect.cpp +      RegisterBank.cpp        )  # Add GlobalISel files to the dependencies if the user wants to build it. diff --git a/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp b/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp new file mode 100644 index 00000000000..5c86e426e1b --- /dev/null +++ b/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp @@ -0,0 +1,39 @@ +//===- llvm/CodeGen/GlobalISel/RegisterBank.cpp - Register Bank --*- C++ -*-==// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// This file implements the RegisterBank class. +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/GlobalISel/RegisterBank.h" + +#include "llvm/Target/TargetRegisterInfo.h" + +#define DEBUG_TYPE "registerbank" + +using namespace llvm; + +void RegisterBank::verify(const TargetRegisterInfo &TRI) const { +  // Verify that the Size of the register bank is big enough to cover all the +  // register classes it covers. +  // Verify that the register bank covers all the sub and super classes of the +  // classes it covers. +} + +bool RegisterBank::contains(const TargetRegisterClass &RC) const { +  return ContainedRegClass.test(RC.getID()); +} + +bool RegisterBank::operator==(const RegisterBank &OtherRB) const { +  // There must be only one instance of a given register bank alive +  // for the whole compilation. +  // The RegisterBankInfo is supposed to enforce that. +  assert((OtherRB.getID() != getID() || &OtherRB == this) && +         "ID does not uniquely identify a RegisterBank"); +  return &OtherRB == this; +}  | 

