1 //===- llvm/CodeGen/GlobalISel/Utils.cpp -------------------------*- C++ -*-==// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// \file This file implements the utility functions used by the GlobalISel 9 /// pipeline. 10 //===----------------------------------------------------------------------===// 11 12 #include "llvm/CodeGen/GlobalISel/Utils.h" 13 #include "llvm/ADT/APFloat.h" 14 #include "llvm/ADT/APInt.h" 15 #include "llvm/ADT/Optional.h" 16 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h" 17 #include "llvm/CodeGen/GlobalISel/GISelKnownBits.h" 18 #include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h" 19 #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" 20 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h" 21 #include "llvm/CodeGen/MachineInstr.h" 22 #include "llvm/CodeGen/MachineInstrBuilder.h" 23 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" 24 #include "llvm/CodeGen/MachineSizeOpts.h" 25 #include "llvm/CodeGen/MachineRegisterInfo.h" 26 #include "llvm/CodeGen/StackProtector.h" 27 #include "llvm/CodeGen/TargetInstrInfo.h" 28 #include "llvm/CodeGen/TargetLowering.h" 29 #include "llvm/CodeGen/TargetPassConfig.h" 30 #include "llvm/CodeGen/TargetRegisterInfo.h" 31 #include "llvm/IR/Constants.h" 32 #include "llvm/Target/TargetMachine.h" 33 34 #define DEBUG_TYPE "globalisel-utils" 35 36 using namespace llvm; 37 using namespace MIPatternMatch; 38 39 Register llvm::constrainRegToClass(MachineRegisterInfo &MRI, 40 const TargetInstrInfo &TII, 41 const RegisterBankInfo &RBI, Register Reg, 42 const TargetRegisterClass &RegClass) { 43 if (!RBI.constrainGenericRegister(Reg, RegClass, MRI)) 44 return MRI.createVirtualRegister(&RegClass); 45 46 return Reg; 47 } 48 49 Register llvm::constrainOperandRegClass( 50 const MachineFunction &MF, const TargetRegisterInfo &TRI, 51 MachineRegisterInfo &MRI, const TargetInstrInfo &TII, 52 const RegisterBankInfo &RBI, MachineInstr &InsertPt, 53 const TargetRegisterClass &RegClass, MachineOperand &RegMO) { 54 Register Reg = RegMO.getReg(); 55 // Assume physical registers are properly constrained. 56 assert(Register::isVirtualRegister(Reg) && "PhysReg not implemented"); 57 58 Register ConstrainedReg = constrainRegToClass(MRI, TII, RBI, Reg, RegClass); 59 // If we created a new virtual register because the class is not compatible 60 // then create a copy between the new and the old register. 61 if (ConstrainedReg != Reg) { 62 MachineBasicBlock::iterator InsertIt(&InsertPt); 63 MachineBasicBlock &MBB = *InsertPt.getParent(); 64 if (RegMO.isUse()) { 65 BuildMI(MBB, InsertIt, InsertPt.getDebugLoc(), 66 TII.get(TargetOpcode::COPY), ConstrainedReg) 67 .addReg(Reg); 68 } else { 69 assert(RegMO.isDef() && "Must be a definition"); 70 BuildMI(MBB, std::next(InsertIt), InsertPt.getDebugLoc(), 71 TII.get(TargetOpcode::COPY), Reg) 72 .addReg(ConstrainedReg); 73 } 74 if (GISelChangeObserver *Observer = MF.getObserver()) { 75 Observer->changingInstr(*RegMO.getParent()); 76 } 77 RegMO.setReg(ConstrainedReg); 78 if (GISelChangeObserver *Observer = MF.getObserver()) { 79 Observer->changedInstr(*RegMO.getParent()); 80 } 81 } else { 82 if (GISelChangeObserver *Observer = MF.getObserver()) { 83 if (!RegMO.isDef()) { 84 MachineInstr *RegDef = MRI.getVRegDef(Reg); 85 Observer->changedInstr(*RegDef); 86 } 87 Observer->changingAllUsesOfReg(MRI, Reg); 88 Observer->finishedChangingAllUsesOfReg(); 89 } 90 } 91 return ConstrainedReg; 92 } 93 94 Register llvm::constrainOperandRegClass( 95 const MachineFunction &MF, const TargetRegisterInfo &TRI, 96 MachineRegisterInfo &MRI, const TargetInstrInfo &TII, 97 const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, 98 MachineOperand &RegMO, unsigned OpIdx) { 99 Register Reg = RegMO.getReg(); 100 // Assume physical registers are properly constrained. 101 assert(Register::isVirtualRegister(Reg) && "PhysReg not implemented"); 102 103 const TargetRegisterClass *RegClass = TII.getRegClass(II, OpIdx, &TRI, MF); 104 // Some of the target independent instructions, like COPY, may not impose any 105 // register class constraints on some of their operands: If it's a use, we can 106 // skip constraining as the instruction defining the register would constrain 107 // it. 108 109 // We can't constrain unallocatable register classes, because we can't create 110 // virtual registers for these classes, so we need to let targets handled this 111 // case. 112 if (RegClass && !RegClass->isAllocatable()) 113 RegClass = TRI.getConstrainedRegClassForOperand(RegMO, MRI); 114 115 if (!RegClass) { 116 assert((!isTargetSpecificOpcode(II.getOpcode()) || RegMO.isUse()) && 117 "Register class constraint is required unless either the " 118 "instruction is target independent or the operand is a use"); 119 // FIXME: Just bailing out like this here could be not enough, unless we 120 // expect the users of this function to do the right thing for PHIs and 121 // COPY: 122 // v1 = COPY v0 123 // v2 = COPY v1 124 // v1 here may end up not being constrained at all. Please notice that to 125 // reproduce the issue we likely need a destination pattern of a selection 126 // rule producing such extra copies, not just an input GMIR with them as 127 // every existing target using selectImpl handles copies before calling it 128 // and they never reach this function. 129 return Reg; 130 } 131 return constrainOperandRegClass(MF, TRI, MRI, TII, RBI, InsertPt, *RegClass, 132 RegMO); 133 } 134 135 bool llvm::constrainSelectedInstRegOperands(MachineInstr &I, 136 const TargetInstrInfo &TII, 137 const TargetRegisterInfo &TRI, 138 const RegisterBankInfo &RBI) { 139 assert(!isPreISelGenericOpcode(I.getOpcode()) && 140 "A selected instruction is expected"); 141 MachineBasicBlock &MBB = *I.getParent(); 142 MachineFunction &MF = *MBB.getParent(); 143 MachineRegisterInfo &MRI = MF.getRegInfo(); 144 145 for (unsigned OpI = 0, OpE = I.getNumExplicitOperands(); OpI != OpE; ++OpI) { 146 MachineOperand &MO = I.getOperand(OpI); 147 148 // There's nothing to be done on non-register operands. 149 if (!MO.isReg()) 150 continue; 151 152 LLVM_DEBUG(dbgs() << "Converting operand: " << MO << '\n'); 153 assert(MO.isReg() && "Unsupported non-reg operand"); 154 155 Register Reg = MO.getReg(); 156 // Physical registers don't need to be constrained. 157 if (Register::isPhysicalRegister(Reg)) 158 continue; 159 160 // Register operands with a value of 0 (e.g. predicate operands) don't need 161 // to be constrained. 162 if (Reg == 0) 163 continue; 164 165 // If the operand is a vreg, we should constrain its regclass, and only 166 // insert COPYs if that's impossible. 167 // constrainOperandRegClass does that for us. 168 constrainOperandRegClass(MF, TRI, MRI, TII, RBI, I, I.getDesc(), MO, OpI); 169 170 // Tie uses to defs as indicated in MCInstrDesc if this hasn't already been 171 // done. 172 if (MO.isUse()) { 173 int DefIdx = I.getDesc().getOperandConstraint(OpI, MCOI::TIED_TO); 174 if (DefIdx != -1 && !I.isRegTiedToUseOperand(DefIdx)) 175 I.tieOperands(DefIdx, OpI); 176 } 177 } 178 return true; 179 } 180 181 bool llvm::canReplaceReg(Register DstReg, Register SrcReg, 182 MachineRegisterInfo &MRI) { 183 // Give up if either DstReg or SrcReg is a physical register. 184 if (DstReg.isPhysical() || SrcReg.isPhysical()) 185 return false; 186 // Give up if the types don't match. 187 if (MRI.getType(DstReg) != MRI.getType(SrcReg)) 188 return false; 189 // Replace if either DstReg has no constraints or the register 190 // constraints match. 191 return !MRI.getRegClassOrRegBank(DstReg) || 192 MRI.getRegClassOrRegBank(DstReg) == MRI.getRegClassOrRegBank(SrcReg); 193 } 194 195 bool llvm::isTriviallyDead(const MachineInstr &MI, 196 const MachineRegisterInfo &MRI) { 197 // FIXME: This logical is mostly duplicated with 198 // DeadMachineInstructionElim::isDead. Why is LOCAL_ESCAPE not considered in 199 // MachineInstr::isLabel? 200 201 // Don't delete frame allocation labels. 202 if (MI.getOpcode() == TargetOpcode::LOCAL_ESCAPE) 203 return false; 204 // LIFETIME markers should be preserved even if they seem dead. 205 if (MI.getOpcode() == TargetOpcode::LIFETIME_START || 206 MI.getOpcode() == TargetOpcode::LIFETIME_END) 207 return false; 208 209 // If we can move an instruction, we can remove it. Otherwise, it has 210 // a side-effect of some sort. 211 bool SawStore = false; 212 if (!MI.isSafeToMove(/*AA=*/nullptr, SawStore) && !MI.isPHI()) 213 return false; 214 215 // Instructions without side-effects are dead iff they only define dead vregs. 216 for (auto &MO : MI.operands()) { 217 if (!MO.isReg() || !MO.isDef()) 218 continue; 219 220 Register Reg = MO.getReg(); 221 if (Register::isPhysicalRegister(Reg) || !MRI.use_nodbg_empty(Reg)) 222 return false; 223 } 224 return true; 225 } 226 227 static void reportGISelDiagnostic(DiagnosticSeverity Severity, 228 MachineFunction &MF, 229 const TargetPassConfig &TPC, 230 MachineOptimizationRemarkEmitter &MORE, 231 MachineOptimizationRemarkMissed &R) { 232 bool IsFatal = Severity == DS_Error && 233 TPC.isGlobalISelAbortEnabled(); 234 // Print the function name explicitly if we don't have a debug location (which 235 // makes the diagnostic less useful) or if we're going to emit a raw error. 236 if (!R.getLocation().isValid() || IsFatal) 237 R << (" (in function: " + MF.getName() + ")").str(); 238 239 if (IsFatal) 240 report_fatal_error(Twine(R.getMsg())); 241 else 242 MORE.emit(R); 243 } 244 245 void llvm::reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC, 246 MachineOptimizationRemarkEmitter &MORE, 247 MachineOptimizationRemarkMissed &R) { 248 reportGISelDiagnostic(DS_Warning, MF, TPC, MORE, R); 249 } 250 251 void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, 252 MachineOptimizationRemarkEmitter &MORE, 253 MachineOptimizationRemarkMissed &R) { 254 MF.getProperties().set(MachineFunctionProperties::Property::FailedISel); 255 reportGISelDiagnostic(DS_Error, MF, TPC, MORE, R); 256 } 257 258 void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, 259 MachineOptimizationRemarkEmitter &MORE, 260 const char *PassName, StringRef Msg, 261 const MachineInstr &MI) { 262 MachineOptimizationRemarkMissed R(PassName, "GISelFailure: ", 263 MI.getDebugLoc(), MI.getParent()); 264 R << Msg; 265 // Printing MI is expensive; only do it if expensive remarks are enabled. 266 if (TPC.isGlobalISelAbortEnabled() || MORE.allowExtraAnalysis(PassName)) 267 R << ": " << ore::MNV("Inst", MI); 268 reportGISelFailure(MF, TPC, MORE, R); 269 } 270 271 Optional<APInt> llvm::getIConstantVRegVal(Register VReg, 272 const MachineRegisterInfo &MRI) { 273 Optional<ValueAndVReg> ValAndVReg = getIConstantVRegValWithLookThrough( 274 VReg, MRI, /*LookThroughInstrs*/ false); 275 assert((!ValAndVReg || ValAndVReg->VReg == VReg) && 276 "Value found while looking through instrs"); 277 if (!ValAndVReg) 278 return None; 279 return ValAndVReg->Value; 280 } 281 282 Optional<int64_t> 283 llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI) { 284 Optional<APInt> Val = getIConstantVRegVal(VReg, MRI); 285 if (Val && Val->getBitWidth() <= 64) 286 return Val->getSExtValue(); 287 return None; 288 } 289 290 namespace { 291 292 typedef std::function<bool(const MachineInstr *)> IsOpcodeFn; 293 typedef std::function<Optional<APInt>(const MachineInstr *MI)> GetAPCstFn; 294 295 Optional<ValueAndVReg> getConstantVRegValWithLookThrough( 296 Register VReg, const MachineRegisterInfo &MRI, IsOpcodeFn IsConstantOpcode, 297 GetAPCstFn getAPCstValue, bool LookThroughInstrs = true, 298 bool LookThroughAnyExt = false) { 299 SmallVector<std::pair<unsigned, unsigned>, 4> SeenOpcodes; 300 MachineInstr *MI; 301 302 while ((MI = MRI.getVRegDef(VReg)) && !IsConstantOpcode(MI) && 303 LookThroughInstrs) { 304 switch (MI->getOpcode()) { 305 case TargetOpcode::G_ANYEXT: 306 if (!LookThroughAnyExt) 307 return None; 308 LLVM_FALLTHROUGH; 309 case TargetOpcode::G_TRUNC: 310 case TargetOpcode::G_SEXT: 311 case TargetOpcode::G_ZEXT: 312 SeenOpcodes.push_back(std::make_pair( 313 MI->getOpcode(), 314 MRI.getType(MI->getOperand(0).getReg()).getSizeInBits())); 315 VReg = MI->getOperand(1).getReg(); 316 break; 317 case TargetOpcode::COPY: 318 VReg = MI->getOperand(1).getReg(); 319 if (Register::isPhysicalRegister(VReg)) 320 return None; 321 break; 322 case TargetOpcode::G_INTTOPTR: 323 VReg = MI->getOperand(1).getReg(); 324 break; 325 default: 326 return None; 327 } 328 } 329 if (!MI || !IsConstantOpcode(MI)) 330 return None; 331 332 Optional<APInt> MaybeVal = getAPCstValue(MI); 333 if (!MaybeVal) 334 return None; 335 APInt &Val = *MaybeVal; 336 while (!SeenOpcodes.empty()) { 337 std::pair<unsigned, unsigned> OpcodeAndSize = SeenOpcodes.pop_back_val(); 338 switch (OpcodeAndSize.first) { 339 case TargetOpcode::G_TRUNC: 340 Val = Val.trunc(OpcodeAndSize.second); 341 break; 342 case TargetOpcode::G_ANYEXT: 343 case TargetOpcode::G_SEXT: 344 Val = Val.sext(OpcodeAndSize.second); 345 break; 346 case TargetOpcode::G_ZEXT: 347 Val = Val.zext(OpcodeAndSize.second); 348 break; 349 } 350 } 351 352 return ValueAndVReg{Val, VReg}; 353 } 354 355 bool isIConstant(const MachineInstr *MI) { 356 if (!MI) 357 return false; 358 return MI->getOpcode() == TargetOpcode::G_CONSTANT; 359 } 360 361 bool isFConstant(const MachineInstr *MI) { 362 if (!MI) 363 return false; 364 return MI->getOpcode() == TargetOpcode::G_FCONSTANT; 365 } 366 367 bool isAnyConstant(const MachineInstr *MI) { 368 if (!MI) 369 return false; 370 unsigned Opc = MI->getOpcode(); 371 return Opc == TargetOpcode::G_CONSTANT || Opc == TargetOpcode::G_FCONSTANT; 372 } 373 374 Optional<APInt> getCImmAsAPInt(const MachineInstr *MI) { 375 const MachineOperand &CstVal = MI->getOperand(1); 376 if (CstVal.isCImm()) 377 return CstVal.getCImm()->getValue(); 378 return None; 379 } 380 381 Optional<APInt> getCImmOrFPImmAsAPInt(const MachineInstr *MI) { 382 const MachineOperand &CstVal = MI->getOperand(1); 383 if (CstVal.isCImm()) 384 return CstVal.getCImm()->getValue(); 385 if (CstVal.isFPImm()) 386 return CstVal.getFPImm()->getValueAPF().bitcastToAPInt(); 387 return None; 388 } 389 390 } // end anonymous namespace 391 392 Optional<ValueAndVReg> llvm::getIConstantVRegValWithLookThrough( 393 Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs) { 394 return getConstantVRegValWithLookThrough(VReg, MRI, isIConstant, 395 getCImmAsAPInt, LookThroughInstrs); 396 } 397 398 Optional<ValueAndVReg> llvm::getAnyConstantVRegValWithLookThrough( 399 Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs, 400 bool LookThroughAnyExt) { 401 return getConstantVRegValWithLookThrough( 402 VReg, MRI, isAnyConstant, getCImmOrFPImmAsAPInt, LookThroughInstrs, 403 LookThroughAnyExt); 404 } 405 406 Optional<FPValueAndVReg> llvm::getFConstantVRegValWithLookThrough( 407 Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs) { 408 auto Reg = getConstantVRegValWithLookThrough( 409 VReg, MRI, isFConstant, getCImmOrFPImmAsAPInt, LookThroughInstrs); 410 if (!Reg) 411 return None; 412 return FPValueAndVReg{getConstantFPVRegVal(Reg->VReg, MRI)->getValueAPF(), 413 Reg->VReg}; 414 } 415 416 const ConstantFP * 417 llvm::getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI) { 418 MachineInstr *MI = MRI.getVRegDef(VReg); 419 if (TargetOpcode::G_FCONSTANT != MI->getOpcode()) 420 return nullptr; 421 return MI->getOperand(1).getFPImm(); 422 } 423 424 Optional<DefinitionAndSourceRegister> 425 llvm::getDefSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI) { 426 Register DefSrcReg = Reg; 427 auto *DefMI = MRI.getVRegDef(Reg); 428 auto DstTy = MRI.getType(DefMI->getOperand(0).getReg()); 429 if (!DstTy.isValid()) 430 return None; 431 unsigned Opc = DefMI->getOpcode(); 432 while (Opc == TargetOpcode::COPY || isPreISelGenericOptimizationHint(Opc)) { 433 Register SrcReg = DefMI->getOperand(1).getReg(); 434 auto SrcTy = MRI.getType(SrcReg); 435 if (!SrcTy.isValid()) 436 break; 437 DefMI = MRI.getVRegDef(SrcReg); 438 DefSrcReg = SrcReg; 439 Opc = DefMI->getOpcode(); 440 } 441 return DefinitionAndSourceRegister{DefMI, DefSrcReg}; 442 } 443 444 MachineInstr *llvm::getDefIgnoringCopies(Register Reg, 445 const MachineRegisterInfo &MRI) { 446 Optional<DefinitionAndSourceRegister> DefSrcReg = 447 getDefSrcRegIgnoringCopies(Reg, MRI); 448 return DefSrcReg ? DefSrcReg->MI : nullptr; 449 } 450 451 Register llvm::getSrcRegIgnoringCopies(Register Reg, 452 const MachineRegisterInfo &MRI) { 453 Optional<DefinitionAndSourceRegister> DefSrcReg = 454 getDefSrcRegIgnoringCopies(Reg, MRI); 455 return DefSrcReg ? DefSrcReg->Reg : Register(); 456 } 457 458 MachineInstr *llvm::getOpcodeDef(unsigned Opcode, Register Reg, 459 const MachineRegisterInfo &MRI) { 460 MachineInstr *DefMI = getDefIgnoringCopies(Reg, MRI); 461 return DefMI && DefMI->getOpcode() == Opcode ? DefMI : nullptr; 462 } 463 464 APFloat llvm::getAPFloatFromSize(double Val, unsigned Size) { 465 if (Size == 32) 466 return APFloat(float(Val)); 467 if (Size == 64) 468 return APFloat(Val); 469 if (Size != 16) 470 llvm_unreachable("Unsupported FPConstant size"); 471 bool Ignored; 472 APFloat APF(Val); 473 APF.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &Ignored); 474 return APF; 475 } 476 477 Optional<APInt> llvm::ConstantFoldBinOp(unsigned Opcode, const Register Op1, 478 const Register Op2, 479 const MachineRegisterInfo &MRI) { 480 auto MaybeOp2Cst = getAnyConstantVRegValWithLookThrough(Op2, MRI, false); 481 if (!MaybeOp2Cst) 482 return None; 483 484 auto MaybeOp1Cst = getAnyConstantVRegValWithLookThrough(Op1, MRI, false); 485 if (!MaybeOp1Cst) 486 return None; 487 488 const APInt &C1 = MaybeOp1Cst->Value; 489 const APInt &C2 = MaybeOp2Cst->Value; 490 switch (Opcode) { 491 default: 492 break; 493 case TargetOpcode::G_ADD: 494 return C1 + C2; 495 case TargetOpcode::G_AND: 496 return C1 & C2; 497 case TargetOpcode::G_ASHR: 498 return C1.ashr(C2); 499 case TargetOpcode::G_LSHR: 500 return C1.lshr(C2); 501 case TargetOpcode::G_MUL: 502 return C1 * C2; 503 case TargetOpcode::G_OR: 504 return C1 | C2; 505 case TargetOpcode::G_SHL: 506 return C1 << C2; 507 case TargetOpcode::G_SUB: 508 return C1 - C2; 509 case TargetOpcode::G_XOR: 510 return C1 ^ C2; 511 case TargetOpcode::G_UDIV: 512 if (!C2.getBoolValue()) 513 break; 514 return C1.udiv(C2); 515 case TargetOpcode::G_SDIV: 516 if (!C2.getBoolValue()) 517 break; 518 return C1.sdiv(C2); 519 case TargetOpcode::G_UREM: 520 if (!C2.getBoolValue()) 521 break; 522 return C1.urem(C2); 523 case TargetOpcode::G_SREM: 524 if (!C2.getBoolValue()) 525 break; 526 return C1.srem(C2); 527 } 528 529 return None; 530 } 531 532 Optional<APFloat> llvm::ConstantFoldFPBinOp(unsigned Opcode, const Register Op1, 533 const Register Op2, 534 const MachineRegisterInfo &MRI) { 535 const ConstantFP *Op2Cst = getConstantFPVRegVal(Op2, MRI); 536 if (!Op2Cst) 537 return None; 538 539 const ConstantFP *Op1Cst = getConstantFPVRegVal(Op1, MRI); 540 if (!Op1Cst) 541 return None; 542 543 APFloat C1 = Op1Cst->getValueAPF(); 544 const APFloat &C2 = Op2Cst->getValueAPF(); 545 switch (Opcode) { 546 case TargetOpcode::G_FADD: 547 C1.add(C2, APFloat::rmNearestTiesToEven); 548 return C1; 549 case TargetOpcode::G_FSUB: 550 C1.subtract(C2, APFloat::rmNearestTiesToEven); 551 return C1; 552 case TargetOpcode::G_FMUL: 553 C1.multiply(C2, APFloat::rmNearestTiesToEven); 554 return C1; 555 case TargetOpcode::G_FDIV: 556 C1.divide(C2, APFloat::rmNearestTiesToEven); 557 return C1; 558 case TargetOpcode::G_FREM: 559 C1.mod(C2); 560 return C1; 561 case TargetOpcode::G_FCOPYSIGN: 562 C1.copySign(C2); 563 return C1; 564 case TargetOpcode::G_FMINNUM: 565 return minnum(C1, C2); 566 case TargetOpcode::G_FMAXNUM: 567 return maxnum(C1, C2); 568 case TargetOpcode::G_FMINIMUM: 569 return minimum(C1, C2); 570 case TargetOpcode::G_FMAXIMUM: 571 return maximum(C1, C2); 572 case TargetOpcode::G_FMINNUM_IEEE: 573 case TargetOpcode::G_FMAXNUM_IEEE: 574 // FIXME: These operations were unfortunately named. fminnum/fmaxnum do not 575 // follow the IEEE behavior for signaling nans and follow libm's fmin/fmax, 576 // and currently there isn't a nice wrapper in APFloat for the version with 577 // correct snan handling. 578 break; 579 default: 580 break; 581 } 582 583 return None; 584 } 585 586 bool llvm::isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI, 587 bool SNaN) { 588 const MachineInstr *DefMI = MRI.getVRegDef(Val); 589 if (!DefMI) 590 return false; 591 592 const TargetMachine& TM = DefMI->getMF()->getTarget(); 593 if (DefMI->getFlag(MachineInstr::FmNoNans) || TM.Options.NoNaNsFPMath) 594 return true; 595 596 // If the value is a constant, we can obviously see if it is a NaN or not. 597 if (const ConstantFP *FPVal = getConstantFPVRegVal(Val, MRI)) { 598 return !FPVal->getValueAPF().isNaN() || 599 (SNaN && !FPVal->getValueAPF().isSignaling()); 600 } 601 602 if (DefMI->getOpcode() == TargetOpcode::G_BUILD_VECTOR) { 603 for (const auto &Op : DefMI->uses()) 604 if (!isKnownNeverNaN(Op.getReg(), MRI, SNaN)) 605 return false; 606 return true; 607 } 608 609 switch (DefMI->getOpcode()) { 610 default: 611 break; 612 case TargetOpcode::G_FMINNUM_IEEE: 613 case TargetOpcode::G_FMAXNUM_IEEE: { 614 if (SNaN) 615 return true; 616 // This can return a NaN if either operand is an sNaN, or if both operands 617 // are NaN. 618 return (isKnownNeverNaN(DefMI->getOperand(1).getReg(), MRI) && 619 isKnownNeverSNaN(DefMI->getOperand(2).getReg(), MRI)) || 620 (isKnownNeverSNaN(DefMI->getOperand(1).getReg(), MRI) && 621 isKnownNeverNaN(DefMI->getOperand(2).getReg(), MRI)); 622 } 623 case TargetOpcode::G_FMINNUM: 624 case TargetOpcode::G_FMAXNUM: { 625 // Only one needs to be known not-nan, since it will be returned if the 626 // other ends up being one. 627 return isKnownNeverNaN(DefMI->getOperand(1).getReg(), MRI, SNaN) || 628 isKnownNeverNaN(DefMI->getOperand(2).getReg(), MRI, SNaN); 629 } 630 } 631 632 if (SNaN) { 633 // FP operations quiet. For now, just handle the ones inserted during 634 // legalization. 635 switch (DefMI->getOpcode()) { 636 case TargetOpcode::G_FPEXT: 637 case TargetOpcode::G_FPTRUNC: 638 case TargetOpcode::G_FCANONICALIZE: 639 return true; 640 default: 641 return false; 642 } 643 } 644 645 return false; 646 } 647 648 Align llvm::inferAlignFromPtrInfo(MachineFunction &MF, 649 const MachinePointerInfo &MPO) { 650 auto PSV = MPO.V.dyn_cast<const PseudoSourceValue *>(); 651 if (auto FSPV = dyn_cast_or_null<FixedStackPseudoSourceValue>(PSV)) { 652 MachineFrameInfo &MFI = MF.getFrameInfo(); 653 return commonAlignment(MFI.getObjectAlign(FSPV->getFrameIndex()), 654 MPO.Offset); 655 } 656 657 if (const Value *V = MPO.V.dyn_cast<const Value *>()) { 658 const Module *M = MF.getFunction().getParent(); 659 return V->getPointerAlignment(M->getDataLayout()); 660 } 661 662 return Align(1); 663 } 664 665 Register llvm::getFunctionLiveInPhysReg(MachineFunction &MF, 666 const TargetInstrInfo &TII, 667 MCRegister PhysReg, 668 const TargetRegisterClass &RC, 669 LLT RegTy) { 670 DebugLoc DL; // FIXME: Is no location the right choice? 671 MachineBasicBlock &EntryMBB = MF.front(); 672 MachineRegisterInfo &MRI = MF.getRegInfo(); 673 Register LiveIn = MRI.getLiveInVirtReg(PhysReg); 674 if (LiveIn) { 675 MachineInstr *Def = MRI.getVRegDef(LiveIn); 676 if (Def) { 677 // FIXME: Should the verifier check this is in the entry block? 678 assert(Def->getParent() == &EntryMBB && "live-in copy not in entry block"); 679 return LiveIn; 680 } 681 682 // It's possible the incoming argument register and copy was added during 683 // lowering, but later deleted due to being/becoming dead. If this happens, 684 // re-insert the copy. 685 } else { 686 // The live in register was not present, so add it. 687 LiveIn = MF.addLiveIn(PhysReg, &RC); 688 if (RegTy.isValid()) 689 MRI.setType(LiveIn, RegTy); 690 } 691 692 BuildMI(EntryMBB, EntryMBB.begin(), DL, TII.get(TargetOpcode::COPY), LiveIn) 693 .addReg(PhysReg); 694 if (!EntryMBB.isLiveIn(PhysReg)) 695 EntryMBB.addLiveIn(PhysReg); 696 return LiveIn; 697 } 698 699 Optional<APInt> llvm::ConstantFoldExtOp(unsigned Opcode, const Register Op1, 700 uint64_t Imm, 701 const MachineRegisterInfo &MRI) { 702 auto MaybeOp1Cst = getIConstantVRegVal(Op1, MRI); 703 if (MaybeOp1Cst) { 704 switch (Opcode) { 705 default: 706 break; 707 case TargetOpcode::G_SEXT_INREG: { 708 LLT Ty = MRI.getType(Op1); 709 return MaybeOp1Cst->trunc(Imm).sext(Ty.getScalarSizeInBits()); 710 } 711 } 712 } 713 return None; 714 } 715 716 Optional<APFloat> llvm::ConstantFoldIntToFloat(unsigned Opcode, LLT DstTy, 717 Register Src, 718 const MachineRegisterInfo &MRI) { 719 assert(Opcode == TargetOpcode::G_SITOFP || Opcode == TargetOpcode::G_UITOFP); 720 if (auto MaybeSrcVal = getIConstantVRegVal(Src, MRI)) { 721 APFloat DstVal(getFltSemanticForLLT(DstTy)); 722 DstVal.convertFromAPInt(*MaybeSrcVal, Opcode == TargetOpcode::G_SITOFP, 723 APFloat::rmNearestTiesToEven); 724 return DstVal; 725 } 726 return None; 727 } 728 729 bool llvm::isKnownToBeAPowerOfTwo(Register Reg, const MachineRegisterInfo &MRI, 730 GISelKnownBits *KB) { 731 Optional<DefinitionAndSourceRegister> DefSrcReg = 732 getDefSrcRegIgnoringCopies(Reg, MRI); 733 if (!DefSrcReg) 734 return false; 735 736 const MachineInstr &MI = *DefSrcReg->MI; 737 const LLT Ty = MRI.getType(Reg); 738 739 switch (MI.getOpcode()) { 740 case TargetOpcode::G_CONSTANT: { 741 unsigned BitWidth = Ty.getScalarSizeInBits(); 742 const ConstantInt *CI = MI.getOperand(1).getCImm(); 743 return CI->getValue().zextOrTrunc(BitWidth).isPowerOf2(); 744 } 745 case TargetOpcode::G_SHL: { 746 // A left-shift of a constant one will have exactly one bit set because 747 // shifting the bit off the end is undefined. 748 749 // TODO: Constant splat 750 if (auto ConstLHS = getIConstantVRegVal(MI.getOperand(1).getReg(), MRI)) { 751 if (*ConstLHS == 1) 752 return true; 753 } 754 755 break; 756 } 757 case TargetOpcode::G_LSHR: { 758 if (auto ConstLHS = getIConstantVRegVal(MI.getOperand(1).getReg(), MRI)) { 759 if (ConstLHS->isSignMask()) 760 return true; 761 } 762 763 break; 764 } 765 case TargetOpcode::G_BUILD_VECTOR: { 766 // TODO: Probably should have a recursion depth guard since you could have 767 // bitcasted vector elements. 768 for (unsigned I = 1, E = MI.getNumOperands(); I != E; ++I) { 769 if (!isKnownToBeAPowerOfTwo(MI.getOperand(I).getReg(), MRI, KB)) 770 return false; 771 } 772 773 return true; 774 } 775 case TargetOpcode::G_BUILD_VECTOR_TRUNC: { 776 // Only handle constants since we would need to know if number of leading 777 // zeros is greater than the truncation amount. 778 const unsigned BitWidth = Ty.getScalarSizeInBits(); 779 for (unsigned I = 1, E = MI.getNumOperands(); I != E; ++I) { 780 auto Const = getIConstantVRegVal(MI.getOperand(I).getReg(), MRI); 781 if (!Const || !Const->zextOrTrunc(BitWidth).isPowerOf2()) 782 return false; 783 } 784 785 return true; 786 } 787 default: 788 break; 789 } 790 791 if (!KB) 792 return false; 793 794 // More could be done here, though the above checks are enough 795 // to handle some common cases. 796 797 // Fall back to computeKnownBits to catch other known cases. 798 KnownBits Known = KB->getKnownBits(Reg); 799 return (Known.countMaxPopulation() == 1) && (Known.countMinPopulation() == 1); 800 } 801 802 void llvm::getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU) { 803 AU.addPreserved<StackProtector>(); 804 } 805 806 static unsigned getLCMSize(unsigned OrigSize, unsigned TargetSize) { 807 unsigned Mul = OrigSize * TargetSize; 808 unsigned GCDSize = greatestCommonDivisor(OrigSize, TargetSize); 809 return Mul / GCDSize; 810 } 811 812 LLT llvm::getLCMType(LLT OrigTy, LLT TargetTy) { 813 const unsigned OrigSize = OrigTy.getSizeInBits(); 814 const unsigned TargetSize = TargetTy.getSizeInBits(); 815 816 if (OrigSize == TargetSize) 817 return OrigTy; 818 819 if (OrigTy.isVector()) { 820 const LLT OrigElt = OrigTy.getElementType(); 821 822 if (TargetTy.isVector()) { 823 const LLT TargetElt = TargetTy.getElementType(); 824 825 if (OrigElt.getSizeInBits() == TargetElt.getSizeInBits()) { 826 int GCDElts = greatestCommonDivisor(OrigTy.getNumElements(), 827 TargetTy.getNumElements()); 828 // Prefer the original element type. 829 ElementCount Mul = OrigTy.getElementCount() * TargetTy.getNumElements(); 830 return LLT::vector(Mul.divideCoefficientBy(GCDElts), 831 OrigTy.getElementType()); 832 } 833 } else { 834 if (OrigElt.getSizeInBits() == TargetSize) 835 return OrigTy; 836 } 837 838 unsigned LCMSize = getLCMSize(OrigSize, TargetSize); 839 return LLT::fixed_vector(LCMSize / OrigElt.getSizeInBits(), OrigElt); 840 } 841 842 if (TargetTy.isVector()) { 843 unsigned LCMSize = getLCMSize(OrigSize, TargetSize); 844 return LLT::fixed_vector(LCMSize / OrigSize, OrigTy); 845 } 846 847 unsigned LCMSize = getLCMSize(OrigSize, TargetSize); 848 849 // Preserve pointer types. 850 if (LCMSize == OrigSize) 851 return OrigTy; 852 if (LCMSize == TargetSize) 853 return TargetTy; 854 855 return LLT::scalar(LCMSize); 856 } 857 858 LLT llvm::getGCDType(LLT OrigTy, LLT TargetTy) { 859 const unsigned OrigSize = OrigTy.getSizeInBits(); 860 const unsigned TargetSize = TargetTy.getSizeInBits(); 861 862 if (OrigSize == TargetSize) 863 return OrigTy; 864 865 if (OrigTy.isVector()) { 866 LLT OrigElt = OrigTy.getElementType(); 867 if (TargetTy.isVector()) { 868 LLT TargetElt = TargetTy.getElementType(); 869 if (OrigElt.getSizeInBits() == TargetElt.getSizeInBits()) { 870 int GCD = greatestCommonDivisor(OrigTy.getNumElements(), 871 TargetTy.getNumElements()); 872 return LLT::scalarOrVector(ElementCount::getFixed(GCD), OrigElt); 873 } 874 } else { 875 // If the source is a vector of pointers, return a pointer element. 876 if (OrigElt.getSizeInBits() == TargetSize) 877 return OrigElt; 878 } 879 880 unsigned GCD = greatestCommonDivisor(OrigSize, TargetSize); 881 if (GCD == OrigElt.getSizeInBits()) 882 return OrigElt; 883 884 // If we can't produce the original element type, we have to use a smaller 885 // scalar. 886 if (GCD < OrigElt.getSizeInBits()) 887 return LLT::scalar(GCD); 888 return LLT::fixed_vector(GCD / OrigElt.getSizeInBits(), OrigElt); 889 } 890 891 if (TargetTy.isVector()) { 892 // Try to preserve the original element type. 893 LLT TargetElt = TargetTy.getElementType(); 894 if (TargetElt.getSizeInBits() == OrigSize) 895 return OrigTy; 896 } 897 898 unsigned GCD = greatestCommonDivisor(OrigSize, TargetSize); 899 return LLT::scalar(GCD); 900 } 901 902 Optional<int> llvm::getSplatIndex(MachineInstr &MI) { 903 assert(MI.getOpcode() == TargetOpcode::G_SHUFFLE_VECTOR && 904 "Only G_SHUFFLE_VECTOR can have a splat index!"); 905 ArrayRef<int> Mask = MI.getOperand(3).getShuffleMask(); 906 auto FirstDefinedIdx = find_if(Mask, [](int Elt) { return Elt >= 0; }); 907 908 // If all elements are undefined, this shuffle can be considered a splat. 909 // Return 0 for better potential for callers to simplify. 910 if (FirstDefinedIdx == Mask.end()) 911 return 0; 912 913 // Make sure all remaining elements are either undef or the same 914 // as the first non-undef value. 915 int SplatValue = *FirstDefinedIdx; 916 if (any_of(make_range(std::next(FirstDefinedIdx), Mask.end()), 917 [&SplatValue](int Elt) { return Elt >= 0 && Elt != SplatValue; })) 918 return None; 919 920 return SplatValue; 921 } 922 923 static bool isBuildVectorOp(unsigned Opcode) { 924 return Opcode == TargetOpcode::G_BUILD_VECTOR || 925 Opcode == TargetOpcode::G_BUILD_VECTOR_TRUNC; 926 } 927 928 namespace { 929 930 Optional<ValueAndVReg> getAnyConstantSplat(Register VReg, 931 const MachineRegisterInfo &MRI, 932 bool AllowUndef) { 933 MachineInstr *MI = getDefIgnoringCopies(VReg, MRI); 934 if (!MI) 935 return None; 936 937 if (!isBuildVectorOp(MI->getOpcode())) 938 return None; 939 940 Optional<ValueAndVReg> SplatValAndReg = None; 941 for (MachineOperand &Op : MI->uses()) { 942 Register Element = Op.getReg(); 943 auto ElementValAndReg = 944 getAnyConstantVRegValWithLookThrough(Element, MRI, true, true); 945 946 // If AllowUndef, treat undef as value that will result in a constant splat. 947 if (!ElementValAndReg) { 948 if (AllowUndef && isa<GImplicitDef>(MRI.getVRegDef(Element))) 949 continue; 950 return None; 951 } 952 953 // Record splat value 954 if (!SplatValAndReg) 955 SplatValAndReg = ElementValAndReg; 956 957 // Different constant then the one already recorded, not a constant splat. 958 if (SplatValAndReg->Value != ElementValAndReg->Value) 959 return None; 960 } 961 962 return SplatValAndReg; 963 } 964 965 bool isBuildVectorConstantSplat(const MachineInstr &MI, 966 const MachineRegisterInfo &MRI, 967 int64_t SplatValue, bool AllowUndef) { 968 if (auto SplatValAndReg = 969 getAnyConstantSplat(MI.getOperand(0).getReg(), MRI, AllowUndef)) 970 return mi_match(SplatValAndReg->VReg, MRI, m_SpecificICst(SplatValue)); 971 return false; 972 } 973 974 } // end anonymous namespace 975 976 Optional<int64_t> 977 llvm::getBuildVectorConstantSplat(const MachineInstr &MI, 978 const MachineRegisterInfo &MRI) { 979 if (auto SplatValAndReg = 980 getAnyConstantSplat(MI.getOperand(0).getReg(), MRI, false)) 981 return getIConstantVRegSExtVal(SplatValAndReg->VReg, MRI); 982 return None; 983 } 984 985 Optional<FPValueAndVReg> llvm::getFConstantSplat(Register VReg, 986 const MachineRegisterInfo &MRI, 987 bool AllowUndef) { 988 if (auto SplatValAndReg = getAnyConstantSplat(VReg, MRI, AllowUndef)) 989 return getFConstantVRegValWithLookThrough(SplatValAndReg->VReg, MRI); 990 return None; 991 } 992 993 bool llvm::isBuildVectorAllZeros(const MachineInstr &MI, 994 const MachineRegisterInfo &MRI, 995 bool AllowUndef) { 996 return isBuildVectorConstantSplat(MI, MRI, 0, AllowUndef); 997 } 998 999 bool llvm::isBuildVectorAllOnes(const MachineInstr &MI, 1000 const MachineRegisterInfo &MRI, 1001 bool AllowUndef) { 1002 return isBuildVectorConstantSplat(MI, MRI, -1, AllowUndef); 1003 } 1004 1005 Optional<RegOrConstant> llvm::getVectorSplat(const MachineInstr &MI, 1006 const MachineRegisterInfo &MRI) { 1007 unsigned Opc = MI.getOpcode(); 1008 if (!isBuildVectorOp(Opc)) 1009 return None; 1010 if (auto Splat = getBuildVectorConstantSplat(MI, MRI)) 1011 return RegOrConstant(*Splat); 1012 auto Reg = MI.getOperand(1).getReg(); 1013 if (any_of(make_range(MI.operands_begin() + 2, MI.operands_end()), 1014 [&Reg](const MachineOperand &Op) { return Op.getReg() != Reg; })) 1015 return None; 1016 return RegOrConstant(Reg); 1017 } 1018 1019 Optional<APInt> 1020 llvm::isConstantOrConstantSplatVector(MachineInstr &MI, 1021 const MachineRegisterInfo &MRI) { 1022 Register Def = MI.getOperand(0).getReg(); 1023 if (auto C = getIConstantVRegValWithLookThrough(Def, MRI)) 1024 return C->Value; 1025 auto MaybeCst = getBuildVectorConstantSplat(MI, MRI); 1026 if (!MaybeCst) 1027 return None; 1028 const unsigned ScalarSize = MRI.getType(Def).getScalarSizeInBits(); 1029 return APInt(ScalarSize, *MaybeCst, true); 1030 } 1031 1032 bool llvm::matchUnaryPredicate( 1033 const MachineRegisterInfo &MRI, Register Reg, 1034 std::function<bool(const Constant *ConstVal)> Match, bool AllowUndefs) { 1035 1036 const MachineInstr *Def = getDefIgnoringCopies(Reg, MRI); 1037 if (AllowUndefs && Def->getOpcode() == TargetOpcode::G_IMPLICIT_DEF) 1038 return Match(nullptr); 1039 1040 // TODO: Also handle fconstant 1041 if (Def->getOpcode() == TargetOpcode::G_CONSTANT) 1042 return Match(Def->getOperand(1).getCImm()); 1043 1044 if (Def->getOpcode() != TargetOpcode::G_BUILD_VECTOR) 1045 return false; 1046 1047 for (unsigned I = 1, E = Def->getNumOperands(); I != E; ++I) { 1048 Register SrcElt = Def->getOperand(I).getReg(); 1049 const MachineInstr *SrcDef = getDefIgnoringCopies(SrcElt, MRI); 1050 if (AllowUndefs && SrcDef->getOpcode() == TargetOpcode::G_IMPLICIT_DEF) { 1051 if (!Match(nullptr)) 1052 return false; 1053 continue; 1054 } 1055 1056 if (SrcDef->getOpcode() != TargetOpcode::G_CONSTANT || 1057 !Match(SrcDef->getOperand(1).getCImm())) 1058 return false; 1059 } 1060 1061 return true; 1062 } 1063 1064 bool llvm::isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector, 1065 bool IsFP) { 1066 switch (TLI.getBooleanContents(IsVector, IsFP)) { 1067 case TargetLowering::UndefinedBooleanContent: 1068 return Val & 0x1; 1069 case TargetLowering::ZeroOrOneBooleanContent: 1070 return Val == 1; 1071 case TargetLowering::ZeroOrNegativeOneBooleanContent: 1072 return Val == -1; 1073 } 1074 llvm_unreachable("Invalid boolean contents"); 1075 } 1076 1077 int64_t llvm::getICmpTrueVal(const TargetLowering &TLI, bool IsVector, 1078 bool IsFP) { 1079 switch (TLI.getBooleanContents(IsVector, IsFP)) { 1080 case TargetLowering::UndefinedBooleanContent: 1081 case TargetLowering::ZeroOrOneBooleanContent: 1082 return 1; 1083 case TargetLowering::ZeroOrNegativeOneBooleanContent: 1084 return -1; 1085 } 1086 llvm_unreachable("Invalid boolean contents"); 1087 } 1088 1089 bool llvm::shouldOptForSize(const MachineBasicBlock &MBB, 1090 ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) { 1091 const auto &F = MBB.getParent()->getFunction(); 1092 return F.hasOptSize() || F.hasMinSize() || 1093 llvm::shouldOptimizeForSize(MBB.getBasicBlock(), PSI, BFI); 1094 } 1095 1096 /// These artifacts generally don't have any debug users because they don't 1097 /// directly originate from IR instructions, but instead usually from 1098 /// legalization. Avoiding checking for debug users improves compile time. 1099 /// Note that truncates or extends aren't included because they have IR 1100 /// counterparts which can have debug users after translation. 1101 static bool shouldSkipDbgValueFor(MachineInstr &MI) { 1102 switch (MI.getOpcode()) { 1103 case TargetOpcode::G_UNMERGE_VALUES: 1104 case TargetOpcode::G_MERGE_VALUES: 1105 case TargetOpcode::G_CONCAT_VECTORS: 1106 case TargetOpcode::G_BUILD_VECTOR: 1107 case TargetOpcode::G_EXTRACT: 1108 case TargetOpcode::G_INSERT: 1109 return true; 1110 default: 1111 return false; 1112 } 1113 } 1114 1115 void llvm::saveUsesAndErase(MachineInstr &MI, MachineRegisterInfo &MRI, 1116 LostDebugLocObserver *LocObserver, 1117 SmallInstListTy &DeadInstChain) { 1118 for (MachineOperand &Op : MI.uses()) { 1119 if (Op.isReg() && Op.getReg().isVirtual()) 1120 DeadInstChain.insert(MRI.getVRegDef(Op.getReg())); 1121 } 1122 LLVM_DEBUG(dbgs() << MI << "Is dead; erasing.\n"); 1123 DeadInstChain.remove(&MI); 1124 if (shouldSkipDbgValueFor(MI)) 1125 MI.eraseFromParent(); 1126 else 1127 MI.eraseFromParentAndMarkDBGValuesForRemoval(); 1128 if (LocObserver) 1129 LocObserver->checkpoint(false); 1130 } 1131 1132 void llvm::eraseInstrs(ArrayRef<MachineInstr *> DeadInstrs, 1133 MachineRegisterInfo &MRI, 1134 LostDebugLocObserver *LocObserver) { 1135 SmallInstListTy DeadInstChain; 1136 for (MachineInstr *MI : DeadInstrs) 1137 saveUsesAndErase(*MI, MRI, LocObserver, DeadInstChain); 1138 1139 while (!DeadInstChain.empty()) { 1140 MachineInstr *Inst = DeadInstChain.pop_back_val(); 1141 if (!isTriviallyDead(*Inst, MRI)) 1142 continue; 1143 saveUsesAndErase(*Inst, MRI, LocObserver, DeadInstChain); 1144 } 1145 } 1146 1147 void llvm::eraseInstr(MachineInstr &MI, MachineRegisterInfo &MRI, 1148 LostDebugLocObserver *LocObserver) { 1149 return eraseInstrs({&MI}, MRI, LocObserver); 1150 } 1151