|
37 | 37 | #define LLVM_LIB_CODEGEN_REGALLOCBASE_H |
38 | 38 |
|
39 | 39 | #include "llvm/ADT/SmallPtrSet.h" |
| 40 | +#include "llvm/CodeGen/MachineRegisterInfo.h" |
40 | 41 | #include "llvm/CodeGen/RegAllocCommon.h" |
41 | 42 | #include "llvm/CodeGen/RegisterClassInfo.h" |
42 | 43 |
|
@@ -68,22 +69,32 @@ class RegAllocBase { |
68 | 69 | LiveIntervals *LIS = nullptr; |
69 | 70 | LiveRegMatrix *Matrix = nullptr; |
70 | 71 | RegisterClassInfo RegClassInfo; |
| 72 | + |
| 73 | +private: |
| 74 | + /// Private, callees should go through shouldAllocateRegister |
71 | 75 | const RegClassFilterFunc ShouldAllocateClass; |
72 | 76 |
|
| 77 | +protected: |
73 | 78 | /// Inst which is a def of an original reg and whose defs are already all |
74 | 79 | /// dead after remat is saved in DeadRemats. The deletion of such inst is |
75 | 80 | /// postponed till all the allocations are done, so its remat expr is |
76 | 81 | /// always available for the remat of all the siblings of the original reg. |
77 | 82 | SmallPtrSet<MachineInstr *, 32> DeadRemats; |
78 | 83 |
|
79 | | - RegAllocBase(const RegClassFilterFunc F = allocateAllRegClasses) : |
80 | | - ShouldAllocateClass(F) {} |
| 84 | + RegAllocBase(const RegClassFilterFunc F = nullptr) : ShouldAllocateClass(F) {} |
81 | 85 |
|
82 | 86 | virtual ~RegAllocBase() = default; |
83 | 87 |
|
84 | 88 | // A RegAlloc pass should call this before allocatePhysRegs. |
85 | 89 | void init(VirtRegMap &vrm, LiveIntervals &lis, LiveRegMatrix &mat); |
86 | 90 |
|
| 91 | + /// Get whether a given register should be allocated |
| 92 | + bool shouldAllocateRegister(Register Reg) { |
| 93 | + if (!ShouldAllocateClass) |
| 94 | + return true; |
| 95 | + return ShouldAllocateClass(*TRI, *MRI->getRegClass(Reg)); |
| 96 | + } |
| 97 | + |
87 | 98 | // The top-level driver. The output is a VirtRegMap that us updated with |
88 | 99 | // physical register assignments. |
89 | 100 | void allocatePhysRegs(); |
|
0 commit comments