34 #define GET_INSTRINFO_CTOR_DTOR 35 #include "MipsGenInstrInfo.inc" 38 void MipsInstrInfo::anchor() {}
62 BuildMI(MBB, MI, DL,
get(Mips::NOP));
80 void MipsInstrInfo::AnalyzeCondBr(
const MachineInstr *Inst,
unsigned Opc,
83 assert(getAnalyzableBrOpc(Opc) &&
"Not an analyzable branch");
91 for (
int i = 0; i < NumOp-1; i++)
99 bool AllowModify)
const {
109 unsigned Opc = Cond[0].getImm();
113 for (
unsigned i = 1; i < Cond.
size(); ++i) {
115 "Cannot copy operand for conditional branch!");
126 int *BytesAdded)
const {
128 assert(TBB &&
"insertBranch must not be told to insert a fallthrough");
129 assert(!BytesAdded &&
"code size not handled");
137 "# of Mips branch conditions must be <= 3!");
141 BuildCondBr(MBB, TBB, DL, Cond);
151 BuildCondBr(MBB, TBB, DL, Cond);
156 int *BytesRemoved)
const {
157 assert(!BytesRemoved &&
"code size not handled");
160 unsigned removed = 0;
164 while (I != REnd && removed < 2) {
166 if (I->isDebugInstr()) {
170 if (!getAnalyzableBrOpc(I->getOpcode()))
173 I->eraseFromParent();
186 "Invalid Mips branch condition!");
198 while (I != REnd && I->isDebugInstr())
201 if (I == REnd || !isUnpredicatedTerminator(*I)) {
209 unsigned LastOpc = LastInst->
getOpcode();
213 if (!getAnalyzableBrOpc(LastOpc))
217 unsigned SecondLastOpc = 0;
223 while (I != REnd && I->isDebugInstr())
227 SecondLastInst = &*
I;
228 SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->
getOpcode());
231 if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc)
236 if (!SecondLastOpc) {
244 AnalyzeCondBr(LastInst, LastOpc, TBB, Cond);
250 if (++I != REnd && isUnpredicatedTerminator(*I))
253 BranchInstrs.
insert(BranchInstrs.
begin(), SecondLastInst);
273 AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
287 case Mips::BEQ:
case Mips::BEQ64:
289 case Mips::BGEZ:
case Mips::BGEZ64:
293 case Mips::BGTZ:
case Mips::BGTZ64:
295 case Mips::BLEZ:
case Mips::BLEZ64:
297 case Mips::BLTZ:
case Mips::BLTZ64:
301 case Mips::BNE:
case Mips::BNE64:
303 return isInt<18>(BrOffset);
311 case Mips::BGEZAL_MM:
315 case Mips::BLTZAL_MM:
319 return isInt<17>(BrOffset);
323 return isInt<11>(BrOffset);
325 case Mips::BEQZ16_MM:
326 case Mips::BNEZ16_MM:
332 return isInt<28>(BrOffset);
338 case Mips::BEQC:
case Mips::BEQC64:
339 case Mips::BNEC:
case Mips::BNEC64:
340 case Mips::BGEC:
case Mips::BGEC64:
341 case Mips::BGEUC:
case Mips::BGEUC64:
342 case Mips::BGEZC:
case Mips::BGEZC64:
343 case Mips::BGTZC:
case Mips::BGTZC64:
344 case Mips::BLEZC:
case Mips::BLEZC64:
345 case Mips::BLTC:
case Mips::BLTC64:
346 case Mips::BLTUC:
case Mips::BLTUC64:
347 case Mips::BLTZC:
case Mips::BLTZC64:
356 return isInt<18>(BrOffset);
358 case Mips::BEQZC:
case Mips::BEQZC64:
359 case Mips::BNEZC:
case Mips::BNEZC64:
360 return isInt<23>(BrOffset);
363 case Mips::BC16_MMR6:
364 return isInt<11>(BrOffset);
366 case Mips::BEQZC16_MMR6:
367 case Mips::BNEZC16_MMR6:
370 case Mips::BALC_MMR6:
372 return isInt<27>(BrOffset);
374 case Mips::BC1EQZC_MMR6:
375 case Mips::BC1NEZC_MMR6:
376 case Mips::BC2EQZC_MMR6:
377 case Mips::BC2NEZC_MMR6:
378 case Mips::BGEZALC_MMR6:
379 case Mips::BEQZALC_MMR6:
380 case Mips::BGTZALC_MMR6:
381 case Mips::BLEZALC_MMR6:
382 case Mips::BLTZALC_MMR6:
383 case Mips::BNEZALC_MMR6:
384 case Mips::BNVC_MMR6:
385 case Mips::BOVC_MMR6:
386 return isInt<17>(BrOffset);
388 case Mips::BEQC_MMR6:
389 case Mips::BNEC_MMR6:
390 case Mips::BGEC_MMR6:
391 case Mips::BGEUC_MMR6:
392 case Mips::BGEZC_MMR6:
393 case Mips::BGTZC_MMR6:
394 case Mips::BLEZC_MMR6:
395 case Mips::BLTC_MMR6:
396 case Mips::BLTUC_MMR6:
397 case Mips::BLTZC_MMR6:
398 return isInt<18>(BrOffset);
400 case Mips::BEQZC_MMR6:
401 case Mips::BNEZC_MMR6:
402 return isInt<23>(BrOffset);
406 return isInt<18>(BrOffset);
407 case Mips::BPOSGE32_MM:
408 case Mips::BPOSGE32C_MMR3:
409 return isInt<17>(BrOffset);
416 return isInt<18>(BrOffset);
429 return isInt<18>(BrOffset);
439 unsigned Opcode = I->getOpcode();
440 bool canUseShortMicroMipsCTI =
false;
451 canUseShortMicroMipsCTI =
true;
456 case Mips::PseudoReturn:
457 case Mips::PseudoIndirectBranch:
458 canUseShortMicroMipsCTI =
true;
465 (I->getOperand(0).isReg() &&
466 (I->getOperand(0).getReg() == Mips::ZERO ||
467 I->getOperand(0).getReg() == Mips::ZERO_64)) &&
468 (I->getOperand(1).isReg() &&
469 (I->getOperand(1).getReg() == Mips::ZERO ||
470 I->getOperand(1).getReg() == Mips::ZERO_64)))
481 if (canUseShortMicroMipsCTI)
482 return Mips::BEQZC_MM;
483 else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
488 if (canUseShortMicroMipsCTI)
489 return Mips::BNEZC_MM;
490 else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
494 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
498 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
508 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
512 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
518 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
522 if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
526 return Mips::BGTZC64;
528 return Mips::BGEZC64;
530 return Mips::BLTZC64;
532 return Mips::BLEZC64;
536 case Mips::PseudoIndirectBranchR6:
537 case Mips::PseudoReturn:
538 case Mips::TAILCALLR6REG:
539 if (canUseShortMicroMipsCTI)
540 return Mips::JRC16_MM;
542 case Mips::JALRPseudo:
545 case Mips::PseudoIndirectBranch64R6:
546 case Mips::PseudoReturn64:
547 case Mips::TAILCALL64R6REG:
549 case Mips::JALR64Pseudo:
550 return Mips::JIALC64;
584 case Mips::CONSTPOOL_ENTRY:
605 int ZeroOperandPosition = -1;
606 bool BranchWithZeroOperand =
false;
607 if (I->isBranch() && !I->isPseudo()) {
608 auto TRI = I->getParent()->getParent()->getSubtarget().getRegisterInfo();
609 ZeroOperandPosition = I->findRegisterUseOperandIdx(Mips::ZERO,
false,
TRI);
610 BranchWithZeroOperand = ZeroOperandPosition != -1;
613 if (BranchWithZeroOperand) {
616 NewOpc = Mips::BEQZC;
619 NewOpc = Mips::BNEZC;
622 NewOpc = Mips::BGEZC;
625 NewOpc = Mips::BLTZC;
628 NewOpc = Mips::BEQZC64;
631 NewOpc = Mips::BNEZC64;
636 MIB =
BuildMI(*I->getParent(),
I, I->getDebugLoc(),
get(NewOpc));
642 if (NewOpc == Mips::JIC || NewOpc == Mips::JIALC || NewOpc == Mips::JIC64 ||
643 NewOpc == Mips::JIALC64) {
645 if (NewOpc == Mips::JIALC || NewOpc == Mips::JIALC64)
648 for (
unsigned J = 0,
E = I->getDesc().getNumOperands(); J <
E; ++J) {
649 MIB.
add(I->getOperand(J));
655 for (
unsigned J = 0,
E = I->getDesc().getNumOperands(); J <
E; ++J) {
656 if (BranchWithZeroOperand && (
unsigned)ZeroOperandPosition == J)
659 MIB.
add(I->getOperand(J));
665 MIB.
setMemRefs(I->memoperands_begin(), I->memoperands_end());
670 unsigned &SrcOpIdx2)
const {
672 "TargetInstrInfo::findCommutedOpIndices() can't handle bundles");
675 if (!MCID.isCommutable())
679 case Mips::DPADD_U_H:
680 case Mips::DPADD_U_W:
681 case Mips::DPADD_U_D:
682 case Mips::DPADD_S_H:
683 case Mips::DPADD_S_W:
684 case Mips::DPADD_S_D:
686 if (!fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3))
711 const int64_t PosLow,
const int64_t PosHigh,
712 const int64_t SizeLow,
713 const int64_t SizeHigh,
714 const int64_t BothLow,
715 const int64_t BothHigh) {
717 if (!MOPos.
isImm()) {
718 ErrInfo =
"Position is not an immediate!";
721 int64_t Pos = MOPos.
getImm();
722 if (!((PosLow <= Pos) && (Pos < PosHigh))) {
723 ErrInfo =
"Position operand is out of range!";
728 if (!MOSize.
isImm()) {
729 ErrInfo =
"Size operand is not an immediate!";
733 if (!((SizeLow < Size) && (Size <= SizeHigh))) {
734 ErrInfo =
"Size operand is out of range!";
738 if (!((BothLow < (Pos + Size)) && ((Pos + Size) <= BothHigh))) {
739 ErrInfo =
"Position + Size is out of range!";
776 case Mips::TAILCALLREG:
777 case Mips::PseudoIndirectBranch:
782 case Mips::JALRPseudo:
786 ErrInfo =
"invalid instruction when using jump guards!";
795 std::pair<unsigned, unsigned>
797 return std::make_pair(TF, 0u);
802 using namespace MipsII;
804 static const std::pair<unsigned, const char*> Flags[] = {
static bool isReg(const MCInst &MI, unsigned OpNo)
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 MachineInstrBuilder & add(const MachineOperand &MO) const
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
Determine if the branch target is in range.
IsCTI - Instruction is a Control Transfer Instruction.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
MachineBasicBlock * getMBB() const
Compute iterated dominance frontiers using a linear time algorithm.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Branch Analysis.
MO_TLSLDM - Represents the offset into the global offset table at which.
bool inMips16Mode() const
MO_HIGHER/HIGHEST - Represents the highest or higher half word of a 64-bit symbol address...
MO_GOT_HI16/LO16, MO_CALL_HI16/LO16 - Relocations used for large GOTs.
MO_TLSGD - Represents the offset into the global offset table at which.
Describe properties that are true of each instruction in the target description file.
constexpr bool isInt< 8 >(int64_t x)
bool SafeInForbiddenSlot(const MachineInstr &MI) const
Predicate to determine if an instruction can go in a forbidden slot.
MachineMemOperand * GetMemOperand(MachineBasicBlock &MBB, int FI, MachineMemOperand::Flags Flags) const
unsigned const TargetRegisterInfo * TRI
virtual unsigned getOppositeBranchOpc(unsigned Opc) const =0
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
reverseBranchCondition - Return the inverse opcode of the specified Branch instruction.
bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const override
Perform target specific instruction verification.
bool HasForbiddenSlot(const MachineInstr &MI) const
Predicate to determine if an instruction has a forbidden slot.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
Insert nop instruction when hazard condition is found.
static bool verifyInsExtInstruction(const MachineInstr &MI, StringRef &ErrInfo, const int64_t PosLow, const int64_t PosHigh, const int64_t SizeLow, const int64_t SizeHigh, const int64_t BothLow, const int64_t BothHigh)
A description of a memory reference used in the backend.
MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool inMicroMipsMode() const
bool useIndirectJumpsHazard() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const char * getSymbolName() const
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.
INLINEASM - Represents an inline asm block.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
reverse_iterator rbegin()
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const MipsInstrInfo * createMips16InstrInfo(const MipsSubtarget &STI)
Create MipsInstrInfo objects.
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...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
unsigned getEquivalentCompactForm(const MachineBasicBlock::iterator I) const
Determine the opcode of a non-delay slot form for a branch if one exists.
bool isZeroImm(const MachineOperand &op) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const MipsABIInfo & getABI() const
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
MO_GOTTPREL - Represents the offset from the thread pointer (Initial.
HasForbiddenSlot - Instruction has a forbidden slot.
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...
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...
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
bool isUnconditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which always transfers control flow to some other block...
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
iterator insert(iterator I, T &&Elt)
Flags
Flags values. These may be or'd together.
MO_TPREL_HI/LO - Represents the hi and low part of the offset from.
const MachineBasicBlock * getParent() const
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
static MachineOperand CreateImm(int64_t Val)
const MipsInstrInfo * createMipsSEInstrInfo(const MipsSubtarget &STI)
unsigned GetZeroReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
StringRef - Represent a constant reference to a string, i.e.
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
const MachineInstrBuilder & setMemRefs(MachineInstr::mmo_iterator b, MachineInstr::mmo_iterator e) const
const MachineOperand & getOperand(unsigned i) const
static const MipsInstrInfo * create(MipsSubtarget &STI)
bool empty() const
empty - Check if the array is empty.
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...