Revert r155365, r155366, and r155367. All three of these have regression
[oota-llvm.git] / lib / Target / Hexagon / HexagonInstrInfo.cpp
1 //===-- HexagonInstrInfo.cpp - Hexagon 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 Hexagon implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "Hexagon.h"
15 #include "HexagonInstrInfo.h"
16 #include "HexagonRegisterInfo.h"
17 #include "HexagonSubtarget.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/CodeGen/DFAPacketizer.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineMemOperand.h"
25 #include "llvm/CodeGen/PseudoSourceValue.h"
26 #include "llvm/Support/MathExtras.h"
27 #define GET_INSTRINFO_CTOR
28 #include "HexagonGenInstrInfo.inc"
29 #include "HexagonGenDFAPacketizer.inc"
30
31 using namespace llvm;
32
33 ///
34 /// Constants for Hexagon instructions.
35 ///
36 const int Hexagon_MEMW_OFFSET_MAX = 4095;
37 const int Hexagon_MEMW_OFFSET_MIN = 4096;
38 const int Hexagon_MEMD_OFFSET_MAX = 8191;
39 const int Hexagon_MEMD_OFFSET_MIN = 8192;
40 const int Hexagon_MEMH_OFFSET_MAX = 2047;
41 const int Hexagon_MEMH_OFFSET_MIN = 2048;
42 const int Hexagon_MEMB_OFFSET_MAX = 1023;
43 const int Hexagon_MEMB_OFFSET_MIN = 1024;
44 const int Hexagon_ADDI_OFFSET_MAX = 32767;
45 const int Hexagon_ADDI_OFFSET_MIN = 32768;
46 const int Hexagon_MEMD_AUTOINC_MAX = 56;
47 const int Hexagon_MEMD_AUTOINC_MIN = 64;
48 const int Hexagon_MEMW_AUTOINC_MAX = 28;
49 const int Hexagon_MEMW_AUTOINC_MIN = 32;
50 const int Hexagon_MEMH_AUTOINC_MAX = 14;
51 const int Hexagon_MEMH_AUTOINC_MIN = 16;
52 const int Hexagon_MEMB_AUTOINC_MAX = 7;
53 const int Hexagon_MEMB_AUTOINC_MIN = 8;
54
55
56
57 HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST)
58   : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
59     RI(ST, *this), Subtarget(ST) {
60 }
61
62
63 /// isLoadFromStackSlot - If the specified machine instruction is a direct
64 /// load from a stack slot, return the virtual or physical register number of
65 /// the destination along with the FrameIndex of the loaded stack slot.  If
66 /// not, return 0.  This predicate must return 0 if the instruction has
67 /// any side effects other than loading from the stack slot.
68 unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
69                                              int &FrameIndex) const {
70
71
72   switch (MI->getOpcode()) {
73   case Hexagon::LDriw:
74   case Hexagon::LDrid:
75   case Hexagon::LDrih:
76   case Hexagon::LDrib:
77   case Hexagon::LDriub:
78     if (MI->getOperand(2).isFI() &&
79         MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
80       FrameIndex = MI->getOperand(2).getIndex();
81       return MI->getOperand(0).getReg();
82     }
83     break;
84
85   default:
86     break;
87   }
88
89   return 0;
90 }
91
92
93 /// isStoreToStackSlot - If the specified machine instruction is a direct
94 /// store to a stack slot, return the virtual or physical register number of
95 /// the source reg along with the FrameIndex of the loaded stack slot.  If
96 /// not, return 0.  This predicate must return 0 if the instruction has
97 /// any side effects other than storing to the stack slot.
98 unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
99                                             int &FrameIndex) const {
100   switch (MI->getOpcode()) {
101   case Hexagon::STriw:
102   case Hexagon::STrid:
103   case Hexagon::STrih:
104   case Hexagon::STrib:
105     if (MI->getOperand(2).isFI() &&
106         MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
107       FrameIndex = MI->getOperand(2).getIndex();
108       return MI->getOperand(0).getReg();
109     }
110     break;
111
112   default:
113     break;
114   }
115
116   return 0;
117 }
118
119
120 unsigned
121 HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
122                              MachineBasicBlock *FBB,
123                              const SmallVectorImpl<MachineOperand> &Cond,
124                              DebugLoc DL) const{
125
126     int BOpc   = Hexagon::JMP;
127     int BccOpc = Hexagon::JMP_c;
128
129     assert(TBB && "InsertBranch must not be told to insert a fallthrough");
130
131     int regPos = 0;
132     // Check if ReverseBranchCondition has asked to reverse this branch
133     // If we want to reverse the branch an odd number of times, we want
134     // JMP_cNot.
135     if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
136       BccOpc = Hexagon::JMP_cNot;
137       regPos = 1;
138     }
139
140     if (FBB == 0) {
141       if (Cond.empty()) {
142         // Due to a bug in TailMerging/CFG Optimization, we need to add a
143         // special case handling of a predicated jump followed by an
144         // unconditional jump. If not, Tail Merging and CFG Optimization go
145         // into an infinite loop.
146         MachineBasicBlock *NewTBB, *NewFBB;
147         SmallVector<MachineOperand, 4> Cond;
148         MachineInstr *Term = MBB.getFirstTerminator();
149         if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond,
150                                                  false)) {
151           MachineBasicBlock *NextBB =
152             llvm::next(MachineFunction::iterator(&MBB));
153           if (NewTBB == NextBB) {
154             ReverseBranchCondition(Cond);
155             RemoveBranch(MBB);
156             return InsertBranch(MBB, TBB, 0, Cond, DL);
157           }
158         }
159         BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
160       } else {
161         BuildMI(&MBB, DL,
162                 get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
163       }
164       return 1;
165     }
166
167     BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
168     BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
169
170     return 2;
171 }
172
173
174 bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
175                                      MachineBasicBlock *&TBB,
176                                  MachineBasicBlock *&FBB,
177                                  SmallVectorImpl<MachineOperand> &Cond,
178                                  bool AllowModify) const {
179   FBB = NULL;
180
181   // If the block has no terminators, it just falls into the block after it.
182   MachineBasicBlock::iterator I = MBB.end();
183   if (I == MBB.begin())
184     return false;
185
186   // A basic block may looks like this:
187   //
188   //  [   insn
189   //     EH_LABEL
190   //      insn
191   //      insn
192   //      insn
193   //     EH_LABEL
194   //      insn     ]
195   //
196   // It has two succs but does not have a terminator
197   // Don't know how to handle it.
198   do {
199     --I;
200     if (I->isEHLabel())
201       return true;
202   } while (I != MBB.begin());
203
204   I = MBB.end();
205   --I;
206
207   while (I->isDebugValue()) {
208     if (I == MBB.begin())
209       return false;
210     --I;
211   }
212   if (!isUnpredicatedTerminator(I))
213     return false;
214
215   // Get the last instruction in the block.
216   MachineInstr *LastInst = I;
217
218   // If there is only one terminator instruction, process it.
219   if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
220     if (LastInst->getOpcode() == Hexagon::JMP) {
221       TBB = LastInst->getOperand(0).getMBB();
222       return false;
223     }
224     if (LastInst->getOpcode() == Hexagon::JMP_c) {
225       // Block ends with fall-through true condbranch.
226       TBB = LastInst->getOperand(1).getMBB();
227       Cond.push_back(LastInst->getOperand(0));
228       return false;
229     }
230     if (LastInst->getOpcode() == Hexagon::JMP_cNot) {
231       // Block ends with fall-through false condbranch.
232       TBB = LastInst->getOperand(1).getMBB();
233       Cond.push_back(MachineOperand::CreateImm(0));
234       Cond.push_back(LastInst->getOperand(0));
235       return false;
236     }
237     // Otherwise, don't know what this is.
238     return true;
239   }
240
241   // Get the instruction before it if it's a terminator.
242   MachineInstr *SecondLastInst = I;
243
244   // If there are three terminators, we don't know what sort of block this is.
245   if (SecondLastInst && I != MBB.begin() &&
246       isUnpredicatedTerminator(--I))
247     return true;
248
249   // If the block ends with Hexagon::BRCOND and Hexagon:JMP, handle it.
250   if (((SecondLastInst->getOpcode() == Hexagon::BRCOND) ||
251       (SecondLastInst->getOpcode() == Hexagon::JMP_c)) &&
252       LastInst->getOpcode() == Hexagon::JMP) {
253     TBB =  SecondLastInst->getOperand(1).getMBB();
254     Cond.push_back(SecondLastInst->getOperand(0));
255     FBB = LastInst->getOperand(0).getMBB();
256     return false;
257   }
258
259   // If the block ends with Hexagon::JMP_cNot and Hexagon:JMP, handle it.
260   if ((SecondLastInst->getOpcode() == Hexagon::JMP_cNot) &&
261       LastInst->getOpcode() == Hexagon::JMP) {
262     TBB =  SecondLastInst->getOperand(1).getMBB();
263     Cond.push_back(MachineOperand::CreateImm(0));
264     Cond.push_back(SecondLastInst->getOperand(0));
265     FBB = LastInst->getOperand(0).getMBB();
266     return false;
267   }
268
269   // If the block ends with two Hexagon:JMPs, handle it.  The second one is not
270   // executed, so remove it.
271   if (SecondLastInst->getOpcode() == Hexagon::JMP &&
272       LastInst->getOpcode() == Hexagon::JMP) {
273     TBB = SecondLastInst->getOperand(0).getMBB();
274     I = LastInst;
275     if (AllowModify)
276       I->eraseFromParent();
277     return false;
278   }
279
280   // Otherwise, can't handle this.
281   return true;
282 }
283
284
285 unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
286   int BOpc   = Hexagon::JMP;
287   int BccOpc = Hexagon::JMP_c;
288   int BccOpcNot = Hexagon::JMP_cNot;
289
290   MachineBasicBlock::iterator I = MBB.end();
291   if (I == MBB.begin()) return 0;
292   --I;
293   if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
294       I->getOpcode() != BccOpcNot)
295     return 0;
296
297   // Remove the branch.
298   I->eraseFromParent();
299
300   I = MBB.end();
301
302   if (I == MBB.begin()) return 1;
303   --I;
304   if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
305     return 1;
306
307   // Remove the branch.
308   I->eraseFromParent();
309   return 2;
310 }
311
312
313 void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
314                                  MachineBasicBlock::iterator I, DebugLoc DL,
315                                  unsigned DestReg, unsigned SrcReg,
316                                  bool KillSrc) const {
317   if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
318     BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg);
319     return;
320   }
321   if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
322     BuildMI(MBB, I, DL, get(Hexagon::TFR_64), DestReg).addReg(SrcReg);
323     return;
324   }
325   if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
326     // Map Pd = Ps to Pd = or(Ps, Ps).
327     BuildMI(MBB, I, DL, get(Hexagon::OR_pp),
328             DestReg).addReg(SrcReg).addReg(SrcReg);
329     return;
330   }
331   if (Hexagon::DoubleRegsRegClass.contains(DestReg, SrcReg)) {
332     // We can have an overlap between single and double reg: r1:0 = r0.
333     if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) {
334         // r1:0 = r0
335         BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
336                 Hexagon::subreg_hireg))).addImm(0);
337     } else {
338         // r1:0 = r1 or no overlap.
339         BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg,
340                 Hexagon::subreg_loreg))).addReg(SrcReg);
341         BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
342                 Hexagon::subreg_hireg))).addImm(0);
343     }
344     return;
345   }
346   if (Hexagon::CRRegsRegClass.contains(DestReg, SrcReg)) {
347     BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg);
348     return;
349   }
350
351   llvm_unreachable("Unimplemented");
352 }
353
354
355 void HexagonInstrInfo::
356 storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
357                     unsigned SrcReg, bool isKill, int FI,
358                     const TargetRegisterClass *RC,
359                     const TargetRegisterInfo *TRI) const {
360
361   DebugLoc DL = MBB.findDebugLoc(I);
362   MachineFunction &MF = *MBB.getParent();
363   MachineFrameInfo &MFI = *MF.getFrameInfo();
364   unsigned Align = MFI.getObjectAlignment(FI);
365
366   MachineMemOperand *MMO =
367       MF.getMachineMemOperand(
368                       MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
369                       MachineMemOperand::MOStore,
370                       MFI.getObjectSize(FI),
371                       Align);
372
373   if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
374     BuildMI(MBB, I, DL, get(Hexagon::STriw))
375           .addFrameIndex(FI).addImm(0)
376           .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
377   } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
378     BuildMI(MBB, I, DL, get(Hexagon::STrid))
379           .addFrameIndex(FI).addImm(0)
380           .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
381   } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
382     BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
383           .addFrameIndex(FI).addImm(0)
384           .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
385   } else {
386     llvm_unreachable("Unimplemented");
387   }
388 }
389
390
391 void HexagonInstrInfo::storeRegToAddr(
392                                  MachineFunction &MF, unsigned SrcReg,
393                                  bool isKill,
394                                  SmallVectorImpl<MachineOperand> &Addr,
395                                  const TargetRegisterClass *RC,
396                                  SmallVectorImpl<MachineInstr*> &NewMIs) const
397 {
398   llvm_unreachable("Unimplemented");
399 }
400
401
402 void HexagonInstrInfo::
403 loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
404                      unsigned DestReg, int FI,
405                      const TargetRegisterClass *RC,
406                      const TargetRegisterInfo *TRI) const {
407   DebugLoc DL = MBB.findDebugLoc(I);
408   MachineFunction &MF = *MBB.getParent();
409   MachineFrameInfo &MFI = *MF.getFrameInfo();
410   unsigned Align = MFI.getObjectAlignment(FI);
411
412   MachineMemOperand *MMO =
413       MF.getMachineMemOperand(
414                       MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
415                       MachineMemOperand::MOLoad,
416                       MFI.getObjectSize(FI),
417                       Align);
418
419   if (RC == &Hexagon::IntRegsRegClass) {
420     BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg)
421           .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
422   } else if (RC == &Hexagon::DoubleRegsRegClass) {
423     BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg)
424           .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
425   } else if (RC == &Hexagon::PredRegsRegClass) {
426     BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
427           .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
428   } else {
429     llvm_unreachable("Can't store this register to stack slot");
430   }
431 }
432
433
434 void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
435                                         SmallVectorImpl<MachineOperand> &Addr,
436                                         const TargetRegisterClass *RC,
437                                  SmallVectorImpl<MachineInstr*> &NewMIs) const {
438   llvm_unreachable("Unimplemented");
439 }
440
441
442 MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
443                                                     MachineInstr* MI,
444                                           const SmallVectorImpl<unsigned> &Ops,
445                                                     int FI) const {
446   // Hexagon_TODO: Implement.
447   return(0);
448 }
449
450
451 unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const {
452
453   MachineRegisterInfo &RegInfo = MF->getRegInfo();
454   const TargetRegisterClass *TRC;
455   if (VT == MVT::i1)
456     TRC = &Hexagon::PredRegsRegClass;
457   else if (VT == MVT::i32)
458     TRC = &Hexagon::IntRegsRegClass;
459   else if (VT == MVT::i64)
460     TRC = &Hexagon::DoubleRegsRegClass;
461   else
462     llvm_unreachable("Cannot handle this register class");
463
464   unsigned NewReg = RegInfo.createVirtualRegister(TRC);
465   return NewReg;
466 }
467
468
469
470 bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
471   bool isPred = MI->getDesc().isPredicable();
472
473   if (!isPred)
474     return false;
475
476   const int Opc = MI->getOpcode();
477
478   switch(Opc) {
479   case Hexagon::TFRI:
480     return isInt<12>(MI->getOperand(1).getImm());
481
482   case Hexagon::STrid:
483   case Hexagon::STrid_indexed:
484     return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
485
486   case Hexagon::STriw:
487   case Hexagon::STriw_indexed:
488   case Hexagon::STriw_nv_V4:
489     return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
490
491   case Hexagon::STrih:
492   case Hexagon::STrih_indexed:
493   case Hexagon::STrih_nv_V4:
494     return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
495
496   case Hexagon::STrib:
497   case Hexagon::STrib_indexed:
498   case Hexagon::STrib_nv_V4:
499     return isUInt<6>(MI->getOperand(1).getImm());
500
501   case Hexagon::LDrid:
502   case Hexagon::LDrid_indexed:
503     return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
504
505   case Hexagon::LDriw:
506   case Hexagon::LDriw_indexed:
507     return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
508
509   case Hexagon::LDrih:
510   case Hexagon::LDriuh:
511   case Hexagon::LDrih_indexed:
512   case Hexagon::LDriuh_indexed:
513     return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
514
515   case Hexagon::LDrib:
516   case Hexagon::LDriub:
517   case Hexagon::LDrib_indexed:
518   case Hexagon::LDriub_indexed:
519     return isUInt<6>(MI->getOperand(2).getImm());
520
521   case Hexagon::POST_LDrid:
522     return isShiftedInt<4,3>(MI->getOperand(3).getImm());
523
524   case Hexagon::POST_LDriw:
525     return isShiftedInt<4,2>(MI->getOperand(3).getImm());
526
527   case Hexagon::POST_LDrih:
528   case Hexagon::POST_LDriuh:
529     return isShiftedInt<4,1>(MI->getOperand(3).getImm());
530
531   case Hexagon::POST_LDrib:
532   case Hexagon::POST_LDriub:
533     return isInt<4>(MI->getOperand(3).getImm());
534
535   case Hexagon::STrib_imm_V4:
536   case Hexagon::STrih_imm_V4:
537   case Hexagon::STriw_imm_V4:
538     return (isUInt<6>(MI->getOperand(1).getImm()) &&
539             isInt<6>(MI->getOperand(2).getImm()));
540
541   case Hexagon::ADD_ri:
542     return isInt<8>(MI->getOperand(2).getImm());
543
544   case Hexagon::ASLH:
545   case Hexagon::ASRH:
546   case Hexagon::SXTB:
547   case Hexagon::SXTH:
548   case Hexagon::ZXTB:
549   case Hexagon::ZXTH:
550     return Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
551
552   case Hexagon::JMPR:
553     return false;
554   }
555
556   return true;
557 }
558
559 unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const {
560   switch(Opc) {
561     case Hexagon::TFR_cPt:
562       return Hexagon::TFR_cNotPt;
563     case Hexagon::TFR_cNotPt:
564       return Hexagon::TFR_cPt;
565
566     case Hexagon::TFRI_cPt:
567       return Hexagon::TFRI_cNotPt;
568     case Hexagon::TFRI_cNotPt:
569       return Hexagon::TFRI_cPt;
570
571     case Hexagon::JMP_c:
572       return Hexagon::JMP_cNot;
573     case Hexagon::JMP_cNot:
574       return Hexagon::JMP_c;
575
576     case Hexagon::ADD_ri_cPt:
577       return Hexagon::ADD_ri_cNotPt;
578     case Hexagon::ADD_ri_cNotPt:
579       return Hexagon::ADD_ri_cPt;
580
581     case Hexagon::ADD_rr_cPt:
582       return Hexagon::ADD_rr_cNotPt;
583     case Hexagon::ADD_rr_cNotPt:
584       return Hexagon::ADD_rr_cPt;
585
586     case Hexagon::XOR_rr_cPt:
587       return Hexagon::XOR_rr_cNotPt;
588     case Hexagon::XOR_rr_cNotPt:
589       return Hexagon::XOR_rr_cPt;
590
591     case Hexagon::AND_rr_cPt:
592       return Hexagon::AND_rr_cNotPt;
593     case Hexagon::AND_rr_cNotPt:
594       return Hexagon::AND_rr_cPt;
595
596     case Hexagon::OR_rr_cPt:
597       return Hexagon::OR_rr_cNotPt;
598     case Hexagon::OR_rr_cNotPt:
599       return Hexagon::OR_rr_cPt;
600
601     case Hexagon::SUB_rr_cPt:
602       return Hexagon::SUB_rr_cNotPt;
603     case Hexagon::SUB_rr_cNotPt:
604       return Hexagon::SUB_rr_cPt;
605
606     case Hexagon::COMBINE_rr_cPt:
607       return Hexagon::COMBINE_rr_cNotPt;
608     case Hexagon::COMBINE_rr_cNotPt:
609       return Hexagon::COMBINE_rr_cPt;
610
611     case Hexagon::ASLH_cPt_V4:
612       return Hexagon::ASLH_cNotPt_V4;
613     case Hexagon::ASLH_cNotPt_V4:
614       return Hexagon::ASLH_cPt_V4;
615
616     case Hexagon::ASRH_cPt_V4:
617       return Hexagon::ASRH_cNotPt_V4;
618     case Hexagon::ASRH_cNotPt_V4:
619       return Hexagon::ASRH_cPt_V4;
620
621     case Hexagon::SXTB_cPt_V4:
622       return Hexagon::SXTB_cNotPt_V4;
623     case Hexagon::SXTB_cNotPt_V4:
624       return Hexagon::SXTB_cPt_V4;
625
626     case Hexagon::SXTH_cPt_V4:
627       return Hexagon::SXTH_cNotPt_V4;
628     case Hexagon::SXTH_cNotPt_V4:
629       return Hexagon::SXTH_cPt_V4;
630
631     case Hexagon::ZXTB_cPt_V4:
632       return Hexagon::ZXTB_cNotPt_V4;
633     case Hexagon::ZXTB_cNotPt_V4:
634       return Hexagon::ZXTB_cPt_V4;
635
636     case Hexagon::ZXTH_cPt_V4:
637       return Hexagon::ZXTH_cNotPt_V4;
638     case Hexagon::ZXTH_cNotPt_V4:
639       return Hexagon::ZXTH_cPt_V4;
640
641
642     case Hexagon::JMPR_cPt:
643       return Hexagon::JMPR_cNotPt;
644     case Hexagon::JMPR_cNotPt:
645       return Hexagon::JMPR_cPt;
646
647   // V4 indexed+scaled load.
648     case Hexagon::LDrid_indexed_cPt_V4:
649       return Hexagon::LDrid_indexed_cNotPt_V4;
650     case Hexagon::LDrid_indexed_cNotPt_V4:
651       return Hexagon::LDrid_indexed_cPt_V4;
652
653     case Hexagon::LDrid_indexed_shl_cPt_V4:
654       return Hexagon::LDrid_indexed_shl_cNotPt_V4;
655     case Hexagon::LDrid_indexed_shl_cNotPt_V4:
656       return Hexagon::LDrid_indexed_shl_cPt_V4;
657
658     case Hexagon::LDrib_indexed_cPt_V4:
659       return Hexagon::LDrib_indexed_cNotPt_V4;
660     case Hexagon::LDrib_indexed_cNotPt_V4:
661       return Hexagon::LDrib_indexed_cPt_V4;
662
663     case Hexagon::LDriub_indexed_cPt_V4:
664       return Hexagon::LDriub_indexed_cNotPt_V4;
665     case Hexagon::LDriub_indexed_cNotPt_V4:
666       return Hexagon::LDriub_indexed_cPt_V4;
667
668     case Hexagon::LDrib_indexed_shl_cPt_V4:
669       return Hexagon::LDrib_indexed_shl_cNotPt_V4;
670     case Hexagon::LDrib_indexed_shl_cNotPt_V4:
671       return Hexagon::LDrib_indexed_shl_cPt_V4;
672
673     case Hexagon::LDriub_indexed_shl_cPt_V4:
674       return Hexagon::LDriub_indexed_shl_cNotPt_V4;
675     case Hexagon::LDriub_indexed_shl_cNotPt_V4:
676       return Hexagon::LDriub_indexed_shl_cPt_V4;
677
678     case Hexagon::LDrih_indexed_cPt_V4:
679       return Hexagon::LDrih_indexed_cNotPt_V4;
680     case Hexagon::LDrih_indexed_cNotPt_V4:
681       return Hexagon::LDrih_indexed_cPt_V4;
682
683     case Hexagon::LDriuh_indexed_cPt_V4:
684       return Hexagon::LDriuh_indexed_cNotPt_V4;
685     case Hexagon::LDriuh_indexed_cNotPt_V4:
686       return Hexagon::LDriuh_indexed_cPt_V4;
687
688     case Hexagon::LDrih_indexed_shl_cPt_V4:
689       return Hexagon::LDrih_indexed_shl_cNotPt_V4;
690     case Hexagon::LDrih_indexed_shl_cNotPt_V4:
691       return Hexagon::LDrih_indexed_shl_cPt_V4;
692
693     case Hexagon::LDriuh_indexed_shl_cPt_V4:
694       return Hexagon::LDriuh_indexed_shl_cNotPt_V4;
695     case Hexagon::LDriuh_indexed_shl_cNotPt_V4:
696       return Hexagon::LDriuh_indexed_shl_cPt_V4;
697
698     case Hexagon::LDriw_indexed_cPt_V4:
699       return Hexagon::LDriw_indexed_cNotPt_V4;
700     case Hexagon::LDriw_indexed_cNotPt_V4:
701       return Hexagon::LDriw_indexed_cPt_V4;
702
703     case Hexagon::LDriw_indexed_shl_cPt_V4:
704       return Hexagon::LDriw_indexed_shl_cNotPt_V4;
705     case Hexagon::LDriw_indexed_shl_cNotPt_V4:
706       return Hexagon::LDriw_indexed_shl_cPt_V4;
707
708     // Byte.
709     case Hexagon::POST_STbri_cPt:
710       return Hexagon::POST_STbri_cNotPt;
711     case Hexagon::POST_STbri_cNotPt:
712       return Hexagon::POST_STbri_cPt;
713
714     case Hexagon::STrib_cPt:
715       return Hexagon::STrib_cNotPt;
716     case Hexagon::STrib_cNotPt:
717       return Hexagon::STrib_cPt;
718
719     case Hexagon::STrib_indexed_cPt:
720       return Hexagon::STrib_indexed_cNotPt;
721     case Hexagon::STrib_indexed_cNotPt:
722       return Hexagon::STrib_indexed_cPt;
723
724     case Hexagon::STrib_imm_cPt_V4:
725       return Hexagon::STrib_imm_cNotPt_V4;
726     case Hexagon::STrib_imm_cNotPt_V4:
727       return Hexagon::STrib_imm_cPt_V4;
728
729     case Hexagon::STrib_indexed_shl_cPt_V4:
730       return Hexagon::STrib_indexed_shl_cNotPt_V4;
731     case Hexagon::STrib_indexed_shl_cNotPt_V4:
732       return Hexagon::STrib_indexed_shl_cPt_V4;
733
734   // Halfword.
735     case Hexagon::POST_SThri_cPt:
736       return Hexagon::POST_SThri_cNotPt;
737     case Hexagon::POST_SThri_cNotPt:
738       return Hexagon::POST_SThri_cPt;
739
740     case Hexagon::STrih_cPt:
741       return Hexagon::STrih_cNotPt;
742     case Hexagon::STrih_cNotPt:
743       return Hexagon::STrih_cPt;
744
745     case Hexagon::STrih_indexed_cPt:
746       return Hexagon::STrih_indexed_cNotPt;
747     case Hexagon::STrih_indexed_cNotPt:
748       return Hexagon::STrih_indexed_cPt;
749
750     case Hexagon::STrih_imm_cPt_V4:
751       return Hexagon::STrih_imm_cNotPt_V4;
752     case Hexagon::STrih_imm_cNotPt_V4:
753       return Hexagon::STrih_imm_cPt_V4;
754
755     case Hexagon::STrih_indexed_shl_cPt_V4:
756       return Hexagon::STrih_indexed_shl_cNotPt_V4;
757     case Hexagon::STrih_indexed_shl_cNotPt_V4:
758       return Hexagon::STrih_indexed_shl_cPt_V4;
759
760   // Word.
761     case Hexagon::POST_STwri_cPt:
762       return Hexagon::POST_STwri_cNotPt;
763     case Hexagon::POST_STwri_cNotPt:
764       return Hexagon::POST_STwri_cPt;
765
766     case Hexagon::STriw_cPt:
767       return Hexagon::STriw_cNotPt;
768     case Hexagon::STriw_cNotPt:
769       return Hexagon::STriw_cPt;
770
771     case Hexagon::STriw_indexed_cPt:
772       return Hexagon::STriw_indexed_cNotPt;
773     case Hexagon::STriw_indexed_cNotPt:
774       return Hexagon::STriw_indexed_cPt;
775
776     case Hexagon::STriw_indexed_shl_cPt_V4:
777       return Hexagon::STriw_indexed_shl_cNotPt_V4;
778     case Hexagon::STriw_indexed_shl_cNotPt_V4:
779       return Hexagon::STriw_indexed_shl_cPt_V4;
780
781     case Hexagon::STriw_imm_cPt_V4:
782       return Hexagon::STriw_imm_cNotPt_V4;
783     case Hexagon::STriw_imm_cNotPt_V4:
784       return Hexagon::STriw_imm_cPt_V4;
785
786   // Double word.
787     case Hexagon::POST_STdri_cPt:
788       return Hexagon::POST_STdri_cNotPt;
789     case Hexagon::POST_STdri_cNotPt:
790       return Hexagon::POST_STdri_cPt;
791
792     case Hexagon::STrid_cPt:
793       return Hexagon::STrid_cNotPt;
794     case Hexagon::STrid_cNotPt:
795       return Hexagon::STrid_cPt;
796
797     case Hexagon::STrid_indexed_cPt:
798       return Hexagon::STrid_indexed_cNotPt;
799     case Hexagon::STrid_indexed_cNotPt:
800       return Hexagon::STrid_indexed_cPt;
801
802     case Hexagon::STrid_indexed_shl_cPt_V4:
803       return Hexagon::STrid_indexed_shl_cNotPt_V4;
804     case Hexagon::STrid_indexed_shl_cNotPt_V4:
805       return Hexagon::STrid_indexed_shl_cPt_V4;
806
807   // Load.
808     case Hexagon::LDrid_cPt:
809       return Hexagon::LDrid_cNotPt;
810     case Hexagon::LDrid_cNotPt:
811       return Hexagon::LDrid_cPt;
812
813     case Hexagon::LDriw_cPt:
814       return Hexagon::LDriw_cNotPt;
815     case Hexagon::LDriw_cNotPt:
816       return Hexagon::LDriw_cPt;
817
818     case Hexagon::LDrih_cPt:
819       return Hexagon::LDrih_cNotPt;
820     case Hexagon::LDrih_cNotPt:
821       return Hexagon::LDrih_cPt;
822
823     case Hexagon::LDriuh_cPt:
824       return Hexagon::LDriuh_cNotPt;
825     case Hexagon::LDriuh_cNotPt:
826       return Hexagon::LDriuh_cPt;
827
828     case Hexagon::LDrib_cPt:
829       return Hexagon::LDrib_cNotPt;
830     case Hexagon::LDrib_cNotPt:
831       return Hexagon::LDrib_cPt;
832
833     case Hexagon::LDriub_cPt:
834       return Hexagon::LDriub_cNotPt;
835     case Hexagon::LDriub_cNotPt:
836       return Hexagon::LDriub_cPt;
837
838  // Load Indexed.
839     case Hexagon::LDrid_indexed_cPt:
840       return Hexagon::LDrid_indexed_cNotPt;
841     case Hexagon::LDrid_indexed_cNotPt:
842       return Hexagon::LDrid_indexed_cPt;
843
844     case Hexagon::LDriw_indexed_cPt:
845       return Hexagon::LDriw_indexed_cNotPt;
846     case Hexagon::LDriw_indexed_cNotPt:
847       return Hexagon::LDriw_indexed_cPt;
848
849     case Hexagon::LDrih_indexed_cPt:
850       return Hexagon::LDrih_indexed_cNotPt;
851     case Hexagon::LDrih_indexed_cNotPt:
852       return Hexagon::LDrih_indexed_cPt;
853
854     case Hexagon::LDriuh_indexed_cPt:
855       return Hexagon::LDriuh_indexed_cNotPt;
856     case Hexagon::LDriuh_indexed_cNotPt:
857       return Hexagon::LDriuh_indexed_cPt;
858
859     case Hexagon::LDrib_indexed_cPt:
860       return Hexagon::LDrib_indexed_cNotPt;
861     case Hexagon::LDrib_indexed_cNotPt:
862       return Hexagon::LDrib_indexed_cPt;
863
864     case Hexagon::LDriub_indexed_cPt:
865       return Hexagon::LDriub_indexed_cNotPt;
866     case Hexagon::LDriub_indexed_cNotPt:
867       return Hexagon::LDriub_indexed_cPt;
868
869   // Post Inc Load.
870     case Hexagon::POST_LDrid_cPt:
871       return Hexagon::POST_LDrid_cNotPt;
872     case Hexagon::POST_LDriw_cNotPt:
873       return Hexagon::POST_LDriw_cPt;
874
875     case Hexagon::POST_LDrih_cPt:
876       return Hexagon::POST_LDrih_cNotPt;
877     case Hexagon::POST_LDrih_cNotPt:
878       return Hexagon::POST_LDrih_cPt;
879
880     case Hexagon::POST_LDriuh_cPt:
881       return Hexagon::POST_LDriuh_cNotPt;
882     case Hexagon::POST_LDriuh_cNotPt:
883       return Hexagon::POST_LDriuh_cPt;
884
885     case Hexagon::POST_LDrib_cPt:
886       return Hexagon::POST_LDrib_cNotPt;
887     case Hexagon::POST_LDrib_cNotPt:
888       return Hexagon::POST_LDrib_cPt;
889
890     case Hexagon::POST_LDriub_cPt:
891       return Hexagon::POST_LDriub_cNotPt;
892     case Hexagon::POST_LDriub_cNotPt:
893       return Hexagon::POST_LDriub_cPt;
894
895   // Dealloc_return.
896     case Hexagon::DEALLOC_RET_cPt_V4:
897       return Hexagon::DEALLOC_RET_cNotPt_V4;
898     case Hexagon::DEALLOC_RET_cNotPt_V4:
899       return Hexagon::DEALLOC_RET_cPt_V4;
900
901    // New Value Jump.
902    // JMPEQ_ri - with -1.
903     case Hexagon::JMP_EQriPtneg_nv_V4:
904       return Hexagon::JMP_EQriNotPtneg_nv_V4;
905     case Hexagon::JMP_EQriNotPtneg_nv_V4:
906       return Hexagon::JMP_EQriPtneg_nv_V4;
907
908     case Hexagon::JMP_EQriPntneg_nv_V4:
909       return Hexagon::JMP_EQriNotPntneg_nv_V4;
910     case Hexagon::JMP_EQriNotPntneg_nv_V4:
911       return Hexagon::JMP_EQriPntneg_nv_V4;
912
913    // JMPEQ_ri.
914      case Hexagon::JMP_EQriPt_nv_V4:
915       return Hexagon::JMP_EQriNotPt_nv_V4;
916     case Hexagon::JMP_EQriNotPt_nv_V4:
917       return Hexagon::JMP_EQriPt_nv_V4;
918
919      case Hexagon::JMP_EQriPnt_nv_V4:
920       return Hexagon::JMP_EQriNotPnt_nv_V4;
921     case Hexagon::JMP_EQriNotPnt_nv_V4:
922       return Hexagon::JMP_EQriPnt_nv_V4;
923
924    // JMPEQ_rr.
925      case Hexagon::JMP_EQrrPt_nv_V4:
926       return Hexagon::JMP_EQrrNotPt_nv_V4;
927     case Hexagon::JMP_EQrrNotPt_nv_V4:
928       return Hexagon::JMP_EQrrPt_nv_V4;
929
930      case Hexagon::JMP_EQrrPnt_nv_V4:
931       return Hexagon::JMP_EQrrNotPnt_nv_V4;
932     case Hexagon::JMP_EQrrNotPnt_nv_V4:
933       return Hexagon::JMP_EQrrPnt_nv_V4;
934
935    // JMPGT_ri - with -1.
936     case Hexagon::JMP_GTriPtneg_nv_V4:
937       return Hexagon::JMP_GTriNotPtneg_nv_V4;
938     case Hexagon::JMP_GTriNotPtneg_nv_V4:
939       return Hexagon::JMP_GTriPtneg_nv_V4;
940
941     case Hexagon::JMP_GTriPntneg_nv_V4:
942       return Hexagon::JMP_GTriNotPntneg_nv_V4;
943     case Hexagon::JMP_GTriNotPntneg_nv_V4:
944       return Hexagon::JMP_GTriPntneg_nv_V4;
945
946    // JMPGT_ri.
947      case Hexagon::JMP_GTriPt_nv_V4:
948       return Hexagon::JMP_GTriNotPt_nv_V4;
949     case Hexagon::JMP_GTriNotPt_nv_V4:
950       return Hexagon::JMP_GTriPt_nv_V4;
951
952      case Hexagon::JMP_GTriPnt_nv_V4:
953       return Hexagon::JMP_GTriNotPnt_nv_V4;
954     case Hexagon::JMP_GTriNotPnt_nv_V4:
955       return Hexagon::JMP_GTriPnt_nv_V4;
956
957    // JMPGT_rr.
958      case Hexagon::JMP_GTrrPt_nv_V4:
959       return Hexagon::JMP_GTrrNotPt_nv_V4;
960     case Hexagon::JMP_GTrrNotPt_nv_V4:
961       return Hexagon::JMP_GTrrPt_nv_V4;
962
963      case Hexagon::JMP_GTrrPnt_nv_V4:
964       return Hexagon::JMP_GTrrNotPnt_nv_V4;
965     case Hexagon::JMP_GTrrNotPnt_nv_V4:
966       return Hexagon::JMP_GTrrPnt_nv_V4;
967
968    // JMPGT_rrdn.
969      case Hexagon::JMP_GTrrdnPt_nv_V4:
970       return Hexagon::JMP_GTrrdnNotPt_nv_V4;
971     case Hexagon::JMP_GTrrdnNotPt_nv_V4:
972       return Hexagon::JMP_GTrrdnPt_nv_V4;
973
974      case Hexagon::JMP_GTrrdnPnt_nv_V4:
975       return Hexagon::JMP_GTrrdnNotPnt_nv_V4;
976     case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
977       return Hexagon::JMP_GTrrdnPnt_nv_V4;
978
979    // JMPGTU_ri.
980      case Hexagon::JMP_GTUriPt_nv_V4:
981       return Hexagon::JMP_GTUriNotPt_nv_V4;
982     case Hexagon::JMP_GTUriNotPt_nv_V4:
983       return Hexagon::JMP_GTUriPt_nv_V4;
984
985      case Hexagon::JMP_GTUriPnt_nv_V4:
986       return Hexagon::JMP_GTUriNotPnt_nv_V4;
987     case Hexagon::JMP_GTUriNotPnt_nv_V4:
988       return Hexagon::JMP_GTUriPnt_nv_V4;
989
990    // JMPGTU_rr.
991      case Hexagon::JMP_GTUrrPt_nv_V4:
992       return Hexagon::JMP_GTUrrNotPt_nv_V4;
993     case Hexagon::JMP_GTUrrNotPt_nv_V4:
994       return Hexagon::JMP_GTUrrPt_nv_V4;
995
996      case Hexagon::JMP_GTUrrPnt_nv_V4:
997       return Hexagon::JMP_GTUrrNotPnt_nv_V4;
998     case Hexagon::JMP_GTUrrNotPnt_nv_V4:
999       return Hexagon::JMP_GTUrrPnt_nv_V4;
1000
1001    // JMPGTU_rrdn.
1002      case Hexagon::JMP_GTUrrdnPt_nv_V4:
1003       return Hexagon::JMP_GTUrrdnNotPt_nv_V4;
1004     case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
1005       return Hexagon::JMP_GTUrrdnPt_nv_V4;
1006
1007      case Hexagon::JMP_GTUrrdnPnt_nv_V4:
1008       return Hexagon::JMP_GTUrrdnNotPnt_nv_V4;
1009     case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
1010       return Hexagon::JMP_GTUrrdnPnt_nv_V4;
1011
1012   default:
1013     llvm_unreachable("Unexpected predicated instruction");
1014   }
1015 }
1016
1017
1018 int HexagonInstrInfo::
1019 getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const {
1020   switch(Opc) {
1021   case Hexagon::TFR:
1022     return !invertPredicate ? Hexagon::TFR_cPt :
1023                               Hexagon::TFR_cNotPt;
1024   case Hexagon::TFRI:
1025     return !invertPredicate ? Hexagon::TFRI_cPt :
1026                               Hexagon::TFRI_cNotPt;
1027   case Hexagon::JMP:
1028     return !invertPredicate ? Hexagon::JMP_c :
1029                               Hexagon::JMP_cNot;
1030   case Hexagon::ADD_ri:
1031     return !invertPredicate ? Hexagon::ADD_ri_cPt :
1032                               Hexagon::ADD_ri_cNotPt;
1033   case Hexagon::ADD_rr:
1034     return !invertPredicate ? Hexagon::ADD_rr_cPt :
1035                               Hexagon::ADD_rr_cNotPt;
1036   case Hexagon::XOR_rr:
1037     return !invertPredicate ? Hexagon::XOR_rr_cPt :
1038                               Hexagon::XOR_rr_cNotPt;
1039   case Hexagon::AND_rr:
1040     return !invertPredicate ? Hexagon::AND_rr_cPt :
1041                               Hexagon::AND_rr_cNotPt;
1042   case Hexagon::OR_rr:
1043     return !invertPredicate ? Hexagon::OR_rr_cPt :
1044                               Hexagon::OR_rr_cNotPt;
1045   case Hexagon::SUB_rr:
1046     return !invertPredicate ? Hexagon::SUB_rr_cPt :
1047                               Hexagon::SUB_rr_cNotPt;
1048   case Hexagon::COMBINE_rr:
1049     return !invertPredicate ? Hexagon::COMBINE_rr_cPt :
1050                               Hexagon::COMBINE_rr_cNotPt;
1051   case Hexagon::ASLH:
1052     return !invertPredicate ? Hexagon::ASLH_cPt_V4 :
1053                               Hexagon::ASLH_cNotPt_V4;
1054   case Hexagon::ASRH:
1055     return !invertPredicate ? Hexagon::ASRH_cPt_V4 :
1056                               Hexagon::ASRH_cNotPt_V4;
1057   case Hexagon::SXTB:
1058     return !invertPredicate ? Hexagon::SXTB_cPt_V4 :
1059                               Hexagon::SXTB_cNotPt_V4;
1060   case Hexagon::SXTH:
1061     return !invertPredicate ? Hexagon::SXTH_cPt_V4 :
1062                               Hexagon::SXTH_cNotPt_V4;
1063   case Hexagon::ZXTB:
1064     return !invertPredicate ? Hexagon::ZXTB_cPt_V4 :
1065                               Hexagon::ZXTB_cNotPt_V4;
1066   case Hexagon::ZXTH:
1067     return !invertPredicate ? Hexagon::ZXTH_cPt_V4 :
1068                               Hexagon::ZXTH_cNotPt_V4;
1069
1070   case Hexagon::JMPR:
1071     return !invertPredicate ? Hexagon::JMPR_cPt :
1072                               Hexagon::JMPR_cNotPt;
1073
1074   // V4 indexed+scaled load.
1075   case Hexagon::LDrid_indexed_V4:
1076     return !invertPredicate ? Hexagon::LDrid_indexed_cPt_V4 :
1077                               Hexagon::LDrid_indexed_cNotPt_V4;
1078   case Hexagon::LDrid_indexed_shl_V4:
1079     return !invertPredicate ? Hexagon::LDrid_indexed_shl_cPt_V4 :
1080                               Hexagon::LDrid_indexed_shl_cNotPt_V4;
1081   case Hexagon::LDrib_indexed_V4:
1082     return !invertPredicate ? Hexagon::LDrib_indexed_cPt_V4 :
1083                               Hexagon::LDrib_indexed_cNotPt_V4;
1084   case Hexagon::LDriub_indexed_V4:
1085     return !invertPredicate ? Hexagon::LDriub_indexed_cPt_V4 :
1086                               Hexagon::LDriub_indexed_cNotPt_V4;
1087   case Hexagon::LDriub_ae_indexed_V4:
1088     return !invertPredicate ? Hexagon::LDriub_indexed_cPt_V4 :
1089                               Hexagon::LDriub_indexed_cNotPt_V4;
1090   case Hexagon::LDrib_indexed_shl_V4:
1091     return !invertPredicate ? Hexagon::LDrib_indexed_shl_cPt_V4 :
1092                               Hexagon::LDrib_indexed_shl_cNotPt_V4;
1093   case Hexagon::LDriub_indexed_shl_V4:
1094     return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
1095                               Hexagon::LDriub_indexed_shl_cNotPt_V4;
1096   case Hexagon::LDriub_ae_indexed_shl_V4:
1097     return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
1098                               Hexagon::LDriub_indexed_shl_cNotPt_V4;
1099   case Hexagon::LDrih_indexed_V4:
1100     return !invertPredicate ? Hexagon::LDrih_indexed_cPt_V4 :
1101                               Hexagon::LDrih_indexed_cNotPt_V4;
1102   case Hexagon::LDriuh_indexed_V4:
1103     return !invertPredicate ? Hexagon::LDriuh_indexed_cPt_V4 :
1104                               Hexagon::LDriuh_indexed_cNotPt_V4;
1105   case Hexagon::LDriuh_ae_indexed_V4:
1106     return !invertPredicate ? Hexagon::LDriuh_indexed_cPt_V4 :
1107                               Hexagon::LDriuh_indexed_cNotPt_V4;
1108   case Hexagon::LDrih_indexed_shl_V4:
1109     return !invertPredicate ? Hexagon::LDrih_indexed_shl_cPt_V4 :
1110                               Hexagon::LDrih_indexed_shl_cNotPt_V4;
1111   case Hexagon::LDriuh_indexed_shl_V4:
1112     return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
1113                               Hexagon::LDriuh_indexed_shl_cNotPt_V4;
1114   case Hexagon::LDriuh_ae_indexed_shl_V4:
1115     return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
1116                               Hexagon::LDriuh_indexed_shl_cNotPt_V4;
1117   case Hexagon::LDriw_indexed_V4:
1118     return !invertPredicate ? Hexagon::LDriw_indexed_cPt_V4 :
1119                               Hexagon::LDriw_indexed_cNotPt_V4;
1120   case Hexagon::LDriw_indexed_shl_V4:
1121     return !invertPredicate ? Hexagon::LDriw_indexed_shl_cPt_V4 :
1122                               Hexagon::LDriw_indexed_shl_cNotPt_V4;
1123     // Byte.
1124   case Hexagon::POST_STbri:
1125     return !invertPredicate ? Hexagon::POST_STbri_cPt :
1126                               Hexagon::POST_STbri_cNotPt;
1127   case Hexagon::STrib:
1128     return !invertPredicate ? Hexagon::STrib_cPt :
1129                               Hexagon::STrib_cNotPt;
1130   case Hexagon::STrib_indexed:
1131     return !invertPredicate ? Hexagon::STrib_indexed_cPt :
1132                               Hexagon::STrib_indexed_cNotPt;
1133   case Hexagon::STrib_imm_V4:
1134     return !invertPredicate ? Hexagon::STrib_imm_cPt_V4 :
1135                               Hexagon::STrib_imm_cNotPt_V4;
1136   case Hexagon::STrib_indexed_shl_V4:
1137     return !invertPredicate ? Hexagon::STrib_indexed_shl_cPt_V4 :
1138                               Hexagon::STrib_indexed_shl_cNotPt_V4;
1139   // Halfword.
1140   case Hexagon::POST_SThri:
1141     return !invertPredicate ? Hexagon::POST_SThri_cPt :
1142                               Hexagon::POST_SThri_cNotPt;
1143   case Hexagon::STrih:
1144     return !invertPredicate ? Hexagon::STrih_cPt :
1145                               Hexagon::STrih_cNotPt;
1146   case Hexagon::STrih_indexed:
1147     return !invertPredicate ? Hexagon::STrih_indexed_cPt :
1148                               Hexagon::STrih_indexed_cNotPt;
1149   case Hexagon::STrih_imm_V4:
1150     return !invertPredicate ? Hexagon::STrih_imm_cPt_V4 :
1151                               Hexagon::STrih_imm_cNotPt_V4;
1152   case Hexagon::STrih_indexed_shl_V4:
1153     return !invertPredicate ? Hexagon::STrih_indexed_shl_cPt_V4 :
1154                               Hexagon::STrih_indexed_shl_cNotPt_V4;
1155   // Word.
1156   case Hexagon::POST_STwri:
1157     return !invertPredicate ? Hexagon::POST_STwri_cPt :
1158                               Hexagon::POST_STwri_cNotPt;
1159   case Hexagon::STriw:
1160     return !invertPredicate ? Hexagon::STriw_cPt :
1161                               Hexagon::STriw_cNotPt;
1162   case Hexagon::STriw_indexed:
1163     return !invertPredicate ? Hexagon::STriw_indexed_cPt :
1164                               Hexagon::STriw_indexed_cNotPt;
1165   case Hexagon::STriw_indexed_shl_V4:
1166     return !invertPredicate ? Hexagon::STriw_indexed_shl_cPt_V4 :
1167                               Hexagon::STriw_indexed_shl_cNotPt_V4;
1168   case Hexagon::STriw_imm_V4:
1169     return !invertPredicate ? Hexagon::STriw_imm_cPt_V4 :
1170                               Hexagon::STriw_imm_cNotPt_V4;
1171   // Double word.
1172   case Hexagon::POST_STdri:
1173     return !invertPredicate ? Hexagon::POST_STdri_cPt :
1174                               Hexagon::POST_STdri_cNotPt;
1175   case Hexagon::STrid:
1176     return !invertPredicate ? Hexagon::STrid_cPt :
1177                               Hexagon::STrid_cNotPt;
1178   case Hexagon::STrid_indexed:
1179     return !invertPredicate ? Hexagon::STrid_indexed_cPt :
1180                               Hexagon::STrid_indexed_cNotPt;
1181   case Hexagon::STrid_indexed_shl_V4:
1182     return !invertPredicate ? Hexagon::STrid_indexed_shl_cPt_V4 :
1183                               Hexagon::STrid_indexed_shl_cNotPt_V4;
1184   // Load.
1185   case Hexagon::LDrid:
1186     return !invertPredicate ? Hexagon::LDrid_cPt :
1187                               Hexagon::LDrid_cNotPt;
1188   case Hexagon::LDriw:
1189     return !invertPredicate ? Hexagon::LDriw_cPt :
1190                               Hexagon::LDriw_cNotPt;
1191   case Hexagon::LDrih:
1192     return !invertPredicate ? Hexagon::LDrih_cPt :
1193                               Hexagon::LDrih_cNotPt;
1194   case Hexagon::LDriuh:
1195     return !invertPredicate ? Hexagon::LDriuh_cPt :
1196                               Hexagon::LDriuh_cNotPt;
1197   case Hexagon::LDrib:
1198     return !invertPredicate ? Hexagon::LDrib_cPt :
1199                               Hexagon::LDrib_cNotPt;
1200   case Hexagon::LDriub:
1201     return !invertPredicate ? Hexagon::LDriub_cPt :
1202                               Hexagon::LDriub_cNotPt;
1203   case Hexagon::LDriubit:
1204     return !invertPredicate ? Hexagon::LDriub_cPt :
1205                               Hexagon::LDriub_cNotPt;
1206  // Load Indexed.
1207   case Hexagon::LDrid_indexed:
1208     return !invertPredicate ? Hexagon::LDrid_indexed_cPt :
1209                               Hexagon::LDrid_indexed_cNotPt;
1210   case Hexagon::LDriw_indexed:
1211     return !invertPredicate ? Hexagon::LDriw_indexed_cPt :
1212                               Hexagon::LDriw_indexed_cNotPt;
1213   case Hexagon::LDrih_indexed:
1214     return !invertPredicate ? Hexagon::LDrih_indexed_cPt :
1215                               Hexagon::LDrih_indexed_cNotPt;
1216   case Hexagon::LDriuh_indexed:
1217     return !invertPredicate ? Hexagon::LDriuh_indexed_cPt :
1218                               Hexagon::LDriuh_indexed_cNotPt;
1219   case Hexagon::LDrib_indexed:
1220     return !invertPredicate ? Hexagon::LDrib_indexed_cPt :
1221                               Hexagon::LDrib_indexed_cNotPt;
1222   case Hexagon::LDriub_indexed:
1223     return !invertPredicate ? Hexagon::LDriub_indexed_cPt :
1224                               Hexagon::LDriub_indexed_cNotPt;
1225   // Post Increment Load.
1226   case Hexagon::POST_LDrid:
1227     return !invertPredicate ? Hexagon::POST_LDrid_cPt :
1228                               Hexagon::POST_LDrid_cNotPt;
1229   case Hexagon::POST_LDriw:
1230     return !invertPredicate ? Hexagon::POST_LDriw_cPt :
1231                               Hexagon::POST_LDriw_cNotPt;
1232   case Hexagon::POST_LDrih:
1233     return !invertPredicate ? Hexagon::POST_LDrih_cPt :
1234                               Hexagon::POST_LDrih_cNotPt;
1235   case Hexagon::POST_LDriuh:
1236     return !invertPredicate ? Hexagon::POST_LDriuh_cPt :
1237                               Hexagon::POST_LDriuh_cNotPt;
1238   case Hexagon::POST_LDrib:
1239     return !invertPredicate ? Hexagon::POST_LDrib_cPt :
1240                               Hexagon::POST_LDrib_cNotPt;
1241   case Hexagon::POST_LDriub:
1242     return !invertPredicate ? Hexagon::POST_LDriub_cPt :
1243                               Hexagon::POST_LDriub_cNotPt;
1244   // DEALLOC_RETURN.
1245   case Hexagon::DEALLOC_RET_V4:
1246     return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 :
1247                               Hexagon::DEALLOC_RET_cNotPt_V4;
1248   }
1249   llvm_unreachable("Unexpected predicable instruction");
1250 }
1251
1252
1253 bool HexagonInstrInfo::
1254 PredicateInstruction(MachineInstr *MI,
1255                      const SmallVectorImpl<MachineOperand> &Cond) const {
1256   int Opc = MI->getOpcode();
1257   assert (isPredicable(MI) && "Expected predicable instruction");
1258   bool invertJump = (!Cond.empty() && Cond[0].isImm() &&
1259                      (Cond[0].getImm() == 0));
1260   MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump)));
1261   //
1262   // This assumes that the predicate is always the first operand
1263   // in the set of inputs.
1264   //
1265   MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1266   int oper;
1267   for (oper = MI->getNumOperands() - 3; oper >= 0; --oper) {
1268     MachineOperand MO = MI->getOperand(oper);
1269     if ((MO.isReg() && !MO.isUse() && !MO.isImplicit())) {
1270       break;
1271     }
1272
1273     if (MO.isReg()) {
1274       MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(),
1275                                               MO.isImplicit(), MO.isKill(),
1276                                               MO.isDead(), MO.isUndef(),
1277                                               MO.isDebug());
1278     } else if (MO.isImm()) {
1279       MI->getOperand(oper+1).ChangeToImmediate(MO.getImm());
1280     } else {
1281       llvm_unreachable("Unexpected operand type");
1282     }
1283   }
1284
1285   int regPos = invertJump ? 1 : 0;
1286   MachineOperand PredMO = Cond[regPos];
1287   MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(),
1288                                           PredMO.isImplicit(), PredMO.isKill(),
1289                                           PredMO.isDead(), PredMO.isUndef(),
1290                                           PredMO.isDebug());
1291
1292   return true;
1293 }
1294
1295
1296 bool
1297 HexagonInstrInfo::
1298 isProfitableToIfCvt(MachineBasicBlock &MBB,
1299                     unsigned NumCyles,
1300                     unsigned ExtraPredCycles,
1301                     const BranchProbability &Probability) const {
1302   return true;
1303 }
1304
1305
1306 bool
1307 HexagonInstrInfo::
1308 isProfitableToIfCvt(MachineBasicBlock &TMBB,
1309                     unsigned NumTCycles,
1310                     unsigned ExtraTCycles,
1311                     MachineBasicBlock &FMBB,
1312                     unsigned NumFCycles,
1313                     unsigned ExtraFCycles,
1314                     const BranchProbability &Probability) const {
1315   return true;
1316 }
1317
1318
1319 bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
1320   const uint64_t F = MI->getDesc().TSFlags;
1321
1322   return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
1323 }
1324
1325
1326 bool
1327 HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
1328                                    std::vector<MachineOperand> &Pred) const {
1329   for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
1330     MachineOperand MO = MI->getOperand(oper);
1331     if (MO.isReg() && MO.isDef()) {
1332       const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg());
1333       if (RC == &Hexagon::PredRegsRegClass) {
1334         Pred.push_back(MO);
1335         return true;
1336       }
1337     }
1338   }
1339   return false;
1340 }
1341
1342
1343 bool
1344 HexagonInstrInfo::
1345 SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
1346                   const SmallVectorImpl<MachineOperand> &Pred2) const {
1347   // TODO: Fix this
1348   return false;
1349 }
1350
1351
1352 //
1353 // We indicate that we want to reverse the branch by
1354 // inserting a 0 at the beginning of the Cond vector.
1355 //
1356 bool HexagonInstrInfo::
1357 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
1358   if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
1359     Cond.erase(Cond.begin());
1360   } else {
1361     Cond.insert(Cond.begin(), MachineOperand::CreateImm(0));
1362   }
1363   return false;
1364 }
1365
1366
1367 bool HexagonInstrInfo::
1368 isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs,
1369                           const BranchProbability &Probability) const {
1370   return (NumInstrs <= 4);
1371 }
1372
1373 bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const {
1374   switch (MI->getOpcode()) {
1375   case Hexagon::DEALLOC_RET_V4 :
1376   case Hexagon::DEALLOC_RET_cPt_V4 :
1377   case Hexagon::DEALLOC_RET_cNotPt_V4 :
1378   case Hexagon::DEALLOC_RET_cdnPnt_V4 :
1379   case Hexagon::DEALLOC_RET_cNotdnPnt_V4 :
1380   case Hexagon::DEALLOC_RET_cdnPt_V4 :
1381   case Hexagon::DEALLOC_RET_cNotdnPt_V4 :
1382    return true;
1383   }
1384   return false;
1385 }
1386
1387
1388 bool HexagonInstrInfo::
1389 isValidOffset(const int Opcode, const int Offset) const {
1390   // This function is to check whether the "Offset" is in the correct range of
1391   // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is
1392   // inserted to calculate the final address. Due to this reason, the function
1393   // assumes that the "Offset" has correct alignment.
1394
1395   switch(Opcode) {
1396
1397   case Hexagon::LDriw:
1398   case Hexagon::STriw:
1399     assert((Offset % 4 == 0) && "Offset has incorrect alignment");
1400     return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
1401       (Offset <= Hexagon_MEMW_OFFSET_MAX);
1402
1403   case Hexagon::LDrid:
1404   case Hexagon::STrid:
1405     assert((Offset % 8 == 0) && "Offset has incorrect alignment");
1406     return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
1407       (Offset <= Hexagon_MEMD_OFFSET_MAX);
1408
1409   case Hexagon::LDrih:
1410   case Hexagon::LDriuh:
1411   case Hexagon::STrih:
1412   case Hexagon::LDrih_ae:
1413     assert((Offset % 2 == 0) && "Offset has incorrect alignment");
1414     return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
1415       (Offset <= Hexagon_MEMH_OFFSET_MAX);
1416
1417   case Hexagon::LDrib:
1418   case Hexagon::STrib:
1419   case Hexagon::LDriub:
1420   case Hexagon::LDriubit:
1421   case Hexagon::LDrib_ae:
1422   case Hexagon::LDriub_ae:
1423     return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
1424       (Offset <= Hexagon_MEMB_OFFSET_MAX);
1425
1426   case Hexagon::ADD_ri:
1427   case Hexagon::TFR_FI:
1428     return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
1429       (Offset <= Hexagon_ADDI_OFFSET_MAX);
1430
1431   case Hexagon::MEMw_ADDSUBi_indexed_MEM_V4 :
1432   case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
1433   case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
1434   case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
1435   case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
1436   case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
1437   case Hexagon::MEMw_ORr_indexed_MEM_V4 :
1438   case Hexagon::MEMw_ADDSUBi_MEM_V4 :
1439   case Hexagon::MEMw_ADDi_MEM_V4 :
1440   case Hexagon::MEMw_SUBi_MEM_V4 :
1441   case Hexagon::MEMw_ADDr_MEM_V4 :
1442   case Hexagon::MEMw_SUBr_MEM_V4 :
1443   case Hexagon::MEMw_ANDr_MEM_V4 :
1444   case Hexagon::MEMw_ORr_MEM_V4 :
1445     assert ((Offset % 4) == 0 && "MEMOPw offset is not aligned correctly." );
1446     return (0 <= Offset && Offset <= 255);
1447
1448   case Hexagon::MEMh_ADDSUBi_indexed_MEM_V4 :
1449   case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
1450   case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
1451   case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
1452   case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
1453   case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
1454   case Hexagon::MEMh_ORr_indexed_MEM_V4 :
1455   case Hexagon::MEMh_ADDSUBi_MEM_V4 :
1456   case Hexagon::MEMh_ADDi_MEM_V4 :
1457   case Hexagon::MEMh_SUBi_MEM_V4 :
1458   case Hexagon::MEMh_ADDr_MEM_V4 :
1459   case Hexagon::MEMh_SUBr_MEM_V4 :
1460   case Hexagon::MEMh_ANDr_MEM_V4 :
1461   case Hexagon::MEMh_ORr_MEM_V4 :
1462     assert ((Offset % 2) == 0 && "MEMOPh offset is not aligned correctly." );
1463     return (0 <= Offset && Offset <= 127);
1464
1465   case Hexagon::MEMb_ADDSUBi_indexed_MEM_V4 :
1466   case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
1467   case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
1468   case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
1469   case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
1470   case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
1471   case Hexagon::MEMb_ORr_indexed_MEM_V4 :
1472   case Hexagon::MEMb_ADDSUBi_MEM_V4 :
1473   case Hexagon::MEMb_ADDi_MEM_V4 :
1474   case Hexagon::MEMb_SUBi_MEM_V4 :
1475   case Hexagon::MEMb_ADDr_MEM_V4 :
1476   case Hexagon::MEMb_SUBr_MEM_V4 :
1477   case Hexagon::MEMb_ANDr_MEM_V4 :
1478   case Hexagon::MEMb_ORr_MEM_V4 :
1479     return (0 <= Offset && Offset <= 63);
1480
1481   // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of
1482   // any size. Later pass knows how to handle it.
1483   case Hexagon::STriw_pred:
1484   case Hexagon::LDriw_pred:
1485     return true;
1486
1487   // INLINEASM is very special.
1488   case Hexagon::INLINEASM:
1489     return true;
1490   }
1491
1492   llvm_unreachable("No offset range is defined for this opcode. "
1493                    "Please define it in the above switch statement!");
1494 }
1495
1496
1497 //
1498 // Check if the Offset is a valid auto-inc imm by Load/Store Type.
1499 //
1500 bool HexagonInstrInfo::
1501 isValidAutoIncImm(const EVT VT, const int Offset) const {
1502
1503   if (VT == MVT::i64) {
1504       return (Offset >= Hexagon_MEMD_AUTOINC_MIN &&
1505               Offset <= Hexagon_MEMD_AUTOINC_MAX &&
1506               (Offset & 0x7) == 0);
1507   }
1508   if (VT == MVT::i32) {
1509       return (Offset >= Hexagon_MEMW_AUTOINC_MIN &&
1510               Offset <= Hexagon_MEMW_AUTOINC_MAX &&
1511               (Offset & 0x3) == 0);
1512   }
1513   if (VT == MVT::i16) {
1514       return (Offset >= Hexagon_MEMH_AUTOINC_MIN &&
1515               Offset <= Hexagon_MEMH_AUTOINC_MAX &&
1516               (Offset & 0x1) == 0);
1517   }
1518   if (VT == MVT::i8) {
1519       return (Offset >= Hexagon_MEMB_AUTOINC_MIN &&
1520               Offset <= Hexagon_MEMB_AUTOINC_MAX);
1521   }
1522   llvm_unreachable("Not an auto-inc opc!");
1523 }
1524
1525
1526 bool HexagonInstrInfo::
1527 isMemOp(const MachineInstr *MI) const {
1528   switch (MI->getOpcode())
1529   {
1530     case Hexagon::MEMw_ADDSUBi_indexed_MEM_V4 :
1531     case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
1532     case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
1533     case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
1534     case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
1535     case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
1536     case Hexagon::MEMw_ORr_indexed_MEM_V4 :
1537     case Hexagon::MEMw_ADDSUBi_MEM_V4 :
1538     case Hexagon::MEMw_ADDi_MEM_V4 :
1539     case Hexagon::MEMw_SUBi_MEM_V4 :
1540     case Hexagon::MEMw_ADDr_MEM_V4 :
1541     case Hexagon::MEMw_SUBr_MEM_V4 :
1542     case Hexagon::MEMw_ANDr_MEM_V4 :
1543     case Hexagon::MEMw_ORr_MEM_V4 :
1544     case Hexagon::MEMh_ADDSUBi_indexed_MEM_V4 :
1545     case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
1546     case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
1547     case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
1548     case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
1549     case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
1550     case Hexagon::MEMh_ORr_indexed_MEM_V4 :
1551     case Hexagon::MEMh_ADDSUBi_MEM_V4 :
1552     case Hexagon::MEMh_ADDi_MEM_V4 :
1553     case Hexagon::MEMh_SUBi_MEM_V4 :
1554     case Hexagon::MEMh_ADDr_MEM_V4 :
1555     case Hexagon::MEMh_SUBr_MEM_V4 :
1556     case Hexagon::MEMh_ANDr_MEM_V4 :
1557     case Hexagon::MEMh_ORr_MEM_V4 :
1558     case Hexagon::MEMb_ADDSUBi_indexed_MEM_V4 :
1559     case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
1560     case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
1561     case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
1562     case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
1563     case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
1564     case Hexagon::MEMb_ORr_indexed_MEM_V4 :
1565     case Hexagon::MEMb_ADDSUBi_MEM_V4 :
1566     case Hexagon::MEMb_ADDi_MEM_V4 :
1567     case Hexagon::MEMb_SUBi_MEM_V4 :
1568     case Hexagon::MEMb_ADDr_MEM_V4 :
1569     case Hexagon::MEMb_SUBr_MEM_V4 :
1570     case Hexagon::MEMb_ANDr_MEM_V4 :
1571     case Hexagon::MEMb_ORr_MEM_V4 :
1572     return true;
1573   }
1574   return false;
1575 }
1576
1577
1578 bool HexagonInstrInfo::
1579 isSpillPredRegOp(const MachineInstr *MI) const {
1580   switch (MI->getOpcode())
1581   {
1582     case Hexagon::STriw_pred :
1583     case Hexagon::LDriw_pred :
1584     return true;
1585   }
1586   return false;
1587 }
1588
1589
1590 bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const {
1591   const HexagonRegisterInfo& QRI = getRegisterInfo();
1592   switch (MI->getOpcode())
1593   {
1594     case Hexagon::ADD_ri_cPt:
1595     case Hexagon::ADD_ri_cNotPt:
1596     case Hexagon::ADD_rr_cPt:
1597     case Hexagon::ADD_rr_cNotPt:
1598     case Hexagon::XOR_rr_cPt:
1599     case Hexagon::XOR_rr_cNotPt:
1600     case Hexagon::AND_rr_cPt:
1601     case Hexagon::AND_rr_cNotPt:
1602     case Hexagon::OR_rr_cPt:
1603     case Hexagon::OR_rr_cNotPt:
1604     case Hexagon::SUB_rr_cPt:
1605     case Hexagon::SUB_rr_cNotPt:
1606     case Hexagon::COMBINE_rr_cPt:
1607     case Hexagon::COMBINE_rr_cNotPt:
1608       return true;
1609     case Hexagon::ASLH_cPt_V4:
1610     case Hexagon::ASLH_cNotPt_V4:
1611     case Hexagon::ASRH_cPt_V4:
1612     case Hexagon::ASRH_cNotPt_V4:
1613     case Hexagon::SXTB_cPt_V4:
1614     case Hexagon::SXTB_cNotPt_V4:
1615     case Hexagon::SXTH_cPt_V4:
1616     case Hexagon::SXTH_cNotPt_V4:
1617     case Hexagon::ZXTB_cPt_V4:
1618     case Hexagon::ZXTB_cNotPt_V4:
1619     case Hexagon::ZXTH_cPt_V4:
1620     case Hexagon::ZXTH_cNotPt_V4:
1621       return QRI.Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
1622
1623     default:
1624       return false;
1625   }
1626 }
1627
1628
1629 bool HexagonInstrInfo::
1630 isConditionalLoad (const MachineInstr* MI) const {
1631   const HexagonRegisterInfo& QRI = getRegisterInfo();
1632   switch (MI->getOpcode())
1633   {
1634     case Hexagon::LDrid_cPt :
1635     case Hexagon::LDrid_cNotPt :
1636     case Hexagon::LDrid_indexed_cPt :
1637     case Hexagon::LDrid_indexed_cNotPt :
1638     case Hexagon::LDriw_cPt :
1639     case Hexagon::LDriw_cNotPt :
1640     case Hexagon::LDriw_indexed_cPt :
1641     case Hexagon::LDriw_indexed_cNotPt :
1642     case Hexagon::LDrih_cPt :
1643     case Hexagon::LDrih_cNotPt :
1644     case Hexagon::LDrih_indexed_cPt :
1645     case Hexagon::LDrih_indexed_cNotPt :
1646     case Hexagon::LDrib_cPt :
1647     case Hexagon::LDrib_cNotPt :
1648     case Hexagon::LDrib_indexed_cPt :
1649     case Hexagon::LDrib_indexed_cNotPt :
1650     case Hexagon::LDriuh_cPt :
1651     case Hexagon::LDriuh_cNotPt :
1652     case Hexagon::LDriuh_indexed_cPt :
1653     case Hexagon::LDriuh_indexed_cNotPt :
1654     case Hexagon::LDriub_cPt :
1655     case Hexagon::LDriub_cNotPt :
1656     case Hexagon::LDriub_indexed_cPt :
1657     case Hexagon::LDriub_indexed_cNotPt :
1658       return true;
1659     case Hexagon::POST_LDrid_cPt :
1660     case Hexagon::POST_LDrid_cNotPt :
1661     case Hexagon::POST_LDriw_cPt :
1662     case Hexagon::POST_LDriw_cNotPt :
1663     case Hexagon::POST_LDrih_cPt :
1664     case Hexagon::POST_LDrih_cNotPt :
1665     case Hexagon::POST_LDrib_cPt :
1666     case Hexagon::POST_LDrib_cNotPt :
1667     case Hexagon::POST_LDriuh_cPt :
1668     case Hexagon::POST_LDriuh_cNotPt :
1669     case Hexagon::POST_LDriub_cPt :
1670     case Hexagon::POST_LDriub_cNotPt :
1671       return QRI.Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
1672     case Hexagon::LDrid_indexed_cPt_V4 :
1673     case Hexagon::LDrid_indexed_cNotPt_V4 :
1674     case Hexagon::LDrid_indexed_shl_cPt_V4 :
1675     case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
1676     case Hexagon::LDrib_indexed_cPt_V4 :
1677     case Hexagon::LDrib_indexed_cNotPt_V4 :
1678     case Hexagon::LDrib_indexed_shl_cPt_V4 :
1679     case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
1680     case Hexagon::LDriub_indexed_cPt_V4 :
1681     case Hexagon::LDriub_indexed_cNotPt_V4 :
1682     case Hexagon::LDriub_indexed_shl_cPt_V4 :
1683     case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
1684     case Hexagon::LDrih_indexed_cPt_V4 :
1685     case Hexagon::LDrih_indexed_cNotPt_V4 :
1686     case Hexagon::LDrih_indexed_shl_cPt_V4 :
1687     case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
1688     case Hexagon::LDriuh_indexed_cPt_V4 :
1689     case Hexagon::LDriuh_indexed_cNotPt_V4 :
1690     case Hexagon::LDriuh_indexed_shl_cPt_V4 :
1691     case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
1692     case Hexagon::LDriw_indexed_cPt_V4 :
1693     case Hexagon::LDriw_indexed_cNotPt_V4 :
1694     case Hexagon::LDriw_indexed_shl_cPt_V4 :
1695     case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
1696       return QRI.Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
1697     default:
1698       return false;
1699   }
1700 }
1701
1702 DFAPacketizer *HexagonInstrInfo::
1703 CreateTargetScheduleState(const TargetMachine *TM,
1704                            const ScheduleDAG *DAG) const {
1705   const InstrItineraryData *II = TM->getInstrItineraryData();
1706   return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II);
1707 }
1708
1709 bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
1710                                             const MachineBasicBlock *MBB,
1711                                             const MachineFunction &MF) const {
1712   // Debug info is never a scheduling boundary. It's necessary to be explicit
1713   // due to the special treatment of IT instructions below, otherwise a
1714   // dbg_value followed by an IT will result in the IT instruction being
1715   // considered a scheduling hazard, which is wrong. It should be the actual
1716   // instruction preceding the dbg_value instruction(s), just like it is
1717   // when debug info is not present.
1718   if (MI->isDebugValue())
1719     return false;
1720
1721   // Terminators and labels can't be scheduled around.
1722   if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm())
1723     return true;
1724
1725   return false;
1726 }