28 #define DEBUG_TYPE "delay-slot-filler" 30 STATISTIC(FilledSlots,
"Number of delay slots filled");
33 "disable-sparc-delay-filler",
35 cl::desc(
"Disable the Sparc delay slot filler."),
45 StringRef getPassName()
const override {
return "SPARC Delay Slot Filler"; }
58 Changed |= runOnMachineBasicBlock(*FI);
79 bool &sawLoad,
bool &sawStore,
107 bool Changed =
false;
117 (MI->getOpcode() == SP::RESTORErr
118 || MI->getOpcode() == SP::RESTOREri)) {
119 Changed |= tryCombineRestoreWithPrevInst(MBB, MI);
125 if (!Subtarget->
isV9() &&
126 (MI->getOpcode() == SP::FCMPS || MI->getOpcode() == SP::FCMPD
127 || MI->getOpcode() == SP::FCMPQ)) {
128 BuildMI(MBB,
I, MI->getDebugLoc(), TII->get(SP::NOP));
134 if (!MI->hasDelaySlot())
140 D = findDelayInstr(MBB, MI);
146 BuildMI(MBB,
I, MI->getDebugLoc(), TII->get(SP::NOP));
150 unsigned structSize = 0;
151 if (needsUnimp(MI, structSize)) {
154 assert (J != MBB.
end() &&
"MI needs a delay instruction.");
155 BuildMI(MBB, ++J, MI->getDebugLoc(),
156 TII->get(SP::UNIMP)).addImm(structSize);
172 bool sawLoad =
false;
173 bool sawStore =
false;
175 if (slot == MBB.
begin())
181 if (slot->getOpcode() == SP::RETL) {
185 if (J->getOpcode() == SP::RESTORErr
186 || J->getOpcode() == SP::RESTOREri) {
195 insertCallDefsUses(slot, RegDefs, RegUses);
197 insertDefsUses(slot, RegDefs, RegUses);
204 done = (I == MBB.
begin());
210 if (I->isDebugInstr())
213 if (I->hasUnmodeledSideEffects() || I->isInlineAsm() || I->isPosition() ||
214 I->hasDelaySlot() || I->isBundledWithSucc())
217 if (delayHasHazard(I, sawLoad, sawStore, RegDefs, RegUses)) {
218 insertDefsUses(I, RegDefs, RegUses);
234 if (candidate->isImplicitDef() || candidate->isKill())
237 if (candidate->mayLoad()) {
243 if (candidate->mayStore()) {
251 for (
unsigned i = 0,
e = candidate->getNumOperands(); i!=
e; ++i) {
260 if (IsRegInSet(RegDefs, Reg) || IsRegInSet(RegUses, Reg))
265 if (IsRegInSet(RegDefs, Reg))
270 unsigned Opcode = candidate->getOpcode();
275 Opcode >= SP::LDDArr && Opcode <= SP::LDrr)
281 Opcode >= SP::FDIVD && Opcode <= SP::FSQRTD)
296 switch(MI->getOpcode()) {
301 assert(MI->getNumOperands() >= 2);
303 assert(Reg.isReg() &&
"CALL first operand is not a register.");
304 assert(Reg.isUse() &&
"CALL first operand is not a use.");
305 RegUses.
insert(Reg.getReg());
310 assert(Operand1.
isReg() &&
"CALLrr second operand is not a register.");
311 assert(Operand1.
isUse() &&
"CALLrr second operand is not a use.");
322 for (
unsigned i = 0,
e = MI->getNumOperands(); i !=
e; ++i) {
335 if (MO.
isImplicit() && MI->getOpcode() == SP::RETL)
348 if (RegSet.
count(*AI))
358 unsigned structSizeOpNum = 0;
359 switch (I->getOpcode()) {
361 case SP::CALL: structSizeOpNum = 1;
break;
363 case SP::CALLri: structSizeOpNum = 2;
break;
383 Register reg = AddMI->getOperand(0).getReg();
384 if (reg < SP::I0 || reg > SP::I7)
388 RestoreMI->eraseFromParent();
391 AddMI->setDesc(TII->
get((AddMI->getOpcode() == SP::ADDrr)
396 AddMI->getOperand(0).setReg(reg - SP::I0 + SP::O0);
411 Register reg = OrMI->getOperand(0).getReg();
412 if (reg < SP::I0 || reg > SP::I7)
416 if (OrMI->getOpcode() == SP::ORrr
417 && OrMI->getOperand(1).getReg() != SP::G0
418 && OrMI->getOperand(2).getReg() != SP::G0)
421 if (OrMI->getOpcode() == SP::ORri
422 && OrMI->getOperand(1).getReg() != SP::G0
423 && (!OrMI->getOperand(2).isImm() || OrMI->getOperand(2).getImm() != 0))
427 RestoreMI->eraseFromParent();
430 OrMI->setDesc(TII->
get((OrMI->getOpcode() == SP::ORrr)
435 OrMI->getOperand(0).setReg(reg - SP::I0 + SP::O0);
449 Register reg = SetHiMI->getOperand(0).getReg();
450 if (reg < SP::I0 || reg > SP::I7)
453 if (!SetHiMI->getOperand(1).isImm())
456 int64_t imm = SetHiMI->getOperand(1).getImm();
463 imm = (imm << 10) & 0x1FFF;
465 assert(RestoreMI->getOpcode() == SP::RESTORErr);
467 RestoreMI->setDesc(TII->
get(SP::RESTOREri));
469 RestoreMI->getOperand(0).setReg(reg - SP::I0 + SP::O0);
470 RestoreMI->getOperand(1).setReg(SP::G0);
471 RestoreMI->getOperand(2).ChangeToImmediate(imm);
475 SetHiMI->eraseFromParent();
484 if (MBBI == MBB.
begin())
488 assert(MBBI->getOpcode() == SP::RESTORErr
489 && MBBI->getOperand(0).getReg() == SP::G0
490 && MBBI->getOperand(1).getReg() == SP::G0
491 && MBBI->getOperand(2).getReg() == SP::G0);
496 if (PrevInst->isBundledWithSucc())
501 switch (PrevInst->getOpcode()) {
This class represents lattice values for constants.
FunctionPass * createSparcDelaySlotFillerPass()
createSparcDelaySlotFillerPass - Returns a pass that fills in delay slots in Sparc MachineFunctions ...
STATISTIC(NumFunctions, "Total number of functions")
const SparcInstrInfo * getInstrInfo() const override
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static bool combineRestoreOR(MachineBasicBlock::iterator RestoreMI, MachineBasicBlock::iterator OrMI, const TargetInstrInfo *TII)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool insertNOPLoad() const
bool fixAllFDIVSQRT() const
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
static bool combineRestoreSETHIi(MachineBasicBlock::iterator RestoreMI, MachineBasicBlock::iterator SetHiMI, const TargetInstrInfo *TII)
MCRegAliasIterator enumerates all registers aliasing Reg.
FunctionPass class - This class is used to implement most global optimizations.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const SparcRegisterInfo * getRegisterInfo() const override
static cl::opt< bool > DisableDelaySlotFiller("disable-sparc-delay-filler", cl::init(false), cl::desc("Disable the Sparc delay slot filler."), cl::Hidden)
Iterator for intrusive lists based on ilist_node.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperand class - Representation of each machine instruction operand.
static bool combineRestoreADD(MachineBasicBlock::iterator RestoreMI, MachineBasicBlock::iterator AddMI, const TargetInstrInfo *TII)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
MachineFunctionProperties & set(Property P)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
Properties which a MachineFunction may have at a given point in time.
Wrapper class representing virtual and physical registers.
Helper class for constructing bundles of MachineInstrs.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.