26 #define GET_INSTRINFO_CTOR_DTOR
27 #include "MipsGenInstrInfo.inc"
30 void MipsInstrInfo::anchor() {}
34 Subtarget(STI), UncondBrOpc(UncondBr) {}
54 BuildMI(MBB, MI, DL,
get(Mips::NOP));
72 void MipsInstrInfo::AnalyzeCondBr(
const MachineInstr *Inst,
unsigned Opc,
75 assert(getAnalyzableBrOpc(Opc) &&
"Not an analyzable branch");
83 for (
int i=0; i<NumOp-1; i++)
91 bool AllowModify)
const {
101 unsigned Opc = Cond[0].getImm();
105 for (
unsigned i = 1; i < Cond.
size(); ++i) {
107 "Cannot copy operand for conditional branch!");
118 int *BytesAdded)
const {
120 assert(TBB &&
"insertBranch must not be told to insert a fallthrough");
121 assert(!BytesAdded &&
"code size not handled");
129 "# of Mips branch conditions must be <= 3!");
133 BuildCondBr(MBB, TBB, DL, Cond);
143 BuildCondBr(MBB, TBB, DL, Cond);
148 int *BytesRemoved)
const {
149 assert(!BytesRemoved &&
"code size not handled");
155 while (I != REnd && I->isDebugValue())
165 for (removed = 0; I != REnd && removed < 2; ++
I, ++removed)
166 if (!getAnalyzableBrOpc(I->getOpcode()))
169 MBB.
erase((--I).getReverse(), FirstBr);
179 "Invalid Mips branch condition!");
192 while (I != REnd && I->isDebugValue())
195 if (I == REnd || !isUnpredicatedTerminator(*I)) {
203 unsigned LastOpc = LastInst->
getOpcode();
207 if (!getAnalyzableBrOpc(LastOpc))
211 unsigned SecondLastOpc = 0;
215 SecondLastInst = &*
I;
216 SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->
getOpcode());
219 if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc)
224 if (!SecondLastOpc) {
232 AnalyzeCondBr(LastInst, LastOpc, TBB, Cond);
238 if (++I != REnd && isUnpredicatedTerminator(*I))
241 BranchInstrs.
insert(BranchInstrs.
begin(), SecondLastInst);
261 AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
270 unsigned Opcode = I->getOpcode();
271 bool canUseShortMicroMipsCTI =
false;
282 canUseShortMicroMipsCTI =
true;
287 case Mips::PseudoReturn:
288 case Mips::PseudoIndirectBranch:
289 case Mips::TAILCALLREG:
290 canUseShortMicroMipsCTI =
true;
297 (I->getOperand(0).isReg() &&
298 (I->getOperand(0).getReg() == Mips::ZERO ||
299 I->getOperand(0).getReg() == Mips::ZERO_64)) &&
300 (I->getOperand(1).isReg() &&
301 (I->getOperand(1).getReg() == Mips::ZERO ||
302 I->getOperand(1).getReg() == Mips::ZERO_64)))
313 if (canUseShortMicroMipsCTI)
314 return Mips::BEQZC_MM;
315 else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
320 if (canUseShortMicroMipsCTI)
321 return Mips::BNEZC_MM;
322 else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
326 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
330 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
340 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
344 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
350 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
354 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
358 return Mips::BGTZC64;
360 return Mips::BGEZC64;
362 return Mips::BLTZC64;
364 return Mips::BLEZC64;
368 case Mips::PseudoReturn:
369 case Mips::PseudoIndirectBranch:
370 case Mips::TAILCALLREG:
371 if (canUseShortMicroMipsCTI)
372 return Mips::JRC16_MM;
374 case Mips::JALRPseudo:
377 case Mips::PseudoReturn64:
378 case Mips::PseudoIndirectBranch64:
379 case Mips::TAILCALLREG64:
381 case Mips::JALR64Pseudo:
382 return Mips::JIALC64;
417 case Mips::CONSTPOOL_ENTRY:
438 int ZeroOperandPosition = -1;
439 bool BranchWithZeroOperand =
false;
440 if (I->isBranch() && !I->isPseudo()) {
441 auto TRI = I->getParent()->getParent()->getSubtarget().getRegisterInfo();
442 ZeroOperandPosition = I->findRegisterUseOperandIdx(Mips::ZERO,
false, TRI);
443 BranchWithZeroOperand = ZeroOperandPosition != -1;
446 if (BranchWithZeroOperand) {
449 NewOpc = Mips::BEQZC;
452 NewOpc = Mips::BNEZC;
455 NewOpc = Mips::BGEZC;
458 NewOpc = Mips::BLTZC;
461 NewOpc = Mips::BEQZC64;
464 NewOpc = Mips::BNEZC64;
469 MIB =
BuildMI(*I->getParent(),
I, I->getDebugLoc(),
get(NewOpc));
475 if (NewOpc == Mips::JIC || NewOpc == Mips::JIALC || NewOpc == Mips::JIC64 ||
476 NewOpc == Mips::JIALC64) {
478 if (NewOpc == Mips::JIALC || NewOpc == Mips::JIALC64)
481 for (
unsigned J = 0,
E = I->getDesc().getNumOperands(); J <
E; ++J) {
482 MIB.
add(I->getOperand(J));
488 for (
unsigned J = 0,
E = I->getDesc().getNumOperands(); J <
E; ++J) {
489 if (BranchWithZeroOperand && (
unsigned)ZeroOperandPosition == J)
492 MIB.
add(I->getOperand(J));
498 MIB.
setMemRefs(I->memoperands_begin(), I->memoperands_end());
503 unsigned &SrcOpIdx2)
const {
505 "TargetInstrInfo::findCommutedOpIndices() can't handle bundles");
508 if (!MCID.isCommutable())
512 case Mips::DPADD_U_H:
513 case Mips::DPADD_U_W:
514 case Mips::DPADD_U_D:
515 case Mips::DPADD_S_H:
516 case Mips::DPADD_S_W:
517 case Mips::DPADD_S_D: {
519 if (!fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3))
static bool isReg(const MCInst &MI, unsigned OpNo)
bool isZeroImm(const MachineOperand &op) const
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
Return the number of bytes of code the specified instruction may be.
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
bool HasForbiddenSlot(const MachineInstr &MI) const
Predicate to determine if an instruction has a forbidden slot.
const MipsABIInfo & getABI() const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Branch Analysis.
MachineBasicBlock * getMBB() const
Describe properties that are true of each instruction in the target description file.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
const char * getSymbolName() const
virtual unsigned getOppositeBranchOpc(unsigned Opc) const =0
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
reverseBranchCondition - Return the inverse opcode of the specified Branch instruction.
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
Insert nop instruction when hazard condition is found.
A description of a memory reference used in the backend.
MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc)
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MipsSubtarget & Subtarget
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
INLINEASM - Represents an inline asm block.
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
size_t size() const
size - Get the array size.
reverse_iterator rbegin()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const MachineInstrBuilder & setMemRefs(MachineInstr::mmo_iterator b, MachineInstr::mmo_iterator e) const
const MipsInstrInfo * createMips16InstrInfo(const MipsSubtarget &STI)
Create MipsInstrInfo objects.
HasForbiddenSlot - Instruction has a forbidden slot.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const MachineOperand & getOperand(unsigned i) const
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
virtual bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const
Returns true iff the routine could find two commutable operands in the given machine instruction...
bool SafeInForbiddenSlot(const MachineInstr &MI) const
Predicate to determine if an instruction can go in a forbidden slot.
bool empty() const
empty - Check if the array is empty.
bool inMicroMipsMode() const
bool inMips16Mode() const
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
unsigned getEquivalentCompactForm(const MachineBasicBlock::iterator I) const
Determine the opcode of a non-delay slot form for a branch if one exists.
bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MachineMemOperand * GetMemOperand(MachineBasicBlock &MBB, int FI, MachineMemOperand::Flags Flags) const
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
IsCTI - Instruction is a Control Transfer Instruction.
iterator insert(iterator I, T &&Elt)
Flags
Flags values. These may be or'd together.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static std::vector< std::string > Flags
Representation of each machine instruction.
unsigned GetZeroReg() const
static MachineOperand CreateImm(int64_t Val)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const MipsInstrInfo * createMipsSEInstrInfo(const MipsSubtarget &STI)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
static const MipsInstrInfo * create(MipsSubtarget &STI)
MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc, MachineBasicBlock::iterator I) const
Create an instruction which has the same operands and memory operands as MI but has a new opcode...
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isUnconditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which always transfers control flow to some other block...