LLVM API Documentation
00001 //===----- HexagonNewValueJump.cpp - Hexagon Backend New Value Jump -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This implements NewValueJump pass in Hexagon. 00011 // Ideally, we should merge this as a Peephole pass prior to register 00012 // allocation, but because we have a spill in between the feeder and new value 00013 // jump instructions, we are forced to write after register allocation. 00014 // Having said that, we should re-attempt to pull this earlier at some point 00015 // in future. 00016 00017 // The basic approach looks for sequence of predicated jump, compare instruciton 00018 // that genereates the predicate and, the feeder to the predicate. Once it finds 00019 // all, it collapses compare and jump instruction into a new valu jump 00020 // intstructions. 00021 // 00022 // 00023 //===----------------------------------------------------------------------===// 00024 #include "llvm/PassSupport.h" 00025 #include "Hexagon.h" 00026 #include "HexagonInstrInfo.h" 00027 #include "HexagonMachineFunctionInfo.h" 00028 #include "HexagonRegisterInfo.h" 00029 #include "HexagonSubtarget.h" 00030 #include "HexagonTargetMachine.h" 00031 #include "llvm/ADT/DenseMap.h" 00032 #include "llvm/ADT/Statistic.h" 00033 #include "llvm/CodeGen/LiveVariables.h" 00034 #include "llvm/CodeGen/MachineFunctionAnalysis.h" 00035 #include "llvm/CodeGen/MachineFunctionPass.h" 00036 #include "llvm/CodeGen/MachineInstrBuilder.h" 00037 #include "llvm/CodeGen/MachineRegisterInfo.h" 00038 #include "llvm/CodeGen/Passes.h" 00039 #include "llvm/CodeGen/ScheduleDAGInstrs.h" 00040 #include "llvm/Support/CommandLine.h" 00041 #include "llvm/Support/Compiler.h" 00042 #include "llvm/Support/Debug.h" 00043 #include "llvm/Target/TargetInstrInfo.h" 00044 #include "llvm/Target/TargetMachine.h" 00045 #include "llvm/Target/TargetRegisterInfo.h" 00046 #include <map> 00047 using namespace llvm; 00048 00049 #define DEBUG_TYPE "hexagon-nvj" 00050 00051 STATISTIC(NumNVJGenerated, "Number of New Value Jump Instructions created"); 00052 00053 static cl::opt<int> 00054 DbgNVJCount("nvj-count", cl::init(-1), cl::Hidden, cl::desc( 00055 "Maximum number of predicated jumps to be converted to New Value Jump")); 00056 00057 static cl::opt<bool> DisableNewValueJumps("disable-nvjump", cl::Hidden, 00058 cl::ZeroOrMore, cl::init(false), 00059 cl::desc("Disable New Value Jumps")); 00060 00061 namespace llvm { 00062 void initializeHexagonNewValueJumpPass(PassRegistry&); 00063 } 00064 00065 00066 namespace { 00067 struct HexagonNewValueJump : public MachineFunctionPass { 00068 const HexagonInstrInfo *QII; 00069 const HexagonRegisterInfo *QRI; 00070 00071 public: 00072 static char ID; 00073 00074 HexagonNewValueJump() : MachineFunctionPass(ID) { 00075 initializeHexagonNewValueJumpPass(*PassRegistry::getPassRegistry()); 00076 } 00077 00078 void getAnalysisUsage(AnalysisUsage &AU) const override { 00079 AU.addRequired<MachineBranchProbabilityInfo>(); 00080 MachineFunctionPass::getAnalysisUsage(AU); 00081 } 00082 00083 const char *getPassName() const override { 00084 return "Hexagon NewValueJump"; 00085 } 00086 00087 bool runOnMachineFunction(MachineFunction &Fn) override; 00088 00089 private: 00090 /// \brief A handle to the branch probability pass. 00091 const MachineBranchProbabilityInfo *MBPI; 00092 00093 }; 00094 00095 } // end of anonymous namespace 00096 00097 char HexagonNewValueJump::ID = 0; 00098 00099 INITIALIZE_PASS_BEGIN(HexagonNewValueJump, "hexagon-nvj", 00100 "Hexagon NewValueJump", false, false) 00101 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) 00102 INITIALIZE_PASS_END(HexagonNewValueJump, "hexagon-nvj", 00103 "Hexagon NewValueJump", false, false) 00104 00105 00106 // We have identified this II could be feeder to NVJ, 00107 // verify that it can be. 00108 static bool canBeFeederToNewValueJump(const HexagonInstrInfo *QII, 00109 const TargetRegisterInfo *TRI, 00110 MachineBasicBlock::iterator II, 00111 MachineBasicBlock::iterator end, 00112 MachineBasicBlock::iterator skip, 00113 MachineFunction &MF) { 00114 00115 // Predicated instruction can not be feeder to NVJ. 00116 if (QII->isPredicated(II)) 00117 return false; 00118 00119 // Bail out if feederReg is a paired register (double regs in 00120 // our case). One would think that we can check to see if a given 00121 // register cmpReg1 or cmpReg2 is a sub register of feederReg 00122 // using -- if (QRI->isSubRegister(feederReg, cmpReg1) logic 00123 // before the callsite of this function 00124 // But we can not as it comes in the following fashion. 00125 // %D0<def> = Hexagon_S2_lsr_r_p %D0<kill>, %R2<kill> 00126 // %R0<def> = KILL %R0, %D0<imp-use,kill> 00127 // %P0<def> = CMPEQri %R0<kill>, 0 00128 // Hence, we need to check if it's a KILL instruction. 00129 if (II->getOpcode() == TargetOpcode::KILL) 00130 return false; 00131 00132 00133 // Make sure there there is no 'def' or 'use' of any of the uses of 00134 // feeder insn between it's definition, this MI and jump, jmpInst 00135 // skipping compare, cmpInst. 00136 // Here's the example. 00137 // r21=memub(r22+r24<<#0) 00138 // p0 = cmp.eq(r21, #0) 00139 // r4=memub(r3+r21<<#0) 00140 // if (p0.new) jump:t .LBB29_45 00141 // Without this check, it will be converted into 00142 // r4=memub(r3+r21<<#0) 00143 // r21=memub(r22+r24<<#0) 00144 // p0 = cmp.eq(r21, #0) 00145 // if (p0.new) jump:t .LBB29_45 00146 // and result WAR hazards if converted to New Value Jump. 00147 00148 for (unsigned i = 0; i < II->getNumOperands(); ++i) { 00149 if (II->getOperand(i).isReg() && 00150 (II->getOperand(i).isUse() || II->getOperand(i).isDef())) { 00151 MachineBasicBlock::iterator localII = II; 00152 ++localII; 00153 unsigned Reg = II->getOperand(i).getReg(); 00154 for (MachineBasicBlock::iterator localBegin = localII; 00155 localBegin != end; ++localBegin) { 00156 if (localBegin == skip ) continue; 00157 // Check for Subregisters too. 00158 if (localBegin->modifiesRegister(Reg, TRI) || 00159 localBegin->readsRegister(Reg, TRI)) 00160 return false; 00161 } 00162 } 00163 } 00164 return true; 00165 } 00166 00167 // These are the common checks that need to performed 00168 // to determine if 00169 // 1. compare instruction can be moved before jump. 00170 // 2. feeder to the compare instruction can be moved before jump. 00171 static bool commonChecksToProhibitNewValueJump(bool afterRA, 00172 MachineBasicBlock::iterator MII) { 00173 00174 // If store in path, bail out. 00175 if (MII->getDesc().mayStore()) 00176 return false; 00177 00178 // if call in path, bail out. 00179 if (MII->getOpcode() == Hexagon::CALLv3) 00180 return false; 00181 00182 // if NVJ is running prior to RA, do the following checks. 00183 if (!afterRA) { 00184 // The following Target Opcode instructions are spurious 00185 // to new value jump. If they are in the path, bail out. 00186 // KILL sets kill flag on the opcode. It also sets up a 00187 // single register, out of pair. 00188 // %D0<def> = Hexagon_S2_lsr_r_p %D0<kill>, %R2<kill> 00189 // %R0<def> = KILL %R0, %D0<imp-use,kill> 00190 // %P0<def> = CMPEQri %R0<kill>, 0 00191 // PHI can be anything after RA. 00192 // COPY can remateriaze things in between feeder, compare and nvj. 00193 if (MII->getOpcode() == TargetOpcode::KILL || 00194 MII->getOpcode() == TargetOpcode::PHI || 00195 MII->getOpcode() == TargetOpcode::COPY) 00196 return false; 00197 00198 // The following pseudo Hexagon instructions sets "use" and "def" 00199 // of registers by individual passes in the backend. At this time, 00200 // we don't know the scope of usage and definitions of these 00201 // instructions. 00202 if (MII->getOpcode() == Hexagon::TFR_condset_rr || 00203 MII->getOpcode() == Hexagon::TFR_condset_ii || 00204 MII->getOpcode() == Hexagon::TFR_condset_ri || 00205 MII->getOpcode() == Hexagon::TFR_condset_ir || 00206 MII->getOpcode() == Hexagon::LDriw_pred || 00207 MII->getOpcode() == Hexagon::STriw_pred) 00208 return false; 00209 } 00210 00211 return true; 00212 } 00213 00214 static bool canCompareBeNewValueJump(const HexagonInstrInfo *QII, 00215 const TargetRegisterInfo *TRI, 00216 MachineBasicBlock::iterator II, 00217 unsigned pReg, 00218 bool secondReg, 00219 bool optLocation, 00220 MachineBasicBlock::iterator end, 00221 MachineFunction &MF) { 00222 00223 MachineInstr *MI = II; 00224 00225 // If the second operand of the compare is an imm, make sure it's in the 00226 // range specified by the arch. 00227 if (!secondReg) { 00228 int64_t v = MI->getOperand(2).getImm(); 00229 00230 if (!(isUInt<5>(v) || 00231 ((MI->getOpcode() == Hexagon::CMPEQri || 00232 MI->getOpcode() == Hexagon::CMPGTri) && 00233 (v == -1)))) 00234 return false; 00235 } 00236 00237 unsigned cmpReg1, cmpOp2 = 0; // cmpOp2 assignment silences compiler warning. 00238 cmpReg1 = MI->getOperand(1).getReg(); 00239 00240 if (secondReg) { 00241 cmpOp2 = MI->getOperand(2).getReg(); 00242 00243 // Make sure that that second register is not from COPY 00244 // At machine code level, we don't need this, but if we decide 00245 // to move new value jump prior to RA, we would be needing this. 00246 MachineRegisterInfo &MRI = MF.getRegInfo(); 00247 if (secondReg && !TargetRegisterInfo::isPhysicalRegister(cmpOp2)) { 00248 MachineInstr *def = MRI.getVRegDef(cmpOp2); 00249 if (def->getOpcode() == TargetOpcode::COPY) 00250 return false; 00251 } 00252 } 00253 00254 // Walk the instructions after the compare (predicate def) to the jump, 00255 // and satisfy the following conditions. 00256 ++II ; 00257 for (MachineBasicBlock::iterator localII = II; localII != end; 00258 ++localII) { 00259 00260 // Check 1. 00261 // If "common" checks fail, bail out. 00262 if (!commonChecksToProhibitNewValueJump(optLocation, localII)) 00263 return false; 00264 00265 // Check 2. 00266 // If there is a def or use of predicate (result of compare), bail out. 00267 if (localII->modifiesRegister(pReg, TRI) || 00268 localII->readsRegister(pReg, TRI)) 00269 return false; 00270 00271 // Check 3. 00272 // If there is a def of any of the use of the compare (operands of compare), 00273 // bail out. 00274 // Eg. 00275 // p0 = cmp.eq(r2, r0) 00276 // r2 = r4 00277 // if (p0.new) jump:t .LBB28_3 00278 if (localII->modifiesRegister(cmpReg1, TRI) || 00279 (secondReg && localII->modifiesRegister(cmpOp2, TRI))) 00280 return false; 00281 } 00282 return true; 00283 } 00284 00285 // Given a compare operator, return a matching New Value Jump 00286 // compare operator. Make sure that MI here is included in 00287 // HexagonInstrInfo.cpp::isNewValueJumpCandidate 00288 static unsigned getNewValueJumpOpcode(MachineInstr *MI, int reg, 00289 bool secondRegNewified, 00290 MachineBasicBlock *jmpTarget, 00291 const MachineBranchProbabilityInfo 00292 *MBPI) { 00293 bool taken = false; 00294 MachineBasicBlock *Src = MI->getParent(); 00295 const BranchProbability Prediction = 00296 MBPI->getEdgeProbability(Src, jmpTarget); 00297 00298 if (Prediction >= BranchProbability(1,2)) 00299 taken = true; 00300 00301 switch (MI->getOpcode()) { 00302 case Hexagon::CMPEQrr: 00303 return taken ? Hexagon::CMPEQrr_t_Jumpnv_t_V4 00304 : Hexagon::CMPEQrr_t_Jumpnv_nt_V4; 00305 00306 case Hexagon::CMPEQri: { 00307 if (reg >= 0) 00308 return taken ? Hexagon::CMPEQri_t_Jumpnv_t_V4 00309 : Hexagon::CMPEQri_t_Jumpnv_nt_V4; 00310 else 00311 return taken ? Hexagon::CMPEQn1_t_Jumpnv_t_V4 00312 : Hexagon::CMPEQn1_t_Jumpnv_nt_V4; 00313 } 00314 00315 case Hexagon::CMPGTrr: { 00316 if (secondRegNewified) 00317 return taken ? Hexagon::CMPLTrr_t_Jumpnv_t_V4 00318 : Hexagon::CMPLTrr_t_Jumpnv_nt_V4; 00319 else 00320 return taken ? Hexagon::CMPGTrr_t_Jumpnv_t_V4 00321 : Hexagon::CMPGTrr_t_Jumpnv_nt_V4; 00322 } 00323 00324 case Hexagon::CMPGTri: { 00325 if (reg >= 0) 00326 return taken ? Hexagon::CMPGTri_t_Jumpnv_t_V4 00327 : Hexagon::CMPGTri_t_Jumpnv_nt_V4; 00328 else 00329 return taken ? Hexagon::CMPGTn1_t_Jumpnv_t_V4 00330 : Hexagon::CMPGTn1_t_Jumpnv_nt_V4; 00331 } 00332 00333 case Hexagon::CMPGTUrr: { 00334 if (secondRegNewified) 00335 return taken ? Hexagon::CMPLTUrr_t_Jumpnv_t_V4 00336 : Hexagon::CMPLTUrr_t_Jumpnv_nt_V4; 00337 else 00338 return taken ? Hexagon::CMPGTUrr_t_Jumpnv_t_V4 00339 : Hexagon::CMPGTUrr_t_Jumpnv_nt_V4; 00340 } 00341 00342 case Hexagon::CMPGTUri: 00343 return taken ? Hexagon::CMPGTUri_t_Jumpnv_t_V4 00344 : Hexagon::CMPGTUri_t_Jumpnv_nt_V4; 00345 00346 default: 00347 llvm_unreachable("Could not find matching New Value Jump instruction."); 00348 } 00349 // return *some value* to avoid compiler warning 00350 return 0; 00351 } 00352 00353 bool HexagonNewValueJump::runOnMachineFunction(MachineFunction &MF) { 00354 00355 DEBUG(dbgs() << "********** Hexagon New Value Jump **********\n" 00356 << "********** Function: " 00357 << MF.getName() << "\n"); 00358 00359 #if 0 00360 // for now disable this, if we move NewValueJump before register 00361 // allocation we need this information. 00362 LiveVariables &LVs = getAnalysis<LiveVariables>(); 00363 #endif 00364 00365 QII = static_cast<const HexagonInstrInfo *>(MF.getSubtarget().getInstrInfo()); 00366 QRI = static_cast<const HexagonRegisterInfo *>( 00367 MF.getSubtarget().getRegisterInfo()); 00368 MBPI = &getAnalysis<MachineBranchProbabilityInfo>(); 00369 00370 if (!QRI->Subtarget.hasV4TOps() || 00371 DisableNewValueJumps) { 00372 return false; 00373 } 00374 00375 int nvjCount = DbgNVJCount; 00376 int nvjGenerated = 0; 00377 00378 // Loop through all the bb's of the function 00379 for (MachineFunction::iterator MBBb = MF.begin(), MBBe = MF.end(); 00380 MBBb != MBBe; ++MBBb) { 00381 MachineBasicBlock* MBB = MBBb; 00382 00383 DEBUG(dbgs() << "** dumping bb ** " 00384 << MBB->getNumber() << "\n"); 00385 DEBUG(MBB->dump()); 00386 DEBUG(dbgs() << "\n" << "********** dumping instr bottom up **********\n"); 00387 bool foundJump = false; 00388 bool foundCompare = false; 00389 bool invertPredicate = false; 00390 unsigned predReg = 0; // predicate reg of the jump. 00391 unsigned cmpReg1 = 0; 00392 int cmpOp2 = 0; 00393 bool MO1IsKill = false; 00394 bool MO2IsKill = false; 00395 MachineBasicBlock::iterator jmpPos; 00396 MachineBasicBlock::iterator cmpPos; 00397 MachineInstr *cmpInstr = nullptr, *jmpInstr = nullptr; 00398 MachineBasicBlock *jmpTarget = nullptr; 00399 bool afterRA = false; 00400 bool isSecondOpReg = false; 00401 bool isSecondOpNewified = false; 00402 // Traverse the basic block - bottom up 00403 for (MachineBasicBlock::iterator MII = MBB->end(), E = MBB->begin(); 00404 MII != E;) { 00405 MachineInstr *MI = --MII; 00406 if (MI->isDebugValue()) { 00407 continue; 00408 } 00409 00410 if ((nvjCount == 0) || (nvjCount > -1 && nvjCount <= nvjGenerated)) 00411 break; 00412 00413 DEBUG(dbgs() << "Instr: "; MI->dump(); dbgs() << "\n"); 00414 00415 if (!foundJump && 00416 (MI->getOpcode() == Hexagon::JMP_t || 00417 MI->getOpcode() == Hexagon::JMP_f || 00418 MI->getOpcode() == Hexagon::JMP_tnew_t || 00419 MI->getOpcode() == Hexagon::JMP_tnew_nt || 00420 MI->getOpcode() == Hexagon::JMP_fnew_t || 00421 MI->getOpcode() == Hexagon::JMP_fnew_nt)) { 00422 // This is where you would insert your compare and 00423 // instr that feeds compare 00424 jmpPos = MII; 00425 jmpInstr = MI; 00426 predReg = MI->getOperand(0).getReg(); 00427 afterRA = TargetRegisterInfo::isPhysicalRegister(predReg); 00428 00429 // If ifconverter had not messed up with the kill flags of the 00430 // operands, the following check on the kill flag would suffice. 00431 // if(!jmpInstr->getOperand(0).isKill()) break; 00432 00433 // This predicate register is live out out of BB 00434 // this would only work if we can actually use Live 00435 // variable analysis on phy regs - but LLVM does not 00436 // provide LV analysis on phys regs. 00437 //if(LVs.isLiveOut(predReg, *MBB)) break; 00438 00439 // Get all the successors of this block - which will always 00440 // be 2. Check if the predicate register is live in in those 00441 // successor. If yes, we can not delete the predicate - 00442 // I am doing this only because LLVM does not provide LiveOut 00443 // at the BB level. 00444 bool predLive = false; 00445 for (MachineBasicBlock::const_succ_iterator SI = MBB->succ_begin(), 00446 SIE = MBB->succ_end(); SI != SIE; ++SI) { 00447 MachineBasicBlock* succMBB = *SI; 00448 if (succMBB->isLiveIn(predReg)) { 00449 predLive = true; 00450 } 00451 } 00452 if (predLive) 00453 break; 00454 00455 jmpTarget = MI->getOperand(1).getMBB(); 00456 foundJump = true; 00457 if (MI->getOpcode() == Hexagon::JMP_f || 00458 MI->getOpcode() == Hexagon::JMP_fnew_t || 00459 MI->getOpcode() == Hexagon::JMP_fnew_nt) { 00460 invertPredicate = true; 00461 } 00462 continue; 00463 } 00464 00465 // No new value jump if there is a barrier. A barrier has to be in its 00466 // own packet. A barrier has zero operands. We conservatively bail out 00467 // here if we see any instruction with zero operands. 00468 if (foundJump && MI->getNumOperands() == 0) 00469 break; 00470 00471 if (foundJump && 00472 !foundCompare && 00473 MI->getOperand(0).isReg() && 00474 MI->getOperand(0).getReg() == predReg) { 00475 00476 // Not all compares can be new value compare. Arch Spec: 7.6.1.1 00477 if (QII->isNewValueJumpCandidate(MI)) { 00478 00479 assert((MI->getDesc().isCompare()) && 00480 "Only compare instruction can be collapsed into New Value Jump"); 00481 isSecondOpReg = MI->getOperand(2).isReg(); 00482 00483 if (!canCompareBeNewValueJump(QII, QRI, MII, predReg, isSecondOpReg, 00484 afterRA, jmpPos, MF)) 00485 break; 00486 00487 cmpInstr = MI; 00488 cmpPos = MII; 00489 foundCompare = true; 00490 00491 // We need cmpReg1 and cmpOp2(imm or reg) while building 00492 // new value jump instruction. 00493 cmpReg1 = MI->getOperand(1).getReg(); 00494 if (MI->getOperand(1).isKill()) 00495 MO1IsKill = true; 00496 00497 if (isSecondOpReg) { 00498 cmpOp2 = MI->getOperand(2).getReg(); 00499 if (MI->getOperand(2).isKill()) 00500 MO2IsKill = true; 00501 } else 00502 cmpOp2 = MI->getOperand(2).getImm(); 00503 continue; 00504 } 00505 } 00506 00507 if (foundCompare && foundJump) { 00508 00509 // If "common" checks fail, bail out on this BB. 00510 if (!commonChecksToProhibitNewValueJump(afterRA, MII)) 00511 break; 00512 00513 bool foundFeeder = false; 00514 MachineBasicBlock::iterator feederPos = MII; 00515 if (MI->getOperand(0).isReg() && 00516 MI->getOperand(0).isDef() && 00517 (MI->getOperand(0).getReg() == cmpReg1 || 00518 (isSecondOpReg && 00519 MI->getOperand(0).getReg() == (unsigned) cmpOp2))) { 00520 00521 unsigned feederReg = MI->getOperand(0).getReg(); 00522 00523 // First try to see if we can get the feeder from the first operand 00524 // of the compare. If we can not, and if secondOpReg is true 00525 // (second operand of the compare is also register), try that one. 00526 // TODO: Try to come up with some heuristic to figure out which 00527 // feeder would benefit. 00528 00529 if (feederReg == cmpReg1) { 00530 if (!canBeFeederToNewValueJump(QII, QRI, MII, jmpPos, cmpPos, MF)) { 00531 if (!isSecondOpReg) 00532 break; 00533 else 00534 continue; 00535 } else 00536 foundFeeder = true; 00537 } 00538 00539 if (!foundFeeder && 00540 isSecondOpReg && 00541 feederReg == (unsigned) cmpOp2) 00542 if (!canBeFeederToNewValueJump(QII, QRI, MII, jmpPos, cmpPos, MF)) 00543 break; 00544 00545 if (isSecondOpReg) { 00546 // In case of CMPLT, or CMPLTU, or EQ with the second register 00547 // to newify, swap the operands. 00548 if (cmpInstr->getOpcode() == Hexagon::CMPEQrr && 00549 feederReg == (unsigned) cmpOp2) { 00550 unsigned tmp = cmpReg1; 00551 bool tmpIsKill = MO1IsKill; 00552 cmpReg1 = cmpOp2; 00553 MO1IsKill = MO2IsKill; 00554 cmpOp2 = tmp; 00555 MO2IsKill = tmpIsKill; 00556 } 00557 00558 // Now we have swapped the operands, all we need to check is, 00559 // if the second operand (after swap) is the feeder. 00560 // And if it is, make a note. 00561 if (feederReg == (unsigned)cmpOp2) 00562 isSecondOpNewified = true; 00563 } 00564 00565 // Now that we are moving feeder close the jump, 00566 // make sure we are respecting the kill values of 00567 // the operands of the feeder. 00568 00569 bool updatedIsKill = false; 00570 for (unsigned i = 0; i < MI->getNumOperands(); i++) { 00571 MachineOperand &MO = MI->getOperand(i); 00572 if (MO.isReg() && MO.isUse()) { 00573 unsigned feederReg = MO.getReg(); 00574 for (MachineBasicBlock::iterator localII = feederPos, 00575 end = jmpPos; localII != end; localII++) { 00576 MachineInstr *localMI = localII; 00577 for (unsigned j = 0; j < localMI->getNumOperands(); j++) { 00578 MachineOperand &localMO = localMI->getOperand(j); 00579 if (localMO.isReg() && localMO.isUse() && 00580 localMO.isKill() && feederReg == localMO.getReg()) { 00581 // We found that there is kill of a use register 00582 // Set up a kill flag on the register 00583 localMO.setIsKill(false); 00584 MO.setIsKill(); 00585 updatedIsKill = true; 00586 break; 00587 } 00588 } 00589 if (updatedIsKill) break; 00590 } 00591 } 00592 if (updatedIsKill) break; 00593 } 00594 00595 MBB->splice(jmpPos, MI->getParent(), MI); 00596 MBB->splice(jmpPos, MI->getParent(), cmpInstr); 00597 DebugLoc dl = MI->getDebugLoc(); 00598 MachineInstr *NewMI; 00599 00600 assert((QII->isNewValueJumpCandidate(cmpInstr)) && 00601 "This compare is not a New Value Jump candidate."); 00602 unsigned opc = getNewValueJumpOpcode(cmpInstr, cmpOp2, 00603 isSecondOpNewified, 00604 jmpTarget, MBPI); 00605 if (invertPredicate) 00606 opc = QII->getInvertedPredicatedOpcode(opc); 00607 00608 if (isSecondOpReg) 00609 NewMI = BuildMI(*MBB, jmpPos, dl, 00610 QII->get(opc)) 00611 .addReg(cmpReg1, getKillRegState(MO1IsKill)) 00612 .addReg(cmpOp2, getKillRegState(MO2IsKill)) 00613 .addMBB(jmpTarget); 00614 00615 else if ((cmpInstr->getOpcode() == Hexagon::CMPEQri || 00616 cmpInstr->getOpcode() == Hexagon::CMPGTri) && 00617 cmpOp2 == -1 ) 00618 // Corresponding new-value compare jump instructions don't have the 00619 // operand for -1 immediate value. 00620 NewMI = BuildMI(*MBB, jmpPos, dl, 00621 QII->get(opc)) 00622 .addReg(cmpReg1, getKillRegState(MO1IsKill)) 00623 .addMBB(jmpTarget); 00624 00625 else 00626 NewMI = BuildMI(*MBB, jmpPos, dl, 00627 QII->get(opc)) 00628 .addReg(cmpReg1, getKillRegState(MO1IsKill)) 00629 .addImm(cmpOp2) 00630 .addMBB(jmpTarget); 00631 00632 assert(NewMI && "New Value Jump Instruction Not created!"); 00633 (void)NewMI; 00634 if (cmpInstr->getOperand(0).isReg() && 00635 cmpInstr->getOperand(0).isKill()) 00636 cmpInstr->getOperand(0).setIsKill(false); 00637 if (cmpInstr->getOperand(1).isReg() && 00638 cmpInstr->getOperand(1).isKill()) 00639 cmpInstr->getOperand(1).setIsKill(false); 00640 cmpInstr->eraseFromParent(); 00641 jmpInstr->eraseFromParent(); 00642 ++nvjGenerated; 00643 ++NumNVJGenerated; 00644 break; 00645 } 00646 } 00647 } 00648 } 00649 00650 return true; 00651 00652 } 00653 00654 FunctionPass *llvm::createHexagonNewValueJump() { 00655 return new HexagonNewValueJump(); 00656 }