102#define DEBUG_TYPE "aarch64-srlt-define-superregs"
103#define PASS_NAME "AArch64 SRLT Define Super-Regs Pass"
107class AArch64SRLTDefineSuperRegsImpl {
121 inline static char ID = 0;
126 return AArch64SRLTDefineSuperRegsImpl().run(MF);
152Register AArch64SRLTDefineSuperRegsImpl::getWidestSuperReg(
156 "Expected to be run straight after virtregrewriter!");
159 for (MCRegUnit U :
TRI->regunits(R))
160 Units.
set((
unsigned)U);
162 auto IsSuitableSuperReg = [&](
Register SR) {
163 for (MCRegUnit U :
TRI->regunits(SR)) {
168 if (QHiRegUnits.test((
unsigned)U) &&
169 !Subtarget->isSVEorStreamingSVEAvailable())
175 if (!
TRI->isArtificialRegUnit(U) &&
176 (!Units.
test((
unsigned)U) || !RequiredBaseRegUnits.test((
unsigned)U)))
182 Register LargestSuperReg = AArch64::NoRegister;
184 if (IsSuitableSuperReg(SR) && (LargestSuperReg == AArch64::NoRegister ||
185 TRI->isSuperRegister(LargestSuperReg, SR)))
186 LargestSuperReg = SR;
188 return LargestSuperReg;
194 const MachineRegisterInfo *MRI = &MF.
getRegInfo();
199 assert(!MRI->
isSSA() &&
"Expected to be run after breaking down SSA form!");
203 constexpr unsigned FixedRegs[] = {AArch64::FP, AArch64::LR, AArch64::SP};
205 BitVector RequiredBaseRegUnits(
TRI->getNumRegUnits());
207 for (MCRegUnit U :
TRI->regunits(R))
208 RequiredBaseRegUnits.set((
unsigned)U);
210 BitVector QHiRegUnits(
TRI->getNumRegUnits());
212 for (MCRegUnit U :
TRI->regunits(R))
213 QHiRegUnits.set((
unsigned)U);
216 for (MachineBasicBlock &
MBB : MF) {
217 for (MachineInstr &
MI :
MBB) {
219 if (
MI.getOpcode() == TargetOpcode::PATCHPOINT)
223 SmallSet<Register, 8> SuperRegs;
224 for (
const MachineOperand &DefOp :
MI.defs())
225 if (
Register R = getWidestSuperReg(DefOp.getReg(), RequiredBaseRegUnits,
227 R != AArch64::NoRegister)
230 if (!SuperRegs.
size())
236 bool IsRenamable =
any_of(
MI.defs(), [&](
const MachineOperand &MO) {
237 return MO.isRenamable() && TRI->regsOverlap(MO.getReg(), R);
240 return MO.isDead() && TRI->regsOverlap(MO.getReg(), R);
243 R,
true,
true,
false,
247 MI.addOperand(DefOp);
257 return new AArch64SRLTDefineSuperRegsLegacy();
263 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.
AnalysisUsage & addPreservedID(const void *ID)
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
auto seq_inclusive(T Begin, T End)
Iterate over an integral type from Begin to End inclusive.
LLVM_ABI char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
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.
LLVM_ABI char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
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.