31#define DEBUG_TYPE "delay-slot-filler"
33STATISTIC(FilledSlots,
"Number of delay slots filled");
40 StringRef getPassName()
const override {
return "SPARC Delay Slot Filler"; }
44 MachineFunctionProperties getRequiredProperties()
const override {
45 return MachineFunctionProperties().setNoVRegs();
48 void getAnalysisUsage(AnalysisUsage &AU)
const override {
53char SparcDelaySlotFillerLegacy::ID = 0;
60 return new SparcDelaySlotFillerLegacy;
73 Register reg = AddMI->getOperand(0).getReg();
74 if (reg < SP::I0 || reg > SP::I7)
80 bool IsCall = LastInst !=
MBB.end() && LastInst->isCall();
82 if (IsCall && AddMI->getOpcode() == SP::ADDrr &&
83 AddMI->readsRegister(SP::O7,
TRI))
86 if (IsCall && AddMI->getOpcode() == SP::ADDri &&
87 AddMI->readsRegister(SP::O7,
TRI))
91 RestoreMI->eraseFromParent();
94 AddMI->setDesc(
TII->get((AddMI->getOpcode() == SP::ADDrr) ? SP::RESTORErr
98 AddMI->getOperand(0).setReg(reg - SP::I0 + SP::O0);
114 Register reg = OrMI->getOperand(0).getReg();
115 if (reg < SP::I0 || reg > SP::I7)
119 if (OrMI->getOpcode() == SP::ORrr && OrMI->getOperand(1).getReg() != SP::G0 &&
120 OrMI->getOperand(2).getReg() != SP::G0)
123 if (OrMI->getOpcode() == SP::ORri && OrMI->getOperand(1).getReg() != SP::G0 &&
124 (!OrMI->getOperand(2).isImm() || OrMI->getOperand(2).getImm() != 0))
130 bool IsCall = LastInst !=
MBB.end() && LastInst->isCall();
132 if (IsCall && OrMI->getOpcode() == SP::ORrr &&
133 OrMI->readsRegister(SP::O7,
TRI))
137 RestoreMI->eraseFromParent();
140 OrMI->setDesc(
TII->get((OrMI->getOpcode() == SP::ORrr) ? SP::RESTORErr
144 OrMI->getOperand(0).setReg(reg - SP::I0 + SP::O0);
157 Register reg = SetHiMI->getOperand(0).getReg();
158 if (reg < SP::I0 || reg > SP::I7)
161 if (!SetHiMI->getOperand(1).isImm())
164 int64_t imm = SetHiMI->getOperand(1).getImm();
171 imm = (imm << 10) & 0x1FFF;
173 assert(RestoreMI->getOpcode() == SP::RESTORErr);
175 RestoreMI->setDesc(
TII->get(SP::RESTOREri));
177 RestoreMI->getOperand(0).setReg(reg - SP::I0 + SP::O0);
178 RestoreMI->getOperand(1).setReg(SP::G0);
179 RestoreMI->getOperand(2).ChangeToImmediate(imm);
182 SetHiMI->eraseFromParent();
196 MBBI->getOperand(0).getReg() == SP::G0 &&
197 MBBI->getOperand(1).getReg() == SP::G0 &&
198 MBBI->getOperand(2).getReg() == SP::G0);
204 if (PrevInst->isDebugInstr())
208 if (PrevInst->isBundledWithSucc())
217 if (PrevInst->getNumOperands() && PrevInst->getOperand(0).isReg())
219 if (
MI.isDebugValue() &&
220 MI.hasDebugOperandForReg(PrevInst->getOperand(0).getReg()))
223 bool Combined =
false;
224 switch (PrevInst->getOpcode()) {
241 MI->setDebugValueUndef();
252 unsigned Opc = slot->getOpcode();
253 if ((
Opc != SP::TAIL_CALL &&
Opc != SP::TAIL_CALLri) || slot ==
MBB.begin())
259 if (J->getOpcode() == SP::RESTORErr || J->getOpcode() == SP::RESTOREri)
261 if (
Opc == SP::TAIL_CALL && J->getOpcode() == SP::ORrr &&
262 J->getOperand(0).getReg() == SP::O7)
272 switch (
MI->getOpcode()) {
284 case SP::TAIL_CALLri:
287 assert(
Reg.isReg() &&
"CALL first operand is not a register.");
288 assert(
Reg.isUse() &&
"CALL first operand is not a use.");
294 assert(Operand1.
isReg() &&
"CALLrr second operand is not a register.");
295 assert(Operand1.
isUse() &&
"CALLrr second operand is not a use.");
318 if (MO.isImplicit() &&
MI->getOpcode() == SP::RETL)
331 if (RegSet.
count(*AI))
341 if (candidate->isImplicitDef() || candidate->isKill())
344 if (candidate->mayLoad()) {
350 if (candidate->mayStore()) {
377 unsigned Opcode = candidate->getOpcode();
382 Opcode >= SP::LDDArr && Opcode <= SP::LDrr)
385 if (
Subtarget->fixTN0009() && candidate->mayStore())
408 bool sawLoad =
false;
409 bool sawStore =
false;
411 if (slot ==
MBB.begin())
414 unsigned Opc = slot->getOpcode();
416 if (
Opc == SP::RET ||
Opc == SP::TLS_CALL)
419 if (
Opc == SP::RETL ||
Opc == SP::TAIL_CALL ||
Opc == SP::TAIL_CALLri) {
424 if (J->getOpcode() == SP::RESTORErr || J->getOpcode() == SP::RESTOREri) {
427 slot->setDesc(
Subtarget->getInstrInfo()->get(SP::RET));
443 done = (
I ==
MBB.begin());
449 if (
I->isMetaInstruction())
452 if (
I->hasUnmodeledSideEffects() ||
I->isInlineAsm() ||
I->isPosition() ||
453 I->hasDelaySlot() ||
I->isBundledWithSucc())
467 return (
MI.getOpcode() == SP::WRASRrr ||
MI.getOpcode() == SP::WRASRri) &&
468 MI.getOperand(0).getReg() == SP::Y;
488 for (
auto I =
MBB.instr_begin(),
E =
MBB.instr_end();
I !=
E; ++
I) {
490 if (
I->isMetaInstruction() ||
I->getOpcode() == SP::UNIMP)
498 while (Pos->isBundledWithPred())
500 for (; Since < 3; ++Since)
521 !
Subtarget->getCLOpts().disable_sparc_delay_filler &&
530 if (FillSlots && (
MI->getOpcode() == SP::RESTORErr ||
531 MI->getOpcode() == SP::RESTOREri)) {
539 (
MI->getOpcode() == SP::FCMPS ||
MI->getOpcode() == SP::FCMPD ||
540 MI->getOpcode() == SP::FCMPQ ||
MI->getOpcode() == SP::FCMPES ||
541 MI->getOpcode() == SP::FCMPED ||
MI->getOpcode() == SP::FCMPEQ)) {
548 if (!
MI->hasDelaySlot())
553 if (
D ==
MBB.end() && FillSlots)
564 unsigned structSize = 0;
565 if (
TII->needsUnimp(*
MI, structSize)) {
568 assert(J !=
MBB.end() &&
"MI needs a delay instruction.");
593bool SparcDelaySlotFillerLegacy::runOnMachineFunction(
MachineFunction &MF) {
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool tryCombineRestoreWithPrevInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const SparcSubtarget *Subtarget)
static void insertDefsUses(MachineBasicBlock::iterator MI, SmallSet< unsigned, 32 > &RegDefs, SmallSet< unsigned, 32 > &RegUses, const SparcSubtarget *Subtarget)
static bool combineRestoreADD(MachineBasicBlock &MBB, MachineBasicBlock::iterator RestoreMI, MachineBasicBlock::iterator AddMI, const TargetInstrInfo *TII)
static void insertCallDefsUses(MachineBasicBlock::iterator MI, SmallSet< unsigned, 32 > &RegDefs, SmallSet< unsigned, 32 > &RegUses)
static bool combineRestoreSETHIi(MachineBasicBlock::iterator RestoreMI, MachineBasicBlock::iterator SetHiMI, const TargetInstrInfo *TII)
static MachineBasicBlock::iterator findRequiredDelayInstr(MachineBasicBlock &MBB, MachineBasicBlock::iterator slot)
The restore before a tail call must run in its delay slot: jmp reg reads a register of the current wi...
static bool runDelaySlotFillerOnMachineFunction(MachineFunction &MF)
static bool runOnMachineBasicBlock(MachineBasicBlock &MBB)
runOnMachineBasicBlock - Fill in delay slots for the given basic block.
static MachineBasicBlock::iterator findDelayInstr(MachineBasicBlock &MBB, MachineBasicBlock::iterator slot, const SparcSubtarget *Subtarget)
static bool combineRestoreOR(MachineBasicBlock &MBB, MachineBasicBlock::iterator RestoreMI, MachineBasicBlock::iterator OrMI, const TargetInstrInfo *TII)
static bool isWriteY(const MachineInstr &MI)
static bool padWriteYHazards(MachineBasicBlock &MBB, const SparcSubtarget *Subtarget)
On SPARC V8 a write to y may take until the third instruction after it completes to take effect,...
static bool delayHasHazard(MachineBasicBlock::iterator candidate, bool &sawLoad, bool &sawStore, SmallSet< unsigned, 32 > &RegDefs, SmallSet< unsigned, 32 > &RegUses, const SparcSubtarget *Subtarget)
static bool IsRegInSet(SmallSet< unsigned, 32 > &RegSet, unsigned Reg, const SparcSubtarget *Subtarget)
Register const TargetRegisterInfo * TRI
This file defines the SmallSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool readsRegister(const MCInst &Inst, const MCInstrDesc &Desc, MCRegister Reg, const MCRegisterInfo &RI)
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.
FunctionPass class - This class is used to implement most global optimizations.
MCRegAliasIterator enumerates all registers aliasing Reg.
An RAII based helper class to modify MachineFunctionProperties when running pass.
Helper class for constructing bundles of MachineInstrs.
MachineInstrBundleIterator< MachineInstr > iterator
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
IterT skipMetaInstructionsBackward(IterT It, IterT Begin)
Decrement It until it points to a non-meta instruction or to Begin and return the resulting iterator.
IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
FunctionPass * createSparcDelaySlotFillerLegacyPass()
createSparcDelaySlotFillerPass - Returns a pass that fills in delay slots in Sparc MachineFunctions