[llvm] 5319638 - Add register size info back to MCRegisterClass

Rafael Auler via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 15:05:16 PDT 2021


Author: Rafael Auler
Date: 2021-03-23T15:04:44-07:00
New Revision: 53196387c201fd082d62f58459adb03267811a4c

URL: https://github.com/llvm/llvm-project/commit/53196387c201fd082d62f58459adb03267811a4c
DIFF: https://github.com/llvm/llvm-project/commit/53196387c201fd082d62f58459adb03267811a4c.diff

LOG: Add register size info back to MCRegisterClass

This patch addresses the removal of register size information done in
commit c8b782c.

Without this change, there is no viable option to get register size
information outside libTarget. We need this information to run
analysis that know the register size from the MC layer, used by
BOLT.

Discussion D50285 and D47199.

Reviewed By: kparzysz

Differential Revision: https://reviews.llvm.org/D97891

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCRegisterInfo.h
    llvm/utils/TableGen/RegisterInfoEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCRegisterInfo.h b/llvm/include/llvm/MC/MCRegisterInfo.h
index 0c1ac6254ec12..65436dc74c3e2 100644
--- a/llvm/include/llvm/MC/MCRegisterInfo.h
+++ b/llvm/include/llvm/MC/MCRegisterInfo.h
@@ -39,6 +39,7 @@ class MCRegisterClass {
   const uint16_t RegsSize;
   const uint16_t RegSetSize;
   const uint16_t ID;
+  const uint16_t RegSizeInBits;
   const int8_t CopyCost;
   const bool Allocatable;
 
@@ -78,6 +79,12 @@ class MCRegisterClass {
     return contains(Reg1) && contains(Reg2);
   }
 
+  /// Return the size of the physical register in bits if we are able to
+  /// determine it. This always returns zero for registers of targets that use
+  /// HW modes, as we need more information to determine the size of registers
+  /// in such cases. Use TargetRegisterInfo to cover them.
+  unsigned getSizeInBits() const { return RegSizeInBits; }
+
   /// getCopyCost - Return the cost of copying a value between two registers in
   /// this class. A negative number means the register class is very expensive
   /// to copy e.g. status flag register classes.

diff  --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
index 41d5720b70a62..8a744e64334e3 100644
--- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
@@ -1084,12 +1084,15 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
 
   for (const auto &RC : RegisterClasses) {
     assert(isInt<8>(RC.CopyCost) && "Copy cost too large.");
+    uint32_t RegSize = 0;
+    if (RC.RSI.isSimple())
+      RegSize = RC.RSI.getSimple().RegSize;
     OS << "  { " << RC.getName() << ", " << RC.getName() << "Bits, "
-       << RegClassStrings.get(RC.getName()) << ", "
-       << RC.getOrder().size() << ", sizeof(" << RC.getName() << "Bits), "
-       << RC.getQualifiedName() + "RegClassID" << ", "
-       << RC.CopyCost << ", "
-       << ( RC.Allocatable ? "true" : "false" ) << " },\n";
+       << RegClassStrings.get(RC.getName()) << ", " << RC.getOrder().size()
+       << ", sizeof(" << RC.getName() << "Bits), "
+       << RC.getQualifiedName() + "RegClassID"
+       << ", " << RegSize << ", " << RC.CopyCost << ", "
+       << (RC.Allocatable ? "true" : "false") << " },\n";
   }
 
   OS << "};\n\n";


        


More information about the llvm-commits mailing list