86 struct MachineVerifier {
87 MachineVerifier(
Pass *
pass,
const char *b) : PASS(pass), Banner(b) {}
102 bool isFunctionRegBankSelected;
103 bool isFunctionSelected;
112 BlockSet FunctionBlocks;
116 RegVector regsDefined, regsDead, regsKilled;
117 RegMaskVector regMasks;
122 void addRegWithSubRegs(RegVector &RV,
unsigned Reg) {
126 RV.push_back(*SubRegs);
131 bool reachable =
false;
151 RegSet vregsRequired;
154 BlockSet Preds, Succs;
160 bool addPassed(
unsigned Reg) {
163 if (regsKilled.count(Reg) || regsLiveOut.count(Reg))
165 return vregsPassed.insert(Reg).second;
169 bool addPassed(
const RegSet &RS) {
170 bool changed =
false;
171 for (RegSet::const_iterator
I = RS.begin(),
E = RS.end();
I !=
E; ++
I)
179 bool addRequired(
unsigned Reg) {
182 if (regsLiveOut.count(Reg))
184 return vregsRequired.insert(Reg).second;
188 bool addRequired(
const RegSet &RS) {
189 bool changed =
false;
190 for (RegSet::const_iterator
I = RS.begin(),
E = RS.end();
I !=
E; ++
I)
197 bool addRequired(
const RegMap &
RM) {
198 bool changed =
false;
199 for (RegMap::const_iterator
I = RM.begin(),
E = RM.end();
I !=
E; ++
I)
200 if (addRequired(
I->first))
207 return regsLiveOut.count(Reg) || vregsPassed.count(Reg);
214 bool isReserved(
unsigned Reg) {
215 return Reg < regsReserved.
size() && regsReserved.
test(Reg);
218 bool isAllocatable(
unsigned Reg)
const {
220 !regsReserved.
test(Reg);
229 void visitMachineFunctionBefore();
233 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
237 void visitMachineFunctionAfter();
242 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
246 void report_context(
const LiveRange &LR,
unsigned VRegUnit,
249 void report_context(
const VNInfo &VNI)
const;
250 void report_context(
SlotIndex Pos)
const;
251 void report_context_liverange(
const LiveRange &LR)
const;
252 void report_context_lanemask(
LaneBitmask LaneMask)
const;
253 void report_context_vreg(
unsigned VReg)
const;
254 void report_context_vreg_regunit(
unsigned VRegOrUnit)
const;
267 void calcRegsPassed();
270 void calcRegsRequired();
271 void verifyLiveVariables();
272 void verifyLiveIntervals();
276 void verifyLiveRangeSegment(
const LiveRange&,
279 void verifyLiveRange(
const LiveRange&,
unsigned,
282 void verifyStackFrame();
284 void verifySlotIndexes()
const;
291 const std::string Banner;
293 MachineVerifierPass(std::string banner = std::string())
304 unsigned FoundErrors = MachineVerifier(
this, Banner.c_str()).
verify(MF);
316 "Verify generated machine code",
false,
false)
319 return new MachineVerifierPass(Banner);
325 unsigned FoundErrors = MachineVerifier(p, Banner).verify(MF);
326 if (AbortOnErrors && FoundErrors)
328 return FoundErrors == 0;
331 void MachineVerifier::verifySlotIndexes()
const {
332 if (Indexes ==
nullptr)
351 report(
"Function has NoVRegs property but there are VReg operands", &MF);
365 isFunctionRegBankSelected =
366 !isFunctionFailedISel &&
369 isFunctionSelected = !isFunctionFailedISel &&
387 verifyProperties(MF);
389 visitMachineFunctionBefore();
392 visitMachineBasicBlockBefore(&*MFI);
396 bool InBundle =
false;
399 MBBE = MFI->instr_end(); MBBI != MBBE; ++MBBI) {
400 if (MBBI->getParent() != &*MFI) {
401 report(
"Bad instruction parent pointer", &*MFI);
402 errs() <<
"Instruction: " << *MBBI;
407 if (InBundle && !MBBI->isBundledWithPred())
408 report(
"Missing BundledPred flag, " 409 "BundledSucc was set on predecessor",
411 if (!InBundle && MBBI->isBundledWithPred())
412 report(
"BundledPred flag is set, " 413 "but BundledSucc not set on predecessor",
417 if (!MBBI->isInsideBundle()) {
419 visitMachineBundleAfter(CurBundle);
421 visitMachineBundleBefore(CurBundle);
422 }
else if (!CurBundle)
423 report(
"No bundle header", &*MBBI);
424 visitMachineInstrBefore(&*MBBI);
425 for (
unsigned I = 0,
E = MBBI->getNumOperands();
I !=
E; ++
I) {
431 report(
"Instruction has operand with wrong parent set", &MI);
434 visitMachineOperand(&Op,
I);
437 visitMachineInstrAfter(&*MBBI);
440 InBundle = MBBI->isBundledWithSucc();
443 visitMachineBundleAfter(CurBundle);
445 report(
"BundledSucc flag set on last instruction in block", &MFI->back());
446 visitMachineBasicBlockAfter(&*MFI);
448 visitMachineFunctionAfter();
461 void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
464 if (!foundErrors++) {
466 errs() <<
"# " << Banner <<
'\n';
467 if (LiveInts !=
nullptr)
472 errs() <<
"*** Bad machine code: " << msg <<
" ***\n" 473 <<
"- function: " << MF->
getName() <<
"\n";
480 << MBB->
getName() <<
" (" << (
const void *)MBB <<
')';
487 void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
490 errs() <<
"- instruction: ";
491 if (Indexes && Indexes->
hasIndex(*MI))
496 void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
497 unsigned MONum,
LLT MOVRegType) {
500 errs() <<
"- operand " << MONum <<
": ";
505 void MachineVerifier::report_context(
SlotIndex Pos)
const {
506 errs() <<
"- at: " << Pos <<
'\n';
509 void MachineVerifier::report_context(
const LiveInterval &LI)
const {
510 errs() <<
"- interval: " << LI <<
'\n';
513 void MachineVerifier::report_context(
const LiveRange &LR,
unsigned VRegUnit,
515 report_context_liverange(LR);
516 report_context_vreg_regunit(VRegUnit);
518 report_context_lanemask(LaneMask);
522 errs() <<
"- segment: " << S <<
'\n';
525 void MachineVerifier::report_context(
const VNInfo &VNI)
const {
526 errs() <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
529 void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
530 errs() <<
"- liverange: " << LR <<
'\n';
533 void MachineVerifier::report_context_vreg(
unsigned VReg)
const {
534 errs() <<
"- v. register: " <<
printReg(VReg, TRI) <<
'\n';
537 void MachineVerifier::report_context_vreg_regunit(
unsigned VRegOrUnit)
const {
539 report_context_vreg(VRegOrUnit);
545 void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
550 BBInfo &MInfo = MBBInfoMap[MBB];
551 if (!MInfo.reachable) {
552 MInfo.reachable =
true;
554 SuE = MBB->
succ_end(); SuI != SuE; ++SuI)
559 void MachineVerifier::visitMachineFunctionBefore() {
565 markReachable(&MF->
front());
568 FunctionBlocks.
clear();
569 for (
const auto &MBB : *MF) {
570 FunctionBlocks.insert(&MBB);
571 BBInfo &MInfo = MBBInfoMap[&MBB];
574 if (MInfo.Preds.size() != MBB.
pred_size())
575 report(
"MBB has duplicate entries in its predecessor list.", &MBB);
578 if (MInfo.Succs.size() != MBB.
succ_size())
579 report(
"MBB has duplicate entries in its successor list.", &MBB);
601 FirstTerminator =
nullptr;
607 for (
const auto &LI : MBB->
liveins()) {
608 if (isAllocatable(LI.PhysReg) && !MBB->
isEHPad() &&
610 report(
"MBB has allocatable live-in, but isn't entry or landing-pad.", MBB);
621 if (!FunctionBlocks.count(*
I))
622 report(
"MBB has successor that isn't part of the function.", MBB);
623 if (!MBBInfoMap[*
I].Preds.
count(MBB)) {
624 report(
"Inconsistent CFG", MBB);
625 errs() <<
"MBB is not in the predecessor list of the successor " 633 if (!FunctionBlocks.count(*
I))
634 report(
"MBB has predecessor that isn't part of the function.", MBB);
635 if (!MBBInfoMap[*
I].Succs.
count(MBB)) {
636 report(
"Inconsistent CFG", MBB);
637 errs() <<
"MBB is not in the successor list of the predecessor " 645 if (LandingPadSuccs.
size() > 1 &&
650 report(
"MBB has more than one landing pad successor", MBB);
655 if (!TII->
analyzeBranch(*const_cast<MachineBasicBlock *>(MBB), TBB, FBB,
663 if (MBBI == MF->
end()) {
672 report(
"MBB exits via unconditional fall-through but doesn't have " 673 "exactly one CFG successor!", MBB);
675 report(
"MBB exits via unconditional fall-through but its successor " 676 "differs from its CFG successor!", MBB);
680 report(
"MBB exits via unconditional fall-through but ends with a " 681 "barrier instruction!", MBB);
684 report(
"MBB exits via unconditional fall-through but has a condition!",
687 }
else if (TBB && !FBB && Cond.
empty()) {
694 report(
"MBB exits via unconditional branch but doesn't have " 695 "exactly one CFG successor!", MBB);
697 report(
"MBB exits via unconditional branch but the CFG " 698 "successor doesn't match the actual successor!", MBB);
701 report(
"MBB exits via unconditional branch but doesn't contain " 702 "any instructions!", MBB);
704 report(
"MBB exits via unconditional branch but doesn't end with a " 705 "barrier instruction!", MBB);
707 report(
"MBB exits via unconditional branch but the branch isn't a " 708 "terminator instruction!", MBB);
710 }
else if (TBB && !FBB && !Cond.
empty()) {
714 if (MBBI == MF->
end()) {
715 report(
"MBB conditionally falls through out of function!", MBB);
719 report(
"MBB exits via conditional branch/fall-through but only has " 720 "one CFG successor!", MBB);
722 report(
"MBB exits via conditional branch/fall-through but the CFG " 723 "successor don't match the actual successor!", MBB);
725 report(
"MBB exits via conditional branch/fall-through but doesn't have " 726 "exactly two CFG successors!", MBB);
728 report(
"MBB exits via conditional branch/fall-through but the CFG " 729 "successors don't match the actual successors!", MBB);
732 report(
"MBB exits via conditional branch/fall-through but doesn't " 733 "contain any instructions!", MBB);
735 report(
"MBB exits via conditional branch/fall-through but ends with a " 736 "barrier instruction!", MBB);
738 report(
"MBB exits via conditional branch/fall-through but the branch " 739 "isn't a terminator instruction!", MBB);
741 }
else if (TBB && FBB) {
747 report(
"MBB exits via conditional branch/branch through but only has " 748 "one CFG successor!", MBB);
750 report(
"MBB exits via conditional branch/branch through but the CFG " 751 "successor don't match the actual successor!", MBB);
753 report(
"MBB exits via conditional branch/branch but doesn't have " 754 "exactly two CFG successors!", MBB);
756 report(
"MBB exits via conditional branch/branch but the CFG " 757 "successors don't match the actual successors!", MBB);
760 report(
"MBB exits via conditional branch/branch but doesn't " 761 "contain any instructions!", MBB);
763 report(
"MBB exits via conditional branch/branch but doesn't end with a " 764 "barrier instruction!", MBB);
766 report(
"MBB exits via conditional branch/branch but the branch " 767 "isn't a terminator instruction!", MBB);
770 report(
"MBB exits via conditinal branch/branch but there's no " 774 report(
"AnalyzeBranch returned invalid data!", MBB);
780 for (
const auto &LI : MBB->
liveins()) {
782 report(
"MBB live-in list contains non-physical register", MBB);
787 regsLive.insert(*SubRegs);
796 regsLive.insert(*SubRegs);
808 void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *MI) {
809 if (Indexes && Indexes->
hasIndex(*MI)) {
811 if (!(idx > lastIndex)) {
812 report(
"Instruction index out of order", MI);
813 errs() <<
"Last instruction was at " << lastIndex <<
'\n';
822 if (!FirstTerminator)
823 FirstTerminator =
MI;
824 }
else if (FirstTerminator) {
825 report(
"Non-terminator instruction after the first terminator", MI);
826 errs() <<
"First terminator was:\t" << *FirstTerminator;
832 void MachineVerifier::verifyInlineAsm(
const MachineInstr *MI) {
835 report(
"Too few operands on inline asm", MI);
839 report(
"Asm string must be an external symbol", MI);
841 report(
"Asm flags must be an immediate", MI);
846 report(
"Unknown asm flags", &MI->
getOperand(1), 1);
852 for (
unsigned e = MI->
getNumOperands(); OpNo < e; OpNo += NumOps) {
861 report(
"Missing operands in last group", MI);
871 report(
"Expected implicit register after groups", &MO, OpNo);
875 void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *MI) {
878 report(
"Too few operands", MI);
885 report(
"Found PHI instruction with NoPHIs property set", MI);
895 if ((*I)->isLoad() && !MI->
mayLoad())
896 report(
"Missing mayLoad flag", MI);
897 if ((*I)->isStore() && !MI->
mayStore())
898 report(
"Missing mayStore flag", MI);
907 report(
"Debug instruction has a slot index", MI);
910 report(
"Instruction inside bundle has a slot index", MI);
913 report(
"Missing slot index", MI);
918 if (isFunctionSelected)
919 report(
"Unexpected generic instruction in a Selected function", MI);
938 if (!Types[TypeIdx].isValid())
939 Types[TypeIdx] = OpTy;
940 else if (Types[TypeIdx] != OpTy)
941 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
944 report(
"Generic instruction is missing a virtual register type", MO,
I);
952 report(
"Generic instruction cannot have physical register", MO,
I);
958 report(ErrorInfo.
data(),
MI);
964 case TargetOpcode::G_LOAD:
965 case TargetOpcode::G_STORE:
969 report(
"Generic instruction accessing memory must have one mem operand",
972 case TargetOpcode::G_PHI: {
980 if (!Ty.
isValid() || (Ty != DstTy))
984 report(
"Generic Instruction G_PHI has operands with incompatible/missing " 989 case TargetOpcode::G_SEXT:
990 case TargetOpcode::G_ZEXT:
991 case TargetOpcode::G_ANYEXT:
992 case TargetOpcode::G_TRUNC:
993 case TargetOpcode::G_FPEXT:
994 case TargetOpcode::G_FPTRUNC: {
1011 report(
"Generic extend/truncate can not operate on pointers", MI);
1014 report(
"Generic extend/truncate must be all-vector or all-scalar", MI);
1023 report(
"Generic vector extend/truncate must preserve number of lanes",
1029 if (DstSize <= SrcSize)
1030 report(
"Generic extend has destination type no larger than source", MI);
1032 case TargetOpcode::G_TRUNC:
1033 case TargetOpcode::G_FPTRUNC:
1034 if (DstSize >= SrcSize)
1035 report(
"Generic truncate has destination type no smaller than source",
1041 case TargetOpcode::COPY: {
1050 if (SrcTy != DstTy) {
1051 report(
"Copy Instruction is illegal with mismatching types", MI);
1052 errs() <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
"\n";
1060 assert(SrcSize &&
"Expecting size here");
1061 assert(DstSize &&
"Expecting size here");
1062 if (SrcSize != DstSize)
1064 report(
"Copy Instruction is illegal with mismatching sizes", MI);
1065 errs() <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize
1071 case TargetOpcode::STATEPOINT:
1075 report(
"meta operands to STATEPOINT not constant!", MI);
1078 auto VerifyStackMapConstant = [&](
unsigned Offset) {
1082 report(
"stack map constant to STATEPOINT not well formed!", MI);
1094 MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
1098 if (MCID.
getOpcode() == TargetOpcode::PATCHPOINT)
1099 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
1102 if (MONum < NumDefs) {
1105 report(
"Explicit definition must be a register", MO, MONum);
1107 report(
"Explicit definition marked as use", MO, MONum);
1109 report(
"Explicit definition marked as implicit", MO, MONum);
1117 report(
"Explicit operand marked as def", MO, MONum);
1119 report(
"Explicit operand marked as implicit", MO, MONum);
1125 report(
"Tied use must be a register", MO, MONum);
1127 report(
"Operand should be tied", MO, MONum);
1129 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
1132 if (!MOTied.
isReg())
1133 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
1136 report(
"Tied physical registers must match.", &MOTied, TiedTo);
1139 report(
"Explicit operand should not be tied", MO, MONum);
1143 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
1148 const unsigned Reg = MO->
getReg();
1152 checkLiveness(MO, MONum);
1158 if (!OtherMO.
isReg())
1159 report(
"Must be tied to a register", MO, MONum);
1161 report(
"Missing tie flags on tied operand", MO, MONum);
1163 report(
"Inconsistent tie links", MO, MONum);
1167 report(
"Explicit def tied to explicit use without tie constraint",
1171 report(
"Explicit def should be tied to implicit use", MO, MONum);
1181 report(
"Two-address instruction operands must be identical", MO, MONum);
1188 report(
"Illegal subregister index for physical register", MO, MONum);
1194 if (!DRC->contains(Reg)) {
1195 report(
"Illegal physical register for instruction", MO, MONum);
1203 report(
"isRenamable set on reserved register", MO, MONum);
1208 report(
"Use-reg is not IsDebug in a DBG_VALUE", MO, MONum);
1218 if (isFunctionSelected) {
1219 report(
"Generic virtual register invalid in a Selected function",
1227 report(
"Generic virtual register must have a valid type", MO,
1235 if (!RegBank && isFunctionRegBankSelected) {
1236 report(
"Generic virtual register must have a bank in a " 1237 "RegBankSelected function",
1243 if (RegBank && Ty.
isValid() &&
1245 report(
"Register bank is too small for virtual register", MO,
1247 errs() <<
"Register bank " << RegBank->
getName() <<
" too small(" 1253 report(
"Generic virtual register does not subregister index", MO,
1264 report(
"Virtual register does not match instruction constraint", MO,
1266 errs() <<
"Expect register class " 1269 <<
" but got nothing\n";
1279 report(
"Invalid subregister index for virtual register", MO, MONum);
1281 <<
" does not support subreg index " << SubIdx <<
"\n";
1285 report(
"Invalid register class for subregister index", MO, MONum);
1287 <<
" does not fully support subreg index " << SubIdx <<
"\n";
1298 report(
"No largest legal super class exists.", MO, MONum);
1303 report(
"No matching super-reg register class.", MO, MONum);
1308 report(
"Illegal virtual register for instruction", MO, MONum);
1325 report(
"PHI operand is not in the CFG", MO, MONum);
1340 if (stores && loads) {
1343 if (PSV ==
nullptr)
continue;
1346 if (Value ==
nullptr)
continue;
1355 if (loads == stores)
1356 report(
"Missing fixed stack memoperand.", MI);
1359 report(
"Instruction loads from dead spill slot", MO, MONum);
1360 errs() <<
"Live stack: " << LI <<
'\n';
1363 report(
"Instruction stores to dead spill slot", MO, MONum);
1364 errs() <<
"Live stack: " << LI <<
'\n';
1374 void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
1381 report(
"No live segment at use", MO, MONum);
1382 report_context_liverange(LR);
1383 report_context_vreg_regunit(VRegOrUnit);
1384 report_context(UseIdx);
1387 report(
"Live range continues after kill flag", MO, MONum);
1388 report_context_liverange(LR);
1389 report_context_vreg_regunit(VRegOrUnit);
1391 report_context_lanemask(LaneMask);
1392 report_context(UseIdx);
1396 void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
1400 assert(VNI &&
"NULL valno is not allowed");
1401 if (VNI->
def != DefIdx) {
1402 report(
"Inconsistent valno->def", MO, MONum);
1403 report_context_liverange(LR);
1404 report_context_vreg_regunit(VRegOrUnit);
1406 report_context_lanemask(LaneMask);
1407 report_context(*VNI);
1408 report_context(DefIdx);
1411 report(
"No live segment at def", MO, MONum);
1412 report_context_liverange(LR);
1413 report_context_vreg_regunit(VRegOrUnit);
1415 report_context_lanemask(LaneMask);
1416 report_context(DefIdx);
1424 bool otherDef =
false;
1430 unsigned Reg = MO.
getReg();
1432 if (*Units == VRegOrUnit) {
1441 report(
"Live range continues after dead def flag", MO, MONum);
1442 report_context_liverange(LR);
1443 report_context_vreg_regunit(VRegOrUnit);
1445 report_context_lanemask(LaneMask);
1451 void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
1453 const unsigned Reg = MO->
getReg();
1458 addRegWithSubRegs(regsKilled, Reg);
1465 report(
"Kill missing from LiveVariables", MO, MONum);
1477 checkLivenessAtUse(MO, MONum, UseIdx, *LR, *Units);
1485 checkLivenessAtUse(MO, MONum, UseIdx, LI, Reg);
1494 if ((MOMask & SR.LaneMask).none())
1496 checkLivenessAtUse(MO, MONum, UseIdx, SR, Reg, SR.LaneMask);
1499 LiveInMask |= SR.LaneMask;
1502 if ((LiveInMask & MOMask).none()) {
1503 report(
"No live subrange at use", MO, MONum);
1505 report_context(UseIdx);
1509 report(
"Virtual register has no live interval", MO, MONum);
1515 if (!regsLive.count(Reg)) {
1518 bool Bad = !isReserved(Reg);
1523 if (regsLive.count(*SubRegs)) {
1537 if (!MOP.isImplicit())
1541 if (*SubRegs == Reg) {
1549 report(
"Using an undefined physical register", MO, MONum);
1551 report(
"Reading virtual register without a def", MO, MONum);
1553 BBInfo &MInfo = MBBInfoMap[MI->
getParent()];
1557 if (MInfo.regsKilled.count(Reg))
1558 report(
"Using a killed virtual register", MO, MONum);
1559 else if (!MI->
isPHI())
1560 MInfo.vregsLiveIn.insert(std::make_pair(Reg, MI));
1569 addRegWithSubRegs(regsDead, Reg);
1571 addRegWithSubRegs(regsDefined, Reg);
1576 report(
"Multiple virtual register defs in SSA form", MO, MONum);
1586 checkLivenessAtDef(MO, MONum, DefIdx, LI, Reg);
1594 if ((SR.LaneMask & MOMask).none())
1596 checkLivenessAtDef(MO, MONum, DefIdx, SR, Reg, SR.LaneMask);
1600 report(
"Virtual register has no Live interval", MO, MONum);
1607 void MachineVerifier::visitMachineInstrAfter(
const MachineInstr *MI) {}
1613 void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *MI) {
1614 BBInfo &MInfo = MBBInfoMap[MI->
getParent()];
1615 set_union(MInfo.regsKilled, regsKilled);
1616 set_subtract(regsLive, regsKilled); regsKilled.clear();
1618 while (!regMasks.empty()) {
1620 for (RegSet::iterator
I = regsLive.begin(),
E = regsLive.end();
I !=
E; ++
I)
1623 regsDead.push_back(*
I);
1626 set_union(regsLive, regsDefined); regsDefined.clear();
1631 MBBInfoMap[MBB].regsLiveOut = regsLive;
1636 if (!(stop > lastIndex)) {
1637 report(
"Block ends before last instruction index", MBB);
1638 errs() <<
"Block ends at " << stop
1639 <<
" last instruction was at " << lastIndex <<
'\n';
1648 void MachineVerifier::calcRegsPassed() {
1652 for (
const auto &MBB : *MF) {
1653 BBInfo &MInfo = MBBInfoMap[&MBB];
1654 if (!MInfo.reachable)
1657 SuE = MBB.
succ_end(); SuI != SuE; ++SuI) {
1658 BBInfo &SInfo = MBBInfoMap[*SuI];
1659 if (SInfo.addPassed(MInfo.regsLiveOut))
1666 while (!todo.
empty()) {
1669 BBInfo &MInfo = MBBInfoMap[MBB];
1671 SuE = MBB->
succ_end(); SuI != SuE; ++SuI) {
1674 BBInfo &SInfo = MBBInfoMap[*SuI];
1675 if (SInfo.addPassed(MInfo.vregsPassed))
1684 void MachineVerifier::calcRegsRequired() {
1687 for (
const auto &MBB : *MF) {
1688 BBInfo &MInfo = MBBInfoMap[&MBB];
1690 PrE = MBB.
pred_end(); PrI != PrE; ++PrI) {
1691 BBInfo &PInfo = MBBInfoMap[*PrI];
1692 if (PInfo.addRequired(MInfo.vregsLiveIn))
1699 while (!todo.
empty()) {
1702 BBInfo &MInfo = MBBInfoMap[MBB];
1704 PrE = MBB->
pred_end(); PrI != PrE; ++PrI) {
1707 BBInfo &SInfo = MBBInfoMap[*PrI];
1708 if (SInfo.addRequired(MInfo.vregsRequired))
1717 BBInfo &MInfo = MBBInfoMap[&MBB];
1727 report(
"Expected first PHI operand to be a register def", &MODef, 0);
1732 report(
"Unexpected flag on PHI operand", &MODef, 0);
1733 unsigned DefReg = MODef.
getReg();
1735 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
1737 for (
unsigned I = 1,
E = Phi.getNumOperands();
I !=
E;
I += 2) {
1740 report(
"Expected PHI operand to be a register", &MO0,
I);
1745 report(
"Unexpected flag on PHI operand", &MO0,
I);
1749 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
1755 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
1759 if (MInfo.reachable) {
1761 BBInfo &PrInfo = MBBInfoMap[&Pre];
1762 if (!MO0.
isUndef() && PrInfo.reachable &&
1763 !PrInfo.isLiveOut(MO0.
getReg()))
1764 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
1769 if (MInfo.reachable) {
1771 if (!seen.
count(Pred)) {
1772 report(
"Missing PHI operand", &Phi);
1774 <<
" is a predecessor according to the CFG.\n";
1781 void MachineVerifier::visitMachineFunctionAfter() {
1791 for (
const auto &MBB : *MF) {
1792 BBInfo &MInfo = MBBInfoMap[&MBB];
1793 for (RegSet::iterator
1794 I = MInfo.vregsRequired.begin(),
E = MInfo.vregsRequired.end();
I !=
E;
1796 if (MInfo.regsKilled.count(*
I)) {
1797 report(
"Virtual register killed in block, but needed live out.", &MBB);
1799 <<
" is used after the block.\n";
1804 BBInfo &MInfo = MBBInfoMap[&MF->front()];
1805 for (RegSet::iterator
1806 I = MInfo.vregsRequired.begin(),
E = MInfo.vregsRequired.end();
I !=
E;
1808 report(
"Virtual register defs don't dominate all uses.", MF);
1809 report_context_vreg(*
I);
1814 verifyLiveVariables();
1816 verifyLiveIntervals();
1819 void MachineVerifier::verifyLiveVariables() {
1820 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
1824 for (
const auto &MBB : *MF) {
1825 BBInfo &MInfo = MBBInfoMap[&MBB];
1828 if (MInfo.vregsRequired.count(Reg)) {
1830 report(
"LiveVariables: Block missing from AliveBlocks", &MBB);
1832 <<
" must be live through the block.\n";
1836 report(
"LiveVariables: Block should not be in AliveBlocks", &MBB);
1838 <<
" is not needed live through the block.\n";
1845 void MachineVerifier::verifyLiveIntervals() {
1846 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
1855 report(
"Missing live interval for virtual register", MF);
1856 errs() <<
printReg(Reg, TRI) <<
" still has defs or uses\n";
1861 assert(Reg == LI.
reg &&
"Invalid reg to interval mapping");
1862 verifyLiveInterval(LI);
1868 verifyLiveRange(*LR, i);
1871 void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
1872 const VNInfo *VNI,
unsigned Reg,
1880 report(
"Value not live at VNInfo def and not marked unused", MF);
1881 report_context(LR, Reg, LaneMask);
1882 report_context(*VNI);
1886 if (DefVNI != VNI) {
1887 report(
"Live segment at def has different VNInfo", MF);
1888 report_context(LR, Reg, LaneMask);
1889 report_context(*VNI);
1895 report(
"Invalid VNInfo definition index", MF);
1896 report_context(LR, Reg, LaneMask);
1897 report_context(*VNI);
1903 report(
"PHIDef VNInfo is not defined at MBB start", MBB);
1904 report_context(LR, Reg, LaneMask);
1905 report_context(*VNI);
1913 report(
"No instruction at VNInfo def index", MBB);
1914 report_context(LR, Reg, LaneMask);
1915 report_context(*VNI);
1920 bool hasDef =
false;
1921 bool isEarlyClobber =
false;
1923 if (!MOI->isReg() || !MOI->isDef())
1926 if (MOI->getReg() !=
Reg)
1933 if (LaneMask.
any() &&
1937 if (MOI->isEarlyClobber())
1938 isEarlyClobber =
true;
1942 report(
"Defining instruction does not modify register", MI);
1943 report_context(LR, Reg, LaneMask);
1944 report_context(*VNI);
1949 if (isEarlyClobber) {
1951 report(
"Early clobber def must be at an early-clobber slot", MBB);
1952 report_context(LR, Reg, LaneMask);
1953 report_context(*VNI);
1956 report(
"Non-PHI, non-early clobber def must be at a register slot", MBB);
1957 report_context(LR, Reg, LaneMask);
1958 report_context(*VNI);
1963 void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
1969 assert(VNI &&
"Live segment has no valno");
1972 report(
"Foreign valno in live segment", MF);
1973 report_context(LR, Reg, LaneMask);
1975 report_context(*VNI);
1979 report(
"Live segment valno is marked unused", MF);
1980 report_context(LR, Reg, LaneMask);
1986 report(
"Bad start of live segment, no basic block", MF);
1987 report_context(LR, Reg, LaneMask);
1993 report(
"Live segment must begin at MBB entry or valno def", MBB);
1994 report_context(LR, Reg, LaneMask);
2001 report(
"Bad end of live segment, no basic block", MF);
2002 report_context(LR, Reg, LaneMask);
2020 report(
"Live segment doesn't end at a valid instruction", EndMBB);
2021 report_context(LR, Reg, LaneMask);
2028 report(
"Live segment ends at B slot of an instruction", EndMBB);
2029 report_context(LR, Reg, LaneMask);
2037 report(
"Live segment ending at dead slot spans instructions", EndMBB);
2038 report_context(LR, Reg, LaneMask);
2046 if (I+1 == LR.
end() || (I+1)->start != S.
end) {
2047 report(
"Live segment ending at early clobber slot must be " 2048 "redefined by an EC def in the same instruction", EndMBB);
2049 report_context(LR, Reg, LaneMask);
2059 bool hasRead =
false;
2060 bool hasSubRegDef =
false;
2061 bool hasDeadDef =
false;
2063 if (!MOI->isReg() || MOI->getReg() !=
Reg)
2065 unsigned Sub = MOI->getSubReg();
2070 hasSubRegDef =
true;
2079 if (LaneMask.
any() && (LaneMask & SLM).none())
2081 if (MOI->readsReg())
2088 if (LaneMask.
none() && !hasDeadDef) {
2089 report(
"Instruction ending live segment on dead slot has no dead flag",
2091 report_context(LR, Reg, LaneMask);
2100 report(
"Instruction ending live segment doesn't read the register",
2102 report_context(LR, Reg, LaneMask);
2124 if (&*MFI == EndMBB)
2136 PE = MFI->pred_end(); PI != PE; ++PI) {
2144 if (!PVNI && (LaneMask.
none() || !IsPHI) ) {
2145 report(
"Register not marked live out of predecessor", *PI);
2146 report_context(LR, Reg, LaneMask);
2147 report_context(*VNI);
2155 if (!IsPHI && PVNI != VNI) {
2156 report(
"Different value live out of predecessor", *PI);
2157 report_context(LR, Reg, LaneMask);
2158 errs() <<
"Valno #" << PVNI->
id <<
" live out of " 2164 if (&*MFI == EndMBB)
2170 void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
unsigned Reg,
2173 verifyLiveRangeValue(LR, VNI, Reg, LaneMask);
2176 verifyLiveRangeSegment(LR, I, Reg, LaneMask);
2179 void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
2180 unsigned Reg = LI.
reg;
2182 verifyLiveRange(LI, Reg);
2187 if ((Mask & SR.LaneMask).any()) {
2188 report(
"Lane masks of sub ranges overlap in live interval", MF);
2191 if ((SR.LaneMask & ~MaxMask).any()) {
2192 report(
"Subrange lanemask is invalid", MF);
2196 report(
"Subrange must not be empty", MF);
2197 report_context(SR, LI.
reg, SR.LaneMask);
2199 Mask |= SR.LaneMask;
2200 verifyLiveRange(SR, LI.
reg, SR.LaneMask);
2202 report(
"A Subrange is not covered by the main range", MF);
2209 unsigned NumComp = ConEQ.
Classify(LI);
2211 report(
"Multiple connected components in live interval", MF);
2213 for (
unsigned comp = 0; comp != NumComp; ++comp) {
2214 errs() << comp <<
": valnos";
2218 errs() <<
' ' << (*I)->id;
2230 struct StackStateOfBB {
2231 StackStateOfBB() =
default;
2232 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup) :
2233 EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
2234 ExitIsSetup(ExitSetup) {}
2239 bool EntryIsSetup =
false;
2240 bool ExitIsSetup =
false;
2248 void MachineVerifier::verifyStackFrame() {
2251 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
2262 DFI != DFE; ++DFI) {
2265 StackStateOfBB BBState;
2267 if (DFI.getPathLength() >= 2) {
2270 "DFS stack predecessor is already visited.\n");
2271 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
2272 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
2273 BBState.ExitValue = BBState.EntryValue;
2274 BBState.ExitIsSetup = BBState.EntryIsSetup;
2278 for (
const auto &I : *MBB) {
2279 if (I.getOpcode() == FrameSetupOpcode) {
2280 if (BBState.ExitIsSetup)
2281 report(
"FrameSetup is after another FrameSetup", &I);
2283 BBState.ExitIsSetup =
true;
2286 if (I.getOpcode() == FrameDestroyOpcode) {
2288 if (!BBState.ExitIsSetup)
2289 report(
"FrameDestroy is not after a FrameSetup", &I);
2290 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
2292 if (BBState.ExitIsSetup && AbsSPAdj != Size) {
2293 report(
"FrameDestroy <n> is after FrameSetup <m>", &I);
2294 errs() <<
"FrameDestroy <" << Size <<
"> is after FrameSetup <" 2295 << AbsSPAdj <<
">.\n";
2297 BBState.ExitValue +=
Size;
2298 BBState.ExitIsSetup =
false;
2301 SPState[MBB->getNumber()] = BBState;
2306 E = MBB->pred_end(); I !=
E; ++
I) {
2307 if (Reachable.
count(*I) &&
2308 (SPState[(*I)->getNumber()].ExitValue != BBState.EntryValue ||
2309 SPState[(*I)->getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
2310 report(
"The exit stack state of a predecessor is inconsistent.", MBB);
2312 <<
" has exit state (" << SPState[(*I)->getNumber()].ExitValue
2313 <<
", " << SPState[(*I)->getNumber()].ExitIsSetup <<
"), while " 2315 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
2322 E = MBB->succ_end(); I !=
E; ++
I) {
2323 if (Reachable.
count(*I) &&
2324 (SPState[(*I)->getNumber()].EntryValue != BBState.ExitValue ||
2325 SPState[(*I)->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
2326 report(
"The entry stack state of a successor is inconsistent.", MBB);
2328 <<
" has entry state (" << SPState[(*I)->getNumber()].EntryValue
2329 <<
", " << SPState[(*I)->getNumber()].EntryIsSetup <<
"), while " 2331 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
2336 if (!MBB->empty() && MBB->back().isReturn()) {
2337 if (BBState.ExitIsSetup)
2338 report(
"A return block ends with a FrameSetup.", MBB);
2339 if (BBState.ExitValue)
2340 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.
Compute iterated dominance frontiers using a linear time algorithm.
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
iterator_range< mmo_iterator > memoperands()
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.
iterator_range< mop_iterator > operands()
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.
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.
A description of a memory reference used in the backend.
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
Access to explicit operands of the instruction.
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.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
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.
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.
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...
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.
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.
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.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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.
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
mmo_iterator memoperands_end() const
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.