1 //===-- RegisterClassInfo.h - Dynamic Register Class Info -*- C++ -*-------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the RegisterClassInfo class which provides dynamic
11 // information about target register classes. Callee saved and reserved
12 // registers depends on calling conventions and other dynamic information, so
13 // some things cannot be determined statically.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CODEGEN_REGISTERCLASSINFO_H
18 #define LLVM_CODEGEN_REGISTERCLASSINFO_H
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/BitVector.h"
22 #include "llvm/ADT/OwningPtr.h"
23 #include "llvm/Target/TargetRegisterInfo.h"
27 class RegisterClassInfo {
33 uint16_t LastCostChange;
34 OwningArrayPtr<MCPhysReg> Order;
37 : Tag(0), NumRegs(0), ProperSubClass(false), MinCost(0),
40 operator ArrayRef<MCPhysReg>() const {
41 return makeArrayRef(Order.get(), NumRegs);
45 // Brief cached information for each register class.
46 OwningArrayPtr<RCInfo> RegClass;
48 // Tag changes whenever cached information needs to be recomputed. An RCInfo
49 // entry is valid when its tag matches.
52 const MachineFunction *MF;
53 const TargetRegisterInfo *TRI;
55 // Callee saved registers of last MF. Assumed to be valid until the next
56 // runOnFunction() call.
57 const uint16_t *CalleeSaved;
59 // Map register number to CalleeSaved index + 1;
60 SmallVector<uint8_t, 4> CSRNum;
62 // Reserved registers in the current MF.
65 OwningArrayPtr<unsigned> PSetLimits;
67 // Compute all information about RC.
68 void compute(const TargetRegisterClass *RC) const;
70 // Return an up-to-date RCInfo for RC.
71 const RCInfo &get(const TargetRegisterClass *RC) const {
72 const RCInfo &RCI = RegClass[RC->getID()];
81 /// runOnFunction - Prepare to answer questions about MF. This must be called
82 /// before any other methods are used.
83 void runOnMachineFunction(const MachineFunction &MF);
85 /// getNumAllocatableRegs - Returns the number of actually allocatable
86 /// registers in RC in the current function.
87 unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const {
88 return get(RC).NumRegs;
91 /// getOrder - Returns the preferred allocation order for RC. The order
92 /// contains no reserved registers, and registers that alias callee saved
93 /// registers come last.
94 ArrayRef<MCPhysReg> getOrder(const TargetRegisterClass *RC) const {
98 /// isProperSubClass - Returns true if RC has a legal super-class with more
99 /// allocatable registers.
101 /// Register classes like GR32_NOSP are not proper sub-classes because %esp
102 /// is not allocatable. Similarly, tGPR is not a proper sub-class in Thumb
103 /// mode because the GPR super-class is not legal.
104 bool isProperSubClass(const TargetRegisterClass *RC) const {
105 return get(RC).ProperSubClass;
108 /// getLastCalleeSavedAlias - Returns the last callee saved register that
109 /// overlaps PhysReg, or 0 if Reg doesn't overlap a CSR.
110 unsigned getLastCalleeSavedAlias(unsigned PhysReg) const {
111 assert(TargetRegisterInfo::isPhysicalRegister(PhysReg));
112 if (unsigned N = CSRNum[PhysReg])
113 return CalleeSaved[N-1];
117 /// Get the minimum register cost in RC's allocation order.
118 /// This is the smallest value returned by TRI->getCostPerUse(Reg) for all
119 /// the registers in getOrder(RC).
120 unsigned getMinCost(const TargetRegisterClass *RC) {
121 return get(RC).MinCost;
124 /// Get the position of the last cost change in getOrder(RC).
126 /// All registers in getOrder(RC).slice(getLastCostChange(RC)) will have the
127 /// same cost according to TRI->getCostPerUse().
128 unsigned getLastCostChange(const TargetRegisterClass *RC) {
129 return get(RC).LastCostChange;
132 /// Get the register unit limit for the given pressure set index.
134 /// RegisterClassInfo adjusts this limit for reserved registers.
135 unsigned getRegPressureSetLimit(unsigned Idx) const {
136 if (!PSetLimits[Idx])
137 PSetLimits[Idx] = computePSetLimit(Idx);
138 return PSetLimits[Idx];
142 unsigned computePSetLimit(unsigned Idx) const;
144 } // end namespace llvm