Replace LDriu*[bhdw]_indexed_V4 instructions with "def Pats".
[oota-llvm.git] / lib / Target / Hexagon / HexagonVLIWPacketizer.cpp
1 //===----- HexagonPacketizer.cpp - vliw packetizer ---------------------===//
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 implements a simple VLIW packetizer using DFA. The packetizer works on
11 // machine basic blocks. For each instruction I in BB, the packetizer consults
12 // the DFA to see if machine resources are available to execute I. If so, the
13 // packetizer checks if I depends on any instruction J in the current packet.
14 // If no dependency is found, I is added to current packet and machine resource
15 // is marked as taken. If any dependency is found, a target API call is made to
16 // prune the dependence.
17 //
18 //===----------------------------------------------------------------------===//
19 #define DEBUG_TYPE "packets"
20 #include "Hexagon.h"
21 #include "HexagonMachineFunctionInfo.h"
22 #include "HexagonRegisterInfo.h"
23 #include "HexagonSubtarget.h"
24 #include "HexagonTargetMachine.h"
25 #include "llvm/ADT/DenseMap.h"
26 #include "llvm/ADT/Statistic.h"
27 #include "llvm/CodeGen/DFAPacketizer.h"
28 #include "llvm/CodeGen/LatencyPriorityQueue.h"
29 #include "llvm/CodeGen/MachineDominators.h"
30 #include "llvm/CodeGen/MachineFrameInfo.h"
31 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
32 #include "llvm/CodeGen/MachineFunctionPass.h"
33 #include "llvm/CodeGen/MachineInstrBuilder.h"
34 #include "llvm/CodeGen/MachineLoopInfo.h"
35 #include "llvm/CodeGen/MachineRegisterInfo.h"
36 #include "llvm/CodeGen/Passes.h"
37 #include "llvm/CodeGen/ScheduleDAG.h"
38 #include "llvm/CodeGen/ScheduleDAGInstrs.h"
39 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
40 #include "llvm/CodeGen/SchedulerRegistry.h"
41 #include "llvm/MC/MCInstrItineraries.h"
42 #include "llvm/Support/CommandLine.h"
43 #include "llvm/Support/Compiler.h"
44 #include "llvm/Support/Debug.h"
45 #include "llvm/Support/MathExtras.h"
46 #include "llvm/Target/TargetInstrInfo.h"
47 #include "llvm/Target/TargetMachine.h"
48 #include "llvm/Target/TargetRegisterInfo.h"
49 #include <map>
50
51 using namespace llvm;
52
53 namespace {
54   class HexagonPacketizer : public MachineFunctionPass {
55
56   public:
57     static char ID;
58     HexagonPacketizer() : MachineFunctionPass(ID) {}
59
60     void getAnalysisUsage(AnalysisUsage &AU) const {
61       AU.setPreservesCFG();
62       AU.addRequired<MachineDominatorTree>();
63       AU.addPreserved<MachineDominatorTree>();
64       AU.addRequired<MachineLoopInfo>();
65       AU.addPreserved<MachineLoopInfo>();
66       MachineFunctionPass::getAnalysisUsage(AU);
67     }
68
69     const char *getPassName() const {
70       return "Hexagon Packetizer";
71     }
72
73     bool runOnMachineFunction(MachineFunction &Fn);
74   };
75   char HexagonPacketizer::ID = 0;
76
77   class HexagonPacketizerList : public VLIWPacketizerList {
78
79   private:
80
81     // Has the instruction been promoted to a dot-new instruction.
82     bool PromotedToDotNew;
83
84     // Has the instruction been glued to allocframe.
85     bool GlueAllocframeStore;
86
87     // Has the feeder instruction been glued to new value jump.
88     bool GlueToNewValueJump;
89
90     // Check if there is a dependence between some instruction already in this
91     // packet and this instruction.
92     bool Dependence;
93
94     // Only check for dependence if there are resources available to
95     // schedule this instruction.
96     bool FoundSequentialDependence;
97
98   public:
99     // Ctor.
100     HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
101                           MachineDominatorTree &MDT);
102
103     // initPacketizerState - initialize some internal flags.
104     void initPacketizerState();
105
106     // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
107     bool ignorePseudoInstruction(MachineInstr *MI, MachineBasicBlock *MBB);
108
109     // isSoloInstruction - return true if instruction MI can not be packetized
110     // with any other instruction, which means that MI itself is a packet.
111     bool isSoloInstruction(MachineInstr *MI);
112
113     // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
114     // together.
115     bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ);
116
117     // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
118     // and SUJ.
119     bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ);
120
121     MachineBasicBlock::iterator addToPacket(MachineInstr *MI);
122   private:
123     bool IsCallDependent(MachineInstr* MI, SDep::Kind DepType, unsigned DepReg);
124     bool PromoteToDotNew(MachineInstr* MI, SDep::Kind DepType,
125                     MachineBasicBlock::iterator &MII,
126                     const TargetRegisterClass* RC);
127     bool CanPromoteToDotNew(MachineInstr* MI, SUnit* PacketSU,
128                     unsigned DepReg,
129                     std::map <MachineInstr*, SUnit*> MIToSUnit,
130                     MachineBasicBlock::iterator &MII,
131                     const TargetRegisterClass* RC);
132     bool CanPromoteToNewValue(MachineInstr* MI, SUnit* PacketSU,
133                     unsigned DepReg,
134                     std::map <MachineInstr*, SUnit*> MIToSUnit,
135                     MachineBasicBlock::iterator &MII);
136     bool CanPromoteToNewValueStore(MachineInstr* MI, MachineInstr* PacketMI,
137                     unsigned DepReg,
138                     std::map <MachineInstr*, SUnit*> MIToSUnit);
139     bool DemoteToDotOld(MachineInstr* MI);
140     bool ArePredicatesComplements(MachineInstr* MI1, MachineInstr* MI2,
141                     std::map <MachineInstr*, SUnit*> MIToSUnit);
142     bool RestrictingDepExistInPacket(MachineInstr*,
143                     unsigned, std::map <MachineInstr*, SUnit*>);
144     bool isNewifiable(MachineInstr* MI);
145     bool isCondInst(MachineInstr* MI);
146     bool IsNewifyStore (MachineInstr* MI);
147     bool tryAllocateResourcesForConstExt(MachineInstr* MI);
148     bool canReserveResourcesForConstExt(MachineInstr *MI);
149     void reserveResourcesForConstExt(MachineInstr* MI);
150     bool isNewValueInst(MachineInstr* MI);
151     bool isDotNewInst(MachineInstr* MI);
152   };
153 }
154
155 // HexagonPacketizerList Ctor.
156 HexagonPacketizerList::HexagonPacketizerList(
157   MachineFunction &MF, MachineLoopInfo &MLI,MachineDominatorTree &MDT)
158   : VLIWPacketizerList(MF, MLI, MDT, true){
159 }
160
161 bool HexagonPacketizer::runOnMachineFunction(MachineFunction &Fn) {
162   const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
163   MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
164   MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
165
166   // Instantiate the packetizer.
167   HexagonPacketizerList Packetizer(Fn, MLI, MDT);
168
169   // DFA state table should not be empty.
170   assert(Packetizer.getResourceTracker() && "Empty DFA table!");
171
172   //
173   // Loop over all basic blocks and remove KILL pseudo-instructions
174   // These instructions confuse the dependence analysis. Consider:
175   // D0 = ...   (Insn 0)
176   // R0 = KILL R0, D0 (Insn 1)
177   // R0 = ... (Insn 2)
178   // Here, Insn 1 will result in the dependence graph not emitting an output
179   // dependence between Insn 0 and Insn 2. This can lead to incorrect
180   // packetization
181   //
182   for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
183        MBB != MBBe; ++MBB) {
184     MachineBasicBlock::iterator End = MBB->end();
185     MachineBasicBlock::iterator MI = MBB->begin();
186     while (MI != End) {
187       if (MI->isKill()) {
188         MachineBasicBlock::iterator DeleteMI = MI;
189         ++MI;
190         MBB->erase(DeleteMI);
191         End = MBB->end();
192         continue;
193       }
194       ++MI;
195     }
196   }
197
198   // Loop over all of the basic blocks.
199   for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
200        MBB != MBBe; ++MBB) {
201     // Find scheduling regions and schedule / packetize each region.
202     unsigned RemainingCount = MBB->size();
203     for(MachineBasicBlock::iterator RegionEnd = MBB->end();
204         RegionEnd != MBB->begin();) {
205       // The next region starts above the previous region. Look backward in the
206       // instruction stream until we find the nearest boundary.
207       MachineBasicBlock::iterator I = RegionEnd;
208       for(;I != MBB->begin(); --I, --RemainingCount) {
209         if (TII->isSchedulingBoundary(llvm::prior(I), MBB, Fn))
210           break;
211       }
212       I = MBB->begin();
213
214       // Skip empty scheduling regions.
215       if (I == RegionEnd) {
216         RegionEnd = llvm::prior(RegionEnd);
217         --RemainingCount;
218         continue;
219       }
220       // Skip regions with one instruction.
221       if (I == llvm::prior(RegionEnd)) {
222         RegionEnd = llvm::prior(RegionEnd);
223         continue;
224       }
225
226       Packetizer.PacketizeMIs(MBB, I, RegionEnd);
227       RegionEnd = I;
228     }
229   }
230
231   return true;
232 }
233
234
235 static bool IsIndirectCall(MachineInstr* MI) {
236   return ((MI->getOpcode() == Hexagon::CALLR) ||
237           (MI->getOpcode() == Hexagon::CALLRv3));
238 }
239
240 // Reserve resources for constant extender. Trigure an assertion if
241 // reservation fail.
242 void HexagonPacketizerList::reserveResourcesForConstExt(MachineInstr* MI) {
243   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
244   MachineFunction *MF = MI->getParent()->getParent();
245   MachineInstr *PseudoMI = MF->CreateMachineInstr(QII->get(Hexagon::IMMEXT_i),
246                                                   MI->getDebugLoc());
247
248   if (ResourceTracker->canReserveResources(PseudoMI)) {
249     ResourceTracker->reserveResources(PseudoMI);
250     MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
251   } else {
252     MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
253     llvm_unreachable("can not reserve resources for constant extender.");
254   }
255   return;
256 }
257
258 bool HexagonPacketizerList::canReserveResourcesForConstExt(MachineInstr *MI) {
259   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
260   assert(QII->isExtended(MI) &&
261          "Should only be called for constant extended instructions");
262   MachineFunction *MF = MI->getParent()->getParent();
263   MachineInstr *PseudoMI = MF->CreateMachineInstr(QII->get(Hexagon::IMMEXT_i),
264                                                   MI->getDebugLoc());
265   bool CanReserve = ResourceTracker->canReserveResources(PseudoMI);
266   MF->DeleteMachineInstr(PseudoMI);
267   return CanReserve;
268 }
269
270 // Allocate resources (i.e. 4 bytes) for constant extender. If succeed, return
271 // true, otherwise, return false.
272 bool HexagonPacketizerList::tryAllocateResourcesForConstExt(MachineInstr* MI) {
273   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
274   MachineFunction *MF = MI->getParent()->getParent();
275   MachineInstr *PseudoMI = MF->CreateMachineInstr(QII->get(Hexagon::IMMEXT_i),
276                                                   MI->getDebugLoc());
277
278   if (ResourceTracker->canReserveResources(PseudoMI)) {
279     ResourceTracker->reserveResources(PseudoMI);
280     MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
281     return true;
282   } else {
283     MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
284     return false;
285   }
286 }
287
288
289 bool HexagonPacketizerList::IsCallDependent(MachineInstr* MI,
290                                           SDep::Kind DepType,
291                                           unsigned DepReg) {
292
293   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
294   const HexagonRegisterInfo* QRI =
295               (const HexagonRegisterInfo *) TM.getRegisterInfo();
296
297   // Check for lr dependence
298   if (DepReg == QRI->getRARegister()) {
299     return true;
300   }
301
302   if (QII->isDeallocRet(MI)) {
303     if (DepReg == QRI->getFrameRegister() ||
304         DepReg == QRI->getStackRegister())
305       return true;
306   }
307
308   // Check if this is a predicate dependence
309   const TargetRegisterClass* RC = QRI->getMinimalPhysRegClass(DepReg);
310   if (RC == &Hexagon::PredRegsRegClass) {
311     return true;
312   }
313
314   //
315   // Lastly check for an operand used in an indirect call
316   // If we had an attribute for checking if an instruction is an indirect call,
317   // then we could have avoided this relatively brittle implementation of
318   // IsIndirectCall()
319   //
320   // Assumes that the first operand of the CALLr is the function address
321   //
322   if (IsIndirectCall(MI) && (DepType == SDep::Data)) {
323     MachineOperand MO = MI->getOperand(0);
324     if (MO.isReg() && MO.isUse() && (MO.getReg() == DepReg)) {
325       return true;
326     }
327   }
328
329   return false;
330 }
331
332 static bool IsRegDependence(const SDep::Kind DepType) {
333   return (DepType == SDep::Data || DepType == SDep::Anti ||
334           DepType == SDep::Output);
335 }
336
337 static bool IsDirectJump(MachineInstr* MI) {
338   return (MI->getOpcode() == Hexagon::JMP);
339 }
340
341 static bool IsSchedBarrier(MachineInstr* MI) {
342   switch (MI->getOpcode()) {
343   case Hexagon::BARRIER:
344     return true;
345   }
346   return false;
347 }
348
349 static bool IsControlFlow(MachineInstr* MI) {
350   return (MI->getDesc().isTerminator() || MI->getDesc().isCall());
351 }
352
353 bool HexagonPacketizerList::isNewValueInst(MachineInstr* MI) {
354   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
355   if (QII->isNewValueJump(MI))
356     return true;
357
358   if (QII->isNewValueStore(MI))
359     return true;
360
361   return false;
362 }
363
364 // Function returns true if an instruction can be promoted to the new-value
365 // store. It will always return false for v2 and v3.
366 // It lists all the conditional and unconditional stores that can be promoted
367 // to the new-value stores.
368
369 bool HexagonPacketizerList::IsNewifyStore (MachineInstr* MI) {
370   const HexagonRegisterInfo* QRI =
371                           (const HexagonRegisterInfo *) TM.getRegisterInfo();
372   switch (MI->getOpcode())
373   {
374     // store byte
375     case Hexagon::STrib:
376     case Hexagon::STrib_indexed:
377     case Hexagon::STrib_indexed_shl_V4:
378     case Hexagon::STrib_shl_V4:
379     case Hexagon::STrib_GP_V4:
380     case Hexagon::STb_GP_V4:
381     case Hexagon::POST_STbri:
382     case Hexagon::STrib_cPt:
383     case Hexagon::STrib_cdnPt_V4:
384     case Hexagon::STrib_cNotPt:
385     case Hexagon::STrib_cdnNotPt_V4:
386     case Hexagon::STrib_indexed_cPt:
387     case Hexagon::STrib_indexed_cdnPt_V4:
388     case Hexagon::STrib_indexed_cNotPt:
389     case Hexagon::STrib_indexed_cdnNotPt_V4:
390     case Hexagon::STrib_indexed_shl_cPt_V4:
391     case Hexagon::STrib_indexed_shl_cdnPt_V4:
392     case Hexagon::STrib_indexed_shl_cNotPt_V4:
393     case Hexagon::STrib_indexed_shl_cdnNotPt_V4:
394     case Hexagon::POST_STbri_cPt:
395     case Hexagon::POST_STbri_cdnPt_V4:
396     case Hexagon::POST_STbri_cNotPt:
397     case Hexagon::POST_STbri_cdnNotPt_V4:
398     case Hexagon::STb_GP_cPt_V4:
399     case Hexagon::STb_GP_cNotPt_V4:
400     case Hexagon::STb_GP_cdnPt_V4:
401     case Hexagon::STb_GP_cdnNotPt_V4:
402     case Hexagon::STrib_GP_cPt_V4:
403     case Hexagon::STrib_GP_cNotPt_V4:
404     case Hexagon::STrib_GP_cdnPt_V4:
405     case Hexagon::STrib_GP_cdnNotPt_V4:
406
407     // store halfword
408     case Hexagon::STrih:
409     case Hexagon::STrih_indexed:
410     case Hexagon::STrih_indexed_shl_V4:
411     case Hexagon::STrih_shl_V4:
412     case Hexagon::STrih_GP_V4:
413     case Hexagon::STh_GP_V4:
414     case Hexagon::POST_SThri:
415     case Hexagon::STrih_cPt:
416     case Hexagon::STrih_cdnPt_V4:
417     case Hexagon::STrih_cNotPt:
418     case Hexagon::STrih_cdnNotPt_V4:
419     case Hexagon::STrih_indexed_cPt:
420     case Hexagon::STrih_indexed_cdnPt_V4:
421     case Hexagon::STrih_indexed_cNotPt:
422     case Hexagon::STrih_indexed_cdnNotPt_V4:
423     case Hexagon::STrih_indexed_shl_cPt_V4:
424     case Hexagon::STrih_indexed_shl_cdnPt_V4:
425     case Hexagon::STrih_indexed_shl_cNotPt_V4:
426     case Hexagon::STrih_indexed_shl_cdnNotPt_V4:
427     case Hexagon::POST_SThri_cPt:
428     case Hexagon::POST_SThri_cdnPt_V4:
429     case Hexagon::POST_SThri_cNotPt:
430     case Hexagon::POST_SThri_cdnNotPt_V4:
431     case Hexagon::STh_GP_cPt_V4:
432     case Hexagon::STh_GP_cNotPt_V4:
433     case Hexagon::STh_GP_cdnPt_V4:
434     case Hexagon::STh_GP_cdnNotPt_V4:
435     case Hexagon::STrih_GP_cPt_V4:
436     case Hexagon::STrih_GP_cNotPt_V4:
437     case Hexagon::STrih_GP_cdnPt_V4:
438     case Hexagon::STrih_GP_cdnNotPt_V4:
439
440     // store word
441     case Hexagon::STriw:
442     case Hexagon::STriw_indexed:
443     case Hexagon::STriw_indexed_shl_V4:
444     case Hexagon::STriw_shl_V4:
445     case Hexagon::STriw_GP_V4:
446     case Hexagon::STw_GP_V4:
447     case Hexagon::POST_STwri:
448     case Hexagon::STriw_cPt:
449     case Hexagon::STriw_cdnPt_V4:
450     case Hexagon::STriw_cNotPt:
451     case Hexagon::STriw_cdnNotPt_V4:
452     case Hexagon::STriw_indexed_cPt:
453     case Hexagon::STriw_indexed_cdnPt_V4:
454     case Hexagon::STriw_indexed_cNotPt:
455     case Hexagon::STriw_indexed_cdnNotPt_V4:
456     case Hexagon::STriw_indexed_shl_cPt_V4:
457     case Hexagon::STriw_indexed_shl_cdnPt_V4:
458     case Hexagon::STriw_indexed_shl_cNotPt_V4:
459     case Hexagon::STriw_indexed_shl_cdnNotPt_V4:
460     case Hexagon::POST_STwri_cPt:
461     case Hexagon::POST_STwri_cdnPt_V4:
462     case Hexagon::POST_STwri_cNotPt:
463     case Hexagon::POST_STwri_cdnNotPt_V4:
464     case Hexagon::STw_GP_cPt_V4:
465     case Hexagon::STw_GP_cNotPt_V4:
466     case Hexagon::STw_GP_cdnPt_V4:
467     case Hexagon::STw_GP_cdnNotPt_V4:
468     case Hexagon::STriw_GP_cPt_V4:
469     case Hexagon::STriw_GP_cNotPt_V4:
470     case Hexagon::STriw_GP_cdnPt_V4:
471     case Hexagon::STriw_GP_cdnNotPt_V4:
472         return QRI->Subtarget.hasV4TOps();
473   }
474   return false;
475 }
476
477 static bool IsLoopN(MachineInstr *MI) {
478   return (MI->getOpcode() == Hexagon::LOOP0_i ||
479           MI->getOpcode() == Hexagon::LOOP0_r);
480 }
481
482 /// DoesModifyCalleeSavedReg - Returns true if the instruction modifies a
483 /// callee-saved register.
484 static bool DoesModifyCalleeSavedReg(MachineInstr *MI,
485                                      const TargetRegisterInfo *TRI) {
486   for (const uint16_t *CSR = TRI->getCalleeSavedRegs(); *CSR; ++CSR) {
487     unsigned CalleeSavedReg = *CSR;
488     if (MI->modifiesRegister(CalleeSavedReg, TRI))
489       return true;
490   }
491   return false;
492 }
493
494 // Return the new value instruction for a given store.
495 static int GetDotNewOp(const int opc) {
496   switch (opc) {
497   default: llvm_unreachable("Unknown .new type");
498   // store new value byte
499   case Hexagon::STrib:
500     return Hexagon::STrib_nv_V4;
501
502   case Hexagon::STrib_indexed:
503     return Hexagon::STrib_indexed_nv_V4;
504
505   case Hexagon::STrib_indexed_shl_V4:
506     return Hexagon::STrib_indexed_shl_nv_V4;
507
508   case Hexagon::STrib_shl_V4:
509     return Hexagon::STrib_shl_nv_V4;
510
511   case Hexagon::STrib_GP_V4:
512     return Hexagon::STrib_GP_nv_V4;
513
514   case Hexagon::STb_GP_V4:
515     return Hexagon::STb_GP_nv_V4;
516
517   case Hexagon::POST_STbri:
518     return Hexagon::POST_STbri_nv_V4;
519
520   case Hexagon::STrib_cPt:
521     return Hexagon::STrib_cPt_nv_V4;
522
523   case Hexagon::STrib_cdnPt_V4:
524     return Hexagon::STrib_cdnPt_nv_V4;
525
526   case Hexagon::STrib_cNotPt:
527     return Hexagon::STrib_cNotPt_nv_V4;
528
529   case Hexagon::STrib_cdnNotPt_V4:
530     return Hexagon::STrib_cdnNotPt_nv_V4;
531
532   case Hexagon::STrib_indexed_cPt:
533     return Hexagon::STrib_indexed_cPt_nv_V4;
534
535   case Hexagon::STrib_indexed_cdnPt_V4:
536     return Hexagon::STrib_indexed_cdnPt_nv_V4;
537
538   case Hexagon::STrib_indexed_cNotPt:
539     return Hexagon::STrib_indexed_cNotPt_nv_V4;
540
541   case Hexagon::STrib_indexed_cdnNotPt_V4:
542     return Hexagon::STrib_indexed_cdnNotPt_nv_V4;
543
544   case Hexagon::STrib_indexed_shl_cPt_V4:
545     return Hexagon::STrib_indexed_shl_cPt_nv_V4;
546
547   case Hexagon::STrib_indexed_shl_cdnPt_V4:
548     return Hexagon::STrib_indexed_shl_cdnPt_nv_V4;
549
550   case Hexagon::STrib_indexed_shl_cNotPt_V4:
551     return Hexagon::STrib_indexed_shl_cNotPt_nv_V4;
552
553   case Hexagon::STrib_indexed_shl_cdnNotPt_V4:
554     return Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4;
555
556   case Hexagon::POST_STbri_cPt:
557     return Hexagon::POST_STbri_cPt_nv_V4;
558
559   case Hexagon::POST_STbri_cdnPt_V4:
560     return Hexagon::POST_STbri_cdnPt_nv_V4;
561
562   case Hexagon::POST_STbri_cNotPt:
563     return Hexagon::POST_STbri_cNotPt_nv_V4;
564
565   case Hexagon::POST_STbri_cdnNotPt_V4:
566     return Hexagon::POST_STbri_cdnNotPt_nv_V4;
567
568   case Hexagon::STb_GP_cPt_V4:
569     return Hexagon::STb_GP_cPt_nv_V4;
570
571   case Hexagon::STb_GP_cNotPt_V4:
572     return Hexagon::STb_GP_cNotPt_nv_V4;
573
574   case Hexagon::STb_GP_cdnPt_V4:
575     return Hexagon::STb_GP_cdnPt_nv_V4;
576
577   case Hexagon::STb_GP_cdnNotPt_V4:
578     return Hexagon::STb_GP_cdnNotPt_nv_V4;
579
580   case Hexagon::STrib_GP_cPt_V4:
581     return Hexagon::STrib_GP_cPt_nv_V4;
582
583   case Hexagon::STrib_GP_cNotPt_V4:
584     return Hexagon::STrib_GP_cNotPt_nv_V4;
585
586   case Hexagon::STrib_GP_cdnPt_V4:
587     return Hexagon::STrib_GP_cdnPt_nv_V4;
588
589   case Hexagon::STrib_GP_cdnNotPt_V4:
590     return Hexagon::STrib_GP_cdnNotPt_nv_V4;
591
592   // store new value halfword
593   case Hexagon::STrih:
594     return Hexagon::STrih_nv_V4;
595
596   case Hexagon::STrih_indexed:
597     return Hexagon::STrih_indexed_nv_V4;
598
599   case Hexagon::STrih_indexed_shl_V4:
600     return Hexagon::STrih_indexed_shl_nv_V4;
601
602   case Hexagon::STrih_shl_V4:
603     return Hexagon::STrih_shl_nv_V4;
604
605   case Hexagon::STrih_GP_V4:
606     return Hexagon::STrih_GP_nv_V4;
607
608   case Hexagon::STh_GP_V4:
609     return Hexagon::STh_GP_nv_V4;
610
611   case Hexagon::POST_SThri:
612     return Hexagon::POST_SThri_nv_V4;
613
614   case Hexagon::STrih_cPt:
615     return Hexagon::STrih_cPt_nv_V4;
616
617   case Hexagon::STrih_cdnPt_V4:
618     return Hexagon::STrih_cdnPt_nv_V4;
619
620   case Hexagon::STrih_cNotPt:
621     return Hexagon::STrih_cNotPt_nv_V4;
622
623   case Hexagon::STrih_cdnNotPt_V4:
624     return Hexagon::STrih_cdnNotPt_nv_V4;
625
626   case Hexagon::STrih_indexed_cPt:
627     return Hexagon::STrih_indexed_cPt_nv_V4;
628
629   case Hexagon::STrih_indexed_cdnPt_V4:
630     return Hexagon::STrih_indexed_cdnPt_nv_V4;
631
632   case Hexagon::STrih_indexed_cNotPt:
633     return Hexagon::STrih_indexed_cNotPt_nv_V4;
634
635   case Hexagon::STrih_indexed_cdnNotPt_V4:
636     return Hexagon::STrih_indexed_cdnNotPt_nv_V4;
637
638   case Hexagon::STrih_indexed_shl_cPt_V4:
639     return Hexagon::STrih_indexed_shl_cPt_nv_V4;
640
641   case Hexagon::STrih_indexed_shl_cdnPt_V4:
642     return Hexagon::STrih_indexed_shl_cdnPt_nv_V4;
643
644   case Hexagon::STrih_indexed_shl_cNotPt_V4:
645     return Hexagon::STrih_indexed_shl_cNotPt_nv_V4;
646
647   case Hexagon::STrih_indexed_shl_cdnNotPt_V4:
648     return Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4;
649
650   case Hexagon::POST_SThri_cPt:
651     return Hexagon::POST_SThri_cPt_nv_V4;
652
653   case Hexagon::POST_SThri_cdnPt_V4:
654     return Hexagon::POST_SThri_cdnPt_nv_V4;
655
656   case Hexagon::POST_SThri_cNotPt:
657     return Hexagon::POST_SThri_cNotPt_nv_V4;
658
659   case Hexagon::POST_SThri_cdnNotPt_V4:
660     return Hexagon::POST_SThri_cdnNotPt_nv_V4;
661
662   case Hexagon::STh_GP_cPt_V4:
663     return Hexagon::STh_GP_cPt_nv_V4;
664
665   case Hexagon::STh_GP_cNotPt_V4:
666     return Hexagon::STh_GP_cNotPt_nv_V4;
667
668   case Hexagon::STh_GP_cdnPt_V4:
669     return Hexagon::STh_GP_cdnPt_nv_V4;
670
671   case Hexagon::STh_GP_cdnNotPt_V4:
672     return Hexagon::STh_GP_cdnNotPt_nv_V4;
673
674   case Hexagon::STrih_GP_cPt_V4:
675     return Hexagon::STrih_GP_cPt_nv_V4;
676
677   case Hexagon::STrih_GP_cNotPt_V4:
678     return Hexagon::STrih_GP_cNotPt_nv_V4;
679
680   case Hexagon::STrih_GP_cdnPt_V4:
681     return Hexagon::STrih_GP_cdnPt_nv_V4;
682
683   case Hexagon::STrih_GP_cdnNotPt_V4:
684     return Hexagon::STrih_GP_cdnNotPt_nv_V4;
685
686   // store new value word
687   case Hexagon::STriw:
688     return Hexagon::STriw_nv_V4;
689
690   case Hexagon::STriw_indexed:
691     return Hexagon::STriw_indexed_nv_V4;
692
693   case Hexagon::STriw_indexed_shl_V4:
694     return Hexagon::STriw_indexed_shl_nv_V4;
695
696   case Hexagon::STriw_shl_V4:
697     return Hexagon::STriw_shl_nv_V4;
698
699   case Hexagon::STriw_GP_V4:
700     return Hexagon::STriw_GP_nv_V4;
701
702   case Hexagon::STw_GP_V4:
703     return Hexagon::STw_GP_nv_V4;
704
705   case Hexagon::POST_STwri:
706     return Hexagon::POST_STwri_nv_V4;
707
708   case Hexagon::STriw_cPt:
709     return Hexagon::STriw_cPt_nv_V4;
710
711   case Hexagon::STriw_cdnPt_V4:
712     return Hexagon::STriw_cdnPt_nv_V4;
713
714   case Hexagon::STriw_cNotPt:
715     return Hexagon::STriw_cNotPt_nv_V4;
716
717   case Hexagon::STriw_cdnNotPt_V4:
718     return Hexagon::STriw_cdnNotPt_nv_V4;
719
720   case Hexagon::STriw_indexed_cPt:
721     return Hexagon::STriw_indexed_cPt_nv_V4;
722
723   case Hexagon::STriw_indexed_cdnPt_V4:
724     return Hexagon::STriw_indexed_cdnPt_nv_V4;
725
726   case Hexagon::STriw_indexed_cNotPt:
727     return Hexagon::STriw_indexed_cNotPt_nv_V4;
728
729   case Hexagon::STriw_indexed_cdnNotPt_V4:
730     return Hexagon::STriw_indexed_cdnNotPt_nv_V4;
731
732   case Hexagon::STriw_indexed_shl_cPt_V4:
733     return Hexagon::STriw_indexed_shl_cPt_nv_V4;
734
735   case Hexagon::STriw_indexed_shl_cdnPt_V4:
736     return Hexagon::STriw_indexed_shl_cdnPt_nv_V4;
737
738   case Hexagon::STriw_indexed_shl_cNotPt_V4:
739     return Hexagon::STriw_indexed_shl_cNotPt_nv_V4;
740
741   case Hexagon::STriw_indexed_shl_cdnNotPt_V4:
742     return Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4;
743
744   case Hexagon::POST_STwri_cPt:
745     return Hexagon::POST_STwri_cPt_nv_V4;
746
747   case Hexagon::POST_STwri_cdnPt_V4:
748     return Hexagon::POST_STwri_cdnPt_nv_V4;
749
750   case Hexagon::POST_STwri_cNotPt:
751     return Hexagon::POST_STwri_cNotPt_nv_V4;
752
753   case Hexagon::POST_STwri_cdnNotPt_V4:
754     return Hexagon::POST_STwri_cdnNotPt_nv_V4;
755
756   case Hexagon::STw_GP_cPt_V4:
757     return Hexagon::STw_GP_cPt_nv_V4;
758
759   case Hexagon::STw_GP_cNotPt_V4:
760     return Hexagon::STw_GP_cNotPt_nv_V4;
761
762   case Hexagon::STw_GP_cdnPt_V4:
763     return Hexagon::STw_GP_cdnPt_nv_V4;
764
765   case Hexagon::STw_GP_cdnNotPt_V4:
766     return Hexagon::STw_GP_cdnNotPt_nv_V4;
767
768   case Hexagon::STriw_GP_cPt_V4:
769     return Hexagon::STriw_GP_cPt_nv_V4;
770
771   case Hexagon::STriw_GP_cNotPt_V4:
772     return Hexagon::STriw_GP_cNotPt_nv_V4;
773
774   case Hexagon::STriw_GP_cdnPt_V4:
775     return Hexagon::STriw_GP_cdnPt_nv_V4;
776
777   case Hexagon::STriw_GP_cdnNotPt_V4:
778     return Hexagon::STriw_GP_cdnNotPt_nv_V4;
779   }
780 }
781
782 // Return .new predicate version for an instruction
783 static int GetDotNewPredOp(const int opc) {
784   switch (opc) {
785   default: llvm_unreachable("Unknown .new type");
786   // Conditional stores
787   // Store byte conditionally
788   case Hexagon::STrib_cPt :
789     return Hexagon::STrib_cdnPt_V4;
790
791   case Hexagon::STrib_cNotPt :
792     return Hexagon::STrib_cdnNotPt_V4;
793
794   case Hexagon::STrib_indexed_cPt :
795     return Hexagon::STrib_indexed_cdnPt_V4;
796
797   case Hexagon::STrib_indexed_cNotPt :
798     return Hexagon::STrib_indexed_cdnNotPt_V4;
799
800   case Hexagon::STrib_imm_cPt_V4 :
801     return Hexagon::STrib_imm_cdnPt_V4;
802
803   case Hexagon::STrib_imm_cNotPt_V4 :
804     return Hexagon::STrib_imm_cdnNotPt_V4;
805
806   case Hexagon::POST_STbri_cPt :
807     return Hexagon::POST_STbri_cdnPt_V4;
808
809   case Hexagon::POST_STbri_cNotPt :
810     return Hexagon::POST_STbri_cdnNotPt_V4;
811
812   case Hexagon::STrib_indexed_shl_cPt_V4 :
813     return Hexagon::STrib_indexed_shl_cdnPt_V4;
814
815   case Hexagon::STrib_indexed_shl_cNotPt_V4 :
816     return Hexagon::STrib_indexed_shl_cdnNotPt_V4;
817
818   case Hexagon::STb_GP_cPt_V4 :
819     return Hexagon::STb_GP_cdnPt_V4;
820
821   case Hexagon::STb_GP_cNotPt_V4 :
822     return Hexagon::STb_GP_cdnNotPt_V4;
823
824   case Hexagon::STrib_GP_cPt_V4 :
825     return Hexagon::STrib_GP_cdnPt_V4;
826
827   case Hexagon::STrib_GP_cNotPt_V4 :
828     return Hexagon::STrib_GP_cdnNotPt_V4;
829
830   // Store doubleword conditionally
831   case Hexagon::STrid_cPt :
832     return Hexagon::STrid_cdnPt_V4;
833
834   case Hexagon::STrid_cNotPt :
835     return Hexagon::STrid_cdnNotPt_V4;
836
837   case Hexagon::STrid_indexed_cPt :
838     return Hexagon::STrid_indexed_cdnPt_V4;
839
840   case Hexagon::STrid_indexed_cNotPt :
841     return Hexagon::STrid_indexed_cdnNotPt_V4;
842
843   case Hexagon::STrid_indexed_shl_cPt_V4 :
844     return Hexagon::STrid_indexed_shl_cdnPt_V4;
845
846   case Hexagon::STrid_indexed_shl_cNotPt_V4 :
847     return Hexagon::STrid_indexed_shl_cdnNotPt_V4;
848
849   case Hexagon::POST_STdri_cPt :
850     return Hexagon::POST_STdri_cdnPt_V4;
851
852   case Hexagon::POST_STdri_cNotPt :
853     return Hexagon::POST_STdri_cdnNotPt_V4;
854
855   case Hexagon::STd_GP_cPt_V4 :
856     return Hexagon::STd_GP_cdnPt_V4;
857
858   case Hexagon::STd_GP_cNotPt_V4 :
859     return Hexagon::STd_GP_cdnNotPt_V4;
860
861   case Hexagon::STrid_GP_cPt_V4 :
862     return Hexagon::STrid_GP_cdnPt_V4;
863
864   case Hexagon::STrid_GP_cNotPt_V4 :
865     return Hexagon::STrid_GP_cdnNotPt_V4;
866
867   // Store halfword conditionally
868   case Hexagon::STrih_cPt :
869     return Hexagon::STrih_cdnPt_V4;
870
871   case Hexagon::STrih_cNotPt :
872     return Hexagon::STrih_cdnNotPt_V4;
873
874   case Hexagon::STrih_indexed_cPt :
875     return Hexagon::STrih_indexed_cdnPt_V4;
876
877   case Hexagon::STrih_indexed_cNotPt :
878     return Hexagon::STrih_indexed_cdnNotPt_V4;
879
880   case Hexagon::STrih_imm_cPt_V4 :
881     return Hexagon::STrih_imm_cdnPt_V4;
882
883   case Hexagon::STrih_imm_cNotPt_V4 :
884     return Hexagon::STrih_imm_cdnNotPt_V4;
885
886   case Hexagon::STrih_indexed_shl_cPt_V4 :
887     return Hexagon::STrih_indexed_shl_cdnPt_V4;
888
889   case Hexagon::STrih_indexed_shl_cNotPt_V4 :
890     return Hexagon::STrih_indexed_shl_cdnNotPt_V4;
891
892   case Hexagon::POST_SThri_cPt :
893     return Hexagon::POST_SThri_cdnPt_V4;
894
895   case Hexagon::POST_SThri_cNotPt :
896     return Hexagon::POST_SThri_cdnNotPt_V4;
897
898   case Hexagon::STh_GP_cPt_V4 :
899     return Hexagon::STh_GP_cdnPt_V4;
900
901   case Hexagon::STh_GP_cNotPt_V4 :
902     return Hexagon::STh_GP_cdnNotPt_V4;
903
904   case Hexagon::STrih_GP_cPt_V4 :
905     return Hexagon::STrih_GP_cdnPt_V4;
906
907   case Hexagon::STrih_GP_cNotPt_V4 :
908     return Hexagon::STrih_GP_cdnNotPt_V4;
909
910   // Store word conditionally
911   case Hexagon::STriw_cPt :
912     return Hexagon::STriw_cdnPt_V4;
913
914   case Hexagon::STriw_cNotPt :
915     return Hexagon::STriw_cdnNotPt_V4;
916
917   case Hexagon::STriw_indexed_cPt :
918     return Hexagon::STriw_indexed_cdnPt_V4;
919
920   case Hexagon::STriw_indexed_cNotPt :
921     return Hexagon::STriw_indexed_cdnNotPt_V4;
922
923   case Hexagon::STriw_imm_cPt_V4 :
924     return Hexagon::STriw_imm_cdnPt_V4;
925
926   case Hexagon::STriw_imm_cNotPt_V4 :
927     return Hexagon::STriw_imm_cdnNotPt_V4;
928
929   case Hexagon::STriw_indexed_shl_cPt_V4 :
930     return Hexagon::STriw_indexed_shl_cdnPt_V4;
931
932   case Hexagon::STriw_indexed_shl_cNotPt_V4 :
933     return Hexagon::STriw_indexed_shl_cdnNotPt_V4;
934
935   case Hexagon::POST_STwri_cPt :
936     return Hexagon::POST_STwri_cdnPt_V4;
937
938   case Hexagon::POST_STwri_cNotPt :
939     return Hexagon::POST_STwri_cdnNotPt_V4;
940
941   case Hexagon::STw_GP_cPt_V4 :
942     return Hexagon::STw_GP_cdnPt_V4;
943
944   case Hexagon::STw_GP_cNotPt_V4 :
945     return Hexagon::STw_GP_cdnNotPt_V4;
946
947   case Hexagon::STriw_GP_cPt_V4 :
948     return Hexagon::STriw_GP_cdnPt_V4;
949
950   case Hexagon::STriw_GP_cNotPt_V4 :
951     return Hexagon::STriw_GP_cdnNotPt_V4;
952
953   // Condtional Jumps
954   case Hexagon::JMP_c:
955     return Hexagon::JMP_cdnPt;
956
957   case Hexagon::JMP_cNot:
958     return Hexagon::JMP_cdnNotPt;
959
960   case Hexagon::JMPR_cPt:
961     return Hexagon::JMPR_cdnPt_V3;
962
963   case Hexagon::JMPR_cNotPt:
964     return Hexagon::JMPR_cdnNotPt_V3;
965
966   // Conditional Transfers
967   case Hexagon::TFR_cPt:
968     return Hexagon::TFR_cdnPt;
969
970   case Hexagon::TFR_cNotPt:
971     return Hexagon::TFR_cdnNotPt;
972
973   case Hexagon::TFRI_cPt:
974     return Hexagon::TFRI_cdnPt;
975
976   case Hexagon::TFRI_cNotPt:
977     return Hexagon::TFRI_cdnNotPt;
978
979   // Load double word
980   case Hexagon::LDrid_cPt :
981     return Hexagon::LDrid_cdnPt;
982
983   case Hexagon::LDrid_cNotPt :
984     return Hexagon::LDrid_cdnNotPt;
985
986   case Hexagon::LDrid_indexed_cPt :
987     return Hexagon::LDrid_indexed_cdnPt;
988
989   case Hexagon::LDrid_indexed_cNotPt :
990     return Hexagon::LDrid_indexed_cdnNotPt;
991
992   case Hexagon::POST_LDrid_cPt :
993     return Hexagon::POST_LDrid_cdnPt_V4;
994
995   case Hexagon::POST_LDrid_cNotPt :
996     return Hexagon::POST_LDrid_cdnNotPt_V4;
997
998   // Load word
999   case Hexagon::LDriw_cPt :
1000     return Hexagon::LDriw_cdnPt;
1001
1002   case Hexagon::LDriw_cNotPt :
1003     return Hexagon::LDriw_cdnNotPt;
1004
1005   case Hexagon::LDriw_indexed_cPt :
1006     return Hexagon::LDriw_indexed_cdnPt;
1007
1008   case Hexagon::LDriw_indexed_cNotPt :
1009     return Hexagon::LDriw_indexed_cdnNotPt;
1010
1011   case Hexagon::POST_LDriw_cPt :
1012     return Hexagon::POST_LDriw_cdnPt_V4;
1013
1014   case Hexagon::POST_LDriw_cNotPt :
1015     return Hexagon::POST_LDriw_cdnNotPt_V4;
1016
1017   // Load halfword
1018   case Hexagon::LDrih_cPt :
1019     return Hexagon::LDrih_cdnPt;
1020
1021   case Hexagon::LDrih_cNotPt :
1022     return Hexagon::LDrih_cdnNotPt;
1023
1024   case Hexagon::LDrih_indexed_cPt :
1025     return Hexagon::LDrih_indexed_cdnPt;
1026
1027   case Hexagon::LDrih_indexed_cNotPt :
1028     return Hexagon::LDrih_indexed_cdnNotPt;
1029
1030   case Hexagon::POST_LDrih_cPt :
1031     return Hexagon::POST_LDrih_cdnPt_V4;
1032
1033   case Hexagon::POST_LDrih_cNotPt :
1034     return Hexagon::POST_LDrih_cdnNotPt_V4;
1035
1036   // Load byte
1037   case Hexagon::LDrib_cPt :
1038     return Hexagon::LDrib_cdnPt;
1039
1040   case Hexagon::LDrib_cNotPt :
1041     return Hexagon::LDrib_cdnNotPt;
1042
1043   case Hexagon::LDrib_indexed_cPt :
1044     return Hexagon::LDrib_indexed_cdnPt;
1045
1046   case Hexagon::LDrib_indexed_cNotPt :
1047     return Hexagon::LDrib_indexed_cdnNotPt;
1048
1049   case Hexagon::POST_LDrib_cPt :
1050     return Hexagon::POST_LDrib_cdnPt_V4;
1051
1052   case Hexagon::POST_LDrib_cNotPt :
1053     return Hexagon::POST_LDrib_cdnNotPt_V4;
1054
1055   // Load unsigned halfword
1056   case Hexagon::LDriuh_cPt :
1057     return Hexagon::LDriuh_cdnPt;
1058
1059   case Hexagon::LDriuh_cNotPt :
1060     return Hexagon::LDriuh_cdnNotPt;
1061
1062   case Hexagon::LDriuh_indexed_cPt :
1063     return Hexagon::LDriuh_indexed_cdnPt;
1064
1065   case Hexagon::LDriuh_indexed_cNotPt :
1066     return Hexagon::LDriuh_indexed_cdnNotPt;
1067
1068   case Hexagon::POST_LDriuh_cPt :
1069     return Hexagon::POST_LDriuh_cdnPt_V4;
1070
1071   case Hexagon::POST_LDriuh_cNotPt :
1072     return Hexagon::POST_LDriuh_cdnNotPt_V4;
1073
1074   // Load unsigned byte
1075   case Hexagon::LDriub_cPt :
1076     return Hexagon::LDriub_cdnPt;
1077
1078   case Hexagon::LDriub_cNotPt :
1079     return Hexagon::LDriub_cdnNotPt;
1080
1081   case Hexagon::LDriub_indexed_cPt :
1082     return Hexagon::LDriub_indexed_cdnPt;
1083
1084   case Hexagon::LDriub_indexed_cNotPt :
1085     return Hexagon::LDriub_indexed_cdnNotPt;
1086
1087   case Hexagon::POST_LDriub_cPt :
1088     return Hexagon::POST_LDriub_cdnPt_V4;
1089
1090   case Hexagon::POST_LDriub_cNotPt :
1091     return Hexagon::POST_LDriub_cdnNotPt_V4;
1092
1093   // V4 indexed+scaled load
1094
1095   case Hexagon::LDrid_indexed_shl_cPt_V4 :
1096     return Hexagon::LDrid_indexed_shl_cdnPt_V4;
1097
1098   case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
1099     return Hexagon::LDrid_indexed_shl_cdnNotPt_V4;
1100
1101   case Hexagon::LDrib_indexed_shl_cPt_V4 :
1102     return Hexagon::LDrib_indexed_shl_cdnPt_V4;
1103
1104   case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
1105     return Hexagon::LDrib_indexed_shl_cdnNotPt_V4;
1106
1107   case Hexagon::LDriub_indexed_shl_cPt_V4 :
1108     return Hexagon::LDriub_indexed_shl_cdnPt_V4;
1109
1110   case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
1111     return Hexagon::LDriub_indexed_shl_cdnNotPt_V4;
1112
1113   case Hexagon::LDrih_indexed_shl_cPt_V4 :
1114     return Hexagon::LDrih_indexed_shl_cdnPt_V4;
1115
1116   case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
1117     return Hexagon::LDrih_indexed_shl_cdnNotPt_V4;
1118
1119   case Hexagon::LDriuh_indexed_shl_cPt_V4 :
1120     return Hexagon::LDriuh_indexed_shl_cdnPt_V4;
1121
1122   case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
1123     return Hexagon::LDriuh_indexed_shl_cdnNotPt_V4;
1124
1125   case Hexagon::LDriw_indexed_shl_cPt_V4 :
1126     return Hexagon::LDriw_indexed_shl_cdnPt_V4;
1127
1128   case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
1129     return Hexagon::LDriw_indexed_shl_cdnNotPt_V4;
1130
1131   // V4 global address load
1132
1133   case Hexagon::LDd_GP_cPt_V4:
1134     return Hexagon::LDd_GP_cdnPt_V4;
1135
1136   case Hexagon::LDd_GP_cNotPt_V4:
1137     return Hexagon::LDd_GP_cdnNotPt_V4;
1138
1139   case Hexagon::LDb_GP_cPt_V4:
1140     return Hexagon::LDb_GP_cdnPt_V4;
1141
1142   case Hexagon::LDb_GP_cNotPt_V4:
1143     return Hexagon::LDb_GP_cdnNotPt_V4;
1144
1145   case Hexagon::LDub_GP_cPt_V4:
1146     return Hexagon::LDub_GP_cdnPt_V4;
1147
1148   case Hexagon::LDub_GP_cNotPt_V4:
1149     return Hexagon::LDub_GP_cdnNotPt_V4;
1150
1151   case Hexagon::LDh_GP_cPt_V4:
1152     return Hexagon::LDh_GP_cdnPt_V4;
1153
1154   case Hexagon::LDh_GP_cNotPt_V4:
1155     return Hexagon::LDh_GP_cdnNotPt_V4;
1156
1157   case Hexagon::LDuh_GP_cPt_V4:
1158     return Hexagon::LDuh_GP_cdnPt_V4;
1159
1160   case Hexagon::LDuh_GP_cNotPt_V4:
1161     return Hexagon::LDuh_GP_cdnNotPt_V4;
1162
1163   case Hexagon::LDw_GP_cPt_V4:
1164     return Hexagon::LDw_GP_cdnPt_V4;
1165
1166   case Hexagon::LDw_GP_cNotPt_V4:
1167     return Hexagon::LDw_GP_cdnNotPt_V4;
1168
1169   case Hexagon::LDrid_GP_cPt_V4:
1170     return Hexagon::LDrid_GP_cdnPt_V4;
1171
1172   case Hexagon::LDrid_GP_cNotPt_V4:
1173     return Hexagon::LDrid_GP_cdnNotPt_V4;
1174
1175   case Hexagon::LDrib_GP_cPt_V4:
1176     return Hexagon::LDrib_GP_cdnPt_V4;
1177
1178   case Hexagon::LDrib_GP_cNotPt_V4:
1179     return Hexagon::LDrib_GP_cdnNotPt_V4;
1180
1181   case Hexagon::LDriub_GP_cPt_V4:
1182     return Hexagon::LDriub_GP_cdnPt_V4;
1183
1184   case Hexagon::LDriub_GP_cNotPt_V4:
1185     return Hexagon::LDriub_GP_cdnNotPt_V4;
1186
1187   case Hexagon::LDrih_GP_cPt_V4:
1188     return Hexagon::LDrih_GP_cdnPt_V4;
1189
1190   case Hexagon::LDrih_GP_cNotPt_V4:
1191     return Hexagon::LDrih_GP_cdnNotPt_V4;
1192
1193   case Hexagon::LDriuh_GP_cPt_V4:
1194     return Hexagon::LDriuh_GP_cdnPt_V4;
1195
1196   case Hexagon::LDriuh_GP_cNotPt_V4:
1197     return Hexagon::LDriuh_GP_cdnNotPt_V4;
1198
1199   case Hexagon::LDriw_GP_cPt_V4:
1200     return Hexagon::LDriw_GP_cdnPt_V4;
1201
1202   case Hexagon::LDriw_GP_cNotPt_V4:
1203     return Hexagon::LDriw_GP_cdnNotPt_V4;
1204
1205   // Conditional store new-value byte
1206   case Hexagon::STrib_cPt_nv_V4 :
1207     return Hexagon::STrib_cdnPt_nv_V4;
1208   case Hexagon::STrib_cNotPt_nv_V4 :
1209     return Hexagon::STrib_cdnNotPt_nv_V4;
1210
1211   case Hexagon::STrib_indexed_cPt_nv_V4 :
1212     return Hexagon::STrib_indexed_cdnPt_nv_V4;
1213   case Hexagon::STrib_indexed_cNotPt_nv_V4 :
1214     return Hexagon::STrib_indexed_cdnNotPt_nv_V4;
1215
1216   case Hexagon::STrib_indexed_shl_cPt_nv_V4 :
1217     return Hexagon::STrib_indexed_shl_cdnPt_nv_V4;
1218   case Hexagon::STrib_indexed_shl_cNotPt_nv_V4 :
1219     return Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4;
1220
1221   case Hexagon::POST_STbri_cPt_nv_V4 :
1222     return Hexagon::POST_STbri_cdnPt_nv_V4;
1223   case Hexagon::POST_STbri_cNotPt_nv_V4 :
1224     return Hexagon::POST_STbri_cdnNotPt_nv_V4;
1225
1226   case Hexagon::STb_GP_cPt_nv_V4 :
1227     return Hexagon::STb_GP_cdnPt_nv_V4;
1228
1229   case Hexagon::STb_GP_cNotPt_nv_V4 :
1230     return Hexagon::STb_GP_cdnNotPt_nv_V4;
1231
1232   case Hexagon::STrib_GP_cPt_nv_V4 :
1233     return Hexagon::STrib_GP_cdnPt_nv_V4;
1234
1235   case Hexagon::STrib_GP_cNotPt_nv_V4 :
1236     return Hexagon::STrib_GP_cdnNotPt_nv_V4;
1237
1238   // Conditional store new-value halfword
1239   case Hexagon::STrih_cPt_nv_V4 :
1240     return Hexagon::STrih_cdnPt_nv_V4;
1241   case Hexagon::STrih_cNotPt_nv_V4 :
1242     return Hexagon::STrih_cdnNotPt_nv_V4;
1243
1244   case Hexagon::STrih_indexed_cPt_nv_V4 :
1245     return Hexagon::STrih_indexed_cdnPt_nv_V4;
1246   case Hexagon::STrih_indexed_cNotPt_nv_V4 :
1247     return Hexagon::STrih_indexed_cdnNotPt_nv_V4;
1248
1249   case Hexagon::STrih_indexed_shl_cPt_nv_V4 :
1250     return Hexagon::STrih_indexed_shl_cdnPt_nv_V4;
1251   case Hexagon::STrih_indexed_shl_cNotPt_nv_V4 :
1252     return Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4;
1253
1254   case Hexagon::POST_SThri_cPt_nv_V4 :
1255     return Hexagon::POST_SThri_cdnPt_nv_V4;
1256   case Hexagon::POST_SThri_cNotPt_nv_V4 :
1257     return Hexagon::POST_SThri_cdnNotPt_nv_V4;
1258
1259   case Hexagon::STh_GP_cPt_nv_V4 :
1260     return Hexagon::STh_GP_cdnPt_nv_V4;
1261
1262   case Hexagon::STh_GP_cNotPt_nv_V4 :
1263     return Hexagon::STh_GP_cdnNotPt_nv_V4;
1264
1265   case Hexagon::STrih_GP_cPt_nv_V4 :
1266     return Hexagon::STrih_GP_cdnPt_nv_V4;
1267
1268   case Hexagon::STrih_GP_cNotPt_nv_V4 :
1269     return Hexagon::STrih_GP_cdnNotPt_nv_V4;
1270
1271   // Conditional store new-value word
1272   case Hexagon::STriw_cPt_nv_V4 :
1273     return  Hexagon::STriw_cdnPt_nv_V4;
1274   case Hexagon::STriw_cNotPt_nv_V4 :
1275     return Hexagon::STriw_cdnNotPt_nv_V4;
1276
1277   case Hexagon::STriw_indexed_cPt_nv_V4 :
1278     return Hexagon::STriw_indexed_cdnPt_nv_V4;
1279   case Hexagon::STriw_indexed_cNotPt_nv_V4 :
1280     return Hexagon::STriw_indexed_cdnNotPt_nv_V4;
1281
1282   case Hexagon::STriw_indexed_shl_cPt_nv_V4 :
1283     return Hexagon::STriw_indexed_shl_cdnPt_nv_V4;
1284   case Hexagon::STriw_indexed_shl_cNotPt_nv_V4 :
1285     return Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4;
1286
1287   case Hexagon::POST_STwri_cPt_nv_V4 :
1288     return Hexagon::POST_STwri_cdnPt_nv_V4;
1289   case Hexagon::POST_STwri_cNotPt_nv_V4:
1290     return Hexagon::POST_STwri_cdnNotPt_nv_V4;
1291
1292   case Hexagon::STw_GP_cPt_nv_V4 :
1293     return Hexagon::STw_GP_cdnPt_nv_V4;
1294
1295   case Hexagon::STw_GP_cNotPt_nv_V4 :
1296     return Hexagon::STw_GP_cdnNotPt_nv_V4;
1297
1298   case Hexagon::STriw_GP_cPt_nv_V4 :
1299     return Hexagon::STriw_GP_cdnPt_nv_V4;
1300
1301   case Hexagon::STriw_GP_cNotPt_nv_V4 :
1302     return Hexagon::STriw_GP_cdnNotPt_nv_V4;
1303
1304   // Conditional add
1305   case Hexagon::ADD_ri_cPt :
1306     return Hexagon::ADD_ri_cdnPt;
1307   case Hexagon::ADD_ri_cNotPt :
1308     return Hexagon::ADD_ri_cdnNotPt;
1309
1310   case Hexagon::ADD_rr_cPt :
1311     return Hexagon::ADD_rr_cdnPt;
1312   case Hexagon::ADD_rr_cNotPt :
1313     return Hexagon::ADD_rr_cdnNotPt;
1314
1315   // Conditional logical Operations
1316   case Hexagon::XOR_rr_cPt :
1317     return Hexagon::XOR_rr_cdnPt;
1318   case Hexagon::XOR_rr_cNotPt :
1319     return Hexagon::XOR_rr_cdnNotPt;
1320
1321   case Hexagon::AND_rr_cPt :
1322     return Hexagon::AND_rr_cdnPt;
1323   case Hexagon::AND_rr_cNotPt :
1324     return Hexagon::AND_rr_cdnNotPt;
1325
1326   case Hexagon::OR_rr_cPt :
1327     return Hexagon::OR_rr_cdnPt;
1328   case Hexagon::OR_rr_cNotPt :
1329     return Hexagon::OR_rr_cdnNotPt;
1330
1331   // Conditional Subtract
1332   case Hexagon::SUB_rr_cPt :
1333     return Hexagon::SUB_rr_cdnPt;
1334   case Hexagon::SUB_rr_cNotPt :
1335     return Hexagon::SUB_rr_cdnNotPt;
1336
1337   // Conditional combine
1338   case Hexagon::COMBINE_rr_cPt :
1339     return Hexagon::COMBINE_rr_cdnPt;
1340   case Hexagon::COMBINE_rr_cNotPt :
1341     return Hexagon::COMBINE_rr_cdnNotPt;
1342
1343   case Hexagon::ASLH_cPt_V4 :
1344     return Hexagon::ASLH_cdnPt_V4;
1345   case Hexagon::ASLH_cNotPt_V4 :
1346     return Hexagon::ASLH_cdnNotPt_V4;
1347
1348   case Hexagon::ASRH_cPt_V4 :
1349     return Hexagon::ASRH_cdnPt_V4;
1350   case Hexagon::ASRH_cNotPt_V4 :
1351     return Hexagon::ASRH_cdnNotPt_V4;
1352
1353   case Hexagon::SXTB_cPt_V4 :
1354     return Hexagon::SXTB_cdnPt_V4;
1355   case Hexagon::SXTB_cNotPt_V4 :
1356     return Hexagon::SXTB_cdnNotPt_V4;
1357
1358   case Hexagon::SXTH_cPt_V4 :
1359     return Hexagon::SXTH_cdnPt_V4;
1360   case Hexagon::SXTH_cNotPt_V4 :
1361     return Hexagon::SXTH_cdnNotPt_V4;
1362
1363   case Hexagon::ZXTB_cPt_V4 :
1364     return Hexagon::ZXTB_cdnPt_V4;
1365   case Hexagon::ZXTB_cNotPt_V4 :
1366     return Hexagon::ZXTB_cdnNotPt_V4;
1367
1368   case Hexagon::ZXTH_cPt_V4 :
1369     return Hexagon::ZXTH_cdnPt_V4;
1370   case Hexagon::ZXTH_cNotPt_V4 :
1371     return Hexagon::ZXTH_cdnNotPt_V4;
1372   }
1373 }
1374
1375 // Returns true if an instruction can be promoted to .new predicate
1376 // or new-value store.
1377 bool HexagonPacketizerList::isNewifiable(MachineInstr* MI) {
1378   if ( isCondInst(MI) || IsNewifyStore(MI))
1379     return true;
1380   else
1381     return false;
1382 }
1383
1384 bool HexagonPacketizerList::isCondInst (MachineInstr* MI) {
1385   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
1386   const MCInstrDesc& TID = MI->getDesc();
1387                                     // bug 5670: until that is fixed,
1388                                     // this portion is disabled.
1389   if (   TID.isConditionalBranch()  // && !IsRegisterJump(MI)) ||
1390       || QII->isConditionalTransfer(MI)
1391       || QII->isConditionalALU32(MI)
1392       || QII->isConditionalLoad(MI)
1393       || QII->isConditionalStore(MI)) {
1394     return true;
1395   }
1396   return false;
1397 }
1398
1399
1400 // Promote an instructiont to its .new form.
1401 // At this time, we have already made a call to CanPromoteToDotNew
1402 // and made sure that it can *indeed* be promoted.
1403 bool HexagonPacketizerList::PromoteToDotNew(MachineInstr* MI,
1404                         SDep::Kind DepType, MachineBasicBlock::iterator &MII,
1405                         const TargetRegisterClass* RC) {
1406
1407   assert (DepType == SDep::Data);
1408   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
1409
1410   int NewOpcode;
1411   if (RC == &Hexagon::PredRegsRegClass)
1412     NewOpcode = GetDotNewPredOp(MI->getOpcode());
1413   else
1414     NewOpcode = GetDotNewOp(MI->getOpcode());
1415   MI->setDesc(QII->get(NewOpcode));
1416
1417   return true;
1418 }
1419
1420 // Returns the most basic instruction for the .new predicated instructions and
1421 // new-value stores.
1422 // For example, all of the following instructions will be converted back to the
1423 // same instruction:
1424 // 1) if (p0.new) memw(R0+#0) = R1.new  --->
1425 // 2) if (p0) memw(R0+#0)= R1.new      -------> if (p0) memw(R0+#0) = R1
1426 // 3) if (p0.new) memw(R0+#0) = R1      --->
1427 //
1428 // To understand the translation of instruction 1 to its original form, consider
1429 // a packet with 3 instructions.
1430 // { p0 = cmp.eq(R0,R1)
1431 //   if (p0.new) R2 = add(R3, R4)
1432 //   R5 = add (R3, R1)
1433 //   }
1434 // if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet
1435 //
1436 // This instruction can be part of the previous packet only if both p0 and R2
1437 // are promoted to .new values. This promotion happens in steps, first
1438 // predicate register is promoted to .new and in the next iteration R2 is
1439 // promoted. Therefore, in case of dependence check failure (due to R5) during
1440 // next iteration, it should be converted back to its most basic form.
1441
1442 static int GetDotOldOp(const int opc) {
1443   switch (opc) {
1444   default: llvm_unreachable("Unknown .old type");
1445   case Hexagon::TFR_cdnPt:
1446     return Hexagon::TFR_cPt;
1447
1448   case Hexagon::TFR_cdnNotPt:
1449     return Hexagon::TFR_cNotPt;
1450
1451   case Hexagon::TFRI_cdnPt:
1452     return Hexagon::TFRI_cPt;
1453
1454   case Hexagon::TFRI_cdnNotPt:
1455     return Hexagon::TFRI_cNotPt;
1456
1457   case Hexagon::JMP_cdnPt:
1458     return Hexagon::JMP_c;
1459
1460   case Hexagon::JMP_cdnNotPt:
1461     return Hexagon::JMP_cNot;
1462
1463   case Hexagon::JMPR_cdnPt_V3:
1464     return Hexagon::JMPR_cPt;
1465
1466   case Hexagon::JMPR_cdnNotPt_V3:
1467     return Hexagon::JMPR_cNotPt;
1468
1469   // Load double word
1470
1471   case Hexagon::LDrid_cdnPt :
1472     return Hexagon::LDrid_cPt;
1473
1474   case Hexagon::LDrid_cdnNotPt :
1475     return Hexagon::LDrid_cNotPt;
1476
1477   case Hexagon::LDrid_indexed_cdnPt :
1478     return Hexagon::LDrid_indexed_cPt;
1479
1480   case Hexagon::LDrid_indexed_cdnNotPt :
1481     return Hexagon::LDrid_indexed_cNotPt;
1482
1483   case Hexagon::POST_LDrid_cdnPt_V4 :
1484     return Hexagon::POST_LDrid_cPt;
1485
1486   case Hexagon::POST_LDrid_cdnNotPt_V4 :
1487     return Hexagon::POST_LDrid_cNotPt;
1488
1489   // Load word
1490
1491   case Hexagon::LDriw_cdnPt :
1492     return Hexagon::LDriw_cPt;
1493
1494   case Hexagon::LDriw_cdnNotPt :
1495     return Hexagon::LDriw_cNotPt;
1496
1497   case Hexagon::LDriw_indexed_cdnPt :
1498     return Hexagon::LDriw_indexed_cPt;
1499
1500   case Hexagon::LDriw_indexed_cdnNotPt :
1501     return Hexagon::LDriw_indexed_cNotPt;
1502
1503   case Hexagon::POST_LDriw_cdnPt_V4 :
1504     return Hexagon::POST_LDriw_cPt;
1505
1506   case Hexagon::POST_LDriw_cdnNotPt_V4 :
1507     return Hexagon::POST_LDriw_cNotPt;
1508
1509   // Load half
1510
1511   case Hexagon::LDrih_cdnPt :
1512     return Hexagon::LDrih_cPt;
1513
1514   case Hexagon::LDrih_cdnNotPt :
1515     return Hexagon::LDrih_cNotPt;
1516
1517   case Hexagon::LDrih_indexed_cdnPt :
1518     return Hexagon::LDrih_indexed_cPt;
1519
1520   case Hexagon::LDrih_indexed_cdnNotPt :
1521     return Hexagon::LDrih_indexed_cNotPt;
1522
1523   case Hexagon::POST_LDrih_cdnPt_V4 :
1524     return Hexagon::POST_LDrih_cPt;
1525
1526   case Hexagon::POST_LDrih_cdnNotPt_V4 :
1527     return Hexagon::POST_LDrih_cNotPt;
1528
1529   // Load byte
1530
1531   case Hexagon::LDrib_cdnPt :
1532     return Hexagon::LDrib_cPt;
1533
1534   case Hexagon::LDrib_cdnNotPt :
1535     return Hexagon::LDrib_cNotPt;
1536
1537   case Hexagon::LDrib_indexed_cdnPt :
1538     return Hexagon::LDrib_indexed_cPt;
1539
1540   case Hexagon::LDrib_indexed_cdnNotPt :
1541     return Hexagon::LDrib_indexed_cNotPt;
1542
1543   case Hexagon::POST_LDrib_cdnPt_V4 :
1544     return Hexagon::POST_LDrib_cPt;
1545
1546   case Hexagon::POST_LDrib_cdnNotPt_V4 :
1547     return Hexagon::POST_LDrib_cNotPt;
1548
1549   // Load unsigned half
1550
1551   case Hexagon::LDriuh_cdnPt :
1552     return Hexagon::LDriuh_cPt;
1553
1554   case Hexagon::LDriuh_cdnNotPt :
1555     return Hexagon::LDriuh_cNotPt;
1556
1557   case Hexagon::LDriuh_indexed_cdnPt :
1558     return Hexagon::LDriuh_indexed_cPt;
1559
1560   case Hexagon::LDriuh_indexed_cdnNotPt :
1561     return Hexagon::LDriuh_indexed_cNotPt;
1562
1563   case Hexagon::POST_LDriuh_cdnPt_V4 :
1564     return Hexagon::POST_LDriuh_cPt;
1565
1566   case Hexagon::POST_LDriuh_cdnNotPt_V4 :
1567     return Hexagon::POST_LDriuh_cNotPt;
1568
1569   // Load unsigned byte
1570   case Hexagon::LDriub_cdnPt :
1571     return Hexagon::LDriub_cPt;
1572
1573   case Hexagon::LDriub_cdnNotPt :
1574     return Hexagon::LDriub_cNotPt;
1575
1576   case Hexagon::LDriub_indexed_cdnPt :
1577     return Hexagon::LDriub_indexed_cPt;
1578
1579   case Hexagon::LDriub_indexed_cdnNotPt :
1580     return Hexagon::LDriub_indexed_cNotPt;
1581
1582   case Hexagon::POST_LDriub_cdnPt_V4 :
1583     return Hexagon::POST_LDriub_cPt;
1584
1585   case Hexagon::POST_LDriub_cdnNotPt_V4 :
1586     return Hexagon::POST_LDriub_cNotPt;
1587
1588   // V4 indexed+scaled Load
1589
1590   case Hexagon::LDrid_indexed_shl_cdnPt_V4 :
1591     return Hexagon::LDrid_indexed_shl_cPt_V4;
1592
1593   case Hexagon::LDrid_indexed_shl_cdnNotPt_V4 :
1594     return Hexagon::LDrid_indexed_shl_cNotPt_V4;
1595
1596   case Hexagon::LDrib_indexed_shl_cdnPt_V4 :
1597     return Hexagon::LDrib_indexed_shl_cPt_V4;
1598
1599   case Hexagon::LDrib_indexed_shl_cdnNotPt_V4 :
1600     return Hexagon::LDrib_indexed_shl_cNotPt_V4;
1601
1602   case Hexagon::LDriub_indexed_shl_cdnPt_V4 :
1603     return Hexagon::LDriub_indexed_shl_cPt_V4;
1604
1605   case Hexagon::LDriub_indexed_shl_cdnNotPt_V4 :
1606     return Hexagon::LDriub_indexed_shl_cNotPt_V4;
1607
1608   case Hexagon::LDrih_indexed_shl_cdnPt_V4 :
1609     return Hexagon::LDrih_indexed_shl_cPt_V4;
1610
1611   case Hexagon::LDrih_indexed_shl_cdnNotPt_V4 :
1612     return Hexagon::LDrih_indexed_shl_cNotPt_V4;
1613
1614   case Hexagon::LDriuh_indexed_shl_cdnPt_V4 :
1615     return Hexagon::LDriuh_indexed_shl_cPt_V4;
1616
1617   case Hexagon::LDriuh_indexed_shl_cdnNotPt_V4 :
1618     return Hexagon::LDriuh_indexed_shl_cNotPt_V4;
1619
1620   case Hexagon::LDriw_indexed_shl_cdnPt_V4 :
1621     return Hexagon::LDriw_indexed_shl_cPt_V4;
1622
1623   case Hexagon::LDriw_indexed_shl_cdnNotPt_V4 :
1624     return Hexagon::LDriw_indexed_shl_cNotPt_V4;
1625
1626   // V4 global address load
1627
1628   case Hexagon::LDd_GP_cdnPt_V4:
1629     return Hexagon::LDd_GP_cPt_V4;
1630
1631   case Hexagon::LDd_GP_cdnNotPt_V4:
1632     return Hexagon::LDd_GP_cNotPt_V4;
1633
1634   case Hexagon::LDb_GP_cdnPt_V4:
1635     return Hexagon::LDb_GP_cPt_V4;
1636
1637   case Hexagon::LDb_GP_cdnNotPt_V4:
1638     return Hexagon::LDb_GP_cNotPt_V4;
1639
1640   case Hexagon::LDub_GP_cdnPt_V4:
1641     return Hexagon::LDub_GP_cPt_V4;
1642
1643   case Hexagon::LDub_GP_cdnNotPt_V4:
1644     return Hexagon::LDub_GP_cNotPt_V4;
1645
1646   case Hexagon::LDh_GP_cdnPt_V4:
1647     return Hexagon::LDh_GP_cPt_V4;
1648
1649   case Hexagon::LDh_GP_cdnNotPt_V4:
1650     return Hexagon::LDh_GP_cNotPt_V4;
1651
1652   case Hexagon::LDuh_GP_cdnPt_V4:
1653     return Hexagon::LDuh_GP_cPt_V4;
1654
1655   case Hexagon::LDuh_GP_cdnNotPt_V4:
1656     return Hexagon::LDuh_GP_cNotPt_V4;
1657
1658   case Hexagon::LDw_GP_cdnPt_V4:
1659     return Hexagon::LDw_GP_cPt_V4;
1660
1661   case Hexagon::LDw_GP_cdnNotPt_V4:
1662     return Hexagon::LDw_GP_cNotPt_V4;
1663
1664   case Hexagon::LDrid_GP_cdnPt_V4:
1665     return Hexagon::LDrid_GP_cPt_V4;
1666
1667   case Hexagon::LDrid_GP_cdnNotPt_V4:
1668     return Hexagon::LDrid_GP_cNotPt_V4;
1669
1670   case Hexagon::LDrib_GP_cdnPt_V4:
1671     return Hexagon::LDrib_GP_cPt_V4;
1672
1673   case Hexagon::LDrib_GP_cdnNotPt_V4:
1674     return Hexagon::LDrib_GP_cNotPt_V4;
1675
1676   case Hexagon::LDriub_GP_cdnPt_V4:
1677     return Hexagon::LDriub_GP_cPt_V4;
1678
1679   case Hexagon::LDriub_GP_cdnNotPt_V4:
1680     return Hexagon::LDriub_GP_cNotPt_V4;
1681
1682   case Hexagon::LDrih_GP_cdnPt_V4:
1683     return Hexagon::LDrih_GP_cPt_V4;
1684
1685   case Hexagon::LDrih_GP_cdnNotPt_V4:
1686     return Hexagon::LDrih_GP_cNotPt_V4;
1687
1688   case Hexagon::LDriuh_GP_cdnPt_V4:
1689     return Hexagon::LDriuh_GP_cPt_V4;
1690
1691   case Hexagon::LDriuh_GP_cdnNotPt_V4:
1692     return Hexagon::LDriuh_GP_cNotPt_V4;
1693
1694   case Hexagon::LDriw_GP_cdnPt_V4:
1695     return Hexagon::LDriw_GP_cPt_V4;
1696
1697   case Hexagon::LDriw_GP_cdnNotPt_V4:
1698     return Hexagon::LDriw_GP_cNotPt_V4;
1699
1700   // Conditional add
1701
1702   case Hexagon::ADD_ri_cdnPt :
1703     return Hexagon::ADD_ri_cPt;
1704   case Hexagon::ADD_ri_cdnNotPt :
1705     return Hexagon::ADD_ri_cNotPt;
1706
1707   case Hexagon::ADD_rr_cdnPt :
1708     return Hexagon::ADD_rr_cPt;
1709   case Hexagon::ADD_rr_cdnNotPt:
1710     return Hexagon::ADD_rr_cNotPt;
1711
1712   // Conditional logical Operations
1713
1714   case Hexagon::XOR_rr_cdnPt :
1715     return Hexagon::XOR_rr_cPt;
1716   case Hexagon::XOR_rr_cdnNotPt :
1717     return Hexagon::XOR_rr_cNotPt;
1718
1719   case Hexagon::AND_rr_cdnPt :
1720     return Hexagon::AND_rr_cPt;
1721   case Hexagon::AND_rr_cdnNotPt :
1722     return Hexagon::AND_rr_cNotPt;
1723
1724   case Hexagon::OR_rr_cdnPt :
1725     return Hexagon::OR_rr_cPt;
1726   case Hexagon::OR_rr_cdnNotPt :
1727     return Hexagon::OR_rr_cNotPt;
1728
1729   // Conditional Subtract
1730
1731   case Hexagon::SUB_rr_cdnPt :
1732     return Hexagon::SUB_rr_cPt;
1733   case Hexagon::SUB_rr_cdnNotPt :
1734     return Hexagon::SUB_rr_cNotPt;
1735
1736   // Conditional combine
1737
1738   case Hexagon::COMBINE_rr_cdnPt :
1739     return Hexagon::COMBINE_rr_cPt;
1740   case Hexagon::COMBINE_rr_cdnNotPt :
1741     return Hexagon::COMBINE_rr_cNotPt;
1742
1743 // Conditional shift operations
1744
1745   case Hexagon::ASLH_cdnPt_V4 :
1746     return Hexagon::ASLH_cPt_V4;
1747   case Hexagon::ASLH_cdnNotPt_V4 :
1748     return Hexagon::ASLH_cNotPt_V4;
1749
1750   case Hexagon::ASRH_cdnPt_V4 :
1751     return Hexagon::ASRH_cPt_V4;
1752   case Hexagon::ASRH_cdnNotPt_V4 :
1753     return Hexagon::ASRH_cNotPt_V4;
1754
1755   case Hexagon::SXTB_cdnPt_V4 :
1756     return Hexagon::SXTB_cPt_V4;
1757   case Hexagon::SXTB_cdnNotPt_V4 :
1758     return Hexagon::SXTB_cNotPt_V4;
1759
1760   case Hexagon::SXTH_cdnPt_V4 :
1761     return Hexagon::SXTH_cPt_V4;
1762   case Hexagon::SXTH_cdnNotPt_V4 :
1763     return Hexagon::SXTH_cNotPt_V4;
1764
1765   case Hexagon::ZXTB_cdnPt_V4 :
1766     return Hexagon::ZXTB_cPt_V4;
1767   case Hexagon::ZXTB_cdnNotPt_V4 :
1768     return Hexagon::ZXTB_cNotPt_V4;
1769
1770   case Hexagon::ZXTH_cdnPt_V4 :
1771     return Hexagon::ZXTH_cPt_V4;
1772   case Hexagon::ZXTH_cdnNotPt_V4 :
1773     return Hexagon::ZXTH_cNotPt_V4;
1774
1775   // Store byte
1776
1777   case Hexagon::STrib_imm_cdnPt_V4 :
1778     return Hexagon::STrib_imm_cPt_V4;
1779
1780   case Hexagon::STrib_imm_cdnNotPt_V4 :
1781     return Hexagon::STrib_imm_cNotPt_V4;
1782
1783   case Hexagon::STrib_cdnPt_nv_V4 :
1784   case Hexagon::STrib_cPt_nv_V4 :
1785   case Hexagon::STrib_cdnPt_V4 :
1786     return Hexagon::STrib_cPt;
1787
1788   case Hexagon::STrib_cdnNotPt_nv_V4 :
1789   case Hexagon::STrib_cNotPt_nv_V4 :
1790   case Hexagon::STrib_cdnNotPt_V4 :
1791     return Hexagon::STrib_cNotPt;
1792
1793   case Hexagon::STrib_indexed_cdnPt_V4 :
1794   case Hexagon::STrib_indexed_cPt_nv_V4 :
1795   case Hexagon::STrib_indexed_cdnPt_nv_V4 :
1796     return Hexagon::STrib_indexed_cPt;
1797
1798   case Hexagon::STrib_indexed_cdnNotPt_V4 :
1799   case Hexagon::STrib_indexed_cNotPt_nv_V4 :
1800   case Hexagon::STrib_indexed_cdnNotPt_nv_V4 :
1801     return Hexagon::STrib_indexed_cNotPt;
1802
1803   case Hexagon::STrib_indexed_shl_cdnPt_nv_V4:
1804   case Hexagon::STrib_indexed_shl_cPt_nv_V4 :
1805   case Hexagon::STrib_indexed_shl_cdnPt_V4 :
1806     return Hexagon::STrib_indexed_shl_cPt_V4;
1807
1808   case Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4:
1809   case Hexagon::STrib_indexed_shl_cNotPt_nv_V4 :
1810   case Hexagon::STrib_indexed_shl_cdnNotPt_V4 :
1811     return Hexagon::STrib_indexed_shl_cNotPt_V4;
1812
1813   case Hexagon::POST_STbri_cdnPt_nv_V4 :
1814   case Hexagon::POST_STbri_cPt_nv_V4 :
1815   case Hexagon::POST_STbri_cdnPt_V4 :
1816     return Hexagon::POST_STbri_cPt;
1817
1818   case Hexagon::POST_STbri_cdnNotPt_nv_V4 :
1819   case Hexagon::POST_STbri_cNotPt_nv_V4:
1820   case Hexagon::POST_STbri_cdnNotPt_V4 :
1821     return Hexagon::POST_STbri_cNotPt;
1822
1823   case Hexagon::STb_GP_cdnPt_nv_V4:
1824   case Hexagon::STb_GP_cdnPt_V4:
1825   case Hexagon::STb_GP_cPt_nv_V4:
1826     return Hexagon::STb_GP_cPt_V4;
1827
1828   case Hexagon::STb_GP_cdnNotPt_nv_V4:
1829   case Hexagon::STb_GP_cdnNotPt_V4:
1830   case Hexagon::STb_GP_cNotPt_nv_V4:
1831     return Hexagon::STb_GP_cNotPt_V4;
1832
1833   case Hexagon::STrib_GP_cdnPt_nv_V4:
1834   case Hexagon::STrib_GP_cdnPt_V4:
1835   case Hexagon::STrib_GP_cPt_nv_V4:
1836     return Hexagon::STrib_GP_cPt_V4;
1837
1838   case Hexagon::STrib_GP_cdnNotPt_nv_V4:
1839   case Hexagon::STrib_GP_cdnNotPt_V4:
1840   case Hexagon::STrib_GP_cNotPt_nv_V4:
1841     return Hexagon::STrib_GP_cNotPt_V4;
1842
1843   // Store new-value byte - unconditional
1844   case Hexagon::STrib_nv_V4:
1845     return Hexagon::STrib;
1846
1847   case Hexagon::STrib_indexed_nv_V4:
1848     return Hexagon::STrib_indexed;
1849
1850   case Hexagon::STrib_indexed_shl_nv_V4:
1851     return Hexagon::STrib_indexed_shl_V4;
1852
1853   case Hexagon::STrib_shl_nv_V4:
1854     return Hexagon::STrib_shl_V4;
1855
1856   case Hexagon::STrib_GP_nv_V4:
1857     return Hexagon::STrib_GP_V4;
1858
1859   case Hexagon::STb_GP_nv_V4:
1860     return Hexagon::STb_GP_V4;
1861
1862   case Hexagon::POST_STbri_nv_V4:
1863     return Hexagon::POST_STbri;
1864
1865   // Store halfword
1866   case Hexagon::STrih_imm_cdnPt_V4 :
1867     return Hexagon::STrih_imm_cPt_V4;
1868
1869   case Hexagon::STrih_imm_cdnNotPt_V4 :
1870     return Hexagon::STrih_imm_cNotPt_V4;
1871
1872   case Hexagon::STrih_cdnPt_nv_V4 :
1873   case Hexagon::STrih_cPt_nv_V4 :
1874   case Hexagon::STrih_cdnPt_V4 :
1875     return Hexagon::STrih_cPt;
1876
1877   case Hexagon::STrih_cdnNotPt_nv_V4 :
1878   case Hexagon::STrih_cNotPt_nv_V4 :
1879   case Hexagon::STrih_cdnNotPt_V4 :
1880     return Hexagon::STrih_cNotPt;
1881
1882   case Hexagon::STrih_indexed_cdnPt_nv_V4:
1883   case Hexagon::STrih_indexed_cPt_nv_V4 :
1884   case Hexagon::STrih_indexed_cdnPt_V4 :
1885     return Hexagon::STrih_indexed_cPt;
1886
1887   case Hexagon::STrih_indexed_cdnNotPt_nv_V4:
1888   case Hexagon::STrih_indexed_cNotPt_nv_V4 :
1889   case Hexagon::STrih_indexed_cdnNotPt_V4 :
1890     return Hexagon::STrih_indexed_cNotPt;
1891
1892   case Hexagon::STrih_indexed_shl_cdnPt_nv_V4 :
1893   case Hexagon::STrih_indexed_shl_cPt_nv_V4 :
1894   case Hexagon::STrih_indexed_shl_cdnPt_V4 :
1895     return Hexagon::STrih_indexed_shl_cPt_V4;
1896
1897   case Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4 :
1898   case Hexagon::STrih_indexed_shl_cNotPt_nv_V4 :
1899   case Hexagon::STrih_indexed_shl_cdnNotPt_V4 :
1900     return Hexagon::STrih_indexed_shl_cNotPt_V4;
1901
1902   case Hexagon::POST_SThri_cdnPt_nv_V4 :
1903   case Hexagon::POST_SThri_cPt_nv_V4 :
1904   case Hexagon::POST_SThri_cdnPt_V4 :
1905     return Hexagon::POST_SThri_cPt;
1906
1907   case Hexagon::POST_SThri_cdnNotPt_nv_V4 :
1908   case Hexagon::POST_SThri_cNotPt_nv_V4 :
1909   case Hexagon::POST_SThri_cdnNotPt_V4 :
1910     return Hexagon::POST_SThri_cNotPt;
1911
1912   case Hexagon::STh_GP_cdnPt_nv_V4:
1913   case Hexagon::STh_GP_cdnPt_V4:
1914   case Hexagon::STh_GP_cPt_nv_V4:
1915     return Hexagon::STh_GP_cPt_V4;
1916
1917   case Hexagon::STh_GP_cdnNotPt_nv_V4:
1918   case Hexagon::STh_GP_cdnNotPt_V4:
1919   case Hexagon::STh_GP_cNotPt_nv_V4:
1920     return Hexagon::STh_GP_cNotPt_V4;
1921
1922   case Hexagon::STrih_GP_cdnPt_nv_V4:
1923   case Hexagon::STrih_GP_cdnPt_V4:
1924   case Hexagon::STrih_GP_cPt_nv_V4:
1925     return Hexagon::STrih_GP_cPt_V4;
1926
1927   case Hexagon::STrih_GP_cdnNotPt_nv_V4:
1928   case Hexagon::STrih_GP_cdnNotPt_V4:
1929   case Hexagon::STrih_GP_cNotPt_nv_V4:
1930     return Hexagon::STrih_GP_cNotPt_V4;
1931
1932   // Store new-value halfword - unconditional
1933
1934   case Hexagon::STrih_nv_V4:
1935     return Hexagon::STrih;
1936
1937   case Hexagon::STrih_indexed_nv_V4:
1938     return Hexagon::STrih_indexed;
1939
1940   case Hexagon::STrih_indexed_shl_nv_V4:
1941     return Hexagon::STrih_indexed_shl_V4;
1942
1943   case Hexagon::STrih_shl_nv_V4:
1944     return Hexagon::STrih_shl_V4;
1945
1946   case Hexagon::STrih_GP_nv_V4:
1947     return Hexagon::STrih_GP_V4;
1948
1949   case Hexagon::STh_GP_nv_V4:
1950     return Hexagon::STh_GP_V4;
1951
1952   case Hexagon::POST_SThri_nv_V4:
1953     return Hexagon::POST_SThri;
1954
1955    // Store word
1956
1957    case Hexagon::STriw_imm_cdnPt_V4 :
1958     return Hexagon::STriw_imm_cPt_V4;
1959
1960   case Hexagon::STriw_imm_cdnNotPt_V4 :
1961     return Hexagon::STriw_imm_cNotPt_V4;
1962
1963   case Hexagon::STriw_cdnPt_nv_V4 :
1964   case Hexagon::STriw_cPt_nv_V4 :
1965   case Hexagon::STriw_cdnPt_V4 :
1966     return Hexagon::STriw_cPt;
1967
1968   case Hexagon::STriw_cdnNotPt_nv_V4 :
1969   case Hexagon::STriw_cNotPt_nv_V4 :
1970   case Hexagon::STriw_cdnNotPt_V4 :
1971     return Hexagon::STriw_cNotPt;
1972
1973   case Hexagon::STriw_indexed_cdnPt_nv_V4 :
1974   case Hexagon::STriw_indexed_cPt_nv_V4 :
1975   case Hexagon::STriw_indexed_cdnPt_V4 :
1976     return Hexagon::STriw_indexed_cPt;
1977
1978   case Hexagon::STriw_indexed_cdnNotPt_nv_V4 :
1979   case Hexagon::STriw_indexed_cNotPt_nv_V4 :
1980   case Hexagon::STriw_indexed_cdnNotPt_V4 :
1981     return Hexagon::STriw_indexed_cNotPt;
1982
1983   case Hexagon::STriw_indexed_shl_cdnPt_nv_V4 :
1984   case Hexagon::STriw_indexed_shl_cPt_nv_V4 :
1985   case Hexagon::STriw_indexed_shl_cdnPt_V4 :
1986     return Hexagon::STriw_indexed_shl_cPt_V4;
1987
1988   case Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4 :
1989   case Hexagon::STriw_indexed_shl_cNotPt_nv_V4 :
1990   case Hexagon::STriw_indexed_shl_cdnNotPt_V4 :
1991     return Hexagon::STriw_indexed_shl_cNotPt_V4;
1992
1993   case Hexagon::POST_STwri_cdnPt_nv_V4 :
1994   case Hexagon::POST_STwri_cPt_nv_V4 :
1995   case Hexagon::POST_STwri_cdnPt_V4 :
1996     return Hexagon::POST_STwri_cPt;
1997
1998   case Hexagon::POST_STwri_cdnNotPt_nv_V4 :
1999   case Hexagon::POST_STwri_cNotPt_nv_V4 :
2000   case Hexagon::POST_STwri_cdnNotPt_V4 :
2001     return Hexagon::POST_STwri_cNotPt;
2002
2003   case Hexagon::STw_GP_cdnPt_nv_V4:
2004   case Hexagon::STw_GP_cdnPt_V4:
2005   case Hexagon::STw_GP_cPt_nv_V4:
2006     return Hexagon::STw_GP_cPt_V4;
2007
2008   case Hexagon::STw_GP_cdnNotPt_nv_V4:
2009   case Hexagon::STw_GP_cdnNotPt_V4:
2010   case Hexagon::STw_GP_cNotPt_nv_V4:
2011     return Hexagon::STw_GP_cNotPt_V4;
2012
2013   case Hexagon::STriw_GP_cdnPt_nv_V4:
2014   case Hexagon::STriw_GP_cdnPt_V4:
2015   case Hexagon::STriw_GP_cPt_nv_V4:
2016     return Hexagon::STriw_GP_cPt_V4;
2017
2018   case Hexagon::STriw_GP_cdnNotPt_nv_V4:
2019   case Hexagon::STriw_GP_cdnNotPt_V4:
2020   case Hexagon::STriw_GP_cNotPt_nv_V4:
2021     return Hexagon::STriw_GP_cNotPt_V4;
2022
2023   // Store new-value word - unconditional
2024
2025   case Hexagon::STriw_nv_V4:
2026     return Hexagon::STriw;
2027
2028   case Hexagon::STriw_indexed_nv_V4:
2029     return Hexagon::STriw_indexed;
2030
2031   case Hexagon::STriw_indexed_shl_nv_V4:
2032     return Hexagon::STriw_indexed_shl_V4;
2033
2034   case Hexagon::STriw_shl_nv_V4:
2035     return Hexagon::STriw_shl_V4;
2036
2037   case Hexagon::STriw_GP_nv_V4:
2038     return Hexagon::STriw_GP_V4;
2039
2040   case Hexagon::STw_GP_nv_V4:
2041     return Hexagon::STw_GP_V4;
2042
2043   case Hexagon::POST_STwri_nv_V4:
2044     return Hexagon::POST_STwri;
2045
2046  // Store doubleword
2047
2048   case Hexagon::STrid_cdnPt_V4 :
2049     return Hexagon::STrid_cPt;
2050
2051   case Hexagon::STrid_cdnNotPt_V4 :
2052     return Hexagon::STrid_cNotPt;
2053
2054   case Hexagon::STrid_indexed_cdnPt_V4 :
2055     return Hexagon::STrid_indexed_cPt;
2056
2057   case Hexagon::STrid_indexed_cdnNotPt_V4 :
2058     return Hexagon::STrid_indexed_cNotPt;
2059
2060   case Hexagon::STrid_indexed_shl_cdnPt_V4 :
2061     return Hexagon::STrid_indexed_shl_cPt_V4;
2062
2063   case Hexagon::STrid_indexed_shl_cdnNotPt_V4 :
2064     return Hexagon::STrid_indexed_shl_cNotPt_V4;
2065
2066   case Hexagon::POST_STdri_cdnPt_V4 :
2067     return Hexagon::POST_STdri_cPt;
2068
2069   case Hexagon::POST_STdri_cdnNotPt_V4 :
2070     return Hexagon::POST_STdri_cNotPt;
2071
2072   case Hexagon::STd_GP_cdnPt_V4 :
2073     return Hexagon::STd_GP_cPt_V4;
2074
2075   case Hexagon::STd_GP_cdnNotPt_V4 :
2076     return Hexagon::STd_GP_cNotPt_V4;
2077
2078   case Hexagon::STrid_GP_cdnPt_V4 :
2079     return Hexagon::STrid_GP_cPt_V4;
2080
2081   case Hexagon::STrid_GP_cdnNotPt_V4 :
2082     return Hexagon::STrid_GP_cNotPt_V4;
2083   }
2084 }
2085
2086 bool HexagonPacketizerList::DemoteToDotOld(MachineInstr* MI) {
2087   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2088   int NewOpcode = GetDotOldOp(MI->getOpcode());
2089   MI->setDesc(QII->get(NewOpcode));
2090   return true;
2091 }
2092
2093 // Returns true if an instruction is predicated on p0 and false if it's
2094 // predicated on !p0.
2095
2096 static bool GetPredicateSense(MachineInstr* MI,
2097                               const HexagonInstrInfo *QII) {
2098
2099   switch (MI->getOpcode()) {
2100   default: llvm_unreachable("Unknown predicate sense of the instruction");
2101   case Hexagon::TFR_cPt:
2102   case Hexagon::TFR_cdnPt:
2103   case Hexagon::TFRI_cPt:
2104   case Hexagon::TFRI_cdnPt:
2105   case Hexagon::STrib_cPt :
2106   case Hexagon::STrib_cdnPt_V4 :
2107   case Hexagon::STrib_indexed_cPt :
2108   case Hexagon::STrib_indexed_cdnPt_V4 :
2109   case Hexagon::STrib_indexed_shl_cPt_V4 :
2110   case Hexagon::STrib_indexed_shl_cdnPt_V4 :
2111   case Hexagon::POST_STbri_cPt :
2112   case Hexagon::POST_STbri_cdnPt_V4 :
2113   case Hexagon::STrih_cPt :
2114   case Hexagon::STrih_cdnPt_V4 :
2115   case Hexagon::STrih_indexed_cPt :
2116   case Hexagon::STrih_indexed_cdnPt_V4 :
2117   case Hexagon::STrih_indexed_shl_cPt_V4 :
2118   case Hexagon::STrih_indexed_shl_cdnPt_V4 :
2119   case Hexagon::POST_SThri_cPt :
2120   case Hexagon::POST_SThri_cdnPt_V4 :
2121   case Hexagon::STriw_cPt :
2122   case Hexagon::STriw_cdnPt_V4 :
2123   case Hexagon::STriw_indexed_cPt :
2124   case Hexagon::STriw_indexed_cdnPt_V4 :
2125   case Hexagon::STriw_indexed_shl_cPt_V4 :
2126   case Hexagon::STriw_indexed_shl_cdnPt_V4 :
2127   case Hexagon::POST_STwri_cPt :
2128   case Hexagon::POST_STwri_cdnPt_V4 :
2129   case Hexagon::STrib_imm_cPt_V4 :
2130   case Hexagon::STrib_imm_cdnPt_V4 :
2131   case Hexagon::STrid_cPt :
2132   case Hexagon::STrid_cdnPt_V4 :
2133   case Hexagon::STrid_indexed_cPt :
2134   case Hexagon::STrid_indexed_cdnPt_V4 :
2135   case Hexagon::STrid_indexed_shl_cPt_V4 :
2136   case Hexagon::STrid_indexed_shl_cdnPt_V4 :
2137   case Hexagon::POST_STdri_cPt :
2138   case Hexagon::POST_STdri_cdnPt_V4 :
2139   case Hexagon::STrih_imm_cPt_V4 :
2140   case Hexagon::STrih_imm_cdnPt_V4 :
2141   case Hexagon::STriw_imm_cPt_V4 :
2142   case Hexagon::STriw_imm_cdnPt_V4 :
2143   case Hexagon::JMP_cdnPt :
2144   case Hexagon::LDrid_cPt :
2145   case Hexagon::LDrid_cdnPt :
2146   case Hexagon::LDrid_indexed_cPt :
2147   case Hexagon::LDrid_indexed_cdnPt :
2148   case Hexagon::POST_LDrid_cPt :
2149   case Hexagon::POST_LDrid_cdnPt_V4 :
2150   case Hexagon::LDriw_cPt :
2151   case Hexagon::LDriw_cdnPt :
2152   case Hexagon::LDriw_indexed_cPt :
2153   case Hexagon::LDriw_indexed_cdnPt :
2154   case Hexagon::POST_LDriw_cPt :
2155   case Hexagon::POST_LDriw_cdnPt_V4 :
2156   case Hexagon::LDrih_cPt :
2157   case Hexagon::LDrih_cdnPt :
2158   case Hexagon::LDrih_indexed_cPt :
2159   case Hexagon::LDrih_indexed_cdnPt :
2160   case Hexagon::POST_LDrih_cPt :
2161   case Hexagon::POST_LDrih_cdnPt_V4 :
2162   case Hexagon::LDrib_cPt :
2163   case Hexagon::LDrib_cdnPt :
2164   case Hexagon::LDrib_indexed_cPt :
2165   case Hexagon::LDrib_indexed_cdnPt :
2166   case Hexagon::POST_LDrib_cPt :
2167   case Hexagon::POST_LDrib_cdnPt_V4 :
2168   case Hexagon::LDriuh_cPt :
2169   case Hexagon::LDriuh_cdnPt :
2170   case Hexagon::LDriuh_indexed_cPt :
2171   case Hexagon::LDriuh_indexed_cdnPt :
2172   case Hexagon::POST_LDriuh_cPt :
2173   case Hexagon::POST_LDriuh_cdnPt_V4 :
2174   case Hexagon::LDriub_cPt :
2175   case Hexagon::LDriub_cdnPt :
2176   case Hexagon::LDriub_indexed_cPt :
2177   case Hexagon::LDriub_indexed_cdnPt :
2178   case Hexagon::POST_LDriub_cPt :
2179   case Hexagon::POST_LDriub_cdnPt_V4 :
2180   case Hexagon::LDrid_indexed_shl_cPt_V4 :
2181   case Hexagon::LDrid_indexed_shl_cdnPt_V4 :
2182   case Hexagon::LDrib_indexed_shl_cPt_V4 :
2183   case Hexagon::LDrib_indexed_shl_cdnPt_V4 :
2184   case Hexagon::LDriub_indexed_shl_cPt_V4 :
2185   case Hexagon::LDriub_indexed_shl_cdnPt_V4 :
2186   case Hexagon::LDrih_indexed_shl_cPt_V4 :
2187   case Hexagon::LDrih_indexed_shl_cdnPt_V4 :
2188   case Hexagon::LDriuh_indexed_shl_cPt_V4 :
2189   case Hexagon::LDriuh_indexed_shl_cdnPt_V4 :
2190   case Hexagon::LDriw_indexed_shl_cPt_V4 :
2191   case Hexagon::LDriw_indexed_shl_cdnPt_V4 :
2192   case Hexagon::ADD_ri_cPt :
2193   case Hexagon::ADD_ri_cdnPt :
2194   case Hexagon::ADD_rr_cPt :
2195   case Hexagon::ADD_rr_cdnPt :
2196   case Hexagon::XOR_rr_cPt :
2197   case Hexagon::XOR_rr_cdnPt :
2198   case Hexagon::AND_rr_cPt :
2199   case Hexagon::AND_rr_cdnPt :
2200   case Hexagon::OR_rr_cPt :
2201   case Hexagon::OR_rr_cdnPt :
2202   case Hexagon::SUB_rr_cPt :
2203   case Hexagon::SUB_rr_cdnPt :
2204   case Hexagon::COMBINE_rr_cPt :
2205   case Hexagon::COMBINE_rr_cdnPt :
2206   case Hexagon::ASLH_cPt_V4 :
2207   case Hexagon::ASLH_cdnPt_V4 :
2208   case Hexagon::ASRH_cPt_V4 :
2209   case Hexagon::ASRH_cdnPt_V4 :
2210   case Hexagon::SXTB_cPt_V4 :
2211   case Hexagon::SXTB_cdnPt_V4 :
2212   case Hexagon::SXTH_cPt_V4 :
2213   case Hexagon::SXTH_cdnPt_V4 :
2214   case Hexagon::ZXTB_cPt_V4 :
2215   case Hexagon::ZXTB_cdnPt_V4 :
2216   case Hexagon::ZXTH_cPt_V4 :
2217   case Hexagon::ZXTH_cdnPt_V4 :
2218   case Hexagon::LDrid_GP_cPt_V4 :
2219   case Hexagon::LDrib_GP_cPt_V4 :
2220   case Hexagon::LDriub_GP_cPt_V4 :
2221   case Hexagon::LDrih_GP_cPt_V4 :
2222   case Hexagon::LDriuh_GP_cPt_V4 :
2223   case Hexagon::LDriw_GP_cPt_V4 :
2224   case Hexagon::LDd_GP_cPt_V4 :
2225   case Hexagon::LDb_GP_cPt_V4 :
2226   case Hexagon::LDub_GP_cPt_V4 :
2227   case Hexagon::LDh_GP_cPt_V4 :
2228   case Hexagon::LDuh_GP_cPt_V4 :
2229   case Hexagon::LDw_GP_cPt_V4 :
2230   case Hexagon::STrid_GP_cPt_V4 :
2231   case Hexagon::STrib_GP_cPt_V4 :
2232   case Hexagon::STrih_GP_cPt_V4 :
2233   case Hexagon::STriw_GP_cPt_V4 :
2234   case Hexagon::STd_GP_cPt_V4 :
2235   case Hexagon::STb_GP_cPt_V4 :
2236   case Hexagon::STh_GP_cPt_V4 :
2237   case Hexagon::STw_GP_cPt_V4 :
2238   case Hexagon::LDrid_GP_cdnPt_V4 :
2239   case Hexagon::LDrib_GP_cdnPt_V4 :
2240   case Hexagon::LDriub_GP_cdnPt_V4 :
2241   case Hexagon::LDrih_GP_cdnPt_V4 :
2242   case Hexagon::LDriuh_GP_cdnPt_V4 :
2243   case Hexagon::LDriw_GP_cdnPt_V4 :
2244   case Hexagon::LDd_GP_cdnPt_V4 :
2245   case Hexagon::LDb_GP_cdnPt_V4 :
2246   case Hexagon::LDub_GP_cdnPt_V4 :
2247   case Hexagon::LDh_GP_cdnPt_V4 :
2248   case Hexagon::LDuh_GP_cdnPt_V4 :
2249   case Hexagon::LDw_GP_cdnPt_V4 :
2250   case Hexagon::STrid_GP_cdnPt_V4 :
2251   case Hexagon::STrib_GP_cdnPt_V4 :
2252   case Hexagon::STrih_GP_cdnPt_V4 :
2253   case Hexagon::STriw_GP_cdnPt_V4 :
2254   case Hexagon::STd_GP_cdnPt_V4 :
2255   case Hexagon::STb_GP_cdnPt_V4 :
2256   case Hexagon::STh_GP_cdnPt_V4 :
2257   case Hexagon::STw_GP_cdnPt_V4 :
2258     return true;
2259
2260   case Hexagon::TFR_cNotPt:
2261   case Hexagon::TFR_cdnNotPt:
2262   case Hexagon::TFRI_cNotPt:
2263   case Hexagon::TFRI_cdnNotPt:
2264   case Hexagon::STrib_cNotPt :
2265   case Hexagon::STrib_cdnNotPt_V4 :
2266   case Hexagon::STrib_indexed_cNotPt :
2267   case Hexagon::STrib_indexed_cdnNotPt_V4 :
2268   case Hexagon::STrib_indexed_shl_cNotPt_V4 :
2269   case Hexagon::STrib_indexed_shl_cdnNotPt_V4 :
2270   case Hexagon::POST_STbri_cNotPt :
2271   case Hexagon::POST_STbri_cdnNotPt_V4 :
2272   case Hexagon::STrih_cNotPt :
2273   case Hexagon::STrih_cdnNotPt_V4 :
2274   case Hexagon::STrih_indexed_cNotPt :
2275   case Hexagon::STrih_indexed_cdnNotPt_V4 :
2276   case Hexagon::STrih_indexed_shl_cNotPt_V4 :
2277   case Hexagon::STrih_indexed_shl_cdnNotPt_V4 :
2278   case Hexagon::POST_SThri_cNotPt :
2279   case Hexagon::POST_SThri_cdnNotPt_V4 :
2280   case Hexagon::STriw_cNotPt :
2281   case Hexagon::STriw_cdnNotPt_V4 :
2282   case Hexagon::STriw_indexed_cNotPt :
2283   case Hexagon::STriw_indexed_cdnNotPt_V4 :
2284   case Hexagon::STriw_indexed_shl_cNotPt_V4 :
2285   case Hexagon::STriw_indexed_shl_cdnNotPt_V4 :
2286   case Hexagon::POST_STwri_cNotPt :
2287   case Hexagon::POST_STwri_cdnNotPt_V4 :
2288   case Hexagon::STrib_imm_cNotPt_V4 :
2289   case Hexagon::STrib_imm_cdnNotPt_V4 :
2290   case Hexagon::STrid_cNotPt :
2291   case Hexagon::STrid_cdnNotPt_V4 :
2292   case Hexagon::STrid_indexed_cdnNotPt_V4 :
2293   case Hexagon::STrid_indexed_cNotPt :
2294   case Hexagon::STrid_indexed_shl_cNotPt_V4 :
2295   case Hexagon::STrid_indexed_shl_cdnNotPt_V4 :
2296   case Hexagon::POST_STdri_cNotPt :
2297   case Hexagon::POST_STdri_cdnNotPt_V4 :
2298   case Hexagon::STrih_imm_cNotPt_V4 :
2299   case Hexagon::STrih_imm_cdnNotPt_V4 :
2300   case Hexagon::STriw_imm_cNotPt_V4 :
2301   case Hexagon::STriw_imm_cdnNotPt_V4 :
2302   case Hexagon::JMP_cdnNotPt :
2303   case Hexagon::LDrid_cNotPt :
2304   case Hexagon::LDrid_cdnNotPt :
2305   case Hexagon::LDrid_indexed_cNotPt :
2306   case Hexagon::LDrid_indexed_cdnNotPt :
2307   case Hexagon::POST_LDrid_cNotPt :
2308   case Hexagon::POST_LDrid_cdnNotPt_V4 :
2309   case Hexagon::LDriw_cNotPt :
2310   case Hexagon::LDriw_cdnNotPt :
2311   case Hexagon::LDriw_indexed_cNotPt :
2312   case Hexagon::LDriw_indexed_cdnNotPt :
2313   case Hexagon::POST_LDriw_cNotPt :
2314   case Hexagon::POST_LDriw_cdnNotPt_V4 :
2315   case Hexagon::LDrih_cNotPt :
2316   case Hexagon::LDrih_cdnNotPt :
2317   case Hexagon::LDrih_indexed_cNotPt :
2318   case Hexagon::LDrih_indexed_cdnNotPt :
2319   case Hexagon::POST_LDrih_cNotPt :
2320   case Hexagon::POST_LDrih_cdnNotPt_V4 :
2321   case Hexagon::LDrib_cNotPt :
2322   case Hexagon::LDrib_cdnNotPt :
2323   case Hexagon::LDrib_indexed_cNotPt :
2324   case Hexagon::LDrib_indexed_cdnNotPt :
2325   case Hexagon::POST_LDrib_cNotPt :
2326   case Hexagon::POST_LDrib_cdnNotPt_V4 :
2327   case Hexagon::LDriuh_cNotPt :
2328   case Hexagon::LDriuh_cdnNotPt :
2329   case Hexagon::LDriuh_indexed_cNotPt :
2330   case Hexagon::LDriuh_indexed_cdnNotPt :
2331   case Hexagon::POST_LDriuh_cNotPt :
2332   case Hexagon::POST_LDriuh_cdnNotPt_V4 :
2333   case Hexagon::LDriub_cNotPt :
2334   case Hexagon::LDriub_cdnNotPt :
2335   case Hexagon::LDriub_indexed_cNotPt :
2336   case Hexagon::LDriub_indexed_cdnNotPt :
2337   case Hexagon::POST_LDriub_cNotPt :
2338   case Hexagon::POST_LDriub_cdnNotPt_V4 :
2339   case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
2340   case Hexagon::LDrid_indexed_shl_cdnNotPt_V4 :
2341   case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
2342   case Hexagon::LDrib_indexed_shl_cdnNotPt_V4 :
2343   case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
2344   case Hexagon::LDriub_indexed_shl_cdnNotPt_V4 :
2345   case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
2346   case Hexagon::LDrih_indexed_shl_cdnNotPt_V4 :
2347   case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
2348   case Hexagon::LDriuh_indexed_shl_cdnNotPt_V4 :
2349   case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
2350   case Hexagon::LDriw_indexed_shl_cdnNotPt_V4 :
2351   case Hexagon::ADD_ri_cNotPt :
2352   case Hexagon::ADD_ri_cdnNotPt :
2353   case Hexagon::ADD_rr_cNotPt :
2354   case Hexagon::ADD_rr_cdnNotPt :
2355   case Hexagon::XOR_rr_cNotPt :
2356   case Hexagon::XOR_rr_cdnNotPt :
2357   case Hexagon::AND_rr_cNotPt :
2358   case Hexagon::AND_rr_cdnNotPt :
2359   case Hexagon::OR_rr_cNotPt :
2360   case Hexagon::OR_rr_cdnNotPt :
2361   case Hexagon::SUB_rr_cNotPt :
2362   case Hexagon::SUB_rr_cdnNotPt :
2363   case Hexagon::COMBINE_rr_cNotPt :
2364   case Hexagon::COMBINE_rr_cdnNotPt :
2365   case Hexagon::ASLH_cNotPt_V4 :
2366   case Hexagon::ASLH_cdnNotPt_V4 :
2367   case Hexagon::ASRH_cNotPt_V4 :
2368   case Hexagon::ASRH_cdnNotPt_V4 :
2369   case Hexagon::SXTB_cNotPt_V4 :
2370   case Hexagon::SXTB_cdnNotPt_V4 :
2371   case Hexagon::SXTH_cNotPt_V4 :
2372   case Hexagon::SXTH_cdnNotPt_V4 :
2373   case Hexagon::ZXTB_cNotPt_V4 :
2374   case Hexagon::ZXTB_cdnNotPt_V4 :
2375   case Hexagon::ZXTH_cNotPt_V4 :
2376   case Hexagon::ZXTH_cdnNotPt_V4 :
2377
2378   case Hexagon::LDrid_GP_cNotPt_V4 :
2379   case Hexagon::LDrib_GP_cNotPt_V4 :
2380   case Hexagon::LDriub_GP_cNotPt_V4 :
2381   case Hexagon::LDrih_GP_cNotPt_V4 :
2382   case Hexagon::LDriuh_GP_cNotPt_V4 :
2383   case Hexagon::LDriw_GP_cNotPt_V4 :
2384   case Hexagon::LDd_GP_cNotPt_V4 :
2385   case Hexagon::LDb_GP_cNotPt_V4 :
2386   case Hexagon::LDub_GP_cNotPt_V4 :
2387   case Hexagon::LDh_GP_cNotPt_V4 :
2388   case Hexagon::LDuh_GP_cNotPt_V4 :
2389   case Hexagon::LDw_GP_cNotPt_V4 :
2390   case Hexagon::STrid_GP_cNotPt_V4 :
2391   case Hexagon::STrib_GP_cNotPt_V4 :
2392   case Hexagon::STrih_GP_cNotPt_V4 :
2393   case Hexagon::STriw_GP_cNotPt_V4 :
2394   case Hexagon::STd_GP_cNotPt_V4 :
2395   case Hexagon::STb_GP_cNotPt_V4 :
2396   case Hexagon::STh_GP_cNotPt_V4 :
2397   case Hexagon::STw_GP_cNotPt_V4 :
2398   case Hexagon::LDrid_GP_cdnNotPt_V4 :
2399   case Hexagon::LDrib_GP_cdnNotPt_V4 :
2400   case Hexagon::LDriub_GP_cdnNotPt_V4 :
2401   case Hexagon::LDrih_GP_cdnNotPt_V4 :
2402   case Hexagon::LDriuh_GP_cdnNotPt_V4 :
2403   case Hexagon::LDriw_GP_cdnNotPt_V4 :
2404   case Hexagon::LDd_GP_cdnNotPt_V4 :
2405   case Hexagon::LDb_GP_cdnNotPt_V4 :
2406   case Hexagon::LDub_GP_cdnNotPt_V4 :
2407   case Hexagon::LDh_GP_cdnNotPt_V4 :
2408   case Hexagon::LDuh_GP_cdnNotPt_V4 :
2409   case Hexagon::LDw_GP_cdnNotPt_V4 :
2410   case Hexagon::STrid_GP_cdnNotPt_V4 :
2411   case Hexagon::STrib_GP_cdnNotPt_V4 :
2412   case Hexagon::STrih_GP_cdnNotPt_V4 :
2413   case Hexagon::STriw_GP_cdnNotPt_V4 :
2414   case Hexagon::STd_GP_cdnNotPt_V4 :
2415   case Hexagon::STb_GP_cdnNotPt_V4 :
2416   case Hexagon::STh_GP_cdnNotPt_V4 :
2417   case Hexagon::STw_GP_cdnNotPt_V4 :
2418     return false;
2419   }
2420   // return *some value* to avoid compiler warning
2421   return false;
2422 }
2423
2424 bool HexagonPacketizerList::isDotNewInst(MachineInstr* MI) {
2425   if (isNewValueInst(MI))
2426     return true;
2427
2428   switch (MI->getOpcode()) {
2429   case Hexagon::TFR_cdnNotPt:
2430   case Hexagon::TFR_cdnPt:
2431   case Hexagon::TFRI_cdnNotPt:
2432   case Hexagon::TFRI_cdnPt:
2433   case Hexagon::LDrid_cdnPt :
2434   case Hexagon::LDrid_cdnNotPt :
2435   case Hexagon::LDrid_indexed_cdnPt :
2436   case Hexagon::LDrid_indexed_cdnNotPt :
2437   case Hexagon::POST_LDrid_cdnPt_V4 :
2438   case Hexagon::POST_LDrid_cdnNotPt_V4 :
2439   case Hexagon::LDriw_cdnPt :
2440   case Hexagon::LDriw_cdnNotPt :
2441   case Hexagon::LDriw_indexed_cdnPt :
2442   case Hexagon::LDriw_indexed_cdnNotPt :
2443   case Hexagon::POST_LDriw_cdnPt_V4 :
2444   case Hexagon::POST_LDriw_cdnNotPt_V4 :
2445   case Hexagon::LDrih_cdnPt :
2446   case Hexagon::LDrih_cdnNotPt :
2447   case Hexagon::LDrih_indexed_cdnPt :
2448   case Hexagon::LDrih_indexed_cdnNotPt :
2449   case Hexagon::POST_LDrih_cdnPt_V4 :
2450   case Hexagon::POST_LDrih_cdnNotPt_V4 :
2451   case Hexagon::LDrib_cdnPt :
2452   case Hexagon::LDrib_cdnNotPt :
2453   case Hexagon::LDrib_indexed_cdnPt :
2454   case Hexagon::LDrib_indexed_cdnNotPt :
2455   case Hexagon::POST_LDrib_cdnPt_V4 :
2456   case Hexagon::POST_LDrib_cdnNotPt_V4 :
2457   case Hexagon::LDriuh_cdnPt :
2458   case Hexagon::LDriuh_cdnNotPt :
2459   case Hexagon::LDriuh_indexed_cdnPt :
2460   case Hexagon::LDriuh_indexed_cdnNotPt :
2461   case Hexagon::POST_LDriuh_cdnPt_V4 :
2462   case Hexagon::POST_LDriuh_cdnNotPt_V4 :
2463   case Hexagon::LDriub_cdnPt :
2464   case Hexagon::LDriub_cdnNotPt :
2465   case Hexagon::LDriub_indexed_cdnPt :
2466   case Hexagon::LDriub_indexed_cdnNotPt :
2467   case Hexagon::POST_LDriub_cdnPt_V4 :
2468   case Hexagon::POST_LDriub_cdnNotPt_V4 :
2469
2470   case Hexagon::LDrid_indexed_shl_cdnPt_V4 :
2471   case Hexagon::LDrid_indexed_shl_cdnNotPt_V4 :
2472   case Hexagon::LDrib_indexed_shl_cdnPt_V4 :
2473   case Hexagon::LDrib_indexed_shl_cdnNotPt_V4 :
2474   case Hexagon::LDriub_indexed_shl_cdnPt_V4 :
2475   case Hexagon::LDriub_indexed_shl_cdnNotPt_V4 :
2476   case Hexagon::LDrih_indexed_shl_cdnPt_V4 :
2477   case Hexagon::LDrih_indexed_shl_cdnNotPt_V4 :
2478   case Hexagon::LDriuh_indexed_shl_cdnPt_V4 :
2479   case Hexagon::LDriuh_indexed_shl_cdnNotPt_V4 :
2480   case Hexagon::LDriw_indexed_shl_cdnPt_V4 :
2481   case Hexagon::LDriw_indexed_shl_cdnNotPt_V4 :
2482
2483 // Coditional add
2484   case Hexagon::ADD_ri_cdnPt:
2485   case Hexagon::ADD_ri_cdnNotPt:
2486   case Hexagon::ADD_rr_cdnPt:
2487   case Hexagon::ADD_rr_cdnNotPt:
2488
2489   // Conditional logical operations
2490   case Hexagon::XOR_rr_cdnPt :
2491   case Hexagon::XOR_rr_cdnNotPt :
2492   case Hexagon::AND_rr_cdnPt :
2493   case Hexagon::AND_rr_cdnNotPt :
2494   case Hexagon::OR_rr_cdnPt :
2495   case Hexagon::OR_rr_cdnNotPt :
2496
2497   // Conditonal subtract
2498   case Hexagon::SUB_rr_cdnPt :
2499   case Hexagon::SUB_rr_cdnNotPt :
2500
2501   // Conditional combine
2502   case Hexagon::COMBINE_rr_cdnPt :
2503   case Hexagon::COMBINE_rr_cdnNotPt :
2504
2505   // Conditional shift operations
2506   case Hexagon::ASLH_cdnPt_V4:
2507   case Hexagon::ASLH_cdnNotPt_V4:
2508   case Hexagon::ASRH_cdnPt_V4:
2509   case Hexagon::ASRH_cdnNotPt_V4:
2510   case Hexagon::SXTB_cdnPt_V4:
2511   case Hexagon::SXTB_cdnNotPt_V4:
2512   case Hexagon::SXTH_cdnPt_V4:
2513   case Hexagon::SXTH_cdnNotPt_V4:
2514   case Hexagon::ZXTB_cdnPt_V4:
2515   case Hexagon::ZXTB_cdnNotPt_V4:
2516   case Hexagon::ZXTH_cdnPt_V4:
2517   case Hexagon::ZXTH_cdnNotPt_V4:
2518
2519   // Conditional stores
2520   case Hexagon::STrib_imm_cdnPt_V4 :
2521   case Hexagon::STrib_imm_cdnNotPt_V4 :
2522   case Hexagon::STrib_cdnPt_V4 :
2523   case Hexagon::STrib_cdnNotPt_V4 :
2524   case Hexagon::STrib_indexed_cdnPt_V4 :
2525   case Hexagon::STrib_indexed_cdnNotPt_V4 :
2526   case Hexagon::POST_STbri_cdnPt_V4 :
2527   case Hexagon::POST_STbri_cdnNotPt_V4 :
2528   case Hexagon::STrib_indexed_shl_cdnPt_V4 :
2529   case Hexagon::STrib_indexed_shl_cdnNotPt_V4 :
2530
2531   // Store doubleword conditionally
2532   case Hexagon::STrid_indexed_cdnPt_V4 :
2533   case Hexagon::STrid_indexed_cdnNotPt_V4 :
2534   case Hexagon::STrid_indexed_shl_cdnPt_V4 :
2535   case Hexagon::STrid_indexed_shl_cdnNotPt_V4 :
2536   case Hexagon::POST_STdri_cdnPt_V4 :
2537   case Hexagon::POST_STdri_cdnNotPt_V4 :
2538
2539   // Store halfword conditionally
2540   case Hexagon::STrih_cdnPt_V4 :
2541   case Hexagon::STrih_cdnNotPt_V4 :
2542   case Hexagon::STrih_indexed_cdnPt_V4 :
2543   case Hexagon::STrih_indexed_cdnNotPt_V4 :
2544   case Hexagon::STrih_imm_cdnPt_V4 :
2545   case Hexagon::STrih_imm_cdnNotPt_V4 :
2546   case Hexagon::STrih_indexed_shl_cdnPt_V4 :
2547   case Hexagon::STrih_indexed_shl_cdnNotPt_V4 :
2548   case Hexagon::POST_SThri_cdnPt_V4 :
2549   case Hexagon::POST_SThri_cdnNotPt_V4 :
2550
2551   // Store word conditionally
2552   case Hexagon::STriw_cdnPt_V4 :
2553   case Hexagon::STriw_cdnNotPt_V4 :
2554   case Hexagon::STriw_indexed_cdnPt_V4 :
2555   case Hexagon::STriw_indexed_cdnNotPt_V4 :
2556   case Hexagon::STriw_imm_cdnPt_V4 :
2557   case Hexagon::STriw_imm_cdnNotPt_V4 :
2558   case Hexagon::STriw_indexed_shl_cdnPt_V4 :
2559   case Hexagon::STriw_indexed_shl_cdnNotPt_V4 :
2560   case Hexagon::POST_STwri_cdnPt_V4 :
2561   case Hexagon::POST_STwri_cdnNotPt_V4 :
2562
2563   case Hexagon::LDd_GP_cdnPt_V4:
2564   case Hexagon::LDd_GP_cdnNotPt_V4:
2565   case Hexagon::LDb_GP_cdnPt_V4:
2566   case Hexagon::LDb_GP_cdnNotPt_V4:
2567   case Hexagon::LDub_GP_cdnPt_V4:
2568   case Hexagon::LDub_GP_cdnNotPt_V4:
2569   case Hexagon::LDh_GP_cdnPt_V4:
2570   case Hexagon::LDh_GP_cdnNotPt_V4:
2571   case Hexagon::LDuh_GP_cdnPt_V4:
2572   case Hexagon::LDuh_GP_cdnNotPt_V4:
2573   case Hexagon::LDw_GP_cdnPt_V4:
2574   case Hexagon::LDw_GP_cdnNotPt_V4:
2575   case Hexagon::LDrid_GP_cdnPt_V4:
2576   case Hexagon::LDrid_GP_cdnNotPt_V4:
2577   case Hexagon::LDrib_GP_cdnPt_V4:
2578   case Hexagon::LDrib_GP_cdnNotPt_V4:
2579   case Hexagon::LDriub_GP_cdnPt_V4:
2580   case Hexagon::LDriub_GP_cdnNotPt_V4:
2581   case Hexagon::LDrih_GP_cdnPt_V4:
2582   case Hexagon::LDrih_GP_cdnNotPt_V4:
2583   case Hexagon::LDriuh_GP_cdnPt_V4:
2584   case Hexagon::LDriuh_GP_cdnNotPt_V4:
2585   case Hexagon::LDriw_GP_cdnPt_V4:
2586   case Hexagon::LDriw_GP_cdnNotPt_V4:
2587
2588   case Hexagon::STrid_GP_cdnPt_V4:
2589   case Hexagon::STrid_GP_cdnNotPt_V4:
2590   case Hexagon::STrib_GP_cdnPt_V4:
2591   case Hexagon::STrib_GP_cdnNotPt_V4:
2592   case Hexagon::STrih_GP_cdnPt_V4:
2593   case Hexagon::STrih_GP_cdnNotPt_V4:
2594   case Hexagon::STriw_GP_cdnPt_V4:
2595   case Hexagon::STriw_GP_cdnNotPt_V4:
2596   case Hexagon::STd_GP_cdnPt_V4:
2597   case Hexagon::STd_GP_cdnNotPt_V4:
2598   case Hexagon::STb_GP_cdnPt_V4:
2599   case Hexagon::STb_GP_cdnNotPt_V4:
2600   case Hexagon::STh_GP_cdnPt_V4:
2601   case Hexagon::STh_GP_cdnNotPt_V4:
2602   case Hexagon::STw_GP_cdnPt_V4:
2603   case Hexagon::STw_GP_cdnNotPt_V4:
2604     return true;
2605   }
2606   return false;
2607 }
2608
2609 static MachineOperand& GetPostIncrementOperand(MachineInstr *MI,
2610                                                const HexagonInstrInfo *QII) {
2611   assert(QII->isPostIncrement(MI) && "Not a post increment operation.");
2612 #ifndef NDEBUG
2613   // Post Increment means duplicates. Use dense map to find duplicates in the
2614   // list. Caution: Densemap initializes with the minimum of 64 buckets,
2615   // whereas there are at most 5 operands in the post increment.
2616   DenseMap<unsigned,  unsigned> DefRegsSet;
2617   for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++)
2618     if (MI->getOperand(opNum).isReg() &&
2619         MI->getOperand(opNum).isDef()) {
2620       DefRegsSet[MI->getOperand(opNum).getReg()] = 1;
2621     }
2622
2623   for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++)
2624     if (MI->getOperand(opNum).isReg() &&
2625         MI->getOperand(opNum).isUse()) {
2626       if (DefRegsSet[MI->getOperand(opNum).getReg()]) {
2627         return MI->getOperand(opNum);
2628       }
2629     }
2630 #else
2631   if (MI->getDesc().mayLoad()) {
2632     // The 2nd operand is always the post increment operand in load.
2633     assert(MI->getOperand(1).isReg() &&
2634                 "Post increment operand has be to a register.");
2635     return (MI->getOperand(1));
2636   }
2637   if (MI->getDesc().mayStore()) {
2638     // The 1st operand is always the post increment operand in store.
2639     assert(MI->getOperand(0).isReg() &&
2640                 "Post increment operand has be to a register.");
2641     return (MI->getOperand(0));
2642   }
2643 #endif
2644   // we should never come here.
2645   llvm_unreachable("mayLoad or mayStore not set for Post Increment operation");
2646 }
2647
2648 // get the value being stored
2649 static MachineOperand& GetStoreValueOperand(MachineInstr *MI) {
2650   // value being stored is always the last operand.
2651   return (MI->getOperand(MI->getNumOperands()-1));
2652 }
2653
2654 // can be new value store?
2655 // Following restrictions are to be respected in convert a store into
2656 // a new value store.
2657 // 1. If an instruction uses auto-increment, its address register cannot
2658 //    be a new-value register. Arch Spec 5.4.2.1
2659 // 2. If an instruction uses absolute-set addressing mode,
2660 //    its address register cannot be a new-value register.
2661 //    Arch Spec 5.4.2.1.TODO: This is not enabled as
2662 //    as absolute-set address mode patters are not implemented.
2663 // 3. If an instruction produces a 64-bit result, its registers cannot be used
2664 //    as new-value registers. Arch Spec 5.4.2.2.
2665 // 4. If the instruction that sets a new-value register is conditional, then
2666 //    the instruction that uses the new-value register must also be conditional,
2667 //    and both must always have their predicates evaluate identically.
2668 //    Arch Spec 5.4.2.3.
2669 // 5. There is an implied restriction of a packet can not have another store,
2670 //    if there is a  new value store in the packet. Corollary, if there is
2671 //    already a store in a packet, there can not be a new value store.
2672 //    Arch Spec: 3.4.4.2
2673 bool HexagonPacketizerList::CanPromoteToNewValueStore( MachineInstr *MI,
2674                 MachineInstr *PacketMI, unsigned DepReg,
2675                 std::map <MachineInstr*, SUnit*> MIToSUnit)
2676 {
2677   // Make sure we are looking at the store
2678   if (!IsNewifyStore(MI))
2679     return false;
2680
2681   // Make sure there is dependency and can be new value'ed
2682   if (GetStoreValueOperand(MI).isReg() &&
2683       GetStoreValueOperand(MI).getReg() != DepReg)
2684     return false;
2685
2686   const HexagonRegisterInfo* QRI = 
2687                             (const HexagonRegisterInfo *) TM.getRegisterInfo();
2688   const MCInstrDesc& MCID = PacketMI->getDesc();
2689   // first operand is always the result
2690
2691   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2692   const TargetRegisterClass* PacketRC = QII->getRegClass(MCID, 0, QRI, MF);
2693
2694   // if there is already an store in the packet, no can do new value store
2695   // Arch Spec 3.4.4.2.
2696   for (std::vector<MachineInstr*>::iterator VI = CurrentPacketMIs.begin(),
2697          VE = CurrentPacketMIs.end();
2698        (VI != VE); ++VI) {
2699     SUnit* PacketSU = MIToSUnit[*VI];
2700     if (PacketSU->getInstr()->getDesc().mayStore() ||
2701         // if we have mayStore = 1 set on ALLOCFRAME and DEALLOCFRAME,
2702         // then we don't need this
2703         PacketSU->getInstr()->getOpcode() == Hexagon::ALLOCFRAME ||
2704         PacketSU->getInstr()->getOpcode() == Hexagon::DEALLOCFRAME)
2705       return false;
2706   }
2707
2708   if (PacketRC == &Hexagon::DoubleRegsRegClass) {
2709     // new value store constraint: double regs can not feed into new value store
2710     // arch spec section: 5.4.2.2
2711     return false;
2712   }
2713
2714   // Make sure it's NOT the post increment register that we are going to
2715   // new value.
2716   if (QII->isPostIncrement(MI) &&
2717       MI->getDesc().mayStore() &&
2718       GetPostIncrementOperand(MI, QII).getReg() == DepReg) {
2719     return false;
2720   }
2721
2722   if (QII->isPostIncrement(PacketMI) &&
2723       PacketMI->getDesc().mayLoad() &&
2724       GetPostIncrementOperand(PacketMI, QII).getReg() == DepReg) {
2725     // if source is post_inc, or absolute-set addressing,
2726     // it can not feed into new value store
2727     //  r3 = memw(r2++#4)
2728     //  memw(r30 + #-1404) = r2.new -> can not be new value store
2729     // arch spec section: 5.4.2.1
2730     return false;
2731   }
2732
2733   // If the source that feeds the store is predicated, new value store must
2734   // also be also predicated.
2735   if (QII->isPredicated(PacketMI)) {
2736     if (!QII->isPredicated(MI))
2737       return false;
2738
2739     // Check to make sure that they both will have their predicates
2740     // evaluate identically
2741     unsigned predRegNumSrc = 0;
2742     unsigned predRegNumDst = 0;
2743     const TargetRegisterClass* predRegClass = NULL;
2744
2745     // Get predicate register used in the source instruction
2746     for(unsigned opNum = 0; opNum < PacketMI->getNumOperands(); opNum++) {
2747       if ( PacketMI->getOperand(opNum).isReg())
2748       predRegNumSrc = PacketMI->getOperand(opNum).getReg();
2749       predRegClass = QRI->getMinimalPhysRegClass(predRegNumSrc);
2750       if (predRegClass == &Hexagon::PredRegsRegClass) {
2751         break;
2752       }
2753     }
2754     assert ((predRegClass == &Hexagon::PredRegsRegClass ) &&
2755         ("predicate register not found in a predicated PacketMI instruction"));
2756
2757     // Get predicate register used in new-value store instruction
2758     for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++) {
2759       if ( MI->getOperand(opNum).isReg())
2760       predRegNumDst = MI->getOperand(opNum).getReg();
2761       predRegClass = QRI->getMinimalPhysRegClass(predRegNumDst);
2762       if (predRegClass == &Hexagon::PredRegsRegClass) {
2763         break;
2764       }
2765     }
2766     assert ((predRegClass == &Hexagon::PredRegsRegClass ) &&
2767             ("predicate register not found in a predicated MI instruction"));
2768
2769     // New-value register producer and user (store) need to satisfy these
2770     // constraints:
2771     // 1) Both instructions should be predicated on the same register.
2772     // 2) If producer of the new-value register is .new predicated then store
2773     // should also be .new predicated and if producer is not .new predicated
2774     // then store should not be .new predicated.
2775     // 3) Both new-value register producer and user should have same predicate
2776     // sense, i.e, either both should be negated or both should be none negated.
2777
2778     if (( predRegNumDst != predRegNumSrc) ||
2779           isDotNewInst(PacketMI) != isDotNewInst(MI)  ||
2780           GetPredicateSense(MI, QII) != GetPredicateSense(PacketMI, QII)) {
2781       return false;
2782     }
2783   }
2784
2785   // Make sure that other than the new-value register no other store instruction
2786   // register has been modified in the same packet. Predicate registers can be
2787   // modified by they should not be modified between the producer and the store
2788   // instruction as it will make them both conditional on different values.
2789   // We already know this to be true for all the instructions before and
2790   // including PacketMI. Howerver, we need to perform the check for the
2791   // remaining instructions in the packet.
2792
2793   std::vector<MachineInstr*>::iterator VI;
2794   std::vector<MachineInstr*>::iterator VE;
2795   unsigned StartCheck = 0;
2796
2797   for (VI=CurrentPacketMIs.begin(), VE = CurrentPacketMIs.end();
2798       (VI != VE); ++VI) {
2799     SUnit* TempSU = MIToSUnit[*VI];
2800     MachineInstr* TempMI = TempSU->getInstr();
2801
2802     // Following condition is true for all the instructions until PacketMI is
2803     // reached (StartCheck is set to 0 before the for loop).
2804     // StartCheck flag is 1 for all the instructions after PacketMI.
2805     if (TempMI != PacketMI && !StartCheck) // start processing only after
2806       continue;                            // encountering PacketMI
2807
2808     StartCheck = 1;
2809     if (TempMI == PacketMI) // We don't want to check PacketMI for dependence
2810       continue;
2811
2812     for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++) {
2813       if (MI->getOperand(opNum).isReg() &&
2814           TempSU->getInstr()->modifiesRegister(MI->getOperand(opNum).getReg(),
2815                                                QRI))
2816         return false;
2817     }
2818   }
2819
2820   // Make sure that for non POST_INC stores:
2821   // 1. The only use of reg is DepReg and no other registers.
2822   //    This handles V4 base+index registers.
2823   //    The following store can not be dot new.
2824   //    Eg.   r0 = add(r0, #3)a
2825   //          memw(r1+r0<<#2) = r0
2826   if (!QII->isPostIncrement(MI) &&
2827       GetStoreValueOperand(MI).isReg() &&
2828       GetStoreValueOperand(MI).getReg() == DepReg) {
2829     for(unsigned opNum = 0; opNum < MI->getNumOperands()-1; opNum++) {
2830       if (MI->getOperand(opNum).isReg() &&
2831           MI->getOperand(opNum).getReg() == DepReg) {
2832         return false;
2833       }
2834     }
2835     // 2. If data definition is because of implicit definition of the register,
2836     //    do not newify the store. Eg.
2837     //    %R9<def> = ZXTH %R12, %D6<imp-use>, %R12<imp-def>
2838     //    STrih_indexed %R8, 2, %R12<kill>; mem:ST2[%scevgep343]
2839     for(unsigned opNum = 0; opNum < PacketMI->getNumOperands(); opNum++) {
2840       if (PacketMI->getOperand(opNum).isReg() &&
2841           PacketMI->getOperand(opNum).getReg() == DepReg &&
2842           PacketMI->getOperand(opNum).isDef() &&
2843           PacketMI->getOperand(opNum).isImplicit()) {
2844         return false;
2845       }
2846     }
2847   }
2848
2849   // Can be dot new store.
2850   return true;
2851 }
2852
2853 // can this MI to promoted to either
2854 // new value store or new value jump
2855 bool HexagonPacketizerList::CanPromoteToNewValue( MachineInstr *MI,
2856                 SUnit *PacketSU, unsigned DepReg,
2857                 std::map <MachineInstr*, SUnit*> MIToSUnit,
2858                 MachineBasicBlock::iterator &MII)
2859 {
2860
2861   const HexagonRegisterInfo* QRI =
2862                             (const HexagonRegisterInfo *) TM.getRegisterInfo();
2863   if (!QRI->Subtarget.hasV4TOps() ||
2864       !IsNewifyStore(MI))
2865     return false;
2866
2867   MachineInstr *PacketMI = PacketSU->getInstr();
2868
2869   // Check to see the store can be new value'ed.
2870   if (CanPromoteToNewValueStore(MI, PacketMI, DepReg, MIToSUnit))
2871     return true;
2872
2873   // Check to see the compare/jump can be new value'ed.
2874   // This is done as a pass on its own. Don't need to check it here.
2875   return false;
2876 }
2877
2878 // Check to see if an instruction can be dot new
2879 // There are three kinds.
2880 // 1. dot new on predicate - V2/V3/V4
2881 // 2. dot new on stores NV/ST - V4
2882 // 3. dot new on jump NV/J - V4 -- This is generated in a pass.
2883 bool HexagonPacketizerList::CanPromoteToDotNew( MachineInstr *MI,
2884                               SUnit *PacketSU, unsigned DepReg,
2885                               std::map <MachineInstr*, SUnit*> MIToSUnit,
2886                               MachineBasicBlock::iterator &MII,
2887                               const TargetRegisterClass* RC )
2888 {
2889   // already a dot new instruction
2890   if (isDotNewInst(MI) && !IsNewifyStore(MI))
2891     return false;
2892
2893   if (!isNewifiable(MI))
2894     return false;
2895
2896   // predicate .new
2897   if (RC == &Hexagon::PredRegsRegClass && isCondInst(MI))
2898       return true;
2899   else if (RC != &Hexagon::PredRegsRegClass &&
2900       !IsNewifyStore(MI)) // MI is not a new-value store
2901     return false;
2902   else {
2903     // Create a dot new machine instruction to see if resources can be
2904     // allocated. If not, bail out now.
2905     const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2906     int NewOpcode = GetDotNewOp(MI->getOpcode());
2907     const MCInstrDesc &desc = QII->get(NewOpcode);
2908     DebugLoc dl;
2909     MachineInstr *NewMI =
2910                     MI->getParent()->getParent()->CreateMachineInstr(desc, dl);
2911     bool ResourcesAvailable = ResourceTracker->canReserveResources(NewMI);
2912     MI->getParent()->getParent()->DeleteMachineInstr(NewMI);
2913
2914     if (!ResourcesAvailable)
2915       return false;
2916
2917     // new value store only
2918     // new new value jump generated as a passes
2919     if (!CanPromoteToNewValue(MI, PacketSU, DepReg, MIToSUnit, MII)) {
2920       return false;
2921     }
2922   }
2923   return true;
2924 }
2925
2926 // Go through the packet instructions and search for anti dependency
2927 // between them and DepReg from MI
2928 // Consider this case:
2929 // Trying to add
2930 // a) %R1<def> = TFRI_cdNotPt %P3, 2
2931 // to this packet:
2932 // {
2933 //   b) %P0<def> = OR_pp %P3<kill>, %P0<kill>
2934 //   c) %P3<def> = TFR_PdRs %R23
2935 //   d) %R1<def> = TFRI_cdnPt %P3, 4
2936 //  }
2937 // The P3 from a) and d) will be complements after
2938 // a)'s P3 is converted to .new form
2939 // Anti Dep between c) and b) is irrelevant for this case
2940 bool HexagonPacketizerList::RestrictingDepExistInPacket (MachineInstr* MI,
2941       unsigned DepReg,
2942       std::map <MachineInstr*, SUnit*> MIToSUnit) {
2943
2944   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2945   SUnit* PacketSUDep = MIToSUnit[MI];
2946
2947   for (std::vector<MachineInstr*>::iterator VIN = CurrentPacketMIs.begin(),
2948        VEN = CurrentPacketMIs.end(); (VIN != VEN); ++VIN) {
2949
2950     // We only care for dependencies to predicated instructions
2951     if(!QII->isPredicated(*VIN)) continue;
2952
2953     // Scheduling Unit for current insn in the packet
2954     SUnit* PacketSU = MIToSUnit[*VIN];
2955
2956     // Look at dependencies between current members of the packet
2957     // and predicate defining instruction MI.
2958     // Make sure that dependency is on the exact register
2959     // we care about.
2960     if (PacketSU->isSucc(PacketSUDep)) {
2961       for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
2962         if ((PacketSU->Succs[i].getSUnit() == PacketSUDep) &&
2963             (PacketSU->Succs[i].getKind() == SDep::Anti) &&
2964             (PacketSU->Succs[i].getReg() == DepReg)) {
2965           return true;
2966         }
2967       }
2968     }
2969   }
2970
2971   return false;
2972 }
2973
2974
2975 // Given two predicated instructions, this function detects whether
2976 // the predicates are complements
2977 bool HexagonPacketizerList::ArePredicatesComplements (MachineInstr* MI1,
2978      MachineInstr* MI2, std::map <MachineInstr*, SUnit*> MIToSUnit) {
2979
2980   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2981   // Currently can only reason about conditional transfers
2982   if (!QII->isConditionalTransfer(MI1) || !QII->isConditionalTransfer(MI2)) {
2983     return false;
2984   }
2985
2986   // Scheduling unit for candidate
2987   SUnit* SU = MIToSUnit[MI1];
2988
2989   // One corner case deals with the following scenario:
2990   // Trying to add
2991   // a) %R24<def> = TFR_cPt %P0, %R25
2992   // to this packet:
2993   //
2994   // {
2995   //   b) %R25<def> = TFR_cNotPt %P0, %R24
2996   //   c) %P0<def> = CMPEQri %R26, 1
2997   // }
2998   //
2999   // On general check a) and b) are complements, but
3000   // presence of c) will convert a) to .new form, and
3001   // then it is not a complement
3002   // We attempt to detect it by analyzing  existing
3003   // dependencies in the packet
3004
3005   // Analyze relationships between all existing members of the packet.
3006   // Look for Anti dependecy on the same predicate reg
3007   // as used in the candidate
3008   for (std::vector<MachineInstr*>::iterator VIN = CurrentPacketMIs.begin(),
3009        VEN = CurrentPacketMIs.end(); (VIN != VEN); ++VIN) {
3010
3011     // Scheduling Unit for current insn in the packet
3012     SUnit* PacketSU = MIToSUnit[*VIN];
3013
3014     // If this instruction in the packet is succeeded by the candidate...
3015     if (PacketSU->isSucc(SU)) {
3016       for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
3017         // The corner case exist when there is true data
3018         // dependency between candidate and one of current
3019         // packet members, this dep is on predicate reg, and
3020         // there already exist anti dep on the same pred in
3021         // the packet.
3022         if (PacketSU->Succs[i].getSUnit() == SU &&
3023             Hexagon::PredRegsRegClass.contains(
3024               PacketSU->Succs[i].getReg()) &&
3025             PacketSU->Succs[i].getKind() == SDep::Data &&
3026             // Here I know that *VIN is predicate setting instruction
3027             // with true data dep to candidate on the register
3028             // we care about - c) in the above example.
3029             // Now I need to see if there is an anti dependency
3030             // from c) to any other instruction in the
3031             // same packet on the pred reg of interest
3032             RestrictingDepExistInPacket(*VIN,PacketSU->Succs[i].getReg(),
3033                                         MIToSUnit)) {
3034            return false;
3035         }
3036       }
3037     }
3038   }
3039
3040   // If the above case does not apply, check regular
3041   // complement condition.
3042   // Check that the predicate register is the same and
3043   // that the predicate sense is different
3044   // We also need to differentiate .old vs. .new:
3045   // !p0 is not complimentary to p0.new
3046   return ((MI1->getOperand(1).getReg() == MI2->getOperand(1).getReg()) &&
3047           (GetPredicateSense(MI1, QII) != GetPredicateSense(MI2, QII)) &&
3048           (isDotNewInst(MI1) == isDotNewInst(MI2)));
3049 }
3050
3051 // initPacketizerState - Initialize packetizer flags
3052 void HexagonPacketizerList::initPacketizerState() {
3053
3054   Dependence = false;
3055   PromotedToDotNew = false;
3056   GlueToNewValueJump = false;
3057   GlueAllocframeStore = false;
3058   FoundSequentialDependence = false;
3059
3060   return;
3061 }
3062
3063 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
3064 bool HexagonPacketizerList::ignorePseudoInstruction(MachineInstr *MI,
3065                                                     MachineBasicBlock *MBB) {
3066   if (MI->isDebugValue())
3067     return true;
3068
3069   // We must print out inline assembly
3070   if (MI->isInlineAsm())
3071     return false;
3072
3073   // We check if MI has any functional units mapped to it.
3074   // If it doesn't, we ignore the instruction.
3075   const MCInstrDesc& TID = MI->getDesc();
3076   unsigned SchedClass = TID.getSchedClass();
3077   const InstrStage* IS =
3078                     ResourceTracker->getInstrItins()->beginStage(SchedClass);
3079   unsigned FuncUnits = IS->getUnits();
3080   return !FuncUnits;
3081 }
3082
3083 // isSoloInstruction: - Returns true for instructions that must be
3084 // scheduled in their own packet.
3085 bool HexagonPacketizerList::isSoloInstruction(MachineInstr *MI) {
3086
3087   if (MI->isInlineAsm())
3088     return true;
3089
3090   if (MI->isEHLabel())
3091     return true;
3092
3093   // From Hexagon V4 Programmer's Reference Manual 3.4.4 Grouping constraints:
3094   // trap, pause, barrier, icinva, isync, and syncht are solo instructions.
3095   // They must not be grouped with other instructions in a packet.
3096   if (IsSchedBarrier(MI))
3097     return true;
3098
3099   return false;
3100 }
3101
3102 // isLegalToPacketizeTogether:
3103 // SUI is the current instruction that is out side of the current packet.
3104 // SUJ is the current instruction inside the current packet against which that
3105 // SUI will be packetized.
3106 bool HexagonPacketizerList::isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) {
3107   MachineInstr *I = SUI->getInstr();
3108   MachineInstr *J = SUJ->getInstr();
3109   assert(I && J && "Unable to packetize null instruction!");
3110
3111   const MCInstrDesc &MCIDI = I->getDesc();
3112   const MCInstrDesc &MCIDJ = J->getDesc();
3113
3114   MachineBasicBlock::iterator II = I;
3115
3116   const unsigned FrameSize = MF.getFrameInfo()->getStackSize();
3117   const HexagonRegisterInfo* QRI =
3118                       (const HexagonRegisterInfo *) TM.getRegisterInfo();
3119   const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
3120
3121   // Inline asm cannot go in the packet.
3122   if (I->getOpcode() == Hexagon::INLINEASM)
3123     llvm_unreachable("Should not meet inline asm here!");
3124
3125   if (isSoloInstruction(I))
3126     llvm_unreachable("Should not meet solo instr here!");
3127
3128   // A save callee-save register function call can only be in a packet
3129   // with instructions that don't write to the callee-save registers.
3130   if ((QII->isSaveCalleeSavedRegsCall(I) &&
3131        DoesModifyCalleeSavedReg(J, QRI)) ||
3132       (QII->isSaveCalleeSavedRegsCall(J) &&
3133        DoesModifyCalleeSavedReg(I, QRI))) {
3134     Dependence = true;
3135     return false;
3136   }
3137
3138   // Two control flow instructions cannot go in the same packet.
3139   if (IsControlFlow(I) && IsControlFlow(J)) {
3140     Dependence = true;
3141     return false;
3142   }
3143
3144   // A LoopN instruction cannot appear in the same packet as a jump or call.
3145   if (IsLoopN(I) && (   IsDirectJump(J)
3146                      || MCIDJ.isCall()
3147                      || QII->isDeallocRet(J))) {
3148     Dependence = true;
3149     return false;
3150   }
3151   if (IsLoopN(J) && (   IsDirectJump(I)
3152                      || MCIDI.isCall()
3153                      || QII->isDeallocRet(I))) {
3154     Dependence = true;
3155     return false;
3156   }
3157
3158   // dealloc_return cannot appear in the same packet as a conditional or
3159   // unconditional jump.
3160   if (QII->isDeallocRet(I) && (   MCIDJ.isBranch()
3161                                || MCIDJ.isCall()
3162                                || MCIDJ.isBarrier())) {
3163     Dependence = true;
3164     return false;
3165   }
3166
3167
3168   // V4 allows dual store. But does not allow second store, if the
3169   // first store is not in SLOT0. New value store, new value jump,
3170   // dealloc_return and memop always take SLOT0.
3171   // Arch spec 3.4.4.2
3172   if (QRI->Subtarget.hasV4TOps()) {
3173
3174     if (MCIDI.mayStore() && MCIDJ.mayStore() && isNewValueInst(J)) {
3175       Dependence = true;
3176       return false;
3177     }
3178
3179     if (   (QII->isMemOp(J) && MCIDI.mayStore())
3180         || (MCIDJ.mayStore() && QII->isMemOp(I))
3181         || (QII->isMemOp(J) && QII->isMemOp(I))) {
3182       Dependence = true;
3183       return false;
3184     }
3185
3186     //if dealloc_return
3187     if (MCIDJ.mayStore() && QII->isDeallocRet(I)){
3188       Dependence = true;
3189       return false;
3190     }
3191
3192     // If an instruction feeds new value jump, glue it.
3193     MachineBasicBlock::iterator NextMII = I;
3194     ++NextMII;
3195     MachineInstr *NextMI = NextMII;
3196
3197     if (QII->isNewValueJump(NextMI)) {
3198
3199       bool secondRegMatch = false;
3200       bool maintainNewValueJump = false;
3201
3202       if (NextMI->getOperand(1).isReg() &&
3203           I->getOperand(0).getReg() == NextMI->getOperand(1).getReg()) {
3204         secondRegMatch = true;
3205         maintainNewValueJump = true;
3206       }
3207
3208       if (!secondRegMatch &&
3209            I->getOperand(0).getReg() == NextMI->getOperand(0).getReg()) {
3210         maintainNewValueJump = true;
3211       }
3212
3213       for (std::vector<MachineInstr*>::iterator
3214             VI = CurrentPacketMIs.begin(),
3215              VE = CurrentPacketMIs.end();
3216            (VI != VE && maintainNewValueJump); ++VI) {
3217         SUnit* PacketSU = MIToSUnit[*VI];
3218
3219         // NVJ can not be part of the dual jump - Arch Spec: section 7.8
3220         if (PacketSU->getInstr()->getDesc().isCall()) {
3221           Dependence = true;
3222           break;
3223         }
3224         // Validate
3225         // 1. Packet does not have a store in it.
3226         // 2. If the first operand of the nvj is newified, and the second
3227         //    operand is also a reg, it (second reg) is not defined in
3228         //    the same packet.
3229         // 3. If the second operand of the nvj is newified, (which means
3230         //    first operand is also a reg), first reg is not defined in
3231         //    the same packet.
3232         if (PacketSU->getInstr()->getDesc().mayStore()               ||
3233             PacketSU->getInstr()->getOpcode() == Hexagon::ALLOCFRAME ||
3234             // Check #2.
3235             (!secondRegMatch && NextMI->getOperand(1).isReg() &&
3236              PacketSU->getInstr()->modifiesRegister(
3237                                NextMI->getOperand(1).getReg(), QRI)) ||
3238             // Check #3.
3239             (secondRegMatch &&
3240              PacketSU->getInstr()->modifiesRegister(
3241                                NextMI->getOperand(0).getReg(), QRI))) {
3242           Dependence = true;
3243           break;
3244         }
3245       }
3246       if (!Dependence)
3247         GlueToNewValueJump = true;
3248       else
3249         return false;
3250     }
3251   }
3252
3253   if (SUJ->isSucc(SUI)) {
3254     for (unsigned i = 0;
3255          (i < SUJ->Succs.size()) && !FoundSequentialDependence;
3256          ++i) {
3257
3258       if (SUJ->Succs[i].getSUnit() != SUI) {
3259         continue;
3260       }
3261
3262       SDep::Kind DepType = SUJ->Succs[i].getKind();
3263
3264       // For direct calls:
3265       // Ignore register dependences for call instructions for
3266       // packetization purposes except for those due to r31 and
3267       // predicate registers.
3268       //
3269       // For indirect calls:
3270       // Same as direct calls + check for true dependences to the register
3271       // used in the indirect call.
3272       //
3273       // We completely ignore Order dependences for call instructions
3274       //
3275       // For returns:
3276       // Ignore register dependences for return instructions like jumpr,
3277       // dealloc return unless we have dependencies on the explicit uses
3278       // of the registers used by jumpr (like r31) or dealloc return
3279       // (like r29 or r30).
3280       //
3281       // TODO: Currently, jumpr is handling only return of r31. So, the
3282       // following logic (specificaly IsCallDependent) is working fine.
3283       // We need to enable jumpr for register other than r31 and then,
3284       // we need to rework the last part, where it handles indirect call
3285       // of that (IsCallDependent) function. Bug 6216 is opened for this.
3286       //
3287       unsigned DepReg = 0;
3288       const TargetRegisterClass* RC = NULL;
3289       if (DepType == SDep::Data) {
3290         DepReg = SUJ->Succs[i].getReg();
3291         RC = QRI->getMinimalPhysRegClass(DepReg);
3292       }
3293       if ((MCIDI.isCall() || MCIDI.isReturn()) &&
3294           (!IsRegDependence(DepType) ||
3295             !IsCallDependent(I, DepType, SUJ->Succs[i].getReg()))) {
3296         /* do nothing */
3297       }
3298
3299       // For instructions that can be promoted to dot-new, try to promote.
3300       else if ((DepType == SDep::Data) &&
3301                CanPromoteToDotNew(I, SUJ, DepReg, MIToSUnit, II, RC) &&
3302                PromoteToDotNew(I, DepType, II, RC)) {
3303         PromotedToDotNew = true;
3304         /* do nothing */
3305       }
3306
3307       else if ((DepType == SDep::Data) &&
3308                (QII->isNewValueJump(I))) {
3309         /* do nothing */
3310       }
3311
3312       // For predicated instructions, if the predicates are complements
3313       // then there can be no dependence.
3314       else if (QII->isPredicated(I) &&
3315                QII->isPredicated(J) &&
3316           ArePredicatesComplements(I, J, MIToSUnit)) {
3317         /* do nothing */
3318
3319       }
3320       else if (IsDirectJump(I) &&
3321                !MCIDJ.isBranch() &&
3322                !MCIDJ.isCall() &&
3323                (DepType == SDep::Order)) {
3324         // Ignore Order dependences between unconditional direct branches
3325         // and non-control-flow instructions
3326         /* do nothing */
3327       }
3328       else if (MCIDI.isConditionalBranch() && (DepType != SDep::Data) &&
3329                (DepType != SDep::Output)) {
3330         // Ignore all dependences for jumps except for true and output
3331         // dependences
3332         /* do nothing */
3333       }
3334
3335       // Ignore output dependences due to superregs. We can
3336       // write to two different subregisters of R1:0 for instance
3337       // in the same cycle
3338       //
3339
3340       //
3341       // Let the
3342       // If neither I nor J defines DepReg, then this is a
3343       // superfluous output dependence. The dependence must be of the
3344       // form:
3345       //  R0 = ...
3346       //  R1 = ...
3347       // and there is an output dependence between the two instructions
3348       // with
3349       // DepReg = D0
3350       // We want to ignore these dependences.
3351       // Ideally, the dependence constructor should annotate such
3352       // dependences. We can then avoid this relatively expensive check.
3353       //
3354       else if (DepType == SDep::Output) {
3355         // DepReg is the register that's responsible for the dependence.
3356         unsigned DepReg = SUJ->Succs[i].getReg();
3357
3358         // Check if I and J really defines DepReg.
3359         if (I->definesRegister(DepReg) ||
3360             J->definesRegister(DepReg)) {
3361           FoundSequentialDependence = true;
3362           break;
3363         }
3364       }
3365
3366       // We ignore Order dependences for
3367       // 1. Two loads unless they are volatile.
3368       // 2. Two stores in V4 unless they are volatile.
3369       else if ((DepType == SDep::Order) &&
3370                !I->hasOrderedMemoryRef() &&
3371                !J->hasOrderedMemoryRef()) {
3372         if (QRI->Subtarget.hasV4TOps() &&
3373             // hexagonv4 allows dual store.
3374             MCIDI.mayStore() && MCIDJ.mayStore()) {
3375           /* do nothing */
3376         }
3377         // store followed by store-- not OK on V2
3378         // store followed by load -- not OK on all (OK if addresses
3379         // are not aliased)
3380         // load followed by store -- OK on all
3381         // load followed by load  -- OK on all
3382         else if ( !MCIDJ.mayStore()) {
3383           /* do nothing */
3384         }
3385         else {
3386           FoundSequentialDependence = true;
3387           break;
3388         }
3389       }
3390
3391       // For V4, special case ALLOCFRAME. Even though there is dependency
3392       // between ALLOCAFRAME and subsequent store, allow it to be
3393       // packetized in a same packet. This implies that the store is using
3394       // caller's SP. Hense, offset needs to be updated accordingly.
3395       else if (DepType == SDep::Data
3396                && QRI->Subtarget.hasV4TOps()
3397                && J->getOpcode() == Hexagon::ALLOCFRAME
3398                && (I->getOpcode() == Hexagon::STrid
3399                    || I->getOpcode() == Hexagon::STriw
3400                    || I->getOpcode() == Hexagon::STrib)
3401                && I->getOperand(0).getReg() == QRI->getStackRegister()
3402                && QII->isValidOffset(I->getOpcode(),
3403                                      I->getOperand(1).getImm() -
3404                                      (FrameSize + HEXAGON_LRFP_SIZE)))
3405       {
3406         GlueAllocframeStore = true;
3407         // Since this store is to be glued with allocframe in the same
3408         // packet, it will use SP of the previous stack frame, i.e
3409         // caller's SP. Therefore, we need to recalculate offset according
3410         // to this change.
3411         I->getOperand(1).setImm(I->getOperand(1).getImm() -
3412                                         (FrameSize + HEXAGON_LRFP_SIZE));
3413       }
3414
3415       //
3416       // Skip over anti-dependences. Two instructions that are
3417       // anti-dependent can share a packet
3418       //
3419       else if (DepType != SDep::Anti) {
3420         FoundSequentialDependence = true;
3421         break;
3422       }
3423     }
3424
3425     if (FoundSequentialDependence) {
3426       Dependence = true;
3427       return false;
3428     }
3429   }
3430
3431   return true;
3432 }
3433
3434 // isLegalToPruneDependencies
3435 bool HexagonPacketizerList::isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) {
3436   MachineInstr *I = SUI->getInstr();
3437   assert(I && SUJ->getInstr() && "Unable to packetize null instruction!");
3438
3439   const unsigned FrameSize = MF.getFrameInfo()->getStackSize();
3440
3441   if (Dependence) {
3442
3443     // Check if the instruction was promoted to a dot-new. If so, demote it
3444     // back into a dot-old.
3445     if (PromotedToDotNew) {
3446       DemoteToDotOld(I);
3447     }
3448
3449     // Check if the instruction (must be a store) was glued with an Allocframe
3450     // instruction. If so, restore its offset to its original value, i.e. use
3451     // curent SP instead of caller's SP.
3452     if (GlueAllocframeStore) {
3453       I->getOperand(1).setImm(I->getOperand(1).getImm() +
3454                                              FrameSize + HEXAGON_LRFP_SIZE);
3455     }
3456
3457     return false;
3458   }
3459   return true;
3460 }
3461
3462 MachineBasicBlock::iterator
3463 HexagonPacketizerList::addToPacket(MachineInstr *MI) {
3464
3465     MachineBasicBlock::iterator MII = MI;
3466     MachineBasicBlock *MBB = MI->getParent();
3467
3468     const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
3469
3470     if (GlueToNewValueJump) {
3471
3472       ++MII;
3473       MachineInstr *nvjMI = MII;
3474       assert(ResourceTracker->canReserveResources(MI));
3475       ResourceTracker->reserveResources(MI);
3476       if (QII->isExtended(MI) &&
3477           !tryAllocateResourcesForConstExt(MI)) {
3478         endPacket(MBB, MI);
3479         ResourceTracker->reserveResources(MI);
3480         assert(canReserveResourcesForConstExt(MI) &&
3481                "Ensure that there is a slot");
3482         reserveResourcesForConstExt(MI);
3483         // Reserve resources for new value jump constant extender.
3484         assert(canReserveResourcesForConstExt(MI) &&
3485                "Ensure that there is a slot");
3486         reserveResourcesForConstExt(nvjMI);
3487         assert(ResourceTracker->canReserveResources(nvjMI) &&
3488                "Ensure that there is a slot");
3489
3490       } else if (   // Extended instruction takes two slots in the packet.
3491         // Try reserve and allocate 4-byte in the current packet first.
3492         (QII->isExtended(nvjMI)
3493             && (!tryAllocateResourcesForConstExt(nvjMI)
3494                 || !ResourceTracker->canReserveResources(nvjMI)))
3495         || // For non-extended instruction, no need to allocate extra 4 bytes.
3496         (!QII->isExtended(nvjMI) && 
3497               !ResourceTracker->canReserveResources(nvjMI)))
3498       {
3499         endPacket(MBB, MI);
3500         // A new and empty packet starts.
3501         // We are sure that the resources requirements can be satisfied.
3502         // Therefore, do not need to call "canReserveResources" anymore.
3503         ResourceTracker->reserveResources(MI);
3504         if (QII->isExtended(nvjMI))
3505           reserveResourcesForConstExt(nvjMI);
3506       }
3507       // Here, we are sure that "reserveResources" would succeed.
3508       ResourceTracker->reserveResources(nvjMI);
3509       CurrentPacketMIs.push_back(MI);
3510       CurrentPacketMIs.push_back(nvjMI);
3511     } else {
3512       if (   QII->isExtended(MI)
3513           && (   !tryAllocateResourcesForConstExt(MI)
3514               || !ResourceTracker->canReserveResources(MI)))
3515       {
3516         endPacket(MBB, MI);
3517         // Check if the instruction was promoted to a dot-new. If so, demote it
3518         // back into a dot-old
3519         if (PromotedToDotNew) {
3520           DemoteToDotOld(MI);
3521         }
3522         reserveResourcesForConstExt(MI);
3523       }
3524       // In case that "MI" is not an extended insn,
3525       // the resource availability has already been checked.
3526       ResourceTracker->reserveResources(MI);
3527       CurrentPacketMIs.push_back(MI);
3528     }
3529     return MII;
3530 }
3531
3532 //===----------------------------------------------------------------------===//
3533 //                         Public Constructor Functions
3534 //===----------------------------------------------------------------------===//
3535
3536 FunctionPass *llvm::createHexagonPacketizer() {
3537   return new HexagonPacketizer();
3538 }
3539