102struct MachineVerifier {
106 ReportedErrs(AbortOnError) {}
109 bool AbortOnError =
true)
111 ReportedErrs(AbortOnError) {}
116 bool AbortOnError =
true)
117 :
OS(
OS ? *
OS :
nulls()), Banner(
b), LiveVars(LiveVars),
118 LiveInts(LiveInts), LiveStks(LiveStks), Indexes(Indexes),
119 ReportedErrs(AbortOnError) {}
125 Pass *
const PASS =
nullptr;
136 bool isFunctionRegBankSelected =
false;
137 bool isFunctionSelected =
false;
138 bool isFunctionTracksDebugUserValues =
false;
148 BlockSet FunctionBlocks;
152 RegVector regsDefined, regsDead, regsKilled;
153 RegMaskVector regMasks;
158 void addRegWithSubRegs(RegVector &RV,
Register Reg) {
160 if (
Reg.isPhysical())
166 bool reachable =
false;
187 RegSet vregsRequired;
190 BlockSet Preds, Succs;
197 if (!
Reg.isVirtual())
199 if (regsLiveOut.count(Reg))
201 return vregsRequired.insert(Reg).second;
205 bool addRequired(
const RegSet &RS) {
206 bool Changed =
false;
208 Changed |= addRequired(Reg);
213 bool addRequired(
const RegMap &RM) {
214 bool Changed =
false;
215 for (
const auto &
I : RM)
216 Changed |= addRequired(
I.first);
222 return regsLiveOut.count(Reg) || vregsPassed.count(Reg);
230 return Reg.id() < regsReserved.
size() && regsReserved.
test(
Reg.id());
233 bool isAllocatable(
Register Reg)
const {
234 return Reg.id() <
TRI->getNumRegs() &&
TRI->isInAllocatableClass(Reg) &&
246 class ReportedErrors {
247 unsigned NumReported = 0;
252 ReportedErrors(
bool AbortOnError) : AbortOnError(AbortOnError) {}
259 " machine code errors.");
262 ReportedErrorsLock->unlock();
272 ReportedErrorsLock->lock();
274 return NumReported == 1;
278 bool hasError() {
return NumReported; }
280 ReportedErrors ReportedErrs;
287 void visitMachineFunctionBefore();
303 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
306 void visitMachineFunctionAfter();
311 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
319 void report_context(
const VNInfo &VNI)
const;
320 void report_context(
SlotIndex Pos)
const;
321 void report_context(
MCPhysReg PhysReg)
const;
322 void report_context_liverange(
const LiveRange &LR)
const;
323 void report_context_lanemask(
LaneBitmask LaneMask)
const;
324 void report_context_vreg(
Register VReg)
const;
325 void report_context_vreg_regunit(
Register VRegOrUnit)
const;
336 Register VRegOrUnit,
bool SubRangeCheck =
false,
340 void calcRegsPassed();
343 void calcRegsRequired();
344 void verifyLiveVariables();
345 void verifyLiveIntervals();
349 void verifyLiveRangeSegment(
const LiveRange &,
355 void verifyStackFrame();
357 void verifyStackProtector();
359 void verifySlotIndexes()
const;
366 const std::string Banner;
368 MachineVerifierLegacyPass(std::string banner = std::string())
387 MachineFunctionProperties::Property::FailsVerification))
390 MachineVerifier(
this, Banner.c_str(), &
errs()).verify(MF);
406 MachineVerifier(MFAM, Banner.c_str(), &
errs()).verify(MF);
410char MachineVerifierLegacyPass::ID = 0;
413 "Verify generated machine code",
false,
false)
416 return new MachineVerifierLegacyPass(Banner);
426 MachineVerifier(
nullptr, Banner.c_str(), &
errs()).verify(MF);
430 bool AbortOnError)
const {
431 return MachineVerifier(p, Banner,
OS, AbortOnError).verify(*
this);
436 bool AbortOnError)
const {
437 return MachineVerifier(Banner,
nullptr, LiveInts,
438 nullptr, Indexes,
OS, AbortOnError)
442void MachineVerifier::verifySlotIndexes()
const {
443 if (Indexes ==
nullptr)
461 MRI->getNumVirtRegs())
462 report(
"Function has NoVRegs property but there are VReg operands", &MF);
479 if (isFunctionFailedISel)
491 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
495 LiveVars = LVWrapper ? &LVWrapper->getLV() :
nullptr;
497 LiveStks = LSWrapper ? &LSWrapper->getLS() :
nullptr;
499 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
512 verifyProperties(MF);
514 visitMachineFunctionBefore();
516 visitMachineBasicBlockBefore(&
MBB);
520 bool InBundle =
false;
523 if (
MI.getParent() != &
MBB) {
524 report(
"Bad instruction parent pointer", &
MBB);
525 OS <<
"Instruction: " <<
MI;
530 if (InBundle && !
MI.isBundledWithPred())
531 report(
"Missing BundledPred flag, "
532 "BundledSucc was set on predecessor",
534 if (!InBundle &&
MI.isBundledWithPred())
535 report(
"BundledPred flag is set, "
536 "but BundledSucc not set on predecessor",
540 if (!
MI.isInsideBundle()) {
542 visitMachineBundleAfter(CurBundle);
544 visitMachineBundleBefore(CurBundle);
545 }
else if (!CurBundle)
546 report(
"No bundle header", &
MI);
547 visitMachineInstrBefore(&
MI);
548 for (
unsigned I = 0, E =
MI.getNumOperands();
I != E; ++
I) {
550 if (
Op.getParent() != &
MI) {
553 report(
"Instruction has operand with wrong parent set", &
MI);
556 visitMachineOperand(&
Op,
I);
560 InBundle =
MI.isBundledWithSucc();
563 visitMachineBundleAfter(CurBundle);
565 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
566 visitMachineBasicBlockAfter(&
MBB);
568 visitMachineFunctionAfter();
578 return !ReportedErrs.hasError();
581void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
584 if (ReportedErrs.increment()) {
586 OS <<
"# " << Banner <<
'\n';
588 if (LiveInts !=
nullptr)
594 OS <<
"*** Bad machine code: " << msg <<
" ***\n"
595 <<
"- function: " << MF->
getName() <<
'\n';
602 <<
" (" << (
const void *)
MBB <<
')';
604 OS <<
" [" << Indexes->getMBBStartIdx(
MBB) <<
';'
605 << Indexes->getMBBEndIdx(
MBB) <<
')';
609void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
611 report(msg,
MI->getParent());
612 OS <<
"- instruction: ";
613 if (Indexes && Indexes->hasIndex(*
MI))
614 OS << Indexes->getInstructionIndex(*
MI) <<
'\t';
618void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
619 unsigned MONum,
LLT MOVRegType) {
622 OS <<
"- operand " << MONum <<
": ";
628 report(Msg.
str().c_str(),
MI);
631void MachineVerifier::report_context(
SlotIndex Pos)
const {
632 OS <<
"- at: " << Pos <<
'\n';
635void MachineVerifier::report_context(
const LiveInterval &LI)
const {
636 OS <<
"- interval: " << LI <<
'\n';
641 report_context_liverange(LR);
642 report_context_vreg_regunit(VRegUnit);
644 report_context_lanemask(LaneMask);
648 OS <<
"- segment: " << S <<
'\n';
651void MachineVerifier::report_context(
const VNInfo &VNI)
const {
652 OS <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
655void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
656 OS <<
"- liverange: " << LR <<
'\n';
659void MachineVerifier::report_context(
MCPhysReg PReg)
const {
663void MachineVerifier::report_context_vreg(
Register VReg)
const {
667void MachineVerifier::report_context_vreg_regunit(
Register VRegOrUnit)
const {
669 report_context_vreg(VRegOrUnit);
675void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
680 BBInfo &MInfo = MBBInfoMap[
MBB];
681 if (!MInfo.reachable) {
682 MInfo.reachable =
true;
688void MachineVerifier::visitMachineFunctionBefore() {
690 regsReserved =
MRI->reservedRegsFrozen() ?
MRI->getReservedRegs()
691 :
TRI->getReservedRegs(*MF);
694 markReachable(&MF->
front());
697 FunctionBlocks.clear();
698 for (
const auto &
MBB : *MF) {
699 FunctionBlocks.insert(&
MBB);
700 BBInfo &MInfo = MBBInfoMap[&
MBB];
704 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
708 report(
"MBB has duplicate entries in its successor list.", &
MBB);
712 MRI->verifyUseLists();
716 verifyStackProtector();
722 FirstTerminator =
nullptr;
723 FirstNonPHI =
nullptr;
725 if (!MF->getProperties().hasProperty(
730 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
733 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
734 "inlineasm-br-indirect-target.",
736 report_context(LI.PhysReg);
743 report(
"ir-block-address-taken is associated with basic block not used by "
752 LandingPadSuccs.
insert(succ);
753 if (!FunctionBlocks.count(succ))
754 report(
"MBB has successor that isn't part of the function.",
MBB);
755 if (!MBBInfoMap[succ].Preds.count(
MBB)) {
756 report(
"Inconsistent CFG",
MBB);
757 OS <<
"MBB is not in the predecessor list of the successor "
764 if (!FunctionBlocks.count(Pred))
765 report(
"MBB has predecessor that isn't part of the function.",
MBB);
766 if (!MBBInfoMap[Pred].Succs.count(
MBB)) {
767 report(
"Inconsistent CFG",
MBB);
768 OS <<
"MBB is not in the successor list of the predecessor "
776 if (LandingPadSuccs.
size() > 1 &&
781 report(
"MBB has more than one landing pad successor",
MBB);
794 report(
"MBB exits via unconditional fall-through but ends with a "
795 "barrier instruction!",
MBB);
798 report(
"MBB exits via unconditional fall-through but has a condition!",
801 }
else if (
TBB && !FBB &&
Cond.empty()) {
804 report(
"MBB exits via unconditional branch but doesn't contain "
805 "any instructions!",
MBB);
807 report(
"MBB exits via unconditional branch but doesn't end with a "
808 "barrier instruction!",
MBB);
810 report(
"MBB exits via unconditional branch but the branch isn't a "
811 "terminator instruction!",
MBB);
813 }
else if (
TBB && !FBB && !
Cond.empty()) {
816 report(
"MBB exits via conditional branch/fall-through but doesn't "
817 "contain any instructions!",
MBB);
819 report(
"MBB exits via conditional branch/fall-through but ends with a "
820 "barrier instruction!",
MBB);
822 report(
"MBB exits via conditional branch/fall-through but the branch "
823 "isn't a terminator instruction!",
MBB);
825 }
else if (
TBB && FBB) {
829 report(
"MBB exits via conditional branch/branch but doesn't "
830 "contain any instructions!",
MBB);
832 report(
"MBB exits via conditional branch/branch but doesn't end with a "
833 "barrier instruction!",
MBB);
835 report(
"MBB exits via conditional branch/branch but the branch "
836 "isn't a terminator instruction!",
MBB);
839 report(
"MBB exits via conditional branch/branch but there's no "
843 report(
"analyzeBranch returned invalid data!",
MBB);
849 report(
"MBB exits via jump or conditional branch, but its target isn't a "
853 report(
"MBB exits via conditional branch, but its target isn't a CFG "
860 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
865 if (!
Cond.empty() && !FBB) {
868 report(
"MBB conditionally falls through out of function!",
MBB);
870 report(
"MBB exits via conditional branch/fall-through but the CFG "
871 "successors don't match the actual successors!",
878 if (SuccMBB ==
TBB || SuccMBB == FBB)
886 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
888 report(
"MBB has unexpected successors which are not branch targets, "
889 "fallthrough, EHPads, or inlineasm_br targets.",
895 if (
MRI->tracksLiveness()) {
898 report(
"MBB live-in list contains non-physical register",
MBB);
917 lastIndex = Indexes->getMBBStartIdx(
MBB);
922void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
923 if (Indexes && Indexes->hasIndex(*
MI)) {
925 if (!(idx > lastIndex)) {
926 report(
"Instruction index out of order",
MI);
927 OS <<
"Last instruction was at " << lastIndex <<
'\n';
933 if (
MI->isTerminator()) {
934 if (!FirstTerminator)
935 FirstTerminator =
MI;
936 }
else if (FirstTerminator) {
939 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
940 report(
"Non-terminator instruction after the first terminator",
MI);
941 OS <<
"First terminator was:\t" << *FirstTerminator;
950 if (
MI->getNumOperands() < 2) {
951 report(
"Too few operands on inline asm",
MI);
954 if (!
MI->getOperand(0).isSymbol())
955 report(
"Asm string must be an external symbol",
MI);
956 if (!
MI->getOperand(1).isImm())
957 report(
"Asm flags must be an immediate",
MI);
961 if (!isUInt<6>(
MI->getOperand(1).getImm()))
962 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
968 for (
unsigned e =
MI->getNumOperands(); OpNo <
e; OpNo += NumOps) {
974 NumOps = 1 +
F.getNumOperandRegisters();
977 if (OpNo >
MI->getNumOperands())
978 report(
"Missing operands in last group",
MI);
981 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
985 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
988 report(
"Expected implicit register after groups", &MO, OpNo);
991 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
1004 if (!IndirectTargetMBB) {
1005 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1010 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1014 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1020bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1025 const auto Reg = Op.getReg();
1026 if (Reg.isPhysical())
1028 return !MRI.getType(Reg).isScalar();
1031 report(
"All register operands must have scalar types", &
MI);
1038bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1041 report(
"operand types must be all-vector or all-scalar",
MI);
1051 report(
"operand types must preserve number of vector elements",
MI);
1058bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1059 auto Opcode =
MI->getOpcode();
1060 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1061 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1062 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1063 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1065 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1066 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1067 if (NoSideEffects && DeclHasSideEffects) {
1069 " used with intrinsic that accesses memory"),
1073 if (!NoSideEffects && !DeclHasSideEffects) {
1074 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1082bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1083 auto Opcode =
MI->getOpcode();
1084 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1085 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1086 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1087 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1089 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1090 bool DeclIsConvergent =
Attrs.hasFnAttr(Attribute::Convergent);
1091 if (NotConvergent && DeclIsConvergent) {
1092 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1096 if (!NotConvergent && !DeclIsConvergent) {
1098 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1107void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1108 if (isFunctionSelected)
1109 report(
"Unexpected generic instruction in a Selected function",
MI);
1112 unsigned NumOps =
MI->getNumOperands();
1115 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1116 bool HasMBB =
false;
1125 report(
"Branch instruction is missing a basic block operand or "
1126 "isIndirectBranch property",
1135 if (!MCID.
operands()[
I].isGenericType())
1139 size_t TypeIdx = MCID.
operands()[
I].getGenericTypeIndex();
1140 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1144 report(
"generic instruction must use register operands",
MI);
1154 if (!Types[TypeIdx].
isValid())
1155 Types[TypeIdx] = OpTy;
1156 else if (Types[TypeIdx] != OpTy)
1157 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1160 report(
"Generic instruction is missing a virtual register type", MO,
I);
1165 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1168 report(
"Generic instruction cannot have physical register", MO,
I);
1180 unsigned Opc =
MI->getOpcode();
1182 case TargetOpcode::G_ASSERT_SEXT:
1183 case TargetOpcode::G_ASSERT_ZEXT: {
1184 std::string OpcName =
1185 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1186 if (!
MI->getOperand(2).isImm()) {
1187 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1193 LLT SrcTy =
MRI->getType(Src);
1194 int64_t
Imm =
MI->getOperand(2).getImm();
1196 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1201 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1209 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1210 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1216 if (DstRC && DstRC !=
MRI->getRegClassOrNull(Src)) {
1218 Twine(OpcName,
" source and destination register classes must match"),
1226 case TargetOpcode::G_CONSTANT:
1227 case TargetOpcode::G_FCONSTANT: {
1228 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1230 report(
"Instruction cannot use a vector result type",
MI);
1232 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1233 if (!
MI->getOperand(1).isCImm()) {
1234 report(
"G_CONSTANT operand must be cimm",
MI);
1240 report(
"inconsistent constant size",
MI);
1242 if (!
MI->getOperand(1).isFPImm()) {
1243 report(
"G_FCONSTANT operand must be fpimm",
MI);
1250 report(
"inconsistent constant size",
MI);
1256 case TargetOpcode::G_LOAD:
1257 case TargetOpcode::G_STORE:
1258 case TargetOpcode::G_ZEXTLOAD:
1259 case TargetOpcode::G_SEXTLOAD: {
1260 LLT ValTy =
MRI->getType(
MI->getOperand(0).getReg());
1261 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1263 report(
"Generic memory instruction must access a pointer",
MI);
1267 if (!
MI->hasOneMemOperand()) {
1268 report(
"Generic instruction accessing memory must have one mem operand",
1272 if (
MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
1273 MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
1276 report(
"Generic extload must have a narrower memory type",
MI);
1277 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1280 report(
"load memory size cannot exceed result size",
MI);
1281 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1284 report(
"store memory size cannot exceed value size",
MI);
1288 if (Opc == TargetOpcode::G_STORE) {
1291 report(
"atomic store cannot use acquire ordering",
MI);
1296 report(
"atomic load cannot use release ordering",
MI);
1302 case TargetOpcode::G_PHI: {
1303 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1308 LLT Ty = MRI->getType(MO.getReg());
1309 if (!Ty.isValid() || (Ty != DstTy))
1313 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1318 case TargetOpcode::G_BITCAST: {
1319 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1320 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1325 report(
"bitcast cannot convert between pointers and other types",
MI);
1328 report(
"bitcast sizes must match",
MI);
1331 report(
"bitcast must change the type",
MI);
1335 case TargetOpcode::G_INTTOPTR:
1336 case TargetOpcode::G_PTRTOINT:
1337 case TargetOpcode::G_ADDRSPACE_CAST: {
1338 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1339 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1343 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1348 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1350 report(
"inttoptr result type must be a pointer",
MI);
1352 report(
"inttoptr source type must not be a pointer",
MI);
1353 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1355 report(
"ptrtoint source type must be a pointer",
MI);
1357 report(
"ptrtoint result type must not be a pointer",
MI);
1359 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1361 report(
"addrspacecast types must be pointers",
MI);
1364 report(
"addrspacecast must convert different address spaces",
MI);
1370 case TargetOpcode::G_PTR_ADD: {
1371 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1372 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1373 LLT OffsetTy =
MRI->getType(
MI->getOperand(2).getReg());
1378 report(
"gep first operand must be a pointer",
MI);
1381 report(
"gep offset operand must not be a pointer",
MI);
1386 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1388 report(
"gep offset operand must match index size for address space",
1396 case TargetOpcode::G_PTRMASK: {
1397 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1398 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1399 LLT MaskTy =
MRI->getType(
MI->getOperand(2).getReg());
1404 report(
"ptrmask result type must be a pointer",
MI);
1407 report(
"ptrmask mask type must be an integer",
MI);
1409 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1412 case TargetOpcode::G_SEXT:
1413 case TargetOpcode::G_ZEXT:
1414 case TargetOpcode::G_ANYEXT:
1415 case TargetOpcode::G_TRUNC:
1416 case TargetOpcode::G_FPEXT:
1417 case TargetOpcode::G_FPTRUNC: {
1424 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1425 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1430 report(
"Generic extend/truncate can not operate on pointers",
MI);
1432 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1436 switch (
MI->getOpcode()) {
1438 if (DstSize <= SrcSize)
1439 report(
"Generic extend has destination type no larger than source",
MI);
1441 case TargetOpcode::G_TRUNC:
1442 case TargetOpcode::G_FPTRUNC:
1443 if (DstSize >= SrcSize)
1444 report(
"Generic truncate has destination type no smaller than source",
1450 case TargetOpcode::G_SELECT: {
1451 LLT SelTy =
MRI->getType(
MI->getOperand(0).getReg());
1452 LLT CondTy =
MRI->getType(
MI->getOperand(1).getReg());
1458 verifyVectorElementMatch(SelTy, CondTy,
MI);
1461 case TargetOpcode::G_MERGE_VALUES: {
1466 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1467 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1469 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1471 const unsigned NumOps =
MI->getNumOperands();
1473 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1475 for (
unsigned I = 2;
I != NumOps; ++
I) {
1476 if (
MRI->getType(
MI->getOperand(
I).getReg()) != SrcTy)
1477 report(
"G_MERGE_VALUES source types do not match",
MI);
1482 case TargetOpcode::G_UNMERGE_VALUES: {
1483 unsigned NumDsts =
MI->getNumOperands() - 1;
1484 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1485 for (
unsigned i = 1; i < NumDsts; ++i) {
1486 if (
MRI->getType(
MI->getOperand(i).getReg()) != DstTy) {
1487 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1492 LLT SrcTy =
MRI->getType(
MI->getOperand(NumDsts).getReg());
1500 report(
"G_UNMERGE_VALUES source operand does not match vector "
1501 "destination operands",
1508 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1509 "destination operands",
1514 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1515 "destination operands",
1521 case TargetOpcode::G_BUILD_VECTOR: {
1524 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1525 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1527 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1532 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1535 report(
"G_BUILD_VECTOR must have an operand for each elemement",
MI);
1538 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1539 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1543 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1546 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1547 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1549 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1552 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1553 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1556 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1561 case TargetOpcode::G_CONCAT_VECTORS: {
1564 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1565 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1567 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1570 if (
MI->getNumOperands() < 3)
1571 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1574 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1575 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1578 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1581 case TargetOpcode::G_ICMP:
1582 case TargetOpcode::G_FCMP: {
1583 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1584 LLT SrcTy =
MRI->getType(
MI->getOperand(2).getReg());
1589 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1593 case TargetOpcode::G_SCMP:
1594 case TargetOpcode::G_UCMP: {
1595 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1596 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1599 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1604 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1609 report(
"Result type must be at least 2 bits wide",
MI);
1616 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1622 case TargetOpcode::G_EXTRACT: {
1624 if (!
SrcOp.isReg()) {
1625 report(
"extract source must be a register",
MI);
1630 if (!OffsetOp.
isImm()) {
1631 report(
"extract offset must be a constant",
MI);
1635 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1637 if (SrcSize == DstSize)
1638 report(
"extract source must be larger than result",
MI);
1640 if (DstSize + OffsetOp.
getImm() > SrcSize)
1641 report(
"extract reads past end of register",
MI);
1644 case TargetOpcode::G_INSERT: {
1646 if (!
SrcOp.isReg()) {
1647 report(
"insert source must be a register",
MI);
1652 if (!OffsetOp.
isImm()) {
1653 report(
"insert offset must be a constant",
MI);
1657 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1660 if (DstSize <= SrcSize)
1661 report(
"inserted size must be smaller than total register",
MI);
1663 if (SrcSize + OffsetOp.
getImm() > DstSize)
1664 report(
"insert writes past end of register",
MI);
1668 case TargetOpcode::G_JUMP_TABLE: {
1669 if (!
MI->getOperand(1).isJTI())
1670 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1671 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1673 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1676 case TargetOpcode::G_BRJT: {
1677 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
1678 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1680 if (!
MI->getOperand(1).isJTI())
1681 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1683 const auto &IdxOp =
MI->getOperand(2);
1684 if (!IdxOp.isReg() ||
MRI->getType(IdxOp.getReg()).isPointer())
1685 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1688 case TargetOpcode::G_INTRINSIC:
1689 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1690 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1691 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1696 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1700 if (!verifyGIntrinsicSideEffects(
MI))
1702 if (!verifyGIntrinsicConvergence(
MI))
1707 case TargetOpcode::G_SEXT_INREG: {
1708 if (!
MI->getOperand(2).isImm()) {
1709 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1713 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1714 int64_t
Imm =
MI->getOperand(2).getImm();
1716 report(
"G_SEXT_INREG size must be >= 1",
MI);
1718 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1721 case TargetOpcode::G_BSWAP: {
1722 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1724 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1727 case TargetOpcode::G_VSCALE: {
1728 if (!
MI->getOperand(1).isCImm()) {
1729 report(
"G_VSCALE operand must be cimm",
MI);
1732 if (
MI->getOperand(1).getCImm()->isZero()) {
1733 report(
"G_VSCALE immediate cannot be zero",
MI);
1738 case TargetOpcode::G_STEP_VECTOR: {
1739 if (!
MI->getOperand(1).isCImm()) {
1740 report(
"operand must be cimm",
MI);
1744 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1745 report(
"step must be > 0",
MI);
1749 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1751 report(
"Destination type must be a scalable vector",
MI);
1757 report(
"Destination element type must be scalar",
MI);
1761 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1763 report(
"step bitwidth differs from result type element bitwidth",
MI);
1768 case TargetOpcode::G_INSERT_SUBVECTOR: {
1770 if (!Src0Op.
isReg()) {
1771 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1776 if (!Src1Op.
isReg()) {
1777 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1782 if (!IndexOp.
isImm()) {
1783 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1787 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1791 report(
"Destination type must be a vector",
MI);
1796 report(
"Second source must be a vector",
MI);
1801 report(
"Element type of vectors must be the same",
MI);
1806 report(
"Vector types must both be fixed or both be scalable",
MI);
1812 report(
"Second source must be smaller than destination vector",
MI);
1818 if (IndexOp.
getImm() % Src1MinLen != 0) {
1819 report(
"Index must be a multiple of the second source vector's "
1820 "minimum vector length",
1826 if (
Idx >= DstMinLen ||
Idx + Src1MinLen > DstMinLen) {
1827 report(
"Subvector type and index must not cause insert to overrun the "
1828 "vector being inserted into",
1835 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1837 if (!
SrcOp.isReg()) {
1838 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1843 if (!IndexOp.
isImm()) {
1844 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1848 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1852 report(
"Destination type must be a vector",
MI);
1857 report(
"Source must be a vector",
MI);
1862 report(
"Element type of vectors must be the same",
MI);
1867 report(
"Vector types must both be fixed or both be scalable",
MI);
1873 report(
"Destination vector must be smaller than source vector",
MI);
1879 if (
Idx % DstMinLen != 0) {
1880 report(
"Index must be a multiple of the destination vector's minimum "
1887 if (
Idx >= SrcMinLen ||
Idx + DstMinLen > SrcMinLen) {
1888 report(
"Destination type and index must not cause extract to overrun the "
1896 case TargetOpcode::G_SHUFFLE_VECTOR: {
1899 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1903 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1904 LLT Src0Ty =
MRI->getType(
MI->getOperand(1).getReg());
1905 LLT Src1Ty =
MRI->getType(
MI->getOperand(2).getReg());
1907 if (Src0Ty != Src1Ty)
1908 report(
"Source operands must be the same type",
MI);
1911 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1920 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1921 report(
"Wrong result type for shufflemask",
MI);
1923 for (
int Idx : MaskIdxes) {
1927 if (
Idx >= 2 * SrcNumElts)
1928 report(
"Out of bounds shuffle index",
MI);
1934 case TargetOpcode::G_SPLAT_VECTOR: {
1935 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1936 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1939 report(
"Destination type must be a scalable vector",
MI);
1944 report(
"Source type must be a scalar or pointer",
MI);
1950 report(
"Element type of the destination must be the same size or smaller "
1951 "than the source type",
1958 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1959 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1960 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1961 LLT IdxTy =
MRI->getType(
MI->getOperand(2).getReg());
1964 report(
"Destination type must be a scalar or pointer",
MI);
1969 report(
"First source must be a vector",
MI);
1973 auto TLI = MF->getSubtarget().getTargetLowering();
1975 TLI->getVectorIdxTy(MF->getDataLayout()).getFixedSizeInBits()) {
1976 report(
"Index type must match VectorIdxTy",
MI);
1982 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1983 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1984 LLT VecTy =
MRI->getType(
MI->getOperand(1).getReg());
1985 LLT ScaTy =
MRI->getType(
MI->getOperand(2).getReg());
1986 LLT IdxTy =
MRI->getType(
MI->getOperand(3).getReg());
1989 report(
"Destination type must be a vector",
MI);
1993 if (VecTy != DstTy) {
1994 report(
"Destination type and vector type must match",
MI);
1999 report(
"Inserted element must be a scalar or pointer",
MI);
2003 auto TLI = MF->getSubtarget().getTargetLowering();
2005 TLI->getVectorIdxTy(MF->getDataLayout()).getFixedSizeInBits()) {
2006 report(
"Index type must match VectorIdxTy",
MI);
2012 case TargetOpcode::G_DYN_STACKALLOC: {
2018 report(
"dst operand 0 must be a pointer type",
MI);
2022 if (!AllocOp.
isReg() || !
MRI->getType(AllocOp.
getReg()).isScalar()) {
2023 report(
"src operand 1 must be a scalar reg type",
MI);
2027 if (!AlignOp.
isImm()) {
2028 report(
"src operand 2 must be an immediate type",
MI);
2033 case TargetOpcode::G_MEMCPY_INLINE:
2034 case TargetOpcode::G_MEMCPY:
2035 case TargetOpcode::G_MEMMOVE: {
2037 if (MMOs.
size() != 2) {
2038 report(
"memcpy/memmove must have 2 memory operands",
MI);
2044 report(
"wrong memory operand types",
MI);
2049 report(
"inconsistent memory operand sizes",
MI);
2051 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2052 LLT SrcPtrTy =
MRI->getType(
MI->getOperand(1).getReg());
2055 report(
"memory instruction operand must be a pointer",
MI);
2060 report(
"inconsistent store address space",
MI);
2062 report(
"inconsistent load address space",
MI);
2064 if (Opc != TargetOpcode::G_MEMCPY_INLINE)
2065 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2066 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2070 case TargetOpcode::G_BZERO:
2071 case TargetOpcode::G_MEMSET: {
2073 std::string
Name = Opc == TargetOpcode::G_MEMSET ?
"memset" :
"bzero";
2074 if (MMOs.
size() != 1) {
2075 report(
Twine(
Name,
" must have 1 memory operand"),
MI);
2080 report(
Twine(
Name,
" memory operand must be a store"),
MI);
2084 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2086 report(
Twine(
Name,
" operand must be a pointer"),
MI);
2091 report(
"inconsistent " +
Twine(
Name,
" address space"),
MI);
2093 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2094 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2095 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2099 case TargetOpcode::G_UBSANTRAP: {
2101 if (!
MI->getOperand(0).isImm()) {
2102 report(
"Crash kind must be an immediate", &KindOp, 0);
2105 int64_t
Kind =
MI->getOperand(0).getImm();
2106 if (!isInt<8>(Kind))
2107 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2110 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2111 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2112 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2113 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2114 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2116 report(
"Vector reduction requires a scalar destination type",
MI);
2118 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2120 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2123 case TargetOpcode::G_VECREDUCE_FADD:
2124 case TargetOpcode::G_VECREDUCE_FMUL:
2125 case TargetOpcode::G_VECREDUCE_FMAX:
2126 case TargetOpcode::G_VECREDUCE_FMIN:
2127 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2128 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2129 case TargetOpcode::G_VECREDUCE_ADD:
2130 case TargetOpcode::G_VECREDUCE_MUL:
2131 case TargetOpcode::G_VECREDUCE_AND:
2132 case TargetOpcode::G_VECREDUCE_OR:
2133 case TargetOpcode::G_VECREDUCE_XOR:
2134 case TargetOpcode::G_VECREDUCE_SMAX:
2135 case TargetOpcode::G_VECREDUCE_SMIN:
2136 case TargetOpcode::G_VECREDUCE_UMAX:
2137 case TargetOpcode::G_VECREDUCE_UMIN: {
2138 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2140 report(
"Vector reduction requires a scalar destination type",
MI);
2144 case TargetOpcode::G_SBFX:
2145 case TargetOpcode::G_UBFX: {
2146 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2148 report(
"Bitfield extraction is not supported on vectors",
MI);
2153 case TargetOpcode::G_SHL:
2154 case TargetOpcode::G_LSHR:
2155 case TargetOpcode::G_ASHR:
2156 case TargetOpcode::G_ROTR:
2157 case TargetOpcode::G_ROTL: {
2158 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2159 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2161 report(
"Shifts and rotates require operands to be either all scalars or "
2168 case TargetOpcode::G_LLROUND:
2169 case TargetOpcode::G_LROUND: {
2170 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2171 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2176 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2178 verifyAllRegOpsScalar(*
MI, *
MRI);
2181 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2186 case TargetOpcode::G_IS_FPCLASS: {
2187 LLT DestTy =
MRI->getType(
MI->getOperand(0).getReg());
2190 report(
"Destination must be a scalar or vector of scalars",
MI);
2193 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2196 report(
"Source must be a scalar or vector of scalars",
MI);
2199 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2202 if (!TestMO.
isImm()) {
2203 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2208 report(
"Incorrect floating-point class set (operand 2)",
MI);
2213 case TargetOpcode::G_PREFETCH: {
2215 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer()) {
2216 report(
"addr operand must be a pointer", &AddrOp, 0);
2221 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2226 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2231 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2236 case TargetOpcode::G_ASSERT_ALIGN: {
2237 if (
MI->getOperand(2).getImm() < 1)
2238 report(
"alignment immediate must be >= 1",
MI);
2241 case TargetOpcode::G_CONSTANT_POOL: {
2242 if (!
MI->getOperand(1).isCPI())
2243 report(
"Src operand 1 must be a constant pool index",
MI);
2244 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
2245 report(
"Dst operand 0 must be a pointer",
MI);
2248 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2250 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer())
2251 report(
"addr operand must be a pointer", &AddrOp, 1);
2259void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2262 report(
"Too few operands",
MI);
2264 <<
MI->getNumOperands() <<
" given.\n";
2268 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2271 if (MF->getProperties().hasProperty(
2273 report(
"Found PHI instruction with NoPHIs property set",
MI);
2276 report(
"Found PHI instruction after non-PHI",
MI);
2277 }
else if (FirstNonPHI ==
nullptr)
2281 if (
MI->isInlineAsm())
2282 verifyInlineAsm(
MI);
2285 if (
TII->isUnspillableTerminator(
MI)) {
2286 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2287 report(
"Unspillable Terminator does not define a reg",
MI);
2289 if (
Def.isVirtual() &&
2290 !MF->getProperties().hasProperty(
2292 std::distance(
MRI->use_nodbg_begin(Def),
MRI->use_nodbg_end()) > 1)
2293 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2299 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2300 if (!
MI->getDebugLoc())
2301 report(
"Missing DebugLoc for debug instruction",
MI);
2305 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2306 report(
"Metadata instruction should not have a value tracking number",
MI);
2310 if (
Op->isLoad() && !
MI->mayLoad())
2311 report(
"Missing mayLoad flag",
MI);
2312 if (
Op->isStore() && !
MI->mayStore())
2313 report(
"Missing mayStore flag",
MI);
2319 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2320 if (
MI->isDebugOrPseudoInstr()) {
2322 report(
"Debug instruction has a slot index",
MI);
2323 }
else if (
MI->isInsideBundle()) {
2325 report(
"Instruction inside bundle has a slot index",
MI);
2328 report(
"Missing slot index",
MI);
2334 verifyPreISelGenericInstruction(
MI);
2343 switch (
MI->getOpcode()) {
2344 case TargetOpcode::COPY: {
2350 LLT DstTy =
MRI->getType(DstReg);
2351 LLT SrcTy =
MRI->getType(SrcReg);
2354 if (SrcTy != DstTy) {
2355 report(
"Copy Instruction is illegal with mismatching types",
MI);
2356 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2371 TRI->getMinimalPhysRegClassLLT(SrcReg, DstTy);
2373 SrcSize =
TRI->getRegSizeInBits(*SrcRC);
2378 TRI->getMinimalPhysRegClassLLT(DstReg, SrcTy);
2380 DstSize =
TRI->getRegSizeInBits(*DstRC);
2398 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2399 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2400 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2405 case TargetOpcode::STATEPOINT: {
2407 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2408 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2409 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2410 report(
"meta operands to STATEPOINT not constant!",
MI);
2414 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2415 if (
Offset >=
MI->getNumOperands()) {
2416 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2419 if (!
MI->getOperand(
Offset - 1).isImm() ||
2420 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2422 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2424 VerifyStackMapConstant(SO.getCCIdx());
2425 VerifyStackMapConstant(SO.getFlagsIdx());
2426 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2427 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2428 VerifyStackMapConstant(SO.getNumAllocaIdx());
2429 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2433 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2434 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2435 for (
unsigned Idx = 0;
Idx <
MI->getNumDefs();
Idx++) {
2437 if (!
MI->isRegTiedToUseOperand(
Idx, &UseOpIdx)) {
2438 report(
"STATEPOINT defs expected to be tied",
MI);
2441 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2442 report(
"STATEPOINT def tied to non-gc operand",
MI);
2449 case TargetOpcode::INSERT_SUBREG: {
2450 unsigned InsertedSize;
2451 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2452 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2454 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *
MRI);
2455 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2456 if (SubRegSize < InsertedSize) {
2457 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2458 "size than the subreg it was inserted into",
MI);
2462 case TargetOpcode::REG_SEQUENCE: {
2463 unsigned NumOps =
MI->getNumOperands();
2464 if (!(NumOps & 1)) {
2465 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2469 for (
unsigned I = 1;
I != NumOps;
I += 2) {
2474 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2476 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2477 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2478 report(
"Invalid subregister index operand for REG_SEQUENCE",
2483 Register DstReg =
MI->getOperand(0).getReg();
2485 report(
"REG_SEQUENCE does not support physical register results",
MI);
2487 if (
MI->getOperand(0).getSubReg())
2488 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2496MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2500 if (MCID.
getOpcode() == TargetOpcode::PATCHPOINT)
2501 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2504 if (MONum < NumDefs) {
2507 report(
"Explicit definition must be a register", MO, MONum);
2509 report(
"Explicit definition marked as use", MO, MONum);
2511 report(
"Explicit definition marked as implicit", MO, MONum);
2520 report(
"Explicit operand marked as def", MO, MONum);
2522 report(
"Explicit operand marked as implicit", MO, MONum);
2528 report(
"Expected a register operand.", MO, MONum);
2532 !
TII->isPCRelRegisterOperandLegal(*MO)))
2533 report(
"Expected a non-register operand.", MO, MONum);
2540 report(
"Tied use must be a register", MO, MONum);
2542 report(
"Operand should be tied", MO, MONum);
2543 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2544 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2547 if (!MOTied.
isReg())
2548 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2551 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2554 report(
"Explicit operand should not be tied", MO, MONum);
2555 }
else if (!
MI->isVariadic()) {
2558 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2565 if (
MI->isDebugInstr() && MO->
isUse()) {
2567 report(
"Register operand must be marked debug", MO, MONum);
2569 report(
"Register operand must not be marked debug", MO, MONum);
2575 if (
MRI->tracksLiveness() && !
MI->isDebugInstr())
2576 checkLiveness(MO, MONum);
2580 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2584 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2586 if (!OtherMO.
isReg())
2587 report(
"Must be tied to a register", MO, MONum);
2589 report(
"Missing tie flags on tied operand", MO, MONum);
2590 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2591 report(
"Inconsistent tie links", MO, MONum);
2595 report(
"Explicit def tied to explicit use without tie constraint",
2599 report(
"Explicit def should be tied to implicit use", MO, MONum);
2612 if (MF->getProperties().hasProperty(
2614 MO->
isUse() &&
MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2615 Reg !=
MI->getOperand(DefIdx).getReg())
2616 report(
"Two-address instruction operands must be identical", MO, MONum);
2621 if (
Reg.isPhysical()) {
2623 report(
"Illegal subregister index for physical register", MO, MONum);
2628 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2629 if (!DRC->contains(Reg)) {
2630 report(
"Illegal physical register for instruction", MO, MONum);
2632 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2637 if (
MRI->isReserved(Reg)) {
2638 report(
"isRenamable set on reserved register", MO, MONum);
2655 report(
"Generic virtual register use cannot be undef", MO, MONum);
2662 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2663 !
MI->isDebugValue() || !
MRI->def_empty(Reg)) {
2665 if (isFunctionSelected) {
2666 report(
"Generic virtual register invalid in a Selected function",
2672 LLT Ty =
MRI->getType(Reg);
2674 report(
"Generic virtual register must have a valid type", MO,
2683 if (!RegBank && isFunctionRegBankSelected) {
2684 report(
"Generic virtual register must have a bank in a "
2685 "RegBankSelected function",
2693 report(
"Register bank is too small for virtual register", MO,
2695 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2703 report(
"Generic virtual register does not allow subregister index", MO,
2713 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2714 report(
"Virtual register does not match instruction constraint", MO,
2716 OS <<
"Expect register class "
2717 <<
TRI->getRegClassName(
TII->getRegClass(MCID, MONum,
TRI, *MF))
2718 <<
" but got nothing\n";
2726 TRI->getSubClassWithSubReg(RC, SubIdx);
2728 report(
"Invalid subregister index for virtual register", MO, MONum);
2729 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2730 <<
" does not support subreg index " << SubIdx <<
'\n';
2734 report(
"Invalid register class for subregister index", MO, MONum);
2735 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2736 <<
" does not fully support subreg index " << SubIdx <<
'\n';
2742 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2745 TRI->getLargestLegalSuperClass(RC, *MF);
2747 report(
"No largest legal super class exists.", MO, MONum);
2750 DRC =
TRI->getMatchingSuperRegClass(SuperRC, DRC, SubIdx);
2752 report(
"No matching super-reg register class.", MO, MONum);
2757 report(
"Illegal virtual register for instruction", MO, MONum);
2758 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2759 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2774 report(
"PHI operand is not in the CFG", MO, MONum);
2778 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2779 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2790 for (
auto *MMO :
MI->memoperands()) {
2792 if (PSV ==
nullptr)
continue;
2794 dyn_cast<FixedStackPseudoSourceValue>(PSV);
2795 if (
Value ==
nullptr)
continue;
2796 if (
Value->getFrameIndex() != FI)
continue;
2805 report(
"Missing fixed stack memoperand.",
MI);
2808 report(
"Instruction loads from dead spill slot", MO, MONum);
2809 OS <<
"Live stack: " << LI <<
'\n';
2812 report(
"Instruction stores to dead spill slot", MO, MONum);
2813 OS <<
"Live stack: " << LI <<
'\n';
2819 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2820 report(
"CFI instruction has invalid index", MO, MONum);
2828void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2836 report(
"invalid live range", MO, MONum);
2837 report_context_liverange(LR);
2838 report_context_vreg_regunit(VRegOrUnit);
2839 report_context(UseIdx);
2848 report(
"No live segment at use", MO, MONum);
2849 report_context_liverange(LR);
2850 report_context_vreg_regunit(VRegOrUnit);
2851 report_context(UseIdx);
2854 report(
"Live range continues after kill flag", MO, MONum);
2855 report_context_liverange(LR);
2856 report_context_vreg_regunit(VRegOrUnit);
2858 report_context_lanemask(LaneMask);
2859 report_context(UseIdx);
2863void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2870 report(
"invalid live range", MO, MONum);
2871 report_context_liverange(LR);
2872 report_context_vreg_regunit(VRegOrUnit);
2874 report_context_lanemask(LaneMask);
2875 report_context(DefIdx);
2887 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
2889 (VNI->def != DefIdx &&
2890 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
2891 report(
"Inconsistent valno->def", MO, MONum);
2892 report_context_liverange(LR);
2893 report_context_vreg_regunit(VRegOrUnit);
2895 report_context_lanemask(LaneMask);
2896 report_context(*VNI);
2897 report_context(DefIdx);
2900 report(
"No live segment at def", MO, MONum);
2901 report_context_liverange(LR);
2902 report_context_vreg_regunit(VRegOrUnit);
2904 report_context_lanemask(LaneMask);
2905 report_context(DefIdx);
2917 if (SubRangeCheck || MO->
getSubReg() == 0) {
2918 report(
"Live range continues after dead def flag", MO, MONum);
2919 report_context_liverange(LR);
2920 report_context_vreg_regunit(VRegOrUnit);
2922 report_context_lanemask(LaneMask);
2928void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
2931 const unsigned SubRegIdx = MO->
getSubReg();
2934 if (LiveInts &&
Reg.isVirtual()) {
2935 if (LiveInts->hasInterval(Reg)) {
2936 LI = &LiveInts->getInterval(Reg);
2939 report(
"Live interval for subreg operand has no subranges", MO, MONum);
2941 report(
"Virtual register has no live interval", MO, MONum);
2948 addRegWithSubRegs(regsKilled, Reg);
2953 if (LiveVars &&
Reg.isVirtual() && MO->
isKill() &&
2954 !
MI->isBundledWithPred()) {
2957 report(
"Kill missing from LiveVariables", MO, MONum);
2961 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2965 UseIdx = LiveInts->getMBBEndIdx(
2966 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
2968 UseIdx = LiveInts->getInstructionIndex(*
MI);
2971 if (
Reg.isPhysical() && !isReserved(Reg)) {
2973 if (
MRI->isReservedRegUnit(Unit))
2975 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
2976 checkLivenessAtUse(MO, MONum, UseIdx, *LR, Unit);
2980 if (
Reg.isVirtual()) {
2982 checkLivenessAtUse(MO, MONum, UseIdx, *LI, Reg);
2986 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
2987 :
MRI->getMaxLaneMaskForVReg(Reg);
2990 if ((MOMask & SR.LaneMask).none())
2992 checkLivenessAtUse(MO, MONum, UseIdx, SR, Reg, SR.LaneMask);
2995 LiveInMask |= SR.LaneMask;
2998 if ((LiveInMask & MOMask).
none()) {
2999 report(
"No live subrange at use", MO, MONum);
3000 report_context(*LI);
3001 report_context(UseIdx);
3004 if (
MI->isPHI() && LiveInMask != MOMask) {
3005 report(
"Not all lanes of PHI source live at use", MO, MONum);
3006 report_context(*LI);
3007 report_context(UseIdx);
3014 if (!regsLive.count(Reg)) {
3015 if (
Reg.isPhysical()) {
3017 bool Bad = !isReserved(Reg);
3022 if (regsLive.count(
SubReg)) {
3034 if (!MOP.isReg() || !MOP.isImplicit())
3037 if (!MOP.getReg().isPhysical())
3040 if (MOP.getReg() != Reg &&
3042 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3049 report(
"Using an undefined physical register", MO, MONum);
3050 }
else if (
MRI->def_empty(Reg)) {
3051 report(
"Reading virtual register without a def", MO, MONum);
3053 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3057 if (MInfo.regsKilled.count(Reg))
3058 report(
"Using a killed virtual register", MO, MONum);
3059 else if (!
MI->isPHI())
3060 MInfo.vregsLiveIn.insert(std::make_pair(Reg,
MI));
3069 addRegWithSubRegs(regsDead, Reg);
3071 addRegWithSubRegs(regsDefined, Reg);
3074 if (
MRI->isSSA() &&
Reg.isVirtual() &&
3075 std::next(
MRI->def_begin(Reg)) !=
MRI->def_end())
3076 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3079 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3080 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3083 if (
Reg.isVirtual()) {
3084 checkLivenessAtDef(MO, MONum, DefIdx, *LI, Reg);
3088 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3089 :
MRI->getMaxLaneMaskForVReg(Reg);
3091 if ((SR.LaneMask & MOMask).none())
3093 checkLivenessAtDef(MO, MONum, DefIdx, SR, Reg,
true, SR.LaneMask);
3105void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3106 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3107 set_union(MInfo.regsKilled, regsKilled);
3108 set_subtract(regsLive, regsKilled); regsKilled.clear();
3110 while (!regMasks.empty()) {
3113 if (
Reg.isPhysical() &&
3115 regsDead.push_back(Reg);
3118 set_union(regsLive, regsDefined); regsDefined.clear();
3123 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3128 if (!(stop > lastIndex)) {
3129 report(
"Block ends before last instruction index",
MBB);
3130 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3146 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3148 filterAndAdd(FromRegSet, VRegsBuffer);
3153 template <
typename RegSetT>
3154 bool filterAndAdd(
const RegSetT &FromRegSet,
3156 unsigned SparseUniverse = Sparse.size();
3157 unsigned NewSparseUniverse = SparseUniverse;
3158 unsigned NewDenseSize =
Dense.size();
3159 size_t Begin = ToVRegs.
size();
3161 if (!
Reg.isVirtual())
3164 if (
Index < SparseUniverseMax) {
3165 if (
Index < SparseUniverse && Sparse.test(
Index))
3167 NewSparseUniverse = std::max(NewSparseUniverse,
Index + 1);
3182 Sparse.resize(NewSparseUniverse);
3183 Dense.reserve(NewDenseSize);
3184 for (
unsigned I = Begin;
I <
End; ++
I) {
3187 if (
Index < SparseUniverseMax)
3196 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3216class FilteringVRegSet {
3223 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3228 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3231 return Filter.filterAndAdd(RS, VRegs);
3236 size_t size()
const {
return VRegs.
size(); }
3243void MachineVerifier::calcRegsPassed() {
3250 FilteringVRegSet VRegs;
3251 BBInfo &
Info = MBBInfoMap[MB];
3254 VRegs.addToFilter(
Info.regsKilled);
3255 VRegs.addToFilter(
Info.regsLiveOut);
3257 const BBInfo &PredInfo = MBBInfoMap[Pred];
3258 if (!PredInfo.reachable)
3261 VRegs.add(PredInfo.regsLiveOut);
3262 VRegs.add(PredInfo.vregsPassed);
3264 Info.vregsPassed.reserve(VRegs.size());
3265 Info.vregsPassed.insert(VRegs.begin(), VRegs.end());
3272void MachineVerifier::calcRegsRequired() {
3275 for (
const auto &
MBB : *MF) {
3276 BBInfo &MInfo = MBBInfoMap[&
MBB];
3278 BBInfo &PInfo = MBBInfoMap[Pred];
3279 if (PInfo.addRequired(MInfo.vregsLiveIn))
3285 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3287 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3294 BBInfo &PInfo = MBBInfoMap[Pred];
3295 if (PInfo.addRequired(Reg))
3303 while (!todo.
empty()) {
3306 BBInfo &MInfo = MBBInfoMap[
MBB];
3310 BBInfo &SInfo = MBBInfoMap[Pred];
3311 if (SInfo.addRequired(MInfo.vregsRequired))
3320 BBInfo &MInfo = MBBInfoMap[&
MBB];
3330 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3335 report(
"Unexpected flag on PHI operand", &MODef, 0);
3338 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3340 for (
unsigned I = 1, E =
Phi.getNumOperands();
I != E;
I += 2) {
3343 report(
"Expected PHI operand to be a register", &MO0,
I);
3348 report(
"Unexpected flag on PHI operand", &MO0,
I);
3352 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3358 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3362 if (MInfo.reachable) {
3364 BBInfo &PrInfo = MBBInfoMap[&Pre];
3365 if (!MO0.
isUndef() && PrInfo.reachable &&
3366 !PrInfo.isLiveOut(MO0.
getReg()))
3367 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3372 if (MInfo.reachable) {
3374 if (!seen.
count(Pred)) {
3375 report(
"Missing PHI operand", &Phi);
3377 <<
" is a predecessor according to the CFG.\n";
3386 std::function<
void(
const Twine &Message)> FailureCB,
3391 for (
const auto &
MBB : MF) {
3403void MachineVerifier::visitMachineFunctionAfter() {
3404 auto FailureCB = [
this](
const Twine &Message) {
3405 report(Message.str().c_str(), MF);
3418 for (
const auto &
MBB : *MF) {
3419 BBInfo &MInfo = MBBInfoMap[&
MBB];
3420 for (
Register VReg : MInfo.vregsRequired)
3421 if (MInfo.regsKilled.count(VReg)) {
3422 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3424 <<
" is used after the block.\n";
3429 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3430 for (
Register VReg : MInfo.vregsRequired) {
3431 report(
"Virtual register defs don't dominate all uses.", MF);
3432 report_context_vreg(VReg);
3437 verifyLiveVariables();
3439 verifyLiveIntervals();
3448 if (
MRI->tracksLiveness())
3449 for (
const auto &
MBB : *MF)
3453 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3456 BBInfo &PInfo = MBBInfoMap[Pred];
3457 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3458 report(
"Live in register not found to be live out from predecessor.",
3460 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3466 for (
auto CSInfo : MF->getCallSitesInfo())
3467 if (!CSInfo.first->isCall())
3468 report(
"Call site info referencing instruction that is not call", MF);
3472 if (MF->getFunction().getSubprogram()) {
3474 for (
const auto &
MBB : *MF) {
3475 for (
const auto &
MI :
MBB) {
3476 if (
auto Num =
MI.peekDebugInstrNum()) {
3479 report(
"Instruction has a duplicated value tracking number", &
MI);
3486void MachineVerifier::verifyLiveVariables() {
3487 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3488 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3491 for (
const auto &
MBB : *MF) {
3492 BBInfo &MInfo = MBBInfoMap[&
MBB];
3495 if (MInfo.vregsRequired.count(Reg)) {
3497 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3499 <<
" must be live through the block.\n";
3503 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3505 <<
" is not needed live through the block.\n";
3512void MachineVerifier::verifyLiveIntervals() {
3513 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3514 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3518 if (
MRI->reg_nodbg_empty(Reg))
3521 if (!LiveInts->hasInterval(Reg)) {
3522 report(
"Missing live interval for virtual register", MF);
3528 assert(Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3529 verifyLiveInterval(LI);
3533 for (
unsigned i = 0, e =
TRI->getNumRegUnits(); i != e; ++i)
3534 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(i))
3535 verifyLiveRange(*LR, i);
3538void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3547 report(
"Value not live at VNInfo def and not marked unused", MF);
3548 report_context(LR, Reg, LaneMask);
3549 report_context(*VNI);
3553 if (DefVNI != VNI) {
3554 report(
"Live segment at def has different VNInfo", MF);
3555 report_context(LR, Reg, LaneMask);
3556 report_context(*VNI);
3562 report(
"Invalid VNInfo definition index", MF);
3563 report_context(LR, Reg, LaneMask);
3564 report_context(*VNI);
3569 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3570 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3571 report_context(LR, Reg, LaneMask);
3572 report_context(*VNI);
3580 report(
"No instruction at VNInfo def index",
MBB);
3581 report_context(LR, Reg, LaneMask);
3582 report_context(*VNI);
3587 bool hasDef =
false;
3588 bool isEarlyClobber =
false;
3590 if (!MOI->isReg() || !MOI->isDef())
3592 if (
Reg.isVirtual()) {
3593 if (MOI->getReg() != Reg)
3596 if (!MOI->getReg().isPhysical() || !
TRI->hasRegUnit(MOI->getReg(), Reg))
3599 if (LaneMask.
any() &&
3600 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3603 if (MOI->isEarlyClobber())
3604 isEarlyClobber =
true;
3608 report(
"Defining instruction does not modify register",
MI);
3609 report_context(LR, Reg, LaneMask);
3610 report_context(*VNI);
3615 if (isEarlyClobber) {
3617 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3618 report_context(LR, Reg, LaneMask);
3619 report_context(*VNI);
3622 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3623 report_context(LR, Reg, LaneMask);
3624 report_context(*VNI);
3629void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3635 assert(VNI &&
"Live segment has no valno");
3638 report(
"Foreign valno in live segment", MF);
3639 report_context(LR, Reg, LaneMask);
3641 report_context(*VNI);
3645 report(
"Live segment valno is marked unused", MF);
3646 report_context(LR, Reg, LaneMask);
3652 report(
"Bad start of live segment, no basic block", MF);
3653 report_context(LR, Reg, LaneMask);
3659 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3660 report_context(LR, Reg, LaneMask);
3667 report(
"Bad end of live segment, no basic block", MF);
3668 report_context(LR, Reg, LaneMask);
3674 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3684 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3685 report_context(LR, Reg, LaneMask);
3692 report(
"Live segment ends at B slot of an instruction", EndMBB);
3693 report_context(LR, Reg, LaneMask);
3701 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3702 report_context(LR, Reg, LaneMask);
3711 if (MF->getProperties().hasProperty(
3714 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3715 report(
"Live segment ending at early clobber slot must be "
3716 "redefined by an EC def in the same instruction",
3718 report_context(LR, Reg, LaneMask);
3725 if (
Reg.isVirtual()) {
3728 bool hasRead =
false;
3729 bool hasSubRegDef =
false;
3730 bool hasDeadDef =
false;
3732 if (!MOI->isReg() || MOI->getReg() != Reg)
3734 unsigned Sub = MOI->getSubReg();
3739 hasSubRegDef =
true;
3748 if (LaneMask.
any() && (LaneMask & SLM).none())
3750 if (MOI->readsReg())
3757 if (LaneMask.
none() && !hasDeadDef) {
3759 "Instruction ending live segment on dead slot has no dead flag",
3761 report_context(LR, Reg, LaneMask);
3768 if (!
MRI->shouldTrackSubRegLiveness(Reg) || LaneMask.
any() ||
3770 report(
"Instruction ending live segment doesn't read the register",
3772 report_context(LR, Reg, LaneMask);
3792 if (LaneMask.
any()) {
3798 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3800 if (!
Reg.isVirtual() && MFI->isEHPad()) {
3801 if (&*MFI == EndMBB)
3809 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3813 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3815 if (MFI->isEHPad()) {
3818 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3829 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3832 report(
"Register not marked live out of predecessor", Pred);
3833 report_context(LR, Reg, LaneMask);
3834 report_context(*VNI);
3836 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3842 if (!IsPHI && PVNI != VNI) {
3843 report(
"Different value live out of predecessor", Pred);
3844 report_context(LR, Reg, LaneMask);
3845 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3848 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3851 if (&*MFI == EndMBB)
3860 verifyLiveRangeValue(LR, VNI, Reg, LaneMask);
3863 verifyLiveRangeSegment(LR,
I, Reg, LaneMask);
3866void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3869 verifyLiveRange(LI, Reg);
3875 if ((Mask & SR.LaneMask).any()) {
3876 report(
"Lane masks of sub ranges overlap in live interval", MF);
3879 if ((SR.LaneMask & ~MaxMask).any()) {
3880 report(
"Subrange lanemask is invalid", MF);
3884 report(
"Subrange must not be empty", MF);
3885 report_context(SR, LI.
reg(), SR.LaneMask);
3887 Mask |= SR.LaneMask;
3888 verifyLiveRange(SR, LI.
reg(), SR.LaneMask);
3890 report(
"A Subrange is not covered by the main range", MF);
3898 unsigned NumComp = ConEQ.Classify(LI);
3900 report(
"Multiple connected components in live interval", MF);
3902 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3903 OS << comp <<
": valnos";
3905 if (comp == ConEQ.getEqClass(
I))
3918struct StackStateOfBB {
3919 StackStateOfBB() =
default;
3920 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
3921 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
3922 ExitIsSetup(ExitSetup) {}
3927 bool EntryIsSetup =
false;
3928 bool ExitIsSetup =
false;
3936void MachineVerifier::verifyStackFrame() {
3937 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
3938 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
3939 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
3943 SPState.
resize(MF->getNumBlockIDs());
3950 DFI != DFE; ++DFI) {
3953 StackStateOfBB BBState;
3955 if (DFI.getPathLength() >= 2) {
3958 "DFS stack predecessor is already visited.\n");
3959 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
3960 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
3961 BBState.ExitValue = BBState.EntryValue;
3962 BBState.ExitIsSetup = BBState.EntryIsSetup;
3966 report(
"Call frame size on entry does not match value computed from "
3970 <<
" does not match value computed from predecessor "
3971 << -BBState.EntryValue <<
'\n';
3975 for (
const auto &
I : *
MBB) {
3976 if (
I.getOpcode() == FrameSetupOpcode) {
3977 if (BBState.ExitIsSetup)
3978 report(
"FrameSetup is after another FrameSetup", &
I);
3979 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3980 report(
"AdjustsStack not set in presence of a frame pseudo "
3981 "instruction.", &
I);
3982 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
3983 BBState.ExitIsSetup =
true;
3986 if (
I.getOpcode() == FrameDestroyOpcode) {
3987 int Size =
TII->getFrameTotalSize(
I);
3988 if (!BBState.ExitIsSetup)
3989 report(
"FrameDestroy is not after a FrameSetup", &
I);
3990 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
3992 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
3993 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
3994 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
3995 << AbsSPAdj <<
">.\n";
3997 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3998 report(
"AdjustsStack not set in presence of a frame pseudo "
3999 "instruction.", &
I);
4000 BBState.ExitValue +=
Size;
4001 BBState.ExitIsSetup =
false;
4009 if (Reachable.
count(Pred) &&
4010 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4011 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4012 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4014 << SPState[Pred->
getNumber()].ExitValue <<
", "
4015 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4017 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4024 if (Reachable.
count(Succ) &&
4025 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4026 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4027 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4029 << SPState[Succ->getNumber()].EntryValue <<
", "
4030 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4032 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4038 if (BBState.ExitIsSetup)
4039 report(
"A return block ends with a FrameSetup.",
MBB);
4040 if (BBState.ExitValue)
4041 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
4046void MachineVerifier::verifyStackProtector() {
4055 bool StackGrowsDown =
4082 if (SPStart < ObjEnd && ObjStart < SPEnd) {
4083 report(
"Stack protector overlaps with another stack object", MF);
4086 if ((StackGrowsDown && SPStart <= ObjStart) ||
4087 (!StackGrowsDown && SPStart >= ObjStart)) {
4088 report(
"Stack protector is not the top-most object on the stack", MF);
unsigned const MachineRegisterInfo * MRI
static bool isLoad(int Opcode)
static bool isStore(int Opcode)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file implements the BitVector class.
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
global merge Global merge function pass
const HexagonInstrInfo * TII
hexagon widen Hexagon Store false hexagon widen loads
A common definition of LaneBitmask for use in TableGen and CodeGen.
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MIR specialization of the GenericConvergenceVerifier template.
unsigned const TargetRegisterInfo * TRI
static void verifyConvergenceControl(const MachineFunction &MF, MachineDominatorTree &DT, std::function< void(const Twine &Message)> FailureCB, raw_ostream &OS)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
This file defines generic set operations that may be used on set's of different types,...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
static unsigned getSize(unsigned Kind)
const fltSemantics & getSemantics() const
A container for analyses that lazily runs them and caches their results.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool test(unsigned Idx) const
void clear()
clear - Removes all bits from the bitvector.
iterator_range< const_set_bits_iterator > set_bits() const
size_type size() const
size - Returns the number of bits in this bitvector.
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
This is the shared class of boolean and integer constants.
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Base class for user error types.
A specialized PseudoSourceValue for holding FixedStack values, which must include a frame index.
FunctionPass class - This class is used to implement most global optimizations.
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
void verify(const DominatorTreeT &DT)
void visit(const BlockT &BB)
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr unsigned getScalarSizeInBits() const
constexpr bool isScalar() const
constexpr bool isPointerVector() const
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
constexpr bool isPointerOrPointerVector() const
constexpr LLT getScalarType() const
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
void print(raw_ostream &O, const Module *=nullptr) const override
Implement the dump method.
Result of a LiveRange query.
bool isDeadDef() const
Return true if this instruction has a dead def.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
VNInfo * valueOut() const
Return the value leaving the instruction, if any.
bool isKill() const
Return true if the live-in value is killed by this instruction.
static LLVM_ATTRIBUTE_UNUSED bool isJointlyDominated(const MachineBasicBlock *MBB, ArrayRef< SlotIndex > Defs, const SlotIndexes &Indexes)
A diagnostic function to check if the end of the block MBB is jointly dominated by the blocks corresp...
This class represents the liveness of a register, stack slot, etc.
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
bool liveAt(SlotIndex index) const
bool covers(const LiveRange &Other) const
Returns true if all segments of the Other live range are completely covered by this live range.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
bool verify() const
Walk the range and assert if any invariants fail to hold.
unsigned getNumValNums() const
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
VarInfo & getVarInfo(Register Reg)
getVarInfo - Return the VarInfo structure for the specified VIRTUAL register.
TypeSize getValue() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
ExceptionHandling getExceptionHandlingType() const
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
bool isConvergent() const
Return true if this instruction is convergent.
bool variadicOpsAreDefs() const
Return true if variadic operands of this instruction are definitions.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
unsigned getOpcode() const
Return the opcode number for this descriptor.
This holds information about one operand of a machine instruction, indicating the register class for ...
bool isOptionalDef() const
Set if this operand is a optional def.
uint8_t OperandType
Information about the type of the operand.
MCRegAliasIterator enumerates all registers aliasing Reg.
bool isValid() const
isValid - Returns true until all the operands have been visited.
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
unsigned pred_size() const
bool isEHPad() const
Returns true if the block is a landing pad.
iterator_range< livein_iterator > liveins() const
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
succ_iterator succ_begin()
bool isIRBlockAddressTaken() const
Test whether this block is the target of an IR BlockAddress.
unsigned succ_size() const
BasicBlock * getAddressTakenIRBlock() const
Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
pred_iterator pred_begin()
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
unsigned getCallFrameSize() const
Return the call frame size on entry to this basic block.
iterator_range< succ_iterator > successors()
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int getStackProtectorIndex() const
Return the index for the stack protector object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool hasProperty(Property P) const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isReturn(QueryType Type=AnyInBundle) const
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
const PseudoSourceValue * getPseudoValue() const
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
LocationSize getSizeInBits() const
Return the size in bits of the memory reference.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isIntrinsicID() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
ArrayRef< int > getShuffleMask() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isValidExcessOperand() const
Return true if this operand can validly be appended to an arbitrary operand list.
bool isShuffleMask() const
unsigned getCFIIndex() const
bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool isEarlyClobber() const
Register getReg() const
getReg - Returns the register number.
bool isInternalRead() const
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr, const TargetIntrinsicInfo *IntrinsicInfo=nullptr) const
Print the MachineOperand to os.
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Special value supplied for machine level alias analysis.
Holds all the information related to register banks.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
This class implements the register bank concept.
const char * getName() const
Get a user friendly name of this register bank.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SlotIndex - An opaque wrapper around machine indexes.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level Statepoint operands.
StringRef - Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
TargetInstrInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
VNInfo - Value Number Information.
bool isUnused() const
Returns true if this value is unused.
unsigned id
The ID number of this value.
SlotIndex def
The index of the defining instruction.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
LLVM Value Representation.
std::pair< iterator, bool > insert(const ValueT &V)
constexpr bool isNonZero() const
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class implements an extremely fast bulk output stream that can only output to a stream.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
Reg
All possible values of the reg field in the ModR/M byte.
NodeAddr< PhiNode * > Phi
NodeAddr< DefNode * > Def
NodeAddr< FuncNode * > Func
const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
void initializeMachineVerifierLegacyPassPass(PassRegistry &)
@ SjLj
setjmp/longjmp based exceptions
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void set_subtract(S1Ty &S1, const S2Ty &S2)
set_subtract(A, B) - Compute A := A - B
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
bool isPreISelGenericOptimizationHint(unsigned Opcode)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
void verifyMachineFunction(const std::string &Banner, const MachineFunction &MF)
auto reverse(ContainerTy &&C)
detail::ValueMatchesPoly< M > HasValue(M Matcher)
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AtomicOrdering
Atomic ordering for LLVM's memory model.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
FunctionPass * createMachineVerifierPass(const std::string &Banner)
createMachineVerifierPass - This pass verifies cenerated machine code instructions for correctness.
Implement std::hash so that hash_code can be used in STL containers.
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static constexpr LaneBitmask getAll()
constexpr bool none() const
constexpr bool any() const
static constexpr LaneBitmask getNone()
This represents a simple continuous liveness interval for a value.
VarInfo - This represents the regions where a virtual register is live in the program.
Pair of physical register and lane mask.