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