49#define DEBUG_TYPE "riscv-init-undef"
50#define RISCV_INIT_UNDEF_NAME "RISC-V init undef pass"
82 bool isVectorRegClass(
const Register R);
91char RISCVInitUndef::ID = 0;
97 if (RISCV::VRM8RegClass.hasSubClassEq(RC))
98 return &RISCV::VRM8RegClass;
99 if (RISCV::VRM4RegClass.hasSubClassEq(RC))
100 return &RISCV::VRM4RegClass;
101 if (RISCV::VRM2RegClass.hasSubClassEq(RC))
102 return &RISCV::VRM2RegClass;
103 if (RISCV::VRRegClass.hasSubClassEq(RC))
104 return &RISCV::VRRegClass;
108bool RISCVInitUndef::isVectorRegClass(
const Register R) {
110 return RISCV::VRRegClass.hasSubClassEq(RC) ||
111 RISCV::VRM2RegClass.hasSubClassEq(RC) ||
112 RISCV::VRM4RegClass.hasSubClassEq(RC) ||
113 RISCV::VRM8RegClass.hasSubClassEq(RC);
117 switch (RegClassID) {
118 case RISCV::VRRegClassID:
119 return RISCV::PseudoRVVInitUndefM1;
120 case RISCV::VRM2RegClassID:
121 return RISCV::PseudoRVVInitUndefM2;
122 case RISCV::VRM4RegClassID:
123 return RISCV::PseudoRVVInitUndefM4;
124 case RISCV::VRM8RegClassID:
125 return RISCV::PseudoRVVInitUndefM8;
133 return DefMO.isReg() && DefMO.isEarlyClobber();
139 assert(Inst->getOpcode() == TargetOpcode::IMPLICIT_DEF);
142 if (!
Reg.isVirtual())
145 bool HasOtherUse =
false;
149 if (MO.isUse() && !MO.isTied())
160 dbgs() <<
"Emitting PseudoRVVInitUndef for implicit vector register "
164 getVRLargestSuperClass(
MRI->getRegClass(Reg));
169 NewDest =
MRI->createVirtualRegister(TargetRegClass);
172 NewRegs.insert(NewDest);
174 BuildMI(
MBB, Inst, Inst->getDebugLoc(),
TII->get(Opcode), NewDest);
179 for (
auto MO : UseMOs) {
181 MO->setIsUndef(
false);
188 bool Changed =
false;
193 if (!UseMO.getReg().isVirtual())
199 if (NewRegs.count(Reg))
204 if (
Info.UsedLanes ==
Info.DefinedLanes)
208 getVRLargestSuperClass(
MRI->getRegClass(Reg));
213 dbgs() <<
"Instruction has undef subregister.\n";
221 TRI->getCoveringSubRegIndexes(*
MRI, TargetRegClass, NeedDef,
222 SubRegIndexNeedInsert);
225 for (
auto ind : SubRegIndexNeedInsert) {
228 getVRLargestSuperClass(
TRI->getSubRegisterClass(TargetRegClass, ind));
229 Register TmpInitSubReg =
MRI->createVirtualRegister(SubRegClass);
233 Register NewReg =
MRI->createVirtualRegister(TargetRegClass);
235 TII->get(TargetOpcode::INSERT_SUBREG), NewReg)
242 UseMO.setReg(LatestReg);
251 bool Changed =
false;
258 if (
MI.getNumDefs() != 0 &&
MI.isRegTiedToUseOperand(0, &UseOpIdx)) {
260 if (UseMO.
getReg() == RISCV::NoRegister) {
262 TII->getRegClass(
MI.getDesc(), UseOpIdx,
TRI, MF);
266 NewRegs.insert(NewDest);
268 TII->get(TargetOpcode::IMPLICIT_DEF), NewDest);
275 Changed |= handleSubReg(MF,
MI, DLD);
276 if (
MI.isImplicitDef()) {
277 auto DstReg =
MI.getOperand(0).getReg();
278 if (isVectorRegClass(DstReg))
279 Changed |= handleImplicitDef(
MBB,
I);
287 if (!
ST->hasVInstructions())
291 TII =
ST->getInstrInfo();
292 TRI =
MRI->getTargetRegisterInfo();
294 bool Changed =
false;
299 Changed |= processBasicBlock(MF, BB, DLD);
unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool isEarlyClobberMI(MachineInstr &MI)
static unsigned getUndefInitOpcode(unsigned RegClassID)
#define RISCV_INIT_UNDEF_NAME
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void computeSubRegisterLaneBitInfo()
Update the DefinedLanes and the UsedLanes for all virtual registers.
const VRegInfo & getVRegInfo(unsigned RegIdx) const
FunctionPass class - This class is used to implement most global optimizations.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
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.
void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
void push_back(const T &Elt)
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
void initializeRISCVInitUndefPass(PassRegistry &)
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createRISCVInitUndefPass()
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...