[llvm] r265445 - [GlobalISel] Add a class, RegisterBank, to represent register banks.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 12:54:45 PDT 2016


Author: qcolombet
Date: Tue Apr  5 14:54:44 2016
New Revision: 265445

URL: http://llvm.org/viewvc/llvm-project?rev=265445&view=rev
Log:
[GlobalISel] Add a class, RegisterBank, to represent register banks.

Added:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h
    llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp
Modified:
    llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt

Added: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h?rev=265445&view=auto
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h (added)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h Tue Apr  5 14:54:44 2016
@@ -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

Modified: llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt?rev=265445&r1=265444&r2=265445&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt Tue Apr  5 14:54:44 2016
@@ -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.

Added: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp?rev=265445&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp (added)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp Tue Apr  5 14:54:44 2016
@@ -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;
+}




More information about the llvm-commits mailing list