24 #define DEBUG_TYPE "hexagon-nvj"
52 STATISTIC(NumNVJGenerated,
"Number of New Value Jump Instructions created");
56 "Maximum number of predicated jumps to be converted to New Value Jump"));
60 cl::desc(
"Disable New Value Jumps"));
84 const char *getPassName()
const {
85 return "Hexagon NewValueJump";
101 "Hexagon NewValueJump",
false,
false)
117 if (QII->isPredicated(II))
149 for (
unsigned i = 0; i < II->getNumOperands(); ++i) {
150 if (II->getOperand(i).isReg() &&
151 (II->getOperand(i).isUse() || II->getOperand(i).isDef())) {
154 unsigned Reg = II->getOperand(i).getReg();
156 localBegin !=
end; ++localBegin) {
157 if (localBegin == skip )
continue;
159 if (localBegin->modifiesRegister(Reg, TRI) ||
160 localBegin->readsRegister(Reg, TRI))
176 if (MII->getDesc().mayStore())
180 if (MII->getOpcode() == Hexagon::CALLv3)
203 if (MII->getOpcode() == Hexagon::TFR_condset_rr ||
204 MII->getOpcode() == Hexagon::TFR_condset_ii ||
205 MII->getOpcode() == Hexagon::TFR_condset_ri ||
206 MII->getOpcode() == Hexagon::TFR_condset_ir ||
207 MII->getOpcode() == Hexagon::LDriw_pred ||
208 MII->getOpcode() == Hexagon::STriw_pred)
231 if (!(isUInt<5>(v) ||
238 unsigned cmpReg1, cmpOp2 = 0;
268 if (localII->modifiesRegister(pReg, TRI) ||
269 localII->readsRegister(pReg, TRI))
279 if (localII->modifiesRegister(cmpReg1, TRI) ||
280 (secondReg && localII->modifiesRegister(cmpOp2, TRI)))
290 bool secondRegNewified,
303 case Hexagon::CMPEQrr:
304 return taken ? Hexagon::CMPEQrr_t_Jumpnv_t_V4
305 : Hexagon::CMPEQrr_t_Jumpnv_nt_V4;
307 case Hexagon::CMPEQri: {
309 return taken ? Hexagon::CMPEQri_t_Jumpnv_t_V4
310 : Hexagon::CMPEQri_t_Jumpnv_nt_V4;
312 return taken ? Hexagon::CMPEQn1_t_Jumpnv_t_V4
313 : Hexagon::CMPEQn1_t_Jumpnv_nt_V4;
316 case Hexagon::CMPGTrr: {
317 if (secondRegNewified)
318 return taken ? Hexagon::CMPLTrr_t_Jumpnv_t_V4
319 : Hexagon::CMPLTrr_t_Jumpnv_nt_V4;
321 return taken ? Hexagon::CMPGTrr_t_Jumpnv_t_V4
322 : Hexagon::CMPGTrr_t_Jumpnv_nt_V4;
325 case Hexagon::CMPGTri: {
327 return taken ? Hexagon::CMPGTri_t_Jumpnv_t_V4
328 : Hexagon::CMPGTri_t_Jumpnv_nt_V4;
330 return taken ? Hexagon::CMPGTn1_t_Jumpnv_t_V4
331 : Hexagon::CMPGTn1_t_Jumpnv_nt_V4;
334 case Hexagon::CMPGTUrr: {
335 if (secondRegNewified)
336 return taken ? Hexagon::CMPLTUrr_t_Jumpnv_t_V4
337 : Hexagon::CMPLTUrr_t_Jumpnv_nt_V4;
339 return taken ? Hexagon::CMPGTUrr_t_Jumpnv_t_V4
340 : Hexagon::CMPGTUrr_t_Jumpnv_nt_V4;
343 case Hexagon::CMPGTUri:
344 return taken ? Hexagon::CMPGTUri_t_Jumpnv_t_V4
345 : Hexagon::CMPGTUri_t_Jumpnv_nt_V4;
356 DEBUG(
dbgs() <<
"********** Hexagon New Value Jump **********\n"
357 <<
"********** Function: "
369 MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
371 if (!QRI->Subtarget.hasV4TOps() ||
377 int nvjGenerated = 0;
381 MBBb != MBBe; ++MBBb) {
387 DEBUG(
dbgs() <<
"\n" <<
"********** dumping instr bottom up **********\n");
388 bool foundJump =
false;
389 bool foundCompare =
false;
390 bool invertPredicate =
false;
391 unsigned predReg = 0;
392 unsigned cmpReg1 = 0;
394 bool MO1IsKill =
false;
395 bool MO2IsKill =
false;
400 bool afterRA =
false;
401 bool isSecondOpReg =
false;
402 bool isSecondOpNewified =
false;
411 if ((nvjCount == 0) || (nvjCount > -1 && nvjCount <= nvjGenerated))
419 MI->
getOpcode() == Hexagon::JMP_tnew_t ||
420 MI->
getOpcode() == Hexagon::JMP_tnew_nt ||
421 MI->
getOpcode() == Hexagon::JMP_fnew_t ||
422 MI->
getOpcode() == Hexagon::JMP_fnew_nt)) {
445 bool predLive =
false;
447 SIE = MBB->
succ_end(); SI != SIE; ++SI) {
459 MI->
getOpcode() == Hexagon::JMP_fnew_t ||
460 MI->
getOpcode() == Hexagon::JMP_fnew_nt) {
461 invertPredicate =
true;
478 if (QII->isNewValueJumpCandidate(MI)) {
481 "Only compare instruction can be collapsed into New Value Jump");
485 afterRA, jmpPos, MF))
508 if (foundCompare && foundJump) {
514 bool foundFeeder =
false;
530 if (feederReg == cmpReg1) {
542 feederReg == (
unsigned) cmpOp2)
549 if (cmpInstr->
getOpcode() == Hexagon::CMPEQrr &&
551 unsigned tmp = cmpReg1;
552 bool tmpIsKill = MO1IsKill;
554 MO1IsKill = MO2IsKill;
556 MO2IsKill = tmpIsKill;
562 if (feederReg == (
unsigned)cmpOp2)
563 isSecondOpNewified =
true;
570 bool updatedIsKill =
false;
574 unsigned feederReg = MO.
getReg();
576 end = jmpPos; localII !=
end; localII++) {
586 updatedIsKill =
true;
590 if (updatedIsKill)
break;
593 if (updatedIsKill)
break;
601 assert((QII->isNewValueJumpCandidate(cmpInstr)) &&
602 "This compare is not a New Value Jump candidate.");
607 opc = QII->getInvertedPredicatedOpcode(opc);
610 NewMI =
BuildMI(*MBB, jmpPos, dl,
616 else if ((cmpInstr->
getOpcode() == Hexagon::CMPEQri ||
617 cmpInstr->
getOpcode() == Hexagon::CMPGTri) &&
621 NewMI =
BuildMI(*MBB, jmpPos, dl,
627 NewMI =
BuildMI(*MBB, jmpPos, dl,
633 assert(NewMI &&
"New Value Jump Instruction Not created!");
642 jmpInstr->eraseFromParent();
656 return new HexagonNewValueJump();
const_iterator end(StringRef path)
Get end iterator over path.
static PassRegistry * getPassRegistry()
MachineBasicBlock * getMBB() const
const MCInstrDesc & getDesc() const
void skip(CollectionType &C)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define llvm_unreachable(msg)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
BranchProbability getEdgeProbability(MachineBasicBlock *Src, MachineBasicBlock *Dst) const
ID
LLVM Calling Convention Representation.
unsigned getNumOperands() const
INITIALIZE_PASS_BEGIN(HexagonNewValueJump,"hexagon-nvj","Hexagon NewValueJump", false, false) INITIALIZE_PASS_END(HexagonNewValueJump
void initializeHexagonNewValueJumpPass(PassRegistry &)
static bool commonChecksToProhibitNewValueJump(bool afterRA, MachineBasicBlock::iterator MII)
unsigned getKillRegState(bool B)
const MachineBasicBlock * getParent() const
bool isDebugValue() const
bundle_iterator< MachineInstr, instr_iterator > iterator
static unsigned getNewValueJumpOpcode(MachineInstr *MI, int reg, bool secondRegNewified, MachineBasicBlock *jmpTarget, const MachineBranchProbabilityInfo *MBPI)
initializer< Ty > init(const Ty &Val)
const MachineOperand & getOperand(unsigned i) const
bool isCompare() const
Return true if this instruction is a comparison.
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
succ_iterator succ_begin()
hexagon Hexagon static false bool canBeFeederToNewValueJump(const HexagonInstrInfo *QII, const TargetRegisterInfo *TRI, MachineBasicBlock::iterator II, MachineBasicBlock::iterator end, MachineBasicBlock::iterator skip, MachineFunction &MF)
void setIsKill(bool Val=true)
virtual const TargetInstrInfo * getInstrInfo() const
FunctionPass * createHexagonNewValueJump()
STATISTIC(NumNVJGenerated,"Number of New Value Jump Instructions created")
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
static cl::opt< int > DbgNVJCount("nvj-count", cl::init(-1), cl::Hidden, cl::desc("Maximum number of predicated jumps to be converted to New Value Jump"))
static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope, MDNode *InlinedAt=0)
static bool isPhysicalRegister(unsigned Reg)
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
bool isLiveIn(unsigned Reg) const
MachineRegisterInfo & getRegInfo()
static bool canCompareBeNewValueJump(const HexagonInstrInfo *QII, const TargetRegisterInfo *TRI, MachineBasicBlock::iterator II, unsigned pReg, bool secondReg, bool optLocation, MachineBasicBlock::iterator end, MachineFunction &MF)
virtual void getAnalysisUsage(AnalysisUsage &AU) const
const TargetMachine & getTarget() const
virtual const TargetRegisterInfo * getRegisterInfo() const
hexagon Hexagon NewValueJump
MachineInstr * getVRegDef(unsigned Reg) const
unsigned getReg() const
getReg - Returns the register number.
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
BasicBlockListType::iterator iterator
const MCRegisterInfo & MRI
StringRef getName() const
DebugLoc getDebugLoc() const
static cl::opt< bool > DisableNewValueJumps("disable-nvjump", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Disable New Value Jumps"))