87 struct MachineVerifier {
88 MachineVerifier(
Pass *
pass,
const char *b) : PASS(pass), Banner(b) {}
100 unsigned foundErrors;
103 bool isFunctionRegBankSelected;
104 bool isFunctionSelected;
114 BlockSet FunctionBlocks;
118 RegVector regsDefined, regsDead, regsKilled;
119 RegMaskVector regMasks;
124 void addRegWithSubRegs(RegVector &RV,
unsigned Reg) {
128 RV.push_back(*SubRegs);
133 bool reachable =
false;
153 RegSet vregsRequired;
156 BlockSet Preds, Succs;
162 bool addPassed(
unsigned Reg) {
165 if (regsKilled.count(Reg) || regsLiveOut.count(Reg))
167 return vregsPassed.insert(Reg).second;
171 bool addPassed(
const RegSet &RS) {
172 bool changed =
false;
173 for (RegSet::const_iterator
I = RS.begin(),
E = RS.end();
I !=
E; ++
I)
181 bool addRequired(
unsigned Reg) {
184 if (regsLiveOut.count(Reg))
186 return vregsRequired.insert(Reg).second;
190 bool addRequired(
const RegSet &RS) {
191 bool changed =
false;
192 for (RegSet::const_iterator
I = RS.begin(),
E = RS.end();
I !=
E; ++
I)
199 bool addRequired(
const RegMap &
RM) {
200 bool changed =
false;
201 for (RegMap::const_iterator
I = RM.begin(),
E = RM.end();
I !=
E; ++
I)
202 if (addRequired(
I->first))
209 return regsLiveOut.count(Reg) || vregsPassed.count(Reg);
216 bool isReserved(
unsigned Reg) {
217 return Reg < regsReserved.
size() && regsReserved.
test(Reg);
220 bool isAllocatable(
unsigned Reg)
const {
222 !regsReserved.
test(Reg);
231 void visitMachineFunctionBefore();
235 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
239 void visitMachineFunctionAfter();
244 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
248 void report_context(
const LiveRange &LR,
unsigned VRegUnit,
251 void report_context(
const VNInfo &VNI)
const;
252 void report_context(
SlotIndex Pos)
const;
253 void report_context(
MCPhysReg PhysReg)
const;
254 void report_context_liverange(
const LiveRange &LR)
const;
255 void report_context_lanemask(
LaneBitmask LaneMask)
const;
256 void report_context_vreg(
unsigned VReg)
const;
257 void report_context_vreg_regunit(
unsigned VRegOrUnit)
const;
267 bool SubRangeCheck =
false,
271 void calcRegsPassed();
274 void calcRegsRequired();
275 void verifyLiveVariables();
276 void verifyLiveIntervals();
280 void verifyLiveRangeSegment(
const LiveRange&,
283 void verifyLiveRange(
const LiveRange&,
unsigned,
286 void verifyStackFrame();
288 void verifySlotIndexes()
const;
295 const std::string Banner;
297 MachineVerifierPass(std::string banner = std::string())
308 unsigned FoundErrors = MachineVerifier(
this, Banner.c_str()).
verify(MF);
320 "Verify generated machine code",
false,
false)
323 return new MachineVerifierPass(Banner);
329 unsigned FoundErrors = MachineVerifier(p, Banner).verify(MF);
330 if (AbortOnErrors && FoundErrors)
332 return FoundErrors == 0;
335 void MachineVerifier::verifySlotIndexes()
const {
336 if (Indexes ==
nullptr)
355 report(
"Function has NoVRegs property but there are VReg operands", &MF);
373 if (isFunctionFailedISel)
376 isFunctionRegBankSelected =
377 !isFunctionFailedISel &&
380 isFunctionSelected = !isFunctionFailedISel &&
398 verifyProperties(MF);
400 visitMachineFunctionBefore();
403 visitMachineBasicBlockBefore(&*MFI);
407 bool InBundle =
false;
410 MBBE = MFI->instr_end(); MBBI != MBBE; ++MBBI) {
411 if (MBBI->getParent() != &*MFI) {
412 report(
"Bad instruction parent pointer", &*MFI);
413 errs() <<
"Instruction: " << *MBBI;
418 if (InBundle && !MBBI->isBundledWithPred())
419 report(
"Missing BundledPred flag, " 420 "BundledSucc was set on predecessor",
422 if (!InBundle && MBBI->isBundledWithPred())
423 report(
"BundledPred flag is set, " 424 "but BundledSucc not set on predecessor",
428 if (!MBBI->isInsideBundle()) {
430 visitMachineBundleAfter(CurBundle);
432 visitMachineBundleBefore(CurBundle);
433 }
else if (!CurBundle)
434 report(
"No bundle header", &*MBBI);
435 visitMachineInstrBefore(&*MBBI);
436 for (
unsigned I = 0,
E = MBBI->getNumOperands();
I !=
E; ++
I) {
442 report(
"Instruction has operand with wrong parent set", &MI);
445 visitMachineOperand(&Op,
I);
448 visitMachineInstrAfter(&*MBBI);
451 InBundle = MBBI->isBundledWithSucc();
454 visitMachineBundleAfter(CurBundle);
456 report(
"BundledSucc flag set on last instruction in block", &MFI->back());
457 visitMachineBasicBlockAfter(&*MFI);
459 visitMachineFunctionAfter();
472 void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
475 if (!foundErrors++) {
477 errs() <<
"# " << Banner <<
'\n';
478 if (LiveInts !=
nullptr)
483 errs() <<
"*** Bad machine code: " << msg <<
" ***\n" 484 <<
"- function: " << MF->
getName() <<
"\n";
491 << MBB->
getName() <<
" (" << (
const void *)MBB <<
')';
498 void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
501 errs() <<
"- instruction: ";
502 if (Indexes && Indexes->
hasIndex(*MI))
507 void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
508 unsigned MONum,
LLT MOVRegType) {
511 errs() <<
"- operand " << MONum <<
": ";
516 void MachineVerifier::report_context(
SlotIndex Pos)
const {
517 errs() <<
"- at: " << Pos <<
'\n';
520 void MachineVerifier::report_context(
const LiveInterval &LI)
const {
521 errs() <<
"- interval: " << LI <<
'\n';
524 void MachineVerifier::report_context(
const LiveRange &LR,
unsigned VRegUnit,
526 report_context_liverange(LR);
527 report_context_vreg_regunit(VRegUnit);
529 report_context_lanemask(LaneMask);
533 errs() <<
"- segment: " << S <<
'\n';
536 void MachineVerifier::report_context(
const VNInfo &VNI)
const {
537 errs() <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
540 void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
541 errs() <<
"- liverange: " << LR <<
'\n';
544 void MachineVerifier::report_context(
MCPhysReg PReg)
const {
545 errs() <<
"- p. register: " <<
printReg(PReg, TRI) <<
'\n';
548 void MachineVerifier::report_context_vreg(
unsigned VReg)
const {
549 errs() <<
"- v. register: " <<
printReg(VReg, TRI) <<
'\n';
552 void MachineVerifier::report_context_vreg_regunit(
unsigned VRegOrUnit)
const {
554 report_context_vreg(VRegOrUnit);
560 void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
565 BBInfo &MInfo = MBBInfoMap[MBB];
566 if (!MInfo.reachable) {
567 MInfo.reachable =
true;
569 SuE = MBB->
succ_end(); SuI != SuE; ++SuI)
574 void MachineVerifier::visitMachineFunctionBefore() {
580 markReachable(&MF->
front());
583 FunctionBlocks.
clear();
584 for (
const auto &MBB : *MF) {
585 FunctionBlocks.insert(&MBB);
586 BBInfo &MInfo = MBBInfoMap[&MBB];
589 if (MInfo.Preds.size() != MBB.
pred_size())
590 report(
"MBB has duplicate entries in its predecessor list.", &MBB);
593 if (MInfo.Succs.size() != MBB.
succ_size())
594 report(
"MBB has duplicate entries in its successor list.", &MBB);
616 FirstTerminator =
nullptr;
617 FirstNonPHI =
nullptr;
623 for (
const auto &LI : MBB->
liveins()) {
624 if (isAllocatable(LI.PhysReg) && !MBB->
isEHPad() &&
626 report(
"MBB has allocatable live-in, but isn't entry or landing-pad.", MBB);
627 report_context(LI.PhysReg);
638 if (!FunctionBlocks.count(*
I))
639 report(
"MBB has successor that isn't part of the function.", MBB);
640 if (!MBBInfoMap[*
I].Preds.
count(MBB)) {
641 report(
"Inconsistent CFG", MBB);
642 errs() <<
"MBB is not in the predecessor list of the successor " 650 if (!FunctionBlocks.count(*
I))
651 report(
"MBB has predecessor that isn't part of the function.", MBB);
652 if (!MBBInfoMap[*
I].Succs.
count(MBB)) {
653 report(
"Inconsistent CFG", MBB);
654 errs() <<
"MBB is not in the successor list of the predecessor " 662 if (LandingPadSuccs.
size() > 1 &&
667 report(
"MBB has more than one landing pad successor", MBB);
672 if (!TII->
analyzeBranch(*const_cast<MachineBasicBlock *>(MBB), TBB, FBB,
680 if (MBBI == MF->
end()) {
689 report(
"MBB exits via unconditional fall-through but doesn't have " 690 "exactly one CFG successor!", MBB);
692 report(
"MBB exits via unconditional fall-through but its successor " 693 "differs from its CFG successor!", MBB);
697 report(
"MBB exits via unconditional fall-through but ends with a " 698 "barrier instruction!", MBB);
701 report(
"MBB exits via unconditional fall-through but has a condition!",
704 }
else if (TBB && !FBB && Cond.
empty()) {
711 report(
"MBB exits via unconditional branch but doesn't have " 712 "exactly one CFG successor!", MBB);
714 report(
"MBB exits via unconditional branch but the CFG " 715 "successor doesn't match the actual successor!", MBB);
718 report(
"MBB exits via unconditional branch but doesn't contain " 719 "any instructions!", MBB);
721 report(
"MBB exits via unconditional branch but doesn't end with a " 722 "barrier instruction!", MBB);
724 report(
"MBB exits via unconditional branch but the branch isn't a " 725 "terminator instruction!", MBB);
727 }
else if (TBB && !FBB && !Cond.
empty()) {
731 if (MBBI == MF->
end()) {
732 report(
"MBB conditionally falls through out of function!", MBB);
736 report(
"MBB exits via conditional branch/fall-through but only has " 737 "one CFG successor!", MBB);
739 report(
"MBB exits via conditional branch/fall-through but the CFG " 740 "successor don't match the actual successor!", MBB);
742 report(
"MBB exits via conditional branch/fall-through but doesn't have " 743 "exactly two CFG successors!", MBB);
745 report(
"MBB exits via conditional branch/fall-through but the CFG " 746 "successors don't match the actual successors!", MBB);
749 report(
"MBB exits via conditional branch/fall-through but doesn't " 750 "contain any instructions!", MBB);
752 report(
"MBB exits via conditional branch/fall-through but ends with a " 753 "barrier instruction!", MBB);
755 report(
"MBB exits via conditional branch/fall-through but the branch " 756 "isn't a terminator instruction!", MBB);
758 }
else if (TBB && FBB) {
764 report(
"MBB exits via conditional branch/branch through but only has " 765 "one CFG successor!", MBB);
767 report(
"MBB exits via conditional branch/branch through but the CFG " 768 "successor don't match the actual successor!", MBB);
770 report(
"MBB exits via conditional branch/branch but doesn't have " 771 "exactly two CFG successors!", MBB);
773 report(
"MBB exits via conditional branch/branch but the CFG " 774 "successors don't match the actual successors!", MBB);
777 report(
"MBB exits via conditional branch/branch but doesn't " 778 "contain any instructions!", MBB);
780 report(
"MBB exits via conditional branch/branch but doesn't end with a " 781 "barrier instruction!", MBB);
783 report(
"MBB exits via conditional branch/branch but the branch " 784 "isn't a terminator instruction!", MBB);
787 report(
"MBB exits via conditional branch/branch but there's no " 791 report(
"AnalyzeBranch returned invalid data!", MBB);
797 for (
const auto &LI : MBB->
liveins()) {
799 report(
"MBB live-in list contains non-physical register", MBB);
804 regsLive.insert(*SubRegs);
813 regsLive.insert(*SubRegs);
825 void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *MI) {
826 if (Indexes && Indexes->
hasIndex(*MI)) {
828 if (!(idx > lastIndex)) {
829 report(
"Instruction index out of order", MI);
830 errs() <<
"Last instruction was at " << lastIndex <<
'\n';
839 if (!FirstTerminator)
840 FirstTerminator =
MI;
841 }
else if (FirstTerminator) {
842 report(
"Non-terminator instruction after the first terminator", MI);
843 errs() <<
"First terminator was:\t" << *FirstTerminator;
849 void MachineVerifier::verifyInlineAsm(
const MachineInstr *MI) {
852 report(
"Too few operands on inline asm", MI);
856 report(
"Asm string must be an external symbol", MI);
858 report(
"Asm flags must be an immediate", MI);
863 report(
"Unknown asm flags", &MI->
getOperand(1), 1);
869 for (
unsigned e = MI->
getNumOperands(); OpNo < e; OpNo += NumOps) {
878 report(
"Missing operands in last group", MI);
888 report(
"Expected implicit register after groups", &MO, OpNo);
892 void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *MI) {
895 report(
"Too few operands", MI);
903 report(
"Found PHI instruction with NoPHIs property set", MI);
906 report(
"Found PHI instruction after non-PHI", MI);
907 }
else if (FirstNonPHI ==
nullptr)
918 if ((*I)->isLoad() && !MI->
mayLoad())
919 report(
"Missing mayLoad flag", MI);
920 if ((*I)->isStore() && !MI->
mayStore())
921 report(
"Missing mayStore flag", MI);
930 report(
"Debug instruction has a slot index", MI);
933 report(
"Instruction inside bundle has a slot index", MI);
936 report(
"Missing slot index", MI);
941 if (isFunctionSelected)
942 report(
"Unexpected generic instruction in a Selected function", MI);
961 if (!Types[TypeIdx].isValid())
962 Types[TypeIdx] = OpTy;
963 else if (Types[TypeIdx] != OpTy)
964 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
967 report(
"Generic instruction is missing a virtual register type", MO,
I);
975 report(
"Generic instruction cannot have physical register", MO,
I);
981 report(ErrorInfo.
data(),
MI);
987 case TargetOpcode::G_LOAD:
988 case TargetOpcode::G_STORE:
992 report(
"Generic instruction accessing memory must have one mem operand",
995 case TargetOpcode::G_PHI: {
1003 if (!Ty.
isValid() || (Ty != DstTy))
1007 report(
"Generic Instruction G_PHI has operands with incompatible/missing " 1012 case TargetOpcode::G_SEXT:
1013 case TargetOpcode::G_ZEXT:
1014 case TargetOpcode::G_ANYEXT:
1015 case TargetOpcode::G_TRUNC:
1016 case TargetOpcode::G_FPEXT:
1017 case TargetOpcode::G_FPTRUNC: {
1034 report(
"Generic extend/truncate can not operate on pointers", MI);
1037 report(
"Generic extend/truncate must be all-vector or all-scalar", MI);
1046 report(
"Generic vector extend/truncate must preserve number of lanes",
1052 if (DstSize <= SrcSize)
1053 report(
"Generic extend has destination type no larger than source", MI);
1055 case TargetOpcode::G_TRUNC:
1056 case TargetOpcode::G_FPTRUNC:
1057 if (DstSize >= SrcSize)
1058 report(
"Generic truncate has destination type no smaller than source",
1064 case TargetOpcode::G_MERGE_VALUES: {
1072 report(
"G_MERGE_VALUES cannot operate on vectors", MI);
1075 case TargetOpcode::G_UNMERGE_VALUES: {
1081 report(
"G_UNMERGE_VALUES destination types do not match", MI);
1085 report(
"G_UNMERGE_VALUES source operand does not cover dest operands",
1090 case TargetOpcode::G_BUILD_VECTOR: {
1096 report(
"G_BUILD_VECTOR must produce a vector from scalar operands", MI);
1100 report(
"G_BUILD_VECTOR source operand types are not homogeneous", MI);
1104 report(
"G_BUILD_VECTOR src operands total size don't match dest " 1109 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1115 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1120 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1124 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than " 1129 case TargetOpcode::G_CONCAT_VECTORS: {
1135 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1140 report(
"G_CONCAT_VECTOR source operand types are not homogeneous", MI);
1144 report(
"G_CONCAT_VECTOR num dest and source elements should match", MI);
1147 case TargetOpcode::COPY: {
1156 if (SrcTy != DstTy) {
1157 report(
"Copy Instruction is illegal with mismatching types", MI);
1158 errs() <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
"\n";
1166 assert(SrcSize &&
"Expecting size here");
1167 assert(DstSize &&
"Expecting size here");
1168 if (SrcSize != DstSize)
1170 report(
"Copy Instruction is illegal with mismatching sizes", MI);
1171 errs() <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize
1177 case TargetOpcode::STATEPOINT:
1181 report(
"meta operands to STATEPOINT not constant!", MI);
1184 auto VerifyStackMapConstant = [&](
unsigned Offset) {
1188 report(
"stack map constant to STATEPOINT not well formed!", MI);
1200 MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
1204 if (MCID.
getOpcode() == TargetOpcode::PATCHPOINT)
1205 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
1208 if (MONum < NumDefs) {
1211 report(
"Explicit definition must be a register", MO, MONum);
1213 report(
"Explicit definition marked as use", MO, MONum);
1215 report(
"Explicit definition marked as implicit", MO, MONum);
1223 report(
"Explicit operand marked as def", MO, MONum);
1225 report(
"Explicit operand marked as implicit", MO, MONum);
1231 report(
"Tied use must be a register", MO, MONum);
1233 report(
"Operand should be tied", MO, MONum);
1235 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
1238 if (!MOTied.
isReg())
1239 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
1242 report(
"Tied physical registers must match.", &MOTied, TiedTo);
1245 report(
"Explicit operand should not be tied", MO, MONum);
1249 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
1254 const unsigned Reg = MO->
getReg();
1258 checkLiveness(MO, MONum);
1264 if (!OtherMO.
isReg())
1265 report(
"Must be tied to a register", MO, MONum);
1267 report(
"Missing tie flags on tied operand", MO, MONum);
1269 report(
"Inconsistent tie links", MO, MONum);
1273 report(
"Explicit def tied to explicit use without tie constraint",
1277 report(
"Explicit def should be tied to implicit use", MO, MONum);
1287 report(
"Two-address instruction operands must be identical", MO, MONum);
1294 report(
"Illegal subregister index for physical register", MO, MONum);
1300 if (!DRC->contains(Reg)) {
1301 report(
"Illegal physical register for instruction", MO, MONum);
1309 report(
"isRenamable set on reserved register", MO, MONum);
1314 report(
"Use-reg is not IsDebug in a DBG_VALUE", MO, MONum);
1324 if (isFunctionSelected) {
1325 report(
"Generic virtual register invalid in a Selected function",
1333 report(
"Generic virtual register must have a valid type", MO,
1341 if (!RegBank && isFunctionRegBankSelected) {
1342 report(
"Generic virtual register must have a bank in a " 1343 "RegBankSelected function",
1349 if (RegBank && Ty.
isValid() &&
1351 report(
"Register bank is too small for virtual register", MO,
1353 errs() <<
"Register bank " << RegBank->
getName() <<
" too small(" 1359 report(
"Generic virtual register does not subregister index", MO,
1370 report(
"Virtual register does not match instruction constraint", MO,
1372 errs() <<
"Expect register class " 1375 <<
" but got nothing\n";
1385 report(
"Invalid subregister index for virtual register", MO, MONum);
1387 <<
" does not support subreg index " << SubIdx <<
"\n";
1391 report(
"Invalid register class for subregister index", MO, MONum);
1393 <<
" does not fully support subreg index " << SubIdx <<
"\n";
1404 report(
"No largest legal super class exists.", MO, MONum);
1409 report(
"No matching super-reg register class.", MO, MONum);
1414 report(
"Illegal virtual register for instruction", MO, MONum);
1431 report(
"PHI operand is not in the CFG", MO, MONum);
1446 if (stores && loads) {
1449 if (PSV ==
nullptr)
continue;
1452 if (Value ==
nullptr)
continue;
1461 if (loads == stores)
1462 report(
"Missing fixed stack memoperand.", MI);
1465 report(
"Instruction loads from dead spill slot", MO, MONum);
1466 errs() <<
"Live stack: " << LI <<
'\n';
1469 report(
"Instruction stores to dead spill slot", MO, MONum);
1470 errs() <<
"Live stack: " << LI <<
'\n';
1480 void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
1487 report(
"No live segment at use", MO, MONum);
1488 report_context_liverange(LR);
1489 report_context_vreg_regunit(VRegOrUnit);
1490 report_context(UseIdx);
1493 report(
"Live range continues after kill flag", MO, MONum);
1494 report_context_liverange(LR);
1495 report_context_vreg_regunit(VRegOrUnit);
1497 report_context_lanemask(LaneMask);
1498 report_context(UseIdx);
1502 void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
1506 assert(VNI &&
"NULL valno is not allowed");
1507 if (VNI->
def != DefIdx) {
1508 report(
"Inconsistent valno->def", MO, MONum);
1509 report_context_liverange(LR);
1510 report_context_vreg_regunit(VRegOrUnit);
1512 report_context_lanemask(LaneMask);
1513 report_context(*VNI);
1514 report_context(DefIdx);
1517 report(
"No live segment at def", MO, MONum);
1518 report_context_liverange(LR);
1519 report_context_vreg_regunit(VRegOrUnit);
1521 report_context_lanemask(LaneMask);
1522 report_context(DefIdx);
1529 "Expecting a virtual register.");
1535 if (SubRangeCheck || MO->
getSubReg() == 0) {
1536 report(
"Live range continues after dead def flag", MO, MONum);
1537 report_context_liverange(LR);
1538 report_context_vreg_regunit(VRegOrUnit);
1540 report_context_lanemask(LaneMask);
1546 void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
1548 const unsigned Reg = MO->
getReg();
1553 addRegWithSubRegs(regsKilled, Reg);
1560 report(
"Kill missing from LiveVariables", MO, MONum);
1572 checkLivenessAtUse(MO, MONum, UseIdx, *LR, *Units);
1580 checkLivenessAtUse(MO, MONum, UseIdx, LI, Reg);
1589 if ((MOMask & SR.LaneMask).none())
1591 checkLivenessAtUse(MO, MONum, UseIdx, SR, Reg, SR.LaneMask);
1594 LiveInMask |= SR.LaneMask;
1597 if ((LiveInMask & MOMask).none()) {
1598 report(
"No live subrange at use", MO, MONum);
1600 report_context(UseIdx);
1604 report(
"Virtual register has no live interval", MO, MONum);
1610 if (!regsLive.count(Reg)) {
1613 bool Bad = !isReserved(Reg);
1618 if (regsLive.count(*SubRegs)) {
1630 if (!MOP.isReg() || !MOP.isImplicit())
1638 if (*SubRegs == Reg) {
1646 report(
"Using an undefined physical register", MO, MONum);
1648 report(
"Reading virtual register without a def", MO, MONum);
1650 BBInfo &MInfo = MBBInfoMap[MI->
getParent()];
1654 if (MInfo.regsKilled.count(Reg))
1655 report(
"Using a killed virtual register", MO, MONum);
1656 else if (!MI->
isPHI())
1657 MInfo.vregsLiveIn.insert(std::make_pair(Reg, MI));
1666 addRegWithSubRegs(regsDead, Reg);
1668 addRegWithSubRegs(regsDefined, Reg);
1673 report(
"Multiple virtual register defs in SSA form", MO, MONum);
1683 checkLivenessAtDef(MO, MONum, DefIdx, LI, Reg);
1691 if ((SR.LaneMask & MOMask).none())
1693 checkLivenessAtDef(MO, MONum, DefIdx, SR, Reg,
true, SR.LaneMask);
1697 report(
"Virtual register has no Live interval", MO, MONum);
1704 void MachineVerifier::visitMachineInstrAfter(
const MachineInstr *MI) {}
1710 void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *MI) {
1711 BBInfo &MInfo = MBBInfoMap[MI->
getParent()];
1712 set_union(MInfo.regsKilled, regsKilled);
1713 set_subtract(regsLive, regsKilled); regsKilled.clear();
1715 while (!regMasks.empty()) {
1717 for (RegSet::iterator
I = regsLive.begin(),
E = regsLive.end();
I !=
E; ++
I)
1720 regsDead.push_back(*
I);
1723 set_union(regsLive, regsDefined); regsDefined.clear();
1728 MBBInfoMap[MBB].regsLiveOut = regsLive;
1733 if (!(stop > lastIndex)) {
1734 report(
"Block ends before last instruction index", MBB);
1735 errs() <<
"Block ends at " << stop
1736 <<
" last instruction was at " << lastIndex <<
'\n';
1745 void MachineVerifier::calcRegsPassed() {
1749 for (
const auto &MBB : *MF) {
1750 BBInfo &MInfo = MBBInfoMap[&MBB];
1751 if (!MInfo.reachable)
1754 SuE = MBB.
succ_end(); SuI != SuE; ++SuI) {
1755 BBInfo &SInfo = MBBInfoMap[*SuI];
1756 if (SInfo.addPassed(MInfo.regsLiveOut))
1763 while (!todo.
empty()) {
1766 BBInfo &MInfo = MBBInfoMap[MBB];
1768 SuE = MBB->
succ_end(); SuI != SuE; ++SuI) {
1771 BBInfo &SInfo = MBBInfoMap[*SuI];
1772 if (SInfo.addPassed(MInfo.vregsPassed))
1781 void MachineVerifier::calcRegsRequired() {
1784 for (
const auto &MBB : *MF) {
1785 BBInfo &MInfo = MBBInfoMap[&MBB];
1787 PrE = MBB.
pred_end(); PrI != PrE; ++PrI) {
1788 BBInfo &PInfo = MBBInfoMap[*PrI];
1789 if (PInfo.addRequired(MInfo.vregsLiveIn))
1796 while (!todo.
empty()) {
1799 BBInfo &MInfo = MBBInfoMap[MBB];
1801 PrE = MBB->
pred_end(); PrI != PrE; ++PrI) {
1804 BBInfo &SInfo = MBBInfoMap[*PrI];
1805 if (SInfo.addRequired(MInfo.vregsRequired))
1814 BBInfo &MInfo = MBBInfoMap[&MBB];
1824 report(
"Expected first PHI operand to be a register def", &MODef, 0);
1829 report(
"Unexpected flag on PHI operand", &MODef, 0);
1830 unsigned DefReg = MODef.
getReg();
1832 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
1834 for (
unsigned I = 1,
E = Phi.getNumOperands();
I !=
E;
I += 2) {
1837 report(
"Expected PHI operand to be a register", &MO0,
I);
1842 report(
"Unexpected flag on PHI operand", &MO0,
I);
1846 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
1852 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
1856 if (MInfo.reachable) {
1858 BBInfo &PrInfo = MBBInfoMap[&Pre];
1859 if (!MO0.
isUndef() && PrInfo.reachable &&
1860 !PrInfo.isLiveOut(MO0.
getReg()))
1861 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
1866 if (MInfo.reachable) {
1868 if (!seen.
count(Pred)) {
1869 report(
"Missing PHI operand", &Phi);
1871 <<
" is a predecessor according to the CFG.\n";
1878 void MachineVerifier::visitMachineFunctionAfter() {
1888 for (
const auto &MBB : *MF) {
1889 BBInfo &MInfo = MBBInfoMap[&MBB];
1890 for (RegSet::iterator
1891 I = MInfo.vregsRequired.begin(),
E = MInfo.vregsRequired.end();
I !=
E;
1893 if (MInfo.regsKilled.count(*
I)) {
1894 report(
"Virtual register killed in block, but needed live out.", &MBB);
1896 <<
" is used after the block.\n";
1901 BBInfo &MInfo = MBBInfoMap[&MF->front()];
1902 for (RegSet::iterator
1903 I = MInfo.vregsRequired.begin(),
E = MInfo.vregsRequired.end();
I !=
E;
1905 report(
"Virtual register defs don't dominate all uses.", MF);
1906 report_context_vreg(*
I);
1911 verifyLiveVariables();
1913 verifyLiveIntervals();
1916 void MachineVerifier::verifyLiveVariables() {
1917 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
1921 for (
const auto &MBB : *MF) {
1922 BBInfo &MInfo = MBBInfoMap[&MBB];
1925 if (MInfo.vregsRequired.count(Reg)) {
1927 report(
"LiveVariables: Block missing from AliveBlocks", &MBB);
1929 <<
" must be live through the block.\n";
1933 report(
"LiveVariables: Block should not be in AliveBlocks", &MBB);
1935 <<
" is not needed live through the block.\n";
1942 void MachineVerifier::verifyLiveIntervals() {
1943 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
1952 report(
"Missing live interval for virtual register", MF);
1953 errs() <<
printReg(Reg, TRI) <<
" still has defs or uses\n";
1958 assert(Reg == LI.
reg &&
"Invalid reg to interval mapping");
1959 verifyLiveInterval(LI);
1965 verifyLiveRange(*LR, i);
1968 void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
1969 const VNInfo *VNI,
unsigned Reg,
1977 report(
"Value not live at VNInfo def and not marked unused", MF);
1978 report_context(LR, Reg, LaneMask);
1979 report_context(*VNI);
1983 if (DefVNI != VNI) {
1984 report(
"Live segment at def has different VNInfo", MF);
1985 report_context(LR, Reg, LaneMask);
1986 report_context(*VNI);
1992 report(
"Invalid VNInfo definition index", MF);
1993 report_context(LR, Reg, LaneMask);
1994 report_context(*VNI);
2000 report(
"PHIDef VNInfo is not defined at MBB start", MBB);
2001 report_context(LR, Reg, LaneMask);
2002 report_context(*VNI);
2010 report(
"No instruction at VNInfo def index", MBB);
2011 report_context(LR, Reg, LaneMask);
2012 report_context(*VNI);
2017 bool hasDef =
false;
2018 bool isEarlyClobber =
false;
2020 if (!MOI->isReg() || !MOI->isDef())
2023 if (MOI->getReg() !=
Reg)
2030 if (LaneMask.
any() &&
2034 if (MOI->isEarlyClobber())
2035 isEarlyClobber =
true;
2039 report(
"Defining instruction does not modify register", MI);
2040 report_context(LR, Reg, LaneMask);
2041 report_context(*VNI);
2046 if (isEarlyClobber) {
2048 report(
"Early clobber def must be at an early-clobber slot", MBB);
2049 report_context(LR, Reg, LaneMask);
2050 report_context(*VNI);
2053 report(
"Non-PHI, non-early clobber def must be at a register slot", MBB);
2054 report_context(LR, Reg, LaneMask);
2055 report_context(*VNI);
2060 void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
2066 assert(VNI &&
"Live segment has no valno");
2069 report(
"Foreign valno in live segment", MF);
2070 report_context(LR, Reg, LaneMask);
2072 report_context(*VNI);
2076 report(
"Live segment valno is marked unused", MF);
2077 report_context(LR, Reg, LaneMask);
2083 report(
"Bad start of live segment, no basic block", MF);
2084 report_context(LR, Reg, LaneMask);
2090 report(
"Live segment must begin at MBB entry or valno def", MBB);
2091 report_context(LR, Reg, LaneMask);
2098 report(
"Bad end of live segment, no basic block", MF);
2099 report_context(LR, Reg, LaneMask);
2117 report(
"Live segment doesn't end at a valid instruction", EndMBB);
2118 report_context(LR, Reg, LaneMask);
2125 report(
"Live segment ends at B slot of an instruction", EndMBB);
2126 report_context(LR, Reg, LaneMask);
2134 report(
"Live segment ending at dead slot spans instructions", EndMBB);
2135 report_context(LR, Reg, LaneMask);
2143 if (I+1 == LR.
end() || (I+1)->start != S.
end) {
2144 report(
"Live segment ending at early clobber slot must be " 2145 "redefined by an EC def in the same instruction", EndMBB);
2146 report_context(LR, Reg, LaneMask);
2156 bool hasRead =
false;
2157 bool hasSubRegDef =
false;
2158 bool hasDeadDef =
false;
2160 if (!MOI->isReg() || MOI->getReg() !=
Reg)
2162 unsigned Sub = MOI->getSubReg();
2167 hasSubRegDef =
true;
2176 if (LaneMask.
any() && (LaneMask & SLM).none())
2178 if (MOI->readsReg())
2185 if (LaneMask.
none() && !hasDeadDef) {
2186 report(
"Instruction ending live segment on dead slot has no dead flag",
2188 report_context(LR, Reg, LaneMask);
2197 report(
"Instruction ending live segment doesn't read the register",
2199 report_context(LR, Reg, LaneMask);
2218 if (LaneMask.
any()) {
2228 if (&*MFI == EndMBB)
2240 PE = MFI->pred_end(); PI != PE; ++PI) {
2248 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
2251 report(
"Register not marked live out of predecessor", *PI);
2252 report_context(LR, Reg, LaneMask);
2253 report_context(*VNI);
2261 if (!IsPHI && PVNI != VNI) {
2262 report(
"Different value live out of predecessor", *PI);
2263 report_context(LR, Reg, LaneMask);
2264 errs() <<
"Valno #" << PVNI->
id <<
" live out of " 2270 if (&*MFI == EndMBB)
2276 void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
unsigned Reg,
2279 verifyLiveRangeValue(LR, VNI, Reg, LaneMask);
2282 verifyLiveRangeSegment(LR, I, Reg, LaneMask);
2285 void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
2286 unsigned Reg = LI.
reg;
2288 verifyLiveRange(LI, Reg);
2293 if ((Mask & SR.LaneMask).any()) {
2294 report(
"Lane masks of sub ranges overlap in live interval", MF);
2297 if ((SR.LaneMask & ~MaxMask).any()) {
2298 report(
"Subrange lanemask is invalid", MF);
2302 report(
"Subrange must not be empty", MF);
2303 report_context(SR, LI.
reg, SR.LaneMask);
2305 Mask |= SR.LaneMask;
2306 verifyLiveRange(SR, LI.
reg, SR.LaneMask);
2308 report(
"A Subrange is not covered by the main range", MF);
2315 unsigned NumComp = ConEQ.
Classify(LI);
2317 report(
"Multiple connected components in live interval", MF);
2319 for (
unsigned comp = 0; comp != NumComp; ++comp) {
2320 errs() << comp <<
": valnos";
2324 errs() <<
' ' << (*I)->id;
2336 struct StackStateOfBB {
2337 StackStateOfBB() =
default;
2338 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup) :
2339 EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
2340 ExitIsSetup(ExitSetup) {}
2345 bool EntryIsSetup =
false;
2346 bool ExitIsSetup =
false;
2354 void MachineVerifier::verifyStackFrame() {
2357 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
2368 DFI != DFE; ++DFI) {
2371 StackStateOfBB BBState;
2373 if (DFI.getPathLength() >= 2) {
2376 "DFS stack predecessor is already visited.\n");
2377 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
2378 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
2379 BBState.ExitValue = BBState.EntryValue;
2380 BBState.ExitIsSetup = BBState.EntryIsSetup;
2384 for (
const auto &I : *MBB) {
2385 if (I.getOpcode() == FrameSetupOpcode) {
2386 if (BBState.ExitIsSetup)
2387 report(
"FrameSetup is after another FrameSetup", &I);
2389 BBState.ExitIsSetup =
true;
2392 if (I.getOpcode() == FrameDestroyOpcode) {
2394 if (!BBState.ExitIsSetup)
2395 report(
"FrameDestroy is not after a FrameSetup", &I);
2396 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
2398 if (BBState.ExitIsSetup && AbsSPAdj != Size) {
2399 report(
"FrameDestroy <n> is after FrameSetup <m>", &I);
2400 errs() <<
"FrameDestroy <" << Size <<
"> is after FrameSetup <" 2401 << AbsSPAdj <<
">.\n";
2403 BBState.ExitValue +=
Size;
2404 BBState.ExitIsSetup =
false;
2407 SPState[MBB->getNumber()] = BBState;
2412 E = MBB->pred_end(); I !=
E; ++
I) {
2413 if (Reachable.
count(*I) &&
2414 (SPState[(*I)->getNumber()].ExitValue != BBState.EntryValue ||
2415 SPState[(*I)->getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
2416 report(
"The exit stack state of a predecessor is inconsistent.", MBB);
2418 <<
" has exit state (" << SPState[(*I)->getNumber()].ExitValue
2419 <<
", " << SPState[(*I)->getNumber()].ExitIsSetup <<
"), while " 2421 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
2428 E = MBB->succ_end(); I !=
E; ++
I) {
2429 if (Reachable.
count(*I) &&
2430 (SPState[(*I)->getNumber()].EntryValue != BBState.ExitValue ||
2431 SPState[(*I)->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
2432 report(
"The entry stack state of a successor is inconsistent.", MBB);
2434 <<
" has entry state (" << SPState[(*I)->getNumber()].EntryValue
2435 <<
", " << SPState[(*I)->getNumber()].EntryIsSetup <<
"), while " 2437 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
2442 if (!MBB->empty() && MBB->back().isReturn()) {
2443 if (BBState.ExitIsSetup)
2444 report(
"A return block ends with a FrameSetup.", MBB);
2445 if (BBState.ExitValue)
2446 report(
"A return block ends with a nonzero stack adjustment.", MBB);
bool reg_nodbg_empty(unsigned RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions...
Pass interface - Implemented by all 'passes'.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
mop_iterator operands_end()
Safe Stack instrumentation pass
A common definition of LaneBitmask for use in TableGen and CodeGen.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
MachineBasicBlock * getMBB() const
SlotIndex def
The index of the defining instruction.
LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
const char * getName() const
Get a user friendly name of this register bank.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineFunctionProperties & getProperties() const
Get the function properties.
int64_t getFrameTotalSize(const MachineInstr &I) const
Returns the total frame size, which is made up of the space set up inside the pair of frame start-sto...
DWARF-like instruction based exceptions.
LiveInterval - This class represents the liveness of a register, or stack slot.
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
static bool matchPair(MachineBasicBlock::const_succ_iterator i, const MachineBasicBlock *a, const MachineBasicBlock *b)
unsigned getSubReg() const
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
bool test(unsigned Idx) const
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
LiveInterval & getInterval(int Slot)
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
bool isDeadDef() const
Return true if this instruction has a dead def.
A live range for subregisters.
bool isMetadata() const
isMetadata - Tests if this is a MO_Metadata operand.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
bool isValid() const
Returns true if this is a valid index.
MachineBasicBlock reference.
This represents a simple continuous liveness interval for a value.
VarInfo - This represents the regions where a virtual register is live in the program.
unsigned const TargetRegisterInfo * TRI
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
int getFrameIndex() const
unsigned getCallFrameDestroyOpcode() const
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 reservedRegsFrozen() const
reservedRegsFrozen - Returns true after freezeReservedRegs() was called to ensure the set of reserved...
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
VNInfo - Value Number Information.
void print(raw_ostream &O, const Module *=nullptr) const override
Implement the dump method.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void verifyUseLists() const
Verify the use list of all registers.
unsigned getNumRegUnits() const
Return the number of (native) register units in the target.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool isInternalRead() const
This class represents the liveness of a register, stack slot, etc.
void initializeMachineVerifierPassPass(PassRegistry &)
bool isUnused() const
Returns true if this value is unused.
Mask of preserved registers.
bool isEarlyClobber() const
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
bool test(unsigned Idx) const
FunctionPass * createMachineVerifierPass(const std::string &Banner)
createMachineVerifierPass - This pass verifies cenerated machine code instructions for correctness...
bool isNotInMIMap(const MachineInstr &Instr) const
Returns true if the specified machine instr has been removed or was never entered in the map...
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
void clear()
clear - Removes all bits from the bitvector. Does not change capacity.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const HexagonInstrInfo * TII
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
unsigned getVarIdx() const
Get starting index of non call related arguments (calling convention, statepoint flags, vm state and gc state).
bool isLiveInToMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
unsigned getNumOperands() const
Retuns the total number of operands.
const TargetRegisterClass * getRegClass(const MCInstrDesc &MCID, unsigned OpNum, const TargetRegisterInfo *TRI, const MachineFunction &MF) const
Given a machine instruction descriptor, returns the register class constraint for OpNum...
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
iterator_range< subrange_iterator > subranges()
Result of a LiveRange query.
static constexpr LaneBitmask getAll()
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block) ...
virtual const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const
Returns the largest legal sub-class of RC that supports the sub-register index Idx.
def_iterator def_begin(unsigned RegNo) const
SparseBitVector AliveBlocks
AliveBlocks - Set of blocks in which this value is alive completely through.
static constexpr LaneBitmask getNone()
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
unsigned getEqClass(const VNInfo *VNI) const
getEqClass - Classify creates equivalence classes numbered 0..N.
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch, catchpad/ret, and cleanuppad/ret.
bool hasRegUnit(unsigned Reg, unsigned RegUnit) const
Returns true if Reg contains RegUnit.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register. ...
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool isValid() const
isValid - Returns true until all the operands have been visited.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
virtual const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const
Returns the largest super class of RC that is legal to use in the current sub-target and has the same...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
virtual const TargetInstrInfo * getInstrInfo() const
bool isInsideBundle() const
Return true if MI is in a bundle (but not the first MI in a bundle).
bool isKill() const
Return true if the live-in value is killed by this instruction.
LiveRange * getCachedRegUnit(unsigned Unit)
Return the live range for register unit Unit if it has already been computed, or nullptr if it hasn't...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
TargetInstrInfo - Interface to description of machine instruction set.
This class is intended to be used as a base class for asm properties and features specific to the tar...
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
bool isGenericType() const
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
unsigned const MachineRegisterInfo * MRI
VNInfoList::const_iterator const_vni_iterator
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
bool hasInterval(unsigned Reg) const
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
LLVM Basic Block Representation.
bool isOptionalDef() const
Set if this operand is a optional def.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
bool liveAt(SlotIndex index) const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD bool empty() const
unsigned Classify(const LiveRange &LR)
Classify the values in LR into connected components.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
virtual bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const
Perform target-specific instruction verification.
unsigned getCallFrameSetupOpcode() const
These methods return the opcode of the frame setup/destroy instructions if they exist (-1 otherwise)...
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Represent the analysis usage information of a pass.
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
constexpr bool none() const
FunctionPass class - This class is used to implement most global optimizations.
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the specified register class A so that each register in it has a sub-register of...
bool def_empty(unsigned RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
const RegisterBank * getRegBankOrNull(unsigned Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
iterator_range< pred_iterator > predecessors()
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
succ_iterator succ_begin()
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
VarInfo & getVarInfo(unsigned RegIdx)
getVarInfo - Return the VarInfo structure for the specified VIRTUAL register.
virtual bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
pred_iterator pred_begin()
MCSubRegIterator enumerates all sub-registers of Reg.
virtual bool isPredicated(const MachineInstr &MI) const
Returns true if the instruction is already predicated.
bool isDebugInstr() 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...
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
std::vector< MachineInstr * > Kills
Kills - List of MachineInstruction's which are the last use of this virtual register (kill it) in the...
unsigned id
The ID number of this value.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
unsigned findTiedOperandIdx(unsigned OpIdx) const
Given the index of a tied register operand, find the operand it is tied to.
Iterator for intrusive lists based on ilist_node.
bool covers(const LiveRange &Other) const
Returns true if all segments of the Other live range are completely covered by this live range...
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
Segments::const_iterator const_iterator
void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr, const TargetIntrinsicInfo *IntrinsicInfo=nullptr) const
Print the MachineOperand to os.
bool isDebugValue() const
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
MachineOperand class - Representation of each machine instruction operand.
bool isInAllocatableClass(unsigned RegNo) const
Return true if the register is in the allocation of any register class.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
bool isReservedRegUnit(unsigned Unit) const
Returns true when the given register unit is considered reserved.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
LiveInterval & getInterval(unsigned Reg)
bool isVariadic(QueryType Type=IgnoreBundle) const
Return true if this instruction can have a variable number of operands.
This class implements the register bank concept.
unsigned pred_size() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
INITIALIZE_PASS(MachineVerifierPass, "machineverifier", "Verify generated machine code", false, false) FunctionPass *llvm
static bool clobbersPhysReg(const uint32_t *RegMask, unsigned 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.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarilly including Idx...
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 ...
virtual BitVector getReservedRegs(const MachineFunction &MF) const =0
Returns a bitset indexed by physical register number indicating if a register is a special register t...
Special value supplied for machine level alias analysis.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
Base class for user error types.
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
unsigned succ_size() const
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
unsigned getNumValNums() const
void set_subtract(S1Ty &S1, const S2Ty &S2)
set_subtract(A, B) - Compute A := A - B
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_NODISCARD bool empty() const
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
constexpr bool any() const
MI-level Statepoint operands.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
size_type size() const
size - Returns the number of bits in this bitvector.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
Abstract Stack Frame Index.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool shouldTrackSubRegLiveness(const TargetRegisterClass &RC) const
Returns true if liveness for register class RC should be tracked at the subregister level...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
iterator_range< livein_iterator > liveins() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const TargetRegisterClass * getRegClassOrNull(unsigned Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasProperty(Property P) const
bool hasInterval(int Slot) const
static def_iterator def_end()
unsigned getSize() const
Get the maximal size in bits that fits in this register bank.
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
iterator_range< const_set_bits_iterator > set_bits() const
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
mop_iterator operands_begin()
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
const MCOperandInfo * OpInfo
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ExceptionHandling getExceptionHandlingType() const
unsigned getOpcode() const
Return the opcode number for this descriptor.
Primary interface to the complete machine description for the target machine.
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
unsigned getGenericTypeIndex() const
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
StringRef - Represent a constant reference to a string, i.e.
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
A specialized PseudoSourceValue for holding FixedStack values, which must include a frame index...
This holds information about one operand of a machine instruction, indicating the register class for ...
const MachineOperand & getOperand(unsigned i) const
SlotIndex - An opaque wrapper around machine indexes.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
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...
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
mmo_iterator memoperands_end() const
Access to memory operands of the instruction.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.