100#define DEBUG_TYPE "aarch64-srlt-define-superregs"
101#define PASS_NAME "AArch64 SRLT Define Super-Regs Pass"
105class AArch64SRLTDefineSuperRegsImpl {
119 inline static char ID = 0;
124 return AArch64SRLTDefineSuperRegsImpl().run(MF);
148Register AArch64SRLTDefineSuperRegsImpl::getWidestSuperReg(
152 "Expected to be run straight after virtregrewriter!");
155 for (MCRegUnit U :
TRI->regunits(R))
156 Units.
set((
unsigned)U);
158 auto IsSuitableSuperReg = [&](
Register SR) {
159 for (MCRegUnit U :
TRI->regunits(SR)) {
164 if (QHiRegUnits.test((
unsigned)U) &&
165 !Subtarget->isSVEorStreamingSVEAvailable())
171 if (!
TRI->isArtificialRegUnit(U) &&
172 (!Units.
test((
unsigned)U) || !RequiredBaseRegUnits.test((
unsigned)U)))
178 Register LargestSuperReg = AArch64::NoRegister;
180 if (IsSuitableSuperReg(SR) && (LargestSuperReg == AArch64::NoRegister ||
181 TRI->isSuperRegister(LargestSuperReg, SR)))
182 LargestSuperReg = SR;
184 return LargestSuperReg;
190 const MachineRegisterInfo *MRI = &MF.
getRegInfo();
195 assert(!MRI->
isSSA() &&
"Expected to be run after breaking down SSA form!");
199 constexpr unsigned FixedRegs[] = {AArch64::FP, AArch64::LR, AArch64::SP};
201 BitVector RequiredBaseRegUnits(
TRI->getNumRegUnits());
203 for (MCRegUnit U :
TRI->regunits(R))
204 RequiredBaseRegUnits.set((
unsigned)U);
206 BitVector QHiRegUnits(
TRI->getNumRegUnits());
208 for (MCRegUnit U :
TRI->regunits(R))
209 QHiRegUnits.set((
unsigned)U);
212 for (MachineBasicBlock &
MBB : MF) {
213 for (MachineInstr &
MI :
MBB) {
215 if (
MI.getOpcode() == TargetOpcode::PATCHPOINT)
219 SmallSet<Register, 8> SuperRegs;
220 for (
const MachineOperand &DefOp :
MI.defs())
221 if (
Register R = getWidestSuperReg(DefOp.getReg(), RequiredBaseRegUnits,
223 R != AArch64::NoRegister)
226 if (!SuperRegs.
size())
232 bool IsRenamable =
any_of(
MI.defs(), [&](
const MachineOperand &MO) {
233 return MO.isRenamable() && TRI->regsOverlap(MO.getReg(), R);
236 return MO.isDead() && TRI->regsOverlap(MO.getReg(), R);
239 R,
true,
true,
false,
243 MI.addOperand(DefOp);
253 return new AArch64SRLTDefineSuperRegsLegacy();
259 const bool Changed = AArch64SRLTDefineSuperRegsImpl().run(MF);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallSet class.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
const AArch64RegisterInfo * getRegisterInfo() const override
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool test(unsigned Idx) const
Returns true if bit Idx is set.
BitVector & set()
Set all bits in the bitvector.
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
bool subRegLivenessEnabled() const
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Wrapper class representing virtual and physical registers.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
constexpr auto seq_inclusive(T Begin, T End)
Iterate over an integral type from Begin to End inclusive.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createAArch64SRLTDefineSuperRegsLegacyPass()
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.