96 struct MachineVerifier {
98 : MFAM(&MFAM), Banner(
b) {}
100 MachineVerifier(
Pass *
pass,
const char *b) : PASS(
pass), Banner(
b) {}
105 : Banner(
b), LiveVars(LiveVars), LiveInts(LiveInts), LiveStks(LiveStks),
111 Pass *
const PASS =
nullptr;
120 unsigned foundErrors = 0;
123 bool isFunctionRegBankSelected =
false;
124 bool isFunctionSelected =
false;
125 bool isFunctionTracksDebugUserValues =
false;
135 BlockSet FunctionBlocks;
139 RegVector regsDefined, regsDead, regsKilled;
140 RegMaskVector regMasks;
145 void addRegWithSubRegs(RegVector &RV,
Register Reg) {
147 if (
Reg.isPhysical())
153 bool reachable =
false;
174 RegSet vregsRequired;
177 BlockSet Preds, Succs;
184 if (!
Reg.isVirtual())
186 if (regsLiveOut.count(Reg))
188 return vregsRequired.insert(Reg).second;
192 bool addRequired(
const RegSet &RS) {
193 bool Changed =
false;
195 Changed |= addRequired(Reg);
200 bool addRequired(
const RegMap &RM) {
201 bool Changed =
false;
202 for (
const auto &
I : RM)
203 Changed |= addRequired(
I.first);
209 return regsLiveOut.count(Reg) || vregsPassed.count(Reg);
217 return Reg.id() < regsReserved.
size() && regsReserved.
test(
Reg.id());
220 bool isAllocatable(
Register Reg)
const {
221 return Reg.id() <
TRI->getNumRegs() &&
TRI->isInAllocatableClass(Reg) &&
236 void visitMachineFunctionBefore();
252 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
255 void visitMachineFunctionAfter();
260 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
268 void report_context(
const VNInfo &VNI)
const;
269 void report_context(
SlotIndex Pos)
const;
270 void report_context(
MCPhysReg PhysReg)
const;
271 void report_context_liverange(
const LiveRange &LR)
const;
272 void report_context_lanemask(
LaneBitmask LaneMask)
const;
273 void report_context_vreg(
Register VReg)
const;
274 void report_context_vreg_regunit(
Register VRegOrUnit)
const;
285 Register VRegOrUnit,
bool SubRangeCheck =
false,
289 void calcRegsPassed();
292 void calcRegsRequired();
293 void verifyLiveVariables();
294 void verifyLiveIntervals();
298 void verifyLiveRangeSegment(
const LiveRange &,
304 void verifyStackFrame();
306 void verifySlotIndexes()
const;
313 const std::string Banner;
315 MachineVerifierLegacyPass(std::string banner = std::string())
334 MachineFunctionProperties::Property::FailsVerification))
337 unsigned FoundErrors = MachineVerifier(
this, Banner.c_str()).verify(MF);
355 unsigned FoundErrors = MachineVerifier(MFAM, Banner.c_str()).verify(MF);
361char MachineVerifierLegacyPass::ID = 0;
364 "Verify generated machine code",
false,
false)
367 return new MachineVerifierLegacyPass(Banner);
377 unsigned FoundErrors = MachineVerifier(
nullptr, Banner.c_str()).verify(MF);
385 unsigned FoundErrors = MachineVerifier(p, Banner).verify(MF);
386 if (AbortOnErrors && FoundErrors)
388 return FoundErrors == 0;
392 const char *Banner,
bool AbortOnErrors)
const {
394 unsigned FoundErrors =
395 MachineVerifier(Banner,
nullptr, LiveInts,
nullptr, Indexes).verify(MF);
396 if (AbortOnErrors && FoundErrors)
398 return FoundErrors == 0;
401void MachineVerifier::verifySlotIndexes()
const {
402 if (Indexes ==
nullptr)
420 MRI->getNumVirtRegs())
421 report(
"Function has NoVRegs property but there are VReg operands", &MF);
440 if (isFunctionFailedISel)
452 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
456 LiveVars = LVWrapper ? &LVWrapper->getLV() :
nullptr;
459 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
472 verifyProperties(MF);
474 visitMachineFunctionBefore();
476 visitMachineBasicBlockBefore(&
MBB);
480 bool InBundle =
false;
483 if (
MI.getParent() != &
MBB) {
484 report(
"Bad instruction parent pointer", &
MBB);
485 errs() <<
"Instruction: " <<
MI;
490 if (InBundle && !
MI.isBundledWithPred())
491 report(
"Missing BundledPred flag, "
492 "BundledSucc was set on predecessor",
494 if (!InBundle &&
MI.isBundledWithPred())
495 report(
"BundledPred flag is set, "
496 "but BundledSucc not set on predecessor",
500 if (!
MI.isInsideBundle()) {
502 visitMachineBundleAfter(CurBundle);
504 visitMachineBundleBefore(CurBundle);
505 }
else if (!CurBundle)
506 report(
"No bundle header", &
MI);
507 visitMachineInstrBefore(&
MI);
508 for (
unsigned I = 0, E =
MI.getNumOperands();
I != E; ++
I) {
510 if (
Op.getParent() != &
MI) {
513 report(
"Instruction has operand with wrong parent set", &
MI);
516 visitMachineOperand(&
Op,
I);
520 InBundle =
MI.isBundledWithSucc();
523 visitMachineBundleAfter(CurBundle);
525 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
526 visitMachineBasicBlockAfter(&
MBB);
528 visitMachineFunctionAfter();
541void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
544 if (!foundErrors++) {
546 errs() <<
"# " << Banner <<
'\n';
547 if (LiveInts !=
nullptr)
552 errs() <<
"*** Bad machine code: " << msg <<
" ***\n"
553 <<
"- function: " << MF->
getName() <<
"\n";
562 errs() <<
" [" << Indexes->getMBBStartIdx(
MBB)
563 <<
';' << Indexes->getMBBEndIdx(
MBB) <<
')';
567void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
569 report(msg,
MI->getParent());
570 errs() <<
"- instruction: ";
571 if (Indexes && Indexes->hasIndex(*
MI))
572 errs() << Indexes->getInstructionIndex(*
MI) <<
'\t';
576void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
577 unsigned MONum,
LLT MOVRegType) {
580 errs() <<
"- operand " << MONum <<
": ";
586 report(Msg.
str().c_str(),
MI);
589void MachineVerifier::report_context(
SlotIndex Pos)
const {
590 errs() <<
"- at: " << Pos <<
'\n';
593void MachineVerifier::report_context(
const LiveInterval &LI)
const {
594 errs() <<
"- interval: " << LI <<
'\n';
599 report_context_liverange(LR);
600 report_context_vreg_regunit(VRegUnit);
602 report_context_lanemask(LaneMask);
606 errs() <<
"- segment: " << S <<
'\n';
609void MachineVerifier::report_context(
const VNInfo &VNI)
const {
610 errs() <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
613void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
614 errs() <<
"- liverange: " << LR <<
'\n';
617void MachineVerifier::report_context(
MCPhysReg PReg)
const {
621void MachineVerifier::report_context_vreg(
Register VReg)
const {
625void MachineVerifier::report_context_vreg_regunit(
Register VRegOrUnit)
const {
627 report_context_vreg(VRegOrUnit);
633void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
638 BBInfo &MInfo = MBBInfoMap[
MBB];
639 if (!MInfo.reachable) {
640 MInfo.reachable =
true;
646void MachineVerifier::visitMachineFunctionBefore() {
648 regsReserved =
MRI->reservedRegsFrozen() ?
MRI->getReservedRegs()
649 :
TRI->getReservedRegs(*MF);
652 markReachable(&MF->
front());
655 FunctionBlocks.clear();
656 for (
const auto &
MBB : *MF) {
657 FunctionBlocks.insert(&
MBB);
658 BBInfo &MInfo = MBBInfoMap[&
MBB];
662 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
666 report(
"MBB has duplicate entries in its successor list.", &
MBB);
670 MRI->verifyUseLists();
678 FirstTerminator =
nullptr;
679 FirstNonPHI =
nullptr;
681 if (!MF->getProperties().hasProperty(
686 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
689 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
690 "inlineasm-br-indirect-target.",
692 report_context(LI.PhysReg);
699 report(
"ir-block-address-taken is associated with basic block not used by "
708 LandingPadSuccs.
insert(succ);
709 if (!FunctionBlocks.count(succ))
710 report(
"MBB has successor that isn't part of the function.",
MBB);
711 if (!MBBInfoMap[succ].Preds.count(
MBB)) {
712 report(
"Inconsistent CFG",
MBB);
713 errs() <<
"MBB is not in the predecessor list of the successor "
720 if (!FunctionBlocks.count(Pred))
721 report(
"MBB has predecessor that isn't part of the function.",
MBB);
722 if (!MBBInfoMap[Pred].Succs.count(
MBB)) {
723 report(
"Inconsistent CFG",
MBB);
724 errs() <<
"MBB is not in the successor list of the predecessor "
732 if (LandingPadSuccs.
size() > 1 &&
737 report(
"MBB has more than one landing pad successor",
MBB);
750 report(
"MBB exits via unconditional fall-through but ends with a "
751 "barrier instruction!",
MBB);
754 report(
"MBB exits via unconditional fall-through but has a condition!",
757 }
else if (
TBB && !FBB &&
Cond.empty()) {
760 report(
"MBB exits via unconditional branch but doesn't contain "
761 "any instructions!",
MBB);
763 report(
"MBB exits via unconditional branch but doesn't end with a "
764 "barrier instruction!",
MBB);
766 report(
"MBB exits via unconditional branch but the branch isn't a "
767 "terminator instruction!",
MBB);
769 }
else if (
TBB && !FBB && !
Cond.empty()) {
772 report(
"MBB exits via conditional branch/fall-through but doesn't "
773 "contain any instructions!",
MBB);
775 report(
"MBB exits via conditional branch/fall-through but ends with a "
776 "barrier instruction!",
MBB);
778 report(
"MBB exits via conditional branch/fall-through but the branch "
779 "isn't a terminator instruction!",
MBB);
781 }
else if (
TBB && FBB) {
785 report(
"MBB exits via conditional branch/branch but doesn't "
786 "contain any instructions!",
MBB);
788 report(
"MBB exits via conditional branch/branch but doesn't end with a "
789 "barrier instruction!",
MBB);
791 report(
"MBB exits via conditional branch/branch but the branch "
792 "isn't a terminator instruction!",
MBB);
795 report(
"MBB exits via conditional branch/branch but there's no "
799 report(
"analyzeBranch returned invalid data!",
MBB);
805 report(
"MBB exits via jump or conditional branch, but its target isn't a "
809 report(
"MBB exits via conditional branch, but its target isn't a CFG "
816 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
821 if (!
Cond.empty() && !FBB) {
824 report(
"MBB conditionally falls through out of function!",
MBB);
826 report(
"MBB exits via conditional branch/fall-through but the CFG "
827 "successors don't match the actual successors!",
834 if (SuccMBB ==
TBB || SuccMBB == FBB)
842 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
844 report(
"MBB has unexpected successors which are not branch targets, "
845 "fallthrough, EHPads, or inlineasm_br targets.",
851 if (
MRI->tracksLiveness()) {
854 report(
"MBB live-in list contains non-physical register",
MBB);
873 lastIndex = Indexes->getMBBStartIdx(
MBB);
878void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
879 if (Indexes && Indexes->hasIndex(*
MI)) {
881 if (!(idx > lastIndex)) {
882 report(
"Instruction index out of order",
MI);
883 errs() <<
"Last instruction was at " << lastIndex <<
'\n';
889 if (
MI->isTerminator()) {
890 if (!FirstTerminator)
891 FirstTerminator =
MI;
892 }
else if (FirstTerminator) {
895 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
896 report(
"Non-terminator instruction after the first terminator",
MI);
897 errs() <<
"First terminator was:\t" << *FirstTerminator;
906 if (
MI->getNumOperands() < 2) {
907 report(
"Too few operands on inline asm",
MI);
910 if (!
MI->getOperand(0).isSymbol())
911 report(
"Asm string must be an external symbol",
MI);
912 if (!
MI->getOperand(1).isImm())
913 report(
"Asm flags must be an immediate",
MI);
917 if (!isUInt<6>(
MI->getOperand(1).getImm()))
918 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
924 for (
unsigned e =
MI->getNumOperands(); OpNo <
e; OpNo += NumOps) {
930 NumOps = 1 +
F.getNumOperandRegisters();
933 if (OpNo >
MI->getNumOperands())
934 report(
"Missing operands in last group",
MI);
937 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
941 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
944 report(
"Expected implicit register after groups", &MO, OpNo);
947 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
960 if (!IndirectTargetMBB) {
961 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
966 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
970 report(
"INLINEASM_BR indirect target predecessor list missing parent",
976bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
981 const auto Reg = Op.getReg();
982 if (Reg.isPhysical())
984 return !MRI.getType(Reg).isScalar();
987 report(
"All register operands must have scalar types", &
MI);
994bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
997 report(
"operand types must be all-vector or all-scalar",
MI);
1007 report(
"operand types must preserve number of vector elements",
MI);
1014bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1015 auto Opcode =
MI->getOpcode();
1016 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1017 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1018 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1019 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1021 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1022 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1023 if (NoSideEffects && DeclHasSideEffects) {
1025 " used with intrinsic that accesses memory"),
1029 if (!NoSideEffects && !DeclHasSideEffects) {
1030 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1038bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1039 auto Opcode =
MI->getOpcode();
1040 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1041 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1042 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1043 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1045 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1046 bool DeclIsConvergent =
Attrs.hasFnAttr(Attribute::Convergent);
1047 if (NotConvergent && DeclIsConvergent) {
1048 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1052 if (!NotConvergent && !DeclIsConvergent) {
1054 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1063void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1064 if (isFunctionSelected)
1065 report(
"Unexpected generic instruction in a Selected function",
MI);
1068 unsigned NumOps =
MI->getNumOperands();
1071 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1072 bool HasMBB =
false;
1081 report(
"Branch instruction is missing a basic block operand or "
1082 "isIndirectBranch property",
1091 if (!MCID.
operands()[
I].isGenericType())
1095 size_t TypeIdx = MCID.
operands()[
I].getGenericTypeIndex();
1096 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1100 report(
"generic instruction must use register operands",
MI);
1110 if (!Types[TypeIdx].
isValid())
1111 Types[TypeIdx] = OpTy;
1112 else if (Types[TypeIdx] != OpTy)
1113 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1116 report(
"Generic instruction is missing a virtual register type", MO,
I);
1121 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1124 report(
"Generic instruction cannot have physical register", MO,
I);
1136 unsigned Opc =
MI->getOpcode();
1138 case TargetOpcode::G_ASSERT_SEXT:
1139 case TargetOpcode::G_ASSERT_ZEXT: {
1140 std::string OpcName =
1141 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1142 if (!
MI->getOperand(2).isImm()) {
1143 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1149 LLT SrcTy =
MRI->getType(Src);
1150 int64_t
Imm =
MI->getOperand(2).getImm();
1152 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1157 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1165 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1166 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1172 if (DstRC && DstRC !=
MRI->getRegClassOrNull(Src)) {
1174 Twine(OpcName,
" source and destination register classes must match"),
1182 case TargetOpcode::G_CONSTANT:
1183 case TargetOpcode::G_FCONSTANT: {
1184 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1186 report(
"Instruction cannot use a vector result type",
MI);
1188 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1189 if (!
MI->getOperand(1).isCImm()) {
1190 report(
"G_CONSTANT operand must be cimm",
MI);
1196 report(
"inconsistent constant size",
MI);
1198 if (!
MI->getOperand(1).isFPImm()) {
1199 report(
"G_FCONSTANT operand must be fpimm",
MI);
1206 report(
"inconsistent constant size",
MI);
1212 case TargetOpcode::G_LOAD:
1213 case TargetOpcode::G_STORE:
1214 case TargetOpcode::G_ZEXTLOAD:
1215 case TargetOpcode::G_SEXTLOAD: {
1216 LLT ValTy =
MRI->getType(
MI->getOperand(0).getReg());
1217 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1219 report(
"Generic memory instruction must access a pointer",
MI);
1223 if (!
MI->hasOneMemOperand()) {
1224 report(
"Generic instruction accessing memory must have one mem operand",
1228 if (
MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
1229 MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
1232 report(
"Generic extload must have a narrower memory type",
MI);
1233 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1236 report(
"load memory size cannot exceed result size",
MI);
1237 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1240 report(
"store memory size cannot exceed value size",
MI);
1244 if (Opc == TargetOpcode::G_STORE) {
1247 report(
"atomic store cannot use acquire ordering",
MI);
1252 report(
"atomic load cannot use release ordering",
MI);
1258 case TargetOpcode::G_PHI: {
1259 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1264 LLT Ty = MRI->getType(MO.getReg());
1265 if (!Ty.isValid() || (Ty != DstTy))
1269 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1274 case TargetOpcode::G_BITCAST: {
1275 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1276 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1281 report(
"bitcast cannot convert between pointers and other types",
MI);
1284 report(
"bitcast sizes must match",
MI);
1287 report(
"bitcast must change the type",
MI);
1291 case TargetOpcode::G_INTTOPTR:
1292 case TargetOpcode::G_PTRTOINT:
1293 case TargetOpcode::G_ADDRSPACE_CAST: {
1294 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1295 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1299 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1304 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1306 report(
"inttoptr result type must be a pointer",
MI);
1308 report(
"inttoptr source type must not be a pointer",
MI);
1309 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1311 report(
"ptrtoint source type must be a pointer",
MI);
1313 report(
"ptrtoint result type must not be a pointer",
MI);
1315 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1317 report(
"addrspacecast types must be pointers",
MI);
1320 report(
"addrspacecast must convert different address spaces",
MI);
1326 case TargetOpcode::G_PTR_ADD: {
1327 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1328 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1329 LLT OffsetTy =
MRI->getType(
MI->getOperand(2).getReg());
1334 report(
"gep first operand must be a pointer",
MI);
1337 report(
"gep offset operand must not be a pointer",
MI);
1342 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1344 report(
"gep offset operand must match index size for address space",
1352 case TargetOpcode::G_PTRMASK: {
1353 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1354 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1355 LLT MaskTy =
MRI->getType(
MI->getOperand(2).getReg());
1360 report(
"ptrmask result type must be a pointer",
MI);
1363 report(
"ptrmask mask type must be an integer",
MI);
1365 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1368 case TargetOpcode::G_SEXT:
1369 case TargetOpcode::G_ZEXT:
1370 case TargetOpcode::G_ANYEXT:
1371 case TargetOpcode::G_TRUNC:
1372 case TargetOpcode::G_FPEXT:
1373 case TargetOpcode::G_FPTRUNC: {
1380 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1381 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1386 report(
"Generic extend/truncate can not operate on pointers",
MI);
1388 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1392 switch (
MI->getOpcode()) {
1394 if (DstSize <= SrcSize)
1395 report(
"Generic extend has destination type no larger than source",
MI);
1397 case TargetOpcode::G_TRUNC:
1398 case TargetOpcode::G_FPTRUNC:
1399 if (DstSize >= SrcSize)
1400 report(
"Generic truncate has destination type no smaller than source",
1406 case TargetOpcode::G_SELECT: {
1407 LLT SelTy =
MRI->getType(
MI->getOperand(0).getReg());
1408 LLT CondTy =
MRI->getType(
MI->getOperand(1).getReg());
1414 verifyVectorElementMatch(SelTy, CondTy,
MI);
1417 case TargetOpcode::G_MERGE_VALUES: {
1422 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1423 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1425 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1427 const unsigned NumOps =
MI->getNumOperands();
1429 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1431 for (
unsigned I = 2;
I != NumOps; ++
I) {
1432 if (
MRI->getType(
MI->getOperand(
I).getReg()) != SrcTy)
1433 report(
"G_MERGE_VALUES source types do not match",
MI);
1438 case TargetOpcode::G_UNMERGE_VALUES: {
1439 unsigned NumDsts =
MI->getNumOperands() - 1;
1440 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1441 for (
unsigned i = 1; i < NumDsts; ++i) {
1442 if (
MRI->getType(
MI->getOperand(i).getReg()) != DstTy) {
1443 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1448 LLT SrcTy =
MRI->getType(
MI->getOperand(NumDsts).getReg());
1454 report(
"G_UNMERGE_VALUES source operand does not match vector "
1455 "destination operands",
1462 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1463 "destination operands",
1468 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1469 "destination operands",
1475 case TargetOpcode::G_BUILD_VECTOR: {
1478 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1479 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1481 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1486 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1489 report(
"G_BUILD_VECTOR must have an operand for each elemement",
MI);
1492 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1493 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1497 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1500 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1501 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1503 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1506 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1507 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1510 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1515 case TargetOpcode::G_CONCAT_VECTORS: {
1518 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1519 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1521 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1524 if (
MI->getNumOperands() < 3)
1525 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1528 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1529 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1532 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1535 case TargetOpcode::G_ICMP:
1536 case TargetOpcode::G_FCMP: {
1537 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1538 LLT SrcTy =
MRI->getType(
MI->getOperand(2).getReg());
1543 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1547 case TargetOpcode::G_SCMP:
1548 case TargetOpcode::G_UCMP: {
1549 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1550 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1551 LLT SrcTy2 =
MRI->getType(
MI->getOperand(2).getReg());
1554 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1559 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1566 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1570 if (SrcTy != SrcTy2) {
1571 report(
"Generic scmp/ucmp must have same input types",
MI);
1577 case TargetOpcode::G_EXTRACT: {
1579 if (!
SrcOp.isReg()) {
1580 report(
"extract source must be a register",
MI);
1585 if (!OffsetOp.
isImm()) {
1586 report(
"extract offset must be a constant",
MI);
1590 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1592 if (SrcSize == DstSize)
1593 report(
"extract source must be larger than result",
MI);
1595 if (DstSize + OffsetOp.
getImm() > SrcSize)
1596 report(
"extract reads past end of register",
MI);
1599 case TargetOpcode::G_INSERT: {
1601 if (!
SrcOp.isReg()) {
1602 report(
"insert source must be a register",
MI);
1607 if (!OffsetOp.
isImm()) {
1608 report(
"insert offset must be a constant",
MI);
1612 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1615 if (DstSize <= SrcSize)
1616 report(
"inserted size must be smaller than total register",
MI);
1618 if (SrcSize + OffsetOp.
getImm() > DstSize)
1619 report(
"insert writes past end of register",
MI);
1623 case TargetOpcode::G_JUMP_TABLE: {
1624 if (!
MI->getOperand(1).isJTI())
1625 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1626 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1628 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1631 case TargetOpcode::G_BRJT: {
1632 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
1633 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1635 if (!
MI->getOperand(1).isJTI())
1636 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1638 const auto &IdxOp =
MI->getOperand(2);
1639 if (!IdxOp.isReg() ||
MRI->getType(IdxOp.getReg()).isPointer())
1640 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1643 case TargetOpcode::G_INTRINSIC:
1644 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1645 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1646 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1651 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1655 if (!verifyGIntrinsicSideEffects(
MI))
1657 if (!verifyGIntrinsicConvergence(
MI))
1662 case TargetOpcode::G_SEXT_INREG: {
1663 if (!
MI->getOperand(2).isImm()) {
1664 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1668 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1669 int64_t
Imm =
MI->getOperand(2).getImm();
1671 report(
"G_SEXT_INREG size must be >= 1",
MI);
1673 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1676 case TargetOpcode::G_BSWAP: {
1677 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1679 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1682 case TargetOpcode::G_VSCALE: {
1683 if (!
MI->getOperand(1).isCImm()) {
1684 report(
"G_VSCALE operand must be cimm",
MI);
1687 if (
MI->getOperand(1).getCImm()->isZero()) {
1688 report(
"G_VSCALE immediate cannot be zero",
MI);
1693 case TargetOpcode::G_INSERT_SUBVECTOR: {
1695 if (!Src0Op.
isReg()) {
1696 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1701 if (!Src1Op.
isReg()) {
1702 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1707 if (!IndexOp.
isImm()) {
1708 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1712 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1717 report(
"Destination type must be a vector",
MI);
1722 report(
"First source must be a vector",
MI);
1727 report(
"Second source must be a vector",
MI);
1731 if (DstTy != Src0Ty) {
1732 report(
"Destination type must match the first source vector type",
MI);
1737 report(
"Element type of source vectors must be the same",
MI);
1741 if (IndexOp.
getImm() != 0 &&
1743 report(
"Index must be a multiple of the second source vector's "
1744 "minimum vector length",
1750 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1752 if (!
SrcOp.isReg()) {
1753 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1758 if (!IndexOp.
isImm()) {
1759 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1763 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1767 report(
"Destination type must be a vector",
MI);
1772 report(
"First source must be a vector",
MI);
1777 report(
"Element type of vectors must be the same",
MI);
1781 if (IndexOp.
getImm() != 0 &&
1783 report(
"Index must be a multiple of the source vector's minimum vector "
1791 case TargetOpcode::G_SHUFFLE_VECTOR: {
1794 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1798 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1799 LLT Src0Ty =
MRI->getType(
MI->getOperand(1).getReg());
1800 LLT Src1Ty =
MRI->getType(
MI->getOperand(2).getReg());
1802 if (Src0Ty != Src1Ty)
1803 report(
"Source operands must be the same type",
MI);
1806 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1815 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1816 report(
"Wrong result type for shufflemask",
MI);
1818 for (
int Idx : MaskIdxes) {
1822 if (
Idx >= 2 * SrcNumElts)
1823 report(
"Out of bounds shuffle index",
MI);
1829 case TargetOpcode::G_SPLAT_VECTOR: {
1830 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1831 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1834 report(
"Destination type must be a scalable vector",
MI);
1839 report(
"Source type must be a scalar",
MI);
1845 report(
"Element type of the destination must be the same size or smaller "
1846 "than the source type",
1853 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1854 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1855 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1856 LLT IdxTy =
MRI->getType(
MI->getOperand(2).getReg());
1859 report(
"Destination type must be a scalar or pointer",
MI);
1864 report(
"First source must be a vector",
MI);
1868 auto TLI = MF->getSubtarget().getTargetLowering();
1870 TLI->getVectorIdxTy(MF->getDataLayout()).getFixedSizeInBits()) {
1871 report(
"Index type must match VectorIdxTy",
MI);
1877 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1878 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1879 LLT VecTy =
MRI->getType(
MI->getOperand(1).getReg());
1880 LLT ScaTy =
MRI->getType(
MI->getOperand(2).getReg());
1881 LLT IdxTy =
MRI->getType(
MI->getOperand(3).getReg());
1884 report(
"Destination type must be a vector",
MI);
1888 if (VecTy != DstTy) {
1889 report(
"Destination type and vector type must match",
MI);
1894 report(
"Inserted element must be a scalar or pointer",
MI);
1898 auto TLI = MF->getSubtarget().getTargetLowering();
1900 TLI->getVectorIdxTy(MF->getDataLayout()).getFixedSizeInBits()) {
1901 report(
"Index type must match VectorIdxTy",
MI);
1907 case TargetOpcode::G_DYN_STACKALLOC: {
1913 report(
"dst operand 0 must be a pointer type",
MI);
1917 if (!AllocOp.
isReg() || !
MRI->getType(AllocOp.
getReg()).isScalar()) {
1918 report(
"src operand 1 must be a scalar reg type",
MI);
1922 if (!AlignOp.
isImm()) {
1923 report(
"src operand 2 must be an immediate type",
MI);
1928 case TargetOpcode::G_MEMCPY_INLINE:
1929 case TargetOpcode::G_MEMCPY:
1930 case TargetOpcode::G_MEMMOVE: {
1932 if (MMOs.
size() != 2) {
1933 report(
"memcpy/memmove must have 2 memory operands",
MI);
1939 report(
"wrong memory operand types",
MI);
1944 report(
"inconsistent memory operand sizes",
MI);
1946 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
1947 LLT SrcPtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1950 report(
"memory instruction operand must be a pointer",
MI);
1955 report(
"inconsistent store address space",
MI);
1957 report(
"inconsistent load address space",
MI);
1959 if (Opc != TargetOpcode::G_MEMCPY_INLINE)
1960 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
1961 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
1965 case TargetOpcode::G_BZERO:
1966 case TargetOpcode::G_MEMSET: {
1968 std::string
Name = Opc == TargetOpcode::G_MEMSET ?
"memset" :
"bzero";
1969 if (MMOs.
size() != 1) {
1970 report(
Twine(
Name,
" must have 1 memory operand"),
MI);
1975 report(
Twine(
Name,
" memory operand must be a store"),
MI);
1979 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
1981 report(
Twine(
Name,
" operand must be a pointer"),
MI);
1986 report(
"inconsistent " +
Twine(
Name,
" address space"),
MI);
1988 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
1989 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
1990 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
1994 case TargetOpcode::G_UBSANTRAP: {
1996 if (!
MI->getOperand(0).isImm()) {
1997 report(
"Crash kind must be an immediate", &KindOp, 0);
2000 int64_t
Kind =
MI->getOperand(0).getImm();
2001 if (!isInt<8>(Kind))
2002 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2005 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2006 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2007 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2008 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2009 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2011 report(
"Vector reduction requires a scalar destination type",
MI);
2013 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2015 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2018 case TargetOpcode::G_VECREDUCE_FADD:
2019 case TargetOpcode::G_VECREDUCE_FMUL:
2020 case TargetOpcode::G_VECREDUCE_FMAX:
2021 case TargetOpcode::G_VECREDUCE_FMIN:
2022 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2023 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2024 case TargetOpcode::G_VECREDUCE_ADD:
2025 case TargetOpcode::G_VECREDUCE_MUL:
2026 case TargetOpcode::G_VECREDUCE_AND:
2027 case TargetOpcode::G_VECREDUCE_OR:
2028 case TargetOpcode::G_VECREDUCE_XOR:
2029 case TargetOpcode::G_VECREDUCE_SMAX:
2030 case TargetOpcode::G_VECREDUCE_SMIN:
2031 case TargetOpcode::G_VECREDUCE_UMAX:
2032 case TargetOpcode::G_VECREDUCE_UMIN: {
2033 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2035 report(
"Vector reduction requires a scalar destination type",
MI);
2039 case TargetOpcode::G_SBFX:
2040 case TargetOpcode::G_UBFX: {
2041 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2043 report(
"Bitfield extraction is not supported on vectors",
MI);
2048 case TargetOpcode::G_SHL:
2049 case TargetOpcode::G_LSHR:
2050 case TargetOpcode::G_ASHR:
2051 case TargetOpcode::G_ROTR:
2052 case TargetOpcode::G_ROTL: {
2053 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2054 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2056 report(
"Shifts and rotates require operands to be either all scalars or "
2063 case TargetOpcode::G_LLROUND:
2064 case TargetOpcode::G_LROUND: {
2065 verifyAllRegOpsScalar(*
MI, *
MRI);
2068 case TargetOpcode::G_IS_FPCLASS: {
2069 LLT DestTy =
MRI->getType(
MI->getOperand(0).getReg());
2072 report(
"Destination must be a scalar or vector of scalars",
MI);
2075 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2078 report(
"Source must be a scalar or vector of scalars",
MI);
2081 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2084 if (!TestMO.
isImm()) {
2085 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2090 report(
"Incorrect floating-point class set (operand 2)",
MI);
2095 case TargetOpcode::G_PREFETCH: {
2097 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer()) {
2098 report(
"addr operand must be a pointer", &AddrOp, 0);
2103 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2108 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2113 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2118 case TargetOpcode::G_ASSERT_ALIGN: {
2119 if (
MI->getOperand(2).getImm() < 1)
2120 report(
"alignment immediate must be >= 1",
MI);
2123 case TargetOpcode::G_CONSTANT_POOL: {
2124 if (!
MI->getOperand(1).isCPI())
2125 report(
"Src operand 1 must be a constant pool index",
MI);
2126 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
2127 report(
"Dst operand 0 must be a pointer",
MI);
2130 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2132 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer())
2133 report(
"addr operand must be a pointer", &AddrOp, 1);
2141void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2144 report(
"Too few operands",
MI);
2146 <<
MI->getNumOperands() <<
" given.\n";
2150 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2153 if (MF->getProperties().hasProperty(
2155 report(
"Found PHI instruction with NoPHIs property set",
MI);
2158 report(
"Found PHI instruction after non-PHI",
MI);
2159 }
else if (FirstNonPHI ==
nullptr)
2163 if (
MI->isInlineAsm())
2164 verifyInlineAsm(
MI);
2167 if (
TII->isUnspillableTerminator(
MI)) {
2168 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2169 report(
"Unspillable Terminator does not define a reg",
MI);
2171 if (
Def.isVirtual() &&
2172 !MF->getProperties().hasProperty(
2174 std::distance(
MRI->use_nodbg_begin(Def),
MRI->use_nodbg_end()) > 1)
2175 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2181 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2182 if (!
MI->getDebugLoc())
2183 report(
"Missing DebugLoc for debug instruction",
MI);
2187 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2188 report(
"Metadata instruction should not have a value tracking number",
MI);
2192 if (
Op->isLoad() && !
MI->mayLoad())
2193 report(
"Missing mayLoad flag",
MI);
2194 if (
Op->isStore() && !
MI->mayStore())
2195 report(
"Missing mayStore flag",
MI);
2201 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2202 if (
MI->isDebugOrPseudoInstr()) {
2204 report(
"Debug instruction has a slot index",
MI);
2205 }
else if (
MI->isInsideBundle()) {
2207 report(
"Instruction inside bundle has a slot index",
MI);
2210 report(
"Missing slot index",
MI);
2216 verifyPreISelGenericInstruction(
MI);
2225 switch (
MI->getOpcode()) {
2226 case TargetOpcode::COPY: {
2232 LLT DstTy =
MRI->getType(DstReg);
2233 LLT SrcTy =
MRI->getType(SrcReg);
2236 if (SrcTy != DstTy) {
2237 report(
"Copy Instruction is illegal with mismatching types",
MI);
2238 errs() <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
"\n";
2253 TRI->getMinimalPhysRegClassLLT(SrcReg, DstTy);
2255 SrcSize =
TRI->getRegSizeInBits(*SrcRC);
2260 TRI->getMinimalPhysRegClassLLT(DstReg, SrcTy);
2262 DstSize =
TRI->getRegSizeInBits(*DstRC);
2280 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2281 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2282 errs() <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize
2288 case TargetOpcode::STATEPOINT: {
2290 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2291 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2292 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2293 report(
"meta operands to STATEPOINT not constant!",
MI);
2297 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2298 if (
Offset >=
MI->getNumOperands()) {
2299 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2302 if (!
MI->getOperand(
Offset - 1).isImm() ||
2303 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2305 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2307 VerifyStackMapConstant(SO.getCCIdx());
2308 VerifyStackMapConstant(SO.getFlagsIdx());
2309 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2310 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2311 VerifyStackMapConstant(SO.getNumAllocaIdx());
2312 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2316 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2317 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2318 for (
unsigned Idx = 0;
Idx <
MI->getNumDefs();
Idx++) {
2320 if (!
MI->isRegTiedToUseOperand(
Idx, &UseOpIdx)) {
2321 report(
"STATEPOINT defs expected to be tied",
MI);
2324 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2325 report(
"STATEPOINT def tied to non-gc operand",
MI);
2332 case TargetOpcode::INSERT_SUBREG: {
2333 unsigned InsertedSize;
2334 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2335 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2337 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *
MRI);
2338 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2339 if (SubRegSize < InsertedSize) {
2340 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2341 "size than the subreg it was inserted into",
MI);
2345 case TargetOpcode::REG_SEQUENCE: {
2346 unsigned NumOps =
MI->getNumOperands();
2347 if (!(NumOps & 1)) {
2348 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2352 for (
unsigned I = 1;
I != NumOps;
I += 2) {
2357 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2359 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2360 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2361 report(
"Invalid subregister index operand for REG_SEQUENCE",
2366 Register DstReg =
MI->getOperand(0).getReg();
2368 report(
"REG_SEQUENCE does not support physical register results",
MI);
2370 if (
MI->getOperand(0).getSubReg())
2371 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2379MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2383 if (MCID.
getOpcode() == TargetOpcode::PATCHPOINT)
2384 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2387 if (MONum < NumDefs) {
2390 report(
"Explicit definition must be a register", MO, MONum);
2392 report(
"Explicit definition marked as use", MO, MONum);
2394 report(
"Explicit definition marked as implicit", MO, MONum);
2403 report(
"Explicit operand marked as def", MO, MONum);
2405 report(
"Explicit operand marked as implicit", MO, MONum);
2411 report(
"Expected a register operand.", MO, MONum);
2415 !
TII->isPCRelRegisterOperandLegal(*MO)))
2416 report(
"Expected a non-register operand.", MO, MONum);
2423 report(
"Tied use must be a register", MO, MONum);
2425 report(
"Operand should be tied", MO, MONum);
2426 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2427 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2430 if (!MOTied.
isReg())
2431 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2434 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2437 report(
"Explicit operand should not be tied", MO, MONum);
2438 }
else if (!
MI->isVariadic()) {
2441 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2448 if (
MI->isDebugInstr() && MO->
isUse()) {
2450 report(
"Register operand must be marked debug", MO, MONum);
2452 report(
"Register operand must not be marked debug", MO, MONum);
2458 if (
MRI->tracksLiveness() && !
MI->isDebugInstr())
2459 checkLiveness(MO, MONum);
2463 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2467 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2469 if (!OtherMO.
isReg())
2470 report(
"Must be tied to a register", MO, MONum);
2472 report(
"Missing tie flags on tied operand", MO, MONum);
2473 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2474 report(
"Inconsistent tie links", MO, MONum);
2478 report(
"Explicit def tied to explicit use without tie constraint",
2482 report(
"Explicit def should be tied to implicit use", MO, MONum);
2495 if (MF->getProperties().hasProperty(
2497 MO->
isUse() &&
MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2498 Reg !=
MI->getOperand(DefIdx).getReg())
2499 report(
"Two-address instruction operands must be identical", MO, MONum);
2504 if (
Reg.isPhysical()) {
2506 report(
"Illegal subregister index for physical register", MO, MONum);
2511 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2512 if (!DRC->contains(Reg)) {
2513 report(
"Illegal physical register for instruction", MO, MONum);
2515 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2520 if (
MRI->isReserved(Reg)) {
2521 report(
"isRenamable set on reserved register", MO, MONum);
2538 report(
"Generic virtual register use cannot be undef", MO, MONum);
2545 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2546 !
MI->isDebugValue() || !
MRI->def_empty(Reg)) {
2548 if (isFunctionSelected) {
2549 report(
"Generic virtual register invalid in a Selected function",
2555 LLT Ty =
MRI->getType(Reg);
2557 report(
"Generic virtual register must have a valid type", MO,
2566 if (!RegBank && isFunctionRegBankSelected) {
2567 report(
"Generic virtual register must have a bank in a "
2568 "RegBankSelected function",
2576 report(
"Register bank is too small for virtual register", MO,
2578 errs() <<
"Register bank " << RegBank->
getName() <<
" too small("
2586 report(
"Generic virtual register does not allow subregister index", MO,
2596 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2597 report(
"Virtual register does not match instruction constraint", MO,
2599 errs() <<
"Expect register class "
2600 <<
TRI->getRegClassName(
2601 TII->getRegClass(MCID, MONum,
TRI, *MF))
2602 <<
" but got nothing\n";
2610 TRI->getSubClassWithSubReg(RC, SubIdx);
2612 report(
"Invalid subregister index for virtual register", MO, MONum);
2613 errs() <<
"Register class " <<
TRI->getRegClassName(RC)
2614 <<
" does not support subreg index " << SubIdx <<
"\n";
2618 report(
"Invalid register class for subregister index", MO, MONum);
2619 errs() <<
"Register class " <<
TRI->getRegClassName(RC)
2620 <<
" does not fully support subreg index " << SubIdx <<
"\n";
2626 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2629 TRI->getLargestLegalSuperClass(RC, *MF);
2631 report(
"No largest legal super class exists.", MO, MONum);
2634 DRC =
TRI->getMatchingSuperRegClass(SuperRC, DRC, SubIdx);
2636 report(
"No matching super-reg register class.", MO, MONum);
2641 report(
"Illegal virtual register for instruction", MO, MONum);
2642 errs() <<
"Expected a " <<
TRI->getRegClassName(DRC)
2643 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2658 report(
"PHI operand is not in the CFG", MO, MONum);
2663 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2669 bool loads =
MI->mayLoad();
2674 for (
auto *MMO :
MI->memoperands()) {
2676 if (PSV ==
nullptr)
continue;
2678 dyn_cast<FixedStackPseudoSourceValue>(PSV);
2679 if (
Value ==
nullptr)
continue;
2680 if (
Value->getFrameIndex() != FI)
continue;
2689 report(
"Missing fixed stack memoperand.",
MI);
2691 if (loads && !LI.
liveAt(
Idx.getRegSlot(
true))) {
2692 report(
"Instruction loads from dead spill slot", MO, MONum);
2693 errs() <<
"Live stack: " << LI <<
'\n';
2696 report(
"Instruction stores to dead spill slot", MO, MONum);
2697 errs() <<
"Live stack: " << LI <<
'\n';
2703 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2704 report(
"CFI instruction has invalid index", MO, MONum);
2712void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2723 report(
"No live segment at use", MO, MONum);
2724 report_context_liverange(LR);
2725 report_context_vreg_regunit(VRegOrUnit);
2726 report_context(UseIdx);
2729 report(
"Live range continues after kill flag", MO, MONum);
2730 report_context_liverange(LR);
2731 report_context_vreg_regunit(VRegOrUnit);
2733 report_context_lanemask(LaneMask);
2734 report_context(UseIdx);
2738void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2753 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
2755 (VNI->def != DefIdx &&
2756 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
2757 report(
"Inconsistent valno->def", MO, MONum);
2758 report_context_liverange(LR);
2759 report_context_vreg_regunit(VRegOrUnit);
2761 report_context_lanemask(LaneMask);
2762 report_context(*VNI);
2763 report_context(DefIdx);
2766 report(
"No live segment at def", MO, MONum);
2767 report_context_liverange(LR);
2768 report_context_vreg_regunit(VRegOrUnit);
2770 report_context_lanemask(LaneMask);
2771 report_context(DefIdx);
2783 if (SubRangeCheck || MO->
getSubReg() == 0) {
2784 report(
"Live range continues after dead def flag", MO, MONum);
2785 report_context_liverange(LR);
2786 report_context_vreg_regunit(VRegOrUnit);
2788 report_context_lanemask(LaneMask);
2794void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
2797 const unsigned SubRegIdx = MO->
getSubReg();
2800 if (LiveInts &&
Reg.isVirtual()) {
2801 if (LiveInts->hasInterval(Reg)) {
2802 LI = &LiveInts->getInterval(Reg);
2805 report(
"Live interval for subreg operand has no subranges", MO, MONum);
2807 report(
"Virtual register has no live interval", MO, MONum);
2814 addRegWithSubRegs(regsKilled, Reg);
2819 if (LiveVars &&
Reg.isVirtual() && MO->
isKill() &&
2820 !
MI->isBundledWithPred()) {
2823 report(
"Kill missing from LiveVariables", MO, MONum);
2827 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2831 UseIdx = LiveInts->getMBBEndIdx(
2832 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
2834 UseIdx = LiveInts->getInstructionIndex(*
MI);
2837 if (
Reg.isPhysical() && !isReserved(Reg)) {
2839 if (
MRI->isReservedRegUnit(Unit))
2841 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
2842 checkLivenessAtUse(MO, MONum, UseIdx, *LR, Unit);
2846 if (
Reg.isVirtual()) {
2848 checkLivenessAtUse(MO, MONum, UseIdx, *LI, Reg);
2852 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
2853 :
MRI->getMaxLaneMaskForVReg(Reg);
2856 if ((MOMask & SR.LaneMask).none())
2858 checkLivenessAtUse(MO, MONum, UseIdx, SR, Reg, SR.LaneMask);
2861 LiveInMask |= SR.LaneMask;
2864 if ((LiveInMask & MOMask).
none()) {
2865 report(
"No live subrange at use", MO, MONum);
2866 report_context(*LI);
2867 report_context(UseIdx);
2870 if (
MI->isPHI() && LiveInMask != MOMask) {
2871 report(
"Not all lanes of PHI source live at use", MO, MONum);
2872 report_context(*LI);
2873 report_context(UseIdx);
2880 if (!regsLive.count(Reg)) {
2881 if (
Reg.isPhysical()) {
2883 bool Bad = !isReserved(Reg);
2888 if (regsLive.count(
SubReg)) {
2900 if (!MOP.isReg() || !MOP.isImplicit())
2903 if (!MOP.getReg().isPhysical())
2911 report(
"Using an undefined physical register", MO, MONum);
2912 }
else if (
MRI->def_empty(Reg)) {
2913 report(
"Reading virtual register without a def", MO, MONum);
2915 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
2919 if (MInfo.regsKilled.count(Reg))
2920 report(
"Using a killed virtual register", MO, MONum);
2921 else if (!
MI->isPHI())
2922 MInfo.vregsLiveIn.insert(std::make_pair(Reg,
MI));
2931 addRegWithSubRegs(regsDead, Reg);
2933 addRegWithSubRegs(regsDefined, Reg);
2936 if (
MRI->isSSA() &&
Reg.isVirtual() &&
2937 std::next(
MRI->def_begin(Reg)) !=
MRI->def_end())
2938 report(
"Multiple virtual register defs in SSA form", MO, MONum);
2941 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2942 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
2945 if (
Reg.isVirtual()) {
2946 checkLivenessAtDef(MO, MONum, DefIdx, *LI, Reg);
2950 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
2951 :
MRI->getMaxLaneMaskForVReg(Reg);
2953 if ((SR.LaneMask & MOMask).none())
2955 checkLivenessAtDef(MO, MONum, DefIdx, SR, Reg,
true, SR.LaneMask);
2967void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
2968 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
2969 set_union(MInfo.regsKilled, regsKilled);
2970 set_subtract(regsLive, regsKilled); regsKilled.clear();
2972 while (!regMasks.empty()) {
2975 if (
Reg.isPhysical() &&
2977 regsDead.push_back(Reg);
2980 set_union(regsLive, regsDefined); regsDefined.clear();
2985 MBBInfoMap[
MBB].regsLiveOut = regsLive;
2990 if (!(stop > lastIndex)) {
2991 report(
"Block ends before last instruction index",
MBB);
2992 errs() <<
"Block ends at " << stop
2993 <<
" last instruction was at " << lastIndex <<
'\n';
3008 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3010 filterAndAdd(FromRegSet, VRegsBuffer);
3015 template <
typename RegSetT>
3016 bool filterAndAdd(
const RegSetT &FromRegSet,
3018 unsigned SparseUniverse = Sparse.size();
3019 unsigned NewSparseUniverse = SparseUniverse;
3020 unsigned NewDenseSize =
Dense.size();
3021 size_t Begin = ToVRegs.
size();
3023 if (!
Reg.isVirtual())
3026 if (
Index < SparseUniverseMax) {
3027 if (
Index < SparseUniverse && Sparse.test(
Index))
3029 NewSparseUniverse = std::max(NewSparseUniverse,
Index + 1);
3044 Sparse.resize(NewSparseUniverse);
3045 Dense.reserve(NewDenseSize);
3046 for (
unsigned I = Begin;
I <
End; ++
I) {
3049 if (
Index < SparseUniverseMax)
3058 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3078class FilteringVRegSet {
3085 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3090 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3093 return Filter.filterAndAdd(RS, VRegs);
3098 size_t size()
const {
return VRegs.
size(); }
3105void MachineVerifier::calcRegsPassed() {
3112 FilteringVRegSet VRegs;
3113 BBInfo &
Info = MBBInfoMap[MB];
3116 VRegs.addToFilter(
Info.regsKilled);
3117 VRegs.addToFilter(
Info.regsLiveOut);
3119 const BBInfo &PredInfo = MBBInfoMap[Pred];
3120 if (!PredInfo.reachable)
3123 VRegs.add(PredInfo.regsLiveOut);
3124 VRegs.add(PredInfo.vregsPassed);
3126 Info.vregsPassed.reserve(VRegs.size());
3127 Info.vregsPassed.insert(VRegs.begin(), VRegs.end());
3134void MachineVerifier::calcRegsRequired() {
3137 for (
const auto &
MBB : *MF) {
3138 BBInfo &MInfo = MBBInfoMap[&
MBB];
3140 BBInfo &PInfo = MBBInfoMap[Pred];
3141 if (PInfo.addRequired(MInfo.vregsLiveIn))
3147 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3149 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3156 BBInfo &PInfo = MBBInfoMap[Pred];
3157 if (PInfo.addRequired(Reg))
3165 while (!todo.
empty()) {
3168 BBInfo &MInfo = MBBInfoMap[
MBB];
3172 BBInfo &SInfo = MBBInfoMap[Pred];
3173 if (SInfo.addRequired(MInfo.vregsRequired))
3182 BBInfo &MInfo = MBBInfoMap[&
MBB];
3192 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3197 report(
"Unexpected flag on PHI operand", &MODef, 0);
3200 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3202 for (
unsigned I = 1, E =
Phi.getNumOperands();
I != E;
I += 2) {
3205 report(
"Expected PHI operand to be a register", &MO0,
I);
3210 report(
"Unexpected flag on PHI operand", &MO0,
I);
3214 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3220 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3224 if (MInfo.reachable) {
3226 BBInfo &PrInfo = MBBInfoMap[&Pre];
3227 if (!MO0.
isUndef() && PrInfo.reachable &&
3228 !PrInfo.isLiveOut(MO0.
getReg()))
3229 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3234 if (MInfo.reachable) {
3236 if (!seen.
count(Pred)) {
3237 report(
"Missing PHI operand", &Phi);
3239 <<
" is a predecessor according to the CFG.\n";
3248 std::function<
void(
const Twine &Message)> FailureCB) {
3252 for (
const auto &
MBB : MF) {
3264void MachineVerifier::visitMachineFunctionAfter() {
3265 auto FailureCB = [
this](
const Twine &Message) {
3266 report(Message.str().c_str(), MF);
3279 for (
const auto &
MBB : *MF) {
3280 BBInfo &MInfo = MBBInfoMap[&
MBB];
3281 for (
Register VReg : MInfo.vregsRequired)
3282 if (MInfo.regsKilled.count(VReg)) {
3283 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3285 <<
" is used after the block.\n";
3290 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3291 for (
Register VReg : MInfo.vregsRequired) {
3292 report(
"Virtual register defs don't dominate all uses.", MF);
3293 report_context_vreg(VReg);
3298 verifyLiveVariables();
3300 verifyLiveIntervals();
3309 if (
MRI->tracksLiveness())
3310 for (
const auto &
MBB : *MF)
3314 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3317 BBInfo &PInfo = MBBInfoMap[Pred];
3318 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3319 report(
"Live in register not found to be live out from predecessor.",
3321 errs() <<
TRI->getName(LiveInReg)
3322 <<
" not found to be live out from "
3328 for (
auto CSInfo : MF->getCallSitesInfo())
3329 if (!CSInfo.first->isCall())
3330 report(
"Call site info referencing instruction that is not call", MF);
3334 if (MF->getFunction().getSubprogram()) {
3336 for (
const auto &
MBB : *MF) {
3337 for (
const auto &
MI :
MBB) {
3338 if (
auto Num =
MI.peekDebugInstrNum()) {
3341 report(
"Instruction has a duplicated value tracking number", &
MI);
3348void MachineVerifier::verifyLiveVariables() {
3349 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3350 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3353 for (
const auto &
MBB : *MF) {
3354 BBInfo &MInfo = MBBInfoMap[&
MBB];
3357 if (MInfo.vregsRequired.count(Reg)) {
3359 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3361 <<
" must be live through the block.\n";
3365 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3367 <<
" is not needed live through the block.\n";
3374void MachineVerifier::verifyLiveIntervals() {
3375 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3376 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3380 if (
MRI->reg_nodbg_empty(Reg))
3383 if (!LiveInts->hasInterval(Reg)) {
3384 report(
"Missing live interval for virtual register", MF);
3390 assert(Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3391 verifyLiveInterval(LI);
3395 for (
unsigned i = 0, e =
TRI->getNumRegUnits(); i != e; ++i)
3396 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(i))
3397 verifyLiveRange(*LR, i);
3400void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3409 report(
"Value not live at VNInfo def and not marked unused", MF);
3410 report_context(LR, Reg, LaneMask);
3411 report_context(*VNI);
3415 if (DefVNI != VNI) {
3416 report(
"Live segment at def has different VNInfo", MF);
3417 report_context(LR, Reg, LaneMask);
3418 report_context(*VNI);
3424 report(
"Invalid VNInfo definition index", MF);
3425 report_context(LR, Reg, LaneMask);
3426 report_context(*VNI);
3431 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3432 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3433 report_context(LR, Reg, LaneMask);
3434 report_context(*VNI);
3442 report(
"No instruction at VNInfo def index",
MBB);
3443 report_context(LR, Reg, LaneMask);
3444 report_context(*VNI);
3449 bool hasDef =
false;
3450 bool isEarlyClobber =
false;
3452 if (!MOI->isReg() || !MOI->isDef())
3454 if (
Reg.isVirtual()) {
3455 if (MOI->getReg() != Reg)
3458 if (!MOI->getReg().isPhysical() || !
TRI->hasRegUnit(MOI->getReg(), Reg))
3461 if (LaneMask.
any() &&
3462 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3465 if (MOI->isEarlyClobber())
3466 isEarlyClobber =
true;
3470 report(
"Defining instruction does not modify register",
MI);
3471 report_context(LR, Reg, LaneMask);
3472 report_context(*VNI);
3477 if (isEarlyClobber) {
3479 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3480 report_context(LR, Reg, LaneMask);
3481 report_context(*VNI);
3484 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3485 report_context(LR, Reg, LaneMask);
3486 report_context(*VNI);
3491void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3497 assert(VNI &&
"Live segment has no valno");
3500 report(
"Foreign valno in live segment", MF);
3501 report_context(LR, Reg, LaneMask);
3503 report_context(*VNI);
3507 report(
"Live segment valno is marked unused", MF);
3508 report_context(LR, Reg, LaneMask);
3514 report(
"Bad start of live segment, no basic block", MF);
3515 report_context(LR, Reg, LaneMask);
3521 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3522 report_context(LR, Reg, LaneMask);
3529 report(
"Bad end of live segment, no basic block", MF);
3530 report_context(LR, Reg, LaneMask);
3536 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3546 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3547 report_context(LR, Reg, LaneMask);
3554 report(
"Live segment ends at B slot of an instruction", EndMBB);
3555 report_context(LR, Reg, LaneMask);
3563 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3564 report_context(LR, Reg, LaneMask);
3573 if (MF->getProperties().hasProperty(
3576 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3577 report(
"Live segment ending at early clobber slot must be "
3578 "redefined by an EC def in the same instruction",
3580 report_context(LR, Reg, LaneMask);
3587 if (
Reg.isVirtual()) {
3590 bool hasRead =
false;
3591 bool hasSubRegDef =
false;
3592 bool hasDeadDef =
false;
3594 if (!MOI->isReg() || MOI->getReg() != Reg)
3596 unsigned Sub = MOI->getSubReg();
3601 hasSubRegDef =
true;
3610 if (LaneMask.
any() && (LaneMask & SLM).none())
3612 if (MOI->readsReg())
3619 if (LaneMask.
none() && !hasDeadDef) {
3621 "Instruction ending live segment on dead slot has no dead flag",
3623 report_context(LR, Reg, LaneMask);
3630 if (!
MRI->shouldTrackSubRegLiveness(Reg) || LaneMask.
any() ||
3632 report(
"Instruction ending live segment doesn't read the register",
3634 report_context(LR, Reg, LaneMask);
3654 if (LaneMask.
any()) {
3660 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3662 if (!
Reg.isVirtual() && MFI->isEHPad()) {
3663 if (&*MFI == EndMBB)
3671 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3675 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3677 if (MFI->isEHPad()) {
3680 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3691 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3694 report(
"Register not marked live out of predecessor", Pred);
3695 report_context(LR, Reg, LaneMask);
3696 report_context(*VNI);
3698 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before "
3704 if (!IsPHI && PVNI != VNI) {
3705 report(
"Different value live out of predecessor", Pred);
3706 report_context(LR, Reg, LaneMask);
3707 errs() <<
"Valno #" << PVNI->
id <<
" live out of "
3710 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3713 if (&*MFI == EndMBB)
3722 verifyLiveRangeValue(LR, VNI, Reg, LaneMask);
3725 verifyLiveRangeSegment(LR,
I, Reg, LaneMask);
3728void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3731 verifyLiveRange(LI, Reg);
3737 if ((Mask & SR.LaneMask).any()) {
3738 report(
"Lane masks of sub ranges overlap in live interval", MF);
3741 if ((SR.LaneMask & ~MaxMask).any()) {
3742 report(
"Subrange lanemask is invalid", MF);
3746 report(
"Subrange must not be empty", MF);
3747 report_context(SR, LI.
reg(), SR.LaneMask);
3749 Mask |= SR.LaneMask;
3750 verifyLiveRange(SR, LI.
reg(), SR.LaneMask);
3752 report(
"A Subrange is not covered by the main range", MF);
3760 unsigned NumComp = ConEQ.Classify(LI);
3762 report(
"Multiple connected components in live interval", MF);
3764 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3765 errs() << comp <<
": valnos";
3767 if (comp == ConEQ.getEqClass(
I))
3768 errs() <<
' ' <<
I->id;
3780 struct StackStateOfBB {
3781 StackStateOfBB() =
default;
3782 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup) :
3783 EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
3784 ExitIsSetup(ExitSetup) {}
3789 bool EntryIsSetup =
false;
3790 bool ExitIsSetup =
false;
3798void MachineVerifier::verifyStackFrame() {
3799 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
3800 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
3801 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
3805 SPState.
resize(MF->getNumBlockIDs());
3812 DFI != DFE; ++DFI) {
3815 StackStateOfBB BBState;
3817 if (DFI.getPathLength() >= 2) {
3820 "DFS stack predecessor is already visited.\n");
3821 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
3822 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
3823 BBState.ExitValue = BBState.EntryValue;
3824 BBState.ExitIsSetup = BBState.EntryIsSetup;
3828 report(
"Call frame size on entry does not match value computed from "
3832 <<
" does not match value computed from predecessor "
3833 << -BBState.EntryValue <<
'\n';
3837 for (
const auto &
I : *
MBB) {
3838 if (
I.getOpcode() == FrameSetupOpcode) {
3839 if (BBState.ExitIsSetup)
3840 report(
"FrameSetup is after another FrameSetup", &
I);
3841 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3842 report(
"AdjustsStack not set in presence of a frame pseudo "
3843 "instruction.", &
I);
3844 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
3845 BBState.ExitIsSetup =
true;
3848 if (
I.getOpcode() == FrameDestroyOpcode) {
3849 int Size =
TII->getFrameTotalSize(
I);
3850 if (!BBState.ExitIsSetup)
3851 report(
"FrameDestroy is not after a FrameSetup", &
I);
3852 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
3854 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
3855 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
3856 errs() <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
3857 << AbsSPAdj <<
">.\n";
3859 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3860 report(
"AdjustsStack not set in presence of a frame pseudo "
3861 "instruction.", &
I);
3862 BBState.ExitValue +=
Size;
3863 BBState.ExitIsSetup =
false;
3871 if (Reachable.
count(Pred) &&
3872 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
3873 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
3874 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
3876 <<
" has exit state (" << SPState[Pred->
getNumber()].ExitValue
3877 <<
", " << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
3879 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
3886 if (Reachable.
count(Succ) &&
3887 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
3888 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
3889 report(
"The entry stack state of a successor is inconsistent.",
MBB);
3891 <<
" has entry state (" << SPState[Succ->getNumber()].EntryValue
3892 <<
", " << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
3894 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
3900 if (BBState.ExitIsSetup)
3901 report(
"A return block ends with a FrameSetup.",
MBB);
3902 if (BBState.ExitValue)
3903 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...
const HexagonInstrInfo * TII
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)
modulo schedule Modulo Schedule test pass
const char LLVMTargetMachineRef TM
#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 isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
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 necessarilly including Idx,...
unsigned getNumValNums() const
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
LiveInterval & getInterval(int Slot)
bool hasInterval(int Slot) const
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.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
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)
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.
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.
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.