1 //===- MipsInstrInfo.cpp - Mips Instruction Information -------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains the Mips implementation of the TargetInstrInfo class.
11 //===----------------------------------------------------------------------===//
13 #include "MipsInstrInfo.h"
14 #include "MCTargetDesc/MipsBaseInfo.h"
15 #include "MCTargetDesc/MipsMCTargetDesc.h"
16 #include "MipsSubtarget.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/CodeGen/MachineBasicBlock.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineInstr.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineOperand.h"
24 #include "llvm/CodeGen/TargetOpcodes.h"
25 #include "llvm/CodeGen/TargetSubtargetInfo.h"
26 #include "llvm/IR/DebugLoc.h"
27 #include "llvm/MC/MCInstrDesc.h"
28 #include "llvm/Target/TargetMachine.h"
33 #define GET_INSTRINFO_CTOR_DTOR
34 #include "MipsGenInstrInfo.inc"
36 // Pin the vtable to this file.
37 void MipsInstrInfo::anchor() {}
39 MipsInstrInfo::MipsInstrInfo(const MipsSubtarget
&STI
, unsigned UncondBr
)
40 : MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN
, Mips::ADJCALLSTACKUP
),
41 Subtarget(STI
), UncondBrOpc(UncondBr
) {}
43 const MipsInstrInfo
*MipsInstrInfo::create(MipsSubtarget
&STI
) {
44 if (STI
.inMips16Mode())
45 return createMips16InstrInfo(STI
);
47 return createMipsSEInstrInfo(STI
);
50 bool MipsInstrInfo::isZeroImm(const MachineOperand
&op
) const {
51 return op
.isImm() && op
.getImm() == 0;
54 /// insertNoop - If data hazard condition is found insert the target nop
56 // FIXME: This appears to be dead code.
58 insertNoop(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
) const
61 BuildMI(MBB
, MI
, DL
, get(Mips::NOP
));
65 MipsInstrInfo::GetMemOperand(MachineBasicBlock
&MBB
, int FI
,
66 MachineMemOperand::Flags Flags
) const {
67 MachineFunction
&MF
= *MBB
.getParent();
68 MachineFrameInfo
&MFI
= MF
.getFrameInfo();
69 unsigned Align
= MFI
.getObjectAlignment(FI
);
71 return MF
.getMachineMemOperand(MachinePointerInfo::getFixedStack(MF
, FI
),
72 Flags
, MFI
.getObjectSize(FI
), Align
);
75 //===----------------------------------------------------------------------===//
77 //===----------------------------------------------------------------------===//
79 void MipsInstrInfo::AnalyzeCondBr(const MachineInstr
*Inst
, unsigned Opc
,
80 MachineBasicBlock
*&BB
,
81 SmallVectorImpl
<MachineOperand
> &Cond
) const {
82 assert(getAnalyzableBrOpc(Opc
) && "Not an analyzable branch");
83 int NumOp
= Inst
->getNumExplicitOperands();
85 // for both int and fp branches, the last explicit operand is the
87 BB
= Inst
->getOperand(NumOp
-1).getMBB();
88 Cond
.push_back(MachineOperand::CreateImm(Opc
));
90 for (int i
= 0; i
< NumOp
-1; i
++)
91 Cond
.push_back(Inst
->getOperand(i
));
94 bool MipsInstrInfo::analyzeBranch(MachineBasicBlock
&MBB
,
95 MachineBasicBlock
*&TBB
,
96 MachineBasicBlock
*&FBB
,
97 SmallVectorImpl
<MachineOperand
> &Cond
,
98 bool AllowModify
) const {
99 SmallVector
<MachineInstr
*, 2> BranchInstrs
;
100 BranchType BT
= analyzeBranch(MBB
, TBB
, FBB
, Cond
, AllowModify
, BranchInstrs
);
102 return (BT
== BT_None
) || (BT
== BT_Indirect
);
105 void MipsInstrInfo::BuildCondBr(MachineBasicBlock
&MBB
, MachineBasicBlock
*TBB
,
107 ArrayRef
<MachineOperand
> Cond
) const {
108 unsigned Opc
= Cond
[0].getImm();
109 const MCInstrDesc
&MCID
= get(Opc
);
110 MachineInstrBuilder MIB
= BuildMI(&MBB
, DL
, MCID
);
112 for (unsigned i
= 1; i
< Cond
.size(); ++i
) {
113 assert((Cond
[i
].isImm() || Cond
[i
].isReg()) &&
114 "Cannot copy operand for conditional branch!");
120 unsigned MipsInstrInfo::insertBranch(MachineBasicBlock
&MBB
,
121 MachineBasicBlock
*TBB
,
122 MachineBasicBlock
*FBB
,
123 ArrayRef
<MachineOperand
> Cond
,
125 int *BytesAdded
) const {
126 // Shouldn't be a fall through.
127 assert(TBB
&& "insertBranch must not be told to insert a fallthrough");
128 assert(!BytesAdded
&& "code size not handled");
130 // # of condition operands:
131 // Unconditional branches: 0
132 // Floating point branches: 1 (opc)
133 // Int BranchZero: 2 (opc, reg)
134 // Int Branch: 3 (opc, reg0, reg1)
135 assert((Cond
.size() <= 3) &&
136 "# of Mips branch conditions must be <= 3!");
138 // Two-way Conditional branch.
140 BuildCondBr(MBB
, TBB
, DL
, Cond
);
141 BuildMI(&MBB
, DL
, get(UncondBrOpc
)).addMBB(FBB
);
146 // Unconditional branch.
148 BuildMI(&MBB
, DL
, get(UncondBrOpc
)).addMBB(TBB
);
149 else // Conditional branch.
150 BuildCondBr(MBB
, TBB
, DL
, Cond
);
154 unsigned MipsInstrInfo::removeBranch(MachineBasicBlock
&MBB
,
155 int *BytesRemoved
) const {
156 assert(!BytesRemoved
&& "code size not handled");
158 MachineBasicBlock::reverse_iterator I
= MBB
.rbegin(), REnd
= MBB
.rend();
159 unsigned removed
= 0;
161 // Up to 2 branches are removed.
162 // Note that indirect branches are not removed.
163 while (I
!= REnd
&& removed
< 2) {
164 // Skip past debug instructions.
165 if (I
->isDebugInstr()) {
169 if (!getAnalyzableBrOpc(I
->getOpcode()))
171 // Remove the branch.
172 I
->eraseFromParent();
180 /// reverseBranchCondition - Return the inverse opcode of the
181 /// specified Branch instruction.
182 bool MipsInstrInfo::reverseBranchCondition(
183 SmallVectorImpl
<MachineOperand
> &Cond
) const {
184 assert( (Cond
.size() && Cond
.size() <= 3) &&
185 "Invalid Mips branch condition!");
186 Cond
[0].setImm(getOppositeBranchOpc(Cond
[0].getImm()));
190 MipsInstrInfo::BranchType
MipsInstrInfo::analyzeBranch(
191 MachineBasicBlock
&MBB
, MachineBasicBlock
*&TBB
, MachineBasicBlock
*&FBB
,
192 SmallVectorImpl
<MachineOperand
> &Cond
, bool AllowModify
,
193 SmallVectorImpl
<MachineInstr
*> &BranchInstrs
) const {
194 MachineBasicBlock::reverse_iterator I
= MBB
.rbegin(), REnd
= MBB
.rend();
196 // Skip all the debug instructions.
197 while (I
!= REnd
&& I
->isDebugInstr())
200 if (I
== REnd
|| !isUnpredicatedTerminator(*I
)) {
201 // This block ends with no branches (it just falls through to its succ).
202 // Leave TBB/FBB null.
207 MachineInstr
*LastInst
= &*I
;
208 unsigned LastOpc
= LastInst
->getOpcode();
209 BranchInstrs
.push_back(LastInst
);
211 // Not an analyzable branch (e.g., indirect jump).
212 if (!getAnalyzableBrOpc(LastOpc
))
213 return LastInst
->isIndirectBranch() ? BT_Indirect
: BT_None
;
215 // Get the second to last instruction in the block.
216 unsigned SecondLastOpc
= 0;
217 MachineInstr
*SecondLastInst
= nullptr;
219 // Skip past any debug instruction to see if the second last actual
222 while (I
!= REnd
&& I
->isDebugInstr())
226 SecondLastInst
= &*I
;
227 SecondLastOpc
= getAnalyzableBrOpc(SecondLastInst
->getOpcode());
229 // Not an analyzable branch (must be an indirect jump).
230 if (isUnpredicatedTerminator(*SecondLastInst
) && !SecondLastOpc
)
234 // If there is only one terminator instruction, process it.
235 if (!SecondLastOpc
) {
236 // Unconditional branch.
237 if (LastInst
->isUnconditionalBranch()) {
238 TBB
= LastInst
->getOperand(0).getMBB();
242 // Conditional branch
243 AnalyzeCondBr(LastInst
, LastOpc
, TBB
, Cond
);
247 // If we reached here, there are two branches.
248 // If there are three terminators, we don't know what sort of block this is.
249 if (++I
!= REnd
&& isUnpredicatedTerminator(*I
))
252 BranchInstrs
.insert(BranchInstrs
.begin(), SecondLastInst
);
254 // If second to last instruction is an unconditional branch,
255 // analyze it and remove the last instruction.
256 if (SecondLastInst
->isUnconditionalBranch()) {
257 // Return if the last instruction cannot be removed.
261 TBB
= SecondLastInst
->getOperand(0).getMBB();
262 LastInst
->eraseFromParent();
263 BranchInstrs
.pop_back();
267 // Conditional branch followed by an unconditional branch.
268 // The last one must be unconditional.
269 if (!LastInst
->isUnconditionalBranch())
272 AnalyzeCondBr(SecondLastInst
, SecondLastOpc
, TBB
, Cond
);
273 FBB
= LastInst
->getOperand(0).getMBB();
275 return BT_CondUncond
;
278 bool MipsInstrInfo::isBranchOffsetInRange(unsigned BranchOpc
, int64_t BrOffset
) const {
283 case Mips::BAL_BR_MM
:
288 case Mips::BEQ
: case Mips::BEQ64
:
290 case Mips::BGEZ
: case Mips::BGEZ64
:
294 case Mips::BGTZ
: case Mips::BGTZ64
:
296 case Mips::BLEZ
: case Mips::BLEZ64
:
298 case Mips::BLTZ
: case Mips::BLTZ64
:
302 case Mips::BNE
: case Mips::BNE64
:
304 return isInt
<18>(BrOffset
);
306 // microMIPSr3 branches
312 case Mips::BGEZAL_MM
:
316 case Mips::BLTZAL_MM
:
320 return isInt
<17>(BrOffset
);
322 // microMIPSR3 short branches.
324 return isInt
<11>(BrOffset
);
326 case Mips::BEQZ16_MM
:
327 case Mips::BNEZ16_MM
:
328 return isInt
<8>(BrOffset
);
333 return isInt
<28>(BrOffset
);
339 case Mips::BEQC
: case Mips::BEQC64
:
340 case Mips::BNEC
: case Mips::BNEC64
:
341 case Mips::BGEC
: case Mips::BGEC64
:
342 case Mips::BGEUC
: case Mips::BGEUC64
:
343 case Mips::BGEZC
: case Mips::BGEZC64
:
344 case Mips::BGTZC
: case Mips::BGTZC64
:
345 case Mips::BLEZC
: case Mips::BLEZC64
:
346 case Mips::BLTC
: case Mips::BLTC64
:
347 case Mips::BLTUC
: case Mips::BLTUC64
:
348 case Mips::BLTZC
: case Mips::BLTZC64
:
357 return isInt
<18>(BrOffset
);
359 case Mips::BEQZC
: case Mips::BEQZC64
:
360 case Mips::BNEZC
: case Mips::BNEZC64
:
361 return isInt
<23>(BrOffset
);
363 // microMIPSR6 branches
364 case Mips::BC16_MMR6
:
365 return isInt
<11>(BrOffset
);
367 case Mips::BEQZC16_MMR6
:
368 case Mips::BNEZC16_MMR6
:
369 return isInt
<8>(BrOffset
);
371 case Mips::BALC_MMR6
:
373 return isInt
<27>(BrOffset
);
375 case Mips::BC1EQZC_MMR6
:
376 case Mips::BC1NEZC_MMR6
:
377 case Mips::BC2EQZC_MMR6
:
378 case Mips::BC2NEZC_MMR6
:
379 case Mips::BGEZALC_MMR6
:
380 case Mips::BEQZALC_MMR6
:
381 case Mips::BGTZALC_MMR6
:
382 case Mips::BLEZALC_MMR6
:
383 case Mips::BLTZALC_MMR6
:
384 case Mips::BNEZALC_MMR6
:
385 case Mips::BNVC_MMR6
:
386 case Mips::BOVC_MMR6
:
387 return isInt
<17>(BrOffset
);
389 case Mips::BEQC_MMR6
:
390 case Mips::BNEC_MMR6
:
391 case Mips::BGEC_MMR6
:
392 case Mips::BGEUC_MMR6
:
393 case Mips::BGEZC_MMR6
:
394 case Mips::BGTZC_MMR6
:
395 case Mips::BLEZC_MMR6
:
396 case Mips::BLTC_MMR6
:
397 case Mips::BLTUC_MMR6
:
398 case Mips::BLTZC_MMR6
:
399 return isInt
<18>(BrOffset
);
401 case Mips::BEQZC_MMR6
:
402 case Mips::BNEZC_MMR6
:
403 return isInt
<23>(BrOffset
);
407 return isInt
<18>(BrOffset
);
408 case Mips::BPOSGE32_MM
:
409 case Mips::BPOSGE32C_MMR3
:
410 return isInt
<17>(BrOffset
);
417 return isInt
<18>(BrOffset
);
430 return isInt
<18>(BrOffset
);
433 llvm_unreachable("Unknown branch instruction!");
437 /// Return the corresponding compact (no delay slot) form of a branch.
438 unsigned MipsInstrInfo::getEquivalentCompactForm(
439 const MachineBasicBlock::iterator I
) const {
440 unsigned Opcode
= I
->getOpcode();
441 bool canUseShortMicroMipsCTI
= false;
443 if (Subtarget
.inMicroMipsMode()) {
449 // microMIPS has NE,EQ branches that do not have delay slots provided one
450 // of the operands is zero.
451 if (I
->getOperand(1).getReg() == Subtarget
.getABI().GetZeroReg())
452 canUseShortMicroMipsCTI
= true;
454 // For microMIPS the PseudoReturn and PseudoIndirectBranch are always
455 // expanded to JR_MM, so they can be replaced with JRC16_MM.
457 case Mips::PseudoReturn
:
458 case Mips::PseudoIndirectBranch
:
459 canUseShortMicroMipsCTI
= true;
464 // MIPSR6 forbids both operands being the zero register.
465 if (Subtarget
.hasMips32r6() && (I
->getNumOperands() > 1) &&
466 (I
->getOperand(0).isReg() &&
467 (I
->getOperand(0).getReg() == Mips::ZERO
||
468 I
->getOperand(0).getReg() == Mips::ZERO_64
)) &&
469 (I
->getOperand(1).isReg() &&
470 (I
->getOperand(1).getReg() == Mips::ZERO
||
471 I
->getOperand(1).getReg() == Mips::ZERO_64
)))
474 if (Subtarget
.hasMips32r6() || canUseShortMicroMipsCTI
) {
482 if (canUseShortMicroMipsCTI
)
483 return Mips::BEQZC_MM
;
484 else if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
489 if (canUseShortMicroMipsCTI
)
490 return Mips::BNEZC_MM
;
491 else if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
495 if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
499 if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
509 if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
513 if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
519 if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
523 if (I
->getOperand(0).getReg() == I
->getOperand(1).getReg())
527 return Mips::BGTZC64
;
529 return Mips::BGEZC64
;
531 return Mips::BLTZC64
;
533 return Mips::BLEZC64
;
534 // For MIPSR6, the instruction 'jic' can be used for these cases. Some
535 // tools will accept 'jrc reg' as an alias for 'jic 0, $reg'.
537 case Mips::PseudoIndirectBranchR6
:
538 case Mips::PseudoReturn
:
539 case Mips::TAILCALLR6REG
:
540 if (canUseShortMicroMipsCTI
)
541 return Mips::JRC16_MM
;
543 case Mips::JALRPseudo
:
546 case Mips::PseudoIndirectBranch64R6
:
547 case Mips::PseudoReturn64
:
548 case Mips::TAILCALL64R6REG
:
550 case Mips::JALR64Pseudo
:
551 return Mips::JIALC64
;
560 /// Predicate for distingushing between control transfer instructions and all
561 /// other instructions for handling forbidden slots. Consider inline assembly
562 /// as unsafe as well.
563 bool MipsInstrInfo::SafeInForbiddenSlot(const MachineInstr
&MI
) const {
564 if (MI
.isInlineAsm())
567 return (MI
.getDesc().TSFlags
& MipsII::IsCTI
) == 0;
570 /// Predicate for distingushing instructions that have forbidden slots.
571 bool MipsInstrInfo::HasForbiddenSlot(const MachineInstr
&MI
) const {
572 return (MI
.getDesc().TSFlags
& MipsII::HasForbiddenSlot
) != 0;
575 /// Return the number of bytes of code the specified instruction may be.
576 unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr
&MI
) const {
577 switch (MI
.getOpcode()) {
579 return MI
.getDesc().getSize();
580 case TargetOpcode::INLINEASM
:
581 case TargetOpcode::INLINEASM_BR
: { // Inline Asm: Variable size.
582 const MachineFunction
*MF
= MI
.getParent()->getParent();
583 const char *AsmStr
= MI
.getOperand(0).getSymbolName();
584 return getInlineAsmLength(AsmStr
, *MF
->getTarget().getMCAsmInfo());
586 case Mips::CONSTPOOL_ENTRY
:
587 // If this machine instr is a constant pool entry, its size is recorded as
589 return MI
.getOperand(2).getImm();
594 MipsInstrInfo::genInstrWithNewOpc(unsigned NewOpc
,
595 MachineBasicBlock::iterator I
) const {
596 MachineInstrBuilder MIB
;
598 // Certain branches have two forms: e.g beq $1, $zero, dest vs beqz $1, dest
599 // Pick the zero form of the branch for readable assembly and for greater
600 // branch distance in non-microMIPS mode.
601 // Additional MIPSR6 does not permit the use of register $zero for compact
603 // FIXME: Certain atomic sequences on mips64 generate 32bit references to
604 // Mips::ZERO, which is incorrect. This test should be updated to use
605 // Subtarget.getABI().GetZeroReg() when those atomic sequences and others
607 int ZeroOperandPosition
= -1;
608 bool BranchWithZeroOperand
= false;
609 if (I
->isBranch() && !I
->isPseudo()) {
610 auto TRI
= I
->getParent()->getParent()->getSubtarget().getRegisterInfo();
611 ZeroOperandPosition
= I
->findRegisterUseOperandIdx(Mips::ZERO
, false, TRI
);
612 BranchWithZeroOperand
= ZeroOperandPosition
!= -1;
615 if (BranchWithZeroOperand
) {
618 NewOpc
= Mips::BEQZC
;
621 NewOpc
= Mips::BNEZC
;
624 NewOpc
= Mips::BGEZC
;
627 NewOpc
= Mips::BLTZC
;
630 NewOpc
= Mips::BEQZC64
;
633 NewOpc
= Mips::BNEZC64
;
638 MIB
= BuildMI(*I
->getParent(), I
, I
->getDebugLoc(), get(NewOpc
));
640 // For MIPSR6 JI*C requires an immediate 0 as an operand, JIALC(64) an
641 // immediate 0 as an operand and requires the removal of it's implicit-def %ra
642 // implicit operand as copying the implicit operations of the instructio we're
643 // looking at will give us the correct flags.
644 if (NewOpc
== Mips::JIC
|| NewOpc
== Mips::JIALC
|| NewOpc
== Mips::JIC64
||
645 NewOpc
== Mips::JIALC64
) {
647 if (NewOpc
== Mips::JIALC
|| NewOpc
== Mips::JIALC64
)
648 MIB
->RemoveOperand(0);
650 for (unsigned J
= 0, E
= I
->getDesc().getNumOperands(); J
< E
; ++J
) {
651 MIB
.add(I
->getOperand(J
));
656 // If I has an MCSymbol operand (used by asm printer, to emit R_MIPS_JALR),
657 // add it to the new instruction.
658 for (unsigned J
= I
->getDesc().getNumOperands(), E
= I
->getNumOperands();
660 const MachineOperand
&MO
= I
->getOperand(J
);
661 if (MO
.isMCSymbol() && (MO
.getTargetFlags() & MipsII::MO_JALR
))
662 MIB
.addSym(MO
.getMCSymbol(), MipsII::MO_JALR
);
667 for (unsigned J
= 0, E
= I
->getDesc().getNumOperands(); J
< E
; ++J
) {
668 if (BranchWithZeroOperand
&& (unsigned)ZeroOperandPosition
== J
)
671 MIB
.add(I
->getOperand(J
));
675 MIB
.copyImplicitOps(*I
);
676 MIB
.cloneMemRefs(*I
);
680 bool MipsInstrInfo::findCommutedOpIndices(MachineInstr
&MI
, unsigned &SrcOpIdx1
,
681 unsigned &SrcOpIdx2
) const {
682 assert(!MI
.isBundle() &&
683 "TargetInstrInfo::findCommutedOpIndices() can't handle bundles");
685 const MCInstrDesc
&MCID
= MI
.getDesc();
686 if (!MCID
.isCommutable())
689 switch (MI
.getOpcode()) {
690 case Mips::DPADD_U_H
:
691 case Mips::DPADD_U_W
:
692 case Mips::DPADD_U_D
:
693 case Mips::DPADD_S_H
:
694 case Mips::DPADD_S_W
:
695 case Mips::DPADD_S_D
:
696 // The first operand is both input and output, so it should not commute
697 if (!fixCommutedOpIndices(SrcOpIdx1
, SrcOpIdx2
, 2, 3))
700 if (!MI
.getOperand(SrcOpIdx1
).isReg() || !MI
.getOperand(SrcOpIdx2
).isReg())
704 return TargetInstrInfo::findCommutedOpIndices(MI
, SrcOpIdx1
, SrcOpIdx2
);
707 // ins, ext, dext*, dins have the following constraints:
712 // dinsm and dinsu have the following constraints:
717 // The callee of verifyInsExtInstruction however gives the bounds of
718 // dins[um] like the other (d)ins (d)ext(um) instructions, so that this
719 // function doesn't have to vary it's behaviour based on the instruction
721 static bool verifyInsExtInstruction(const MachineInstr
&MI
, StringRef
&ErrInfo
,
722 const int64_t PosLow
, const int64_t PosHigh
,
723 const int64_t SizeLow
,
724 const int64_t SizeHigh
,
725 const int64_t BothLow
,
726 const int64_t BothHigh
) {
727 MachineOperand MOPos
= MI
.getOperand(2);
728 if (!MOPos
.isImm()) {
729 ErrInfo
= "Position is not an immediate!";
732 int64_t Pos
= MOPos
.getImm();
733 if (!((PosLow
<= Pos
) && (Pos
< PosHigh
))) {
734 ErrInfo
= "Position operand is out of range!";
738 MachineOperand MOSize
= MI
.getOperand(3);
739 if (!MOSize
.isImm()) {
740 ErrInfo
= "Size operand is not an immediate!";
743 int64_t Size
= MOSize
.getImm();
744 if (!((SizeLow
< Size
) && (Size
<= SizeHigh
))) {
745 ErrInfo
= "Size operand is out of range!";
749 if (!((BothLow
< (Pos
+ Size
)) && ((Pos
+ Size
) <= BothHigh
))) {
750 ErrInfo
= "Position + Size is out of range!";
757 // Perform target specific instruction verification.
758 bool MipsInstrInfo::verifyInstruction(const MachineInstr
&MI
,
759 StringRef
&ErrInfo
) const {
760 // Verify that ins and ext instructions are well formed.
761 switch (MI
.getOpcode()) {
767 return verifyInsExtInstruction(MI
, ErrInfo
, 0, 32, 0, 32, 0, 32);
769 // The ISA spec has a subtle difference between dinsm and dextm
771 // 2 <= size <= 64 for 'dinsm' but 'dextm' has 32 < size <= 64.
772 // To make the bounds checks similar, the range 1 < size <= 64 is checked
774 return verifyInsExtInstruction(MI
, ErrInfo
, 0, 32, 1, 64, 32, 64);
776 // The ISA spec has a subtle difference between dinsu and dextu in that
777 // the size range of dinsu is specified as 1 <= size <= 32 whereas size
778 // for dextu is 0 < size <= 32. The range checked for dinsu here is
779 // 0 < size <= 32, which is equivalent and similar to dextu.
780 return verifyInsExtInstruction(MI
, ErrInfo
, 32, 64, 0, 32, 32, 64);
782 return verifyInsExtInstruction(MI
, ErrInfo
, 0, 32, 0, 32, 0, 63);
784 return verifyInsExtInstruction(MI
, ErrInfo
, 0, 32, 32, 64, 32, 64);
786 return verifyInsExtInstruction(MI
, ErrInfo
, 32, 64, 0, 32, 32, 64);
787 case Mips::TAILCALLREG
:
788 case Mips::PseudoIndirectBranch
:
793 case Mips::JALRPseudo
:
794 if (!Subtarget
.useIndirectJumpsHazard())
797 ErrInfo
= "invalid instruction when using jump guards!";
806 std::pair
<unsigned, unsigned>
807 MipsInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF
) const {
808 return std::make_pair(TF
, 0u);
811 ArrayRef
<std::pair
<unsigned, const char*>>
812 MipsInstrInfo::getSerializableDirectMachineOperandTargetFlags() const {
813 using namespace MipsII
;
815 static const std::pair
<unsigned, const char*> Flags
[] = {
816 {MO_GOT
, "mips-got"},
817 {MO_GOT_CALL
, "mips-got-call"},
818 {MO_GPREL
, "mips-gprel"},
819 {MO_ABS_HI
, "mips-abs-hi"},
820 {MO_ABS_LO
, "mips-abs-lo"},
821 {MO_TLSGD
, "mips-tlsgd"},
822 {MO_TLSLDM
, "mips-tlsldm"},
823 {MO_DTPREL_HI
, "mips-dtprel-hi"},
824 {MO_DTPREL_LO
, "mips-dtprel-lo"},
825 {MO_GOTTPREL
, "mips-gottprel"},
826 {MO_TPREL_HI
, "mips-tprel-hi"},
827 {MO_TPREL_LO
, "mips-tprel-lo"},
828 {MO_GPOFF_HI
, "mips-gpoff-hi"},
829 {MO_GPOFF_LO
, "mips-gpoff-lo"},
830 {MO_GOT_DISP
, "mips-got-disp"},
831 {MO_GOT_PAGE
, "mips-got-page"},
832 {MO_GOT_OFST
, "mips-got-ofst"},
833 {MO_HIGHER
, "mips-higher"},
834 {MO_HIGHEST
, "mips-highest"},
835 {MO_GOT_HI16
, "mips-got-hi16"},
836 {MO_GOT_LO16
, "mips-got-lo16"},
837 {MO_CALL_HI16
, "mips-call-hi16"},
838 {MO_CALL_LO16
, "mips-call-lo16"},
839 {MO_JALR
, "mips-jalr"}
841 return makeArrayRef(Flags
);