aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Nandakumar <aditya_nandakumar@apple.com>2018-02-02 19:42:07 +0000
committerAditya Nandakumar <aditya_nandakumar@apple.com>2018-02-02 19:42:07 +0000
commit9175ef395ebfec8b50b1766a7758b901e0ddd572 (patch)
tree936de1b495276d04835e33859366538b49b7ea86
parent43f741e3e6968b2834c4aab56f77de9b29cc0e64 (diff)
[GISel][NFC]: Move RegisterBankInfo::getSizeInBits into TargetRegisterInfo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324125 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/TargetRegisterInfo.h3
-rw-r--r--lib/CodeGen/GlobalISel/RegisterBankInfo.cpp18
-rw-r--r--lib/CodeGen/TargetRegisterInfo.cpp22
3 files changed, 30 insertions, 13 deletions
diff --git a/include/llvm/CodeGen/TargetRegisterInfo.h b/include/llvm/CodeGen/TargetRegisterInfo.h
index 81907538fb0..b606f942896 100644
--- a/include/llvm/CodeGen/TargetRegisterInfo.h
+++ b/include/llvm/CodeGen/TargetRegisterInfo.h
@@ -752,6 +752,9 @@ public:
virtual const RegClassWeight &getRegClassWeight(
const TargetRegisterClass *RC) const = 0;
+ /// Returns size in bits of a phys/virtual/generic register.
+ unsigned getRegSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI) const;
+
/// Get the weight in units of pressure for this register unit.
virtual unsigned getRegUnitWeight(unsigned RegUnit) const = 0;
diff --git a/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp b/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
index b3d9209ae6e..dbd53565ba5 100644
--- a/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
+++ b/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
@@ -458,24 +458,16 @@ void RegisterBankInfo::applyDefaultMapping(const OperandsMapper &OpdMapper) {
unsigned RegisterBankInfo::getSizeInBits(unsigned Reg,
const MachineRegisterInfo &MRI,
const TargetRegisterInfo &TRI) const {
- const TargetRegisterClass *RC = nullptr;
if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
// The size is not directly available for physical registers.
// Instead, we need to access a register class that contains Reg and
// get the size of that register class.
- RC = &getMinimalPhysRegClass(Reg, TRI);
- } else {
- LLT Ty = MRI.getType(Reg);
- unsigned RegSize = Ty.isValid() ? Ty.getSizeInBits() : 0;
- // If Reg is not a generic register, query the register class to
- // get its size.
- if (RegSize)
- return RegSize;
- // Since Reg is not a generic register, it must have a register class.
- RC = MRI.getRegClass(Reg);
+ // Because this is expensive, we'll cache the register class by calling
+ auto *RC = &getMinimalPhysRegClass(Reg, TRI);
+ assert(RC && "Expecting Register class");
+ return TRI.getRegSizeInBits(*RC);
}
- assert(RC && "Unable to deduce the register class");
- return TRI.getRegSizeInBits(*RC);
+ return TRI.getRegSizeInBits(Reg, MRI);
}
//------------------------------------------------------------------------------
diff --git a/lib/CodeGen/TargetRegisterInfo.cpp b/lib/CodeGen/TargetRegisterInfo.cpp
index d6064ca6b6f..5db1c58d349 100644
--- a/lib/CodeGen/TargetRegisterInfo.cpp
+++ b/lib/CodeGen/TargetRegisterInfo.cpp
@@ -450,6 +450,28 @@ bool TargetRegisterInfo::regmaskSubsetEqual(const uint32_t *mask0,
return true;
}
+unsigned TargetRegisterInfo::getRegSizeInBits(unsigned Reg,
+ const MachineRegisterInfo &MRI) const {
+ const TargetRegisterClass *RC{};
+ if (isPhysicalRegister(Reg)) {
+ // The size is not directly available for physical registers.
+ // Instead, we need to access a register class that contains Reg and
+ // get the size of that register class.
+ RC = getMinimalPhysRegClass(Reg);
+ } else {
+ LLT Ty = MRI.getType(Reg);
+ unsigned RegSize = Ty.isValid() ? Ty.getSizeInBits() : 0;
+ // If Reg is not a generic register, query the register class to
+ // get its size.
+ if (RegSize)
+ return RegSize;
+ // Since Reg is not a generic register, it must have a register class.
+ RC = MRI.getRegClass(Reg);
+ }
+ assert(RC && "Unable to deduce the register class");
+ return getRegSizeInBits(*RC);
+}
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD
void TargetRegisterInfo::dumpReg(unsigned Reg, unsigned SubRegIndex,