58#define DEBUG_TYPE "init-undef"
59#define INIT_UNDEF_NAME "Init Undef Pass"
103char InitUndefLegacy::ID = 0;
109 return DefMO.isReg() && DefMO.isEarlyClobber();
114 for (
auto &
DefMI :
MRI->def_instructions(Reg)) {
115 if (
DefMI.getOpcode() == TargetOpcode::IMPLICIT_DEF)
122 bool Changed =
false;
123 for (
auto &UseMO :
MI->uses()) {
128 if (!UseMO.getReg().isVirtual())
132 Changed |= fixupIllOperand(
MI, UseMO);
139 bool Changed =
false;
144 if (!UseMO.getReg().isVirtual())
150 if (NewRegs.count(Reg))
154 if (
Info.UsedLanes ==
Info.DefinedLanes)
162 dbgs() <<
"Instruction has undef subregister.\n";
170 TRI->getCoveringSubRegIndexes(TargetRegClass, NeedDef,
171 SubRegIndexNeedInsert);
176 if (
any_of(SubRegIndexNeedInsert, [&](
unsigned Ind) ->
bool {
177 return !
TRI->getSubRegisterClass(TargetRegClass, Ind);
182 for (
auto ind : SubRegIndexNeedInsert) {
185 TRI->getSubRegisterClass(TargetRegClass, ind);
186 Register TmpInitSubReg =
MRI->createVirtualRegister(SubRegClass);
189 TII->get(TargetOpcode::INIT_UNDEF), TmpInitSubReg);
190 Register NewReg =
MRI->createVirtualRegister(TargetRegClass);
192 TII->get(TargetOpcode::INSERT_SUBREG), NewReg)
199 UseMO.setReg(LatestReg);
208 dbgs() <<
"Emitting PseudoInitUndef Instruction for implicit register "
213 Register NewReg =
MRI->createVirtualRegister(TargetRegClass);
215 TII->get(TargetOpcode::INIT_UNDEF), NewReg);
224 bool Changed =
false;
231 if (
MI.getNumDefs() != 0 &&
MI.isRegTiedToUseOperand(0, &UseOpIdx)) {
235 TII->getRegClass(
MI.getDesc(), UseOpIdx,
TRI, MF);
239 NewRegs.insert(NewDest);
240 BuildMI(
MBB,
I,
I->getDebugLoc(),
TII->get(TargetOpcode::IMPLICIT_DEF),
248 if (
MRI->subRegLivenessEnabled())
249 Changed |= handleSubReg(MF,
MI, *DLD);
250 Changed |= handleReg(&
MI);
257 return InitUndef().run(MF);
262 if (!InitUndef().
run(MF))
274 if (!ST->requiresDisjointEarlyClobberAndUndef())
278 TII = ST->getInstrInfo();
279 TRI =
MRI->getTargetRegisterInfo();
281 bool Changed =
false;
282 std::unique_ptr<DeadLaneDetector> DLD;
283 if (
MRI->subRegLivenessEnabled()) {
284 DLD = std::make_unique<DeadLaneDetector>(
MRI,
TRI);
285 DLD->computeSubRegisterLaneBitInfo();
289 Changed |= processBasicBlock(MF, BB, DLD.get());
291 for (
auto *DeadMI : DeadInsts)
292 DeadMI->eraseFromParent();
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
Analysis containing CSE Info
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
const HexagonInstrInfo * TII
static bool isEarlyClobberMI(MachineInstr &MI)
static bool findImplictDefMIFromReg(Register Reg, MachineRegisterInfo *MRI)
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallSet class.
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
const VRegInfo & getVRegInfo(unsigned RegIdx) const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
static constexpr unsigned NoRegister
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
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.
Wrapper class representing virtual and physical registers.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getID() const
Return the register class ID number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI char & InitUndefID
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
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.
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.
Contains a bitmask of which lanes of a given virtual register are defined and which ones are actually...