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 {
32 OwningArrayPtr<unsigned> Order;
34 RCInfo() : Tag(0), NumRegs(0), ProperSubClass(false) {}
35 operator ArrayRef<unsigned>() const {
36 return makeArrayRef(Order.get(), NumRegs);
40 // Brief cached information for each register class.
41 OwningArrayPtr<RCInfo> RegClass;
43 // Tag changes whenever cached information needs to be recomputed. An RCInfo
44 // entry is valid when its tag matches.
47 const MachineFunction *MF;
48 const TargetRegisterInfo *TRI;
50 // Callee saved registers of last MF. Assumed to be valid until the next
51 // runOnFunction() call.
52 const uint16_t *CalleeSaved;
54 // Map register number to CalleeSaved index + 1;
55 SmallVector<uint8_t, 4> CSRNum;
57 // Reserved registers in the current MF.
60 // Compute all information about RC.
61 void compute(const TargetRegisterClass *RC) const;
63 // Return an up-to-date RCInfo for RC.
64 const RCInfo &get(const TargetRegisterClass *RC) const {
65 const RCInfo &RCI = RegClass[RC->getID()];
74 /// runOnFunction - Prepare to answer questions about MF. This must be called
75 /// before any other methods are used.
76 void runOnMachineFunction(const MachineFunction &MF);
78 /// getNumAllocatableRegs - Returns the number of actually allocatable
79 /// registers in RC in the current function.
80 unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const {
81 return get(RC).NumRegs;
84 /// getOrder - Returns the preferred allocation order for RC. The order
85 /// contains no reserved registers, and registers that alias callee saved
86 /// registers come last.
87 ArrayRef<unsigned> getOrder(const TargetRegisterClass *RC) const {
91 /// isProperSubClass - Returns true if RC has a legal super-class with more
92 /// allocatable registers.
94 /// Register classes like GR32_NOSP are not proper sub-classes because %esp
95 /// is not allocatable. Similarly, tGPR is not a proper sub-class in Thumb
96 /// mode because the GPR super-class is not legal.
97 bool isProperSubClass(const TargetRegisterClass *RC) const {
98 return get(RC).ProperSubClass;
101 /// getLastCalleeSavedAlias - Returns the last callee saved register that
102 /// overlaps PhysReg, or 0 if Reg doesn't overlap a CSR.
103 unsigned getLastCalleeSavedAlias(unsigned PhysReg) const {
104 assert(TargetRegisterInfo::isPhysicalRegister(PhysReg));
105 if (unsigned N = CSRNum[PhysReg])
106 return CalleeSaved[N-1];
110 /// isReserved - Returns true when PhysReg is a reserved register.
112 /// Reserved registers may belong to an allocatable register class, but the
113 /// target has explicitly requested that they are not used.
115 bool isReserved(unsigned PhysReg) const {
116 return Reserved.test(PhysReg);
119 /// isAllocatable - Returns true when PhysReg belongs to an allocatable
120 /// register class and it hasn't been reserved.
122 /// Allocatable registers may show up in the allocation order of some virtual
123 /// register, so a register allocator needs to track its liveness and
125 bool isAllocatable(unsigned PhysReg) const {
126 return TRI->isInAllocatableClass(PhysReg) && !isReserved(PhysReg);
129 } // end namespace llvm