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;
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;
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(
VirtRegOrUnit VRegOrUnit)
const;
340 void calcRegsPassed();
343 void calcRegsRequired();
344 void verifyLiveVariables();
345 void verifyLiveIntervals();
349 void verifyLiveRangeSegment(
const LiveRange &,
355 void verifyStackFrame();
357 void verifyStackProtector();
359 void verifySlotIndexes()
const;
366 const std::string Banner;
368 MachineVerifierLegacyPass(std::string banner = std::string())
389 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(MFAM, Banner,
OS, AbortOnError).verify(*
this);
440 bool AbortOnError)
const {
441 return MachineVerifier(Banner,
nullptr, LiveInts,
442 nullptr, Indexes,
OS, AbortOnError)
446void MachineVerifier::verifySlotIndexes()
const {
447 if (Indexes ==
nullptr)
464 report(
"Function has NoVRegs property but there are VReg operands", &MF);
476 const bool isFunctionFailedISel = Props.hasFailedISel();
481 if (isFunctionFailedISel)
484 isFunctionRegBankSelected = Props.hasRegBankSelected();
485 isFunctionSelected = Props.hasSelected();
486 isFunctionTracksDebugUserValues = Props.hasTracksDebugUserValues();
490 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
494 LiveVars = LVWrapper ? &LVWrapper->getLV() :
nullptr;
496 LiveStks = LSWrapper ? &LSWrapper->getLS() :
nullptr;
498 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
511 verifyProperties(MF);
513 visitMachineFunctionBefore();
515 visitMachineBasicBlockBefore(&
MBB);
519 bool InBundle =
false;
522 if (
MI.getParent() != &
MBB) {
523 report(
"Bad instruction parent pointer", &
MBB);
524 OS <<
"Instruction: " <<
MI;
529 if (InBundle && !
MI.isBundledWithPred())
530 report(
"Missing BundledPred flag, "
531 "BundledSucc was set on predecessor",
533 if (!InBundle &&
MI.isBundledWithPred())
534 report(
"BundledPred flag is set, "
535 "but BundledSucc not set on predecessor",
539 if (!
MI.isInsideBundle()) {
541 visitMachineBundleAfter(CurBundle);
543 visitMachineBundleBefore(CurBundle);
544 }
else if (!CurBundle)
545 report(
"No bundle header", &
MI);
546 visitMachineInstrBefore(&
MI);
547 for (
unsigned I = 0, E =
MI.getNumOperands();
I != E; ++
I) {
549 if (
Op.getParent() != &
MI) {
552 report(
"Instruction has operand with wrong parent set", &
MI);
555 visitMachineOperand(&
Op,
I);
559 InBundle =
MI.isBundledWithSucc();
562 visitMachineBundleAfter(CurBundle);
564 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
565 visitMachineBasicBlockAfter(&
MBB);
567 visitMachineFunctionAfter();
577 return !ReportedErrs.hasError();
580void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
583 if (ReportedErrs.increment()) {
585 OS <<
"# " << Banner <<
'\n';
587 if (LiveInts !=
nullptr)
593 OS <<
"*** Bad machine code: " << msg <<
" ***\n"
594 <<
"- function: " << MF->
getName() <<
'\n';
601 <<
" (" << (
const void *)
MBB <<
')';
603 OS <<
" [" << Indexes->getMBBStartIdx(
MBB) <<
';'
604 << Indexes->getMBBEndIdx(
MBB) <<
')';
608void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
610 report(msg,
MI->getParent());
611 OS <<
"- instruction: ";
612 if (Indexes && Indexes->hasIndex(*
MI))
613 OS << Indexes->getInstructionIndex(*
MI) <<
'\t';
617void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
618 unsigned MONum,
LLT MOVRegType) {
621 OS <<
"- operand " << MONum <<
": ";
627 report(Msg.
str().c_str(),
MI);
630void MachineVerifier::report_context(
SlotIndex Pos)
const {
631 OS <<
"- at: " << Pos <<
'\n';
634void MachineVerifier::report_context(
const LiveInterval &LI)
const {
635 OS <<
"- interval: " << LI <<
'\n';
638void MachineVerifier::report_context(
const LiveRange &LR,
641 report_context_liverange(LR);
642 report_context_vreg_regunit(VRegOrUnit);
644 report_context_lanemask(LaneMask);
648 OS <<
"- segment: " << S <<
'\n';
651void MachineVerifier::report_context(
const VNInfo &VNI)
const {
652 OS <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
655void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
656 OS <<
"- liverange: " << LR <<
'\n';
659void MachineVerifier::report_context(
MCPhysReg PReg)
const {
663void MachineVerifier::report_context_vreg(
Register VReg)
const {
667void MachineVerifier::report_context_vreg_regunit(
677void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
682 BBInfo &MInfo = MBBInfoMap[
MBB];
683 if (!MInfo.reachable) {
684 MInfo.reachable =
true;
690void MachineVerifier::visitMachineFunctionBefore() {
692 regsReserved =
MRI->reservedRegsFrozen() ?
MRI->getReservedRegs()
693 :
TRI->getReservedRegs(*MF);
696 markReachable(&MF->
front());
699 FunctionBlocks.clear();
700 for (
const auto &
MBB : *MF) {
701 FunctionBlocks.insert(&
MBB);
702 BBInfo &MInfo = MBBInfoMap[&
MBB];
706 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
710 report(
"MBB has duplicate entries in its successor list.", &
MBB);
714 MRI->verifyUseLists();
718 verifyStackProtector();
724 FirstTerminator =
nullptr;
725 FirstNonPHI =
nullptr;
727 if (!MF->getProperties().hasNoPHIs() &&
MRI->tracksLiveness()) {
731 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
734 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
735 "inlineasm-br-indirect-target.",
737 report_context(LI.PhysReg);
744 report(
"ir-block-address-taken is associated with basic block not used by "
753 LandingPadSuccs.
insert(succ);
754 if (!FunctionBlocks.count(succ))
755 report(
"MBB has successor that isn't part of the function.",
MBB);
756 if (!MBBInfoMap[succ].Preds.count(
MBB)) {
757 report(
"Inconsistent CFG",
MBB);
758 OS <<
"MBB is not in the predecessor list of the successor "
765 if (!FunctionBlocks.count(Pred))
766 report(
"MBB has predecessor that isn't part of the function.",
MBB);
767 if (!MBBInfoMap[Pred].Succs.count(
MBB)) {
768 report(
"Inconsistent CFG",
MBB);
769 OS <<
"MBB is not in the successor list of the predecessor "
777 if (LandingPadSuccs.
size() > 1 &&
782 report(
"MBB has more than one landing pad successor",
MBB);
795 report(
"MBB exits via unconditional fall-through but ends with a "
796 "barrier instruction!",
MBB);
799 report(
"MBB exits via unconditional fall-through but has a condition!",
802 }
else if (
TBB && !FBB &&
Cond.empty()) {
805 report(
"MBB exits via unconditional branch but doesn't contain "
806 "any instructions!",
MBB);
808 report(
"MBB exits via unconditional branch but doesn't end with a "
809 "barrier instruction!",
MBB);
811 report(
"MBB exits via unconditional branch but the branch isn't a "
812 "terminator instruction!",
MBB);
814 }
else if (
TBB && !FBB && !
Cond.empty()) {
817 report(
"MBB exits via conditional branch/fall-through but doesn't "
818 "contain any instructions!",
MBB);
820 report(
"MBB exits via conditional branch/fall-through but ends with a "
821 "barrier instruction!",
MBB);
823 report(
"MBB exits via conditional branch/fall-through but the branch "
824 "isn't a terminator instruction!",
MBB);
826 }
else if (
TBB && FBB) {
830 report(
"MBB exits via conditional branch/branch but doesn't "
831 "contain any instructions!",
MBB);
833 report(
"MBB exits via conditional branch/branch but doesn't end with a "
834 "barrier instruction!",
MBB);
836 report(
"MBB exits via conditional branch/branch but the branch "
837 "isn't a terminator instruction!",
MBB);
840 report(
"MBB exits via conditional branch/branch but there's no "
844 report(
"analyzeBranch returned invalid data!",
MBB);
850 report(
"MBB exits via jump or conditional branch, but its target isn't a "
854 report(
"MBB exits via conditional branch, but its target isn't a CFG "
861 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
866 if (!
Cond.empty() && !FBB) {
869 report(
"MBB conditionally falls through out of function!",
MBB);
871 report(
"MBB exits via conditional branch/fall-through but the CFG "
872 "successors don't match the actual successors!",
879 if (SuccMBB ==
TBB || SuccMBB == FBB)
887 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
889 report(
"MBB has unexpected successors which are not branch targets, "
890 "fallthrough, EHPads, or inlineasm_br targets.",
896 if (
MRI->tracksLiveness()) {
898 if (!LI.PhysReg.isPhysical()) {
899 report(
"MBB live-in list contains non-physical register",
MBB);
902 regsLive.insert_range(
TRI->subregs_inclusive(LI.PhysReg));
909 regsLive.insert_range(
TRI->subregs_inclusive(
I));
915 lastIndex = Indexes->getMBBStartIdx(
MBB);
920void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
921 if (Indexes && Indexes->hasIndex(*
MI)) {
923 if (!(idx > lastIndex)) {
924 report(
"Instruction index out of order",
MI);
925 OS <<
"Last instruction was at " << lastIndex <<
'\n';
931 if (
MI->isTerminator()) {
932 if (!FirstTerminator)
933 FirstTerminator =
MI;
934 }
else if (FirstTerminator) {
937 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
938 report(
"Non-terminator instruction after the first terminator",
MI);
939 OS <<
"First terminator was:\t" << *FirstTerminator;
948 if (
MI->getNumOperands() < 2) {
949 report(
"Too few operands on inline asm",
MI);
952 if (!
MI->getOperand(0).isSymbol())
953 report(
"Asm string must be an external symbol",
MI);
954 if (!
MI->getOperand(1).isImm())
955 report(
"Asm flags must be an immediate",
MI);
959 if (!isUInt<6>(
MI->getOperand(1).getImm()))
960 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
966 for (
unsigned e =
MI->getNumOperands(); OpNo <
e; OpNo += NumOps) {
972 NumOps = 1 +
F.getNumOperandRegisters();
975 if (OpNo >
MI->getNumOperands())
976 report(
"Missing operands in last group",
MI);
979 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
983 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
986 report(
"Expected implicit register after groups", &MO, OpNo);
989 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
1002 if (!IndirectTargetMBB) {
1003 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1008 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1012 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1018bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1023 const auto Reg = Op.getReg();
1024 if (Reg.isPhysical())
1026 return !MRI.getType(Reg).isScalar();
1029 report(
"All register operands must have scalar types", &
MI);
1036bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1039 report(
"operand types must be all-vector or all-scalar",
MI);
1049 report(
"operand types must preserve number of vector elements",
MI);
1056bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1057 auto Opcode =
MI->getOpcode();
1058 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1059 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1060 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1061 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1063 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1064 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1065 if (NoSideEffects && DeclHasSideEffects) {
1067 " used with intrinsic that accesses memory"),
1071 if (!NoSideEffects && !DeclHasSideEffects) {
1072 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1080bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1081 auto Opcode =
MI->getOpcode();
1082 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1083 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1084 unsigned IntrID = cast<GIntrinsic>(
MI)->getIntrinsicID();
1085 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1087 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1088 bool DeclIsConvergent =
Attrs.hasAttribute(Attribute::Convergent);
1089 if (NotConvergent && DeclIsConvergent) {
1090 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1094 if (!NotConvergent && !DeclIsConvergent) {
1096 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1105void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1106 if (isFunctionSelected)
1107 report(
"Unexpected generic instruction in a Selected function",
MI);
1110 unsigned NumOps =
MI->getNumOperands();
1113 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1114 bool HasMBB =
false;
1123 report(
"Branch instruction is missing a basic block operand or "
1124 "isIndirectBranch property",
1133 if (!MCID.
operands()[
I].isGenericType())
1137 size_t TypeIdx = MCID.
operands()[
I].getGenericTypeIndex();
1138 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1142 report(
"generic instruction must use register operands",
MI);
1152 if (!Types[TypeIdx].
isValid())
1153 Types[TypeIdx] = OpTy;
1154 else if (Types[TypeIdx] != OpTy)
1155 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1158 report(
"Generic instruction is missing a virtual register type", MO,
I);
1163 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1166 report(
"Generic instruction cannot have physical register", MO,
I);
1178 unsigned Opc =
MI->getOpcode();
1180 case TargetOpcode::G_ASSERT_SEXT:
1181 case TargetOpcode::G_ASSERT_ZEXT: {
1182 std::string OpcName =
1183 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1184 if (!
MI->getOperand(2).isImm()) {
1185 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1191 LLT SrcTy =
MRI->getType(Src);
1192 int64_t
Imm =
MI->getOperand(2).getImm();
1194 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1199 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1207 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1208 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1214 if (DstRC && DstRC !=
MRI->getRegClassOrNull(Src)) {
1216 Twine(OpcName,
" source and destination register classes must match"),
1224 case TargetOpcode::G_CONSTANT:
1225 case TargetOpcode::G_FCONSTANT: {
1226 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1228 report(
"Instruction cannot use a vector result type",
MI);
1230 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1231 if (!
MI->getOperand(1).isCImm()) {
1232 report(
"G_CONSTANT operand must be cimm",
MI);
1238 report(
"inconsistent constant size",
MI);
1240 if (!
MI->getOperand(1).isFPImm()) {
1241 report(
"G_FCONSTANT operand must be fpimm",
MI);
1248 report(
"inconsistent constant size",
MI);
1254 case TargetOpcode::G_LOAD:
1255 case TargetOpcode::G_STORE:
1256 case TargetOpcode::G_ZEXTLOAD:
1257 case TargetOpcode::G_SEXTLOAD: {
1258 LLT ValTy =
MRI->getType(
MI->getOperand(0).getReg());
1259 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1261 report(
"Generic memory instruction must access a pointer",
MI);
1265 if (!
MI->hasOneMemOperand()) {
1266 report(
"Generic instruction accessing memory must have one mem operand",
1270 if (
MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
1271 MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
1274 report(
"Generic extload must have a narrower memory type",
MI);
1275 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1278 report(
"load memory size cannot exceed result size",
MI);
1289 report(
"range is incompatible with the result type",
MI);
1292 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1295 report(
"store memory size cannot exceed value size",
MI);
1299 if (
Opc == TargetOpcode::G_STORE) {
1302 report(
"atomic store cannot use acquire ordering",
MI);
1307 report(
"atomic load cannot use release ordering",
MI);
1313 case TargetOpcode::G_PHI: {
1314 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1319 LLT Ty = MRI->getType(MO.getReg());
1320 if (!Ty.isValid() || (Ty != DstTy))
1324 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1329 case TargetOpcode::G_BITCAST: {
1330 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1331 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1336 report(
"bitcast cannot convert between pointers and other types",
MI);
1339 report(
"bitcast sizes must match",
MI);
1342 report(
"bitcast must change the type",
MI);
1346 case TargetOpcode::G_INTTOPTR:
1347 case TargetOpcode::G_PTRTOINT:
1348 case TargetOpcode::G_ADDRSPACE_CAST: {
1349 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1350 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1354 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1359 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1361 report(
"inttoptr result type must be a pointer",
MI);
1363 report(
"inttoptr source type must not be a pointer",
MI);
1364 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1366 report(
"ptrtoint source type must be a pointer",
MI);
1368 report(
"ptrtoint result type must not be a pointer",
MI);
1370 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1372 report(
"addrspacecast types must be pointers",
MI);
1375 report(
"addrspacecast must convert different address spaces",
MI);
1381 case TargetOpcode::G_PTR_ADD: {
1382 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1383 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1384 LLT OffsetTy =
MRI->getType(
MI->getOperand(2).getReg());
1389 report(
"gep first operand must be a pointer",
MI);
1392 report(
"gep offset operand must not be a pointer",
MI);
1397 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1399 report(
"gep offset operand must match index size for address space",
1407 case TargetOpcode::G_PTRMASK: {
1408 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1409 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1410 LLT MaskTy =
MRI->getType(
MI->getOperand(2).getReg());
1415 report(
"ptrmask result type must be a pointer",
MI);
1418 report(
"ptrmask mask type must be an integer",
MI);
1420 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1423 case TargetOpcode::G_SEXT:
1424 case TargetOpcode::G_ZEXT:
1425 case TargetOpcode::G_ANYEXT:
1426 case TargetOpcode::G_TRUNC:
1427 case TargetOpcode::G_TRUNC_SSAT_S:
1428 case TargetOpcode::G_TRUNC_SSAT_U:
1429 case TargetOpcode::G_TRUNC_USAT_U:
1430 case TargetOpcode::G_FPEXT:
1431 case TargetOpcode::G_FPTRUNC: {
1438 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1439 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1444 report(
"Generic extend/truncate can not operate on pointers",
MI);
1446 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1450 switch (
MI->getOpcode()) {
1452 if (DstSize <= SrcSize)
1453 report(
"Generic extend has destination type no larger than source",
MI);
1455 case TargetOpcode::G_TRUNC:
1456 case TargetOpcode::G_TRUNC_SSAT_S:
1457 case TargetOpcode::G_TRUNC_SSAT_U:
1458 case TargetOpcode::G_TRUNC_USAT_U:
1459 case TargetOpcode::G_FPTRUNC:
1460 if (DstSize >= SrcSize)
1461 report(
"Generic truncate has destination type no smaller than source",
1467 case TargetOpcode::G_SELECT: {
1468 LLT SelTy =
MRI->getType(
MI->getOperand(0).getReg());
1469 LLT CondTy =
MRI->getType(
MI->getOperand(1).getReg());
1475 verifyVectorElementMatch(SelTy, CondTy,
MI);
1478 case TargetOpcode::G_MERGE_VALUES: {
1483 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1484 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1486 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1488 const unsigned NumOps =
MI->getNumOperands();
1490 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1492 for (
unsigned I = 2;
I != NumOps; ++
I) {
1493 if (
MRI->getType(
MI->getOperand(
I).getReg()) != SrcTy)
1494 report(
"G_MERGE_VALUES source types do not match",
MI);
1499 case TargetOpcode::G_UNMERGE_VALUES: {
1500 unsigned NumDsts =
MI->getNumOperands() - 1;
1501 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1502 for (
unsigned i = 1; i < NumDsts; ++i) {
1503 if (
MRI->getType(
MI->getOperand(i).getReg()) != DstTy) {
1504 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1509 LLT SrcTy =
MRI->getType(
MI->getOperand(NumDsts).getReg());
1517 report(
"G_UNMERGE_VALUES source operand does not match vector "
1518 "destination operands",
1525 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1526 "destination operands",
1531 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1532 "destination operands",
1538 case TargetOpcode::G_BUILD_VECTOR: {
1541 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1542 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1544 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1549 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1552 report(
"G_BUILD_VECTOR must have an operand for each elemement",
MI);
1555 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1556 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1560 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1563 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1564 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1566 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1569 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1570 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1573 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1578 case TargetOpcode::G_CONCAT_VECTORS: {
1581 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1582 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1584 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1587 if (
MI->getNumOperands() < 3)
1588 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1591 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1592 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1595 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1598 case TargetOpcode::G_ICMP:
1599 case TargetOpcode::G_FCMP: {
1600 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1601 LLT SrcTy =
MRI->getType(
MI->getOperand(2).getReg());
1606 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1610 case TargetOpcode::G_SCMP:
1611 case TargetOpcode::G_UCMP: {
1612 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1613 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1616 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1621 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1626 report(
"Result type must be at least 2 bits wide",
MI);
1633 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1639 case TargetOpcode::G_EXTRACT: {
1641 if (!
SrcOp.isReg()) {
1642 report(
"extract source must be a register",
MI);
1648 report(
"extract offset must be a constant",
MI);
1652 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1654 if (SrcSize == DstSize)
1655 report(
"extract source must be larger than result",
MI);
1657 if (DstSize +
OffsetOp.getImm() > SrcSize)
1658 report(
"extract reads past end of register",
MI);
1661 case TargetOpcode::G_INSERT: {
1663 if (!
SrcOp.isReg()) {
1664 report(
"insert source must be a register",
MI);
1670 report(
"insert offset must be a constant",
MI);
1674 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1677 if (DstSize <= SrcSize)
1678 report(
"inserted size must be smaller than total register",
MI);
1680 if (SrcSize +
OffsetOp.getImm() > DstSize)
1681 report(
"insert writes past end of register",
MI);
1685 case TargetOpcode::G_JUMP_TABLE: {
1686 if (!
MI->getOperand(1).isJTI())
1687 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1688 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1690 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1693 case TargetOpcode::G_BRJT: {
1694 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
1695 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1697 if (!
MI->getOperand(1).isJTI())
1698 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1700 const auto &IdxOp =
MI->getOperand(2);
1701 if (!IdxOp.isReg() ||
MRI->getType(IdxOp.getReg()).isPointer())
1702 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1705 case TargetOpcode::G_INTRINSIC:
1706 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1707 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1708 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1713 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1717 if (!verifyGIntrinsicSideEffects(
MI))
1719 if (!verifyGIntrinsicConvergence(
MI))
1724 case TargetOpcode::G_SEXT_INREG: {
1725 if (!
MI->getOperand(2).isImm()) {
1726 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1730 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1731 int64_t
Imm =
MI->getOperand(2).getImm();
1733 report(
"G_SEXT_INREG size must be >= 1",
MI);
1735 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1738 case TargetOpcode::G_BSWAP: {
1739 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1741 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1744 case TargetOpcode::G_VSCALE: {
1745 if (!
MI->getOperand(1).isCImm()) {
1746 report(
"G_VSCALE operand must be cimm",
MI);
1749 if (
MI->getOperand(1).getCImm()->isZero()) {
1750 report(
"G_VSCALE immediate cannot be zero",
MI);
1755 case TargetOpcode::G_STEP_VECTOR: {
1756 if (!
MI->getOperand(1).isCImm()) {
1757 report(
"operand must be cimm",
MI);
1761 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1762 report(
"step must be > 0",
MI);
1766 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1768 report(
"Destination type must be a scalable vector",
MI);
1774 report(
"Destination element type must be scalar",
MI);
1778 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1780 report(
"step bitwidth differs from result type element bitwidth",
MI);
1785 case TargetOpcode::G_INSERT_SUBVECTOR: {
1787 if (!Src0Op.
isReg()) {
1788 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1793 if (!Src1Op.
isReg()) {
1794 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1799 if (!IndexOp.
isImm()) {
1800 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1804 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1808 report(
"Destination type must be a vector",
MI);
1813 report(
"Second source must be a vector",
MI);
1818 report(
"Element type of vectors must be the same",
MI);
1823 report(
"Vector types must both be fixed or both be scalable",
MI);
1829 report(
"Second source must be smaller than destination vector",
MI);
1835 if (IndexOp.
getImm() % Src1MinLen != 0) {
1836 report(
"Index must be a multiple of the second source vector's "
1837 "minimum vector length",
1843 if (
Idx >= DstMinLen ||
Idx + Src1MinLen > DstMinLen) {
1844 report(
"Subvector type and index must not cause insert to overrun the "
1845 "vector being inserted into",
1852 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1854 if (!
SrcOp.isReg()) {
1855 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1860 if (!IndexOp.
isImm()) {
1861 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1865 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1869 report(
"Destination type must be a vector",
MI);
1874 report(
"Source must be a vector",
MI);
1879 report(
"Element type of vectors must be the same",
MI);
1884 report(
"Vector types must both be fixed or both be scalable",
MI);
1890 report(
"Destination vector must be smaller than source vector",
MI);
1896 if (
Idx % DstMinLen != 0) {
1897 report(
"Index must be a multiple of the destination vector's minimum "
1904 if (
Idx >= SrcMinLen ||
Idx + DstMinLen > SrcMinLen) {
1905 report(
"Destination type and index must not cause extract to overrun the "
1913 case TargetOpcode::G_SHUFFLE_VECTOR: {
1916 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1920 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1921 LLT Src0Ty =
MRI->getType(
MI->getOperand(1).getReg());
1922 LLT Src1Ty =
MRI->getType(
MI->getOperand(2).getReg());
1924 if (Src0Ty != Src1Ty)
1925 report(
"Source operands must be the same type",
MI);
1928 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1937 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1938 report(
"Wrong result type for shufflemask",
MI);
1940 for (
int Idx : MaskIdxes) {
1944 if (
Idx >= 2 * SrcNumElts)
1945 report(
"Out of bounds shuffle index",
MI);
1951 case TargetOpcode::G_SPLAT_VECTOR: {
1952 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1953 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1956 report(
"Destination type must be a scalable vector",
MI);
1961 report(
"Source type must be a scalar or pointer",
MI);
1967 report(
"Element type of the destination must be the same size or smaller "
1968 "than the source type",
1975 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1976 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1977 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1978 LLT IdxTy =
MRI->getType(
MI->getOperand(2).getReg());
1981 report(
"Destination type must be a scalar or pointer",
MI);
1986 report(
"First source must be a vector",
MI);
1990 auto TLI = MF->getSubtarget().getTargetLowering();
1991 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
1992 report(
"Index type must match VectorIdxTy",
MI);
1998 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1999 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2000 LLT VecTy =
MRI->getType(
MI->getOperand(1).getReg());
2001 LLT ScaTy =
MRI->getType(
MI->getOperand(2).getReg());
2002 LLT IdxTy =
MRI->getType(
MI->getOperand(3).getReg());
2005 report(
"Destination type must be a vector",
MI);
2009 if (VecTy != DstTy) {
2010 report(
"Destination type and vector type must match",
MI);
2015 report(
"Inserted element must be a scalar or pointer",
MI);
2019 auto TLI = MF->getSubtarget().getTargetLowering();
2020 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2021 report(
"Index type must match VectorIdxTy",
MI);
2027 case TargetOpcode::G_DYN_STACKALLOC: {
2033 report(
"dst operand 0 must be a pointer type",
MI);
2037 if (!AllocOp.
isReg() || !
MRI->getType(AllocOp.
getReg()).isScalar()) {
2038 report(
"src operand 1 must be a scalar reg type",
MI);
2042 if (!AlignOp.
isImm()) {
2043 report(
"src operand 2 must be an immediate type",
MI);
2048 case TargetOpcode::G_MEMCPY_INLINE:
2049 case TargetOpcode::G_MEMCPY:
2050 case TargetOpcode::G_MEMMOVE: {
2052 if (MMOs.
size() != 2) {
2053 report(
"memcpy/memmove must have 2 memory operands",
MI);
2059 report(
"wrong memory operand types",
MI);
2064 report(
"inconsistent memory operand sizes",
MI);
2066 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2067 LLT SrcPtrTy =
MRI->getType(
MI->getOperand(1).getReg());
2070 report(
"memory instruction operand must be a pointer",
MI);
2075 report(
"inconsistent store address space",
MI);
2077 report(
"inconsistent load address space",
MI);
2079 if (
Opc != TargetOpcode::G_MEMCPY_INLINE)
2080 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2081 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2085 case TargetOpcode::G_BZERO:
2086 case TargetOpcode::G_MEMSET: {
2088 std::string
Name =
Opc == TargetOpcode::G_MEMSET ?
"memset" :
"bzero";
2089 if (MMOs.
size() != 1) {
2090 report(
Twine(
Name,
" must have 1 memory operand"),
MI);
2095 report(
Twine(
Name,
" memory operand must be a store"),
MI);
2099 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2101 report(
Twine(
Name,
" operand must be a pointer"),
MI);
2106 report(
"inconsistent " +
Twine(
Name,
" address space"),
MI);
2108 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2109 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2110 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2114 case TargetOpcode::G_UBSANTRAP: {
2116 if (!
MI->getOperand(0).isImm()) {
2117 report(
"Crash kind must be an immediate", &KindOp, 0);
2120 int64_t
Kind =
MI->getOperand(0).getImm();
2121 if (!isInt<8>(Kind))
2122 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2125 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2126 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2127 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2128 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2129 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2131 report(
"Vector reduction requires a scalar destination type",
MI);
2133 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2135 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2138 case TargetOpcode::G_VECREDUCE_FADD:
2139 case TargetOpcode::G_VECREDUCE_FMUL:
2140 case TargetOpcode::G_VECREDUCE_FMAX:
2141 case TargetOpcode::G_VECREDUCE_FMIN:
2142 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2143 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2144 case TargetOpcode::G_VECREDUCE_ADD:
2145 case TargetOpcode::G_VECREDUCE_MUL:
2146 case TargetOpcode::G_VECREDUCE_AND:
2147 case TargetOpcode::G_VECREDUCE_OR:
2148 case TargetOpcode::G_VECREDUCE_XOR:
2149 case TargetOpcode::G_VECREDUCE_SMAX:
2150 case TargetOpcode::G_VECREDUCE_SMIN:
2151 case TargetOpcode::G_VECREDUCE_UMAX:
2152 case TargetOpcode::G_VECREDUCE_UMIN: {
2153 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2155 report(
"Vector reduction requires a scalar destination type",
MI);
2159 case TargetOpcode::G_SBFX:
2160 case TargetOpcode::G_UBFX: {
2161 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2163 report(
"Bitfield extraction is not supported on vectors",
MI);
2168 case TargetOpcode::G_SHL:
2169 case TargetOpcode::G_LSHR:
2170 case TargetOpcode::G_ASHR:
2171 case TargetOpcode::G_ROTR:
2172 case TargetOpcode::G_ROTL: {
2173 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2174 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2176 report(
"Shifts and rotates require operands to be either all scalars or "
2183 case TargetOpcode::G_LLROUND:
2184 case TargetOpcode::G_LROUND: {
2185 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2186 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2191 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2193 verifyAllRegOpsScalar(*
MI, *
MRI);
2196 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2201 case TargetOpcode::G_IS_FPCLASS: {
2202 LLT DestTy =
MRI->getType(
MI->getOperand(0).getReg());
2205 report(
"Destination must be a scalar or vector of scalars",
MI);
2208 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2211 report(
"Source must be a scalar or vector of scalars",
MI);
2214 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2217 if (!TestMO.
isImm()) {
2218 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2223 report(
"Incorrect floating-point class set (operand 2)",
MI);
2228 case TargetOpcode::G_PREFETCH: {
2230 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer()) {
2231 report(
"addr operand must be a pointer", &AddrOp, 0);
2236 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2241 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2246 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2251 case TargetOpcode::G_ASSERT_ALIGN: {
2252 if (
MI->getOperand(2).getImm() < 1)
2253 report(
"alignment immediate must be >= 1",
MI);
2256 case TargetOpcode::G_CONSTANT_POOL: {
2257 if (!
MI->getOperand(1).isCPI())
2258 report(
"Src operand 1 must be a constant pool index",
MI);
2259 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
2260 report(
"Dst operand 0 must be a pointer",
MI);
2263 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2265 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer())
2266 report(
"addr operand must be a pointer", &AddrOp, 1);
2274void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2277 report(
"Too few operands",
MI);
2279 <<
MI->getNumOperands() <<
" given.\n";
2283 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2286 if (MF->getProperties().hasNoPHIs())
2287 report(
"Found PHI instruction with NoPHIs property set",
MI);
2290 report(
"Found PHI instruction after non-PHI",
MI);
2291 }
else if (FirstNonPHI ==
nullptr)
2295 if (
MI->isInlineAsm())
2296 verifyInlineAsm(
MI);
2299 if (
TII->isUnspillableTerminator(
MI)) {
2300 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2301 report(
"Unspillable Terminator does not define a reg",
MI);
2303 if (
Def.isVirtual() && !MF->getProperties().hasNoPHIs() &&
2304 std::distance(
MRI->use_nodbg_begin(Def),
MRI->use_nodbg_end()) > 1)
2305 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2311 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2312 if (!
MI->getDebugLoc())
2313 report(
"Missing DebugLoc for debug instruction",
MI);
2317 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2318 report(
"Metadata instruction should not have a value tracking number",
MI);
2322 if (
Op->isLoad() && !
MI->mayLoad())
2323 report(
"Missing mayLoad flag",
MI);
2324 if (
Op->isStore() && !
MI->mayStore())
2325 report(
"Missing mayStore flag",
MI);
2331 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2332 if (
MI->isDebugOrPseudoInstr()) {
2334 report(
"Debug instruction has a slot index",
MI);
2335 }
else if (
MI->isInsideBundle()) {
2337 report(
"Instruction inside bundle has a slot index",
MI);
2340 report(
"Missing slot index",
MI);
2346 verifyPreISelGenericInstruction(
MI);
2355 switch (
MI->getOpcode()) {
2356 case TargetOpcode::COPY: {
2362 LLT DstTy =
MRI->getType(DstReg);
2363 LLT SrcTy =
MRI->getType(SrcReg);
2366 if (SrcTy != DstTy) {
2367 report(
"Copy Instruction is illegal with mismatching types",
MI);
2368 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2383 TRI->getMinimalPhysRegClassLLT(SrcReg, DstTy);
2385 SrcSize =
TRI->getRegSizeInBits(*SrcRC);
2390 TRI->getMinimalPhysRegClassLLT(DstReg, SrcTy);
2392 DstSize =
TRI->getRegSizeInBits(*DstRC);
2410 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2411 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2412 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2417 case TargetOpcode::STATEPOINT: {
2419 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2420 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2421 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2422 report(
"meta operands to STATEPOINT not constant!",
MI);
2426 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2427 if (
Offset >=
MI->getNumOperands()) {
2428 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2431 if (!
MI->getOperand(
Offset - 1).isImm() ||
2432 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2434 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2436 VerifyStackMapConstant(SO.getCCIdx());
2437 VerifyStackMapConstant(SO.getFlagsIdx());
2438 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2439 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2440 VerifyStackMapConstant(SO.getNumAllocaIdx());
2441 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2445 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2446 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2447 for (
unsigned Idx = 0;
Idx <
MI->getNumDefs();
Idx++) {
2449 if (!
MI->isRegTiedToUseOperand(
Idx, &UseOpIdx)) {
2450 report(
"STATEPOINT defs expected to be tied",
MI);
2453 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2454 report(
"STATEPOINT def tied to non-gc operand",
MI);
2461 case TargetOpcode::INSERT_SUBREG: {
2462 unsigned InsertedSize;
2463 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2464 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2466 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *
MRI);
2467 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2468 if (SubRegSize < InsertedSize) {
2469 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2470 "size than the subreg it was inserted into",
MI);
2474 case TargetOpcode::REG_SEQUENCE: {
2475 unsigned NumOps =
MI->getNumOperands();
2476 if (!(NumOps & 1)) {
2477 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2481 for (
unsigned I = 1;
I != NumOps;
I += 2) {
2486 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2488 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2489 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2490 report(
"Invalid subregister index operand for REG_SEQUENCE",
2495 Register DstReg =
MI->getOperand(0).getReg();
2497 report(
"REG_SEQUENCE does not support physical register results",
MI);
2499 if (
MI->getOperand(0).getSubReg())
2500 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2508MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2512 if (MCID.
getOpcode() == TargetOpcode::PATCHPOINT)
2513 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2516 if (MONum < NumDefs) {
2519 report(
"Explicit definition must be a register", MO, MONum);
2521 report(
"Explicit definition marked as use", MO, MONum);
2523 report(
"Explicit definition marked as implicit", MO, MONum);
2532 report(
"Explicit operand marked as def", MO, MONum);
2534 report(
"Explicit operand marked as implicit", MO, MONum);
2540 report(
"Expected a register operand.", MO, MONum);
2544 !
TII->isPCRelRegisterOperandLegal(*MO)))
2545 report(
"Expected a non-register operand.", MO, MONum);
2552 report(
"Tied use must be a register", MO, MONum);
2554 report(
"Operand should be tied", MO, MONum);
2555 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2556 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2559 if (!MOTied.
isReg())
2560 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2563 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2566 report(
"Explicit operand should not be tied", MO, MONum);
2567 }
else if (!
MI->isVariadic()) {
2570 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2577 if (
MI->isDebugInstr() && MO->
isUse()) {
2579 report(
"Register operand must be marked debug", MO, MONum);
2581 report(
"Register operand must not be marked debug", MO, MONum);
2587 if (
MRI->tracksLiveness() && !
MI->isDebugInstr())
2588 checkLiveness(MO, MONum);
2592 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2596 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2598 if (!OtherMO.
isReg())
2599 report(
"Must be tied to a register", MO, MONum);
2601 report(
"Missing tie flags on tied operand", MO, MONum);
2602 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2603 report(
"Inconsistent tie links", MO, MONum);
2607 report(
"Explicit def tied to explicit use without tie constraint",
2611 report(
"Explicit def should be tied to implicit use", MO, MONum);
2624 if (MF->getProperties().hasTiedOpsRewritten() && MO->
isUse() &&
2625 MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2626 Reg !=
MI->getOperand(DefIdx).getReg())
2627 report(
"Two-address instruction operands must be identical", MO, MONum);
2632 if (
Reg.isPhysical()) {
2634 report(
"Illegal subregister index for physical register", MO, MONum);
2639 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2640 if (!DRC->contains(Reg)) {
2641 report(
"Illegal physical register for instruction", MO, MONum);
2643 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2648 if (
MRI->isReserved(Reg)) {
2649 report(
"isRenamable set on reserved register", MO, MONum);
2666 report(
"Generic virtual register use cannot be undef", MO, MONum);
2673 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2674 !
MI->isDebugValue() || !
MRI->def_empty(Reg)) {
2676 if (isFunctionSelected) {
2677 report(
"Generic virtual register invalid in a Selected function",
2683 LLT Ty =
MRI->getType(Reg);
2685 report(
"Generic virtual register must have a valid type", MO,
2694 if (!RegBank && isFunctionRegBankSelected) {
2695 report(
"Generic virtual register must have a bank in a "
2696 "RegBankSelected function",
2704 report(
"Register bank is too small for virtual register", MO,
2706 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2714 report(
"Generic virtual register does not allow subregister index", MO,
2724 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2725 report(
"Virtual register does not match instruction constraint", MO,
2727 OS <<
"Expect register class "
2728 <<
TRI->getRegClassName(
TII->getRegClass(MCID, MONum,
TRI, *MF))
2729 <<
" but got nothing\n";
2737 TRI->getSubClassWithSubReg(RC, SubIdx);
2739 report(
"Invalid subregister index for virtual register", MO, MONum);
2740 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2741 <<
" does not support subreg index "
2742 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2746 report(
"Invalid register class for subregister index", MO, MONum);
2747 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2748 <<
" does not fully support subreg index "
2749 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2755 TII->getRegClass(MCID, MONum,
TRI, *MF)) {
2758 TRI->getLargestLegalSuperClass(RC, *MF);
2760 report(
"No largest legal super class exists.", MO, MONum);
2763 DRC =
TRI->getMatchingSuperRegClass(SuperRC, DRC, SubIdx);
2765 report(
"No matching super-reg register class.", MO, MONum);
2770 report(
"Illegal virtual register for instruction", MO, MONum);
2771 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2772 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2787 report(
"PHI operand is not in the CFG", MO, MONum);
2791 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2792 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2803 for (
auto *MMO :
MI->memoperands()) {
2805 if (PSV ==
nullptr)
continue;
2807 dyn_cast<FixedStackPseudoSourceValue>(PSV);
2808 if (
Value ==
nullptr)
continue;
2809 if (
Value->getFrameIndex() != FI)
continue;
2818 report(
"Missing fixed stack memoperand.",
MI);
2821 report(
"Instruction loads from dead spill slot", MO, MONum);
2822 OS <<
"Live stack: " << LI <<
'\n';
2825 report(
"Instruction stores to dead spill slot", MO, MONum);
2826 OS <<
"Live stack: " << LI <<
'\n';
2832 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2833 report(
"CFI instruction has invalid index", MO, MONum);
2841void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2849 report(
"invalid live range", MO, MONum);
2850 report_context_liverange(LR);
2851 report_context_vreg_regunit(VRegOrUnit);
2852 report_context(UseIdx);
2861 report(
"No live segment at use", MO, MONum);
2862 report_context_liverange(LR);
2863 report_context_vreg_regunit(VRegOrUnit);
2864 report_context(UseIdx);
2867 report(
"Live range continues after kill flag", MO, MONum);
2868 report_context_liverange(LR);
2869 report_context_vreg_regunit(VRegOrUnit);
2871 report_context_lanemask(LaneMask);
2872 report_context(UseIdx);
2876void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2883 report(
"invalid live range", MO, MONum);
2884 report_context_liverange(LR);
2885 report_context_vreg_regunit(VRegOrUnit);
2887 report_context_lanemask(LaneMask);
2888 report_context(DefIdx);
2900 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
2902 (VNI->def != DefIdx &&
2903 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
2904 report(
"Inconsistent valno->def", MO, MONum);
2905 report_context_liverange(LR);
2906 report_context_vreg_regunit(VRegOrUnit);
2908 report_context_lanemask(LaneMask);
2909 report_context(*VNI);
2910 report_context(DefIdx);
2913 report(
"No live segment at def", MO, MONum);
2914 report_context_liverange(LR);
2915 report_context_vreg_regunit(VRegOrUnit);
2917 report_context_lanemask(LaneMask);
2918 report_context(DefIdx);
2930 if (SubRangeCheck || MO->
getSubReg() == 0) {
2931 report(
"Live range continues after dead def flag", MO, MONum);
2932 report_context_liverange(LR);
2933 report_context_vreg_regunit(VRegOrUnit);
2935 report_context_lanemask(LaneMask);
2941void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
2944 const unsigned SubRegIdx = MO->
getSubReg();
2947 if (LiveInts &&
Reg.isVirtual()) {
2948 if (LiveInts->hasInterval(Reg)) {
2949 LI = &LiveInts->getInterval(Reg);
2952 report(
"Live interval for subreg operand has no subranges", MO, MONum);
2954 report(
"Virtual register has no live interval", MO, MONum);
2961 addRegWithSubRegs(regsKilled, Reg);
2966 if (LiveVars &&
Reg.isVirtual() && MO->
isKill() &&
2967 !
MI->isBundledWithPred()) {
2970 report(
"Kill missing from LiveVariables", MO, MONum);
2974 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2978 UseIdx = LiveInts->getMBBEndIdx(
2979 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
2981 UseIdx = LiveInts->getInstructionIndex(*
MI);
2984 if (
Reg.isPhysical() && !isReserved(Reg)) {
2986 if (
MRI->isReservedRegUnit(Unit))
2988 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
2989 checkLivenessAtUse(MO, MONum, UseIdx, *LR,
VirtRegOrUnit(Unit));
2993 if (
Reg.isVirtual()) {
2995 checkLivenessAtUse(MO, MONum, UseIdx, *LI,
VirtRegOrUnit(Reg));
2999 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3000 :
MRI->getMaxLaneMaskForVReg(Reg);
3003 if ((MOMask & SR.LaneMask).none())
3005 checkLivenessAtUse(MO, MONum, UseIdx, SR,
VirtRegOrUnit(Reg),
3009 LiveInMask |= SR.LaneMask;
3012 if ((LiveInMask & MOMask).
none()) {
3013 report(
"No live subrange at use", MO, MONum);
3014 report_context(*LI);
3015 report_context(UseIdx);
3018 if (
MI->isPHI() && LiveInMask != MOMask) {
3019 report(
"Not all lanes of PHI source live at use", MO, MONum);
3020 report_context(*LI);
3021 report_context(UseIdx);
3028 if (!regsLive.count(Reg)) {
3029 if (
Reg.isPhysical()) {
3031 bool Bad = !isReserved(Reg);
3036 if (regsLive.count(
SubReg)) {
3048 if (!MOP.isReg() || !MOP.isImplicit())
3051 if (!MOP.getReg().isPhysical())
3054 if (MOP.getReg() != Reg &&
3056 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3063 report(
"Using an undefined physical register", MO, MONum);
3064 }
else if (
MRI->def_empty(Reg)) {
3065 report(
"Reading virtual register without a def", MO, MONum);
3067 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3071 if (MInfo.regsKilled.count(Reg))
3072 report(
"Using a killed virtual register", MO, MONum);
3073 else if (!
MI->isPHI())
3074 MInfo.vregsLiveIn.insert(std::make_pair(Reg,
MI));
3083 addRegWithSubRegs(regsDead, Reg);
3085 addRegWithSubRegs(regsDefined, Reg);
3088 if (
MRI->isSSA() &&
Reg.isVirtual() &&
3089 std::next(
MRI->def_begin(Reg)) !=
MRI->def_end())
3090 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3093 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3094 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3097 if (
Reg.isVirtual()) {
3098 checkLivenessAtDef(MO, MONum, DefIdx, *LI,
VirtRegOrUnit(Reg));
3102 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3103 :
MRI->getMaxLaneMaskForVReg(Reg);
3105 if ((SR.LaneMask & MOMask).none())
3107 checkLivenessAtDef(MO, MONum, DefIdx, SR,
VirtRegOrUnit(Reg),
true,
3120void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3121 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3122 set_union(MInfo.regsKilled, regsKilled);
3123 set_subtract(regsLive, regsKilled); regsKilled.clear();
3125 while (!regMasks.empty()) {
3128 if (
Reg.isPhysical() &&
3130 regsDead.push_back(Reg);
3133 set_union(regsLive, regsDefined); regsDefined.clear();
3138 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3143 if (!(stop > lastIndex)) {
3144 report(
"Block ends before last instruction index",
MBB);
3145 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3161 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3163 filterAndAdd(FromRegSet, VRegsBuffer);
3168 template <
typename RegSetT>
3169 bool filterAndAdd(
const RegSetT &FromRegSet,
3171 unsigned SparseUniverse = Sparse.size();
3172 unsigned NewSparseUniverse = SparseUniverse;
3173 unsigned NewDenseSize =
Dense.size();
3174 size_t Begin = ToVRegs.
size();
3179 if (
Index < SparseUniverseMax) {
3180 if (
Index < SparseUniverse && Sparse.test(
Index))
3182 NewSparseUniverse = std::max(NewSparseUniverse,
Index + 1);
3197 Sparse.resize(NewSparseUniverse);
3198 Dense.reserve(NewDenseSize);
3199 for (
unsigned I = Begin;
I <
End; ++
I) {
3202 if (
Index < SparseUniverseMax)
3211 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3231class FilteringVRegSet {
3238 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3243 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3246 return Filter.filterAndAdd(RS, VRegs);
3251 size_t size()
const {
return VRegs.
size(); }
3258void MachineVerifier::calcRegsPassed() {
3265 FilteringVRegSet VRegs;
3266 BBInfo &
Info = MBBInfoMap[MB];
3269 VRegs.addToFilter(
Info.regsKilled);
3270 VRegs.addToFilter(
Info.regsLiveOut);
3272 const BBInfo &PredInfo = MBBInfoMap[Pred];
3273 if (!PredInfo.reachable)
3276 VRegs.add(PredInfo.regsLiveOut);
3277 VRegs.add(PredInfo.vregsPassed);
3279 Info.vregsPassed.reserve(VRegs.size());
3280 Info.vregsPassed.insert_range(VRegs);
3287void MachineVerifier::calcRegsRequired() {
3290 for (
const auto &
MBB : *MF) {
3291 BBInfo &MInfo = MBBInfoMap[&
MBB];
3293 BBInfo &PInfo = MBBInfoMap[Pred];
3294 if (PInfo.addRequired(MInfo.vregsLiveIn))
3300 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3302 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3309 BBInfo &PInfo = MBBInfoMap[Pred];
3310 if (PInfo.addRequired(Reg))
3318 while (!todo.
empty()) {
3321 BBInfo &MInfo = MBBInfoMap[
MBB];
3325 BBInfo &SInfo = MBBInfoMap[Pred];
3326 if (SInfo.addRequired(MInfo.vregsRequired))
3335 BBInfo &MInfo = MBBInfoMap[&
MBB];
3345 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3350 report(
"Unexpected flag on PHI operand", &MODef, 0);
3353 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3355 for (
unsigned I = 1, E =
Phi.getNumOperands();
I != E;
I += 2) {
3358 report(
"Expected PHI operand to be a register", &MO0,
I);
3363 report(
"Unexpected flag on PHI operand", &MO0,
I);
3367 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3373 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3377 if (MInfo.reachable) {
3379 BBInfo &PrInfo = MBBInfoMap[&Pre];
3380 if (!MO0.
isUndef() && PrInfo.reachable &&
3381 !PrInfo.isLiveOut(MO0.
getReg()))
3382 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3387 if (MInfo.reachable) {
3389 if (!seen.
count(Pred)) {
3390 report(
"Missing PHI operand", &Phi);
3392 <<
" is a predecessor according to the CFG.\n";
3401 std::function<
void(
const Twine &Message)> FailureCB,
3406 for (
const auto &
MBB : MF) {
3418void MachineVerifier::visitMachineFunctionAfter() {
3419 auto FailureCB = [
this](
const Twine &Message) {
3420 report(Message.str().c_str(), MF);
3433 for (
const auto &
MBB : *MF) {
3434 BBInfo &MInfo = MBBInfoMap[&
MBB];
3435 for (
Register VReg : MInfo.vregsRequired)
3436 if (MInfo.regsKilled.count(VReg)) {
3437 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3439 <<
" is used after the block.\n";
3444 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3445 for (
Register VReg : MInfo.vregsRequired) {
3446 report(
"Virtual register defs don't dominate all uses.", MF);
3447 report_context_vreg(VReg);
3452 verifyLiveVariables();
3454 verifyLiveIntervals();
3463 if (
MRI->tracksLiveness())
3464 for (
const auto &
MBB : *MF)
3468 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3471 BBInfo &PInfo = MBBInfoMap[Pred];
3472 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3473 report(
"Live in register not found to be live out from predecessor.",
3475 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3481 for (
auto CSInfo : MF->getCallSitesInfo())
3482 if (!CSInfo.first->isCall())
3483 report(
"Call site info referencing instruction that is not call", MF);
3487 if (MF->getFunction().getSubprogram()) {
3489 for (
const auto &
MBB : *MF) {
3490 for (
const auto &
MI :
MBB) {
3491 if (
auto Num =
MI.peekDebugInstrNum()) {
3494 report(
"Instruction has a duplicated value tracking number", &
MI);
3501void MachineVerifier::verifyLiveVariables() {
3502 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3503 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3506 for (
const auto &
MBB : *MF) {
3507 BBInfo &MInfo = MBBInfoMap[&
MBB];
3510 if (MInfo.vregsRequired.count(Reg)) {
3512 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3514 <<
" must be live through the block.\n";
3518 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3520 <<
" is not needed live through the block.\n";
3527void MachineVerifier::verifyLiveIntervals() {
3528 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3529 for (
unsigned I = 0, E =
MRI->getNumVirtRegs();
I != E; ++
I) {
3533 if (
MRI->reg_nodbg_empty(Reg))
3536 if (!LiveInts->hasInterval(Reg)) {
3537 report(
"Missing live interval for virtual register", MF);
3543 assert(Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3544 verifyLiveInterval(LI);
3548 for (
unsigned i = 0, e =
TRI->getNumRegUnits(); i != e; ++i)
3549 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(i))
3553void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3563 report(
"Value not live at VNInfo def and not marked unused", MF);
3564 report_context(LR, VRegOrUnit, LaneMask);
3565 report_context(*VNI);
3569 if (DefVNI != VNI) {
3570 report(
"Live segment at def has different VNInfo", MF);
3571 report_context(LR, VRegOrUnit, LaneMask);
3572 report_context(*VNI);
3578 report(
"Invalid VNInfo definition index", MF);
3579 report_context(LR, VRegOrUnit, LaneMask);
3580 report_context(*VNI);
3585 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3586 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3587 report_context(LR, VRegOrUnit, LaneMask);
3588 report_context(*VNI);
3596 report(
"No instruction at VNInfo def index",
MBB);
3597 report_context(LR, VRegOrUnit, LaneMask);
3598 report_context(*VNI);
3602 bool hasDef =
false;
3603 bool isEarlyClobber =
false;
3605 if (!MOI->isReg() || !MOI->isDef())
3611 if (!MOI->getReg().isPhysical() ||
3615 if (LaneMask.
any() &&
3616 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3619 if (MOI->isEarlyClobber())
3620 isEarlyClobber =
true;
3624 report(
"Defining instruction does not modify register",
MI);
3625 report_context(LR, VRegOrUnit, LaneMask);
3626 report_context(*VNI);
3631 if (isEarlyClobber) {
3633 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3634 report_context(LR, VRegOrUnit, LaneMask);
3635 report_context(*VNI);
3638 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3639 report_context(LR, VRegOrUnit, LaneMask);
3640 report_context(*VNI);
3644void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3650 assert(VNI &&
"Live segment has no valno");
3653 report(
"Foreign valno in live segment", MF);
3654 report_context(LR, VRegOrUnit, LaneMask);
3656 report_context(*VNI);
3660 report(
"Live segment valno is marked unused", MF);
3661 report_context(LR, VRegOrUnit, LaneMask);
3667 report(
"Bad start of live segment, no basic block", MF);
3668 report_context(LR, VRegOrUnit, LaneMask);
3674 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3675 report_context(LR, VRegOrUnit, LaneMask);
3682 report(
"Bad end of live segment, no basic block", MF);
3683 report_context(LR, VRegOrUnit, LaneMask);
3689 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3699 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3700 report_context(LR, VRegOrUnit, LaneMask);
3707 report(
"Live segment ends at B slot of an instruction", EndMBB);
3708 report_context(LR, VRegOrUnit, LaneMask);
3716 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3717 report_context(LR, VRegOrUnit, LaneMask);
3727 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3728 report(
"Live segment ending at early clobber slot must be "
3729 "redefined by an EC def in the same instruction",
3731 report_context(LR, VRegOrUnit, LaneMask);
3741 bool hasRead =
false;
3742 bool hasSubRegDef =
false;
3743 bool hasDeadDef =
false;
3745 if (!MOI->isReg() || MOI->getReg() != VRegOrUnit.
asVirtualReg())
3747 unsigned Sub = MOI->getSubReg();
3752 hasSubRegDef =
true;
3761 if (LaneMask.
any() && (LaneMask & SLM).none())
3763 if (MOI->readsReg())
3770 if (LaneMask.
none() && !hasDeadDef) {
3772 "Instruction ending live segment on dead slot has no dead flag",
3774 report_context(LR, VRegOrUnit, LaneMask);
3782 LaneMask.
any() || !hasSubRegDef) {
3783 report(
"Instruction ending live segment doesn't read the register",
3785 report_context(LR, VRegOrUnit, LaneMask);
3805 if (LaneMask.
any()) {
3811 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3814 if (&*MFI == EndMBB)
3822 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3826 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3828 if (MFI->isEHPad()) {
3831 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3842 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3845 report(
"Register not marked live out of predecessor", Pred);
3846 report_context(LR, VRegOrUnit, LaneMask);
3847 report_context(*VNI);
3849 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3855 if (!IsPHI && PVNI != VNI) {
3856 report(
"Different value live out of predecessor", Pred);
3857 report_context(LR, VRegOrUnit, LaneMask);
3858 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3861 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3864 if (&*MFI == EndMBB)
3870void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
3874 verifyLiveRangeValue(LR, VNI, VRegOrUnit, LaneMask);
3877 verifyLiveRangeSegment(LR,
I, VRegOrUnit, LaneMask);
3880void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3889 if ((Mask & SR.LaneMask).any()) {
3890 report(
"Lane masks of sub ranges overlap in live interval", MF);
3893 if ((SR.LaneMask & ~MaxMask).any()) {
3894 report(
"Subrange lanemask is invalid", MF);
3898 report(
"Subrange must not be empty", MF);
3901 Mask |= SR.LaneMask;
3904 report(
"A Subrange is not covered by the main range", MF);
3912 unsigned NumComp = ConEQ.Classify(LI);
3914 report(
"Multiple connected components in live interval", MF);
3916 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3917 OS << comp <<
": valnos";
3919 if (comp == ConEQ.getEqClass(
I))
3932struct StackStateOfBB {
3933 StackStateOfBB() =
default;
3934 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
3935 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
3936 ExitIsSetup(ExitSetup) {}
3941 bool EntryIsSetup =
false;
3942 bool ExitIsSetup =
false;
3950void MachineVerifier::verifyStackFrame() {
3951 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
3952 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
3953 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
3957 SPState.
resize(MF->getNumBlockIDs());
3964 DFI != DFE; ++DFI) {
3967 StackStateOfBB BBState;
3969 if (DFI.getPathLength() >= 2) {
3972 "DFS stack predecessor is already visited.\n");
3973 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
3974 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
3975 BBState.ExitValue = BBState.EntryValue;
3976 BBState.ExitIsSetup = BBState.EntryIsSetup;
3980 report(
"Call frame size on entry does not match value computed from "
3984 <<
" does not match value computed from predecessor "
3985 << -BBState.EntryValue <<
'\n';
3989 for (
const auto &
I : *
MBB) {
3990 if (
I.getOpcode() == FrameSetupOpcode) {
3991 if (BBState.ExitIsSetup)
3992 report(
"FrameSetup is after another FrameSetup", &
I);
3993 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
3994 report(
"AdjustsStack not set in presence of a frame pseudo "
3995 "instruction.", &
I);
3996 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
3997 BBState.ExitIsSetup =
true;
4000 if (
I.getOpcode() == FrameDestroyOpcode) {
4001 int Size =
TII->getFrameTotalSize(
I);
4002 if (!BBState.ExitIsSetup)
4003 report(
"FrameDestroy is not after a FrameSetup", &
I);
4004 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
4006 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
4007 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
4008 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
4009 << AbsSPAdj <<
">.\n";
4011 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
4012 report(
"AdjustsStack not set in presence of a frame pseudo "
4013 "instruction.", &
I);
4014 BBState.ExitValue +=
Size;
4015 BBState.ExitIsSetup =
false;
4023 if (Reachable.
count(Pred) &&
4024 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4025 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4026 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4028 << SPState[Pred->
getNumber()].ExitValue <<
", "
4029 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4031 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4038 if (Reachable.
count(Succ) &&
4039 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4040 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4041 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4043 << SPState[Succ->getNumber()].EntryValue <<
", "
4044 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4046 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4052 if (BBState.ExitIsSetup)
4053 report(
"A return block ends with a FrameSetup.",
MBB);
4054 if (BBState.ExitValue)
4055 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
4060void MachineVerifier::verifyStackProtector() {
4069 bool StackGrowsDown =
4096 if (SPStart < ObjEnd && ObjStart < SPEnd) {
4097 report(
"Stack protector overlaps with another stack object", MF);
4100 if ((StackGrowsDown && SPStart <= ObjStart) ||
4101 (!StackGrowsDown && SPStart >= ObjStart)) {
4102 report(
"Stack protector is not the top-most object on the stack", MF);
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
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.
Register 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_>.
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
std::unordered_set< BasicBlock * > BlockSet
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.
IntegerType * getIntegerType() const
Variant of the getType() method to always return an IntegerType, which reduces the amount of casting ...
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.
void insert_range(Range &&R)
Inserts range of 'std::pair<KeyT, ValueT>' values into the map.
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....
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
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
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
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()
LLVM_ABI 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.
LLVM_ABI 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
LLVM_ABI 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.
LLVM_ABI 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.
Wrapper class representing physical registers. Should be passed by value.
const MDOperand & getOperand(unsigned I) const
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.
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.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
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()
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int getStackProtectorIndex() const
Return the index for the stack protector object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
LLVM_ABI BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Properties which a MachineFunction may have at a given point in time.
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
LLT getMemoryType() const
Return the memory type of the memory reference.
const MDNode * getRanges() const
Return the range tag for the memory reference.
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
LLVM_ABI void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr) const
Print the MachineOperand to os.
unsigned getCFIIndex() const
LLVM_ABI 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.
@ 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,...
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static LLVM_ABI 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.
unsigned virtRegIndex() const
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.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SlotIndex - An opaque wrapper around machine indexes.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level Statepoint operands.
StringRef - Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
TargetInstrInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI 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.
Wrapper class representing a virtual register or register unit.
constexpr bool isVirtualReg() const
constexpr MCRegUnit asMCRegUnit() const
constexpr Register asVirtualReg() const
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.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function 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
LLVM_ABI const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
LLVM_ABI const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
@ 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.
LLVM_ABI 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,...
LLVM_ABI FunctionPass * createMachineVerifierPass(const std::string &Banner)
createMachineVerifierPass - This pass verifies cenerated machine code instructions for correctness.
LLVM_ABI void verifyMachineFunction(const std::string &Banner, const MachineFunction &MF)
auto reverse(ContainerTy &&C)
LLVM_ABI void initializeMachineVerifierLegacyPassPass(PassRegistry &)
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI 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.
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Sub
Subtraction of integers.
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)
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Implement std::hash so that hash_code can be used in STL containers.
static LLVM_ABI 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.