45 #define DEBUG_TYPE "a15-sd-optimizer" 54 StringRef getPassName()
const override {
return "ARM A15 S->D optimizer"; }
78 const DebugLoc &DL,
unsigned Ssub0,
unsigned Ssub1);
88 unsigned Lane,
unsigned ToInsert);
100 unsigned getDPRLaneFromSPR(
unsigned SReg);
113 unsigned optimizeAllLanesPattern(
MachineInstr *MI,
unsigned Reg);
115 unsigned getPrefSPRLane(
unsigned SReg);
125 std::map<MachineInstr*, unsigned> Replacements;
126 std::set<MachineInstr *> DeadInstr;
139 return MRI->getRegClass(Reg)->hasSuperClassEq(TRC);
144 unsigned A15SDOptimizer::getDPRLaneFromSPR(
unsigned SReg) {
145 unsigned DReg =
TRI->getMatchingSuperReg(SReg, ARM::ssub_1,
147 if (DReg != ARM::NoRegister)
return ARM::ssub_1;
153 unsigned A15SDOptimizer::getPrefSPRLane(
unsigned SReg) {
155 return getDPRLaneFromSPR(SReg);
158 if (!MI)
return ARM::ssub_0;
160 if (!MO)
return ARM::ssub_0;
161 assert(MO->
isReg() &&
"Non-register operand found!");
164 &ARM::SPRRegClass)) {
169 if (MO->
getSubReg() == ARM::ssub_1)
return ARM::ssub_1;
172 return getDPRLaneFromSPR(SReg);
181 LLVM_DEBUG(
dbgs() <<
"Deleting base instruction " << *MI <<
"\n");
184 while (Front.
size() != 0) {
205 if (DeadInstr.find(Def) != DeadInstr.end())
213 if ((!MODef.isReg()) || (!MODef.isDef()))
224 if (DeadInstr.find(&
Use) == DeadInstr.end()) {
231 if (!IsDead)
continue;
234 DeadInstr.insert(Def);
241 unsigned A15SDOptimizer::optimizeSDPattern(
MachineInstr *MI) {
254 if (DPRMI && SPRMI) {
275 eraseInstrWithNoUses(MI);
288 &ARM::SPRRegClass)) {
291 unsigned NumImplicit = 0, NumTotal = 0;
292 unsigned NonImplicitReg = ~0U;
312 if (NumImplicit == NumTotal - 1)
313 return optimizeAllLanesPattern(MI, NonImplicitReg);
323 bool A15SDOptimizer::hasPartialWrite(
MachineInstr *MI) {
349 return elideCopies(Def);
354 void A15SDOptimizer::elideCopiesAndPHIs(
MachineInstr *MI,
358 std::set<MachineInstr *> Reached;
361 while (Front.
size() != 0) {
366 if (Reached.find(MI) != Reached.end())
405 if (!usesRegClass(MO, &ARM::DPRRegClass) &&
406 !usesRegClass(MO, &ARM::QPRRegClass) &&
407 !usesRegClass(MO, &ARM::DPairRegClass))
419 unsigned Lane,
bool QPR) {
421 MRI->createVirtualRegister(QPR ? &ARM::QPRRegClass : &ARM::DPRRegClass);
423 TII->get(QPR ? ARM::VDUPLN32q : ARM::VDUPLN32d), Out)
432 unsigned A15SDOptimizer::createExtractSubreg(
434 const DebugLoc &DL,
unsigned DReg,
unsigned Lane,
440 TII->get(TargetOpcode::COPY), Out)
441 .addReg(DReg, 0, Lane);
447 unsigned A15SDOptimizer::createRegSequence(
449 const DebugLoc &DL,
unsigned Reg1,
unsigned Reg2) {
450 Register Out =
MRI->createVirtualRegister(&ARM::QPRRegClass);
454 TII->get(TargetOpcode::REG_SEQUENCE), Out)
468 Register Out =
MRI->createVirtualRegister(&ARM::DPRRegClass);
469 BuildMI(MBB, InsertBefore, DL,
TII->get(ARM::VEXTd32), Out)
477 unsigned A15SDOptimizer::createInsertSubreg(
479 const DebugLoc &DL,
unsigned DReg,
unsigned Lane,
unsigned ToInsert) {
480 Register Out =
MRI->createVirtualRegister(&ARM::DPR_VFP2RegClass);
484 TII->get(TargetOpcode::INSERT_SUBREG), Out)
496 Register Out =
MRI->createVirtualRegister(&ARM::DPRRegClass);
500 TII->get(TargetOpcode::IMPLICIT_DEF), Out);
508 A15SDOptimizer::optimizeAllLanesPattern(
MachineInstr *MI,
unsigned Reg) {
517 if (
MRI->getRegClass(Reg)->hasSuperClassEq(&ARM::QPRRegClass) ||
518 MRI->getRegClass(Reg)->hasSuperClassEq(&ARM::DPairRegClass)) {
519 unsigned DSub0 = createExtractSubreg(MBB, InsertPt, DL, Reg,
520 ARM::dsub_0, &ARM::DPRRegClass);
521 unsigned DSub1 = createExtractSubreg(MBB, InsertPt, DL, Reg,
522 ARM::dsub_1, &ARM::DPRRegClass);
524 unsigned Out1 = createDupLane(MBB, InsertPt, DL, DSub0, 0);
525 unsigned Out2 = createDupLane(MBB, InsertPt, DL, DSub0, 1);
526 Out = createVExt(MBB, InsertPt, DL, Out1, Out2);
528 unsigned Out3 = createDupLane(MBB, InsertPt, DL, DSub1, 0);
529 unsigned Out4 = createDupLane(MBB, InsertPt, DL, DSub1, 1);
530 Out2 = createVExt(MBB, InsertPt, DL, Out3, Out4);
532 Out = createRegSequence(MBB, InsertPt, DL, Out, Out2);
534 }
else if (
MRI->getRegClass(Reg)->hasSuperClassEq(&ARM::DPRRegClass)) {
535 unsigned Out1 = createDupLane(MBB, InsertPt, DL, Reg, 0);
536 unsigned Out2 = createDupLane(MBB, InsertPt, DL, Reg, 1);
537 Out = createVExt(MBB, InsertPt, DL, Out1, Out2);
540 assert(
MRI->getRegClass(Reg)->hasSuperClassEq(&ARM::SPRRegClass) &&
541 "Found unexpected regclass!");
543 unsigned PrefLane = getPrefSPRLane(Reg);
546 case ARM::ssub_0: Lane = 0;
break;
547 case ARM::ssub_1: Lane = 1;
break;
552 bool UsesQPR = usesRegClass(MI->
getOperand(0), &ARM::QPRRegClass) ||
553 usesRegClass(MI->
getOperand(0), &ARM::DPairRegClass);
555 Out = createImplicitDef(MBB, InsertPt, DL);
556 Out = createInsertSubreg(MBB, InsertPt, DL, Out, PrefLane, Reg);
557 Out = createDupLane(MBB, InsertPt, DL, Out, Lane, UsesQPR);
558 eraseInstrWithNoUses(MI);
563 bool A15SDOptimizer::runOnInstruction(
MachineInstr *MI) {
610 elideCopiesAndPHIs(Def, DefSrcs);
615 if (Replacements.find(MI) != Replacements.end())
619 if (!hasPartialWrite(MI))
626 E =
MRI->use_end();
I !=
E; ++
I)
630 unsigned NewReg = optimizeSDPattern(MI);
641 MRI->constrainRegClass(NewReg,
MRI->getRegClass((*I)->getReg()));
645 (*I)->substVirtReg(NewReg, 0, *
TRI);
648 Replacements[
MI] = NewReg;
672 Replacements.clear();
676 Modified |= runOnInstruction(&MI);
688 return new A15SDOptimizer();
const MachineInstrBuilder & add(const MachineOperand &MO) const
FunctionPass * createA15SDOptimizerPass()
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
typename SuperClass::const_iterator const_iterator
This class represents lattice values for constants.
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getSubReg() const
bool isRegSequence() const
unsigned const TargetRegisterInfo * TRI
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.
iterator_range< mop_iterator > operands()
bool isCopyLike() const
Return true if the instruction behaves like a copy.
const ARMBaseInstrInfo * getInstrInfo() const override
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
A Use represents the edge between a Value definition and its users.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
FunctionPass class - This class is used to implement most global optimizations.
bool isImplicitDef() const
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 getNumExplicitOperands() const
Returns the number of non-implicit operands.
MachineOperand * findRegisterDefOperand(Register Reg, bool isDead=false, bool Overlap=false, const TargetRegisterInfo *TRI=nullptr)
Wrapper for findRegisterDefOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
MachineOperand class - Representation of each machine instruction operand.
bool isInsertSubreg() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
iterator insert(iterator I, T &&Elt)
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const ARMBaseRegisterInfo * getRegisterInfo() const override
bool useSplatVFPToNeon() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Wrapper class representing virtual and physical registers.