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 verifySlotIndexes()
const;
364 const std::string Banner;
366 MachineVerifierLegacyPass(std::string banner = std::string())
385 MachineFunctionProperties::Property::FailsVerification))
388 MachineVerifier(
this, Banner.c_str(), &
errs()).verify(MF);
404 MachineVerifier(MFAM, Banner.c_str(), &
errs()).verify(MF);
408char MachineVerifierLegacyPass::ID = 0;
411 "Verify generated machine code",
false,
false)
414 return new MachineVerifierLegacyPass(Banner);
424 MachineVerifier(
nullptr, Banner.c_str(), &
errs()).verify(MF);
428 bool AbortOnError)
const {
429 return MachineVerifier(p, Banner,
OS, AbortOnError).verify(*
this);
434 bool AbortOnError)
const {
435 return MachineVerifier(Banner,
nullptr, LiveInts,
436 nullptr, Indexes,
OS, AbortOnError)
440void MachineVerifier::verifySlotIndexes()
const {
441 if (Indexes ==
nullptr)
459 MRI->getNumVirtRegs())
460 report(
"Function has NoVRegs property but there are VReg operands", &MF);
477 if (isFunctionFailedISel)
489 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
493 LiveVars = LVWrapper ? &LVWrapper->getLV() :
nullptr;
495 LiveStks = LSWrapper ? &LSWrapper->getLS() :
nullptr;
497 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
510 verifyProperties(MF);
512 visitMachineFunctionBefore();
514 visitMachineBasicBlockBefore(&
MBB);
518 bool InBundle =
false;
521 if (
MI.getParent() != &
MBB) {
522 report(
"Bad instruction parent pointer", &
MBB);
523 OS <<
"Instruction: " <<
MI;
528 if (InBundle && !
MI.isBundledWithPred())
529 report(
"Missing BundledPred flag, "
530 "BundledSucc was set on predecessor",
532 if (!InBundle &&
MI.isBundledWithPred())
533 report(
"BundledPred flag is set, "
534 "but BundledSucc not set on predecessor",
538 if (!
MI.isInsideBundle()) {
540 visitMachineBundleAfter(CurBundle);
542 visitMachineBundleBefore(CurBundle);
543 }
else if (!CurBundle)
544 report(
"No bundle header", &
MI);
545 visitMachineInstrBefore(&
MI);
546 for (
unsigned I = 0, E =
MI.getNumOperands();
I != E; ++
I) {
548 if (
Op.getParent() != &
MI) {
551 report(
"Instruction has operand with wrong parent set", &
MI);
554 visitMachineOperand(&
Op,
I);
558 InBundle =
MI.isBundledWithSucc();
561 visitMachineBundleAfter(CurBundle);
563 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
564 visitMachineBasicBlockAfter(&
MBB);
566 visitMachineFunctionAfter();
576 return !ReportedErrs.hasError();
579void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
582 if (ReportedErrs.increment()) {
584 OS <<
"# " << Banner <<
'\n';
586 if (LiveInts !=
nullptr)
592 OS <<
"*** Bad machine code: " << msg <<
" ***\n"
593 <<
"- function: " << MF->
getName() <<
'\n';
600 <<
" (" << (
const void *)
MBB <<
')';
602 OS <<
" [" << Indexes->getMBBStartIdx(
MBB) <<
';'
603 << Indexes->getMBBEndIdx(
MBB) <<
')';
607void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
609 report(msg,
MI->getParent());
610 OS <<
"- instruction: ";
611 if (Indexes && Indexes->hasIndex(*
MI))
612 OS << Indexes->getInstructionIndex(*
MI) <<
'\t';
616void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
617 unsigned MONum,
LLT MOVRegType) {
620 OS <<
"- operand " << MONum <<
": ";
626 report(Msg.
str().c_str(),
MI);
629void MachineVerifier::report_context(
SlotIndex Pos)
const {
630 OS <<
"- at: " << Pos <<
'\n';
633void MachineVerifier::report_context(
const LiveInterval &LI)
const {
634 OS <<
"- interval: " << LI <<
'\n';
639 report_context_liverange(LR);
640 report_context_vreg_regunit(VRegUnit);
642 report_context_lanemask(LaneMask);
646 OS <<
"- segment: " << S <<
'\n';
649void MachineVerifier::report_context(
const VNInfo &VNI)
const {
650 OS <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
653void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
654 OS <<
"- liverange: " << LR <<
'\n';
657void MachineVerifier::report_context(
MCPhysReg PReg)
const {
661void MachineVerifier::report_context_vreg(
Register VReg)
const {
665void MachineVerifier::report_context_vreg_regunit(
Register VRegOrUnit)
const {
667 report_context_vreg(VRegOrUnit);
673void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
678 BBInfo &MInfo = MBBInfoMap[
MBB];
679 if (!MInfo.reachable) {
680 MInfo.reachable =
true;
686void MachineVerifier::visitMachineFunctionBefore() {
688 regsReserved =
MRI->reservedRegsFrozen() ?
MRI->getReservedRegs()
689 :
TRI->getReservedRegs(*MF);
692 markReachable(&MF->
front());
695 FunctionBlocks.clear();
696 for (
const auto &
MBB : *MF) {
697 FunctionBlocks.insert(&
MBB);
698 BBInfo &MInfo = MBBInfoMap[&
MBB];
702 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
706 report(
"MBB has duplicate entries in its successor list.", &
MBB);
710 MRI->verifyUseLists();
718 FirstTerminator =
nullptr;
719 FirstNonPHI =
nullptr;
721 if (!MF->getProperties().hasProperty(
726 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
729 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
730 "inlineasm-br-indirect-target.",
732 report_context(LI.PhysReg);
739 report(
"ir-block-address-taken is associated with basic block not used by "
748 LandingPadSuccs.
insert(succ);
749 if (!FunctionBlocks.count(succ))
750 report(
"MBB has successor that isn't part of the function.",
MBB);
751 if (!MBBInfoMap[succ].Preds.count(
MBB)) {
752 report(
"Inconsistent CFG",
MBB);
753 OS <<
"MBB is not in the predecessor list of the successor "
760 if (!FunctionBlocks.count(Pred))
761 report(
"MBB has predecessor that isn't part of the function.",
MBB);
762 if (!MBBInfoMap[Pred].Succs.count(
MBB)) {
763 report(
"Inconsistent CFG",
MBB);
764 OS <<
"MBB is not in the successor list of the predecessor "
772 if (LandingPadSuccs.
size() > 1 &&
777 report(
"MBB has more than one landing pad successor",
MBB);
790 report(
"MBB exits via unconditional fall-through but ends with a "
791 "barrier instruction!",
MBB);
794 report(
"MBB exits via unconditional fall-through but has a condition!",
797 }
else if (
TBB && !FBB &&
Cond.empty()) {
800 report(
"MBB exits via unconditional branch but doesn't contain "
801 "any instructions!",
MBB);
803 report(
"MBB exits via unconditional branch but doesn't end with a "
804 "barrier instruction!",
MBB);
806 report(
"MBB exits via unconditional branch but the branch isn't a "
807 "terminator instruction!",
MBB);
809 }
else if (
TBB && !FBB && !
Cond.empty()) {
812 report(
"MBB exits via conditional branch/fall-through but doesn't "
813 "contain any instructions!",
MBB);
815 report(
"MBB exits via conditional branch/fall-through but ends with a "
816 "barrier instruction!",
MBB);
818 report(
"MBB exits via conditional branch/fall-through but the branch "
819 "isn't a terminator instruction!",
MBB);
821 }
else if (
TBB && FBB) {
825 report(
"MBB exits via conditional branch/branch but doesn't "
826 "contain any instructions!",
MBB);
828 report(
"MBB exits via conditional branch/branch but doesn't end with a "
829 "barrier instruction!",
MBB);
831 report(
"MBB exits via conditional branch/branch but the branch "
832 "isn't a terminator instruction!",
MBB);
835 report(
"MBB exits via conditional branch/branch but there's no "
839 report(
"analyzeBranch returned invalid data!",
MBB);
845 report(
"MBB exits via jump or conditional branch, but its target isn't a "
849 report(
"MBB exits via conditional branch, but its target isn't a CFG "
856 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
861 if (!
Cond.empty() && !FBB) {
864 report(
"MBB conditionally falls through out of function!",
MBB);
866 report(
"MBB exits via conditional branch/fall-through but the CFG "
867 "successors don't match the actual successors!",
874 if (SuccMBB ==
TBB || SuccMBB == FBB)
882 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
884 report(
"MBB has unexpected successors which are not branch targets, "
885 "fallthrough, EHPads, or inlineasm_br targets.",
891 if (
MRI->tracksLiveness()) {
894 report(
"MBB live-in list contains non-physical register",
MBB);
913 lastIndex = Indexes->getMBBStartIdx(
MBB);
918void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
919 if (Indexes && Indexes->hasIndex(*
MI)) {
921 if (!(idx > lastIndex)) {
922 report(
"Instruction index out of order",
MI);
923 OS <<
"Last instruction was at " << lastIndex <<
'\n';
929 if (
MI->isTerminator()) {
930 if (!FirstTerminator)
931 FirstTerminator =
MI;
932 }
else if (FirstTerminator) {
935 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
936 report(
"Non-terminator instruction after the first terminator",
MI);
937 OS <<
"First terminator was:\t" << *FirstTerminator;
946 if (
MI->getNumOperands() < 2) {
947 report(
"Too few operands on inline asm",
MI);
950 if (!
MI->getOperand(0).isSymbol())
951 report(
"Asm string must be an external symbol",
MI);
952 if (!
MI->getOperand(1).isImm())
953 report(
"Asm flags must be an immediate",
MI);
957 if (!isUInt<6>(
MI->getOperand(1).getImm()))
958 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
964 for (
unsigned e =
MI->getNumOperands(); OpNo <
e; OpNo += NumOps) {
970 NumOps = 1 +
F.getNumOperandRegisters();
973 if (OpNo >
MI->getNumOperands())
974 report(
"Missing operands in last group",
MI);
977 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
981 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
984 report(
"Expected implicit register after groups", &MO, OpNo);
987 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
1000 if (!IndirectTargetMBB) {
1001 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1006 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1010 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1016bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1021 const auto Reg = Op.getReg();
1022 if (Reg.isPhysical())
1024 return !MRI.getType(Reg).isScalar();
1027 report(
"All register operands must have scalar types", &
MI);
1034bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1037 report(
"operand types must be all-vector or all-scalar",
MI);
1047 report(
"operand types must preserve number of vector elements",
MI);
1054bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1055 auto Opcode =
MI->getOpcode();
1056 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1057 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1058 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1059 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1061 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1062 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1063 if (NoSideEffects && DeclHasSideEffects) {
1065 " used with intrinsic that accesses memory"),
1069 if (!NoSideEffects && !DeclHasSideEffects) {
1070 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1078bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1079 auto Opcode =
MI->getOpcode();
1080 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1081 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1082 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1083 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1085 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1086 bool DeclIsConvergent =
Attrs.hasFnAttr(Attribute::Convergent);
1087 if (NotConvergent && DeclIsConvergent) {
1088 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1092 if (!NotConvergent && !DeclIsConvergent) {
1094 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1103void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1104 if (isFunctionSelected)
1105 report(
"Unexpected generic instruction in a Selected function",
MI);
1108 unsigned NumOps =
MI->getNumOperands();
1111 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1112 bool HasMBB =
false;
1121 report(
"Branch instruction is missing a basic block operand or "
1122 "isIndirectBranch property",
1131 if (!MCID.
operands()[
I].isGenericType())
1135 size_t TypeIdx = MCID.
operands()[
I].getGenericTypeIndex();
1136 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1140 report(
"generic instruction must use register operands",
MI);
1150 if (!Types[TypeIdx].
isValid())
1151 Types[TypeIdx] = OpTy;
1152 else if (Types[TypeIdx] != OpTy)
1153 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1156 report(
"Generic instruction is missing a virtual register type", MO,
I);
1161 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1164 report(
"Generic instruction cannot have physical register", MO,
I);
1176 unsigned Opc =
MI->getOpcode();
1178 case TargetOpcode::G_ASSERT_SEXT:
1179 case TargetOpcode::G_ASSERT_ZEXT: {
1180 std::string OpcName =
1181 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1182 if (!
MI->getOperand(2).isImm()) {
1183 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1189 LLT SrcTy =
MRI->getType(Src);
1190 int64_t
Imm =
MI->getOperand(2).getImm();
1192 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1197 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1205 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1206 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1212 if (DstRC && DstRC !=
MRI->getRegClassOrNull(Src)) {
1214 Twine(OpcName,
" source and destination register classes must match"),
1222 case TargetOpcode::G_CONSTANT:
1223 case TargetOpcode::G_FCONSTANT: {
1224 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1226 report(
"Instruction cannot use a vector result type",
MI);
1228 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1229 if (!
MI->getOperand(1).isCImm()) {
1230 report(
"G_CONSTANT operand must be cimm",
MI);
1236 report(
"inconsistent constant size",
MI);
1238 if (!
MI->getOperand(1).isFPImm()) {
1239 report(
"G_FCONSTANT operand must be fpimm",
MI);
1246 report(
"inconsistent constant size",
MI);
1252 case TargetOpcode::G_LOAD:
1253 case TargetOpcode::G_STORE:
1254 case TargetOpcode::G_ZEXTLOAD:
1255 case TargetOpcode::G_SEXTLOAD: {
1256 LLT ValTy =
MRI->getType(
MI->getOperand(0).getReg());
1257 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1259 report(
"Generic memory instruction must access a pointer",
MI);
1263 if (!
MI->hasOneMemOperand()) {
1264 report(
"Generic instruction accessing memory must have one mem operand",
1268 if (
MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
1269 MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
1272 report(
"Generic extload must have a narrower memory type",
MI);
1273 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1276 report(
"load memory size cannot exceed result size",
MI);
1277 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1280 report(
"store memory size cannot exceed value size",
MI);
1284 if (Opc == TargetOpcode::G_STORE) {
1287 report(
"atomic store cannot use acquire ordering",
MI);
1292 report(
"atomic load cannot use release ordering",
MI);
1298 case TargetOpcode::G_PHI: {
1299 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1304 LLT Ty = MRI->getType(MO.getReg());
1305 if (!Ty.isValid() || (Ty != DstTy))
1309 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1314 case TargetOpcode::G_BITCAST: {
1315 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1316 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1321 report(
"bitcast cannot convert between pointers and other types",
MI);
1324 report(
"bitcast sizes must match",
MI);
1327 report(
"bitcast must change the type",
MI);
1331 case TargetOpcode::G_INTTOPTR:
1332 case TargetOpcode::G_PTRTOINT:
1333 case TargetOpcode::G_ADDRSPACE_CAST: {
1334 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1335 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1339 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1344 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1346 report(
"inttoptr result type must be a pointer",
MI);
1348 report(
"inttoptr source type must not be a pointer",
MI);
1349 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1351 report(
"ptrtoint source type must be a pointer",
MI);
1353 report(
"ptrtoint result type must not be a pointer",
MI);
1355 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1357 report(
"addrspacecast types must be pointers",
MI);
1360 report(
"addrspacecast must convert different address spaces",
MI);
1366 case TargetOpcode::G_PTR_ADD: {
1367 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1368 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1369 LLT OffsetTy =
MRI->getType(
MI->getOperand(2).getReg());
1374 report(
"gep first operand must be a pointer",
MI);
1377 report(
"gep offset operand must not be a pointer",
MI);
1382 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1384 report(
"gep offset operand must match index size for address space",
1392 case TargetOpcode::G_PTRMASK: {
1393 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1394 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1395 LLT MaskTy =
MRI->getType(
MI->getOperand(2).getReg());
1400 report(
"ptrmask result type must be a pointer",
MI);
1403 report(
"ptrmask mask type must be an integer",
MI);
1405 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1408 case TargetOpcode::G_SEXT:
1409 case TargetOpcode::G_ZEXT:
1410 case TargetOpcode::G_ANYEXT:
1411 case TargetOpcode::G_TRUNC:
1412 case TargetOpcode::G_FPEXT:
1413 case TargetOpcode::G_FPTRUNC: {
1420 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1421 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1426 report(
"Generic extend/truncate can not operate on pointers",
MI);
1428 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1432 switch (
MI->getOpcode()) {
1434 if (DstSize <= SrcSize)
1435 report(
"Generic extend has destination type no larger than source",
MI);
1437 case TargetOpcode::G_TRUNC:
1438 case TargetOpcode::G_FPTRUNC:
1439 if (DstSize >= SrcSize)
1440 report(
"Generic truncate has destination type no smaller than source",
1446 case TargetOpcode::G_SELECT: {
1447 LLT SelTy =
MRI->getType(
MI->getOperand(0).getReg());
1448 LLT CondTy =
MRI->getType(
MI->getOperand(1).getReg());
1454 verifyVectorElementMatch(SelTy, CondTy,
MI);
1457 case TargetOpcode::G_MERGE_VALUES: {
1462 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1463 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1465 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1467 const unsigned NumOps =
MI->getNumOperands();
1469 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1471 for (
unsigned I = 2;
I != NumOps; ++
I) {
1472 if (
MRI->getType(
MI->getOperand(
I).getReg()) != SrcTy)
1473 report(
"G_MERGE_VALUES source types do not match",
MI);
1478 case TargetOpcode::G_UNMERGE_VALUES: {
1479 unsigned NumDsts =
MI->getNumOperands() - 1;
1480 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1481 for (
unsigned i = 1; i < NumDsts; ++i) {
1482 if (
MRI->getType(
MI->getOperand(i).getReg()) != DstTy) {
1483 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1488 LLT SrcTy =
MRI->getType(
MI->getOperand(NumDsts).getReg());
1496 report(
"G_UNMERGE_VALUES source operand does not match vector "
1497 "destination operands",
1504 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1505 "destination operands",
1510 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1511 "destination operands",
1517 case TargetOpcode::G_BUILD_VECTOR: {
1520 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1521 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1523 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1528 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1531 report(
"G_BUILD_VECTOR must have an operand for each elemement",
MI);
1534 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1535 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1539 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1542 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1543 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1545 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1548 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1549 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1552 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1557 case TargetOpcode::G_CONCAT_VECTORS: {
1560 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1561 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1563 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1566 if (
MI->getNumOperands() < 3)
1567 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1570 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1571 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1574 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1577 case TargetOpcode::G_ICMP:
1578 case TargetOpcode::G_FCMP: {
1579 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1580 LLT SrcTy =
MRI->getType(
MI->getOperand(2).getReg());
1585 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1589 case TargetOpcode::G_SCMP:
1590 case TargetOpcode::G_UCMP: {
1591 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1592 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1595 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1600 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1605 report(
"Result type must be at least 2 bits wide",
MI);
1612 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1618 case TargetOpcode::G_EXTRACT: {
1620 if (!
SrcOp.isReg()) {
1621 report(
"extract source must be a register",
MI);
1626 if (!OffsetOp.
isImm()) {
1627 report(
"extract offset must be a constant",
MI);
1631 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1633 if (SrcSize == DstSize)
1634 report(
"extract source must be larger than result",
MI);
1636 if (DstSize + OffsetOp.
getImm() > SrcSize)
1637 report(
"extract reads past end of register",
MI);
1640 case TargetOpcode::G_INSERT: {
1642 if (!
SrcOp.isReg()) {
1643 report(
"insert source must be a register",
MI);
1648 if (!OffsetOp.
isImm()) {
1649 report(
"insert offset must be a constant",
MI);
1653 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1656 if (DstSize <= SrcSize)
1657 report(
"inserted size must be smaller than total register",
MI);
1659 if (SrcSize + OffsetOp.
getImm() > DstSize)
1660 report(
"insert writes past end of register",
MI);
1664 case TargetOpcode::G_JUMP_TABLE: {
1665 if (!
MI->getOperand(1).isJTI())
1666 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1667 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1669 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1672 case TargetOpcode::G_BRJT: {
1673 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
1674 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1676 if (!
MI->getOperand(1).isJTI())
1677 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1679 const auto &IdxOp =
MI->getOperand(2);
1680 if (!IdxOp.isReg() ||
MRI->getType(IdxOp.getReg()).isPointer())
1681 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1684 case TargetOpcode::G_INTRINSIC:
1685 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1686 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1687 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1692 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1696 if (!verifyGIntrinsicSideEffects(
MI))
1698 if (!verifyGIntrinsicConvergence(
MI))
1703 case TargetOpcode::G_SEXT_INREG: {
1704 if (!
MI->getOperand(2).isImm()) {
1705 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1709 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1710 int64_t
Imm =
MI->getOperand(2).getImm();
1712 report(
"G_SEXT_INREG size must be >= 1",
MI);
1714 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1717 case TargetOpcode::G_BSWAP: {
1718 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1720 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1723 case TargetOpcode::G_VSCALE: {
1724 if (!
MI->getOperand(1).isCImm()) {
1725 report(
"G_VSCALE operand must be cimm",
MI);
1728 if (
MI->getOperand(1).getCImm()->isZero()) {
1729 report(
"G_VSCALE immediate cannot be zero",
MI);
1734 case TargetOpcode::G_STEP_VECTOR: {
1735 if (!
MI->getOperand(1).isCImm()) {
1736 report(
"operand must be cimm",
MI);
1740 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1741 report(
"step must be > 0",
MI);
1745 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1747 report(
"Destination type must be a scalable vector",
MI);
1753 report(
"Destination element type must be scalar",
MI);
1757 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1759 report(
"step bitwidth differs from result type element bitwidth",
MI);
1764 case TargetOpcode::G_INSERT_SUBVECTOR: {
1766 if (!Src0Op.
isReg()) {
1767 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1772 if (!Src1Op.
isReg()) {
1773 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1778 if (!IndexOp.
isImm()) {
1779 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1783 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1787 report(
"Destination type must be a vector",
MI);
1792 report(
"Second source must be a vector",
MI);
1797 report(
"Element type of vectors must be the same",
MI);
1802 report(
"Vector types must both be fixed or both be scalable",
MI);
1808 report(
"Second source must be smaller than destination vector",
MI);
1814 if (IndexOp.
getImm() % Src1MinLen != 0) {
1815 report(
"Index must be a multiple of the second source vector's "
1816 "minimum vector length",
1822 if (
Idx >= DstMinLen ||
Idx + Src1MinLen > DstMinLen) {
1823 report(
"Subvector type and index must not cause insert to overrun the "
1824 "vector being inserted into",
1831 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1833 if (!
SrcOp.isReg()) {
1834 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1839 if (!IndexOp.
isImm()) {
1840 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1844 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1848 report(
"Destination type must be a vector",
MI);
1853 report(
"Source must be a vector",
MI);
1858 report(
"Element type of vectors must be the same",
MI);
1863 report(
"Vector types must both be fixed or both be scalable",
MI);
1869 report(
"Destination vector must be smaller than source vector",
MI);
1875 if (
Idx % DstMinLen != 0) {
1876 report(
"Index must be a multiple of the destination vector's minimum "
1883 if (
Idx >= SrcMinLen ||
Idx + DstMinLen > SrcMinLen) {
1884 report(
"Destination type and index must not cause extract to overrun the "
1892 case TargetOpcode::G_SHUFFLE_VECTOR: {
1895 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1899 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1900 LLT Src0Ty =
MRI->getType(
MI->getOperand(1).getReg());
1901 LLT Src1Ty =
MRI->getType(
MI->getOperand(2).getReg());
1903 if (Src0Ty != Src1Ty)
1904 report(
"Source operands must be the same type",
MI);
1907 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1916 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1917 report(
"Wrong result type for shufflemask",
MI);
1919 for (
int Idx : MaskIdxes) {
1923 if (
Idx >= 2 * SrcNumElts)
1924 report(
"Out of bounds shuffle index",
MI);
1930 case TargetOpcode::G_SPLAT_VECTOR: {
1931 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1932 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1935 report(
"Destination type must be a scalable vector",
MI);
1940 report(
"Source type must be a scalar or pointer",
MI);
1946 report(
"Element type of the destination must be the same size or smaller "
1947 "than the source type",
1954 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1955 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1956 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1957 LLT IdxTy =
MRI->getType(
MI->getOperand(2).getReg());
1960 report(
"Destination type must be a scalar or pointer",
MI);
1965 report(
"First source must be a vector",
MI);
1969 auto TLI = MF->getSubtarget().getTargetLowering();
1971 TLI->getVectorIdxTy(MF->getDataLayout()).getFixedSizeInBits()) {
1972 report(
"Index type must match VectorIdxTy",
MI);
1978 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1979 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1980 LLT VecTy =
MRI->getType(
MI->getOperand(1).getReg());
1981 LLT ScaTy =
MRI->getType(
MI->getOperand(2).getReg());
1982 LLT IdxTy =
MRI->getType(
MI->getOperand(3).getReg());
1985 report(
"Destination type must be a vector",
MI);
1989 if (VecTy != DstTy) {
1990 report(
"Destination type and vector type must match",
MI);
1995 report(
"Inserted element must be a scalar or pointer",
MI);
1999 auto TLI = MF->getSubtarget().getTargetLowering();
2001 TLI->getVectorIdxTy(MF->getDataLayout()).getFixedSizeInBits()) {
2002 report(
"Index type must match VectorIdxTy",
MI);
2008 case TargetOpcode::G_DYN_STACKALLOC: {
2014 report(
"dst operand 0 must be a pointer type",
MI);
2018 if (!AllocOp.
isReg() || !
MRI->getType(AllocOp.
getReg()).isScalar()) {
2019 report(
"src operand 1 must be a scalar reg type",
MI);
2023 if (!AlignOp.
isImm()) {
2024 report(
"src operand 2 must be an immediate type",
MI);
2029 case TargetOpcode::G_MEMCPY_INLINE:
2030 case TargetOpcode::G_MEMCPY:
2031 case TargetOpcode::G_MEMMOVE: {
2033 if (MMOs.
size() != 2) {
2034 report(
"memcpy/memmove must have 2 memory operands",
MI);
2040 report(
"wrong memory operand types",
MI);
2045 report(
"inconsistent memory operand sizes",
MI);
2047 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2048 LLT SrcPtrTy =
MRI->getType(
MI->getOperand(1).getReg());
2051 report(
"memory instruction operand must be a pointer",
MI);
2056 report(
"inconsistent store address space",
MI);
2058 report(
"inconsistent load address space",
MI);
2060 if (Opc != TargetOpcode::G_MEMCPY_INLINE)
2061 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2062 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2066 case TargetOpcode::G_BZERO:
2067 case TargetOpcode::G_MEMSET: {
2069 std::string
Name = Opc == TargetOpcode::G_MEMSET ?
"memset" :
"bzero";
2070 if (MMOs.
size() != 1) {
2071 report(
Twine(
Name,
" must have 1 memory operand"),
MI);
2076 report(
Twine(
Name,
" memory operand must be a store"),
MI);
2080 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2082 report(
Twine(
Name,
" operand must be a pointer"),
MI);
2087 report(
"inconsistent " +
Twine(
Name,
" address space"),
MI);
2089 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2090 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2091 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2095 case TargetOpcode::G_UBSANTRAP: {
2097 if (!
MI->getOperand(0).isImm()) {
2098 report(
"Crash kind must be an immediate", &KindOp, 0);
2101 int64_t
Kind =
MI->getOperand(0).getImm();
2102 if (!isInt<8>(Kind))
2103 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2106 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2107 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2108 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2109 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2110 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2112 report(
"Vector reduction requires a scalar destination type",
MI);
2114 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2116 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2119 case TargetOpcode::G_VECREDUCE_FADD:
2120 case TargetOpcode::G_VECREDUCE_FMUL:
2121 case TargetOpcode::G_VECREDUCE_FMAX:
2122 case TargetOpcode::G_VECREDUCE_FMIN:
2123 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2124 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2125 case TargetOpcode::G_VECREDUCE_ADD:
2126 case TargetOpcode::G_VECREDUCE_MUL:
2127 case TargetOpcode::G_VECREDUCE_AND:
2128 case TargetOpcode::G_VECREDUCE_OR:
2129 case TargetOpcode::G_VECREDUCE_XOR:
2130 case TargetOpcode::G_VECREDUCE_SMAX:
2131 case TargetOpcode::G_VECREDUCE_SMIN:
2132 case TargetOpcode::G_VECREDUCE_UMAX:
2133 case TargetOpcode::G_VECREDUCE_UMIN: {
2134 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2136 report(
"Vector reduction requires a scalar destination type",
MI);
2140 case TargetOpcode::G_SBFX:
2141 case TargetOpcode::G_UBFX: {
2142 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2144 report(
"Bitfield extraction is not supported on vectors",
MI);
2149 case TargetOpcode::G_SHL:
2150 case TargetOpcode::G_LSHR:
2151 case TargetOpcode::G_ASHR:
2152 case TargetOpcode::G_ROTR:
2153 case TargetOpcode::G_ROTL: {
2154 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2155 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2157 report(
"Shifts and rotates require operands to be either all scalars or "
2164 case TargetOpcode::G_LLROUND:
2165 case TargetOpcode::G_LROUND: {
2166 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2167 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2172 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2174 verifyAllRegOpsScalar(*
MI, *
MRI);
2177 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2182 case TargetOpcode::G_IS_FPCLASS: {
2183 LLT DestTy =
MRI->getType(
MI->getOperand(0).getReg());
2186 report(
"Destination must be a scalar or vector of scalars",
MI);
2189 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2192 report(
"Source must be a scalar or vector of scalars",
MI);
2195 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2198 if (!TestMO.
isImm()) {
2199 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2204 report(
"Incorrect floating-point class set (operand 2)",
MI);
2209 case TargetOpcode::G_PREFETCH: {
2211 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer()) {
2212 report(
"addr operand must be a pointer", &AddrOp, 0);
2217 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2222 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2227 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2232 case TargetOpcode::G_ASSERT_ALIGN: {
2233 if (
MI->getOperand(2).getImm() < 1)
2234 report(
"alignment immediate must be >= 1",
MI);
2237 case TargetOpcode::G_CONSTANT_POOL: {
2238 if (!
MI->getOperand(1).isCPI())
2239 report(
"Src operand 1 must be a constant pool index",
MI);
2240 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
2241 report(
"Dst operand 0 must be a pointer",
MI);
2244 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2246 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer())
2247 report(
"addr operand must be a pointer", &AddrOp, 1);
2255void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2258 report(
"Too few operands",
MI);
2260 <<
MI->getNumOperands() <<
" given.\n";
2264 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2267 if (MF->getProperties().hasProperty(
2269 report(
"Found PHI instruction with NoPHIs property set",
MI);
2272 report(
"Found PHI instruction after non-PHI",
MI);
2273 }
else if (FirstNonPHI ==
nullptr)
2277 if (
MI->isInlineAsm())
2278 verifyInlineAsm(
MI);
2281 if (
TII->isUnspillableTerminator(
MI)) {
2282 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2283 report(
"Unspillable Terminator does not define a reg",
MI);
2285 if (
Def.isVirtual() &&
2286 !MF->getProperties().hasProperty(
2288 std::distance(
MRI->use_nodbg_begin(Def),
MRI->use_nodbg_end()) > 1)
2289 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2295 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2296 if (!
MI->getDebugLoc())
2297 report(
"Missing DebugLoc for debug instruction",
MI);
2301 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2302 report(
"Metadata instruction should not have a value tracking number",
MI);
2306 if (
Op->isLoad() && !
MI->mayLoad())
2307 report(
"Missing mayLoad flag",
MI);
2308 if (
Op->isStore() && !
MI->mayStore())
2309 report(
"Missing mayStore flag",
MI);
2315 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2316 if (
MI->isDebugOrPseudoInstr()) {
2318 report(
"Debug instruction has a slot index",
MI);
2319 }
else if (
MI->isInsideBundle()) {
2321 report(
"Instruction inside bundle has a slot index",
MI);
2324 report(
"Missing slot index",
MI);
2330 verifyPreISelGenericInstruction(
MI);
2339 switch (
MI->getOpcode()) {
2340 case TargetOpcode::COPY: {
2346 LLT DstTy =
MRI->getType(DstReg);
2347 LLT SrcTy =
MRI->getType(SrcReg);
2350 if (SrcTy != DstTy) {
2351 report(
"Copy Instruction is illegal with mismatching types",
MI);
2352 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2367 TRI->getMinimalPhysRegClassLLT(SrcReg, DstTy);
2369 SrcSize =
TRI->getRegSizeInBits(*SrcRC);
2374 TRI->getMinimalPhysRegClassLLT(DstReg, SrcTy);
2376 DstSize =
TRI->getRegSizeInBits(*DstRC);
2394 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2395 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2396 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2401 case TargetOpcode::STATEPOINT: {
2403 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2404 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2405 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2406 report(
"meta operands to STATEPOINT not constant!",
MI);
2410 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2411 if (
Offset >=
MI->getNumOperands()) {
2412 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2415 if (!
MI->getOperand(
Offset - 1).isImm() ||
2416 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2418 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2420 VerifyStackMapConstant(SO.getCCIdx());
2421 VerifyStackMapConstant(SO.getFlagsIdx());
2422 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2423 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2424 VerifyStackMapConstant(SO.getNumAllocaIdx());
2425 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2429 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2430 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2431 for (
unsigned Idx = 0;
Idx <
MI->getNumDefs();
Idx++) {
2433 if (!
MI->isRegTiedToUseOperand(
Idx, &UseOpIdx)) {
2434 report(
"STATEPOINT defs expected to be tied",
MI);
2437 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2438 report(
"STATEPOINT def tied to non-gc operand",
MI);
2445 case TargetOpcode::INSERT_SUBREG: {
2446 unsigned InsertedSize;
2447 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2448 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2450 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *
MRI);
2451 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2452 if (SubRegSize < InsertedSize) {
2453 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2454 "size than the subreg it was inserted into",
MI);
2458 case TargetOpcode::REG_SEQUENCE: {
2459 unsigned NumOps =
MI->getNumOperands();
2460 if (!(NumOps & 1)) {
2461 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2465 for (
unsigned I = 1;
I != NumOps;
I += 2) {
2470 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2472 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2473 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2474 report(
"Invalid subregister index operand for REG_SEQUENCE",
2479 Register DstReg =
MI->getOperand(0).getReg();
2481 report(
"REG_SEQUENCE does not support physical register results",
MI);
2483 if (
MI->getOperand(0).getSubReg())
2484 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2492MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2496 if (MCID.
getOpcode() == TargetOpcode::PATCHPOINT)
2497 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2500 if (MONum < NumDefs) {
2503 report(
"Explicit definition must be a register", MO, MONum);
2505 report(
"Explicit definition marked as use", MO, MONum);
2507 report(
"Explicit definition marked as implicit", MO, MONum);
2516 report(
"Explicit operand marked as def", MO, MONum);
2518 report(
"Explicit operand marked as implicit", MO, MONum);
2524 report(
"Expected a register operand.", MO, MONum);
2528 !
TII->isPCRelRegisterOperandLegal(*MO)))
2529 report(
"Expected a non-register operand.", MO, MONum);
2536 report(
"Tied use must be a register", MO, MONum);
2538 report(
"Operand should be tied", MO, MONum);
2539 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2540 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2543 if (!MOTied.
isReg())
2544 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2547 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2550 report(
"Explicit operand should not be tied", MO, MONum);
2551 }
else if (!
MI->isVariadic()) {
2554 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2561 if (
MI->isDebugInstr() && MO->
isUse()) {
2563 report(
"Register operand must be marked debug", MO, MONum);
2565 report(
"Register operand must not be marked debug", MO, MONum);
2571 if (
MRI->tracksLiveness() && !
MI->isDebugInstr())
2572 checkLiveness(MO, MONum);
2576 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2580 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2582 if (!OtherMO.
isReg())
2583 report(
"Must be tied to a register", MO, MONum);
2585 report(
"Missing tie flags on tied operand", MO, MONum);
2586 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2587 report(
"Inconsistent tie links", MO, MONum);
2591 report(
"Explicit def tied to explicit use without tie constraint",
2595 report(
"Explicit def should be tied to implicit use", MO, MONum);
2608 if (MF->getProperties().hasProperty(
2610 MO->
isUse() &&
MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2611 Reg !=
MI->getOperand(DefIdx).getReg())
2612 report(
"Two-address instruction operands must be identical", MO, MONum);
2617 if (
Reg.isPhysical()) {
2619 report(
"Illegal subregister index for physical register", MO, MONum);
2624 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2625 if (!DRC->contains(Reg)) {
2626 report(
"Illegal physical register for instruction", MO, MONum);
2628 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2633 if (
MRI->isReserved(Reg)) {
2634 report(
"isRenamable set on reserved register", MO, MONum);
2651 report(
"Generic virtual register use cannot be undef", MO, MONum);
2658 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2659 !
MI->isDebugValue() || !
MRI->def_empty(Reg)) {
2661 if (isFunctionSelected) {
2662 report(
"Generic virtual register invalid in a Selected function",
2668 LLT Ty =
MRI->getType(Reg);
2670 report(
"Generic virtual register must have a valid type", MO,
2679 if (!RegBank && isFunctionRegBankSelected) {
2680 report(
"Generic virtual register must have a bank in a "
2681 "RegBankSelected function",
2689 report(
"Register bank is too small for virtual register", MO,
2691 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2699 report(
"Generic virtual register does not allow subregister index", MO,
2709 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2710 report(
"Virtual register does not match instruction constraint", MO,
2712 OS <<
"Expect register class "
2713 <<
TRI->getRegClassName(
TII->getRegClass(MCID, MONum,
TRI, *MF))
2714 <<
" but got nothing\n";
2722 TRI->getSubClassWithSubReg(RC, SubIdx);
2724 report(
"Invalid subregister index for virtual register", MO, MONum);
2725 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2726 <<
" does not support subreg index " << SubIdx <<
'\n';
2730 report(
"Invalid register class for subregister index", MO, MONum);
2731 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2732 <<
" does not fully support subreg index " << SubIdx <<
'\n';
2738 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2741 TRI->getLargestLegalSuperClass(RC, *MF);
2743 report(
"No largest legal super class exists.", MO, MONum);
2746 DRC =
TRI->getMatchingSuperRegClass(SuperRC, DRC, SubIdx);
2748 report(
"No matching super-reg register class.", MO, MONum);
2753 report(
"Illegal virtual register for instruction", MO, MONum);
2754 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2755 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2770 report(
"PHI operand is not in the CFG", MO, MONum);
2774 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2775 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2786 for (
auto *MMO :
MI->memoperands()) {
2788 if (PSV ==
nullptr)
continue;
2790 dyn_cast<FixedStackPseudoSourceValue>(PSV);
2791 if (
Value ==
nullptr)
continue;
2792 if (
Value->getFrameIndex() != FI)
continue;
2801 report(
"Missing fixed stack memoperand.",
MI);
2804 report(
"Instruction loads from dead spill slot", MO, MONum);
2805 OS <<
"Live stack: " << LI <<
'\n';
2808 report(
"Instruction stores to dead spill slot", MO, MONum);
2809 OS <<
"Live stack: " << LI <<
'\n';
2815 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2816 report(
"CFI instruction has invalid index", MO, MONum);
2824void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2832 report(
"invalid live range", MO, MONum);
2833 report_context_liverange(LR);
2834 report_context_vreg_regunit(VRegOrUnit);
2835 report_context(UseIdx);
2844 report(
"No live segment at use", MO, MONum);
2845 report_context_liverange(LR);
2846 report_context_vreg_regunit(VRegOrUnit);
2847 report_context(UseIdx);
2850 report(
"Live range continues after kill flag", MO, MONum);
2851 report_context_liverange(LR);
2852 report_context_vreg_regunit(VRegOrUnit);
2854 report_context_lanemask(LaneMask);
2855 report_context(UseIdx);
2859void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2866 report(
"invalid live range", MO, MONum);
2867 report_context_liverange(LR);
2868 report_context_vreg_regunit(VRegOrUnit);
2870 report_context_lanemask(LaneMask);
2871 report_context(DefIdx);
2883 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
2885 (VNI->def != DefIdx &&
2886 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
2887 report(
"Inconsistent valno->def", MO, MONum);
2888 report_context_liverange(LR);
2889 report_context_vreg_regunit(VRegOrUnit);
2891 report_context_lanemask(LaneMask);
2892 report_context(*VNI);
2893 report_context(DefIdx);
2896 report(
"No live segment at def", MO, MONum);
2897 report_context_liverange(LR);
2898 report_context_vreg_regunit(VRegOrUnit);
2900 report_context_lanemask(LaneMask);
2901 report_context(DefIdx);
2913 if (SubRangeCheck || MO->
getSubReg() == 0) {
2914 report(
"Live range continues after dead def flag", MO, MONum);
2915 report_context_liverange(LR);
2916 report_context_vreg_regunit(VRegOrUnit);
2918 report_context_lanemask(LaneMask);
2924void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
2927 const unsigned SubRegIdx = MO->
getSubReg();
2930 if (LiveInts &&
Reg.isVirtual()) {
2931 if (LiveInts->hasInterval(Reg)) {
2932 LI = &LiveInts->getInterval(Reg);
2935 report(
"Live interval for subreg operand has no subranges", MO, MONum);
2937 report(
"Virtual register has no live interval", MO, MONum);
2944 addRegWithSubRegs(regsKilled, Reg);
2949 if (LiveVars &&
Reg.isVirtual() && MO->
isKill() &&
2950 !
MI->isBundledWithPred()) {
2953 report(
"Kill missing from LiveVariables", MO, MONum);
2957 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2961 UseIdx = LiveInts->getMBBEndIdx(
2962 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
2964 UseIdx = LiveInts->getInstructionIndex(*
MI);
2967 if (
Reg.isPhysical() && !isReserved(Reg)) {
2969 if (
MRI->isReservedRegUnit(Unit))
2971 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
2972 checkLivenessAtUse(MO, MONum, UseIdx, *LR, Unit);
2976 if (
Reg.isVirtual()) {
2978 checkLivenessAtUse(MO, MONum, UseIdx, *LI, Reg);
2982 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
2983 :
MRI->getMaxLaneMaskForVReg(Reg);
2986 if ((MOMask & SR.LaneMask).none())
2988 checkLivenessAtUse(MO, MONum, UseIdx, SR, Reg, SR.LaneMask);
2991 LiveInMask |= SR.LaneMask;
2994 if ((LiveInMask & MOMask).
none()) {
2995 report(
"No live subrange at use", MO, MONum);
2996 report_context(*LI);
2997 report_context(UseIdx);
3000 if (
MI->isPHI() && LiveInMask != MOMask) {
3001 report(
"Not all lanes of PHI source live at use", MO, MONum);
3002 report_context(*LI);
3003 report_context(UseIdx);
3010 if (!regsLive.count(Reg)) {
3011 if (
Reg.isPhysical()) {
3013 bool Bad = !isReserved(Reg);
3018 if (regsLive.count(
SubReg)) {
3030 if (!MOP.isReg() || !MOP.isImplicit())
3033 if (!MOP.getReg().isPhysical())
3036 if (MOP.getReg() != Reg &&
3038 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3045 report(
"Using an undefined physical register", MO, MONum);
3046 }
else if (
MRI->def_empty(Reg)) {
3047 report(
"Reading virtual register without a def", MO, MONum);
3049 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3053 if (MInfo.regsKilled.count(Reg))
3054 report(
"Using a killed virtual register", MO, MONum);
3055 else if (!
MI->isPHI())
3056 MInfo.vregsLiveIn.insert(std::make_pair(Reg,
MI));
3065 addRegWithSubRegs(regsDead, Reg);
3067 addRegWithSubRegs(regsDefined, Reg);
3070 if (
MRI->isSSA() &&
Reg.isVirtual() &&
3071 std::next(
MRI->def_begin(Reg)) !=
MRI->def_end())
3072 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3075 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3076 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3079 if (
Reg.isVirtual()) {
3080 checkLivenessAtDef(MO, MONum, DefIdx, *LI, Reg);
3084 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3085 :
MRI->getMaxLaneMaskForVReg(Reg);
3087 if ((SR.LaneMask & MOMask).none())
3089 checkLivenessAtDef(MO, MONum, DefIdx, SR, Reg,
true, SR.LaneMask);
3101void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3102 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3103 set_union(MInfo.regsKilled, regsKilled);
3104 set_subtract(regsLive, regsKilled); regsKilled.clear();
3106 while (!regMasks.empty()) {
3109 if (
Reg.isPhysical() &&
3111 regsDead.push_back(Reg);
3114 set_union(regsLive, regsDefined); regsDefined.clear();
3119 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3124 if (!(stop > lastIndex)) {
3125 report(
"Block ends before last instruction index",
MBB);
3126 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3142 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3144 filterAndAdd(FromRegSet, VRegsBuffer);
3149 template <
typename RegSetT>
3150 bool filterAndAdd(
const RegSetT &FromRegSet,
3152 unsigned SparseUniverse = Sparse.size();
3153 unsigned NewSparseUniverse = SparseUniverse;
3154 unsigned NewDenseSize =
Dense.size();
3155 size_t Begin = ToVRegs.
size();
3157 if (!
Reg.isVirtual())
3160 if (
Index < SparseUniverseMax) {
3161 if (
Index < SparseUniverse && Sparse.test(
Index))
3163 NewSparseUniverse = std::max(NewSparseUniverse,
Index + 1);
3178 Sparse.resize(NewSparseUniverse);
3179 Dense.reserve(NewDenseSize);
3180 for (
unsigned I = Begin;
I <
End; ++
I) {
3183 if (
Index < SparseUniverseMax)
3192 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3212class FilteringVRegSet {
3219 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3224 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3227 return Filter.filterAndAdd(RS, VRegs);
3232 size_t size()
const {
return VRegs.
size(); }
3239void MachineVerifier::calcRegsPassed() {
3246 FilteringVRegSet VRegs;
3247 BBInfo &
Info = MBBInfoMap[MB];
3250 VRegs.addToFilter(
Info.regsKilled);
3251 VRegs.addToFilter(
Info.regsLiveOut);
3253 const BBInfo &PredInfo = MBBInfoMap[Pred];
3254 if (!PredInfo.reachable)
3257 VRegs.add(PredInfo.regsLiveOut);
3258 VRegs.add(PredInfo.vregsPassed);
3260 Info.vregsPassed.reserve(VRegs.size());
3261 Info.vregsPassed.insert(VRegs.begin(), VRegs.end());
3268void MachineVerifier::calcRegsRequired() {
3271 for (
const auto &
MBB : *MF) {
3272 BBInfo &MInfo = MBBInfoMap[&
MBB];
3274 BBInfo &PInfo = MBBInfoMap[Pred];
3275 if (PInfo.addRequired(MInfo.vregsLiveIn))
3281 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3283 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3290 BBInfo &PInfo = MBBInfoMap[Pred];
3291 if (PInfo.addRequired(Reg))
3299 while (!todo.
empty()) {
3302 BBInfo &MInfo = MBBInfoMap[
MBB];
3306 BBInfo &SInfo = MBBInfoMap[Pred];
3307 if (SInfo.addRequired(MInfo.vregsRequired))
3316 BBInfo &MInfo = MBBInfoMap[&
MBB];
3326 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3331 report(
"Unexpected flag on PHI operand", &MODef, 0);
3334 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3336 for (
unsigned I = 1, E =
Phi.getNumOperands();
I != E;
I += 2) {
3339 report(
"Expected PHI operand to be a register", &MO0,
I);
3344 report(
"Unexpected flag on PHI operand", &MO0,
I);
3348 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3354 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3358 if (MInfo.reachable) {
3360 BBInfo &PrInfo = MBBInfoMap[&Pre];
3361 if (!MO0.
isUndef() && PrInfo.reachable &&
3362 !PrInfo.isLiveOut(MO0.
getReg()))
3363 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3368 if (MInfo.reachable) {
3370 if (!seen.
count(Pred)) {
3371 report(
"Missing PHI operand", &Phi);
3373 <<
" is a predecessor according to the CFG.\n";
3382 std::function<
void(
const Twine &Message)> FailureCB,
3387 for (
const auto &
MBB : MF) {
3399void MachineVerifier::visitMachineFunctionAfter() {
3400 auto FailureCB = [
this](
const Twine &Message) {
3401 report(Message.str().c_str(), MF);
3414 for (
const auto &
MBB : *MF) {
3415 BBInfo &MInfo = MBBInfoMap[&
MBB];
3416 for (
Register VReg : MInfo.vregsRequired)
3417 if (MInfo.regsKilled.count(VReg)) {
3418 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3420 <<
" is used after the block.\n";
3425 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3426 for (
Register VReg : MInfo.vregsRequired) {
3427 report(
"Virtual register defs don't dominate all uses.", MF);
3428 report_context_vreg(VReg);
3433 verifyLiveVariables();
3435 verifyLiveIntervals();
3444 if (
MRI->tracksLiveness())
3445 for (
const auto &
MBB : *MF)
3449 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3452 BBInfo &PInfo = MBBInfoMap[Pred];
3453 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3454 report(
"Live in register not found to be live out from predecessor.",
3456 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3462 for (
auto CSInfo : MF->getCallSitesInfo())
3463 if (!CSInfo.first->isCall())
3464 report(
"Call site info referencing instruction that is not call", MF);
3468 if (MF->getFunction().getSubprogram()) {
3470 for (
const auto &
MBB : *MF) {
3471 for (
const auto &
MI :
MBB) {
3472 if (
auto Num =
MI.peekDebugInstrNum()) {
3475 report(
"Instruction has a duplicated value tracking number", &
MI);
3482void MachineVerifier::verifyLiveVariables() {
3483 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3484 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3487 for (
const auto &
MBB : *MF) {
3488 BBInfo &MInfo = MBBInfoMap[&
MBB];
3491 if (MInfo.vregsRequired.count(Reg)) {
3493 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3495 <<
" must be live through the block.\n";
3499 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3501 <<
" is not needed live through the block.\n";
3508void MachineVerifier::verifyLiveIntervals() {
3509 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3510 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3514 if (
MRI->reg_nodbg_empty(Reg))
3517 if (!LiveInts->hasInterval(Reg)) {
3518 report(
"Missing live interval for virtual register", MF);
3524 assert(Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3525 verifyLiveInterval(LI);
3529 for (
unsigned i = 0, e =
TRI->getNumRegUnits(); i != e; ++i)
3530 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(i))
3531 verifyLiveRange(*LR, i);
3534void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3543 report(
"Value not live at VNInfo def and not marked unused", MF);
3544 report_context(LR, Reg, LaneMask);
3545 report_context(*VNI);
3549 if (DefVNI != VNI) {
3550 report(
"Live segment at def has different VNInfo", MF);
3551 report_context(LR, Reg, LaneMask);
3552 report_context(*VNI);
3558 report(
"Invalid VNInfo definition index", MF);
3559 report_context(LR, Reg, LaneMask);
3560 report_context(*VNI);
3565 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3566 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3567 report_context(LR, Reg, LaneMask);
3568 report_context(*VNI);
3576 report(
"No instruction at VNInfo def index",
MBB);
3577 report_context(LR, Reg, LaneMask);
3578 report_context(*VNI);
3583 bool hasDef =
false;
3584 bool isEarlyClobber =
false;
3586 if (!MOI->isReg() || !MOI->isDef())
3588 if (
Reg.isVirtual()) {
3589 if (MOI->getReg() != Reg)
3592 if (!MOI->getReg().isPhysical() || !
TRI->hasRegUnit(MOI->getReg(), Reg))
3595 if (LaneMask.
any() &&
3596 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3599 if (MOI->isEarlyClobber())
3600 isEarlyClobber =
true;
3604 report(
"Defining instruction does not modify register",
MI);
3605 report_context(LR, Reg, LaneMask);
3606 report_context(*VNI);
3611 if (isEarlyClobber) {
3613 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3614 report_context(LR, Reg, LaneMask);
3615 report_context(*VNI);
3618 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3619 report_context(LR, Reg, LaneMask);
3620 report_context(*VNI);
3625void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3631 assert(VNI &&
"Live segment has no valno");
3634 report(
"Foreign valno in live segment", MF);
3635 report_context(LR, Reg, LaneMask);
3637 report_context(*VNI);
3641 report(
"Live segment valno is marked unused", MF);
3642 report_context(LR, Reg, LaneMask);
3648 report(
"Bad start of live segment, no basic block", MF);
3649 report_context(LR, Reg, LaneMask);
3655 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3656 report_context(LR, Reg, LaneMask);
3663 report(
"Bad end of live segment, no basic block", MF);
3664 report_context(LR, Reg, LaneMask);
3670 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3680 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3681 report_context(LR, Reg, LaneMask);
3688 report(
"Live segment ends at B slot of an instruction", EndMBB);
3689 report_context(LR, Reg, LaneMask);
3697 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3698 report_context(LR, Reg, LaneMask);
3707 if (MF->getProperties().hasProperty(
3710 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3711 report(
"Live segment ending at early clobber slot must be "
3712 "redefined by an EC def in the same instruction",
3714 report_context(LR, Reg, LaneMask);
3721 if (
Reg.isVirtual()) {
3724 bool hasRead =
false;
3725 bool hasSubRegDef =
false;
3726 bool hasDeadDef =
false;
3728 if (!MOI->isReg() || MOI->getReg() != Reg)
3730 unsigned Sub = MOI->getSubReg();
3735 hasSubRegDef =
true;
3744 if (LaneMask.
any() && (LaneMask & SLM).none())
3746 if (MOI->readsReg())
3753 if (LaneMask.
none() && !hasDeadDef) {
3755 "Instruction ending live segment on dead slot has no dead flag",
3757 report_context(LR, Reg, LaneMask);
3764 if (!
MRI->shouldTrackSubRegLiveness(Reg) || LaneMask.
any() ||
3766 report(
"Instruction ending live segment doesn't read the register",
3768 report_context(LR, Reg, LaneMask);
3788 if (LaneMask.
any()) {
3794 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3796 if (!
Reg.isVirtual() && MFI->isEHPad()) {
3797 if (&*MFI == EndMBB)
3805 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3809 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3811 if (MFI->isEHPad()) {
3814 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3825 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3828 report(
"Register not marked live out of predecessor", Pred);
3829 report_context(LR, Reg, LaneMask);
3830 report_context(*VNI);
3832 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3838 if (!IsPHI && PVNI != VNI) {
3839 report(
"Different value live out of predecessor", Pred);
3840 report_context(LR, Reg, LaneMask);
3841 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3844 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3847 if (&*MFI == EndMBB)
3856 verifyLiveRangeValue(LR, VNI, Reg, LaneMask);
3859 verifyLiveRangeSegment(LR,
I, Reg, LaneMask);
3862void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3865 verifyLiveRange(LI, Reg);
3871 if ((Mask & SR.LaneMask).any()) {
3872 report(
"Lane masks of sub ranges overlap in live interval", MF);
3875 if ((SR.LaneMask & ~MaxMask).any()) {
3876 report(
"Subrange lanemask is invalid", MF);
3880 report(
"Subrange must not be empty", MF);
3881 report_context(SR, LI.
reg(), SR.LaneMask);
3883 Mask |= SR.LaneMask;
3884 verifyLiveRange(SR, LI.
reg(), SR.LaneMask);
3886 report(
"A Subrange is not covered by the main range", MF);
3894 unsigned NumComp = ConEQ.Classify(LI);
3896 report(
"Multiple connected components in live interval", MF);
3898 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3899 OS << comp <<
": valnos";
3901 if (comp == ConEQ.getEqClass(
I))
3914struct StackStateOfBB {
3915 StackStateOfBB() =
default;
3916 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
3917 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
3918 ExitIsSetup(ExitSetup) {}
3923 bool EntryIsSetup =
false;
3924 bool ExitIsSetup =
false;
3932void MachineVerifier::verifyStackFrame() {
3933 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
3934 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
3935 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
3939 SPState.
resize(MF->getNumBlockIDs());
3946 DFI != DFE; ++DFI) {
3949 StackStateOfBB BBState;
3951 if (DFI.getPathLength() >= 2) {
3954 "DFS stack predecessor is already visited.\n");
3955 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
3956 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
3957 BBState.ExitValue = BBState.EntryValue;
3958 BBState.ExitIsSetup = BBState.EntryIsSetup;
3962 report(
"Call frame size on entry does not match value computed from "
3966 <<
" does not match value computed from predecessor "
3967 << -BBState.EntryValue <<
'\n';
3971 for (
const auto &
I : *
MBB) {
3972 if (
I.getOpcode() == FrameSetupOpcode) {
3973 if (BBState.ExitIsSetup)
3974 report(
"FrameSetup is after another FrameSetup", &
I);
3975 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3976 report(
"AdjustsStack not set in presence of a frame pseudo "
3977 "instruction.", &
I);
3978 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
3979 BBState.ExitIsSetup =
true;
3982 if (
I.getOpcode() == FrameDestroyOpcode) {
3983 int Size =
TII->getFrameTotalSize(
I);
3984 if (!BBState.ExitIsSetup)
3985 report(
"FrameDestroy is not after a FrameSetup", &
I);
3986 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
3988 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
3989 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
3990 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
3991 << AbsSPAdj <<
">.\n";
3993 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3994 report(
"AdjustsStack not set in presence of a frame pseudo "
3995 "instruction.", &
I);
3996 BBState.ExitValue +=
Size;
3997 BBState.ExitIsSetup =
false;
4005 if (Reachable.
count(Pred) &&
4006 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4007 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4008 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4010 << SPState[Pred->
getNumber()].ExitValue <<
", "
4011 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4013 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4020 if (Reachable.
count(Succ) &&
4021 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4022 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4023 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4025 << SPState[Succ->getNumber()].EntryValue <<
", "
4026 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4028 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4034 if (BBState.ExitIsSetup)
4035 report(
"A return block ends with a FrameSetup.",
MBB);
4036 if (BBState.ExitValue)
4037 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
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.
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
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.
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, Style style=Style::native)
Get begin iterator over path.
const_iterator end(StringRef path)
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.