1 //===----- HexagonPacketizer.cpp - vliw packetizer ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
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"
45 #include "HexagonTargetMachine.h"
46 #include "HexagonRegisterInfo.h"
47 #include "HexagonSubtarget.h"
48 #include "HexagonMachineFunctionInfo.h"
55 static cl::opt<bool> PacketizeVolatiles("hexagon-packetize-volatiles",
56 cl::ZeroOrMore, cl::Hidden, cl::init(true),
57 cl::desc("Allow non-solo packetization of volatile memory references"));
60 void initializeHexagonPacketizerPass(PassRegistry&);
65 class HexagonPacketizer : public MachineFunctionPass {
69 HexagonPacketizer() : MachineFunctionPass(ID) {
70 initializeHexagonPacketizerPass(*PassRegistry::getPassRegistry());
73 void getAnalysisUsage(AnalysisUsage &AU) const {
75 AU.addRequired<MachineDominatorTree>();
76 AU.addRequired<MachineBranchProbabilityInfo>();
77 AU.addPreserved<MachineDominatorTree>();
78 AU.addRequired<MachineLoopInfo>();
79 AU.addPreserved<MachineLoopInfo>();
80 MachineFunctionPass::getAnalysisUsage(AU);
83 const char *getPassName() const {
84 return "Hexagon Packetizer";
87 bool runOnMachineFunction(MachineFunction &Fn);
89 char HexagonPacketizer::ID = 0;
91 class HexagonPacketizerList : public VLIWPacketizerList {
95 // Has the instruction been promoted to a dot-new instruction.
96 bool PromotedToDotNew;
98 // Has the instruction been glued to allocframe.
99 bool GlueAllocframeStore;
101 // Has the feeder instruction been glued to new value jump.
102 bool GlueToNewValueJump;
104 // Check if there is a dependence between some instruction already in this
105 // packet and this instruction.
108 // Only check for dependence if there are resources available to
109 // schedule this instruction.
110 bool FoundSequentialDependence;
112 /// \brief A handle to the branch probability pass.
113 const MachineBranchProbabilityInfo *MBPI;
115 // Track MIs with ignored dependece.
116 std::vector<MachineInstr*> IgnoreDepMIs;
120 HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
121 MachineDominatorTree &MDT,
122 const MachineBranchProbabilityInfo *MBPI);
124 // initPacketizerState - initialize some internal flags.
125 void initPacketizerState();
127 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
128 bool ignorePseudoInstruction(MachineInstr *MI, MachineBasicBlock *MBB);
130 // isSoloInstruction - return true if instruction MI can not be packetized
131 // with any other instruction, which means that MI itself is a packet.
132 bool isSoloInstruction(MachineInstr *MI);
134 // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
136 bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ);
138 // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
140 bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ);
142 MachineBasicBlock::iterator addToPacket(MachineInstr *MI);
144 bool IsCallDependent(MachineInstr* MI, SDep::Kind DepType, unsigned DepReg);
145 bool PromoteToDotNew(MachineInstr* MI, SDep::Kind DepType,
146 MachineBasicBlock::iterator &MII,
147 const TargetRegisterClass* RC);
148 bool CanPromoteToDotNew(MachineInstr* MI, SUnit* PacketSU,
150 std::map <MachineInstr*, SUnit*> MIToSUnit,
151 MachineBasicBlock::iterator &MII,
152 const TargetRegisterClass* RC);
153 bool CanPromoteToNewValue(MachineInstr* MI, SUnit* PacketSU,
155 std::map <MachineInstr*, SUnit*> MIToSUnit,
156 MachineBasicBlock::iterator &MII);
157 bool CanPromoteToNewValueStore(MachineInstr* MI, MachineInstr* PacketMI,
159 std::map <MachineInstr*, SUnit*> MIToSUnit);
160 bool DemoteToDotOld(MachineInstr* MI);
161 bool ArePredicatesComplements(MachineInstr* MI1, MachineInstr* MI2,
162 std::map <MachineInstr*, SUnit*> MIToSUnit);
163 bool RestrictingDepExistInPacket(MachineInstr*,
164 unsigned, std::map <MachineInstr*, SUnit*>);
165 bool isNewifiable(MachineInstr* MI);
166 bool isCondInst(MachineInstr* MI);
167 bool IsNewifyStore (MachineInstr* MI);
168 bool tryAllocateResourcesForConstExt(MachineInstr* MI);
169 bool canReserveResourcesForConstExt(MachineInstr *MI);
170 void reserveResourcesForConstExt(MachineInstr* MI);
171 bool isNewValueInst(MachineInstr* MI);
175 INITIALIZE_PASS_BEGIN(HexagonPacketizer, "packets", "Hexagon Packetizer",
177 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
178 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
179 INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
180 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
181 INITIALIZE_PASS_END(HexagonPacketizer, "packets", "Hexagon Packetizer",
185 // HexagonPacketizerList Ctor.
186 HexagonPacketizerList::HexagonPacketizerList(
187 MachineFunction &MF, MachineLoopInfo &MLI,MachineDominatorTree &MDT,
188 const MachineBranchProbabilityInfo *MBPI)
189 : VLIWPacketizerList(MF, MLI, MDT, true){
193 bool HexagonPacketizer::runOnMachineFunction(MachineFunction &Fn) {
194 const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
195 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
196 MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
197 const MachineBranchProbabilityInfo *MBPI =
198 &getAnalysis<MachineBranchProbabilityInfo>();
199 // Instantiate the packetizer.
200 HexagonPacketizerList Packetizer(Fn, MLI, MDT, MBPI);
202 // DFA state table should not be empty.
203 assert(Packetizer.getResourceTracker() && "Empty DFA table!");
206 // Loop over all basic blocks and remove KILL pseudo-instructions
207 // These instructions confuse the dependence analysis. Consider:
209 // R0 = KILL R0, D0 (Insn 1)
211 // Here, Insn 1 will result in the dependence graph not emitting an output
212 // dependence between Insn 0 and Insn 2. This can lead to incorrect
215 for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
216 MBB != MBBe; ++MBB) {
217 MachineBasicBlock::iterator End = MBB->end();
218 MachineBasicBlock::iterator MI = MBB->begin();
221 MachineBasicBlock::iterator DeleteMI = MI;
223 MBB->erase(DeleteMI);
231 // Loop over all of the basic blocks.
232 for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
233 MBB != MBBe; ++MBB) {
234 // Find scheduling regions and schedule / packetize each region.
235 unsigned RemainingCount = MBB->size();
236 for(MachineBasicBlock::iterator RegionEnd = MBB->end();
237 RegionEnd != MBB->begin();) {
238 // The next region starts above the previous region. Look backward in the
239 // instruction stream until we find the nearest boundary.
240 MachineBasicBlock::iterator I = RegionEnd;
241 for(;I != MBB->begin(); --I, --RemainingCount) {
242 if (TII->isSchedulingBoundary(llvm::prior(I), MBB, Fn))
247 // Skip empty scheduling regions.
248 if (I == RegionEnd) {
249 RegionEnd = llvm::prior(RegionEnd);
253 // Skip regions with one instruction.
254 if (I == llvm::prior(RegionEnd)) {
255 RegionEnd = llvm::prior(RegionEnd);
259 Packetizer.PacketizeMIs(MBB, I, RegionEnd);
268 static bool IsIndirectCall(MachineInstr* MI) {
269 return ((MI->getOpcode() == Hexagon::CALLR) ||
270 (MI->getOpcode() == Hexagon::CALLRv3));
273 // Reserve resources for constant extender. Trigure an assertion if
275 void HexagonPacketizerList::reserveResourcesForConstExt(MachineInstr* MI) {
276 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
277 MachineFunction *MF = MI->getParent()->getParent();
278 MachineInstr *PseudoMI = MF->CreateMachineInstr(QII->get(Hexagon::IMMEXT_i),
281 if (ResourceTracker->canReserveResources(PseudoMI)) {
282 ResourceTracker->reserveResources(PseudoMI);
283 MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
285 MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
286 llvm_unreachable("can not reserve resources for constant extender.");
291 bool HexagonPacketizerList::canReserveResourcesForConstExt(MachineInstr *MI) {
292 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
293 assert((QII->isExtended(MI) || QII->isConstExtended(MI)) &&
294 "Should only be called for constant extended instructions");
295 MachineFunction *MF = MI->getParent()->getParent();
296 MachineInstr *PseudoMI = MF->CreateMachineInstr(QII->get(Hexagon::IMMEXT_i),
298 bool CanReserve = ResourceTracker->canReserveResources(PseudoMI);
299 MF->DeleteMachineInstr(PseudoMI);
303 // Allocate resources (i.e. 4 bytes) for constant extender. If succeed, return
304 // true, otherwise, return false.
305 bool HexagonPacketizerList::tryAllocateResourcesForConstExt(MachineInstr* MI) {
306 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
307 MachineFunction *MF = MI->getParent()->getParent();
308 MachineInstr *PseudoMI = MF->CreateMachineInstr(QII->get(Hexagon::IMMEXT_i),
311 if (ResourceTracker->canReserveResources(PseudoMI)) {
312 ResourceTracker->reserveResources(PseudoMI);
313 MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
316 MI->getParent()->getParent()->DeleteMachineInstr(PseudoMI);
322 bool HexagonPacketizerList::IsCallDependent(MachineInstr* MI,
326 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
327 const HexagonRegisterInfo* QRI =
328 (const HexagonRegisterInfo *) TM.getRegisterInfo();
330 // Check for lr dependence
331 if (DepReg == QRI->getRARegister()) {
335 if (QII->isDeallocRet(MI)) {
336 if (DepReg == QRI->getFrameRegister() ||
337 DepReg == QRI->getStackRegister())
341 // Check if this is a predicate dependence
342 const TargetRegisterClass* RC = QRI->getMinimalPhysRegClass(DepReg);
343 if (RC == &Hexagon::PredRegsRegClass) {
348 // Lastly check for an operand used in an indirect call
349 // If we had an attribute for checking if an instruction is an indirect call,
350 // then we could have avoided this relatively brittle implementation of
353 // Assumes that the first operand of the CALLr is the function address
355 if (IsIndirectCall(MI) && (DepType == SDep::Data)) {
356 MachineOperand MO = MI->getOperand(0);
357 if (MO.isReg() && MO.isUse() && (MO.getReg() == DepReg)) {
365 static bool IsRegDependence(const SDep::Kind DepType) {
366 return (DepType == SDep::Data || DepType == SDep::Anti ||
367 DepType == SDep::Output);
370 static bool IsDirectJump(MachineInstr* MI) {
371 return (MI->getOpcode() == Hexagon::JMP);
374 static bool IsSchedBarrier(MachineInstr* MI) {
375 switch (MI->getOpcode()) {
376 case Hexagon::BARRIER:
382 static bool IsControlFlow(MachineInstr* MI) {
383 return (MI->getDesc().isTerminator() || MI->getDesc().isCall());
386 // Function returns true if an instruction can be promoted to the new-value
387 // store. It will always return false for v2 and v3.
388 // It lists all the conditional and unconditional stores that can be promoted
389 // to the new-value stores.
391 bool HexagonPacketizerList::IsNewifyStore (MachineInstr* MI) {
392 const HexagonRegisterInfo* QRI =
393 (const HexagonRegisterInfo *) TM.getRegisterInfo();
394 switch (MI->getOpcode())
398 case Hexagon::STrib_indexed:
399 case Hexagon::STrib_indexed_shl_V4:
400 case Hexagon::STrib_shl_V4:
401 case Hexagon::STb_GP_V4:
402 case Hexagon::POST_STbri:
403 case Hexagon::STrib_cPt:
404 case Hexagon::STrib_cdnPt_V4:
405 case Hexagon::STrib_cNotPt:
406 case Hexagon::STrib_cdnNotPt_V4:
407 case Hexagon::STrib_indexed_cPt:
408 case Hexagon::STrib_indexed_cdnPt_V4:
409 case Hexagon::STrib_indexed_cNotPt:
410 case Hexagon::STrib_indexed_cdnNotPt_V4:
411 case Hexagon::STrib_indexed_shl_cPt_V4:
412 case Hexagon::STrib_indexed_shl_cdnPt_V4:
413 case Hexagon::STrib_indexed_shl_cNotPt_V4:
414 case Hexagon::STrib_indexed_shl_cdnNotPt_V4:
415 case Hexagon::POST_STbri_cPt:
416 case Hexagon::POST_STbri_cdnPt_V4:
417 case Hexagon::POST_STbri_cNotPt:
418 case Hexagon::POST_STbri_cdnNotPt_V4:
419 case Hexagon::STb_GP_cPt_V4:
420 case Hexagon::STb_GP_cNotPt_V4:
421 case Hexagon::STb_GP_cdnPt_V4:
422 case Hexagon::STb_GP_cdnNotPt_V4:
426 case Hexagon::STrih_indexed:
427 case Hexagon::STrih_indexed_shl_V4:
428 case Hexagon::STrih_shl_V4:
429 case Hexagon::STh_GP_V4:
430 case Hexagon::POST_SThri:
431 case Hexagon::STrih_cPt:
432 case Hexagon::STrih_cdnPt_V4:
433 case Hexagon::STrih_cNotPt:
434 case Hexagon::STrih_cdnNotPt_V4:
435 case Hexagon::STrih_indexed_cPt:
436 case Hexagon::STrih_indexed_cdnPt_V4:
437 case Hexagon::STrih_indexed_cNotPt:
438 case Hexagon::STrih_indexed_cdnNotPt_V4:
439 case Hexagon::STrih_indexed_shl_cPt_V4:
440 case Hexagon::STrih_indexed_shl_cdnPt_V4:
441 case Hexagon::STrih_indexed_shl_cNotPt_V4:
442 case Hexagon::STrih_indexed_shl_cdnNotPt_V4:
443 case Hexagon::POST_SThri_cPt:
444 case Hexagon::POST_SThri_cdnPt_V4:
445 case Hexagon::POST_SThri_cNotPt:
446 case Hexagon::POST_SThri_cdnNotPt_V4:
447 case Hexagon::STh_GP_cPt_V4:
448 case Hexagon::STh_GP_cNotPt_V4:
449 case Hexagon::STh_GP_cdnPt_V4:
450 case Hexagon::STh_GP_cdnNotPt_V4:
454 case Hexagon::STriw_indexed:
455 case Hexagon::STriw_indexed_shl_V4:
456 case Hexagon::STriw_shl_V4:
457 case Hexagon::STw_GP_V4:
458 case Hexagon::POST_STwri:
459 case Hexagon::STriw_cPt:
460 case Hexagon::STriw_cdnPt_V4:
461 case Hexagon::STriw_cNotPt:
462 case Hexagon::STriw_cdnNotPt_V4:
463 case Hexagon::STriw_indexed_cPt:
464 case Hexagon::STriw_indexed_cdnPt_V4:
465 case Hexagon::STriw_indexed_cNotPt:
466 case Hexagon::STriw_indexed_cdnNotPt_V4:
467 case Hexagon::STriw_indexed_shl_cPt_V4:
468 case Hexagon::STriw_indexed_shl_cdnPt_V4:
469 case Hexagon::STriw_indexed_shl_cNotPt_V4:
470 case Hexagon::STriw_indexed_shl_cdnNotPt_V4:
471 case Hexagon::POST_STwri_cPt:
472 case Hexagon::POST_STwri_cdnPt_V4:
473 case Hexagon::POST_STwri_cNotPt:
474 case Hexagon::POST_STwri_cdnNotPt_V4:
475 case Hexagon::STw_GP_cPt_V4:
476 case Hexagon::STw_GP_cNotPt_V4:
477 case Hexagon::STw_GP_cdnPt_V4:
478 case Hexagon::STw_GP_cdnNotPt_V4:
479 return QRI->Subtarget.hasV4TOps();
484 static bool IsLoopN(MachineInstr *MI) {
485 return (MI->getOpcode() == Hexagon::LOOP0_i ||
486 MI->getOpcode() == Hexagon::LOOP0_r);
489 /// DoesModifyCalleeSavedReg - Returns true if the instruction modifies a
490 /// callee-saved register.
491 static bool DoesModifyCalleeSavedReg(MachineInstr *MI,
492 const TargetRegisterInfo *TRI) {
493 for (const uint16_t *CSR = TRI->getCalleeSavedRegs(); *CSR; ++CSR) {
494 unsigned CalleeSavedReg = *CSR;
495 if (MI->modifiesRegister(CalleeSavedReg, TRI))
501 // Return the new value instruction for a given store.
502 static int GetDotNewOp(const int opc) {
504 default: llvm_unreachable("Unknown .new type");
505 // store new value byte
507 return Hexagon::STrib_nv_V4;
509 case Hexagon::STrib_indexed:
510 return Hexagon::STrib_indexed_nv_V4;
512 case Hexagon::STrib_indexed_shl_V4:
513 return Hexagon::STrib_indexed_shl_nv_V4;
515 case Hexagon::STrib_shl_V4:
516 return Hexagon::STrib_shl_nv_V4;
518 case Hexagon::STb_GP_V4:
519 return Hexagon::STb_GP_nv_V4;
521 case Hexagon::POST_STbri:
522 return Hexagon::POST_STbri_nv_V4;
524 case Hexagon::STrib_cPt:
525 return Hexagon::STrib_cPt_nv_V4;
527 case Hexagon::STrib_cdnPt_V4:
528 return Hexagon::STrib_cdnPt_nv_V4;
530 case Hexagon::STrib_cNotPt:
531 return Hexagon::STrib_cNotPt_nv_V4;
533 case Hexagon::STrib_cdnNotPt_V4:
534 return Hexagon::STrib_cdnNotPt_nv_V4;
536 case Hexagon::STrib_indexed_cPt:
537 return Hexagon::STrib_indexed_cPt_nv_V4;
539 case Hexagon::STrib_indexed_cdnPt_V4:
540 return Hexagon::STrib_indexed_cdnPt_nv_V4;
542 case Hexagon::STrib_indexed_cNotPt:
543 return Hexagon::STrib_indexed_cNotPt_nv_V4;
545 case Hexagon::STrib_indexed_cdnNotPt_V4:
546 return Hexagon::STrib_indexed_cdnNotPt_nv_V4;
548 case Hexagon::STrib_indexed_shl_cPt_V4:
549 return Hexagon::STrib_indexed_shl_cPt_nv_V4;
551 case Hexagon::STrib_indexed_shl_cdnPt_V4:
552 return Hexagon::STrib_indexed_shl_cdnPt_nv_V4;
554 case Hexagon::STrib_indexed_shl_cNotPt_V4:
555 return Hexagon::STrib_indexed_shl_cNotPt_nv_V4;
557 case Hexagon::STrib_indexed_shl_cdnNotPt_V4:
558 return Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4;
560 case Hexagon::POST_STbri_cPt:
561 return Hexagon::POST_STbri_cPt_nv_V4;
563 case Hexagon::POST_STbri_cdnPt_V4:
564 return Hexagon::POST_STbri_cdnPt_nv_V4;
566 case Hexagon::POST_STbri_cNotPt:
567 return Hexagon::POST_STbri_cNotPt_nv_V4;
569 case Hexagon::POST_STbri_cdnNotPt_V4:
570 return Hexagon::POST_STbri_cdnNotPt_nv_V4;
572 case Hexagon::STb_GP_cPt_V4:
573 return Hexagon::STb_GP_cPt_nv_V4;
575 case Hexagon::STb_GP_cNotPt_V4:
576 return Hexagon::STb_GP_cNotPt_nv_V4;
578 case Hexagon::STb_GP_cdnPt_V4:
579 return Hexagon::STb_GP_cdnPt_nv_V4;
581 case Hexagon::STb_GP_cdnNotPt_V4:
582 return Hexagon::STb_GP_cdnNotPt_nv_V4;
584 // store new value halfword
586 return Hexagon::STrih_nv_V4;
588 case Hexagon::STrih_indexed:
589 return Hexagon::STrih_indexed_nv_V4;
591 case Hexagon::STrih_indexed_shl_V4:
592 return Hexagon::STrih_indexed_shl_nv_V4;
594 case Hexagon::STrih_shl_V4:
595 return Hexagon::STrih_shl_nv_V4;
597 case Hexagon::STh_GP_V4:
598 return Hexagon::STh_GP_nv_V4;
600 case Hexagon::POST_SThri:
601 return Hexagon::POST_SThri_nv_V4;
603 case Hexagon::STrih_cPt:
604 return Hexagon::STrih_cPt_nv_V4;
606 case Hexagon::STrih_cdnPt_V4:
607 return Hexagon::STrih_cdnPt_nv_V4;
609 case Hexagon::STrih_cNotPt:
610 return Hexagon::STrih_cNotPt_nv_V4;
612 case Hexagon::STrih_cdnNotPt_V4:
613 return Hexagon::STrih_cdnNotPt_nv_V4;
615 case Hexagon::STrih_indexed_cPt:
616 return Hexagon::STrih_indexed_cPt_nv_V4;
618 case Hexagon::STrih_indexed_cdnPt_V4:
619 return Hexagon::STrih_indexed_cdnPt_nv_V4;
621 case Hexagon::STrih_indexed_cNotPt:
622 return Hexagon::STrih_indexed_cNotPt_nv_V4;
624 case Hexagon::STrih_indexed_cdnNotPt_V4:
625 return Hexagon::STrih_indexed_cdnNotPt_nv_V4;
627 case Hexagon::STrih_indexed_shl_cPt_V4:
628 return Hexagon::STrih_indexed_shl_cPt_nv_V4;
630 case Hexagon::STrih_indexed_shl_cdnPt_V4:
631 return Hexagon::STrih_indexed_shl_cdnPt_nv_V4;
633 case Hexagon::STrih_indexed_shl_cNotPt_V4:
634 return Hexagon::STrih_indexed_shl_cNotPt_nv_V4;
636 case Hexagon::STrih_indexed_shl_cdnNotPt_V4:
637 return Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4;
639 case Hexagon::POST_SThri_cPt:
640 return Hexagon::POST_SThri_cPt_nv_V4;
642 case Hexagon::POST_SThri_cdnPt_V4:
643 return Hexagon::POST_SThri_cdnPt_nv_V4;
645 case Hexagon::POST_SThri_cNotPt:
646 return Hexagon::POST_SThri_cNotPt_nv_V4;
648 case Hexagon::POST_SThri_cdnNotPt_V4:
649 return Hexagon::POST_SThri_cdnNotPt_nv_V4;
651 case Hexagon::STh_GP_cPt_V4:
652 return Hexagon::STh_GP_cPt_nv_V4;
654 case Hexagon::STh_GP_cNotPt_V4:
655 return Hexagon::STh_GP_cNotPt_nv_V4;
657 case Hexagon::STh_GP_cdnPt_V4:
658 return Hexagon::STh_GP_cdnPt_nv_V4;
660 case Hexagon::STh_GP_cdnNotPt_V4:
661 return Hexagon::STh_GP_cdnNotPt_nv_V4;
663 // store new value word
665 return Hexagon::STriw_nv_V4;
667 case Hexagon::STriw_indexed:
668 return Hexagon::STriw_indexed_nv_V4;
670 case Hexagon::STriw_indexed_shl_V4:
671 return Hexagon::STriw_indexed_shl_nv_V4;
673 case Hexagon::STriw_shl_V4:
674 return Hexagon::STriw_shl_nv_V4;
676 case Hexagon::STw_GP_V4:
677 return Hexagon::STw_GP_nv_V4;
679 case Hexagon::POST_STwri:
680 return Hexagon::POST_STwri_nv_V4;
682 case Hexagon::STriw_cPt:
683 return Hexagon::STriw_cPt_nv_V4;
685 case Hexagon::STriw_cdnPt_V4:
686 return Hexagon::STriw_cdnPt_nv_V4;
688 case Hexagon::STriw_cNotPt:
689 return Hexagon::STriw_cNotPt_nv_V4;
691 case Hexagon::STriw_cdnNotPt_V4:
692 return Hexagon::STriw_cdnNotPt_nv_V4;
694 case Hexagon::STriw_indexed_cPt:
695 return Hexagon::STriw_indexed_cPt_nv_V4;
697 case Hexagon::STriw_indexed_cdnPt_V4:
698 return Hexagon::STriw_indexed_cdnPt_nv_V4;
700 case Hexagon::STriw_indexed_cNotPt:
701 return Hexagon::STriw_indexed_cNotPt_nv_V4;
703 case Hexagon::STriw_indexed_cdnNotPt_V4:
704 return Hexagon::STriw_indexed_cdnNotPt_nv_V4;
706 case Hexagon::STriw_indexed_shl_cPt_V4:
707 return Hexagon::STriw_indexed_shl_cPt_nv_V4;
709 case Hexagon::STriw_indexed_shl_cdnPt_V4:
710 return Hexagon::STriw_indexed_shl_cdnPt_nv_V4;
712 case Hexagon::STriw_indexed_shl_cNotPt_V4:
713 return Hexagon::STriw_indexed_shl_cNotPt_nv_V4;
715 case Hexagon::STriw_indexed_shl_cdnNotPt_V4:
716 return Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4;
718 case Hexagon::POST_STwri_cPt:
719 return Hexagon::POST_STwri_cPt_nv_V4;
721 case Hexagon::POST_STwri_cdnPt_V4:
722 return Hexagon::POST_STwri_cdnPt_nv_V4;
724 case Hexagon::POST_STwri_cNotPt:
725 return Hexagon::POST_STwri_cNotPt_nv_V4;
727 case Hexagon::POST_STwri_cdnNotPt_V4:
728 return Hexagon::POST_STwri_cdnNotPt_nv_V4;
730 case Hexagon::STw_GP_cPt_V4:
731 return Hexagon::STw_GP_cPt_nv_V4;
733 case Hexagon::STw_GP_cNotPt_V4:
734 return Hexagon::STw_GP_cNotPt_nv_V4;
736 case Hexagon::STw_GP_cdnPt_V4:
737 return Hexagon::STw_GP_cdnPt_nv_V4;
739 case Hexagon::STw_GP_cdnNotPt_V4:
740 return Hexagon::STw_GP_cdnNotPt_nv_V4;
745 // Returns true if an instruction can be promoted to .new predicate
746 // or new-value store.
747 bool HexagonPacketizerList::isNewifiable(MachineInstr* MI) {
748 if ( isCondInst(MI) || IsNewifyStore(MI))
754 bool HexagonPacketizerList::isCondInst (MachineInstr* MI) {
755 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
756 const MCInstrDesc& TID = MI->getDesc();
757 // bug 5670: until that is fixed,
758 // this portion is disabled.
759 if ( TID.isConditionalBranch() // && !IsRegisterJump(MI)) ||
760 || QII->isConditionalTransfer(MI)
761 || QII->isConditionalALU32(MI)
762 || QII->isConditionalLoad(MI)
763 || QII->isConditionalStore(MI)) {
770 // Promote an instructiont to its .new form.
771 // At this time, we have already made a call to CanPromoteToDotNew
772 // and made sure that it can *indeed* be promoted.
773 bool HexagonPacketizerList::PromoteToDotNew(MachineInstr* MI,
774 SDep::Kind DepType, MachineBasicBlock::iterator &MII,
775 const TargetRegisterClass* RC) {
777 assert (DepType == SDep::Data);
778 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
781 if (RC == &Hexagon::PredRegsRegClass)
782 NewOpcode = QII->GetDotNewPredOp(MI, MBPI);
784 NewOpcode = GetDotNewOp(MI->getOpcode());
785 MI->setDesc(QII->get(NewOpcode));
790 // Returns the most basic instruction for the .new predicated instructions and
792 // For example, all of the following instructions will be converted back to the
794 // 1) if (p0.new) memw(R0+#0) = R1.new --->
795 // 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1
796 // 3) if (p0.new) memw(R0+#0) = R1 --->
798 // To understand the translation of instruction 1 to its original form, consider
799 // a packet with 3 instructions.
800 // { p0 = cmp.eq(R0,R1)
801 // if (p0.new) R2 = add(R3, R4)
804 // if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet
806 // This instruction can be part of the previous packet only if both p0 and R2
807 // are promoted to .new values. This promotion happens in steps, first
808 // predicate register is promoted to .new and in the next iteration R2 is
809 // promoted. Therefore, in case of dependence check failure (due to R5) during
810 // next iteration, it should be converted back to its most basic form.
812 static int GetDotOldOp(const int opc) {
814 default: llvm_unreachable("Unknown .old type");
815 case Hexagon::TFR_cdnPt:
816 return Hexagon::TFR_cPt;
818 case Hexagon::TFR_cdnNotPt:
819 return Hexagon::TFR_cNotPt;
821 case Hexagon::TFRI_cdnPt:
822 return Hexagon::TFRI_cPt;
824 case Hexagon::TFRI_cdnNotPt:
825 return Hexagon::TFRI_cNotPt;
827 case Hexagon::JMP_tnew_t:
828 return Hexagon::JMP_t;
830 case Hexagon::JMP_fnew_t:
831 return Hexagon::JMP_f;
833 case Hexagon::JMPR_tnew_tV3:
834 return Hexagon::JMPR_t;
836 case Hexagon::JMPR_fnew_tV3:
837 return Hexagon::JMPR_f;
841 case Hexagon::LDrid_cdnPt :
842 return Hexagon::LDrid_cPt;
844 case Hexagon::LDrid_cdnNotPt :
845 return Hexagon::LDrid_cNotPt;
847 case Hexagon::LDrid_indexed_cdnPt :
848 return Hexagon::LDrid_indexed_cPt;
850 case Hexagon::LDrid_indexed_cdnNotPt :
851 return Hexagon::LDrid_indexed_cNotPt;
853 case Hexagon::POST_LDrid_cdnPt_V4 :
854 return Hexagon::POST_LDrid_cPt;
856 case Hexagon::POST_LDrid_cdnNotPt_V4 :
857 return Hexagon::POST_LDrid_cNotPt;
861 case Hexagon::LDriw_cdnPt :
862 return Hexagon::LDriw_cPt;
864 case Hexagon::LDriw_cdnNotPt :
865 return Hexagon::LDriw_cNotPt;
867 case Hexagon::LDriw_indexed_cdnPt :
868 return Hexagon::LDriw_indexed_cPt;
870 case Hexagon::LDriw_indexed_cdnNotPt :
871 return Hexagon::LDriw_indexed_cNotPt;
873 case Hexagon::POST_LDriw_cdnPt_V4 :
874 return Hexagon::POST_LDriw_cPt;
876 case Hexagon::POST_LDriw_cdnNotPt_V4 :
877 return Hexagon::POST_LDriw_cNotPt;
881 case Hexagon::LDrih_cdnPt :
882 return Hexagon::LDrih_cPt;
884 case Hexagon::LDrih_cdnNotPt :
885 return Hexagon::LDrih_cNotPt;
887 case Hexagon::LDrih_indexed_cdnPt :
888 return Hexagon::LDrih_indexed_cPt;
890 case Hexagon::LDrih_indexed_cdnNotPt :
891 return Hexagon::LDrih_indexed_cNotPt;
893 case Hexagon::POST_LDrih_cdnPt_V4 :
894 return Hexagon::POST_LDrih_cPt;
896 case Hexagon::POST_LDrih_cdnNotPt_V4 :
897 return Hexagon::POST_LDrih_cNotPt;
901 case Hexagon::LDrib_cdnPt :
902 return Hexagon::LDrib_cPt;
904 case Hexagon::LDrib_cdnNotPt :
905 return Hexagon::LDrib_cNotPt;
907 case Hexagon::LDrib_indexed_cdnPt :
908 return Hexagon::LDrib_indexed_cPt;
910 case Hexagon::LDrib_indexed_cdnNotPt :
911 return Hexagon::LDrib_indexed_cNotPt;
913 case Hexagon::POST_LDrib_cdnPt_V4 :
914 return Hexagon::POST_LDrib_cPt;
916 case Hexagon::POST_LDrib_cdnNotPt_V4 :
917 return Hexagon::POST_LDrib_cNotPt;
919 // Load unsigned half
921 case Hexagon::LDriuh_cdnPt :
922 return Hexagon::LDriuh_cPt;
924 case Hexagon::LDriuh_cdnNotPt :
925 return Hexagon::LDriuh_cNotPt;
927 case Hexagon::LDriuh_indexed_cdnPt :
928 return Hexagon::LDriuh_indexed_cPt;
930 case Hexagon::LDriuh_indexed_cdnNotPt :
931 return Hexagon::LDriuh_indexed_cNotPt;
933 case Hexagon::POST_LDriuh_cdnPt_V4 :
934 return Hexagon::POST_LDriuh_cPt;
936 case Hexagon::POST_LDriuh_cdnNotPt_V4 :
937 return Hexagon::POST_LDriuh_cNotPt;
939 // Load unsigned byte
940 case Hexagon::LDriub_cdnPt :
941 return Hexagon::LDriub_cPt;
943 case Hexagon::LDriub_cdnNotPt :
944 return Hexagon::LDriub_cNotPt;
946 case Hexagon::LDriub_indexed_cdnPt :
947 return Hexagon::LDriub_indexed_cPt;
949 case Hexagon::LDriub_indexed_cdnNotPt :
950 return Hexagon::LDriub_indexed_cNotPt;
952 case Hexagon::POST_LDriub_cdnPt_V4 :
953 return Hexagon::POST_LDriub_cPt;
955 case Hexagon::POST_LDriub_cdnNotPt_V4 :
956 return Hexagon::POST_LDriub_cNotPt;
958 // V4 indexed+scaled Load
960 case Hexagon::LDrid_indexed_shl_cdnPt_V4 :
961 return Hexagon::LDrid_indexed_shl_cPt_V4;
963 case Hexagon::LDrid_indexed_shl_cdnNotPt_V4 :
964 return Hexagon::LDrid_indexed_shl_cNotPt_V4;
966 case Hexagon::LDrib_indexed_shl_cdnPt_V4 :
967 return Hexagon::LDrib_indexed_shl_cPt_V4;
969 case Hexagon::LDrib_indexed_shl_cdnNotPt_V4 :
970 return Hexagon::LDrib_indexed_shl_cNotPt_V4;
972 case Hexagon::LDriub_indexed_shl_cdnPt_V4 :
973 return Hexagon::LDriub_indexed_shl_cPt_V4;
975 case Hexagon::LDriub_indexed_shl_cdnNotPt_V4 :
976 return Hexagon::LDriub_indexed_shl_cNotPt_V4;
978 case Hexagon::LDrih_indexed_shl_cdnPt_V4 :
979 return Hexagon::LDrih_indexed_shl_cPt_V4;
981 case Hexagon::LDrih_indexed_shl_cdnNotPt_V4 :
982 return Hexagon::LDrih_indexed_shl_cNotPt_V4;
984 case Hexagon::LDriuh_indexed_shl_cdnPt_V4 :
985 return Hexagon::LDriuh_indexed_shl_cPt_V4;
987 case Hexagon::LDriuh_indexed_shl_cdnNotPt_V4 :
988 return Hexagon::LDriuh_indexed_shl_cNotPt_V4;
990 case Hexagon::LDriw_indexed_shl_cdnPt_V4 :
991 return Hexagon::LDriw_indexed_shl_cPt_V4;
993 case Hexagon::LDriw_indexed_shl_cdnNotPt_V4 :
994 return Hexagon::LDriw_indexed_shl_cNotPt_V4;
996 // V4 global address load
998 case Hexagon::LDd_GP_cdnPt_V4:
999 return Hexagon::LDd_GP_cPt_V4;
1001 case Hexagon::LDd_GP_cdnNotPt_V4:
1002 return Hexagon::LDd_GP_cNotPt_V4;
1004 case Hexagon::LDb_GP_cdnPt_V4:
1005 return Hexagon::LDb_GP_cPt_V4;
1007 case Hexagon::LDb_GP_cdnNotPt_V4:
1008 return Hexagon::LDb_GP_cNotPt_V4;
1010 case Hexagon::LDub_GP_cdnPt_V4:
1011 return Hexagon::LDub_GP_cPt_V4;
1013 case Hexagon::LDub_GP_cdnNotPt_V4:
1014 return Hexagon::LDub_GP_cNotPt_V4;
1016 case Hexagon::LDh_GP_cdnPt_V4:
1017 return Hexagon::LDh_GP_cPt_V4;
1019 case Hexagon::LDh_GP_cdnNotPt_V4:
1020 return Hexagon::LDh_GP_cNotPt_V4;
1022 case Hexagon::LDuh_GP_cdnPt_V4:
1023 return Hexagon::LDuh_GP_cPt_V4;
1025 case Hexagon::LDuh_GP_cdnNotPt_V4:
1026 return Hexagon::LDuh_GP_cNotPt_V4;
1028 case Hexagon::LDw_GP_cdnPt_V4:
1029 return Hexagon::LDw_GP_cPt_V4;
1031 case Hexagon::LDw_GP_cdnNotPt_V4:
1032 return Hexagon::LDw_GP_cNotPt_V4;
1036 case Hexagon::ADD_ri_cdnPt :
1037 return Hexagon::ADD_ri_cPt;
1038 case Hexagon::ADD_ri_cdnNotPt :
1039 return Hexagon::ADD_ri_cNotPt;
1041 case Hexagon::ADD_rr_cdnPt :
1042 return Hexagon::ADD_rr_cPt;
1043 case Hexagon::ADD_rr_cdnNotPt:
1044 return Hexagon::ADD_rr_cNotPt;
1046 // Conditional logical Operations
1048 case Hexagon::XOR_rr_cdnPt :
1049 return Hexagon::XOR_rr_cPt;
1050 case Hexagon::XOR_rr_cdnNotPt :
1051 return Hexagon::XOR_rr_cNotPt;
1053 case Hexagon::AND_rr_cdnPt :
1054 return Hexagon::AND_rr_cPt;
1055 case Hexagon::AND_rr_cdnNotPt :
1056 return Hexagon::AND_rr_cNotPt;
1058 case Hexagon::OR_rr_cdnPt :
1059 return Hexagon::OR_rr_cPt;
1060 case Hexagon::OR_rr_cdnNotPt :
1061 return Hexagon::OR_rr_cNotPt;
1063 // Conditional Subtract
1065 case Hexagon::SUB_rr_cdnPt :
1066 return Hexagon::SUB_rr_cPt;
1067 case Hexagon::SUB_rr_cdnNotPt :
1068 return Hexagon::SUB_rr_cNotPt;
1070 // Conditional combine
1072 case Hexagon::COMBINE_rr_cdnPt :
1073 return Hexagon::COMBINE_rr_cPt;
1074 case Hexagon::COMBINE_rr_cdnNotPt :
1075 return Hexagon::COMBINE_rr_cNotPt;
1077 // Conditional shift operations
1079 case Hexagon::ASLH_cdnPt_V4 :
1080 return Hexagon::ASLH_cPt_V4;
1081 case Hexagon::ASLH_cdnNotPt_V4 :
1082 return Hexagon::ASLH_cNotPt_V4;
1084 case Hexagon::ASRH_cdnPt_V4 :
1085 return Hexagon::ASRH_cPt_V4;
1086 case Hexagon::ASRH_cdnNotPt_V4 :
1087 return Hexagon::ASRH_cNotPt_V4;
1089 case Hexagon::SXTB_cdnPt_V4 :
1090 return Hexagon::SXTB_cPt_V4;
1091 case Hexagon::SXTB_cdnNotPt_V4 :
1092 return Hexagon::SXTB_cNotPt_V4;
1094 case Hexagon::SXTH_cdnPt_V4 :
1095 return Hexagon::SXTH_cPt_V4;
1096 case Hexagon::SXTH_cdnNotPt_V4 :
1097 return Hexagon::SXTH_cNotPt_V4;
1099 case Hexagon::ZXTB_cdnPt_V4 :
1100 return Hexagon::ZXTB_cPt_V4;
1101 case Hexagon::ZXTB_cdnNotPt_V4 :
1102 return Hexagon::ZXTB_cNotPt_V4;
1104 case Hexagon::ZXTH_cdnPt_V4 :
1105 return Hexagon::ZXTH_cPt_V4;
1106 case Hexagon::ZXTH_cdnNotPt_V4 :
1107 return Hexagon::ZXTH_cNotPt_V4;
1111 case Hexagon::STrib_imm_cdnPt_V4 :
1112 return Hexagon::STrib_imm_cPt_V4;
1114 case Hexagon::STrib_imm_cdnNotPt_V4 :
1115 return Hexagon::STrib_imm_cNotPt_V4;
1117 case Hexagon::STrib_cdnPt_nv_V4 :
1118 case Hexagon::STrib_cPt_nv_V4 :
1119 case Hexagon::STrib_cdnPt_V4 :
1120 return Hexagon::STrib_cPt;
1122 case Hexagon::STrib_cdnNotPt_nv_V4 :
1123 case Hexagon::STrib_cNotPt_nv_V4 :
1124 case Hexagon::STrib_cdnNotPt_V4 :
1125 return Hexagon::STrib_cNotPt;
1127 case Hexagon::STrib_indexed_cdnPt_V4 :
1128 case Hexagon::STrib_indexed_cPt_nv_V4 :
1129 case Hexagon::STrib_indexed_cdnPt_nv_V4 :
1130 return Hexagon::STrib_indexed_cPt;
1132 case Hexagon::STrib_indexed_cdnNotPt_V4 :
1133 case Hexagon::STrib_indexed_cNotPt_nv_V4 :
1134 case Hexagon::STrib_indexed_cdnNotPt_nv_V4 :
1135 return Hexagon::STrib_indexed_cNotPt;
1137 case Hexagon::STrib_indexed_shl_cdnPt_nv_V4:
1138 case Hexagon::STrib_indexed_shl_cPt_nv_V4 :
1139 case Hexagon::STrib_indexed_shl_cdnPt_V4 :
1140 return Hexagon::STrib_indexed_shl_cPt_V4;
1142 case Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4:
1143 case Hexagon::STrib_indexed_shl_cNotPt_nv_V4 :
1144 case Hexagon::STrib_indexed_shl_cdnNotPt_V4 :
1145 return Hexagon::STrib_indexed_shl_cNotPt_V4;
1147 case Hexagon::POST_STbri_cdnPt_nv_V4 :
1148 case Hexagon::POST_STbri_cPt_nv_V4 :
1149 case Hexagon::POST_STbri_cdnPt_V4 :
1150 return Hexagon::POST_STbri_cPt;
1152 case Hexagon::POST_STbri_cdnNotPt_nv_V4 :
1153 case Hexagon::POST_STbri_cNotPt_nv_V4:
1154 case Hexagon::POST_STbri_cdnNotPt_V4 :
1155 return Hexagon::POST_STbri_cNotPt;
1157 case Hexagon::STb_GP_cdnPt_nv_V4:
1158 case Hexagon::STb_GP_cdnPt_V4:
1159 case Hexagon::STb_GP_cPt_nv_V4:
1160 return Hexagon::STb_GP_cPt_V4;
1162 case Hexagon::STb_GP_cdnNotPt_nv_V4:
1163 case Hexagon::STb_GP_cdnNotPt_V4:
1164 case Hexagon::STb_GP_cNotPt_nv_V4:
1165 return Hexagon::STb_GP_cNotPt_V4;
1167 // Store new-value byte - unconditional
1168 case Hexagon::STrib_nv_V4:
1169 return Hexagon::STrib;
1171 case Hexagon::STrib_indexed_nv_V4:
1172 return Hexagon::STrib_indexed;
1174 case Hexagon::STrib_indexed_shl_nv_V4:
1175 return Hexagon::STrib_indexed_shl_V4;
1177 case Hexagon::STrib_shl_nv_V4:
1178 return Hexagon::STrib_shl_V4;
1180 case Hexagon::STb_GP_nv_V4:
1181 return Hexagon::STb_GP_V4;
1183 case Hexagon::POST_STbri_nv_V4:
1184 return Hexagon::POST_STbri;
1187 case Hexagon::STrih_imm_cdnPt_V4 :
1188 return Hexagon::STrih_imm_cPt_V4;
1190 case Hexagon::STrih_imm_cdnNotPt_V4 :
1191 return Hexagon::STrih_imm_cNotPt_V4;
1193 case Hexagon::STrih_cdnPt_nv_V4 :
1194 case Hexagon::STrih_cPt_nv_V4 :
1195 case Hexagon::STrih_cdnPt_V4 :
1196 return Hexagon::STrih_cPt;
1198 case Hexagon::STrih_cdnNotPt_nv_V4 :
1199 case Hexagon::STrih_cNotPt_nv_V4 :
1200 case Hexagon::STrih_cdnNotPt_V4 :
1201 return Hexagon::STrih_cNotPt;
1203 case Hexagon::STrih_indexed_cdnPt_nv_V4:
1204 case Hexagon::STrih_indexed_cPt_nv_V4 :
1205 case Hexagon::STrih_indexed_cdnPt_V4 :
1206 return Hexagon::STrih_indexed_cPt;
1208 case Hexagon::STrih_indexed_cdnNotPt_nv_V4:
1209 case Hexagon::STrih_indexed_cNotPt_nv_V4 :
1210 case Hexagon::STrih_indexed_cdnNotPt_V4 :
1211 return Hexagon::STrih_indexed_cNotPt;
1213 case Hexagon::STrih_indexed_shl_cdnPt_nv_V4 :
1214 case Hexagon::STrih_indexed_shl_cPt_nv_V4 :
1215 case Hexagon::STrih_indexed_shl_cdnPt_V4 :
1216 return Hexagon::STrih_indexed_shl_cPt_V4;
1218 case Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4 :
1219 case Hexagon::STrih_indexed_shl_cNotPt_nv_V4 :
1220 case Hexagon::STrih_indexed_shl_cdnNotPt_V4 :
1221 return Hexagon::STrih_indexed_shl_cNotPt_V4;
1223 case Hexagon::POST_SThri_cdnPt_nv_V4 :
1224 case Hexagon::POST_SThri_cPt_nv_V4 :
1225 case Hexagon::POST_SThri_cdnPt_V4 :
1226 return Hexagon::POST_SThri_cPt;
1228 case Hexagon::POST_SThri_cdnNotPt_nv_V4 :
1229 case Hexagon::POST_SThri_cNotPt_nv_V4 :
1230 case Hexagon::POST_SThri_cdnNotPt_V4 :
1231 return Hexagon::POST_SThri_cNotPt;
1233 case Hexagon::STh_GP_cdnPt_nv_V4:
1234 case Hexagon::STh_GP_cdnPt_V4:
1235 case Hexagon::STh_GP_cPt_nv_V4:
1236 return Hexagon::STh_GP_cPt_V4;
1238 case Hexagon::STh_GP_cdnNotPt_nv_V4:
1239 case Hexagon::STh_GP_cdnNotPt_V4:
1240 case Hexagon::STh_GP_cNotPt_nv_V4:
1241 return Hexagon::STh_GP_cNotPt_V4;
1243 // Store new-value halfword - unconditional
1245 case Hexagon::STrih_nv_V4:
1246 return Hexagon::STrih;
1248 case Hexagon::STrih_indexed_nv_V4:
1249 return Hexagon::STrih_indexed;
1251 case Hexagon::STrih_indexed_shl_nv_V4:
1252 return Hexagon::STrih_indexed_shl_V4;
1254 case Hexagon::STrih_shl_nv_V4:
1255 return Hexagon::STrih_shl_V4;
1257 case Hexagon::STh_GP_nv_V4:
1258 return Hexagon::STh_GP_V4;
1260 case Hexagon::POST_SThri_nv_V4:
1261 return Hexagon::POST_SThri;
1265 case Hexagon::STriw_imm_cdnPt_V4 :
1266 return Hexagon::STriw_imm_cPt_V4;
1268 case Hexagon::STriw_imm_cdnNotPt_V4 :
1269 return Hexagon::STriw_imm_cNotPt_V4;
1271 case Hexagon::STriw_cdnPt_nv_V4 :
1272 case Hexagon::STriw_cPt_nv_V4 :
1273 case Hexagon::STriw_cdnPt_V4 :
1274 return Hexagon::STriw_cPt;
1276 case Hexagon::STriw_cdnNotPt_nv_V4 :
1277 case Hexagon::STriw_cNotPt_nv_V4 :
1278 case Hexagon::STriw_cdnNotPt_V4 :
1279 return Hexagon::STriw_cNotPt;
1281 case Hexagon::STriw_indexed_cdnPt_nv_V4 :
1282 case Hexagon::STriw_indexed_cPt_nv_V4 :
1283 case Hexagon::STriw_indexed_cdnPt_V4 :
1284 return Hexagon::STriw_indexed_cPt;
1286 case Hexagon::STriw_indexed_cdnNotPt_nv_V4 :
1287 case Hexagon::STriw_indexed_cNotPt_nv_V4 :
1288 case Hexagon::STriw_indexed_cdnNotPt_V4 :
1289 return Hexagon::STriw_indexed_cNotPt;
1291 case Hexagon::STriw_indexed_shl_cdnPt_nv_V4 :
1292 case Hexagon::STriw_indexed_shl_cPt_nv_V4 :
1293 case Hexagon::STriw_indexed_shl_cdnPt_V4 :
1294 return Hexagon::STriw_indexed_shl_cPt_V4;
1296 case Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4 :
1297 case Hexagon::STriw_indexed_shl_cNotPt_nv_V4 :
1298 case Hexagon::STriw_indexed_shl_cdnNotPt_V4 :
1299 return Hexagon::STriw_indexed_shl_cNotPt_V4;
1301 case Hexagon::POST_STwri_cdnPt_nv_V4 :
1302 case Hexagon::POST_STwri_cPt_nv_V4 :
1303 case Hexagon::POST_STwri_cdnPt_V4 :
1304 return Hexagon::POST_STwri_cPt;
1306 case Hexagon::POST_STwri_cdnNotPt_nv_V4 :
1307 case Hexagon::POST_STwri_cNotPt_nv_V4 :
1308 case Hexagon::POST_STwri_cdnNotPt_V4 :
1309 return Hexagon::POST_STwri_cNotPt;
1311 case Hexagon::STw_GP_cdnPt_nv_V4:
1312 case Hexagon::STw_GP_cdnPt_V4:
1313 case Hexagon::STw_GP_cPt_nv_V4:
1314 return Hexagon::STw_GP_cPt_V4;
1316 case Hexagon::STw_GP_cdnNotPt_nv_V4:
1317 case Hexagon::STw_GP_cdnNotPt_V4:
1318 case Hexagon::STw_GP_cNotPt_nv_V4:
1319 return Hexagon::STw_GP_cNotPt_V4;
1321 // Store new-value word - unconditional
1323 case Hexagon::STriw_nv_V4:
1324 return Hexagon::STriw;
1326 case Hexagon::STriw_indexed_nv_V4:
1327 return Hexagon::STriw_indexed;
1329 case Hexagon::STriw_indexed_shl_nv_V4:
1330 return Hexagon::STriw_indexed_shl_V4;
1332 case Hexagon::STriw_shl_nv_V4:
1333 return Hexagon::STriw_shl_V4;
1335 case Hexagon::STw_GP_nv_V4:
1336 return Hexagon::STw_GP_V4;
1338 case Hexagon::POST_STwri_nv_V4:
1339 return Hexagon::POST_STwri;
1343 case Hexagon::STrid_cdnPt_V4 :
1344 return Hexagon::STrid_cPt;
1346 case Hexagon::STrid_cdnNotPt_V4 :
1347 return Hexagon::STrid_cNotPt;
1349 case Hexagon::STrid_indexed_cdnPt_V4 :
1350 return Hexagon::STrid_indexed_cPt;
1352 case Hexagon::STrid_indexed_cdnNotPt_V4 :
1353 return Hexagon::STrid_indexed_cNotPt;
1355 case Hexagon::STrid_indexed_shl_cdnPt_V4 :
1356 return Hexagon::STrid_indexed_shl_cPt_V4;
1358 case Hexagon::STrid_indexed_shl_cdnNotPt_V4 :
1359 return Hexagon::STrid_indexed_shl_cNotPt_V4;
1361 case Hexagon::POST_STdri_cdnPt_V4 :
1362 return Hexagon::POST_STdri_cPt;
1364 case Hexagon::POST_STdri_cdnNotPt_V4 :
1365 return Hexagon::POST_STdri_cNotPt;
1367 case Hexagon::STd_GP_cdnPt_V4 :
1368 return Hexagon::STd_GP_cPt_V4;
1370 case Hexagon::STd_GP_cdnNotPt_V4 :
1371 return Hexagon::STd_GP_cNotPt_V4;
1376 bool HexagonPacketizerList::DemoteToDotOld(MachineInstr* MI) {
1377 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
1378 int NewOpcode = GetDotOldOp(MI->getOpcode());
1379 MI->setDesc(QII->get(NewOpcode));
1383 // Returns true if an instruction is predicated on p0 and false if it's
1384 // predicated on !p0.
1386 static bool GetPredicateSense(MachineInstr* MI,
1387 const HexagonInstrInfo *QII) {
1389 switch (MI->getOpcode()) {
1390 default: llvm_unreachable("Unknown predicate sense of the instruction");
1391 case Hexagon::TFR_cPt:
1392 case Hexagon::TFR_cdnPt:
1393 case Hexagon::TFRI_cPt:
1394 case Hexagon::TFRI_cdnPt:
1395 case Hexagon::STrib_cPt :
1396 case Hexagon::STrib_cdnPt_V4 :
1397 case Hexagon::STrib_indexed_cPt :
1398 case Hexagon::STrib_indexed_cdnPt_V4 :
1399 case Hexagon::STrib_indexed_shl_cPt_V4 :
1400 case Hexagon::STrib_indexed_shl_cdnPt_V4 :
1401 case Hexagon::POST_STbri_cPt :
1402 case Hexagon::POST_STbri_cdnPt_V4 :
1403 case Hexagon::STrih_cPt :
1404 case Hexagon::STrih_cdnPt_V4 :
1405 case Hexagon::STrih_indexed_cPt :
1406 case Hexagon::STrih_indexed_cdnPt_V4 :
1407 case Hexagon::STrih_indexed_shl_cPt_V4 :
1408 case Hexagon::STrih_indexed_shl_cdnPt_V4 :
1409 case Hexagon::POST_SThri_cPt :
1410 case Hexagon::POST_SThri_cdnPt_V4 :
1411 case Hexagon::STriw_cPt :
1412 case Hexagon::STriw_cdnPt_V4 :
1413 case Hexagon::STriw_indexed_cPt :
1414 case Hexagon::STriw_indexed_cdnPt_V4 :
1415 case Hexagon::STriw_indexed_shl_cPt_V4 :
1416 case Hexagon::STriw_indexed_shl_cdnPt_V4 :
1417 case Hexagon::POST_STwri_cPt :
1418 case Hexagon::POST_STwri_cdnPt_V4 :
1419 case Hexagon::STrib_imm_cPt_V4 :
1420 case Hexagon::STrib_imm_cdnPt_V4 :
1421 case Hexagon::STrid_cPt :
1422 case Hexagon::STrid_cdnPt_V4 :
1423 case Hexagon::STrid_indexed_cPt :
1424 case Hexagon::STrid_indexed_cdnPt_V4 :
1425 case Hexagon::STrid_indexed_shl_cPt_V4 :
1426 case Hexagon::STrid_indexed_shl_cdnPt_V4 :
1427 case Hexagon::POST_STdri_cPt :
1428 case Hexagon::POST_STdri_cdnPt_V4 :
1429 case Hexagon::STrih_imm_cPt_V4 :
1430 case Hexagon::STrih_imm_cdnPt_V4 :
1431 case Hexagon::STriw_imm_cPt_V4 :
1432 case Hexagon::STriw_imm_cdnPt_V4 :
1433 case Hexagon::JMP_tnew_t :
1434 case Hexagon::LDrid_cPt :
1435 case Hexagon::LDrid_cdnPt :
1436 case Hexagon::LDrid_indexed_cPt :
1437 case Hexagon::LDrid_indexed_cdnPt :
1438 case Hexagon::POST_LDrid_cPt :
1439 case Hexagon::POST_LDrid_cdnPt_V4 :
1440 case Hexagon::LDriw_cPt :
1441 case Hexagon::LDriw_cdnPt :
1442 case Hexagon::LDriw_indexed_cPt :
1443 case Hexagon::LDriw_indexed_cdnPt :
1444 case Hexagon::POST_LDriw_cPt :
1445 case Hexagon::POST_LDriw_cdnPt_V4 :
1446 case Hexagon::LDrih_cPt :
1447 case Hexagon::LDrih_cdnPt :
1448 case Hexagon::LDrih_indexed_cPt :
1449 case Hexagon::LDrih_indexed_cdnPt :
1450 case Hexagon::POST_LDrih_cPt :
1451 case Hexagon::POST_LDrih_cdnPt_V4 :
1452 case Hexagon::LDrib_cPt :
1453 case Hexagon::LDrib_cdnPt :
1454 case Hexagon::LDrib_indexed_cPt :
1455 case Hexagon::LDrib_indexed_cdnPt :
1456 case Hexagon::POST_LDrib_cPt :
1457 case Hexagon::POST_LDrib_cdnPt_V4 :
1458 case Hexagon::LDriuh_cPt :
1459 case Hexagon::LDriuh_cdnPt :
1460 case Hexagon::LDriuh_indexed_cPt :
1461 case Hexagon::LDriuh_indexed_cdnPt :
1462 case Hexagon::POST_LDriuh_cPt :
1463 case Hexagon::POST_LDriuh_cdnPt_V4 :
1464 case Hexagon::LDriub_cPt :
1465 case Hexagon::LDriub_cdnPt :
1466 case Hexagon::LDriub_indexed_cPt :
1467 case Hexagon::LDriub_indexed_cdnPt :
1468 case Hexagon::POST_LDriub_cPt :
1469 case Hexagon::POST_LDriub_cdnPt_V4 :
1470 case Hexagon::LDrid_indexed_shl_cPt_V4 :
1471 case Hexagon::LDrid_indexed_shl_cdnPt_V4 :
1472 case Hexagon::LDrib_indexed_shl_cPt_V4 :
1473 case Hexagon::LDrib_indexed_shl_cdnPt_V4 :
1474 case Hexagon::LDriub_indexed_shl_cPt_V4 :
1475 case Hexagon::LDriub_indexed_shl_cdnPt_V4 :
1476 case Hexagon::LDrih_indexed_shl_cPt_V4 :
1477 case Hexagon::LDrih_indexed_shl_cdnPt_V4 :
1478 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
1479 case Hexagon::LDriuh_indexed_shl_cdnPt_V4 :
1480 case Hexagon::LDriw_indexed_shl_cPt_V4 :
1481 case Hexagon::LDriw_indexed_shl_cdnPt_V4 :
1482 case Hexagon::ADD_ri_cPt :
1483 case Hexagon::ADD_ri_cdnPt :
1484 case Hexagon::ADD_rr_cPt :
1485 case Hexagon::ADD_rr_cdnPt :
1486 case Hexagon::XOR_rr_cPt :
1487 case Hexagon::XOR_rr_cdnPt :
1488 case Hexagon::AND_rr_cPt :
1489 case Hexagon::AND_rr_cdnPt :
1490 case Hexagon::OR_rr_cPt :
1491 case Hexagon::OR_rr_cdnPt :
1492 case Hexagon::SUB_rr_cPt :
1493 case Hexagon::SUB_rr_cdnPt :
1494 case Hexagon::COMBINE_rr_cPt :
1495 case Hexagon::COMBINE_rr_cdnPt :
1496 case Hexagon::ASLH_cPt_V4 :
1497 case Hexagon::ASLH_cdnPt_V4 :
1498 case Hexagon::ASRH_cPt_V4 :
1499 case Hexagon::ASRH_cdnPt_V4 :
1500 case Hexagon::SXTB_cPt_V4 :
1501 case Hexagon::SXTB_cdnPt_V4 :
1502 case Hexagon::SXTH_cPt_V4 :
1503 case Hexagon::SXTH_cdnPt_V4 :
1504 case Hexagon::ZXTB_cPt_V4 :
1505 case Hexagon::ZXTB_cdnPt_V4 :
1506 case Hexagon::ZXTH_cPt_V4 :
1507 case Hexagon::ZXTH_cdnPt_V4 :
1508 case Hexagon::LDd_GP_cPt_V4 :
1509 case Hexagon::LDb_GP_cPt_V4 :
1510 case Hexagon::LDub_GP_cPt_V4 :
1511 case Hexagon::LDh_GP_cPt_V4 :
1512 case Hexagon::LDuh_GP_cPt_V4 :
1513 case Hexagon::LDw_GP_cPt_V4 :
1514 case Hexagon::STd_GP_cPt_V4 :
1515 case Hexagon::STb_GP_cPt_V4 :
1516 case Hexagon::STh_GP_cPt_V4 :
1517 case Hexagon::STw_GP_cPt_V4 :
1518 case Hexagon::LDd_GP_cdnPt_V4 :
1519 case Hexagon::LDb_GP_cdnPt_V4 :
1520 case Hexagon::LDub_GP_cdnPt_V4 :
1521 case Hexagon::LDh_GP_cdnPt_V4 :
1522 case Hexagon::LDuh_GP_cdnPt_V4 :
1523 case Hexagon::LDw_GP_cdnPt_V4 :
1524 case Hexagon::STd_GP_cdnPt_V4 :
1525 case Hexagon::STb_GP_cdnPt_V4 :
1526 case Hexagon::STh_GP_cdnPt_V4 :
1527 case Hexagon::STw_GP_cdnPt_V4 :
1530 case Hexagon::TFR_cNotPt:
1531 case Hexagon::TFR_cdnNotPt:
1532 case Hexagon::TFRI_cNotPt:
1533 case Hexagon::TFRI_cdnNotPt:
1534 case Hexagon::STrib_cNotPt :
1535 case Hexagon::STrib_cdnNotPt_V4 :
1536 case Hexagon::STrib_indexed_cNotPt :
1537 case Hexagon::STrib_indexed_cdnNotPt_V4 :
1538 case Hexagon::STrib_indexed_shl_cNotPt_V4 :
1539 case Hexagon::STrib_indexed_shl_cdnNotPt_V4 :
1540 case Hexagon::POST_STbri_cNotPt :
1541 case Hexagon::POST_STbri_cdnNotPt_V4 :
1542 case Hexagon::STrih_cNotPt :
1543 case Hexagon::STrih_cdnNotPt_V4 :
1544 case Hexagon::STrih_indexed_cNotPt :
1545 case Hexagon::STrih_indexed_cdnNotPt_V4 :
1546 case Hexagon::STrih_indexed_shl_cNotPt_V4 :
1547 case Hexagon::STrih_indexed_shl_cdnNotPt_V4 :
1548 case Hexagon::POST_SThri_cNotPt :
1549 case Hexagon::POST_SThri_cdnNotPt_V4 :
1550 case Hexagon::STriw_cNotPt :
1551 case Hexagon::STriw_cdnNotPt_V4 :
1552 case Hexagon::STriw_indexed_cNotPt :
1553 case Hexagon::STriw_indexed_cdnNotPt_V4 :
1554 case Hexagon::STriw_indexed_shl_cNotPt_V4 :
1555 case Hexagon::STriw_indexed_shl_cdnNotPt_V4 :
1556 case Hexagon::POST_STwri_cNotPt :
1557 case Hexagon::POST_STwri_cdnNotPt_V4 :
1558 case Hexagon::STrib_imm_cNotPt_V4 :
1559 case Hexagon::STrib_imm_cdnNotPt_V4 :
1560 case Hexagon::STrid_cNotPt :
1561 case Hexagon::STrid_cdnNotPt_V4 :
1562 case Hexagon::STrid_indexed_cdnNotPt_V4 :
1563 case Hexagon::STrid_indexed_cNotPt :
1564 case Hexagon::STrid_indexed_shl_cNotPt_V4 :
1565 case Hexagon::STrid_indexed_shl_cdnNotPt_V4 :
1566 case Hexagon::POST_STdri_cNotPt :
1567 case Hexagon::POST_STdri_cdnNotPt_V4 :
1568 case Hexagon::STrih_imm_cNotPt_V4 :
1569 case Hexagon::STrih_imm_cdnNotPt_V4 :
1570 case Hexagon::STriw_imm_cNotPt_V4 :
1571 case Hexagon::STriw_imm_cdnNotPt_V4 :
1572 case Hexagon::JMP_fnew_t :
1573 case Hexagon::LDrid_cNotPt :
1574 case Hexagon::LDrid_cdnNotPt :
1575 case Hexagon::LDrid_indexed_cNotPt :
1576 case Hexagon::LDrid_indexed_cdnNotPt :
1577 case Hexagon::POST_LDrid_cNotPt :
1578 case Hexagon::POST_LDrid_cdnNotPt_V4 :
1579 case Hexagon::LDriw_cNotPt :
1580 case Hexagon::LDriw_cdnNotPt :
1581 case Hexagon::LDriw_indexed_cNotPt :
1582 case Hexagon::LDriw_indexed_cdnNotPt :
1583 case Hexagon::POST_LDriw_cNotPt :
1584 case Hexagon::POST_LDriw_cdnNotPt_V4 :
1585 case Hexagon::LDrih_cNotPt :
1586 case Hexagon::LDrih_cdnNotPt :
1587 case Hexagon::LDrih_indexed_cNotPt :
1588 case Hexagon::LDrih_indexed_cdnNotPt :
1589 case Hexagon::POST_LDrih_cNotPt :
1590 case Hexagon::POST_LDrih_cdnNotPt_V4 :
1591 case Hexagon::LDrib_cNotPt :
1592 case Hexagon::LDrib_cdnNotPt :
1593 case Hexagon::LDrib_indexed_cNotPt :
1594 case Hexagon::LDrib_indexed_cdnNotPt :
1595 case Hexagon::POST_LDrib_cNotPt :
1596 case Hexagon::POST_LDrib_cdnNotPt_V4 :
1597 case Hexagon::LDriuh_cNotPt :
1598 case Hexagon::LDriuh_cdnNotPt :
1599 case Hexagon::LDriuh_indexed_cNotPt :
1600 case Hexagon::LDriuh_indexed_cdnNotPt :
1601 case Hexagon::POST_LDriuh_cNotPt :
1602 case Hexagon::POST_LDriuh_cdnNotPt_V4 :
1603 case Hexagon::LDriub_cNotPt :
1604 case Hexagon::LDriub_cdnNotPt :
1605 case Hexagon::LDriub_indexed_cNotPt :
1606 case Hexagon::LDriub_indexed_cdnNotPt :
1607 case Hexagon::POST_LDriub_cNotPt :
1608 case Hexagon::POST_LDriub_cdnNotPt_V4 :
1609 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
1610 case Hexagon::LDrid_indexed_shl_cdnNotPt_V4 :
1611 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
1612 case Hexagon::LDrib_indexed_shl_cdnNotPt_V4 :
1613 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
1614 case Hexagon::LDriub_indexed_shl_cdnNotPt_V4 :
1615 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
1616 case Hexagon::LDrih_indexed_shl_cdnNotPt_V4 :
1617 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
1618 case Hexagon::LDriuh_indexed_shl_cdnNotPt_V4 :
1619 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
1620 case Hexagon::LDriw_indexed_shl_cdnNotPt_V4 :
1621 case Hexagon::ADD_ri_cNotPt :
1622 case Hexagon::ADD_ri_cdnNotPt :
1623 case Hexagon::ADD_rr_cNotPt :
1624 case Hexagon::ADD_rr_cdnNotPt :
1625 case Hexagon::XOR_rr_cNotPt :
1626 case Hexagon::XOR_rr_cdnNotPt :
1627 case Hexagon::AND_rr_cNotPt :
1628 case Hexagon::AND_rr_cdnNotPt :
1629 case Hexagon::OR_rr_cNotPt :
1630 case Hexagon::OR_rr_cdnNotPt :
1631 case Hexagon::SUB_rr_cNotPt :
1632 case Hexagon::SUB_rr_cdnNotPt :
1633 case Hexagon::COMBINE_rr_cNotPt :
1634 case Hexagon::COMBINE_rr_cdnNotPt :
1635 case Hexagon::ASLH_cNotPt_V4 :
1636 case Hexagon::ASLH_cdnNotPt_V4 :
1637 case Hexagon::ASRH_cNotPt_V4 :
1638 case Hexagon::ASRH_cdnNotPt_V4 :
1639 case Hexagon::SXTB_cNotPt_V4 :
1640 case Hexagon::SXTB_cdnNotPt_V4 :
1641 case Hexagon::SXTH_cNotPt_V4 :
1642 case Hexagon::SXTH_cdnNotPt_V4 :
1643 case Hexagon::ZXTB_cNotPt_V4 :
1644 case Hexagon::ZXTB_cdnNotPt_V4 :
1645 case Hexagon::ZXTH_cNotPt_V4 :
1646 case Hexagon::ZXTH_cdnNotPt_V4 :
1648 case Hexagon::LDd_GP_cNotPt_V4 :
1649 case Hexagon::LDb_GP_cNotPt_V4 :
1650 case Hexagon::LDub_GP_cNotPt_V4 :
1651 case Hexagon::LDh_GP_cNotPt_V4 :
1652 case Hexagon::LDuh_GP_cNotPt_V4 :
1653 case Hexagon::LDw_GP_cNotPt_V4 :
1654 case Hexagon::STd_GP_cNotPt_V4 :
1655 case Hexagon::STb_GP_cNotPt_V4 :
1656 case Hexagon::STh_GP_cNotPt_V4 :
1657 case Hexagon::STw_GP_cNotPt_V4 :
1658 case Hexagon::LDd_GP_cdnNotPt_V4 :
1659 case Hexagon::LDb_GP_cdnNotPt_V4 :
1660 case Hexagon::LDub_GP_cdnNotPt_V4 :
1661 case Hexagon::LDh_GP_cdnNotPt_V4 :
1662 case Hexagon::LDuh_GP_cdnNotPt_V4 :
1663 case Hexagon::LDw_GP_cdnNotPt_V4 :
1664 case Hexagon::STd_GP_cdnNotPt_V4 :
1665 case Hexagon::STb_GP_cdnNotPt_V4 :
1666 case Hexagon::STh_GP_cdnNotPt_V4 :
1667 case Hexagon::STw_GP_cdnNotPt_V4 :
1670 // return *some value* to avoid compiler warning
1674 static MachineOperand& GetPostIncrementOperand(MachineInstr *MI,
1675 const HexagonInstrInfo *QII) {
1676 assert(QII->isPostIncrement(MI) && "Not a post increment operation.");
1678 // Post Increment means duplicates. Use dense map to find duplicates in the
1679 // list. Caution: Densemap initializes with the minimum of 64 buckets,
1680 // whereas there are at most 5 operands in the post increment.
1681 DenseMap<unsigned, unsigned> DefRegsSet;
1682 for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++)
1683 if (MI->getOperand(opNum).isReg() &&
1684 MI->getOperand(opNum).isDef()) {
1685 DefRegsSet[MI->getOperand(opNum).getReg()] = 1;
1688 for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++)
1689 if (MI->getOperand(opNum).isReg() &&
1690 MI->getOperand(opNum).isUse()) {
1691 if (DefRegsSet[MI->getOperand(opNum).getReg()]) {
1692 return MI->getOperand(opNum);
1696 if (MI->getDesc().mayLoad()) {
1697 // The 2nd operand is always the post increment operand in load.
1698 assert(MI->getOperand(1).isReg() &&
1699 "Post increment operand has be to a register.");
1700 return (MI->getOperand(1));
1702 if (MI->getDesc().mayStore()) {
1703 // The 1st operand is always the post increment operand in store.
1704 assert(MI->getOperand(0).isReg() &&
1705 "Post increment operand has be to a register.");
1706 return (MI->getOperand(0));
1709 // we should never come here.
1710 llvm_unreachable("mayLoad or mayStore not set for Post Increment operation");
1713 // get the value being stored
1714 static MachineOperand& GetStoreValueOperand(MachineInstr *MI) {
1715 // value being stored is always the last operand.
1716 return (MI->getOperand(MI->getNumOperands()-1));
1719 // can be new value store?
1720 // Following restrictions are to be respected in convert a store into
1721 // a new value store.
1722 // 1. If an instruction uses auto-increment, its address register cannot
1723 // be a new-value register. Arch Spec 5.4.2.1
1724 // 2. If an instruction uses absolute-set addressing mode,
1725 // its address register cannot be a new-value register.
1726 // Arch Spec 5.4.2.1.TODO: This is not enabled as
1727 // as absolute-set address mode patters are not implemented.
1728 // 3. If an instruction produces a 64-bit result, its registers cannot be used
1729 // as new-value registers. Arch Spec 5.4.2.2.
1730 // 4. If the instruction that sets a new-value register is conditional, then
1731 // the instruction that uses the new-value register must also be conditional,
1732 // and both must always have their predicates evaluate identically.
1733 // Arch Spec 5.4.2.3.
1734 // 5. There is an implied restriction of a packet can not have another store,
1735 // if there is a new value store in the packet. Corollary, if there is
1736 // already a store in a packet, there can not be a new value store.
1737 // Arch Spec: 3.4.4.2
1738 bool HexagonPacketizerList::CanPromoteToNewValueStore( MachineInstr *MI,
1739 MachineInstr *PacketMI, unsigned DepReg,
1740 std::map <MachineInstr*, SUnit*> MIToSUnit)
1742 // Make sure we are looking at the store
1743 if (!IsNewifyStore(MI))
1746 // Make sure there is dependency and can be new value'ed
1747 if (GetStoreValueOperand(MI).isReg() &&
1748 GetStoreValueOperand(MI).getReg() != DepReg)
1751 const HexagonRegisterInfo* QRI =
1752 (const HexagonRegisterInfo *) TM.getRegisterInfo();
1753 const MCInstrDesc& MCID = PacketMI->getDesc();
1754 // first operand is always the result
1756 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
1757 const TargetRegisterClass* PacketRC = QII->getRegClass(MCID, 0, QRI, MF);
1759 // if there is already an store in the packet, no can do new value store
1760 // Arch Spec 3.4.4.2.
1761 for (std::vector<MachineInstr*>::iterator VI = CurrentPacketMIs.begin(),
1762 VE = CurrentPacketMIs.end();
1764 SUnit* PacketSU = MIToSUnit[*VI];
1765 if (PacketSU->getInstr()->getDesc().mayStore() ||
1766 // if we have mayStore = 1 set on ALLOCFRAME and DEALLOCFRAME,
1767 // then we don't need this
1768 PacketSU->getInstr()->getOpcode() == Hexagon::ALLOCFRAME ||
1769 PacketSU->getInstr()->getOpcode() == Hexagon::DEALLOCFRAME)
1773 if (PacketRC == &Hexagon::DoubleRegsRegClass) {
1774 // new value store constraint: double regs can not feed into new value store
1775 // arch spec section: 5.4.2.2
1779 // Make sure it's NOT the post increment register that we are going to
1781 if (QII->isPostIncrement(MI) &&
1782 MI->getDesc().mayStore() &&
1783 GetPostIncrementOperand(MI, QII).getReg() == DepReg) {
1787 if (QII->isPostIncrement(PacketMI) &&
1788 PacketMI->getDesc().mayLoad() &&
1789 GetPostIncrementOperand(PacketMI, QII).getReg() == DepReg) {
1790 // if source is post_inc, or absolute-set addressing,
1791 // it can not feed into new value store
1792 // r3 = memw(r2++#4)
1793 // memw(r30 + #-1404) = r2.new -> can not be new value store
1794 // arch spec section: 5.4.2.1
1798 // If the source that feeds the store is predicated, new value store must
1799 // also be also predicated.
1800 if (QII->isPredicated(PacketMI)) {
1801 if (!QII->isPredicated(MI))
1804 // Check to make sure that they both will have their predicates
1805 // evaluate identically
1806 unsigned predRegNumSrc = 0;
1807 unsigned predRegNumDst = 0;
1808 const TargetRegisterClass* predRegClass = NULL;
1810 // Get predicate register used in the source instruction
1811 for(unsigned opNum = 0; opNum < PacketMI->getNumOperands(); opNum++) {
1812 if ( PacketMI->getOperand(opNum).isReg())
1813 predRegNumSrc = PacketMI->getOperand(opNum).getReg();
1814 predRegClass = QRI->getMinimalPhysRegClass(predRegNumSrc);
1815 if (predRegClass == &Hexagon::PredRegsRegClass) {
1819 assert ((predRegClass == &Hexagon::PredRegsRegClass ) &&
1820 ("predicate register not found in a predicated PacketMI instruction"));
1822 // Get predicate register used in new-value store instruction
1823 for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++) {
1824 if ( MI->getOperand(opNum).isReg())
1825 predRegNumDst = MI->getOperand(opNum).getReg();
1826 predRegClass = QRI->getMinimalPhysRegClass(predRegNumDst);
1827 if (predRegClass == &Hexagon::PredRegsRegClass) {
1831 assert ((predRegClass == &Hexagon::PredRegsRegClass ) &&
1832 ("predicate register not found in a predicated MI instruction"));
1834 // New-value register producer and user (store) need to satisfy these
1836 // 1) Both instructions should be predicated on the same register.
1837 // 2) If producer of the new-value register is .new predicated then store
1838 // should also be .new predicated and if producer is not .new predicated
1839 // then store should not be .new predicated.
1840 // 3) Both new-value register producer and user should have same predicate
1841 // sense, i.e, either both should be negated or both should be none negated.
1843 if (( predRegNumDst != predRegNumSrc) ||
1844 QII->isDotNewInst(PacketMI) != QII->isDotNewInst(MI) ||
1845 GetPredicateSense(MI, QII) != GetPredicateSense(PacketMI, QII)) {
1850 // Make sure that other than the new-value register no other store instruction
1851 // register has been modified in the same packet. Predicate registers can be
1852 // modified by they should not be modified between the producer and the store
1853 // instruction as it will make them both conditional on different values.
1854 // We already know this to be true for all the instructions before and
1855 // including PacketMI. Howerver, we need to perform the check for the
1856 // remaining instructions in the packet.
1858 std::vector<MachineInstr*>::iterator VI;
1859 std::vector<MachineInstr*>::iterator VE;
1860 unsigned StartCheck = 0;
1862 for (VI=CurrentPacketMIs.begin(), VE = CurrentPacketMIs.end();
1864 SUnit* TempSU = MIToSUnit[*VI];
1865 MachineInstr* TempMI = TempSU->getInstr();
1867 // Following condition is true for all the instructions until PacketMI is
1868 // reached (StartCheck is set to 0 before the for loop).
1869 // StartCheck flag is 1 for all the instructions after PacketMI.
1870 if (TempMI != PacketMI && !StartCheck) // start processing only after
1871 continue; // encountering PacketMI
1874 if (TempMI == PacketMI) // We don't want to check PacketMI for dependence
1877 for(unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++) {
1878 if (MI->getOperand(opNum).isReg() &&
1879 TempSU->getInstr()->modifiesRegister(MI->getOperand(opNum).getReg(),
1885 // Make sure that for non POST_INC stores:
1886 // 1. The only use of reg is DepReg and no other registers.
1887 // This handles V4 base+index registers.
1888 // The following store can not be dot new.
1889 // Eg. r0 = add(r0, #3)a
1890 // memw(r1+r0<<#2) = r0
1891 if (!QII->isPostIncrement(MI) &&
1892 GetStoreValueOperand(MI).isReg() &&
1893 GetStoreValueOperand(MI).getReg() == DepReg) {
1894 for(unsigned opNum = 0; opNum < MI->getNumOperands()-1; opNum++) {
1895 if (MI->getOperand(opNum).isReg() &&
1896 MI->getOperand(opNum).getReg() == DepReg) {
1900 // 2. If data definition is because of implicit definition of the register,
1901 // do not newify the store. Eg.
1902 // %R9<def> = ZXTH %R12, %D6<imp-use>, %R12<imp-def>
1903 // STrih_indexed %R8, 2, %R12<kill>; mem:ST2[%scevgep343]
1904 for(unsigned opNum = 0; opNum < PacketMI->getNumOperands(); opNum++) {
1905 if (PacketMI->getOperand(opNum).isReg() &&
1906 PacketMI->getOperand(opNum).getReg() == DepReg &&
1907 PacketMI->getOperand(opNum).isDef() &&
1908 PacketMI->getOperand(opNum).isImplicit()) {
1914 // Can be dot new store.
1918 // can this MI to promoted to either
1919 // new value store or new value jump
1920 bool HexagonPacketizerList::CanPromoteToNewValue( MachineInstr *MI,
1921 SUnit *PacketSU, unsigned DepReg,
1922 std::map <MachineInstr*, SUnit*> MIToSUnit,
1923 MachineBasicBlock::iterator &MII)
1926 const HexagonRegisterInfo* QRI =
1927 (const HexagonRegisterInfo *) TM.getRegisterInfo();
1928 if (!QRI->Subtarget.hasV4TOps() ||
1932 MachineInstr *PacketMI = PacketSU->getInstr();
1934 // Check to see the store can be new value'ed.
1935 if (CanPromoteToNewValueStore(MI, PacketMI, DepReg, MIToSUnit))
1938 // Check to see the compare/jump can be new value'ed.
1939 // This is done as a pass on its own. Don't need to check it here.
1943 // Check to see if an instruction can be dot new
1944 // There are three kinds.
1945 // 1. dot new on predicate - V2/V3/V4
1946 // 2. dot new on stores NV/ST - V4
1947 // 3. dot new on jump NV/J - V4 -- This is generated in a pass.
1948 bool HexagonPacketizerList::CanPromoteToDotNew( MachineInstr *MI,
1949 SUnit *PacketSU, unsigned DepReg,
1950 std::map <MachineInstr*, SUnit*> MIToSUnit,
1951 MachineBasicBlock::iterator &MII,
1952 const TargetRegisterClass* RC )
1954 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
1955 // Already a dot new instruction.
1956 if (QII->isDotNewInst(MI) && !IsNewifyStore(MI))
1959 if (!isNewifiable(MI))
1963 if (RC == &Hexagon::PredRegsRegClass && isCondInst(MI))
1965 else if (RC != &Hexagon::PredRegsRegClass &&
1966 !IsNewifyStore(MI)) // MI is not a new-value store
1969 // Create a dot new machine instruction to see if resources can be
1970 // allocated. If not, bail out now.
1971 int NewOpcode = GetDotNewOp(MI->getOpcode());
1972 const MCInstrDesc &desc = QII->get(NewOpcode);
1974 MachineInstr *NewMI =
1975 MI->getParent()->getParent()->CreateMachineInstr(desc, dl);
1976 bool ResourcesAvailable = ResourceTracker->canReserveResources(NewMI);
1977 MI->getParent()->getParent()->DeleteMachineInstr(NewMI);
1979 if (!ResourcesAvailable)
1982 // new value store only
1983 // new new value jump generated as a passes
1984 if (!CanPromoteToNewValue(MI, PacketSU, DepReg, MIToSUnit, MII)) {
1991 // Go through the packet instructions and search for anti dependency
1992 // between them and DepReg from MI
1993 // Consider this case:
1995 // a) %R1<def> = TFRI_cdNotPt %P3, 2
1998 // b) %P0<def> = OR_pp %P3<kill>, %P0<kill>
1999 // c) %P3<def> = TFR_PdRs %R23
2000 // d) %R1<def> = TFRI_cdnPt %P3, 4
2002 // The P3 from a) and d) will be complements after
2003 // a)'s P3 is converted to .new form
2004 // Anti Dep between c) and b) is irrelevant for this case
2005 bool HexagonPacketizerList::RestrictingDepExistInPacket (MachineInstr* MI,
2007 std::map <MachineInstr*, SUnit*> MIToSUnit) {
2009 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2010 SUnit* PacketSUDep = MIToSUnit[MI];
2012 for (std::vector<MachineInstr*>::iterator VIN = CurrentPacketMIs.begin(),
2013 VEN = CurrentPacketMIs.end(); (VIN != VEN); ++VIN) {
2015 // We only care for dependencies to predicated instructions
2016 if(!QII->isPredicated(*VIN)) continue;
2018 // Scheduling Unit for current insn in the packet
2019 SUnit* PacketSU = MIToSUnit[*VIN];
2021 // Look at dependencies between current members of the packet
2022 // and predicate defining instruction MI.
2023 // Make sure that dependency is on the exact register
2025 if (PacketSU->isSucc(PacketSUDep)) {
2026 for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
2027 if ((PacketSU->Succs[i].getSUnit() == PacketSUDep) &&
2028 (PacketSU->Succs[i].getKind() == SDep::Anti) &&
2029 (PacketSU->Succs[i].getReg() == DepReg)) {
2040 // Given two predicated instructions, this function detects whether
2041 // the predicates are complements
2042 bool HexagonPacketizerList::ArePredicatesComplements (MachineInstr* MI1,
2043 MachineInstr* MI2, std::map <MachineInstr*, SUnit*> MIToSUnit) {
2045 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2046 // Currently can only reason about conditional transfers
2047 if (!QII->isConditionalTransfer(MI1) || !QII->isConditionalTransfer(MI2)) {
2051 // Scheduling unit for candidate
2052 SUnit* SU = MIToSUnit[MI1];
2054 // One corner case deals with the following scenario:
2056 // a) %R24<def> = TFR_cPt %P0, %R25
2060 // b) %R25<def> = TFR_cNotPt %P0, %R24
2061 // c) %P0<def> = CMPEQri %R26, 1
2064 // On general check a) and b) are complements, but
2065 // presence of c) will convert a) to .new form, and
2066 // then it is not a complement
2067 // We attempt to detect it by analyzing existing
2068 // dependencies in the packet
2070 // Analyze relationships between all existing members of the packet.
2071 // Look for Anti dependecy on the same predicate reg
2072 // as used in the candidate
2073 for (std::vector<MachineInstr*>::iterator VIN = CurrentPacketMIs.begin(),
2074 VEN = CurrentPacketMIs.end(); (VIN != VEN); ++VIN) {
2076 // Scheduling Unit for current insn in the packet
2077 SUnit* PacketSU = MIToSUnit[*VIN];
2079 // If this instruction in the packet is succeeded by the candidate...
2080 if (PacketSU->isSucc(SU)) {
2081 for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
2082 // The corner case exist when there is true data
2083 // dependency between candidate and one of current
2084 // packet members, this dep is on predicate reg, and
2085 // there already exist anti dep on the same pred in
2087 if (PacketSU->Succs[i].getSUnit() == SU &&
2088 Hexagon::PredRegsRegClass.contains(
2089 PacketSU->Succs[i].getReg()) &&
2090 PacketSU->Succs[i].getKind() == SDep::Data &&
2091 // Here I know that *VIN is predicate setting instruction
2092 // with true data dep to candidate on the register
2093 // we care about - c) in the above example.
2094 // Now I need to see if there is an anti dependency
2095 // from c) to any other instruction in the
2096 // same packet on the pred reg of interest
2097 RestrictingDepExistInPacket(*VIN,PacketSU->Succs[i].getReg(),
2105 // If the above case does not apply, check regular
2106 // complement condition.
2107 // Check that the predicate register is the same and
2108 // that the predicate sense is different
2109 // We also need to differentiate .old vs. .new:
2110 // !p0 is not complimentary to p0.new
2111 return ((MI1->getOperand(1).getReg() == MI2->getOperand(1).getReg()) &&
2112 (GetPredicateSense(MI1, QII) != GetPredicateSense(MI2, QII)) &&
2113 (QII->isDotNewInst(MI1) == QII->isDotNewInst(MI2)));
2116 // initPacketizerState - Initialize packetizer flags
2117 void HexagonPacketizerList::initPacketizerState() {
2120 PromotedToDotNew = false;
2121 GlueToNewValueJump = false;
2122 GlueAllocframeStore = false;
2123 FoundSequentialDependence = false;
2128 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
2129 bool HexagonPacketizerList::ignorePseudoInstruction(MachineInstr *MI,
2130 MachineBasicBlock *MBB) {
2131 if (MI->isDebugValue())
2134 // We must print out inline assembly
2135 if (MI->isInlineAsm())
2138 // We check if MI has any functional units mapped to it.
2139 // If it doesn't, we ignore the instruction.
2140 const MCInstrDesc& TID = MI->getDesc();
2141 unsigned SchedClass = TID.getSchedClass();
2142 const InstrStage* IS =
2143 ResourceTracker->getInstrItins()->beginStage(SchedClass);
2144 unsigned FuncUnits = IS->getUnits();
2148 // isSoloInstruction: - Returns true for instructions that must be
2149 // scheduled in their own packet.
2150 bool HexagonPacketizerList::isSoloInstruction(MachineInstr *MI) {
2152 if (MI->isInlineAsm())
2155 if (MI->isEHLabel())
2158 // From Hexagon V4 Programmer's Reference Manual 3.4.4 Grouping constraints:
2159 // trap, pause, barrier, icinva, isync, and syncht are solo instructions.
2160 // They must not be grouped with other instructions in a packet.
2161 if (IsSchedBarrier(MI))
2167 // isLegalToPacketizeTogether:
2168 // SUI is the current instruction that is out side of the current packet.
2169 // SUJ is the current instruction inside the current packet against which that
2170 // SUI will be packetized.
2171 bool HexagonPacketizerList::isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) {
2172 MachineInstr *I = SUI->getInstr();
2173 MachineInstr *J = SUJ->getInstr();
2174 assert(I && J && "Unable to packetize null instruction!");
2176 const MCInstrDesc &MCIDI = I->getDesc();
2177 const MCInstrDesc &MCIDJ = J->getDesc();
2179 MachineBasicBlock::iterator II = I;
2181 const unsigned FrameSize = MF.getFrameInfo()->getStackSize();
2182 const HexagonRegisterInfo* QRI =
2183 (const HexagonRegisterInfo *) TM.getRegisterInfo();
2184 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2186 // Inline asm cannot go in the packet.
2187 if (I->getOpcode() == Hexagon::INLINEASM)
2188 llvm_unreachable("Should not meet inline asm here!");
2190 if (isSoloInstruction(I))
2191 llvm_unreachable("Should not meet solo instr here!");
2193 // A save callee-save register function call can only be in a packet
2194 // with instructions that don't write to the callee-save registers.
2195 if ((QII->isSaveCalleeSavedRegsCall(I) &&
2196 DoesModifyCalleeSavedReg(J, QRI)) ||
2197 (QII->isSaveCalleeSavedRegsCall(J) &&
2198 DoesModifyCalleeSavedReg(I, QRI))) {
2203 // Two control flow instructions cannot go in the same packet.
2204 if (IsControlFlow(I) && IsControlFlow(J)) {
2209 // A LoopN instruction cannot appear in the same packet as a jump or call.
2210 if (IsLoopN(I) && ( IsDirectJump(J)
2212 || QII->isDeallocRet(J))) {
2216 if (IsLoopN(J) && ( IsDirectJump(I)
2218 || QII->isDeallocRet(I))) {
2223 // dealloc_return cannot appear in the same packet as a conditional or
2224 // unconditional jump.
2225 if (QII->isDeallocRet(I) && ( MCIDJ.isBranch()
2227 || MCIDJ.isBarrier())) {
2233 // V4 allows dual store. But does not allow second store, if the
2234 // first store is not in SLOT0. New value store, new value jump,
2235 // dealloc_return and memop always take SLOT0.
2236 // Arch spec 3.4.4.2
2237 if (QRI->Subtarget.hasV4TOps()) {
2238 if (MCIDI.mayStore() && MCIDJ.mayStore() &&
2239 (QII->isNewValueInst(J) || QII->isMemOp(J) || QII->isMemOp(I))) {
2244 if ((QII->isMemOp(J) && MCIDI.mayStore())
2245 || (MCIDJ.mayStore() && QII->isMemOp(I))
2246 || (QII->isMemOp(J) && QII->isMemOp(I))) {
2252 if (MCIDJ.mayStore() && QII->isDeallocRet(I)){
2257 // If an instruction feeds new value jump, glue it.
2258 MachineBasicBlock::iterator NextMII = I;
2260 if (NextMII != I->getParent()->end() && QII->isNewValueJump(NextMII)) {
2261 MachineInstr *NextMI = NextMII;
2263 bool secondRegMatch = false;
2264 bool maintainNewValueJump = false;
2266 if (NextMI->getOperand(1).isReg() &&
2267 I->getOperand(0).getReg() == NextMI->getOperand(1).getReg()) {
2268 secondRegMatch = true;
2269 maintainNewValueJump = true;
2272 if (!secondRegMatch &&
2273 I->getOperand(0).getReg() == NextMI->getOperand(0).getReg()) {
2274 maintainNewValueJump = true;
2277 for (std::vector<MachineInstr*>::iterator
2278 VI = CurrentPacketMIs.begin(),
2279 VE = CurrentPacketMIs.end();
2280 (VI != VE && maintainNewValueJump); ++VI) {
2281 SUnit* PacketSU = MIToSUnit[*VI];
2283 // NVJ can not be part of the dual jump - Arch Spec: section 7.8
2284 if (PacketSU->getInstr()->getDesc().isCall()) {
2289 // 1. Packet does not have a store in it.
2290 // 2. If the first operand of the nvj is newified, and the second
2291 // operand is also a reg, it (second reg) is not defined in
2293 // 3. If the second operand of the nvj is newified, (which means
2294 // first operand is also a reg), first reg is not defined in
2296 if (PacketSU->getInstr()->getDesc().mayStore() ||
2297 PacketSU->getInstr()->getOpcode() == Hexagon::ALLOCFRAME ||
2299 (!secondRegMatch && NextMI->getOperand(1).isReg() &&
2300 PacketSU->getInstr()->modifiesRegister(
2301 NextMI->getOperand(1).getReg(), QRI)) ||
2304 PacketSU->getInstr()->modifiesRegister(
2305 NextMI->getOperand(0).getReg(), QRI))) {
2311 GlueToNewValueJump = true;
2317 if (SUJ->isSucc(SUI)) {
2318 for (unsigned i = 0;
2319 (i < SUJ->Succs.size()) && !FoundSequentialDependence;
2322 if (SUJ->Succs[i].getSUnit() != SUI) {
2326 SDep::Kind DepType = SUJ->Succs[i].getKind();
2328 // For direct calls:
2329 // Ignore register dependences for call instructions for
2330 // packetization purposes except for those due to r31 and
2331 // predicate registers.
2333 // For indirect calls:
2334 // Same as direct calls + check for true dependences to the register
2335 // used in the indirect call.
2337 // We completely ignore Order dependences for call instructions
2340 // Ignore register dependences for return instructions like jumpr,
2341 // dealloc return unless we have dependencies on the explicit uses
2342 // of the registers used by jumpr (like r31) or dealloc return
2343 // (like r29 or r30).
2345 // TODO: Currently, jumpr is handling only return of r31. So, the
2346 // following logic (specificaly IsCallDependent) is working fine.
2347 // We need to enable jumpr for register other than r31 and then,
2348 // we need to rework the last part, where it handles indirect call
2349 // of that (IsCallDependent) function. Bug 6216 is opened for this.
2351 unsigned DepReg = 0;
2352 const TargetRegisterClass* RC = NULL;
2353 if (DepType == SDep::Data) {
2354 DepReg = SUJ->Succs[i].getReg();
2355 RC = QRI->getMinimalPhysRegClass(DepReg);
2357 if ((MCIDI.isCall() || MCIDI.isReturn()) &&
2358 (!IsRegDependence(DepType) ||
2359 !IsCallDependent(I, DepType, SUJ->Succs[i].getReg()))) {
2363 // For instructions that can be promoted to dot-new, try to promote.
2364 else if ((DepType == SDep::Data) &&
2365 CanPromoteToDotNew(I, SUJ, DepReg, MIToSUnit, II, RC) &&
2366 PromoteToDotNew(I, DepType, II, RC)) {
2367 PromotedToDotNew = true;
2371 else if ((DepType == SDep::Data) &&
2372 (QII->isNewValueJump(I))) {
2376 // For predicated instructions, if the predicates are complements
2377 // then there can be no dependence.
2378 else if (QII->isPredicated(I) &&
2379 QII->isPredicated(J) &&
2380 ArePredicatesComplements(I, J, MIToSUnit)) {
2384 else if (IsDirectJump(I) &&
2385 !MCIDJ.isBranch() &&
2387 (DepType == SDep::Order)) {
2388 // Ignore Order dependences between unconditional direct branches
2389 // and non-control-flow instructions
2392 else if (MCIDI.isConditionalBranch() && (DepType != SDep::Data) &&
2393 (DepType != SDep::Output)) {
2394 // Ignore all dependences for jumps except for true and output
2399 // Ignore output dependences due to superregs. We can
2400 // write to two different subregisters of R1:0 for instance
2401 // in the same cycle
2406 // If neither I nor J defines DepReg, then this is a
2407 // superfluous output dependence. The dependence must be of the
2411 // and there is an output dependence between the two instructions
2414 // We want to ignore these dependences.
2415 // Ideally, the dependence constructor should annotate such
2416 // dependences. We can then avoid this relatively expensive check.
2418 else if (DepType == SDep::Output) {
2419 // DepReg is the register that's responsible for the dependence.
2420 unsigned DepReg = SUJ->Succs[i].getReg();
2422 // Check if I and J really defines DepReg.
2423 if (I->definesRegister(DepReg) ||
2424 J->definesRegister(DepReg)) {
2425 FoundSequentialDependence = true;
2430 // We ignore Order dependences for
2431 // 1. Two loads unless they are volatile.
2432 // 2. Two stores in V4 unless they are volatile.
2433 else if ((DepType == SDep::Order) &&
2434 !I->hasOrderedMemoryRef() &&
2435 !J->hasOrderedMemoryRef()) {
2436 if (QRI->Subtarget.hasV4TOps() &&
2437 // hexagonv4 allows dual store.
2438 MCIDI.mayStore() && MCIDJ.mayStore()) {
2441 // store followed by store-- not OK on V2
2442 // store followed by load -- not OK on all (OK if addresses
2444 // load followed by store -- OK on all
2445 // load followed by load -- OK on all
2446 else if ( !MCIDJ.mayStore()) {
2450 FoundSequentialDependence = true;
2455 // For V4, special case ALLOCFRAME. Even though there is dependency
2456 // between ALLOCAFRAME and subsequent store, allow it to be
2457 // packetized in a same packet. This implies that the store is using
2458 // caller's SP. Hense, offset needs to be updated accordingly.
2459 else if (DepType == SDep::Data
2460 && QRI->Subtarget.hasV4TOps()
2461 && J->getOpcode() == Hexagon::ALLOCFRAME
2462 && (I->getOpcode() == Hexagon::STrid
2463 || I->getOpcode() == Hexagon::STriw
2464 || I->getOpcode() == Hexagon::STrib)
2465 && I->getOperand(0).getReg() == QRI->getStackRegister()
2466 && QII->isValidOffset(I->getOpcode(),
2467 I->getOperand(1).getImm() -
2468 (FrameSize + HEXAGON_LRFP_SIZE)))
2470 GlueAllocframeStore = true;
2471 // Since this store is to be glued with allocframe in the same
2472 // packet, it will use SP of the previous stack frame, i.e
2473 // caller's SP. Therefore, we need to recalculate offset according
2475 I->getOperand(1).setImm(I->getOperand(1).getImm() -
2476 (FrameSize + HEXAGON_LRFP_SIZE));
2480 // Skip over anti-dependences. Two instructions that are
2481 // anti-dependent can share a packet
2483 else if (DepType != SDep::Anti) {
2484 FoundSequentialDependence = true;
2489 if (FoundSequentialDependence) {
2498 // isLegalToPruneDependencies
2499 bool HexagonPacketizerList::isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) {
2500 MachineInstr *I = SUI->getInstr();
2501 assert(I && SUJ->getInstr() && "Unable to packetize null instruction!");
2503 const unsigned FrameSize = MF.getFrameInfo()->getStackSize();
2507 // Check if the instruction was promoted to a dot-new. If so, demote it
2508 // back into a dot-old.
2509 if (PromotedToDotNew) {
2513 // Check if the instruction (must be a store) was glued with an Allocframe
2514 // instruction. If so, restore its offset to its original value, i.e. use
2515 // curent SP instead of caller's SP.
2516 if (GlueAllocframeStore) {
2517 I->getOperand(1).setImm(I->getOperand(1).getImm() +
2518 FrameSize + HEXAGON_LRFP_SIZE);
2526 MachineBasicBlock::iterator
2527 HexagonPacketizerList::addToPacket(MachineInstr *MI) {
2529 MachineBasicBlock::iterator MII = MI;
2530 MachineBasicBlock *MBB = MI->getParent();
2532 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
2534 if (GlueToNewValueJump) {
2537 MachineInstr *nvjMI = MII;
2538 assert(ResourceTracker->canReserveResources(MI));
2539 ResourceTracker->reserveResources(MI);
2540 if ((QII->isExtended(MI) || QII->isConstExtended(MI)) &&
2541 !tryAllocateResourcesForConstExt(MI)) {
2543 ResourceTracker->reserveResources(MI);
2544 assert(canReserveResourcesForConstExt(MI) &&
2545 "Ensure that there is a slot");
2546 reserveResourcesForConstExt(MI);
2547 // Reserve resources for new value jump constant extender.
2548 assert(canReserveResourcesForConstExt(MI) &&
2549 "Ensure that there is a slot");
2550 reserveResourcesForConstExt(nvjMI);
2551 assert(ResourceTracker->canReserveResources(nvjMI) &&
2552 "Ensure that there is a slot");
2554 } else if ( // Extended instruction takes two slots in the packet.
2555 // Try reserve and allocate 4-byte in the current packet first.
2556 (QII->isExtended(nvjMI)
2557 && (!tryAllocateResourcesForConstExt(nvjMI)
2558 || !ResourceTracker->canReserveResources(nvjMI)))
2559 || // For non-extended instruction, no need to allocate extra 4 bytes.
2560 (!QII->isExtended(nvjMI) &&
2561 !ResourceTracker->canReserveResources(nvjMI)))
2564 // A new and empty packet starts.
2565 // We are sure that the resources requirements can be satisfied.
2566 // Therefore, do not need to call "canReserveResources" anymore.
2567 ResourceTracker->reserveResources(MI);
2568 if (QII->isExtended(nvjMI))
2569 reserveResourcesForConstExt(nvjMI);
2571 // Here, we are sure that "reserveResources" would succeed.
2572 ResourceTracker->reserveResources(nvjMI);
2573 CurrentPacketMIs.push_back(MI);
2574 CurrentPacketMIs.push_back(nvjMI);
2576 if ( (QII->isExtended(MI) || QII->isConstExtended(MI))
2577 && ( !tryAllocateResourcesForConstExt(MI)
2578 || !ResourceTracker->canReserveResources(MI)))
2581 // Check if the instruction was promoted to a dot-new. If so, demote it
2582 // back into a dot-old
2583 if (PromotedToDotNew) {
2586 reserveResourcesForConstExt(MI);
2588 // In case that "MI" is not an extended insn,
2589 // the resource availability has already been checked.
2590 ResourceTracker->reserveResources(MI);
2591 CurrentPacketMIs.push_back(MI);
2596 //===----------------------------------------------------------------------===//
2597 // Public Constructor Functions
2598 //===----------------------------------------------------------------------===//
2600 FunctionPass *llvm::createHexagonPacketizer() {
2601 return new HexagonPacketizer();