| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef LLVM_CODEGEN_LIVEREGUNITS_H |
| 15 |
#define LLVM_CODEGEN_LIVEREGUNITS_H |
| 16 |
|
| 17 |
#include "llvm/ADT/BitVector.h" |
| 18 |
#include "llvm/CodeGen/MachineInstrBundle.h" |
| 19 |
#include "llvm/CodeGen/TargetRegisterInfo.h" |
| 20 |
#include "llvm/MC/LaneBitmask.h" |
| 21 |
#include "llvm/MC/MCRegisterInfo.h" |
| 22 |
#include <cstdint> |
| 23 |
|
| 24 |
namespace llvm { |
| 25 |
|
| 26 |
class MachineInstr; |
| 27 |
class MachineBasicBlock; |
| 28 |
|
| 29 |
|
| 30 |
class LiveRegUnits { |
| 31 |
const TargetRegisterInfo *TRI = nullptr; |
| 32 |
BitVector Units; |
| 33 |
|
| 34 |
public: |
| 35 |
|
| 36 |
LiveRegUnits() = default; |
| 37 |
|
| 38 |
|
| 39 |
LiveRegUnits(const TargetRegisterInfo &TRI) { |
| 40 |
init(TRI); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
static void accumulateUsedDefed(const MachineInstr &MI, |
| 48 |
LiveRegUnits &ModifiedRegUnits, |
| 49 |
LiveRegUnits &UsedRegUnits, |
| 50 |
const TargetRegisterInfo *TRI) { |
| 51 |
for (ConstMIBundleOperands O(MI); O.isValid(); ++O) { |
| 52 |
if (O->isRegMask()) |
| 53 |
ModifiedRegUnits.addRegsInMask(O->getRegMask()); |
| 54 |
if (!O->isReg()) |
| 55 |
continue; |
| 56 |
Register Reg = O->getReg(); |
| 57 |
if (!Reg.isPhysical()) |
| 58 |
continue; |
| 59 |
if (O->isDef()) { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
if (!TRI->isConstantPhysReg(Reg)) |
| 64 |
ModifiedRegUnits.addReg(Reg); |
| 65 |
} else { |
| 66 |
assert(O->isUse() && "Reg operand not a def and not a use"); |
| 67 |
UsedRegUnits.addReg(Reg); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
void init(const TargetRegisterInfo &TRI) { |
| 74 |
this->TRI = &TRI; |
| 75 |
Units.reset(); |
| 76 |
Units.resize(TRI.getNumRegUnits()); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
void clear() { Units.reset(); } |
| 81 |
|
| 82 |
|
| 83 |
bool empty() const { return Units.none(); } |
| 84 |
|
| 85 |
|
| 86 |
void addReg(MCPhysReg Reg) { |
| 87 |
for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) |
| 88 |
Units.set(*Unit); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
void addRegMasked(MCPhysReg Reg, LaneBitmask Mask) { |
| 94 |
for (MCRegUnitMaskIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) { |
| 95 |
LaneBitmask UnitMask = (*Unit).second; |
| 96 |
if (UnitMask.none() || (UnitMask & Mask).any()) |
| 97 |
Units.set((*Unit).first); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
void removeReg(MCPhysReg Reg) { |
| 103 |
for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) |
| 104 |
Units.reset(*Unit); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
void removeRegsNotPreserved(const uint32_t *RegMask); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
void addRegsInMask(const uint32_t *RegMask); |
| 114 |
|
| 115 |
|
| 116 |
bool available(MCPhysReg Reg) const { |
| 117 |
for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) { |
| 118 |
if (Units.test(*Unit)) |
| 119 |
return false; |
| 120 |
} |
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
void stepBackward(const MachineInstr &MI); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
void accumulate(const MachineInstr &MI); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
void addLiveOuts(const MachineBasicBlock &MBB); |
| 139 |
|
| 140 |
|
| 141 |
void addLiveIns(const MachineBasicBlock &MBB); |
| 142 |
|
| 143 |
|
| 144 |
void addUnits(const BitVector &RegUnits) { |
| 145 |
Units |= RegUnits; |
| 146 |
} |
| 147 |
|
| 148 |
void removeUnits(const BitVector &RegUnits) { |
| 149 |
Units.reset(RegUnits); |
| 150 |
} |
| 151 |
|
| 152 |
const BitVector &getBitVector() const { |
| 153 |
return Units; |
| 154 |
} |
| 155 |
|
| 156 |
private: |
| 157 |
|
| 158 |
|
| 159 |
void addPristines(const MachineFunction &MF); |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
inline iterator_range<filter_iterator< |
| 165 |
ConstMIBundleOperands, std::function<bool(const MachineOperand &)>>> |
| 166 |
phys_regs_and_masks(const MachineInstr &MI) { |
| 167 |
std::function<bool(const MachineOperand &)> Pred = |
| 168 |
[](const MachineOperand &MOP) { |
| 169 |
return MOP.isRegMask() || (MOP.isReg() && !MOP.isDebug() && |
| 170 |
Register::isPhysicalRegister(MOP.getReg())); |
| 171 |
}; |
| 172 |
return make_filter_range(const_mi_bundle_ops(MI), Pred); |
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
#endif |