1 //===-- HexagonInstrInfo.cpp - Hexagon Instruction Information ------------===//
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 file contains the Hexagon implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "HexagonInstrInfo.h"
16 #include "HexagonRegisterInfo.h"
17 #include "HexagonSubtarget.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/CodeGen/DFAPacketizer.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineMemOperand.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/CodeGen/PseudoSourceValue.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/MathExtras.h"
28 #include "llvm/Support/raw_ostream.h"
29 #define GET_INSTRINFO_CTOR
30 #define GET_INSTRMAP_INFO
31 #include "HexagonGenInstrInfo.inc"
32 #include "HexagonGenDFAPacketizer.inc"
37 /// Constants for Hexagon instructions.
39 const int Hexagon_MEMW_OFFSET_MAX = 4095;
40 const int Hexagon_MEMW_OFFSET_MIN = -4096;
41 const int Hexagon_MEMD_OFFSET_MAX = 8191;
42 const int Hexagon_MEMD_OFFSET_MIN = -8192;
43 const int Hexagon_MEMH_OFFSET_MAX = 2047;
44 const int Hexagon_MEMH_OFFSET_MIN = -2048;
45 const int Hexagon_MEMB_OFFSET_MAX = 1023;
46 const int Hexagon_MEMB_OFFSET_MIN = -1024;
47 const int Hexagon_ADDI_OFFSET_MAX = 32767;
48 const int Hexagon_ADDI_OFFSET_MIN = -32768;
49 const int Hexagon_MEMD_AUTOINC_MAX = 56;
50 const int Hexagon_MEMD_AUTOINC_MIN = -64;
51 const int Hexagon_MEMW_AUTOINC_MAX = 28;
52 const int Hexagon_MEMW_AUTOINC_MIN = -32;
53 const int Hexagon_MEMH_AUTOINC_MAX = 14;
54 const int Hexagon_MEMH_AUTOINC_MIN = -16;
55 const int Hexagon_MEMB_AUTOINC_MAX = 7;
56 const int Hexagon_MEMB_AUTOINC_MIN = -8;
59 HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST)
60 : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
61 RI(ST, *this), Subtarget(ST) {
65 /// isLoadFromStackSlot - If the specified machine instruction is a direct
66 /// load from a stack slot, return the virtual or physical register number of
67 /// the destination along with the FrameIndex of the loaded stack slot. If
68 /// not, return 0. This predicate must return 0 if the instruction has
69 /// any side effects other than loading from the stack slot.
70 unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
71 int &FrameIndex) const {
74 switch (MI->getOpcode()) {
81 if (MI->getOperand(2).isFI() &&
82 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
83 FrameIndex = MI->getOperand(2).getIndex();
84 return MI->getOperand(0).getReg();
92 /// isStoreToStackSlot - If the specified machine instruction is a direct
93 /// store to a stack slot, return the virtual or physical register number of
94 /// the source reg along with the FrameIndex of the loaded stack slot. If
95 /// not, return 0. This predicate must return 0 if the instruction has
96 /// any side effects other than storing to the stack slot.
97 unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
98 int &FrameIndex) const {
99 switch (MI->getOpcode()) {
105 if (MI->getOperand(2).isFI() &&
106 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
107 FrameIndex = MI->getOperand(0).getIndex();
108 return MI->getOperand(2).getReg();
117 HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
118 MachineBasicBlock *FBB,
119 const SmallVectorImpl<MachineOperand> &Cond,
122 int BOpc = Hexagon::JMP;
123 int BccOpc = Hexagon::JMP_t;
125 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
128 // Check if ReverseBranchCondition has asked to reverse this branch
129 // If we want to reverse the branch an odd number of times, we want
131 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
132 BccOpc = Hexagon::JMP_f;
138 // Due to a bug in TailMerging/CFG Optimization, we need to add a
139 // special case handling of a predicated jump followed by an
140 // unconditional jump. If not, Tail Merging and CFG Optimization go
141 // into an infinite loop.
142 MachineBasicBlock *NewTBB, *NewFBB;
143 SmallVector<MachineOperand, 4> Cond;
144 MachineInstr *Term = MBB.getFirstTerminator();
145 if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond,
147 MachineBasicBlock *NextBB =
148 llvm::next(MachineFunction::iterator(&MBB));
149 if (NewTBB == NextBB) {
150 ReverseBranchCondition(Cond);
152 return InsertBranch(MBB, TBB, 0, Cond, DL);
155 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
158 get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
163 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
164 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
170 bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
171 MachineBasicBlock *&TBB,
172 MachineBasicBlock *&FBB,
173 SmallVectorImpl<MachineOperand> &Cond,
174 bool AllowModify) const {
178 // If the block has no terminators, it just falls into the block after it.
179 MachineBasicBlock::instr_iterator I = MBB.instr_end();
180 if (I == MBB.instr_begin())
183 // A basic block may looks like this:
193 // It has two succs but does not have a terminator
194 // Don't know how to handle it.
199 } while (I != MBB.instr_begin());
204 while (I->isDebugValue()) {
205 if (I == MBB.instr_begin())
210 // Delete the JMP if it's equivalent to a fall-through.
211 if (AllowModify && I->getOpcode() == Hexagon::JMP &&
212 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
213 DEBUG(dbgs()<< "\nErasing the jump to successor block\n";);
214 I->eraseFromParent();
216 if (I == MBB.instr_begin())
220 if (!isUnpredicatedTerminator(I))
223 // Get the last instruction in the block.
224 MachineInstr *LastInst = I;
225 MachineInstr *SecondLastInst = NULL;
226 // Find one more terminator if present.
228 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(I)) {
232 // This is a third branch.
235 if (I == MBB.instr_begin())
240 int LastOpcode = LastInst->getOpcode();
242 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
243 bool LastOpcodeHasNot = PredOpcodeHasNot(LastOpcode);
245 // If there is only one terminator instruction, process it.
246 if (LastInst && !SecondLastInst) {
247 if (LastOpcode == Hexagon::JMP) {
248 TBB = LastInst->getOperand(0).getMBB();
251 if (LastOpcode == Hexagon::ENDLOOP0) {
252 TBB = LastInst->getOperand(0).getMBB();
253 Cond.push_back(LastInst->getOperand(0));
256 if (LastOpcodeHasJMP_c) {
257 TBB = LastInst->getOperand(1).getMBB();
258 if (LastOpcodeHasNot) {
259 Cond.push_back(MachineOperand::CreateImm(0));
261 Cond.push_back(LastInst->getOperand(0));
264 // Otherwise, don't know what this is.
268 int SecLastOpcode = SecondLastInst->getOpcode();
270 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
271 bool SecLastOpcodeHasNot = PredOpcodeHasNot(SecLastOpcode);
272 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::JMP)) {
273 TBB = SecondLastInst->getOperand(1).getMBB();
274 if (SecLastOpcodeHasNot)
275 Cond.push_back(MachineOperand::CreateImm(0));
276 Cond.push_back(SecondLastInst->getOperand(0));
277 FBB = LastInst->getOperand(0).getMBB();
281 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
282 // executed, so remove it.
283 if (SecLastOpcode == Hexagon::JMP && LastOpcode == Hexagon::JMP) {
284 TBB = SecondLastInst->getOperand(0).getMBB();
287 I->eraseFromParent();
291 // If the block ends with an ENDLOOP, and JMP, handle it.
292 if (SecLastOpcode == Hexagon::ENDLOOP0 &&
293 LastOpcode == Hexagon::JMP) {
294 TBB = SecondLastInst->getOperand(0).getMBB();
295 Cond.push_back(SecondLastInst->getOperand(0));
296 FBB = LastInst->getOperand(0).getMBB();
300 // Otherwise, can't handle this.
305 unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
306 int BOpc = Hexagon::JMP;
307 int BccOpc = Hexagon::JMP_t;
308 int BccOpcNot = Hexagon::JMP_f;
310 MachineBasicBlock::iterator I = MBB.end();
311 if (I == MBB.begin()) return 0;
313 if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
314 I->getOpcode() != BccOpcNot)
317 // Remove the branch.
318 I->eraseFromParent();
322 if (I == MBB.begin()) return 1;
324 if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
327 // Remove the branch.
328 I->eraseFromParent();
333 /// \brief For a comparison instruction, return the source registers in
334 /// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
335 /// compares against in CmpValue. Return true if the comparison instruction
337 bool HexagonInstrInfo::analyzeCompare(const MachineInstr *MI,
338 unsigned &SrcReg, unsigned &SrcReg2,
339 int &Mask, int &Value) const {
340 unsigned Opc = MI->getOpcode();
342 // Set mask and the first source register.
344 case Hexagon::CMPEHexagon4rr:
345 case Hexagon::CMPEQri:
346 case Hexagon::CMPEQrr:
347 case Hexagon::CMPGT64rr:
348 case Hexagon::CMPGTU64rr:
349 case Hexagon::CMPGTUri:
350 case Hexagon::CMPGTUrr:
351 case Hexagon::CMPGTri:
352 case Hexagon::CMPGTrr:
353 SrcReg = MI->getOperand(1).getReg();
356 case Hexagon::CMPbEQri_V4:
357 case Hexagon::CMPbEQrr_sbsb_V4:
358 case Hexagon::CMPbEQrr_ubub_V4:
359 case Hexagon::CMPbGTUri_V4:
360 case Hexagon::CMPbGTUrr_V4:
361 case Hexagon::CMPbGTrr_V4:
362 SrcReg = MI->getOperand(1).getReg();
365 case Hexagon::CMPhEQri_V4:
366 case Hexagon::CMPhEQrr_shl_V4:
367 case Hexagon::CMPhEQrr_xor_V4:
368 case Hexagon::CMPhGTUri_V4:
369 case Hexagon::CMPhGTUrr_V4:
370 case Hexagon::CMPhGTrr_shl_V4:
371 SrcReg = MI->getOperand(1).getReg();
376 // Set the value/second source register.
378 case Hexagon::CMPEHexagon4rr:
379 case Hexagon::CMPEQrr:
380 case Hexagon::CMPGT64rr:
381 case Hexagon::CMPGTU64rr:
382 case Hexagon::CMPGTUrr:
383 case Hexagon::CMPGTrr:
384 case Hexagon::CMPbEQrr_sbsb_V4:
385 case Hexagon::CMPbEQrr_ubub_V4:
386 case Hexagon::CMPbGTUrr_V4:
387 case Hexagon::CMPbGTrr_V4:
388 case Hexagon::CMPhEQrr_shl_V4:
389 case Hexagon::CMPhEQrr_xor_V4:
390 case Hexagon::CMPhGTUrr_V4:
391 case Hexagon::CMPhGTrr_shl_V4:
392 SrcReg2 = MI->getOperand(2).getReg();
395 case Hexagon::CMPEQri:
396 case Hexagon::CMPGTUri:
397 case Hexagon::CMPGTri:
398 case Hexagon::CMPbEQri_V4:
399 case Hexagon::CMPbGTUri_V4:
400 case Hexagon::CMPhEQri_V4:
401 case Hexagon::CMPhGTUri_V4:
403 Value = MI->getOperand(2).getImm();
411 void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
412 MachineBasicBlock::iterator I, DebugLoc DL,
413 unsigned DestReg, unsigned SrcReg,
414 bool KillSrc) const {
415 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
416 BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg);
419 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
420 BuildMI(MBB, I, DL, get(Hexagon::TFR64), DestReg).addReg(SrcReg);
423 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
424 // Map Pd = Ps to Pd = or(Ps, Ps).
425 BuildMI(MBB, I, DL, get(Hexagon::OR_pp),
426 DestReg).addReg(SrcReg).addReg(SrcReg);
429 if (Hexagon::DoubleRegsRegClass.contains(DestReg) &&
430 Hexagon::IntRegsRegClass.contains(SrcReg)) {
431 // We can have an overlap between single and double reg: r1:0 = r0.
432 if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) {
434 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
435 Hexagon::subreg_hireg))).addImm(0);
437 // r1:0 = r1 or no overlap.
438 BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg,
439 Hexagon::subreg_loreg))).addReg(SrcReg);
440 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
441 Hexagon::subreg_hireg))).addImm(0);
445 if (Hexagon::CRRegsRegClass.contains(DestReg) &&
446 Hexagon::IntRegsRegClass.contains(SrcReg)) {
447 BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg);
450 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
451 Hexagon::IntRegsRegClass.contains(DestReg)) {
452 BuildMI(MBB, I, DL, get(Hexagon::TFR_RsPd), DestReg).
453 addReg(SrcReg, getKillRegState(KillSrc));
456 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
457 Hexagon::PredRegsRegClass.contains(DestReg)) {
458 BuildMI(MBB, I, DL, get(Hexagon::TFR_PdRs), DestReg).
459 addReg(SrcReg, getKillRegState(KillSrc));
463 llvm_unreachable("Unimplemented");
467 void HexagonInstrInfo::
468 storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
469 unsigned SrcReg, bool isKill, int FI,
470 const TargetRegisterClass *RC,
471 const TargetRegisterInfo *TRI) const {
473 DebugLoc DL = MBB.findDebugLoc(I);
474 MachineFunction &MF = *MBB.getParent();
475 MachineFrameInfo &MFI = *MF.getFrameInfo();
476 unsigned Align = MFI.getObjectAlignment(FI);
478 MachineMemOperand *MMO =
479 MF.getMachineMemOperand(
480 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
481 MachineMemOperand::MOStore,
482 MFI.getObjectSize(FI),
485 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
486 BuildMI(MBB, I, DL, get(Hexagon::STriw))
487 .addFrameIndex(FI).addImm(0)
488 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
489 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
490 BuildMI(MBB, I, DL, get(Hexagon::STrid))
491 .addFrameIndex(FI).addImm(0)
492 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
493 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
494 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
495 .addFrameIndex(FI).addImm(0)
496 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
498 llvm_unreachable("Unimplemented");
503 void HexagonInstrInfo::storeRegToAddr(
504 MachineFunction &MF, unsigned SrcReg,
506 SmallVectorImpl<MachineOperand> &Addr,
507 const TargetRegisterClass *RC,
508 SmallVectorImpl<MachineInstr*> &NewMIs) const
510 llvm_unreachable("Unimplemented");
514 void HexagonInstrInfo::
515 loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
516 unsigned DestReg, int FI,
517 const TargetRegisterClass *RC,
518 const TargetRegisterInfo *TRI) const {
519 DebugLoc DL = MBB.findDebugLoc(I);
520 MachineFunction &MF = *MBB.getParent();
521 MachineFrameInfo &MFI = *MF.getFrameInfo();
522 unsigned Align = MFI.getObjectAlignment(FI);
524 MachineMemOperand *MMO =
525 MF.getMachineMemOperand(
526 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
527 MachineMemOperand::MOLoad,
528 MFI.getObjectSize(FI),
530 if (RC == &Hexagon::IntRegsRegClass) {
531 BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg)
532 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
533 } else if (RC == &Hexagon::DoubleRegsRegClass) {
534 BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg)
535 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
536 } else if (RC == &Hexagon::PredRegsRegClass) {
537 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
538 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
540 llvm_unreachable("Can't store this register to stack slot");
545 void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
546 SmallVectorImpl<MachineOperand> &Addr,
547 const TargetRegisterClass *RC,
548 SmallVectorImpl<MachineInstr*> &NewMIs) const {
549 llvm_unreachable("Unimplemented");
553 MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
555 const SmallVectorImpl<unsigned> &Ops,
557 // Hexagon_TODO: Implement.
562 HexagonInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
563 int FrameIx, uint64_t Offset,
566 MachineInstrBuilder MIB = BuildMI(MF, DL, get(Hexagon::DBG_VALUE))
567 .addImm(0).addImm(Offset).addMetadata(MDPtr);
571 unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const {
573 MachineRegisterInfo &RegInfo = MF->getRegInfo();
574 const TargetRegisterClass *TRC;
576 TRC = &Hexagon::PredRegsRegClass;
577 } else if (VT == MVT::i32 || VT == MVT::f32) {
578 TRC = &Hexagon::IntRegsRegClass;
579 } else if (VT == MVT::i64 || VT == MVT::f64) {
580 TRC = &Hexagon::DoubleRegsRegClass;
582 llvm_unreachable("Cannot handle this register class");
585 unsigned NewReg = RegInfo.createVirtualRegister(TRC);
589 bool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const {
590 // Constant extenders are allowed only for V4 and above.
591 if (!Subtarget.hasV4TOps())
594 const MCInstrDesc &MID = MI->getDesc();
595 const uint64_t F = MID.TSFlags;
596 if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask)
599 // TODO: This is largely obsolete now. Will need to be removed
600 // in consecutive patches.
601 switch(MI->getOpcode()) {
602 // TFR_FI Remains a special case.
603 case Hexagon::TFR_FI:
611 // This returns true in two cases:
612 // - The OP code itself indicates that this is an extended instruction.
613 // - One of MOs has been marked with HMOTF_ConstExtended flag.
614 bool HexagonInstrInfo::isExtended(const MachineInstr *MI) const {
615 // First check if this is permanently extended op code.
616 const uint64_t F = MI->getDesc().TSFlags;
617 if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask)
619 // Use MO operand flags to determine if one of MI's operands
620 // has HMOTF_ConstExtended flag set.
621 for (MachineInstr::const_mop_iterator I = MI->operands_begin(),
622 E = MI->operands_end(); I != E; ++I) {
623 if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended)
629 bool HexagonInstrInfo::isBranch (const MachineInstr *MI) const {
630 return MI->getDesc().isBranch();
633 bool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const {
634 switch (MI->getOpcode()) {
635 default: return false;
637 case Hexagon::STrib_nv_V4:
638 case Hexagon::STrib_indexed_nv_V4:
639 case Hexagon::STrib_indexed_shl_nv_V4:
640 case Hexagon::STrib_shl_nv_V4:
641 case Hexagon::STb_GP_nv_V4:
642 case Hexagon::POST_STbri_nv_V4:
643 case Hexagon::STrib_cPt_nv_V4:
644 case Hexagon::STrib_cdnPt_nv_V4:
645 case Hexagon::STrib_cNotPt_nv_V4:
646 case Hexagon::STrib_cdnNotPt_nv_V4:
647 case Hexagon::STrib_indexed_cPt_nv_V4:
648 case Hexagon::STrib_indexed_cdnPt_nv_V4:
649 case Hexagon::STrib_indexed_cNotPt_nv_V4:
650 case Hexagon::STrib_indexed_cdnNotPt_nv_V4:
651 case Hexagon::STrib_indexed_shl_cPt_nv_V4:
652 case Hexagon::STrib_indexed_shl_cdnPt_nv_V4:
653 case Hexagon::STrib_indexed_shl_cNotPt_nv_V4:
654 case Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4:
655 case Hexagon::POST_STbri_cPt_nv_V4:
656 case Hexagon::POST_STbri_cdnPt_nv_V4:
657 case Hexagon::POST_STbri_cNotPt_nv_V4:
658 case Hexagon::POST_STbri_cdnNotPt_nv_V4:
659 case Hexagon::STb_GP_cPt_nv_V4:
660 case Hexagon::STb_GP_cNotPt_nv_V4:
661 case Hexagon::STb_GP_cdnPt_nv_V4:
662 case Hexagon::STb_GP_cdnNotPt_nv_V4:
663 case Hexagon::STrib_abs_nv_V4:
664 case Hexagon::STrib_abs_cPt_nv_V4:
665 case Hexagon::STrib_abs_cdnPt_nv_V4:
666 case Hexagon::STrib_abs_cNotPt_nv_V4:
667 case Hexagon::STrib_abs_cdnNotPt_nv_V4:
670 case Hexagon::STrih_nv_V4:
671 case Hexagon::STrih_indexed_nv_V4:
672 case Hexagon::STrih_indexed_shl_nv_V4:
673 case Hexagon::STrih_shl_nv_V4:
674 case Hexagon::STh_GP_nv_V4:
675 case Hexagon::POST_SThri_nv_V4:
676 case Hexagon::STrih_cPt_nv_V4:
677 case Hexagon::STrih_cdnPt_nv_V4:
678 case Hexagon::STrih_cNotPt_nv_V4:
679 case Hexagon::STrih_cdnNotPt_nv_V4:
680 case Hexagon::STrih_indexed_cPt_nv_V4:
681 case Hexagon::STrih_indexed_cdnPt_nv_V4:
682 case Hexagon::STrih_indexed_cNotPt_nv_V4:
683 case Hexagon::STrih_indexed_cdnNotPt_nv_V4:
684 case Hexagon::STrih_indexed_shl_cPt_nv_V4:
685 case Hexagon::STrih_indexed_shl_cdnPt_nv_V4:
686 case Hexagon::STrih_indexed_shl_cNotPt_nv_V4:
687 case Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4:
688 case Hexagon::POST_SThri_cPt_nv_V4:
689 case Hexagon::POST_SThri_cdnPt_nv_V4:
690 case Hexagon::POST_SThri_cNotPt_nv_V4:
691 case Hexagon::POST_SThri_cdnNotPt_nv_V4:
692 case Hexagon::STh_GP_cPt_nv_V4:
693 case Hexagon::STh_GP_cNotPt_nv_V4:
694 case Hexagon::STh_GP_cdnPt_nv_V4:
695 case Hexagon::STh_GP_cdnNotPt_nv_V4:
696 case Hexagon::STrih_abs_nv_V4:
697 case Hexagon::STrih_abs_cPt_nv_V4:
698 case Hexagon::STrih_abs_cdnPt_nv_V4:
699 case Hexagon::STrih_abs_cNotPt_nv_V4:
700 case Hexagon::STrih_abs_cdnNotPt_nv_V4:
703 case Hexagon::STriw_nv_V4:
704 case Hexagon::STriw_indexed_nv_V4:
705 case Hexagon::STriw_indexed_shl_nv_V4:
706 case Hexagon::STriw_shl_nv_V4:
707 case Hexagon::STw_GP_nv_V4:
708 case Hexagon::POST_STwri_nv_V4:
709 case Hexagon::STriw_cPt_nv_V4:
710 case Hexagon::STriw_cdnPt_nv_V4:
711 case Hexagon::STriw_cNotPt_nv_V4:
712 case Hexagon::STriw_cdnNotPt_nv_V4:
713 case Hexagon::STriw_indexed_cPt_nv_V4:
714 case Hexagon::STriw_indexed_cdnPt_nv_V4:
715 case Hexagon::STriw_indexed_cNotPt_nv_V4:
716 case Hexagon::STriw_indexed_cdnNotPt_nv_V4:
717 case Hexagon::STriw_indexed_shl_cPt_nv_V4:
718 case Hexagon::STriw_indexed_shl_cdnPt_nv_V4:
719 case Hexagon::STriw_indexed_shl_cNotPt_nv_V4:
720 case Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4:
721 case Hexagon::POST_STwri_cPt_nv_V4:
722 case Hexagon::POST_STwri_cdnPt_nv_V4:
723 case Hexagon::POST_STwri_cNotPt_nv_V4:
724 case Hexagon::POST_STwri_cdnNotPt_nv_V4:
725 case Hexagon::STw_GP_cPt_nv_V4:
726 case Hexagon::STw_GP_cNotPt_nv_V4:
727 case Hexagon::STw_GP_cdnPt_nv_V4:
728 case Hexagon::STw_GP_cdnNotPt_nv_V4:
729 case Hexagon::STriw_abs_nv_V4:
730 case Hexagon::STriw_abs_cPt_nv_V4:
731 case Hexagon::STriw_abs_cdnPt_nv_V4:
732 case Hexagon::STriw_abs_cNotPt_nv_V4:
733 case Hexagon::STriw_abs_cdnNotPt_nv_V4:
738 bool HexagonInstrInfo::isPostIncrement (const MachineInstr* MI) const {
739 switch (MI->getOpcode())
741 default: return false;
743 case Hexagon::POST_LDrib:
744 case Hexagon::POST_LDrib_cPt:
745 case Hexagon::POST_LDrib_cNotPt:
746 case Hexagon::POST_LDrib_cdnPt_V4:
747 case Hexagon::POST_LDrib_cdnNotPt_V4:
749 // Load unsigned byte
750 case Hexagon::POST_LDriub:
751 case Hexagon::POST_LDriub_cPt:
752 case Hexagon::POST_LDriub_cNotPt:
753 case Hexagon::POST_LDriub_cdnPt_V4:
754 case Hexagon::POST_LDriub_cdnNotPt_V4:
757 case Hexagon::POST_LDrih:
758 case Hexagon::POST_LDrih_cPt:
759 case Hexagon::POST_LDrih_cNotPt:
760 case Hexagon::POST_LDrih_cdnPt_V4:
761 case Hexagon::POST_LDrih_cdnNotPt_V4:
763 // Load unsigned halfword
764 case Hexagon::POST_LDriuh:
765 case Hexagon::POST_LDriuh_cPt:
766 case Hexagon::POST_LDriuh_cNotPt:
767 case Hexagon::POST_LDriuh_cdnPt_V4:
768 case Hexagon::POST_LDriuh_cdnNotPt_V4:
771 case Hexagon::POST_LDriw:
772 case Hexagon::POST_LDriw_cPt:
773 case Hexagon::POST_LDriw_cNotPt:
774 case Hexagon::POST_LDriw_cdnPt_V4:
775 case Hexagon::POST_LDriw_cdnNotPt_V4:
778 case Hexagon::POST_LDrid:
779 case Hexagon::POST_LDrid_cPt:
780 case Hexagon::POST_LDrid_cNotPt:
781 case Hexagon::POST_LDrid_cdnPt_V4:
782 case Hexagon::POST_LDrid_cdnNotPt_V4:
785 case Hexagon::POST_STbri:
786 case Hexagon::POST_STbri_cPt:
787 case Hexagon::POST_STbri_cNotPt:
788 case Hexagon::POST_STbri_cdnPt_V4:
789 case Hexagon::POST_STbri_cdnNotPt_V4:
792 case Hexagon::POST_SThri:
793 case Hexagon::POST_SThri_cPt:
794 case Hexagon::POST_SThri_cNotPt:
795 case Hexagon::POST_SThri_cdnPt_V4:
796 case Hexagon::POST_SThri_cdnNotPt_V4:
799 case Hexagon::POST_STwri:
800 case Hexagon::POST_STwri_cPt:
801 case Hexagon::POST_STwri_cNotPt:
802 case Hexagon::POST_STwri_cdnPt_V4:
803 case Hexagon::POST_STwri_cdnNotPt_V4:
806 case Hexagon::POST_STdri:
807 case Hexagon::POST_STdri_cPt:
808 case Hexagon::POST_STdri_cNotPt:
809 case Hexagon::POST_STdri_cdnPt_V4:
810 case Hexagon::POST_STdri_cdnNotPt_V4:
815 bool HexagonInstrInfo::isNewValueInst(const MachineInstr *MI) const {
816 if (isNewValueJump(MI))
819 if (isNewValueStore(MI))
825 bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const {
826 return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4;
829 bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
830 bool isPred = MI->getDesc().isPredicable();
835 const int Opc = MI->getOpcode();
839 return isInt<12>(MI->getOperand(1).getImm());
842 case Hexagon::STrid_indexed:
843 return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
846 case Hexagon::STriw_indexed:
847 case Hexagon::STriw_nv_V4:
848 return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
851 case Hexagon::STrih_indexed:
852 case Hexagon::STrih_nv_V4:
853 return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
856 case Hexagon::STrib_indexed:
857 case Hexagon::STrib_nv_V4:
858 return isUInt<6>(MI->getOperand(1).getImm());
861 case Hexagon::LDrid_indexed:
862 return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
865 case Hexagon::LDriw_indexed:
866 return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
869 case Hexagon::LDriuh:
870 case Hexagon::LDrih_indexed:
871 case Hexagon::LDriuh_indexed:
872 return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
875 case Hexagon::LDriub:
876 case Hexagon::LDrib_indexed:
877 case Hexagon::LDriub_indexed:
878 return isUInt<6>(MI->getOperand(2).getImm());
880 case Hexagon::POST_LDrid:
881 return isShiftedInt<4,3>(MI->getOperand(3).getImm());
883 case Hexagon::POST_LDriw:
884 return isShiftedInt<4,2>(MI->getOperand(3).getImm());
886 case Hexagon::POST_LDrih:
887 case Hexagon::POST_LDriuh:
888 return isShiftedInt<4,1>(MI->getOperand(3).getImm());
890 case Hexagon::POST_LDrib:
891 case Hexagon::POST_LDriub:
892 return isInt<4>(MI->getOperand(3).getImm());
894 case Hexagon::STrib_imm_V4:
895 case Hexagon::STrih_imm_V4:
896 case Hexagon::STriw_imm_V4:
897 return (isUInt<6>(MI->getOperand(1).getImm()) &&
898 isInt<6>(MI->getOperand(2).getImm()));
900 case Hexagon::ADD_ri:
901 return isInt<8>(MI->getOperand(2).getImm());
909 return Subtarget.hasV4TOps();
915 // This function performs the following inversiones:
920 unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const {
922 InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc)
923 : Hexagon::getTruePredOpcode(Opc);
924 if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate.
925 return InvPredOpcode;
928 default: llvm_unreachable("Unexpected predicated instruction");
929 case Hexagon::COMBINE_rr_cPt:
930 return Hexagon::COMBINE_rr_cNotPt;
931 case Hexagon::COMBINE_rr_cNotPt:
932 return Hexagon::COMBINE_rr_cPt;
935 case Hexagon::DEALLOC_RET_cPt_V4:
936 return Hexagon::DEALLOC_RET_cNotPt_V4;
937 case Hexagon::DEALLOC_RET_cNotPt_V4:
938 return Hexagon::DEALLOC_RET_cPt_V4;
943 int HexagonInstrInfo::
944 getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const {
945 enum Hexagon::PredSense inPredSense;
946 inPredSense = invertPredicate ? Hexagon::PredSense_false :
947 Hexagon::PredSense_true;
948 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
949 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
952 // This switch case will be removed once all the instructions have been
953 // modified to use relation maps.
955 case Hexagon::TFRI_f:
956 return !invertPredicate ? Hexagon::TFRI_cPt_f :
957 Hexagon::TFRI_cNotPt_f;
958 case Hexagon::COMBINE_rr:
959 return !invertPredicate ? Hexagon::COMBINE_rr_cPt :
960 Hexagon::COMBINE_rr_cNotPt;
963 case Hexagon::STriw_f:
964 return !invertPredicate ? Hexagon::STriw_cPt :
965 Hexagon::STriw_cNotPt;
966 case Hexagon::STriw_indexed_f:
967 return !invertPredicate ? Hexagon::STriw_indexed_cPt :
968 Hexagon::STriw_indexed_cNotPt;
971 case Hexagon::DEALLOC_RET_V4:
972 return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 :
973 Hexagon::DEALLOC_RET_cNotPt_V4;
975 llvm_unreachable("Unexpected predicable instruction");
979 bool HexagonInstrInfo::
980 PredicateInstruction(MachineInstr *MI,
981 const SmallVectorImpl<MachineOperand> &Cond) const {
982 int Opc = MI->getOpcode();
983 assert (isPredicable(MI) && "Expected predicable instruction");
984 bool invertJump = (!Cond.empty() && Cond[0].isImm() &&
985 (Cond[0].getImm() == 0));
987 // This will change MI's opcode to its predicate version.
988 // However, its operand list is still the old one, i.e. the
989 // non-predicate one.
990 MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump)));
993 unsigned int GAIdx = 0;
995 // Indicates whether the current MI has a GlobalAddress operand
996 bool hasGAOpnd = false;
997 std::vector<MachineOperand> tmpOpnds;
999 // Indicates whether we need to shift operands to right.
1000 bool needShift = true;
1002 // The predicate is ALWAYS the FIRST input operand !!!
1003 if (MI->getNumOperands() == 0) {
1004 // The non-predicate version of MI does not take any operands,
1005 // i.e. no outs and no ins. In this condition, the predicate
1006 // operand will be directly placed at Operands[0]. No operand
1012 else if ( MI->getOperand(MI->getNumOperands()-1).isReg()
1013 && MI->getOperand(MI->getNumOperands()-1).isDef()
1014 && !MI->getOperand(MI->getNumOperands()-1).isImplicit()) {
1015 // The non-predicate version of MI does not have any input operands.
1016 // In this condition, we extend the length of Operands[] by one and
1017 // copy the original last operand to the newly allocated slot.
1018 // At this moment, it is just a place holder. Later, we will put
1019 // predicate operand directly into it. No operand shift is needed.
1020 // Example: r0=BARRIER (this is a faked insn used here for illustration)
1021 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1023 oper = MI->getNumOperands() - 2;
1026 // We need to right shift all input operands by one. Duplicate the
1027 // last operand into the newly allocated slot.
1028 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1033 // Operands[ MI->getNumOperands() - 2 ] has been copied into
1034 // Operands[ MI->getNumOperands() - 1 ], so we start from
1035 // Operands[ MI->getNumOperands() - 3 ].
1036 // oper is a signed int.
1037 // It is ok if "MI->getNumOperands()-3" is -3, -2, or -1.
1038 for (oper = MI->getNumOperands() - 3; oper >= 0; --oper)
1040 MachineOperand &MO = MI->getOperand(oper);
1042 // Opnd[0] Opnd[1] Opnd[2] Opnd[3] Opnd[4] Opnd[5] Opnd[6] Opnd[7]
1043 // <Def0> <Def1> <Use0> <Use1> <ImpDef0> <ImpDef1> <ImpUse0> <ImpUse1>
1047 // Predicate Operand here
1048 if (MO.isReg() && !MO.isUse() && !MO.isImplicit()) {
1052 MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(),
1053 MO.isImplicit(), MO.isKill(),
1054 MO.isDead(), MO.isUndef(),
1057 else if (MO.isImm()) {
1058 MI->getOperand(oper+1).ChangeToImmediate(MO.getImm());
1060 else if (MO.isGlobal()) {
1061 // MI can not have more than one GlobalAddress operand.
1062 assert(hasGAOpnd == false && "MI can only have one GlobalAddress opnd");
1064 // There is no member function called "ChangeToGlobalAddress" in the
1065 // MachineOperand class (not like "ChangeToRegister" and
1066 // "ChangeToImmediate"). So we have to remove them from Operands[] list
1067 // first, and then add them back after we have inserted the predicate
1068 // operand. tmpOpnds[] is to remember these operands before we remove
1070 tmpOpnds.push_back(MO);
1072 // Operands[oper] is a GlobalAddress operand;
1073 // Operands[oper+1] has been copied into Operands[oper+2];
1079 assert(false && "Unexpected operand type");
1084 int regPos = invertJump ? 1 : 0;
1085 MachineOperand PredMO = Cond[regPos];
1087 // [oper] now points to the last explicit Def. Predicate operand must be
1088 // located at [oper+1]. See diagram above.
1089 // This assumes that the predicate is always the first operand,
1090 // i.e. Operands[0+numResults], in the set of inputs
1091 // It is better to have an assert here to check this. But I don't know how
1092 // to write this assert because findFirstPredOperandIdx() would return -1
1093 if (oper < -1) oper = -1;
1095 MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(),
1096 PredMO.isImplicit(), false,
1097 PredMO.isDead(), PredMO.isUndef(),
1100 MachineRegisterInfo &RegInfo = MI->getParent()->getParent()->getRegInfo();
1101 RegInfo.clearKillFlags(PredMO.getReg());
1107 // Operands[GAIdx] is the original GlobalAddress operand, which is
1108 // already copied into tmpOpnds[0].
1109 // Operands[GAIdx] now stores a copy of Operands[GAIdx-1]
1110 // Operands[GAIdx+1] has already been copied into Operands[GAIdx+2],
1111 // so we start from [GAIdx+2]
1112 for (i = GAIdx + 2; i < MI->getNumOperands(); ++i)
1113 tmpOpnds.push_back(MI->getOperand(i));
1115 // Remove all operands in range [ (GAIdx+1) ... (MI->getNumOperands()-1) ]
1116 // It is very important that we always remove from the end of Operands[]
1117 // MI->getNumOperands() is at least 2 if program goes to here.
1118 for (i = MI->getNumOperands() - 1; i > GAIdx; --i)
1119 MI->RemoveOperand(i);
1121 for (i = 0; i < tmpOpnds.size(); ++i)
1122 MI->addOperand(tmpOpnds[i]);
1131 isProfitableToIfCvt(MachineBasicBlock &MBB,
1133 unsigned ExtraPredCycles,
1134 const BranchProbability &Probability) const {
1141 isProfitableToIfCvt(MachineBasicBlock &TMBB,
1142 unsigned NumTCycles,
1143 unsigned ExtraTCycles,
1144 MachineBasicBlock &FMBB,
1145 unsigned NumFCycles,
1146 unsigned ExtraFCycles,
1147 const BranchProbability &Probability) const {
1151 // Returns true if an instruction is predicated irrespective of the predicate
1152 // sense. For example, all of the following will return true.
1153 // if (p0) R1 = add(R2, R3)
1154 // if (!p0) R1 = add(R2, R3)
1155 // if (p0.new) R1 = add(R2, R3)
1156 // if (!p0.new) R1 = add(R2, R3)
1157 bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
1158 const uint64_t F = MI->getDesc().TSFlags;
1160 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
1163 bool HexagonInstrInfo::isPredicated(unsigned Opcode) const {
1164 const uint64_t F = get(Opcode).TSFlags;
1166 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
1169 bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr *MI) const {
1170 const uint64_t F = MI->getDesc().TSFlags;
1172 assert(isPredicated(MI));
1173 return (!((F >> HexagonII::PredicatedFalsePos) &
1174 HexagonII::PredicatedFalseMask));
1177 bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const {
1178 const uint64_t F = get(Opcode).TSFlags;
1180 // Make sure that the instruction is predicated.
1181 assert((F>> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
1182 return (!((F >> HexagonII::PredicatedFalsePos) &
1183 HexagonII::PredicatedFalseMask));
1186 bool HexagonInstrInfo::isPredicatedNew(const MachineInstr *MI) const {
1187 const uint64_t F = MI->getDesc().TSFlags;
1189 assert(isPredicated(MI));
1190 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
1193 bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const {
1194 const uint64_t F = get(Opcode).TSFlags;
1196 assert(isPredicated(Opcode));
1197 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
1201 HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
1202 std::vector<MachineOperand> &Pred) const {
1203 for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
1204 MachineOperand MO = MI->getOperand(oper);
1205 if (MO.isReg() && MO.isDef()) {
1206 const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg());
1207 if (RC == &Hexagon::PredRegsRegClass) {
1219 SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
1220 const SmallVectorImpl<MachineOperand> &Pred2) const {
1227 // We indicate that we want to reverse the branch by
1228 // inserting a 0 at the beginning of the Cond vector.
1230 bool HexagonInstrInfo::
1231 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
1232 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
1233 Cond.erase(Cond.begin());
1235 Cond.insert(Cond.begin(), MachineOperand::CreateImm(0));
1241 bool HexagonInstrInfo::
1242 isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs,
1243 const BranchProbability &Probability) const {
1244 return (NumInstrs <= 4);
1247 bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const {
1248 switch (MI->getOpcode()) {
1249 default: return false;
1250 case Hexagon::DEALLOC_RET_V4 :
1251 case Hexagon::DEALLOC_RET_cPt_V4 :
1252 case Hexagon::DEALLOC_RET_cNotPt_V4 :
1253 case Hexagon::DEALLOC_RET_cdnPnt_V4 :
1254 case Hexagon::DEALLOC_RET_cNotdnPnt_V4 :
1255 case Hexagon::DEALLOC_RET_cdnPt_V4 :
1256 case Hexagon::DEALLOC_RET_cNotdnPt_V4 :
1262 bool HexagonInstrInfo::
1263 isValidOffset(const int Opcode, const int Offset) const {
1264 // This function is to check whether the "Offset" is in the correct range of
1265 // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is
1266 // inserted to calculate the final address. Due to this reason, the function
1267 // assumes that the "Offset" has correct alignment.
1268 // We used to assert if the offset was not properly aligned, however,
1269 // there are cases where a misaligned pointer recast can cause this
1270 // problem, and we need to allow for it. The front end warns of such
1271 // misaligns with respect to load size.
1275 case Hexagon::LDriw:
1276 case Hexagon::LDriw_indexed:
1277 case Hexagon::LDriw_f:
1278 case Hexagon::STriw_indexed:
1279 case Hexagon::STriw:
1280 case Hexagon::STriw_f:
1281 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
1282 (Offset <= Hexagon_MEMW_OFFSET_MAX);
1284 case Hexagon::LDrid:
1285 case Hexagon::LDrid_indexed:
1286 case Hexagon::LDrid_f:
1287 case Hexagon::STrid:
1288 case Hexagon::STrid_indexed:
1289 case Hexagon::STrid_f:
1290 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
1291 (Offset <= Hexagon_MEMD_OFFSET_MAX);
1293 case Hexagon::LDrih:
1294 case Hexagon::LDriuh:
1295 case Hexagon::STrih:
1296 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
1297 (Offset <= Hexagon_MEMH_OFFSET_MAX);
1299 case Hexagon::LDrib:
1300 case Hexagon::STrib:
1301 case Hexagon::LDriub:
1302 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
1303 (Offset <= Hexagon_MEMB_OFFSET_MAX);
1305 case Hexagon::ADD_ri:
1306 case Hexagon::TFR_FI:
1307 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
1308 (Offset <= Hexagon_ADDI_OFFSET_MAX);
1310 case Hexagon::MemOPw_ADDi_V4 :
1311 case Hexagon::MemOPw_SUBi_V4 :
1312 case Hexagon::MemOPw_ADDr_V4 :
1313 case Hexagon::MemOPw_SUBr_V4 :
1314 case Hexagon::MemOPw_ANDr_V4 :
1315 case Hexagon::MemOPw_ORr_V4 :
1316 return (0 <= Offset && Offset <= 255);
1318 case Hexagon::MemOPh_ADDi_V4 :
1319 case Hexagon::MemOPh_SUBi_V4 :
1320 case Hexagon::MemOPh_ADDr_V4 :
1321 case Hexagon::MemOPh_SUBr_V4 :
1322 case Hexagon::MemOPh_ANDr_V4 :
1323 case Hexagon::MemOPh_ORr_V4 :
1324 return (0 <= Offset && Offset <= 127);
1326 case Hexagon::MemOPb_ADDi_V4 :
1327 case Hexagon::MemOPb_SUBi_V4 :
1328 case Hexagon::MemOPb_ADDr_V4 :
1329 case Hexagon::MemOPb_SUBr_V4 :
1330 case Hexagon::MemOPb_ANDr_V4 :
1331 case Hexagon::MemOPb_ORr_V4 :
1332 return (0 <= Offset && Offset <= 63);
1334 // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of
1335 // any size. Later pass knows how to handle it.
1336 case Hexagon::STriw_pred:
1337 case Hexagon::LDriw_pred:
1340 case Hexagon::LOOP0_i:
1341 return isUInt<10>(Offset);
1343 // INLINEASM is very special.
1344 case Hexagon::INLINEASM:
1348 llvm_unreachable("No offset range is defined for this opcode. "
1349 "Please define it in the above switch statement!");
1354 // Check if the Offset is a valid auto-inc imm by Load/Store Type.
1356 bool HexagonInstrInfo::
1357 isValidAutoIncImm(const EVT VT, const int Offset) const {
1359 if (VT == MVT::i64) {
1360 return (Offset >= Hexagon_MEMD_AUTOINC_MIN &&
1361 Offset <= Hexagon_MEMD_AUTOINC_MAX &&
1362 (Offset & 0x7) == 0);
1364 if (VT == MVT::i32) {
1365 return (Offset >= Hexagon_MEMW_AUTOINC_MIN &&
1366 Offset <= Hexagon_MEMW_AUTOINC_MAX &&
1367 (Offset & 0x3) == 0);
1369 if (VT == MVT::i16) {
1370 return (Offset >= Hexagon_MEMH_AUTOINC_MIN &&
1371 Offset <= Hexagon_MEMH_AUTOINC_MAX &&
1372 (Offset & 0x1) == 0);
1374 if (VT == MVT::i8) {
1375 return (Offset >= Hexagon_MEMB_AUTOINC_MIN &&
1376 Offset <= Hexagon_MEMB_AUTOINC_MAX);
1378 llvm_unreachable("Not an auto-inc opc!");
1382 bool HexagonInstrInfo::
1383 isMemOp(const MachineInstr *MI) const {
1384 switch (MI->getOpcode())
1386 default: return false;
1387 case Hexagon::MemOPw_ADDi_V4 :
1388 case Hexagon::MemOPw_SUBi_V4 :
1389 case Hexagon::MemOPw_ADDr_V4 :
1390 case Hexagon::MemOPw_SUBr_V4 :
1391 case Hexagon::MemOPw_ANDr_V4 :
1392 case Hexagon::MemOPw_ORr_V4 :
1393 case Hexagon::MemOPh_ADDi_V4 :
1394 case Hexagon::MemOPh_SUBi_V4 :
1395 case Hexagon::MemOPh_ADDr_V4 :
1396 case Hexagon::MemOPh_SUBr_V4 :
1397 case Hexagon::MemOPh_ANDr_V4 :
1398 case Hexagon::MemOPh_ORr_V4 :
1399 case Hexagon::MemOPb_ADDi_V4 :
1400 case Hexagon::MemOPb_SUBi_V4 :
1401 case Hexagon::MemOPb_ADDr_V4 :
1402 case Hexagon::MemOPb_SUBr_V4 :
1403 case Hexagon::MemOPb_ANDr_V4 :
1404 case Hexagon::MemOPb_ORr_V4 :
1405 case Hexagon::MemOPb_SETBITi_V4:
1406 case Hexagon::MemOPh_SETBITi_V4:
1407 case Hexagon::MemOPw_SETBITi_V4:
1408 case Hexagon::MemOPb_CLRBITi_V4:
1409 case Hexagon::MemOPh_CLRBITi_V4:
1410 case Hexagon::MemOPw_CLRBITi_V4:
1417 bool HexagonInstrInfo::
1418 isSpillPredRegOp(const MachineInstr *MI) const {
1419 switch (MI->getOpcode()) {
1420 default: return false;
1421 case Hexagon::STriw_pred :
1422 case Hexagon::LDriw_pred :
1427 bool HexagonInstrInfo::isNewValueJumpCandidate(const MachineInstr *MI) const {
1428 switch (MI->getOpcode()) {
1429 default: return false;
1430 case Hexagon::CMPEQrr:
1431 case Hexagon::CMPEQri:
1432 case Hexagon::CMPGTrr:
1433 case Hexagon::CMPGTri:
1434 case Hexagon::CMPGTUrr:
1435 case Hexagon::CMPGTUri:
1440 bool HexagonInstrInfo::
1441 isConditionalTransfer (const MachineInstr *MI) const {
1442 switch (MI->getOpcode()) {
1443 default: return false;
1444 case Hexagon::TFR_cPt:
1445 case Hexagon::TFR_cNotPt:
1446 case Hexagon::TFRI_cPt:
1447 case Hexagon::TFRI_cNotPt:
1448 case Hexagon::TFR_cdnPt:
1449 case Hexagon::TFR_cdnNotPt:
1450 case Hexagon::TFRI_cdnPt:
1451 case Hexagon::TFRI_cdnNotPt:
1456 bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const {
1457 const HexagonRegisterInfo& QRI = getRegisterInfo();
1458 switch (MI->getOpcode())
1460 default: return false;
1461 case Hexagon::ADD_ri_cPt:
1462 case Hexagon::ADD_ri_cNotPt:
1463 case Hexagon::ADD_rr_cPt:
1464 case Hexagon::ADD_rr_cNotPt:
1465 case Hexagon::XOR_rr_cPt:
1466 case Hexagon::XOR_rr_cNotPt:
1467 case Hexagon::AND_rr_cPt:
1468 case Hexagon::AND_rr_cNotPt:
1469 case Hexagon::OR_rr_cPt:
1470 case Hexagon::OR_rr_cNotPt:
1471 case Hexagon::SUB_rr_cPt:
1472 case Hexagon::SUB_rr_cNotPt:
1473 case Hexagon::COMBINE_rr_cPt:
1474 case Hexagon::COMBINE_rr_cNotPt:
1476 case Hexagon::ASLH_cPt_V4:
1477 case Hexagon::ASLH_cNotPt_V4:
1478 case Hexagon::ASRH_cPt_V4:
1479 case Hexagon::ASRH_cNotPt_V4:
1480 case Hexagon::SXTB_cPt_V4:
1481 case Hexagon::SXTB_cNotPt_V4:
1482 case Hexagon::SXTH_cPt_V4:
1483 case Hexagon::SXTH_cNotPt_V4:
1484 case Hexagon::ZXTB_cPt_V4:
1485 case Hexagon::ZXTB_cNotPt_V4:
1486 case Hexagon::ZXTH_cPt_V4:
1487 case Hexagon::ZXTH_cNotPt_V4:
1488 return QRI.Subtarget.hasV4TOps();
1492 bool HexagonInstrInfo::
1493 isConditionalLoad (const MachineInstr* MI) const {
1494 const HexagonRegisterInfo& QRI = getRegisterInfo();
1495 switch (MI->getOpcode())
1497 default: return false;
1498 case Hexagon::LDrid_cPt :
1499 case Hexagon::LDrid_cNotPt :
1500 case Hexagon::LDrid_indexed_cPt :
1501 case Hexagon::LDrid_indexed_cNotPt :
1502 case Hexagon::LDriw_cPt :
1503 case Hexagon::LDriw_cNotPt :
1504 case Hexagon::LDriw_indexed_cPt :
1505 case Hexagon::LDriw_indexed_cNotPt :
1506 case Hexagon::LDrih_cPt :
1507 case Hexagon::LDrih_cNotPt :
1508 case Hexagon::LDrih_indexed_cPt :
1509 case Hexagon::LDrih_indexed_cNotPt :
1510 case Hexagon::LDrib_cPt :
1511 case Hexagon::LDrib_cNotPt :
1512 case Hexagon::LDrib_indexed_cPt :
1513 case Hexagon::LDrib_indexed_cNotPt :
1514 case Hexagon::LDriuh_cPt :
1515 case Hexagon::LDriuh_cNotPt :
1516 case Hexagon::LDriuh_indexed_cPt :
1517 case Hexagon::LDriuh_indexed_cNotPt :
1518 case Hexagon::LDriub_cPt :
1519 case Hexagon::LDriub_cNotPt :
1520 case Hexagon::LDriub_indexed_cPt :
1521 case Hexagon::LDriub_indexed_cNotPt :
1523 case Hexagon::POST_LDrid_cPt :
1524 case Hexagon::POST_LDrid_cNotPt :
1525 case Hexagon::POST_LDriw_cPt :
1526 case Hexagon::POST_LDriw_cNotPt :
1527 case Hexagon::POST_LDrih_cPt :
1528 case Hexagon::POST_LDrih_cNotPt :
1529 case Hexagon::POST_LDrib_cPt :
1530 case Hexagon::POST_LDrib_cNotPt :
1531 case Hexagon::POST_LDriuh_cPt :
1532 case Hexagon::POST_LDriuh_cNotPt :
1533 case Hexagon::POST_LDriub_cPt :
1534 case Hexagon::POST_LDriub_cNotPt :
1535 return QRI.Subtarget.hasV4TOps();
1536 case Hexagon::LDrid_indexed_shl_cPt_V4 :
1537 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
1538 case Hexagon::LDrib_indexed_shl_cPt_V4 :
1539 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
1540 case Hexagon::LDriub_indexed_shl_cPt_V4 :
1541 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
1542 case Hexagon::LDrih_indexed_shl_cPt_V4 :
1543 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
1544 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
1545 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
1546 case Hexagon::LDriw_indexed_shl_cPt_V4 :
1547 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
1548 return QRI.Subtarget.hasV4TOps();
1552 // Returns true if an instruction is a conditional store.
1554 // Note: It doesn't include conditional new-value stores as they can't be
1555 // converted to .new predicate.
1557 // p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
1559 // / \ (not OK. it will cause new-value store to be
1560 // / X conditional on p0.new while R2 producer is
1563 // p.new store p.old NV store
1564 // [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
1570 // [if (p0)memw(R0+#0)=R2]
1572 // The above diagram shows the steps involoved in the conversion of a predicated
1573 // store instruction to its .new predicated new-value form.
1575 // The following set of instructions further explains the scenario where
1576 // conditional new-value store becomes invalid when promoted to .new predicate
1579 // { 1) if (p0) r0 = add(r1, r2)
1580 // 2) p0 = cmp.eq(r3, #0) }
1582 // 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
1583 // the first two instructions because in instr 1, r0 is conditional on old value
1584 // of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
1585 // is not valid for new-value stores.
1586 bool HexagonInstrInfo::
1587 isConditionalStore (const MachineInstr* MI) const {
1588 const HexagonRegisterInfo& QRI = getRegisterInfo();
1589 switch (MI->getOpcode())
1591 default: return false;
1592 case Hexagon::STrib_imm_cPt_V4 :
1593 case Hexagon::STrib_imm_cNotPt_V4 :
1594 case Hexagon::STrib_indexed_shl_cPt_V4 :
1595 case Hexagon::STrib_indexed_shl_cNotPt_V4 :
1596 case Hexagon::STrib_cPt :
1597 case Hexagon::STrib_cNotPt :
1598 case Hexagon::POST_STbri_cPt :
1599 case Hexagon::POST_STbri_cNotPt :
1600 case Hexagon::STrid_indexed_cPt :
1601 case Hexagon::STrid_indexed_cNotPt :
1602 case Hexagon::STrid_indexed_shl_cPt_V4 :
1603 case Hexagon::POST_STdri_cPt :
1604 case Hexagon::POST_STdri_cNotPt :
1605 case Hexagon::STrih_cPt :
1606 case Hexagon::STrih_cNotPt :
1607 case Hexagon::STrih_indexed_cPt :
1608 case Hexagon::STrih_indexed_cNotPt :
1609 case Hexagon::STrih_imm_cPt_V4 :
1610 case Hexagon::STrih_imm_cNotPt_V4 :
1611 case Hexagon::STrih_indexed_shl_cPt_V4 :
1612 case Hexagon::STrih_indexed_shl_cNotPt_V4 :
1613 case Hexagon::POST_SThri_cPt :
1614 case Hexagon::POST_SThri_cNotPt :
1615 case Hexagon::STriw_cPt :
1616 case Hexagon::STriw_cNotPt :
1617 case Hexagon::STriw_indexed_cPt :
1618 case Hexagon::STriw_indexed_cNotPt :
1619 case Hexagon::STriw_imm_cPt_V4 :
1620 case Hexagon::STriw_imm_cNotPt_V4 :
1621 case Hexagon::STriw_indexed_shl_cPt_V4 :
1622 case Hexagon::STriw_indexed_shl_cNotPt_V4 :
1623 case Hexagon::POST_STwri_cPt :
1624 case Hexagon::POST_STwri_cNotPt :
1625 return QRI.Subtarget.hasV4TOps();
1627 // V4 global address store before promoting to dot new.
1628 case Hexagon::STd_GP_cPt_V4 :
1629 case Hexagon::STd_GP_cNotPt_V4 :
1630 case Hexagon::STb_GP_cPt_V4 :
1631 case Hexagon::STb_GP_cNotPt_V4 :
1632 case Hexagon::STh_GP_cPt_V4 :
1633 case Hexagon::STh_GP_cNotPt_V4 :
1634 case Hexagon::STw_GP_cPt_V4 :
1635 case Hexagon::STw_GP_cNotPt_V4 :
1636 return QRI.Subtarget.hasV4TOps();
1638 // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
1639 // from the "Conditional Store" list. Because a predicated new value store
1640 // would NOT be promoted to a double dot new store. See diagram below:
1641 // This function returns yes for those stores that are predicated but not
1642 // yet promoted to predicate dot new instructions.
1644 // +---------------------+
1645 // /-----| if (p0) memw(..)=r0 |---------\~
1646 // || +---------------------+ ||
1647 // promote || /\ /\ || promote
1649 // \||/ demote || \||/
1651 // +-------------------------+ || +-------------------------+
1652 // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
1653 // +-------------------------+ || +-------------------------+
1656 // promote || \/ NOT possible
1660 // +-----------------------------+
1661 // | if (p0.new) memw(..)=r0.new |
1662 // +-----------------------------+
1663 // Double Dot New Store
1669 bool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const {
1670 if (isNewValue(MI) && isBranch(MI))
1675 bool HexagonInstrInfo::isNewValue(const MachineInstr* MI) const {
1676 const uint64_t F = MI->getDesc().TSFlags;
1677 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
1680 // Returns true, if any one of the operands is a dot new
1681 // insn, whether it is predicated dot new or register dot new.
1682 bool HexagonInstrInfo::isDotNewInst (const MachineInstr* MI) const {
1683 return (isNewValueInst(MI) ||
1684 (isPredicated(MI) && isPredicatedNew(MI)));
1687 unsigned HexagonInstrInfo::getAddrMode(const MachineInstr* MI) const {
1688 const uint64_t F = MI->getDesc().TSFlags;
1690 return((F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask);
1693 /// immediateExtend - Changes the instruction in place to one using an immediate
1695 void HexagonInstrInfo::immediateExtend(MachineInstr *MI) const {
1696 assert((isExtendable(MI)||isConstExtended(MI)) &&
1697 "Instruction must be extendable");
1698 // Find which operand is extendable.
1699 short ExtOpNum = getCExtOpNum(MI);
1700 MachineOperand &MO = MI->getOperand(ExtOpNum);
1701 // This needs to be something we understand.
1702 assert((MO.isMBB() || MO.isImm()) &&
1703 "Branch with unknown extendable field type");
1704 // Mark given operand as extended.
1705 MO.addTargetFlag(HexagonII::HMOTF_ConstExtended);
1708 DFAPacketizer *HexagonInstrInfo::
1709 CreateTargetScheduleState(const TargetMachine *TM,
1710 const ScheduleDAG *DAG) const {
1711 const InstrItineraryData *II = TM->getInstrItineraryData();
1712 return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II);
1715 bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
1716 const MachineBasicBlock *MBB,
1717 const MachineFunction &MF) const {
1718 // Debug info is never a scheduling boundary. It's necessary to be explicit
1719 // due to the special treatment of IT instructions below, otherwise a
1720 // dbg_value followed by an IT will result in the IT instruction being
1721 // considered a scheduling hazard, which is wrong. It should be the actual
1722 // instruction preceding the dbg_value instruction(s), just like it is
1723 // when debug info is not present.
1724 if (MI->isDebugValue())
1727 // Terminators and labels can't be scheduled around.
1728 if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm())
1734 bool HexagonInstrInfo::isConstExtended(MachineInstr *MI) const {
1736 // Constant extenders are allowed only for V4 and above.
1737 if (!Subtarget.hasV4TOps())
1740 const uint64_t F = MI->getDesc().TSFlags;
1741 unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
1742 if (isExtended) // Instruction must be extended.
1745 unsigned isExtendable = (F >> HexagonII::ExtendablePos)
1746 & HexagonII::ExtendableMask;
1750 short ExtOpNum = getCExtOpNum(MI);
1751 const MachineOperand &MO = MI->getOperand(ExtOpNum);
1752 // Use MO operand flags to determine if MO
1753 // has the HMOTF_ConstExtended flag set.
1754 if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended)
1756 // If this is a Machine BB address we are talking about, and it is
1757 // not marked as extended, say so.
1761 // We could be using an instruction with an extendable immediate and shoehorn
1762 // a global address into it. If it is a global address it will be constant
1763 // extended. We do this for COMBINE.
1764 // We currently only handle isGlobal() because it is the only kind of
1765 // object we are going to end up with here for now.
1766 // In the future we probably should add isSymbol(), etc.
1767 if (MO.isGlobal() || MO.isSymbol())
1770 // If the extendable operand is not 'Immediate' type, the instruction should
1771 // have 'isExtended' flag set.
1772 assert(MO.isImm() && "Extendable operand must be Immediate type");
1774 int MinValue = getMinValue(MI);
1775 int MaxValue = getMaxValue(MI);
1776 int ImmValue = MO.getImm();
1778 return (ImmValue < MinValue || ImmValue > MaxValue);
1781 // Returns the opcode to use when converting MI, which is a conditional jump,
1782 // into a conditional instruction which uses the .new value of the predicate.
1783 // We also use branch probabilities to add a hint to the jump.
1785 HexagonInstrInfo::getDotNewPredJumpOp(MachineInstr *MI,
1787 MachineBranchProbabilityInfo *MBPI) const {
1789 // We assume that block can have at most two successors.
1791 MachineBasicBlock *Src = MI->getParent();
1792 MachineOperand *BrTarget = &MI->getOperand(1);
1793 MachineBasicBlock *Dst = BrTarget->getMBB();
1795 const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst);
1796 if (Prediction >= BranchProbability(1,2))
1799 switch (MI->getOpcode()) {
1800 case Hexagon::JMP_t:
1801 return taken ? Hexagon::JMP_tnew_t : Hexagon::JMP_tnew_nt;
1802 case Hexagon::JMP_f:
1803 return taken ? Hexagon::JMP_fnew_t : Hexagon::JMP_fnew_nt;
1806 llvm_unreachable("Unexpected jump instruction.");
1809 // Returns true if a particular operand is extendable for an instruction.
1810 bool HexagonInstrInfo::isOperandExtended(const MachineInstr *MI,
1811 unsigned short OperandNum) const {
1812 // Constant extenders are allowed only for V4 and above.
1813 if (!Subtarget.hasV4TOps())
1816 const uint64_t F = MI->getDesc().TSFlags;
1818 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
1822 // Returns Operand Index for the constant extended instruction.
1823 unsigned short HexagonInstrInfo::getCExtOpNum(const MachineInstr *MI) const {
1824 const uint64_t F = MI->getDesc().TSFlags;
1825 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
1828 // Returns the min value that doesn't need to be extended.
1829 int HexagonInstrInfo::getMinValue(const MachineInstr *MI) const {
1830 const uint64_t F = MI->getDesc().TSFlags;
1831 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
1832 & HexagonII::ExtentSignedMask;
1833 unsigned bits = (F >> HexagonII::ExtentBitsPos)
1834 & HexagonII::ExtentBitsMask;
1836 if (isSigned) // if value is signed
1837 return -1 << (bits - 1);
1842 // Returns the max value that doesn't need to be extended.
1843 int HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const {
1844 const uint64_t F = MI->getDesc().TSFlags;
1845 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
1846 & HexagonII::ExtentSignedMask;
1847 unsigned bits = (F >> HexagonII::ExtentBitsPos)
1848 & HexagonII::ExtentBitsMask;
1850 if (isSigned) // if value is signed
1851 return ~(-1 << (bits - 1));
1853 return ~(-1 << bits);
1856 // Returns true if an instruction can be converted into a non-extended
1857 // equivalent instruction.
1858 bool HexagonInstrInfo::NonExtEquivalentExists (const MachineInstr *MI) const {
1861 // Check if the instruction has a register form that uses register in place
1862 // of the extended operand, if so return that as the non-extended form.
1863 if (Hexagon::getRegForm(MI->getOpcode()) >= 0)
1866 if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) {
1867 // Check addressing mode and retreive non-ext equivalent instruction.
1869 switch (getAddrMode(MI)) {
1870 case HexagonII::Absolute :
1871 // Load/store with absolute addressing mode can be converted into
1872 // base+offset mode.
1873 NonExtOpcode = Hexagon::getBasedWithImmOffset(MI->getOpcode());
1875 case HexagonII::BaseImmOffset :
1876 // Load/store with base+offset addressing mode can be converted into
1877 // base+register offset addressing mode. However left shift operand should
1879 NonExtOpcode = Hexagon::getBaseWithRegOffset(MI->getOpcode());
1884 if (NonExtOpcode < 0)
1891 // Returns opcode of the non-extended equivalent instruction.
1892 short HexagonInstrInfo::getNonExtOpcode (const MachineInstr *MI) const {
1894 // Check if the instruction has a register form that uses register in place
1895 // of the extended operand, if so return that as the non-extended form.
1896 short NonExtOpcode = Hexagon::getRegForm(MI->getOpcode());
1897 if (NonExtOpcode >= 0)
1898 return NonExtOpcode;
1900 if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) {
1901 // Check addressing mode and retreive non-ext equivalent instruction.
1902 switch (getAddrMode(MI)) {
1903 case HexagonII::Absolute :
1904 return Hexagon::getBasedWithImmOffset(MI->getOpcode());
1905 case HexagonII::BaseImmOffset :
1906 return Hexagon::getBaseWithRegOffset(MI->getOpcode());
1914 bool HexagonInstrInfo::PredOpcodeHasJMP_c(Opcode_t Opcode) const {
1915 return (Opcode == Hexagon::JMP_t) ||
1916 (Opcode == Hexagon::JMP_f) ||
1917 (Opcode == Hexagon::JMP_tnew_t) ||
1918 (Opcode == Hexagon::JMP_fnew_t) ||
1919 (Opcode == Hexagon::JMP_tnew_nt) ||
1920 (Opcode == Hexagon::JMP_fnew_nt);
1923 bool HexagonInstrInfo::PredOpcodeHasNot(Opcode_t Opcode) const {
1924 return (Opcode == Hexagon::JMP_f) ||
1925 (Opcode == Hexagon::JMP_fnew_t) ||
1926 (Opcode == Hexagon::JMP_fnew_nt);