File indexing completed on 2026-05-10 08:43:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef LLVM_CODEGEN_REGISTERCLASSINFO_H
0017 #define LLVM_CODEGEN_REGISTERCLASSINFO_H
0018
0019 #include "llvm/ADT/ArrayRef.h"
0020 #include "llvm/ADT/BitVector.h"
0021 #include "llvm/ADT/SmallVector.h"
0022 #include "llvm/CodeGen/TargetRegisterInfo.h"
0023 #include "llvm/MC/MCRegister.h"
0024 #include <cstdint>
0025 #include <memory>
0026
0027 namespace llvm {
0028
0029 class RegisterClassInfo {
0030 struct RCInfo {
0031 unsigned Tag = 0;
0032 unsigned NumRegs = 0;
0033 bool ProperSubClass = false;
0034 uint8_t MinCost = 0;
0035 uint16_t LastCostChange = 0;
0036 std::unique_ptr<MCPhysReg[]> Order;
0037
0038 RCInfo() = default;
0039
0040 operator ArrayRef<MCPhysReg>() const {
0041 return ArrayRef(Order.get(), NumRegs);
0042 }
0043 };
0044
0045
0046 std::unique_ptr<RCInfo[]> RegClass;
0047
0048
0049
0050 unsigned Tag = 0;
0051
0052 const MachineFunction *MF = nullptr;
0053 const TargetRegisterInfo *TRI = nullptr;
0054
0055
0056
0057 SmallVector<MCPhysReg, 16> LastCalleeSavedRegs;
0058
0059
0060 SmallVector<MCPhysReg> CalleeSavedAliases;
0061
0062
0063
0064 BitVector IgnoreCSRForAllocOrder;
0065
0066
0067 BitVector Reserved;
0068
0069 std::unique_ptr<unsigned[]> PSetLimits;
0070
0071
0072 ArrayRef<uint8_t> RegCosts;
0073
0074
0075 void compute(const TargetRegisterClass *RC) const;
0076
0077
0078 const RCInfo &get(const TargetRegisterClass *RC) const {
0079 const RCInfo &RCI = RegClass[RC->getID()];
0080 if (Tag != RCI.Tag)
0081 compute(RC);
0082 return RCI;
0083 }
0084
0085 public:
0086 RegisterClassInfo();
0087
0088
0089
0090 void runOnMachineFunction(const MachineFunction &MF);
0091
0092
0093
0094 unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const {
0095 return get(RC).NumRegs;
0096 }
0097
0098
0099
0100
0101 ArrayRef<MCPhysReg> getOrder(const TargetRegisterClass *RC) const {
0102 return get(RC);
0103 }
0104
0105
0106
0107
0108
0109
0110
0111 bool isProperSubClass(const TargetRegisterClass *RC) const {
0112 return get(RC).ProperSubClass;
0113 }
0114
0115
0116
0117
0118 MCRegister getLastCalleeSavedAlias(MCRegister PhysReg) const {
0119 MCRegister CSR;
0120 for (MCRegUnitIterator UI(PhysReg, TRI); UI.isValid(); ++UI) {
0121 CSR = CalleeSavedAliases[*UI];
0122 if (CSR)
0123 break;
0124 }
0125 return CSR;
0126 }
0127
0128
0129
0130
0131 uint8_t getMinCost(const TargetRegisterClass *RC) const {
0132 return get(RC).MinCost;
0133 }
0134
0135
0136
0137
0138
0139 unsigned getLastCostChange(const TargetRegisterClass *RC) const {
0140 return get(RC).LastCostChange;
0141 }
0142
0143
0144
0145
0146 unsigned getRegPressureSetLimit(unsigned Idx) const {
0147 if (!PSetLimits[Idx])
0148 PSetLimits[Idx] = computePSetLimit(Idx);
0149 return PSetLimits[Idx];
0150 }
0151
0152 protected:
0153 unsigned computePSetLimit(unsigned Idx) const;
0154 };
0155
0156 }
0157
0158 #endif