131d157ae1ac2cd9c787dc3c1d28e64c682803844Jia Liu//===-- HexagonInstrInfo.cpp - Hexagon Instruction Information ------------===// 2b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 3b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// The LLVM Compiler Infrastructure 4b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 5b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// This file is distributed under the University of Illinois Open Source 6b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// License. See LICENSE.TXT for details. 7b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 8b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum//===----------------------------------------------------------------------===// 9b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 10b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// This file contains the Hexagon implementation of the TargetInstrInfo class. 11b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 12b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum//===----------------------------------------------------------------------===// 13b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 14b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonInstrInfo.h" 15d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "Hexagon.h" 1679aa3417eb6f58d668aadfedf075240a41d35a26Craig Topper#include "HexagonRegisterInfo.h" 17b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonSubtarget.h" 18b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/ADT/STLExtras.h" 19b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/ADT/SmallVector.h" 20f3fd7ee415ec8a6475a060e29959d04d6158f45fBenjamin Kramer#include "llvm/CodeGen/DFAPacketizer.h" 21b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineFrameInfo.h" 22d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/CodeGen/MachineInstrBuilder.h" 23b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineMemOperand.h" 24d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/CodeGen/MachineRegisterInfo.h" 25b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/PseudoSourceValue.h" 266ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma#include "llvm/Support/Debug.h" 27f3fd7ee415ec8a6475a060e29959d04d6158f45fBenjamin Kramer#include "llvm/Support/MathExtras.h" 28aa35a569751eb79b2a2db31139932e30c6889400Reid Kleckner#include "llvm/Support/raw_ostream.h" 29b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#define GET_INSTRINFO_CTOR 308aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar#define GET_INSTRMAP_INFO 31b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonGenInstrInfo.inc" 32ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick#include "HexagonGenDFAPacketizer.inc" 33b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 34b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumusing namespace llvm; 35b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 36b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// 37b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// Constants for Hexagon instructions. 38b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// 39b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMW_OFFSET_MAX = 4095; 4026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMW_OFFSET_MIN = -4096; 41b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMD_OFFSET_MAX = 8191; 4226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMD_OFFSET_MIN = -8192; 43b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMH_OFFSET_MAX = 2047; 4426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMH_OFFSET_MIN = -2048; 45b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMB_OFFSET_MAX = 1023; 4626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMB_OFFSET_MIN = -1024; 47b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_ADDI_OFFSET_MAX = 32767; 4826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_ADDI_OFFSET_MIN = -32768; 49b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMD_AUTOINC_MAX = 56; 5026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMD_AUTOINC_MIN = -64; 51b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMW_AUTOINC_MAX = 28; 5226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMW_AUTOINC_MIN = -32; 53b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMH_AUTOINC_MAX = 14; 5426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMH_AUTOINC_MIN = -16; 55b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst int Hexagon_MEMB_AUTOINC_MAX = 7; 5626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandeconst int Hexagon_MEMB_AUTOINC_MIN = -8; 57b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 58b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 59b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST) 60b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP), 6154a56fad36a32f12709da5f96998336f08524be9Bill Wendling RI(ST), Subtarget(ST) { 62b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 63b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 64b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 65b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// isLoadFromStackSlot - If the specified machine instruction is a direct 66b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// load from a stack slot, return the virtual or physical register number of 67b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// the destination along with the FrameIndex of the loaded stack slot. If 68b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// not, return 0. This predicate must return 0 if the instruction has 69b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// any side effects other than loading from the stack slot. 70b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, 71b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int &FrameIndex) const { 72b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 73b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 74b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch (MI->getOpcode()) { 7526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: break; 76b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw: 77b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid: 78b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih: 79b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib: 80b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub: 81b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (MI->getOperand(2).isFI() && 82b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) { 83b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum FrameIndex = MI->getOperand(2).getIndex(); 84b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return MI->getOperand(0).getReg(); 85b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 86b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum break; 87b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 88b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 0; 89b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 90b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 91b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 92b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// isStoreToStackSlot - If the specified machine instruction is a direct 93b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// store to a stack slot, return the virtual or physical register number of 94b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// the source reg along with the FrameIndex of the loaded stack slot. If 95b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// not, return 0. This predicate must return 0 if the instruction has 96b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum/// any side effects other than storing to the stack slot. 97b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI, 98b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int &FrameIndex) const { 99b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch (MI->getOpcode()) { 10026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: break; 101b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw: 102b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrid: 103b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrih: 104b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrib: 105b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (MI->getOperand(2).isFI() && 106b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) { 1072b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande FrameIndex = MI->getOperand(0).getIndex(); 1082b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande return MI->getOperand(2).getReg(); 109b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 110b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum break; 111b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 112b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 0; 113b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 114b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 115b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 116b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned 117b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB, 118b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock *FBB, 119b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const SmallVectorImpl<MachineOperand> &Cond, 120b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum DebugLoc DL) const{ 121b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 122b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int BOpc = Hexagon::JMP; 1236ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma int BccOpc = Hexagon::JMP_t; 124b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 125b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(TBB && "InsertBranch must not be told to insert a fallthrough"); 126b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 127b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int regPos = 0; 128b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Check if ReverseBranchCondition has asked to reverse this branch 129b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If we want to reverse the branch an odd number of times, we want 1306ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma // JMP_f. 131b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) { 1326ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma BccOpc = Hexagon::JMP_f; 133b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum regPos = 1; 134b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 135b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 136b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (FBB == 0) { 137b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (Cond.empty()) { 138b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Due to a bug in TailMerging/CFG Optimization, we need to add a 139b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // special case handling of a predicated jump followed by an 140b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // unconditional jump. If not, Tail Merging and CFG Optimization go 141b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // into an infinite loop. 142b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock *NewTBB, *NewFBB; 143b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum SmallVector<MachineOperand, 4> Cond; 144b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineInstr *Term = MBB.getFirstTerminator(); 145b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond, 146b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum false)) { 147b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock *NextBB = 148b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum llvm::next(MachineFunction::iterator(&MBB)); 149b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (NewTBB == NextBB) { 150b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum ReverseBranchCondition(Cond); 151b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum RemoveBranch(MBB); 152b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return InsertBranch(MBB, TBB, 0, Cond, DL); 153b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 154b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 155b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB); 156b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 157b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(&MBB, DL, 158b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB); 159b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 160b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 1; 161b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 162b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 163b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB); 164b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB); 165b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 166b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 2; 167b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 168b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 169b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 170b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, 171b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock *&TBB, 172b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock *&FBB, 173b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum SmallVectorImpl<MachineOperand> &Cond, 174b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum bool AllowModify) const { 17551b49c52926d65e6fe84e32894f1a8dd32223babBenjamin Kramer TBB = NULL; 176b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum FBB = NULL; 177b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 178b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If the block has no terminators, it just falls into the block after it. 1796ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma MachineBasicBlock::instr_iterator I = MBB.instr_end(); 1806ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (I == MBB.instr_begin()) 181b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 182b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 183b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // A basic block may looks like this: 184b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 185b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // [ insn 186b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // EH_LABEL 187b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // insn 188b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // insn 189b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // insn 190b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // EH_LABEL 191b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // insn ] 192b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 193b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // It has two succs but does not have a terminator 194b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Don't know how to handle it. 195b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum do { 196b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum --I; 197b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (I->isEHLabel()) 198b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1996ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma } while (I != MBB.instr_begin()); 200b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 2016ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma I = MBB.instr_end(); 202b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum --I; 203b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 204b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum while (I->isDebugValue()) { 2056ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (I == MBB.instr_begin()) 2066ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma return false; 2076ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma --I; 2086ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma } 2096ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma 2106ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma // Delete the JMP if it's equivalent to a fall-through. 2116ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (AllowModify && I->getOpcode() == Hexagon::JMP && 2126ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) { 2136ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma DEBUG(dbgs()<< "\nErasing the jump to successor block\n";); 2146ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma I->eraseFromParent(); 2156ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma I = MBB.instr_end(); 2166ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (I == MBB.instr_begin()) 217b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 218b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum --I; 219b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 220b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!isUnpredicatedTerminator(I)) 221b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 222b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 223b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Get the last instruction in the block. 224b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineInstr *LastInst = I; 2256ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma MachineInstr *SecondLastInst = NULL; 2266ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma // Find one more terminator if present. 2276ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma do { 2286ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(I)) { 2296ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (!SecondLastInst) 2306ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma SecondLastInst = I; 2316ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma else 2326ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma // This is a third branch. 2336ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma return true; 2346ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma } 2356ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (I == MBB.instr_begin()) 2366ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma break; 2376ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma --I; 2386ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma } while(I); 2396ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma 2406ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma int LastOpcode = LastInst->getOpcode(); 2416ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma 2426ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode); 2436ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma bool LastOpcodeHasNot = PredOpcodeHasNot(LastOpcode); 244b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 245b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If there is only one terminator instruction, process it. 2466ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (LastInst && !SecondLastInst) { 2476ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (LastOpcode == Hexagon::JMP) { 248b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TBB = LastInst->getOperand(0).getMBB(); 249b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 250b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 2516ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (LastOpcode == Hexagon::ENDLOOP0) { 2526ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma TBB = LastInst->getOperand(0).getMBB(); 253b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Cond.push_back(LastInst->getOperand(0)); 254b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 255b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 2566ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (LastOpcodeHasJMP_c) { 257b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TBB = LastInst->getOperand(1).getMBB(); 2586ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (LastOpcodeHasNot) { 2596ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma Cond.push_back(MachineOperand::CreateImm(0)); 2606ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma } 261b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Cond.push_back(LastInst->getOperand(0)); 262b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 263b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 264b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Otherwise, don't know what this is. 265b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 266b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 267b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 2686ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma int SecLastOpcode = SecondLastInst->getOpcode(); 269b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 2706ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode); 2716ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma bool SecLastOpcodeHasNot = PredOpcodeHasNot(SecLastOpcode); 2726ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::JMP)) { 273b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TBB = SecondLastInst->getOperand(1).getMBB(); 2746ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (SecLastOpcodeHasNot) 2756ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma Cond.push_back(MachineOperand::CreateImm(0)); 276b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Cond.push_back(SecondLastInst->getOperand(0)); 277b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum FBB = LastInst->getOperand(0).getMBB(); 278b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 279b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 280b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 281b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If the block ends with two Hexagon:JMPs, handle it. The second one is not 282b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // executed, so remove it. 2836ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (SecLastOpcode == Hexagon::JMP && LastOpcode == Hexagon::JMP) { 284b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TBB = SecondLastInst->getOperand(0).getMBB(); 285b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum I = LastInst; 286b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (AllowModify) 287b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum I->eraseFromParent(); 288b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 289b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 290b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 2916ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma // If the block ends with an ENDLOOP, and JMP, handle it. 2926ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma if (SecLastOpcode == Hexagon::ENDLOOP0 && 2936ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma LastOpcode == Hexagon::JMP) { 2946ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma TBB = SecondLastInst->getOperand(0).getMBB(); 2956ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma Cond.push_back(SecondLastInst->getOperand(0)); 2966ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma FBB = LastInst->getOperand(0).getMBB(); 2976ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma return false; 2986ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma } 2996ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma 300b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Otherwise, can't handle this. 301b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 302b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 303b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 304b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 305b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { 306b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int BOpc = Hexagon::JMP; 3076ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma int BccOpc = Hexagon::JMP_t; 3086ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma int BccOpcNot = Hexagon::JMP_f; 309b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 310b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock::iterator I = MBB.end(); 311b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (I == MBB.begin()) return 0; 312b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum --I; 313b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc && 314b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum I->getOpcode() != BccOpcNot) 315b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 0; 316b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 317b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Remove the branch. 318b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum I->eraseFromParent(); 319b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 320b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum I = MBB.end(); 321b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 322b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (I == MBB.begin()) return 1; 323b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum --I; 324b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot) 325b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 1; 326b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 327b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Remove the branch. 328b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum I->eraseFromParent(); 329b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 2; 330b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 331b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 332b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 333ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek/// \brief For a comparison instruction, return the source registers in 334ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it 335ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek/// compares against in CmpValue. Return true if the comparison instruction 336ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek/// can be analyzed. 337ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszekbool HexagonInstrInfo::analyzeCompare(const MachineInstr *MI, 338ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek unsigned &SrcReg, unsigned &SrcReg2, 339ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek int &Mask, int &Value) const { 340ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek unsigned Opc = MI->getOpcode(); 341ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek 342ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek // Set mask and the first source register. 343ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek switch (Opc) { 344ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPEHexagon4rr: 345ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPEQri: 346ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPEQrr: 347ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGT64rr: 348ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTU64rr: 349ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTUri: 350ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTUrr: 351ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTri: 352ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTrr: 353ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek SrcReg = MI->getOperand(1).getReg(); 354ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek Mask = ~0; 355ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek break; 356ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbEQri_V4: 357ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbEQrr_sbsb_V4: 358ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbEQrr_ubub_V4: 359ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbGTUri_V4: 360ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbGTUrr_V4: 361ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbGTrr_V4: 362ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek SrcReg = MI->getOperand(1).getReg(); 363ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek Mask = 0xFF; 364ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek break; 365ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhEQri_V4: 366ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhEQrr_shl_V4: 367ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhEQrr_xor_V4: 368ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhGTUri_V4: 369ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhGTUrr_V4: 370ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhGTrr_shl_V4: 371ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek SrcReg = MI->getOperand(1).getReg(); 372ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek Mask = 0xFFFF; 373ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek break; 374ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek } 375ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek 376ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek // Set the value/second source register. 377ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek switch (Opc) { 378ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPEHexagon4rr: 379ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPEQrr: 380ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGT64rr: 381ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTU64rr: 382ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTUrr: 383ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTrr: 384ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbEQrr_sbsb_V4: 385ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbEQrr_ubub_V4: 386ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbGTUrr_V4: 387ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbGTrr_V4: 388ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhEQrr_shl_V4: 389ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhEQrr_xor_V4: 390ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhGTUrr_V4: 391ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhGTrr_shl_V4: 392ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek SrcReg2 = MI->getOperand(2).getReg(); 393ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek return true; 394ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek 395ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPEQri: 396ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTUri: 397ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPGTri: 398ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbEQri_V4: 399ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPbGTUri_V4: 400ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhEQri_V4: 401ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek case Hexagon::CMPhGTUri_V4: 402ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek SrcReg2 = 0; 403ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek Value = MI->getOperand(2).getImm(); 404ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek return true; 405ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek } 406ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek 407ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek return false; 408ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek} 409ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek 410ce55d91ec97b1227cb4cb94354c89452d787515eKrzysztof Parzyszek 411b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB, 412b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock::iterator I, DebugLoc DL, 413b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned DestReg, unsigned SrcReg, 414b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum bool KillSrc) const { 415b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) { 416b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg); 417b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return; 418b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 419b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) { 420b53b791efd85e9278baacb29745217dfa2eae775Jyotsna Verma BuildMI(MBB, I, DL, get(Hexagon::TFR64), DestReg).addReg(SrcReg); 421b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return; 422b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 423b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) { 424b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Map Pd = Ps to Pd = or(Ps, Ps). 425b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::OR_pp), 426b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum DestReg).addReg(SrcReg).addReg(SrcReg); 427b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return; 428b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 4292b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande if (Hexagon::DoubleRegsRegClass.contains(DestReg) && 4302b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande Hexagon::IntRegsRegClass.contains(SrcReg)) { 431b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // We can have an overlap between single and double reg: r1:0 = r0. 432b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) { 433b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r1:0 = r0 434b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg, 435b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::subreg_hireg))).addImm(0); 436b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 437b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r1:0 = r1 or no overlap. 438b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg, 439b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::subreg_loreg))).addReg(SrcReg); 440b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg, 441b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::subreg_hireg))).addImm(0); 442b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 443b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return; 444b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 4452b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande if (Hexagon::CRRegsRegClass.contains(DestReg) && 4462b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande Hexagon::IntRegsRegClass.contains(SrcReg)) { 447b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg); 448b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return; 449ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande } 450666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta if (Hexagon::PredRegsRegClass.contains(SrcReg) && 451666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta Hexagon::IntRegsRegClass.contains(DestReg)) { 452666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta BuildMI(MBB, I, DL, get(Hexagon::TFR_RsPd), DestReg). 453666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta addReg(SrcReg, getKillRegState(KillSrc)); 454666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta return; 455666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta } 456666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta if (Hexagon::IntRegsRegClass.contains(SrcReg) && 457666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta Hexagon::PredRegsRegClass.contains(DestReg)) { 458666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta BuildMI(MBB, I, DL, get(Hexagon::TFR_PdRs), DestReg). 459666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta addReg(SrcReg, getKillRegState(KillSrc)); 460666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta return; 461666e0d3bc4a28540c1aa73b24573af70d1d46aeaAnshuman Dasgupta } 462ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande 463ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande llvm_unreachable("Unimplemented"); 464b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 465b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 466b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 467b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonInstrInfo:: 468b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumstoreRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, 469b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned SrcReg, bool isKill, int FI, 470b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterClass *RC, 471b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterInfo *TRI) const { 472b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 473b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum DebugLoc DL = MBB.findDebugLoc(I); 474b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFunction &MF = *MBB.getParent(); 475b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFrameInfo &MFI = *MF.getFrameInfo(); 476b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned Align = MFI.getObjectAlignment(FI); 477b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 478b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineMemOperand *MMO = 479b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MF.getMachineMemOperand( 480b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)), 481b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineMemOperand::MOStore, 482b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MFI.getObjectSize(FI), 483b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Align); 484b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 485420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) { 4865262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon BuildMI(MBB, I, DL, get(Hexagon::STriw)) 487b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addFrameIndex(FI).addImm(0) 488b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO); 489420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) { 490b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::STrid)) 491b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addFrameIndex(FI).addImm(0) 492b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO); 493420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) { 494b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::STriw_pred)) 495b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addFrameIndex(FI).addImm(0) 496b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO); 497b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 498bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("Unimplemented"); 499b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 500b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 501b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 502b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 503b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonInstrInfo::storeRegToAddr( 504b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFunction &MF, unsigned SrcReg, 505b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum bool isKill, 506b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum SmallVectorImpl<MachineOperand> &Addr, 507b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterClass *RC, 508b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum SmallVectorImpl<MachineInstr*> &NewMIs) const 509b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum{ 510bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("Unimplemented"); 511b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 512b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 513b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 514b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonInstrInfo:: 515b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumloadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, 516b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned DestReg, int FI, 517b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterClass *RC, 518b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterInfo *TRI) const { 519b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum DebugLoc DL = MBB.findDebugLoc(I); 520b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFunction &MF = *MBB.getParent(); 521b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFrameInfo &MFI = *MF.getFrameInfo(); 522b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned Align = MFI.getObjectAlignment(FI); 523b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 524b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineMemOperand *MMO = 525b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MF.getMachineMemOperand( 526b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)), 527b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineMemOperand::MOLoad, 528b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MFI.getObjectSize(FI), 529b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Align); 530420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper if (RC == &Hexagon::IntRegsRegClass) { 531b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg) 532b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addFrameIndex(FI).addImm(0).addMemOperand(MMO); 533420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper } else if (RC == &Hexagon::DoubleRegsRegClass) { 534b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg) 535b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addFrameIndex(FI).addImm(0).addMemOperand(MMO); 536420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper } else if (RC == &Hexagon::PredRegsRegClass) { 537b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg) 538b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum .addFrameIndex(FI).addImm(0).addMemOperand(MMO); 539b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 540bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("Can't store this register to stack slot"); 541b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 542b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 543b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 544b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 545b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg, 546b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum SmallVectorImpl<MachineOperand> &Addr, 547b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterClass *RC, 548b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum SmallVectorImpl<MachineInstr*> &NewMIs) const { 549bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("Unimplemented"); 550b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 551b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 552b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 553b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumMachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF, 554b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineInstr* MI, 555b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const SmallVectorImpl<unsigned> &Ops, 556b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int FI) const { 557b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Hexagon_TODO: Implement. 558b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return(0); 559b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 560b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 561b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const { 562b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 563b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineRegisterInfo &RegInfo = MF->getRegInfo(); 564b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterClass *TRC; 5657517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande if (VT == MVT::i1) { 566420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper TRC = &Hexagon::PredRegsRegClass; 5677517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande } else if (VT == MVT::i32 || VT == MVT::f32) { 568420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper TRC = &Hexagon::IntRegsRegClass; 5697517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande } else if (VT == MVT::i64 || VT == MVT::f64) { 570420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper TRC = &Hexagon::DoubleRegsRegClass; 5717517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande } else { 57227baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer llvm_unreachable("Cannot handle this register class"); 5737517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande } 574b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 575b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned NewReg = RegInfo.createVirtualRegister(TRC); 576b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return NewReg; 577b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 578b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 57926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandebool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const { 5809feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // Constant extenders are allowed only for V4 and above. 5819feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma if (!Subtarget.hasV4TOps()) 5829feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return false; 58326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 5849feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma const MCInstrDesc &MID = MI->getDesc(); 5859feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma const uint64_t F = MID.TSFlags; 5869feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask) 5879feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return true; 58826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 5899feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // TODO: This is largely obsolete now. Will need to be removed 5909feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // in consecutive patches. 5919feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma switch(MI->getOpcode()) { 5929feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // TFR_FI Remains a special case. 59326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFR_FI: 59426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return true; 5959feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma default: 5969feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return false; 59726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande } 5989feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return false; 59926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande} 60026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 6019feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma// This returns true in two cases: 6029feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma// - The OP code itself indicates that this is an extended instruction. 6039feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma// - One of MOs has been marked with HMOTF_ConstExtended flag. 60426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandebool HexagonInstrInfo::isExtended(const MachineInstr *MI) const { 6059feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // First check if this is permanently extended op code. 6069feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 6079feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask) 6089feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return true; 6099feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // Use MO operand flags to determine if one of MI's operands 6109feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma // has HMOTF_ConstExtended flag set. 6119feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma for (MachineInstr::const_mop_iterator I = MI->operands_begin(), 6129feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma E = MI->operands_end(); I != E; ++I) { 6139feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended) 6147517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande return true; 61526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande } 6169feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return false; 61726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande} 61826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 6191a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isBranch (const MachineInstr *MI) const { 6201a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return MI->getDesc().isBranch(); 62126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande} 62226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 6239feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Vermabool HexagonInstrInfo::isNewValueInst(const MachineInstr *MI) const { 6249feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma if (isNewValueJump(MI)) 6259feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return true; 6269feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma 6279feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma if (isNewValueStore(MI)) 6289feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return true; 6299feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma 6309feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma return false; 6319feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma} 6329feabc23b39d90f8bf9ab5ac23f5a7f8af71480aJyotsna Verma 63326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandebool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const { 63426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4; 63526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande} 636ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick 637b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo::isPredicable(MachineInstr *MI) const { 638b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum bool isPred = MI->getDesc().isPredicable(); 639b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 640b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!isPred) 641b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 642b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 643b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const int Opc = MI->getOpcode(); 644b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 645b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Opc) { 646b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::TFRI: 6475262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isInt<12>(MI->getOperand(1).getImm()); 648b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 649b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrid: 650b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrid_indexed: 6515262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedUInt<6,3>(MI->getOperand(1).getImm()); 652b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 653b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw: 654b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw_indexed: 655b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw_nv_V4: 6565262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedUInt<6,2>(MI->getOperand(1).getImm()); 657b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 658b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrih: 659b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrih_indexed: 660b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrih_nv_V4: 6615262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedUInt<6,1>(MI->getOperand(1).getImm()); 662b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 663b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrib: 664b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrib_indexed: 665b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrib_nv_V4: 6665262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isUInt<6>(MI->getOperand(1).getImm()); 667b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 668b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid: 669b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_indexed: 6705262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedUInt<6,3>(MI->getOperand(2).getImm()); 671b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 672b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw: 673b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_indexed: 6745262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedUInt<6,2>(MI->getOperand(2).getImm()); 675b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 676b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih: 677b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh: 678b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_indexed: 679b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_indexed: 6805262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedUInt<6,1>(MI->getOperand(2).getImm()); 681b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 682b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib: 683b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub: 684b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_indexed: 685b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_indexed: 6865262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isUInt<6>(MI->getOperand(2).getImm()); 687b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 688b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrid: 6895262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedInt<4,3>(MI->getOperand(3).getImm()); 690b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 691b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriw: 6925262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedInt<4,2>(MI->getOperand(3).getImm()); 693b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 694b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrih: 695b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriuh: 6965262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isShiftedInt<4,1>(MI->getOperand(3).getImm()); 697b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 698b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrib: 699b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriub: 7005262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isInt<4>(MI->getOperand(3).getImm()); 701b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 702b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrib_imm_V4: 703b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrih_imm_V4: 704b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw_imm_V4: 7055262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return (isUInt<6>(MI->getOperand(1).getImm()) && 7065262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon isInt<6>(MI->getOperand(2).getImm())); 707b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 708b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ADD_ri: 7095262abb2682a4d09cda3563a55f27caffb57466cBrendon Cahoon return isInt<8>(MI->getOperand(2).getImm()); 710b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 711b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ASLH: 712b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ASRH: 713b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SXTB: 714b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SXTH: 715b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ZXTB: 716b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ZXTH: 7172b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande return Subtarget.hasV4TOps(); 718b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 719b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 720b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 721b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 722b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 7232b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande// This function performs the following inversiones: 7242b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande// 7252b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande// cPt ---> cNotPt 7262b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande// cNotPt ---> cPt 7272b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande// 728ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pandeunsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const { 7291a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma int InvPredOpcode; 7301a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc) 7311a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma : Hexagon::getTruePredOpcode(Opc); 7321a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate. 7331a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return InvPredOpcode; 7341a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 735ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande switch(Opc) { 73626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: llvm_unreachable("Unexpected predicated instruction"); 737ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande case Hexagon::COMBINE_rr_cPt: 738ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande return Hexagon::COMBINE_rr_cNotPt; 739ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande case Hexagon::COMBINE_rr_cNotPt: 740ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande return Hexagon::COMBINE_rr_cPt; 741ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande 742f4f60b10e4ccd14511f5c83f4e83dbcad6740f63Jyotsna Verma // Dealloc_return. 743ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande case Hexagon::DEALLOC_RET_cPt_V4: 744ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande return Hexagon::DEALLOC_RET_cNotPt_V4; 745ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande case Hexagon::DEALLOC_RET_cNotPt_V4: 746ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande return Hexagon::DEALLOC_RET_cPt_V4; 747ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande } 748ab7955b9ce3197215406bc9fc97b22074127d035Sirish Pande} 749b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 7501a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma// New Value Store instructions. 7511a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Vermabool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const { 7521a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 7531a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 7541a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return ((F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask); 7551a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma} 7561a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 7571a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Vermabool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const { 7581a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma const uint64_t F = get(Opcode).TSFlags; 7591a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 7601a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return ((F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask); 7611a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma} 762ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick 763b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumint HexagonInstrInfo:: 764b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumgetMatchingCondBranchOpcode(int Opc, bool invertPredicate) const { 7658aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar enum Hexagon::PredSense inPredSense; 7668aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar inPredSense = invertPredicate ? Hexagon::PredSense_false : 7678aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar Hexagon::PredSense_true; 7688aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense); 7698aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar if (CondOpcode >= 0) // Valid Conditional opcode/instruction 7708aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar return CondOpcode; 7718aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar 7728aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar // This switch case will be removed once all the instructions have been 7738aa138c12282e8bccac665f2197e817e32c2adcfPranav Bhandarkar // modified to use relation maps. 774b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Opc) { 7757517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case Hexagon::TFRI_f: 7767517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande return !invertPredicate ? Hexagon::TFRI_cPt_f : 7777517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande Hexagon::TFRI_cNotPt_f; 778b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::COMBINE_rr: 779b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return !invertPredicate ? Hexagon::COMBINE_rr_cPt : 780b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::COMBINE_rr_cNotPt; 781f4f60b10e4ccd14511f5c83f4e83dbcad6740f63Jyotsna Verma 782b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Word. 783f4f60b10e4ccd14511f5c83f4e83dbcad6740f63Jyotsna Verma case Hexagon::STriw_f: 784b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return !invertPredicate ? Hexagon::STriw_cPt : 785b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::STriw_cNotPt; 786f4f60b10e4ccd14511f5c83f4e83dbcad6740f63Jyotsna Verma case Hexagon::STriw_indexed_f: 787b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return !invertPredicate ? Hexagon::STriw_indexed_cPt : 788b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::STriw_indexed_cNotPt; 789f4f60b10e4ccd14511f5c83f4e83dbcad6740f63Jyotsna Verma 790b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // DEALLOC_RETURN. 791b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_V4: 792b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 : 793b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::DEALLOC_RET_cNotPt_V4; 794b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 79527baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer llvm_unreachable("Unexpected predicable instruction"); 796b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 797b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 798b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 799b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 800b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumPredicateInstruction(MachineInstr *MI, 801b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const SmallVectorImpl<MachineOperand> &Cond) const { 802b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int Opc = MI->getOpcode(); 803b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert (isPredicable(MI) && "Expected predicable instruction"); 804b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum bool invertJump = (!Cond.empty() && Cond[0].isImm() && 805b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Cond[0].getImm() == 0)); 8066b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8076b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // This will change MI's opcode to its predicate version. 8086b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // However, its operand list is still the old one, i.e. the 8096b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // non-predicate one. 810b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump))); 811b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 8126b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma int oper = -1; 8136b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma unsigned int GAIdx = 0; 8146b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8156b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Indicates whether the current MI has a GlobalAddress operand 8166b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma bool hasGAOpnd = false; 8176b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma std::vector<MachineOperand> tmpOpnds; 8186b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8196b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Indicates whether we need to shift operands to right. 8206b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma bool needShift = true; 8216b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8226b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // The predicate is ALWAYS the FIRST input operand !!! 8236b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma if (MI->getNumOperands() == 0) { 8246b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // The non-predicate version of MI does not take any operands, 8256b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // i.e. no outs and no ins. In this condition, the predicate 8266b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // operand will be directly placed at Operands[0]. No operand 8276b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // shift is needed. 8286b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Example: BARRIER 8296b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma needShift = false; 8306b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma oper = -1; 8316b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8326b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma else if ( MI->getOperand(MI->getNumOperands()-1).isReg() 8336b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma && MI->getOperand(MI->getNumOperands()-1).isDef() 8346b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma && !MI->getOperand(MI->getNumOperands()-1).isImplicit()) { 8356b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // The non-predicate version of MI does not have any input operands. 8366b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // In this condition, we extend the length of Operands[] by one and 8376b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // copy the original last operand to the newly allocated slot. 8386b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // At this moment, it is just a place holder. Later, we will put 8396b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // predicate operand directly into it. No operand shift is needed. 8406b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Example: r0=BARRIER (this is a faked insn used here for illustration) 8416b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MI->addOperand(MI->getOperand(MI->getNumOperands()-1)); 8426b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma needShift = false; 8436b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma oper = MI->getNumOperands() - 2; 8446b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8456b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma else { 8466b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // We need to right shift all input operands by one. Duplicate the 8476b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // last operand into the newly allocated slot. 8486b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MI->addOperand(MI->getOperand(MI->getNumOperands()-1)); 8496b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8506b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8516b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma if (needShift) 8526b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma { 8536b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[ MI->getNumOperands() - 2 ] has been copied into 8546b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[ MI->getNumOperands() - 1 ], so we start from 8556b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[ MI->getNumOperands() - 3 ]. 8566b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // oper is a signed int. 8576b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // It is ok if "MI->getNumOperands()-3" is -3, -2, or -1. 8586b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma for (oper = MI->getNumOperands() - 3; oper >= 0; --oper) 8596b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma { 8606b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MachineOperand &MO = MI->getOperand(oper); 8616b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8626b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Opnd[0] Opnd[1] Opnd[2] Opnd[3] Opnd[4] Opnd[5] Opnd[6] Opnd[7] 8636b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // <Def0> <Def1> <Use0> <Use1> <ImpDef0> <ImpDef1> <ImpUse0> <ImpUse1> 8646b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // /\~ 8656b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // /||\~ 8666b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // || 8676b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Predicate Operand here 8686b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma if (MO.isReg() && !MO.isUse() && !MO.isImplicit()) { 8696b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma break; 8706b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8716b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma if (MO.isReg()) { 8726b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(), 8736b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MO.isImplicit(), MO.isKill(), 8746b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MO.isDead(), MO.isUndef(), 8756b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MO.isDebug()); 8766b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8776b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma else if (MO.isImm()) { 8786b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MI->getOperand(oper+1).ChangeToImmediate(MO.getImm()); 8796b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8806b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma else if (MO.isGlobal()) { 8816b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // MI can not have more than one GlobalAddress operand. 8826b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma assert(hasGAOpnd == false && "MI can only have one GlobalAddress opnd"); 8836b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8846b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // There is no member function called "ChangeToGlobalAddress" in the 8856b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // MachineOperand class (not like "ChangeToRegister" and 8866b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // "ChangeToImmediate"). So we have to remove them from Operands[] list 8876b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // first, and then add them back after we have inserted the predicate 8886b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // operand. tmpOpnds[] is to remember these operands before we remove 8896b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // them. 8906b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma tmpOpnds.push_back(MO); 8916b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 8926b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[oper] is a GlobalAddress operand; 8936b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[oper+1] has been copied into Operands[oper+2]; 8946b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma hasGAOpnd = true; 8956b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma GAIdx = oper; 8966b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma continue; 8976b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 8986b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma else { 8996b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma assert(false && "Unexpected operand type"); 9006b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 901b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 902b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 903b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 904b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int regPos = invertJump ? 1 : 0; 905b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineOperand PredMO = Cond[regPos]; 9066b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 9076b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // [oper] now points to the last explicit Def. Predicate operand must be 9086b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // located at [oper+1]. See diagram above. 9096b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // This assumes that the predicate is always the first operand, 9106b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // i.e. Operands[0+numResults], in the set of inputs 9116b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // It is better to have an assert here to check this. But I don't know how 9126b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // to write this assert because findFirstPredOperandIdx() would return -1 9136b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma if (oper < -1) oper = -1; 914f9759c9f08af056ca6a496d846dd06656b6f1d9bJyotsna Verma 915b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(), 916f9759c9f08af056ca6a496d846dd06656b6f1d9bJyotsna Verma PredMO.isImplicit(), false, 917b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum PredMO.isDead(), PredMO.isUndef(), 918b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum PredMO.isDebug()); 919b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 920f9759c9f08af056ca6a496d846dd06656b6f1d9bJyotsna Verma MachineRegisterInfo &RegInfo = MI->getParent()->getParent()->getRegInfo(); 921f9759c9f08af056ca6a496d846dd06656b6f1d9bJyotsna Verma RegInfo.clearKillFlags(PredMO.getReg()); 922f9759c9f08af056ca6a496d846dd06656b6f1d9bJyotsna Verma 9236b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma if (hasGAOpnd) 9246b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma { 9256b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma unsigned int i; 9266b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 9276b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[GAIdx] is the original GlobalAddress operand, which is 9286b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // already copied into tmpOpnds[0]. 9296b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[GAIdx] now stores a copy of Operands[GAIdx-1] 9306b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Operands[GAIdx+1] has already been copied into Operands[GAIdx+2], 9316b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // so we start from [GAIdx+2] 9326b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma for (i = GAIdx + 2; i < MI->getNumOperands(); ++i) 9336b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma tmpOpnds.push_back(MI->getOperand(i)); 9346b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 9356b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // Remove all operands in range [ (GAIdx+1) ... (MI->getNumOperands()-1) ] 9366b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // It is very important that we always remove from the end of Operands[] 9376b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma // MI->getNumOperands() is at least 2 if program goes to here. 9386b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma for (i = MI->getNumOperands() - 1; i > GAIdx; --i) 9396b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MI->RemoveOperand(i); 9406b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 9416b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma for (i = 0; i < tmpOpnds.size(); ++i) 9426b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma MI->addOperand(tmpOpnds[i]); 9436b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma } 9446b8d2026ba0b60a317fa239eacbcaeff5f2270f0Jyotsna Verma 945b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 946b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 947b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 948b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 949b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool 950b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonInstrInfo:: 951b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisProfitableToIfCvt(MachineBasicBlock &MBB, 952575e90e955064f60ac66230dce6c27653973c149Kay Tiong Khoo unsigned NumCycles, 953b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned ExtraPredCycles, 954b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const BranchProbability &Probability) const { 955b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 956b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 957b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 958b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 959b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool 960b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonInstrInfo:: 961b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisProfitableToIfCvt(MachineBasicBlock &TMBB, 962b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned NumTCycles, 963b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned ExtraTCycles, 964b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock &FMBB, 965b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned NumFCycles, 966b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned ExtraFCycles, 967b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const BranchProbability &Probability) const { 968b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 969b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 970b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 9711a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma// Returns true if an instruction is predicated irrespective of the predicate 9721a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma// sense. For example, all of the following will return true. 9731a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma// if (p0) R1 = add(R2, R3) 9741a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma// if (!p0) R1 = add(R2, R3) 9751a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma// if (p0.new) R1 = add(R2, R3) 9761a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma// if (!p0.new) R1 = add(R2, R3) 977b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const { 978c635ebdb1a366060fe71ef3028ae888fa5e4130dBrendon Cahoon const uint64_t F = MI->getDesc().TSFlags; 979b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 980c635ebdb1a366060fe71ef3028ae888fa5e4130dBrendon Cahoon return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); 981b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 982b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 9831a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isPredicated(unsigned Opcode) const { 9841a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma const uint64_t F = get(Opcode).TSFlags; 9851a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 9861a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); 9871a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma} 9881a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 9891a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isPredicatedTrue(const MachineInstr *MI) const { 9901a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 9911a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 9921a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma assert(isPredicated(MI)); 9931a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return (!((F >> HexagonII::PredicatedFalsePos) & 9941a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma HexagonII::PredicatedFalseMask)); 9951a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma} 9961a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 9971a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const { 9981a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma const uint64_t F = get(Opcode).TSFlags; 9991a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 10001a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma // Make sure that the instruction is predicated. 10011a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma assert((F>> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); 10021a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return (!((F >> HexagonII::PredicatedFalsePos) & 10031a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma HexagonII::PredicatedFalseMask)); 10041a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma} 10051a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 1006810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Vermabool HexagonInstrInfo::isPredicatedNew(const MachineInstr *MI) const { 1007810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1008810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma 1009810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma assert(isPredicated(MI)); 1010810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask); 1011810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma} 1012810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma 10131a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const { 10141a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma const uint64_t F = get(Opcode).TSFlags; 10151a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 10161a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma assert(isPredicated(Opcode)); 10171a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask); 10181a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma} 10191a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 1020cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// Returns true, if a ST insn can be promoted to a new-value store. 1021cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Vermabool HexagonInstrInfo::mayBeNewStore(const MachineInstr *MI) const { 1022cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma const HexagonRegisterInfo& QRI = getRegisterInfo(); 1023cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1024cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma 1025cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma return ((F >> HexagonII::mayNVStorePos) & 1026cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma HexagonII::mayNVStoreMask & 1027cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma QRI.Subtarget.hasV4TOps()); 1028cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma} 1029cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma 1030b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool 1031b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonInstrInfo::DefinesPredicate(MachineInstr *MI, 1032b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum std::vector<MachineOperand> &Pred) const { 1033b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) { 1034b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineOperand MO = MI->getOperand(oper); 1035b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (MO.isReg() && MO.isDef()) { 1036b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg()); 1037420761a0f193e87d08ee1c51b26bba23ab4bac7fCraig Topper if (RC == &Hexagon::PredRegsRegClass) { 1038b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Pred.push_back(MO); 1039b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1040b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1041b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1042b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1043b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 1044b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1045b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1046b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1047b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool 1048b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonInstrInfo:: 1049b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumSubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, 1050b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const SmallVectorImpl<MachineOperand> &Pred2) const { 1051b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // TODO: Fix this 1052b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 1053b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1054b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1055b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1056b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 1057b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// We indicate that we want to reverse the branch by 1058b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// inserting a 0 at the beginning of the Cond vector. 1059b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 1060b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1061b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { 1062b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) { 1063b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Cond.erase(Cond.begin()); 1064b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 1065b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Cond.insert(Cond.begin(), MachineOperand::CreateImm(0)); 1066b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1067b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return false; 1068b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1069b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1070b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1071b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1072b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs, 1073b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const BranchProbability &Probability) const { 1074b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (NumInstrs <= 4); 1075b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1076b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1077b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const { 1078b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch (MI->getOpcode()) { 107926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 1080b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_V4 : 1081b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_cPt_V4 : 1082b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_cNotPt_V4 : 1083b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_cdnPnt_V4 : 1084b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_cNotdnPnt_V4 : 1085b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_cdnPt_V4 : 1086b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::DEALLOC_RET_cNotdnPt_V4 : 1087b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1088b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1089b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1090b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1091b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1092b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1093b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisValidOffset(const int Opcode, const int Offset) const { 1094b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // This function is to check whether the "Offset" is in the correct range of 1095b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is 1096b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // inserted to calculate the final address. Due to this reason, the function 1097b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // assumes that the "Offset" has correct alignment. 1098cec50e6da221edeef922a5d5f85081ba66b08dabJyotsna Verma // We used to assert if the offset was not properly aligned, however, 1099cec50e6da221edeef922a5d5f85081ba66b08dabJyotsna Verma // there are cases where a misaligned pointer recast can cause this 1100cec50e6da221edeef922a5d5f85081ba66b08dabJyotsna Verma // problem, and we need to allow for it. The front end warns of such 1101cec50e6da221edeef922a5d5f85081ba66b08dabJyotsna Verma // misaligns with respect to load size. 1102b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1103b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Opcode) { 1104b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1105b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw: 1106a454ffd02a7ce2f7c8ffebaad1055bf09637d21bJyotsna Verma case Hexagon::LDriw_indexed: 11077517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case Hexagon::LDriw_f: 1108a454ffd02a7ce2f7c8ffebaad1055bf09637d21bJyotsna Verma case Hexagon::STriw_indexed: 1109b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw: 11107517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case Hexagon::STriw_f: 1111b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMW_OFFSET_MIN) && 1112b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset <= Hexagon_MEMW_OFFSET_MAX); 1113b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1114b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid: 1115a454ffd02a7ce2f7c8ffebaad1055bf09637d21bJyotsna Verma case Hexagon::LDrid_indexed: 11167517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case Hexagon::LDrid_f: 1117b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrid: 1118a454ffd02a7ce2f7c8ffebaad1055bf09637d21bJyotsna Verma case Hexagon::STrid_indexed: 11197517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case Hexagon::STrid_f: 1120b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMD_OFFSET_MIN) && 1121b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset <= Hexagon_MEMD_OFFSET_MAX); 1122b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1123b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih: 1124b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh: 1125b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrih: 1126b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMH_OFFSET_MIN) && 1127b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset <= Hexagon_MEMH_OFFSET_MAX); 1128b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1129b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib: 1130b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STrib: 1131b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub: 1132b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMB_OFFSET_MIN) && 1133b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset <= Hexagon_MEMB_OFFSET_MAX); 1134b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1135b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ADD_ri: 1136b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::TFR_FI: 1137b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_ADDI_OFFSET_MIN) && 1138b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset <= Hexagon_ADDI_OFFSET_MAX); 1139b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 114097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ADDi_V4 : 114197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_SUBi_V4 : 114297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ADDr_V4 : 114397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_SUBr_V4 : 114497e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ANDr_V4 : 114597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ORr_V4 : 1146b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (0 <= Offset && Offset <= 255); 1147b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 114897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ADDi_V4 : 114997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_SUBi_V4 : 115097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ADDr_V4 : 115197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_SUBr_V4 : 115297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ANDr_V4 : 115397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ORr_V4 : 1154b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (0 <= Offset && Offset <= 127); 1155b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 115697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ADDi_V4 : 115797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_SUBi_V4 : 115897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ADDr_V4 : 115997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_SUBr_V4 : 116097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ANDr_V4 : 116197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ORr_V4 : 1162b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (0 <= Offset && Offset <= 63); 1163b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1164b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of 1165b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // any size. Later pass knows how to handle it. 1166b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw_pred: 1167b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_pred: 1168b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1169b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 117071490fa946f750fb3afe7228a32d31d401d4c1d8Krzysztof Parzyszek case Hexagon::LOOP0_i: 117171490fa946f750fb3afe7228a32d31d401d4c1d8Krzysztof Parzyszek return isUInt<10>(Offset); 117271490fa946f750fb3afe7228a32d31d401d4c1d8Krzysztof Parzyszek 1173b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // INLINEASM is very special. 1174b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::INLINEASM: 1175b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1176b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1177b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 117827baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer llvm_unreachable("No offset range is defined for this opcode. " 117927baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer "Please define it in the above switch statement!"); 1180b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1181b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1182b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1183b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 1184b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// Check if the Offset is a valid auto-inc imm by Load/Store Type. 1185b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 1186b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1187b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisValidAutoIncImm(const EVT VT, const int Offset) const { 1188b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1189b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (VT == MVT::i64) { 1190b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMD_AUTOINC_MIN && 1191b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Offset <= Hexagon_MEMD_AUTOINC_MAX && 1192b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset & 0x7) == 0); 1193b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1194b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (VT == MVT::i32) { 1195b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMW_AUTOINC_MIN && 1196b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Offset <= Hexagon_MEMW_AUTOINC_MAX && 1197b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset & 0x3) == 0); 1198b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1199b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (VT == MVT::i16) { 1200b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMH_AUTOINC_MIN && 1201b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Offset <= Hexagon_MEMH_AUTOINC_MAX && 1202b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (Offset & 0x1) == 0); 1203b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1204b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (VT == MVT::i8) { 1205b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return (Offset >= Hexagon_MEMB_AUTOINC_MIN && 1206b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Offset <= Hexagon_MEMB_AUTOINC_MAX); 1207b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1208bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("Not an auto-inc opc!"); 1209b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1210b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1211b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1212b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1213b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisMemOp(const MachineInstr *MI) const { 12141a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma// return MI->getDesc().mayLoad() && MI->getDesc().mayStore(); 12151a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 1216b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch (MI->getOpcode()) 1217b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum { 121826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 121997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ADDi_V4 : 122097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_SUBi_V4 : 122197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ADDr_V4 : 122297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_SUBr_V4 : 122397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ANDr_V4 : 122497e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_ORr_V4 : 122597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ADDi_V4 : 122697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_SUBi_V4 : 122797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ADDr_V4 : 122897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_SUBr_V4 : 122997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ANDr_V4 : 123097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_ORr_V4 : 123197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ADDi_V4 : 123297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_SUBi_V4 : 123397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ADDr_V4 : 123497e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_SUBr_V4 : 123597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ANDr_V4 : 123697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_ORr_V4 : 123797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_SETBITi_V4: 123897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_SETBITi_V4: 123997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_SETBITi_V4: 124097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPb_CLRBITi_V4: 124197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPh_CLRBITi_V4: 124297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma case Hexagon::MemOPw_CLRBITi_V4: 124397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma return true; 1244b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 124597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma return false; 1246b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1247b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1248b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1249b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1250b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisSpillPredRegOp(const MachineInstr *MI) const { 125126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande switch (MI->getOpcode()) { 125226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 1253b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::STriw_pred : 1254b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_pred : 125526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return true; 12561bfd24851ef35e754d9652551e1a7abb12fe6738Sirish Pande } 1257b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande} 1258b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande 1259b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pandebool HexagonInstrInfo::isNewValueJumpCandidate(const MachineInstr *MI) const { 1260b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande switch (MI->getOpcode()) { 12612b38c12643236825a6a49c31ef49da8e62b094c2Sirish Pande default: return false; 1262b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande case Hexagon::CMPEQrr: 1263b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande case Hexagon::CMPEQri: 1264b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande case Hexagon::CMPGTrr: 1265b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande case Hexagon::CMPGTri: 1266b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande case Hexagon::CMPGTUrr: 1267b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande case Hexagon::CMPGTUri: 1268b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande return true; 1269b33857040f63a9fdfb0c2a2ca2af67ec12cf9d02Sirish Pande } 12701bfd24851ef35e754d9652551e1a7abb12fe6738Sirish Pande} 12711bfd24851ef35e754d9652551e1a7abb12fe6738Sirish Pande 127226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandebool HexagonInstrInfo:: 127326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish PandeisConditionalTransfer (const MachineInstr *MI) const { 127426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande switch (MI->getOpcode()) { 127526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 127626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFR_cPt: 127726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFR_cNotPt: 127826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFRI_cPt: 127926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFRI_cNotPt: 128026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFR_cdnPt: 128126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFR_cdnNotPt: 128226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFRI_cdnPt: 128326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::TFRI_cdnNotPt: 128426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return true; 128526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande } 128626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande} 1287b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1288b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const { 1289b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const HexagonRegisterInfo& QRI = getRegisterInfo(); 1290b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch (MI->getOpcode()) 1291b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum { 129226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 1293b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ADD_ri_cPt: 1294b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ADD_ri_cNotPt: 1295b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ADD_rr_cPt: 1296b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ADD_rr_cNotPt: 1297b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::XOR_rr_cPt: 1298b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::XOR_rr_cNotPt: 1299b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::AND_rr_cPt: 1300b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::AND_rr_cNotPt: 1301b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::OR_rr_cPt: 1302b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::OR_rr_cNotPt: 1303b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SUB_rr_cPt: 1304b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SUB_rr_cNotPt: 1305b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::COMBINE_rr_cPt: 1306b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::COMBINE_rr_cNotPt: 1307b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1308b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ASLH_cPt_V4: 1309b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ASLH_cNotPt_V4: 1310b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ASRH_cPt_V4: 1311b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ASRH_cNotPt_V4: 1312b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SXTB_cPt_V4: 1313b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SXTB_cNotPt_V4: 1314b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SXTH_cPt_V4: 1315b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::SXTH_cNotPt_V4: 1316b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ZXTB_cPt_V4: 1317b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ZXTB_cNotPt_V4: 1318b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ZXTH_cPt_V4: 1319b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::ZXTH_cNotPt_V4: 132026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return QRI.Subtarget.hasV4TOps(); 1321b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 1322b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 1323b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 1324b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumbool HexagonInstrInfo:: 1325b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumisConditionalLoad (const MachineInstr* MI) const { 1326b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const HexagonRegisterInfo& QRI = getRegisterInfo(); 1327b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch (MI->getOpcode()) 1328b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum { 132926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 1330b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_cPt : 1331b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_cNotPt : 1332b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_indexed_cPt : 1333b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_indexed_cNotPt : 1334b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_cPt : 1335b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_cNotPt : 1336b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_indexed_cPt : 1337b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_indexed_cNotPt : 1338b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_cPt : 1339b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_cNotPt : 1340b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_indexed_cPt : 1341b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_indexed_cNotPt : 1342b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_cPt : 1343b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_cNotPt : 1344b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_indexed_cPt : 1345b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_indexed_cNotPt : 1346b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_cPt : 1347b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_cNotPt : 1348b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_indexed_cPt : 1349b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_indexed_cNotPt : 1350b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_cPt : 1351b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_cNotPt : 1352b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_indexed_cPt : 1353b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_indexed_cNotPt : 1354b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return true; 1355b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrid_cPt : 1356b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrid_cNotPt : 1357b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriw_cPt : 1358b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriw_cNotPt : 1359b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrih_cPt : 1360b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrih_cNotPt : 1361b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrib_cPt : 1362b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDrib_cNotPt : 1363b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriuh_cPt : 1364b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriuh_cNotPt : 1365b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriub_cPt : 1366b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::POST_LDriub_cNotPt : 136726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return QRI.Subtarget.hasV4TOps(); 1368b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_indexed_shl_cPt_V4 : 1369b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrid_indexed_shl_cNotPt_V4 : 1370b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_indexed_shl_cPt_V4 : 1371b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrib_indexed_shl_cNotPt_V4 : 1372b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_indexed_shl_cPt_V4 : 1373b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriub_indexed_shl_cNotPt_V4 : 1374b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_indexed_shl_cPt_V4 : 1375b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDrih_indexed_shl_cNotPt_V4 : 1376b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_indexed_shl_cPt_V4 : 1377b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriuh_indexed_shl_cNotPt_V4 : 1378b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_indexed_shl_cPt_V4 : 1379b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case Hexagon::LDriw_indexed_shl_cNotPt_V4 : 138026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return QRI.Subtarget.hasV4TOps(); 138126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande } 138226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande} 138326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 138426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// Returns true if an instruction is a conditional store. 138526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 138626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// Note: It doesn't include conditional new-value stores as they can't be 138726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// converted to .new predicate. 138826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 138926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ] 139026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// ^ ^ 139126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// / \ (not OK. it will cause new-value store to be 139226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// / X conditional on p0.new while R2 producer is 139326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// / \ on p0) 139426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// / \. 139526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// p.new store p.old NV store 139626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new] 139726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// ^ ^ 139826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// \ / 139926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// \ / 140026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// \ / 140126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// p.old store 140226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// [if (p0)memw(R0+#0)=R2] 140326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 140426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// The above diagram shows the steps involoved in the conversion of a predicated 140526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// store instruction to its .new predicated new-value form. 140626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 140726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// The following set of instructions further explains the scenario where 140826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// conditional new-value store becomes invalid when promoted to .new predicate 140926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// form. 141026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 141126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// { 1) if (p0) r0 = add(r1, r2) 141226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 2) p0 = cmp.eq(r3, #0) } 141326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 141426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with 141526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// the first two instructions because in instr 1, r0 is conditional on old value 141626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which 141726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande// is not valid for new-value stores. 141826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pandebool HexagonInstrInfo:: 141926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish PandeisConditionalStore (const MachineInstr* MI) const { 142026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande const HexagonRegisterInfo& QRI = getRegisterInfo(); 142126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande switch (MI->getOpcode()) 142226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande { 142326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande default: return false; 142426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrib_imm_cPt_V4 : 142526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrib_imm_cNotPt_V4 : 142626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrib_indexed_shl_cPt_V4 : 142726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrib_indexed_shl_cNotPt_V4 : 142826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrib_cPt : 142926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrib_cNotPt : 143026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_STbri_cPt : 143126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_STbri_cNotPt : 143226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrid_indexed_cPt : 143326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrid_indexed_cNotPt : 143426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrid_indexed_shl_cPt_V4 : 143526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_STdri_cPt : 143626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_STdri_cNotPt : 143726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_cPt : 143826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_cNotPt : 143926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_indexed_cPt : 144026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_indexed_cNotPt : 144126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_imm_cPt_V4 : 144226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_imm_cNotPt_V4 : 144326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_indexed_shl_cPt_V4 : 144426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STrih_indexed_shl_cNotPt_V4 : 144526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_SThri_cPt : 144626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_SThri_cNotPt : 144726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_cPt : 144826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_cNotPt : 144926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_indexed_cPt : 145026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_indexed_cNotPt : 145126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_imm_cPt_V4 : 145226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_imm_cNotPt_V4 : 145326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_indexed_shl_cPt_V4 : 145426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STriw_indexed_shl_cNotPt_V4 : 145526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_STwri_cPt : 145626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::POST_STwri_cNotPt : 145726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return QRI.Subtarget.hasV4TOps(); 145826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 145926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // V4 global address store before promoting to dot new. 146026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STd_GP_cPt_V4 : 146126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STd_GP_cNotPt_V4 : 146226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STb_GP_cPt_V4 : 146326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STb_GP_cNotPt_V4 : 146426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STh_GP_cPt_V4 : 146526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STh_GP_cNotPt_V4 : 146626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STw_GP_cPt_V4 : 146726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande case Hexagon::STw_GP_cNotPt_V4 : 146826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande return QRI.Subtarget.hasV4TOps(); 146926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 147026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded 147126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // from the "Conditional Store" list. Because a predicated new value store 147226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // would NOT be promoted to a double dot new store. See diagram below: 147326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // This function returns yes for those stores that are predicated but not 147426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // yet promoted to predicate dot new instructions. 147526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // 147626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // +---------------------+ 147726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // /-----| if (p0) memw(..)=r0 |---------\~ 147826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // || +---------------------+ || 147926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // promote || /\ /\ || promote 148026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // || /||\ /||\ || 148126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // \||/ demote || \||/ 148226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // \/ || || \/ 148326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // +-------------------------+ || +-------------------------+ 148426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new | 148526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // +-------------------------+ || +-------------------------+ 148626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // || || || 148726f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // || demote \||/ 148826f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // promote || \/ NOT possible 148926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // || || /\~ 149026f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // \||/ || /||\~ 149126f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // \/ || || 149226f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // +-----------------------------+ 149326f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // | if (p0.new) memw(..)=r0.new | 149426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // +-----------------------------+ 149526f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // Double Dot New Store 149626f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande // 1497d1a87a68064e0b9af3b71b681286954f861bb1b3Sirish Pande } 1498d1a87a68064e0b9af3b71b681286954f861bb1b3Sirish Pande} 1499d1a87a68064e0b9af3b71b681286954f861bb1b3Sirish Pande 15001a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 15011a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const { 15021a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma if (isNewValue(MI) && isBranch(MI)) 15031a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return true; 15041a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return false; 15051a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma} 15061a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 150780d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Vermabool HexagonInstrInfo::isPostIncrement (const MachineInstr* MI) const { 150880d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return (getAddrMode(MI) == HexagonII::PostInc); 150980d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma} 151080d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 15111a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Vermabool HexagonInstrInfo::isNewValue(const MachineInstr* MI) const { 15121a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 15131a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask); 15141a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma} 15151a7eab387849feaa3e9c35f145d5b07be54686e3Jyotsna Verma 1516810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma// Returns true, if any one of the operands is a dot new 1517810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma// insn, whether it is predicated dot new or register dot new. 1518810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Vermabool HexagonInstrInfo::isDotNewInst (const MachineInstr* MI) const { 1519810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma return (isNewValueInst(MI) || 1520810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma (isPredicated(MI) && isPredicatedNew(MI))); 1521810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma} 1522810848d5b3bc53747722db0d30a21dc168c5503eJyotsna Verma 1523cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// Returns the most basic instruction for the .new predicated instructions and 1524cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// new-value stores. 1525cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// For example, all of the following instructions will be converted back to the 1526cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// same instruction: 1527cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// 1) if (p0.new) memw(R0+#0) = R1.new ---> 1528cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1 1529cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// 3) if (p0.new) memw(R0+#0) = R1 ---> 1530cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma// 1531cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma 1532cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Vermaint HexagonInstrInfo::GetDotOldOp(const int opc) const { 1533cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma int NewOp = opc; 1534cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form 1535cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma NewOp = Hexagon::getPredOldOpcode(NewOp); 1536cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma if (NewOp < 0) 1537cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma assert(0 && "Couldn't change predicate new instruction to its old form."); 1538cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma } 1539cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma 1540cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma if (isNewValueStore(NewOp)) { // Convert into non new-value format 1541cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma NewOp = Hexagon::getNonNVStore(NewOp); 1542cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma if (NewOp < 0) 1543cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma assert(0 && "Couldn't change new-value store to its old form."); 1544cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma } 1545cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma return NewOp; 1546cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma} 1547cdfb55d15bbcdf1533ca26ffcb9c94fa5d225bd0Jyotsna Verma 15481a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma// Return the new value instruction for a given store. 15491a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Vermaint HexagonInstrInfo::GetDotNewOp(const MachineInstr* MI) const { 15501a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma int NVOpcode = Hexagon::getNewValueOpcode(MI->getOpcode()); 15511a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma if (NVOpcode >= 0) // Valid new-value store instruction. 15521a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return NVOpcode; 15531a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 15541a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma switch (MI->getOpcode()) { 15551a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma default: llvm_unreachable("Unknown .new type"); 15561a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma // store new value byte 15571a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma case Hexagon::STrib_shl_V4: 15581a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return Hexagon::STrib_shl_nv_V4; 15591a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 15601a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma case Hexagon::STrih_shl_V4: 15611a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return Hexagon::STrih_shl_nv_V4; 15621a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 15631a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma case Hexagon::STriw_f: 15641a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return Hexagon::STriw_nv_V4; 15651a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 15661a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma case Hexagon::STriw_indexed_f: 15671a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return Hexagon::STriw_indexed_nv_V4; 15681a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 15691a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma case Hexagon::STriw_shl_V4: 15701a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return Hexagon::STriw_shl_nv_V4; 15711a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 15721a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma } 15731a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma return 0; 15741a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma} 15751a35b8e2eb165624013d5a2eaf8b673f026999fcJyotsna Verma 157680d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma// Return .new predicate version for an instruction. 157780d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Vermaint HexagonInstrInfo::GetDotNewPredOp(MachineInstr *MI, 157880d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma const MachineBranchProbabilityInfo 157980d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma *MBPI) const { 158080d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 158180d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma int NewOpcode = Hexagon::getPredNewOpcode(MI->getOpcode()); 158280d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma if (NewOpcode >= 0) // Valid predicate new instruction 158380d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return NewOpcode; 158480d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 158580d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma switch (MI->getOpcode()) { 158680d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma default: llvm_unreachable("Unknown .new type"); 158780d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma // Condtional Jumps 158880d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::JMP_t: 158980d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::JMP_f: 159080d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return getDotNewPredJumpOp(MI, MBPI); 159180d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 159280d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::JMPR_t: 159380d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return Hexagon::JMPR_tnew_tV3; 159480d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 159580d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::JMPR_f: 159680d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return Hexagon::JMPR_fnew_tV3; 159780d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 159880d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::JMPret_t: 159980d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return Hexagon::JMPret_tnew_tV3; 160080d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 160180d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::JMPret_f: 160280d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return Hexagon::JMPret_fnew_tV3; 160380d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 160480d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 160580d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma // Conditional combine 160680d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::COMBINE_rr_cPt : 160780d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return Hexagon::COMBINE_rr_cdnPt; 160880d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma case Hexagon::COMBINE_rr_cNotPt : 160980d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma return Hexagon::COMBINE_rr_cdnNotPt; 161080d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma } 161180d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma} 161280d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 161380d81aa8ba923c9f9a953410677ac53c4c2b8318Jyotsna Verma 1614ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermaunsigned HexagonInstrInfo::getAddrMode(const MachineInstr* MI) const { 1615ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1616ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1617ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return((F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask); 1618ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 161926f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 1620ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma/// immediateExtend - Changes the instruction in place to one using an immediate 1621ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma/// extender. 1622ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermavoid HexagonInstrInfo::immediateExtend(MachineInstr *MI) const { 1623ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma assert((isExtendable(MI)||isConstExtended(MI)) && 1624ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma "Instruction must be extendable"); 1625ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Find which operand is extendable. 1626ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma short ExtOpNum = getCExtOpNum(MI); 1627ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma MachineOperand &MO = MI->getOperand(ExtOpNum); 1628ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // This needs to be something we understand. 1629ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma assert((MO.isMBB() || MO.isImm()) && 1630ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma "Branch with unknown extendable field type"); 1631ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Mark given operand as extended. 1632ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma MO.addTargetFlag(HexagonII::HMOTF_ConstExtended); 1633ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 163426f61a158b3cce69252c05cc0e79f500d6c3d92eSirish Pande 1635ee498d3254b86bceb4f441741e9f442990647ce6Andrew TrickDFAPacketizer *HexagonInstrInfo:: 1636ee498d3254b86bceb4f441741e9f442990647ce6Andrew TrickCreateTargetScheduleState(const TargetMachine *TM, 1637ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick const ScheduleDAG *DAG) const { 1638ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick const InstrItineraryData *II = TM->getInstrItineraryData(); 1639ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II); 1640ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick} 1641ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick 1642ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trickbool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI, 1643ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick const MachineBasicBlock *MBB, 1644ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick const MachineFunction &MF) const { 1645ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // Debug info is never a scheduling boundary. It's necessary to be explicit 1646ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // due to the special treatment of IT instructions below, otherwise a 1647ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // dbg_value followed by an IT will result in the IT instruction being 1648ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // considered a scheduling hazard, which is wrong. It should be the actual 1649ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // instruction preceding the dbg_value instruction(s), just like it is 1650ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // when debug info is not present. 1651ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick if (MI->isDebugValue()) 1652ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick return false; 1653ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick 1654ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick // Terminators and labels can't be scheduled around. 1655ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm()) 1656ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick return true; 1657ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick 1658ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick return false; 1659ee498d3254b86bceb4f441741e9f442990647ce6Andrew Trick} 1660ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1661ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermabool HexagonInstrInfo::isConstExtended(MachineInstr *MI) const { 1662ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1663ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Constant extenders are allowed only for V4 and above. 1664ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (!Subtarget.hasV4TOps()) 1665ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1666ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1667ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1668ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; 1669ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (isExtended) // Instruction must be extended. 1670ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return true; 1671ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1672ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned isExtendable = (F >> HexagonII::ExtendablePos) 1673ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma & HexagonII::ExtendableMask; 1674ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (!isExtendable) 1675ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1676ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1677ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma short ExtOpNum = getCExtOpNum(MI); 1678ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const MachineOperand &MO = MI->getOperand(ExtOpNum); 1679ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Use MO operand flags to determine if MO 1680ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // has the HMOTF_ConstExtended flag set. 1681ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended) 1682ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return true; 1683ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // If this is a Machine BB address we are talking about, and it is 1684ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // not marked as extended, say so. 1685ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (MO.isMBB()) 1686ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1687ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1688ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // We could be using an instruction with an extendable immediate and shoehorn 1689ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // a global address into it. If it is a global address it will be constant 1690ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // extended. We do this for COMBINE. 1691ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // We currently only handle isGlobal() because it is the only kind of 1692ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // object we are going to end up with here for now. 1693ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // In the future we probably should add isSymbol(), etc. 1694ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (MO.isGlobal() || MO.isSymbol()) 1695ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return true; 1696ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1697ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // If the extendable operand is not 'Immediate' type, the instruction should 1698ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // have 'isExtended' flag set. 1699ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma assert(MO.isImm() && "Extendable operand must be Immediate type"); 1700ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1701ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma int MinValue = getMinValue(MI); 1702ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma int MaxValue = getMaxValue(MI); 1703ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma int ImmValue = MO.getImm(); 1704ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1705ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return (ImmValue < MinValue || ImmValue > MaxValue); 1706ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 1707ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1708f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma// Returns the opcode to use when converting MI, which is a conditional jump, 1709f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma// into a conditional instruction which uses the .new value of the predicate. 1710f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma// We also use branch probabilities to add a hint to the jump. 1711f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Vermaint 1712f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna VermaHexagonInstrInfo::getDotNewPredJumpOp(MachineInstr *MI, 1713f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma const 1714f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma MachineBranchProbabilityInfo *MBPI) const { 1715f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma 1716f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma // We assume that block can have at most two successors. 1717f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma bool taken = false; 1718f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma MachineBasicBlock *Src = MI->getParent(); 1719f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma MachineOperand *BrTarget = &MI->getOperand(1); 1720f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma MachineBasicBlock *Dst = BrTarget->getMBB(); 1721f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma 1722f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst); 1723f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma if (Prediction >= BranchProbability(1,2)) 1724f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma taken = true; 1725f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma 1726f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma switch (MI->getOpcode()) { 1727f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma case Hexagon::JMP_t: 1728f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma return taken ? Hexagon::JMP_tnew_t : Hexagon::JMP_tnew_nt; 1729f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma case Hexagon::JMP_f: 1730f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma return taken ? Hexagon::JMP_fnew_t : Hexagon::JMP_fnew_nt; 1731f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma 1732f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma default: 1733f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma llvm_unreachable("Unexpected jump instruction."); 1734f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma } 1735f945d09d53a4f2f392b8b51191d37de2f8acd566Jyotsna Verma} 1736ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// Returns true if a particular operand is extendable for an instruction. 1737ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermabool HexagonInstrInfo::isOperandExtended(const MachineInstr *MI, 1738ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned short OperandNum) const { 1739ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Constant extenders are allowed only for V4 and above. 1740ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (!Subtarget.hasV4TOps()) 1741ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1742ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1743ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1744ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1745ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) 1746ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma == OperandNum; 1747ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 1748ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1749ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// Returns Operand Index for the constant extended instruction. 1750ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermaunsigned short HexagonInstrInfo::getCExtOpNum(const MachineInstr *MI) const { 1751ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1752ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask); 1753ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 1754ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1755ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// Returns the min value that doesn't need to be extended. 1756ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermaint HexagonInstrInfo::getMinValue(const MachineInstr *MI) const { 1757ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1758ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned isSigned = (F >> HexagonII::ExtentSignedPos) 1759ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma & HexagonII::ExtentSignedMask; 1760ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned bits = (F >> HexagonII::ExtentBitsPos) 1761ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma & HexagonII::ExtentBitsMask; 1762ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1763ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (isSigned) // if value is signed 1764ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return -1 << (bits - 1); 1765ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma else 1766ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return 0; 1767ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 1768ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1769ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// Returns the max value that doesn't need to be extended. 1770ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermaint HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const { 1771ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma const uint64_t F = MI->getDesc().TSFlags; 1772ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned isSigned = (F >> HexagonII::ExtentSignedPos) 1773ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma & HexagonII::ExtentSignedMask; 1774ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma unsigned bits = (F >> HexagonII::ExtentBitsPos) 1775ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma & HexagonII::ExtentBitsMask; 1776ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1777ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (isSigned) // if value is signed 1778ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return ~(-1 << (bits - 1)); 1779ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma else 1780ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return ~(-1 << bits); 1781ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 1782ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1783ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// Returns true if an instruction can be converted into a non-extended 1784ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// equivalent instruction. 1785ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermabool HexagonInstrInfo::NonExtEquivalentExists (const MachineInstr *MI) const { 1786ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1787ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma short NonExtOpcode; 1788ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Check if the instruction has a register form that uses register in place 1789ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // of the extended operand, if so return that as the non-extended form. 1790ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (Hexagon::getRegForm(MI->getOpcode()) >= 0) 1791ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return true; 1792ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1793ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) { 1794ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Check addressing mode and retreive non-ext equivalent instruction. 1795ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1796ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma switch (getAddrMode(MI)) { 1797ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma case HexagonII::Absolute : 1798ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Load/store with absolute addressing mode can be converted into 1799ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // base+offset mode. 1800ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma NonExtOpcode = Hexagon::getBasedWithImmOffset(MI->getOpcode()); 1801ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma break; 1802ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma case HexagonII::BaseImmOffset : 1803ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Load/store with base+offset addressing mode can be converted into 1804ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // base+register offset addressing mode. However left shift operand should 1805ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // be set to 0. 1806ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma NonExtOpcode = Hexagon::getBaseWithRegOffset(MI->getOpcode()); 1807ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma break; 1808ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma default: 1809ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1810ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma } 1811ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (NonExtOpcode < 0) 1812ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1813ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return true; 1814ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma } 1815ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return false; 1816ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 1817ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1818ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma// Returns opcode of the non-extended equivalent instruction. 1819ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Vermashort HexagonInstrInfo::getNonExtOpcode (const MachineInstr *MI) const { 1820ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1821ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Check if the instruction has a register form that uses register in place 1822ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // of the extended operand, if so return that as the non-extended form. 1823ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma short NonExtOpcode = Hexagon::getRegForm(MI->getOpcode()); 1824ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (NonExtOpcode >= 0) 1825ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return NonExtOpcode; 1826ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma 1827ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) { 1828ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma // Check addressing mode and retreive non-ext equivalent instruction. 1829ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma switch (getAddrMode(MI)) { 1830ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma case HexagonII::Absolute : 1831ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return Hexagon::getBasedWithImmOffset(MI->getOpcode()); 1832ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma case HexagonII::BaseImmOffset : 1833ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return Hexagon::getBaseWithRegOffset(MI->getOpcode()); 1834ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma default: 1835ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return -1; 1836ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma } 1837ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma } 1838ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma return -1; 1839ef94c6c85eed42d16fde51ee4415d27bb281a2caJyotsna Verma} 18406ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma 18416ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Vermabool HexagonInstrInfo::PredOpcodeHasJMP_c(Opcode_t Opcode) const { 18426ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma return (Opcode == Hexagon::JMP_t) || 18436ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_f) || 18446ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_tnew_t) || 18456ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_fnew_t) || 18466ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_tnew_nt) || 18476ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_fnew_nt); 18486ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma} 18496ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma 18506ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Vermabool HexagonInstrInfo::PredOpcodeHasNot(Opcode_t Opcode) const { 18516ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma return (Opcode == Hexagon::JMP_f) || 18526ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_fnew_t) || 18536ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma (Opcode == Hexagon::JMP_fnew_nt); 18546ea706e40e841c148bc47bcac4dcca5e0f0245ebJyotsna Verma} 1855