103#define DEBUG_TYPE "aarch64-srlt-define-superregs"
104#define PASS_NAME "AArch64 SRLT Define Super-Regs Pass"
108class AArch64SRLTDefineSuperRegsImpl {
122 inline static char ID = 0;
127 return AArch64SRLTDefineSuperRegsImpl().run(MF);
151Register AArch64SRLTDefineSuperRegsImpl::getWidestSuperReg(
155 "Expected to be run straight after virtregrewriter!");
158 for (MCRegUnit U :
TRI->regunits(R))
159 Units.
set((
unsigned)U);
161 auto IsSuitableSuperReg = [&](
Register SR) {
162 for (MCRegUnit U :
TRI->regunits(SR)) {
167 if (QHiRegUnits.test((
unsigned)U) &&
168 !Subtarget->isSVEorStreamingSVEAvailable())
174 if (!
TRI->isArtificialRegUnit(U) &&
175 (!Units.
test((
unsigned)U) || !RequiredBaseRegUnits.test((
unsigned)U)))
181 Register LargestSuperReg = AArch64::NoRegister;
183 if (IsSuitableSuperReg(SR) && (LargestSuperReg == AArch64::NoRegister ||
184 TRI->isSuperRegister(LargestSuperReg, SR)))
185 LargestSuperReg = SR;
187 return LargestSuperReg;
193 const MachineRegisterInfo *MRI = &MF.
getRegInfo();
198 assert(!MRI->
isSSA() &&
"Expected to be run after breaking down SSA form!");
202 constexpr unsigned FixedRegs[] = {AArch64::FP, AArch64::LR, AArch64::SP};
204 BitVector RequiredBaseRegUnits(
TRI->getNumRegUnits());
206 for (MCRegUnit U :
TRI->regunits(R))
207 RequiredBaseRegUnits.set((
unsigned)U);
209 BitVector QHiRegUnits(
TRI->getNumRegUnits());
211 for (MCRegUnit U :
TRI->regunits(R))
212 QHiRegUnits.set((
unsigned)U);
215 for (MachineBasicBlock &
MBB : MF) {
216 for (MachineInstr &
MI :
MBB) {
218 if (
MI.getOpcode() == TargetOpcode::PATCHPOINT)
222 SmallSet<Register, 8> SuperRegs;
223 for (
const MachineOperand &DefOp :
MI.defs())
224 if (
Register R = getWidestSuperReg(DefOp.getReg(), RequiredBaseRegUnits,
226 R != AArch64::NoRegister)
229 if (!SuperRegs.
size())
235 bool IsRenamable =
any_of(
MI.defs(), [&](
const MachineOperand &MO) {
236 return MO.isRenamable() && TRI->regsOverlap(MO.getReg(), R);
239 return MO.isDead() && TRI->regsOverlap(MO.getReg(), R);
242 R,
true,
true,
false,
246 MI.addOperand(DefOp);
256 return new AArch64SRLTDefineSuperRegsLegacy();
262 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.