]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MipsInstrInfo.cpp
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Mips / MipsInstrInfo.cpp
1 //===- MipsInstrInfo.cpp - Mips Instruction Information -------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the Mips implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MipsInstrInfo.h"
15 #include "MCTargetDesc/MipsBaseInfo.h"
16 #include "MCTargetDesc/MipsMCTargetDesc.h"
17 #include "MipsSubtarget.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/CodeGen/MachineBasicBlock.h"
20 #include "llvm/CodeGen/MachineFrameInfo.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineInstr.h"
23 #include "llvm/CodeGen/MachineInstrBuilder.h"
24 #include "llvm/CodeGen/MachineOperand.h"
25 #include "llvm/CodeGen/TargetOpcodes.h"
26 #include "llvm/CodeGen/TargetSubtargetInfo.h"
27 #include "llvm/IR/DebugLoc.h"
28 #include "llvm/MC/MCInstrDesc.h"
29 #include "llvm/Target/TargetMachine.h"
30 #include <cassert>
31
32 using namespace llvm;
33
34 #define GET_INSTRINFO_CTOR_DTOR
35 #include "MipsGenInstrInfo.inc"
36
37 // Pin the vtable to this file.
38 void MipsInstrInfo::anchor() {}
39
40 MipsInstrInfo::MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBr)
41     : MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
42       Subtarget(STI), UncondBrOpc(UncondBr) {}
43
44 const MipsInstrInfo *MipsInstrInfo::create(MipsSubtarget &STI) {
45   if (STI.inMips16Mode())
46     return createMips16InstrInfo(STI);
47
48   return createMipsSEInstrInfo(STI);
49 }
50
51 bool MipsInstrInfo::isZeroImm(const MachineOperand &op) const {
52   return op.isImm() && op.getImm() == 0;
53 }
54
55 /// insertNoop - If data hazard condition is found insert the target nop
56 /// instruction.
57 // FIXME: This appears to be dead code.
58 void MipsInstrInfo::
59 insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
60 {
61   DebugLoc DL;
62   BuildMI(MBB, MI, DL, get(Mips::NOP));
63 }
64
65 MachineMemOperand *
66 MipsInstrInfo::GetMemOperand(MachineBasicBlock &MBB, int FI,
67                              MachineMemOperand::Flags Flags) const {
68   MachineFunction &MF = *MBB.getParent();
69   MachineFrameInfo &MFI = MF.getFrameInfo();
70   unsigned Align = MFI.getObjectAlignment(FI);
71
72   return MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(MF, FI),
73                                  Flags, MFI.getObjectSize(FI), Align);
74 }
75
76 //===----------------------------------------------------------------------===//
77 // Branch Analysis
78 //===----------------------------------------------------------------------===//
79
80 void MipsInstrInfo::AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
81                                   MachineBasicBlock *&BB,
82                                   SmallVectorImpl<MachineOperand> &Cond) const {
83   assert(getAnalyzableBrOpc(Opc) && "Not an analyzable branch");
84   int NumOp = Inst->getNumExplicitOperands();
85
86   // for both int and fp branches, the last explicit operand is the
87   // MBB.
88   BB = Inst->getOperand(NumOp-1).getMBB();
89   Cond.push_back(MachineOperand::CreateImm(Opc));
90
91   for (int i = 0; i < NumOp-1; i++)
92     Cond.push_back(Inst->getOperand(i));
93 }
94
95 bool MipsInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
96                                   MachineBasicBlock *&TBB,
97                                   MachineBasicBlock *&FBB,
98                                   SmallVectorImpl<MachineOperand> &Cond,
99                                   bool AllowModify) const {
100   SmallVector<MachineInstr*, 2> BranchInstrs;
101   BranchType BT = analyzeBranch(MBB, TBB, FBB, Cond, AllowModify, BranchInstrs);
102
103   return (BT == BT_None) || (BT == BT_Indirect);
104 }
105
106 void MipsInstrInfo::BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
107                                 const DebugLoc &DL,
108                                 ArrayRef<MachineOperand> Cond) const {
109   unsigned Opc = Cond[0].getImm();
110   const MCInstrDesc &MCID = get(Opc);
111   MachineInstrBuilder MIB = BuildMI(&MBB, DL, MCID);
112
113   for (unsigned i = 1; i < Cond.size(); ++i) {
114     assert((Cond[i].isImm() || Cond[i].isReg()) &&
115            "Cannot copy operand for conditional branch!");
116     MIB.add(Cond[i]);
117   }
118   MIB.addMBB(TBB);
119 }
120
121 unsigned MipsInstrInfo::insertBranch(MachineBasicBlock &MBB,
122                                      MachineBasicBlock *TBB,
123                                      MachineBasicBlock *FBB,
124                                      ArrayRef<MachineOperand> Cond,
125                                      const DebugLoc &DL,
126                                      int *BytesAdded) const {
127   // Shouldn't be a fall through.
128   assert(TBB && "insertBranch must not be told to insert a fallthrough");
129   assert(!BytesAdded && "code size not handled");
130
131   // # of condition operands:
132   //  Unconditional branches: 0
133   //  Floating point branches: 1 (opc)
134   //  Int BranchZero: 2 (opc, reg)
135   //  Int Branch: 3 (opc, reg0, reg1)
136   assert((Cond.size() <= 3) &&
137          "# of Mips branch conditions must be <= 3!");
138
139   // Two-way Conditional branch.
140   if (FBB) {
141     BuildCondBr(MBB, TBB, DL, Cond);
142     BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB);
143     return 2;
144   }
145
146   // One way branch.
147   // Unconditional branch.
148   if (Cond.empty())
149     BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB);
150   else // Conditional branch.
151     BuildCondBr(MBB, TBB, DL, Cond);
152   return 1;
153 }
154
155 unsigned MipsInstrInfo::removeBranch(MachineBasicBlock &MBB,
156                                      int *BytesRemoved) const {
157   assert(!BytesRemoved && "code size not handled");
158
159   MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
160   unsigned removed = 0;
161
162   // Up to 2 branches are removed.
163   // Note that indirect branches are not removed.
164   while (I != REnd && removed < 2) {
165     // Skip past debug instructions.
166     if (I->isDebugValue()) {
167       ++I;
168       continue;
169     }
170     if (!getAnalyzableBrOpc(I->getOpcode()))
171       break;
172     // Remove the branch.
173     I->eraseFromParent();
174     I = MBB.rbegin();
175     ++removed;
176   }
177
178   return removed;
179 }
180
181 /// reverseBranchCondition - Return the inverse opcode of the
182 /// specified Branch instruction.
183 bool MipsInstrInfo::reverseBranchCondition(
184     SmallVectorImpl<MachineOperand> &Cond) const {
185   assert( (Cond.size() && Cond.size() <= 3) &&
186           "Invalid Mips branch condition!");
187   Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm()));
188   return false;
189 }
190
191 MipsInstrInfo::BranchType MipsInstrInfo::analyzeBranch(
192     MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
193     SmallVectorImpl<MachineOperand> &Cond, bool AllowModify,
194     SmallVectorImpl<MachineInstr *> &BranchInstrs) const {
195   MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
196
197   // Skip all the debug instructions.
198   while (I != REnd && I->isDebugValue())
199     ++I;
200
201   if (I == REnd || !isUnpredicatedTerminator(*I)) {
202     // This block ends with no branches (it just falls through to its succ).
203     // Leave TBB/FBB null.
204     TBB = FBB = nullptr;
205     return BT_NoBranch;
206   }
207
208   MachineInstr *LastInst = &*I;
209   unsigned LastOpc = LastInst->getOpcode();
210   BranchInstrs.push_back(LastInst);
211
212   // Not an analyzable branch (e.g., indirect jump).
213   if (!getAnalyzableBrOpc(LastOpc))
214     return LastInst->isIndirectBranch() ? BT_Indirect : BT_None;
215
216   // Get the second to last instruction in the block.
217   unsigned SecondLastOpc = 0;
218   MachineInstr *SecondLastInst = nullptr;
219
220   // Skip past any debug instruction to see if the second last actual
221   // is a branch.
222   ++I;
223   while (I != REnd && I->isDebugValue())
224     ++I;
225
226   if (I != REnd) {
227     SecondLastInst = &*I;
228     SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->getOpcode());
229
230     // Not an analyzable branch (must be an indirect jump).
231     if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc)
232       return BT_None;
233   }
234
235   // If there is only one terminator instruction, process it.
236   if (!SecondLastOpc) {
237     // Unconditional branch.
238     if (LastInst->isUnconditionalBranch()) {
239       TBB = LastInst->getOperand(0).getMBB();
240       return BT_Uncond;
241     }
242
243     // Conditional branch
244     AnalyzeCondBr(LastInst, LastOpc, TBB, Cond);
245     return BT_Cond;
246   }
247
248   // If we reached here, there are two branches.
249   // If there are three terminators, we don't know what sort of block this is.
250   if (++I != REnd && isUnpredicatedTerminator(*I))
251     return BT_None;
252
253   BranchInstrs.insert(BranchInstrs.begin(), SecondLastInst);
254
255   // If second to last instruction is an unconditional branch,
256   // analyze it and remove the last instruction.
257   if (SecondLastInst->isUnconditionalBranch()) {
258     // Return if the last instruction cannot be removed.
259     if (!AllowModify)
260       return BT_None;
261
262     TBB = SecondLastInst->getOperand(0).getMBB();
263     LastInst->eraseFromParent();
264     BranchInstrs.pop_back();
265     return BT_Uncond;
266   }
267
268   // Conditional branch followed by an unconditional branch.
269   // The last one must be unconditional.
270   if (!LastInst->isUnconditionalBranch())
271     return BT_None;
272
273   AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
274   FBB = LastInst->getOperand(0).getMBB();
275
276   return BT_CondUncond;
277 }
278
279 /// Return the corresponding compact (no delay slot) form of a branch.
280 unsigned MipsInstrInfo::getEquivalentCompactForm(
281     const MachineBasicBlock::iterator I) const {
282   unsigned Opcode = I->getOpcode();
283   bool canUseShortMicroMipsCTI = false;
284
285   if (Subtarget.inMicroMipsMode()) {
286     switch (Opcode) {
287     case Mips::BNE:
288     case Mips::BNE_MM:
289     case Mips::BEQ:
290     case Mips::BEQ_MM:
291     // microMIPS has NE,EQ branches that do not have delay slots provided one
292     // of the operands is zero.
293       if (I->getOperand(1).getReg() == Subtarget.getABI().GetZeroReg())
294         canUseShortMicroMipsCTI = true;
295       break;
296     // For microMIPS the PseudoReturn and PseudoIndirectBranch are always
297     // expanded to JR_MM, so they can be replaced with JRC16_MM.
298     case Mips::JR:
299     case Mips::PseudoReturn:
300     case Mips::PseudoIndirectBranch:
301       canUseShortMicroMipsCTI = true;
302       break;
303     }
304   }
305
306   // MIPSR6 forbids both operands being the zero register.
307   if (Subtarget.hasMips32r6() && (I->getNumOperands() > 1) &&
308       (I->getOperand(0).isReg() &&
309        (I->getOperand(0).getReg() == Mips::ZERO ||
310         I->getOperand(0).getReg() == Mips::ZERO_64)) &&
311       (I->getOperand(1).isReg() &&
312        (I->getOperand(1).getReg() == Mips::ZERO ||
313         I->getOperand(1).getReg() == Mips::ZERO_64)))
314     return 0;
315
316   if (Subtarget.hasMips32r6() || canUseShortMicroMipsCTI) {
317     switch (Opcode) {
318     case Mips::B:
319       return Mips::BC;
320     case Mips::BAL:
321       return Mips::BALC;
322     case Mips::BEQ:
323     case Mips::BEQ_MM:
324       if (canUseShortMicroMipsCTI)
325         return Mips::BEQZC_MM;
326       else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
327         return 0;
328       return Mips::BEQC;
329     case Mips::BNE:
330     case Mips::BNE_MM:
331       if (canUseShortMicroMipsCTI)
332         return Mips::BNEZC_MM;
333       else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
334         return 0;
335       return Mips::BNEC;
336     case Mips::BGE:
337       if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
338         return 0;
339       return Mips::BGEC;
340     case Mips::BGEU:
341       if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
342         return 0;
343       return Mips::BGEUC;
344     case Mips::BGEZ:
345       return Mips::BGEZC;
346     case Mips::BGTZ:
347       return Mips::BGTZC;
348     case Mips::BLEZ:
349       return Mips::BLEZC;
350     case Mips::BLT:
351       if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
352         return 0;
353       return Mips::BLTC;
354     case Mips::BLTU:
355       if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
356         return 0;
357       return Mips::BLTUC;
358     case Mips::BLTZ:
359       return Mips::BLTZC;
360     case Mips::BEQ64:
361       if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
362         return 0;
363       return Mips::BEQC64;
364     case Mips::BNE64:
365       if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
366         return 0;
367       return Mips::BNEC64;
368     case Mips::BGTZ64:
369       return Mips::BGTZC64;
370     case Mips::BGEZ64:
371       return Mips::BGEZC64;
372     case Mips::BLTZ64:
373       return Mips::BLTZC64;
374     case Mips::BLEZ64:
375       return Mips::BLEZC64;
376     // For MIPSR6, the instruction 'jic' can be used for these cases. Some
377     // tools will accept 'jrc reg' as an alias for 'jic 0, $reg'.
378     case Mips::JR:
379     case Mips::PseudoIndirectBranchR6:
380     case Mips::PseudoReturn:
381     case Mips::TAILCALLR6REG:
382       if (canUseShortMicroMipsCTI)
383         return Mips::JRC16_MM;
384       return Mips::JIC;
385     case Mips::JALRPseudo:
386       return Mips::JIALC;
387     case Mips::JR64:
388     case Mips::PseudoIndirectBranch64R6:
389     case Mips::PseudoReturn64:
390     case Mips::TAILCALL64R6REG:
391       return Mips::JIC64;
392     case Mips::JALR64Pseudo:
393       return Mips::JIALC64;
394     default:
395       return 0;
396     }
397   }
398
399   return 0;
400 }
401
402 /// Predicate for distingushing between control transfer instructions and all
403 /// other instructions for handling forbidden slots. Consider inline assembly
404 /// as unsafe as well.
405 bool MipsInstrInfo::SafeInForbiddenSlot(const MachineInstr &MI) const {
406   if (MI.isInlineAsm())
407     return false;
408
409   return (MI.getDesc().TSFlags & MipsII::IsCTI) == 0;
410 }
411
412 /// Predicate for distingushing instructions that have forbidden slots.
413 bool MipsInstrInfo::HasForbiddenSlot(const MachineInstr &MI) const {
414   return (MI.getDesc().TSFlags & MipsII::HasForbiddenSlot) != 0;
415 }
416
417 /// Return the number of bytes of code the specified instruction may be.
418 unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
419   switch (MI.getOpcode()) {
420   default:
421     return MI.getDesc().getSize();
422   case  TargetOpcode::INLINEASM: {       // Inline Asm: Variable size.
423     const MachineFunction *MF = MI.getParent()->getParent();
424     const char *AsmStr = MI.getOperand(0).getSymbolName();
425     return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
426   }
427   case Mips::CONSTPOOL_ENTRY:
428     // If this machine instr is a constant pool entry, its size is recorded as
429     // operand #2.
430     return MI.getOperand(2).getImm();
431   }
432 }
433
434 MachineInstrBuilder
435 MipsInstrInfo::genInstrWithNewOpc(unsigned NewOpc,
436                                   MachineBasicBlock::iterator I) const {
437   MachineInstrBuilder MIB;
438
439   // Certain branches have two forms: e.g beq $1, $zero, dest vs beqz $1, dest
440   // Pick the zero form of the branch for readable assembly and for greater
441   // branch distance in non-microMIPS mode.
442   // Additional MIPSR6 does not permit the use of register $zero for compact
443   // branches.
444   // FIXME: Certain atomic sequences on mips64 generate 32bit references to
445   // Mips::ZERO, which is incorrect. This test should be updated to use
446   // Subtarget.getABI().GetZeroReg() when those atomic sequences and others
447   // are fixed.
448   int ZeroOperandPosition = -1;
449   bool BranchWithZeroOperand = false;
450   if (I->isBranch() && !I->isPseudo()) {
451     auto TRI = I->getParent()->getParent()->getSubtarget().getRegisterInfo();
452     ZeroOperandPosition = I->findRegisterUseOperandIdx(Mips::ZERO, false, TRI);
453     BranchWithZeroOperand = ZeroOperandPosition != -1;
454   }
455
456   if (BranchWithZeroOperand) {
457     switch (NewOpc) {
458     case Mips::BEQC:
459       NewOpc = Mips::BEQZC;
460       break;
461     case Mips::BNEC:
462       NewOpc = Mips::BNEZC;
463       break;
464     case Mips::BGEC:
465       NewOpc = Mips::BGEZC;
466       break;
467     case Mips::BLTC:
468       NewOpc = Mips::BLTZC;
469       break;
470     case Mips::BEQC64:
471       NewOpc = Mips::BEQZC64;
472       break;
473     case Mips::BNEC64:
474       NewOpc = Mips::BNEZC64;
475       break;
476     }
477   }
478
479   MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), get(NewOpc));
480
481   // For MIPSR6 JI*C requires an immediate 0 as an operand, JIALC(64) an
482   // immediate 0 as an operand and requires the removal of it's implicit-def %ra
483   // implicit operand as copying the implicit operations of the instructio we're
484   // looking at will give us the correct flags.
485   if (NewOpc == Mips::JIC || NewOpc == Mips::JIALC || NewOpc == Mips::JIC64 ||
486       NewOpc == Mips::JIALC64) {
487
488     if (NewOpc == Mips::JIALC || NewOpc == Mips::JIALC64)
489       MIB->RemoveOperand(0);
490
491     for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) {
492       MIB.add(I->getOperand(J));
493     }
494
495     MIB.addImm(0);
496
497   } else {
498     for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) {
499       if (BranchWithZeroOperand && (unsigned)ZeroOperandPosition == J)
500         continue;
501
502       MIB.add(I->getOperand(J));
503     }
504   }
505
506   MIB.copyImplicitOps(*I);
507
508   MIB.setMemRefs(I->memoperands_begin(), I->memoperands_end());
509   return MIB;
510 }
511
512 bool MipsInstrInfo::findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
513                                           unsigned &SrcOpIdx2) const {
514   assert(!MI.isBundle() &&
515          "TargetInstrInfo::findCommutedOpIndices() can't handle bundles");
516
517   const MCInstrDesc &MCID = MI.getDesc();
518   if (!MCID.isCommutable())
519     return false;
520
521   switch (MI.getOpcode()) {
522   case Mips::DPADD_U_H:
523   case Mips::DPADD_U_W:
524   case Mips::DPADD_U_D:
525   case Mips::DPADD_S_H:
526   case Mips::DPADD_S_W:
527   case Mips::DPADD_S_D:
528     // The first operand is both input and output, so it should not commute
529     if (!fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3))
530       return false;
531
532     if (!MI.getOperand(SrcOpIdx1).isReg() || !MI.getOperand(SrcOpIdx2).isReg())
533       return false;
534     return true;
535   }
536   return TargetInstrInfo::findCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2);
537 }
538
539 // ins, ext, dext*, dins have the following constraints:
540 // X <= pos      <  Y
541 // X <  size     <= Y
542 // X <  pos+size <= Y
543 //
544 // dinsm and dinsu have the following constraints:
545 // X <= pos      <  Y
546 // X <= size     <= Y
547 // X <  pos+size <= Y
548 //
549 // The callee of verifyInsExtInstruction however gives the bounds of
550 // dins[um] like the other (d)ins (d)ext(um) instructions, so that this
551 // function doesn't have to vary it's behaviour based on the instruction
552 // being checked.
553 static bool verifyInsExtInstruction(const MachineInstr &MI, StringRef &ErrInfo,
554                                     const int64_t PosLow, const int64_t PosHigh,
555                                     const int64_t SizeLow,
556                                     const int64_t SizeHigh,
557                                     const int64_t BothLow,
558                                     const int64_t BothHigh) {
559   MachineOperand MOPos = MI.getOperand(2);
560   if (!MOPos.isImm()) {
561     ErrInfo = "Position is not an immediate!";
562     return false;
563   }
564   int64_t Pos = MOPos.getImm();
565   if (!((PosLow <= Pos) && (Pos < PosHigh))) {
566     ErrInfo = "Position operand is out of range!";
567     return false;
568   }
569
570   MachineOperand MOSize = MI.getOperand(3);
571   if (!MOSize.isImm()) {
572     ErrInfo = "Size operand is not an immediate!";
573     return false;
574   }
575   int64_t Size = MOSize.getImm();
576   if (!((SizeLow < Size) && (Size <= SizeHigh))) {
577     ErrInfo = "Size operand is out of range!";
578     return false;
579   }
580
581   if (!((BothLow < (Pos + Size)) && ((Pos + Size) <= BothHigh))) {
582     ErrInfo = "Position + Size is out of range!";
583     return false;
584   }
585
586   return true;
587 }
588
589 //  Perform target specific instruction verification.
590 bool MipsInstrInfo::verifyInstruction(const MachineInstr &MI,
591                                       StringRef &ErrInfo) const {
592   // Verify that ins and ext instructions are well formed.
593   switch (MI.getOpcode()) {
594     case Mips::EXT:
595     case Mips::EXT_MM:
596     case Mips::INS:
597     case Mips::INS_MM:
598     case Mips::DINS:
599       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 0, 32, 0, 32);
600     case Mips::DINSM:
601       // The ISA spec has a subtle difference difference between dinsm and dextm
602       // in that it says:
603       // 2 <= size <= 64 for 'dinsm' but 'dextm' has 32 < size <= 64.
604       // To make the bounds checks similar, the range 1 < size <= 64 is checked
605       // for 'dinsm'.
606       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 1, 64, 32, 64);
607     case Mips::DINSU:
608       // The ISA spec has a subtle difference between dinsu and dextu in that
609       // the size range of dinsu is specified as 1 <= size <= 32 whereas size
610       // for dextu is 0 < size <= 32. The range checked for dinsu here is
611       // 0 < size <= 32, which is equivalent and similar to dextu.
612       return verifyInsExtInstruction(MI, ErrInfo, 32, 64, 0, 32, 32, 64);
613     case Mips::DEXT:
614       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 0, 32, 0, 63);
615     case Mips::DEXTM:
616       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 32, 64, 32, 64);
617     case Mips::DEXTU:
618       return verifyInsExtInstruction(MI, ErrInfo, 32, 64, 0, 32, 32, 64);
619     case Mips::TAILCALLREG:
620     case Mips::PseudoIndirectBranch:
621     case Mips::JR:
622     case Mips::JR64:
623     case Mips::JALR:
624     case Mips::JALR64:
625     case Mips::JALRPseudo:
626       if (!Subtarget.useIndirectJumpsHazard())
627         return true;
628
629       ErrInfo = "invalid instruction when using jump guards!";
630       return false;
631     default:
632       return true;
633   }
634
635   return true;
636 }
637
638 std::pair<unsigned, unsigned>
639 MipsInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF) const {
640   return std::make_pair(TF, 0u);
641 }
642
643 ArrayRef<std::pair<unsigned, const char*>>
644 MipsInstrInfo::getSerializableDirectMachineOperandTargetFlags() const {
645  using namespace MipsII;
646
647  static const std::pair<unsigned, const char*> Flags[] = {
648     {MO_GOT,          "mips-got"},
649     {MO_GOT_CALL,     "mips-got-call"},
650     {MO_GPREL,        "mips-gprel"},
651     {MO_ABS_HI,       "mips-abs-hi"},
652     {MO_ABS_LO,       "mips-abs-lo"},
653     {MO_TLSGD,        "mips-tlsgd"},
654     {MO_TLSLDM,       "mips-tlsldm"},
655     {MO_DTPREL_HI,    "mips-dtprel-hi"},
656     {MO_DTPREL_LO,    "mips-dtprel-lo"},
657     {MO_GOTTPREL,     "mips-gottprel"},
658     {MO_TPREL_HI,     "mips-tprel-hi"},
659     {MO_TPREL_LO,     "mips-tprel-lo"},
660     {MO_GPOFF_HI,     "mips-gpoff-hi"},
661     {MO_GPOFF_LO,     "mips-gpoff-lo"},
662     {MO_GOT_DISP,     "mips-got-disp"},
663     {MO_GOT_PAGE,     "mips-got-page"},
664     {MO_GOT_OFST,     "mips-got-ofst"},
665     {MO_HIGHER,       "mips-higher"},
666     {MO_HIGHEST,      "mips-highest"},
667     {MO_GOT_HI16,     "mips-got-hi16"},
668     {MO_GOT_LO16,     "mips-got-lo16"},
669     {MO_CALL_HI16,    "mips-call-hi16"},
670     {MO_CALL_LO16,    "mips-call-lo16"}
671   };
672   return makeArrayRef(Flags);
673 }