104 assert(
Reg.isPhysical() &&
"reg must be a physical register");
105 assert(Ty.isValid() &&
"expected a valid type");
108 if (
TRI.isTypeLegalForClass(*RC, Ty))
112 return RC.contains(Reg) && TRI.isTypeLegalForClass(RC, Ty);
116struct MachineVerifier {
118 raw_ostream *OS,
bool AbortOnError =
true)
119 : MFAM(&MFAM), OS(OS ? *OS :
nulls()), Banner(
b),
120 ReportedErrs(AbortOnError) {}
122 MachineVerifier(
Pass *
pass,
const char *b, raw_ostream *OS,
123 bool AbortOnError =
true)
124 : PASS(
pass), OS(OS ? *OS :
nulls()), Banner(
b),
125 ReportedErrs(AbortOnError) {}
127 MachineVerifier(
const char *b, LiveVariables *LiveVars,
128 LiveIntervals *LiveInts, LiveStacks *LiveStks,
129 SlotIndexes *Indexes, raw_ostream *OS,
130 bool AbortOnError =
true)
131 : OS(OS ? *OS :
nulls()), Banner(
b), LiveVars(LiveVars),
132 LiveInts(LiveInts), LiveStks(LiveStks), Indexes(Indexes),
133 ReportedErrs(AbortOnError) {}
136 bool verify(
const MachineFunction &MF);
139 Pass *
const PASS =
nullptr;
142 const MachineFunction *MF =
nullptr;
143 const TargetMachine *TM =
nullptr;
144 const TargetInstrInfo *TII =
nullptr;
145 const TargetRegisterInfo *TRI =
nullptr;
146 const MachineRegisterInfo *MRI =
nullptr;
147 const RegisterBankInfo *RBI =
nullptr;
150 bool isFunctionRegBankSelected =
false;
151 bool isFunctionSelected =
false;
152 bool isFunctionTracksDebugUserValues =
false;
154 using RegVector = SmallVector<Register, 16>;
155 using RegMaskVector = SmallVector<const uint32_t *, 4>;
156 using RegSet = DenseSet<Register>;
157 using RegMap = DenseMap<Register, const MachineInstr *>;
158 using BlockSet = SmallPtrSet<const MachineBasicBlock *, 8>;
160 const MachineInstr *FirstNonPHI =
nullptr;
161 const MachineInstr *FirstTerminator =
nullptr;
162 BlockSet FunctionBlocks;
164 BitVector regsReserved;
166 RegVector regsDefined, regsDead, regsKilled;
167 RegMaskVector regMasks;
172 void addRegWithSubRegs(RegVector &RV,
Register Reg) {
180 bool reachable =
false;
201 RegSet vregsRequired;
213 if (regsLiveOut.count(
Reg))
219 bool addRequired(
const RegSet &RS) {
227 bool addRequired(
const RegMap &RM) {
229 for (
const auto &
I : RM)
236 return regsLiveOut.count(
Reg) || vregsPassed.count(
Reg);
241 DenseMap<const MachineBasicBlock *, BBInfo> MBBInfoMap;
244 return Reg.
id() < regsReserved.size() && regsReserved.test(
Reg.
id());
248 return Reg.
id() < TRI->getNumRegs() && TRI->isInAllocatableClass(
Reg) &&
249 !regsReserved.test(
Reg.
id());
253 LiveVariables *LiveVars =
nullptr;
254 LiveIntervals *LiveInts =
nullptr;
255 LiveStacks *LiveStks =
nullptr;
256 SlotIndexes *Indexes =
nullptr;
260 class ReportedErrors {
261 unsigned NumReported = 0;
266 ReportedErrors(
bool AbortOnError) : AbortOnError(AbortOnError) {}
273 " machine code errors.");
276 ReportedErrorsLock->unlock();
286 ReportedErrorsLock->lock();
288 return NumReported == 1;
292 bool hasError() {
return NumReported; }
294 ReportedErrors ReportedErrs;
299 MachineDominatorTree DT;
301 void visitMachineFunctionBefore();
302 void visitMachineBasicBlockBefore(
const MachineBasicBlock *
MBB);
303 void visitMachineBundleBefore(
const MachineInstr *
MI);
308 bool verifyAllRegOpsScalar(
const MachineInstr &
MI,
309 const MachineRegisterInfo &MRI);
310 bool verifyVectorElementMatch(LLT Ty0, LLT Ty1,
const MachineInstr *
MI);
312 bool verifyGIntrinsicSideEffects(
const MachineInstr *
MI);
313 bool verifyGIntrinsicConvergence(
const MachineInstr *
MI);
314 void verifyPreISelGenericInstruction(
const MachineInstr *
MI);
316 void visitMachineInstrBefore(
const MachineInstr *
MI);
317 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
318 void visitMachineBundleAfter(
const MachineInstr *
MI);
319 void visitMachineBasicBlockAfter(
const MachineBasicBlock *
MBB);
320 void visitMachineFunctionAfter();
322 void report(
const char *msg,
const MachineFunction *MF);
323 void report(
const char *msg,
const MachineBasicBlock *
MBB);
324 void report(
const char *msg,
const MachineInstr *
MI);
325 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
326 LLT MOVRegType = LLT{});
327 void report(
const Twine &
Msg,
const MachineInstr *
MI);
329 void report_context(
const LiveInterval &LI)
const;
330 void report_context(
const LiveRange &LR, VirtRegOrUnit VRegOrUnit,
331 LaneBitmask LaneMask)
const;
332 void report_context(
const LiveRange::Segment &S)
const;
333 void report_context(
const VNInfo &VNI)
const;
334 void report_context(SlotIndex Pos)
const;
335 void report_context(
MCPhysReg PhysReg)
const;
336 void report_context_liverange(
const LiveRange &LR)
const;
337 void report_context_lanemask(LaneBitmask LaneMask)
const;
338 void report_context_vreg(
Register VReg)
const;
339 void report_context_vreg_regunit(VirtRegOrUnit VRegOrUnit)
const;
341 void verifyInlineAsm(
const MachineInstr *
MI);
343 void checkLiveness(
const MachineOperand *MO,
unsigned MONum);
344 void checkLivenessAtUse(
const MachineOperand *MO,
unsigned MONum,
346 VirtRegOrUnit VRegOrUnit,
348 void checkLivenessAtDef(
const MachineOperand *MO,
unsigned MONum,
350 VirtRegOrUnit VRegOrUnit,
bool SubRangeCheck =
false,
353 void markReachable(
const MachineBasicBlock *
MBB);
354 void calcRegsPassed();
355 void checkPHIOps(
const MachineBasicBlock &
MBB);
357 void calcRegsRequired();
358 void verifyLiveVariables();
359 void verifyLiveIntervals();
360 void verifyLiveInterval(
const LiveInterval &);
361 void verifyLiveRangeValue(
const LiveRange &,
const VNInfo *, VirtRegOrUnit,
363 void verifyLiveRangeSegment(
const LiveRange &,
364 const LiveRange::const_iterator
I, VirtRegOrUnit,
366 void verifyLiveRange(
const LiveRange &, VirtRegOrUnit,
369 void verifyStackFrame();
371 void verifyStackProtector();
373 void verifySlotIndexes()
const;
374 void verifyProperties(
const MachineFunction &MF);
380 const std::string Banner;
382 MachineVerifierLegacyPass(std::string banner = std::string())
383 : MachineFunctionPass(ID), Banner(std::
move(banner)) {}
385 void getAnalysisUsage(AnalysisUsage &AU)
const override {
394 bool runOnMachineFunction(MachineFunction &MF)
override {
401 MachineVerifier(
this, Banner.c_str(), &
errs()).verify(MF);
416 MachineVerifier(MFAM, Banner.c_str(), &
errs()).verify(MF);
420char MachineVerifierLegacyPass::ID = 0;
423 "Verify generated machine code",
false,
false)
426 return new MachineVerifierLegacyPass(Banner);
436 MachineVerifier(
nullptr, Banner.c_str(), &
errs()).verify(MF);
440 bool AbortOnError)
const {
441 return MachineVerifier(p, Banner, OS, AbortOnError).verify(*
this);
446 bool AbortOnError)
const {
447 return MachineVerifier(MFAM, Banner, OS, AbortOnError).verify(*
this);
452 bool AbortOnError)
const {
453 return MachineVerifier(Banner,
nullptr, LiveInts,
454 nullptr, Indexes, OS, AbortOnError)
458void MachineVerifier::verifySlotIndexes()
const {
459 if (Indexes ==
nullptr)
476 report(
"Function has NoVRegs property but there are VReg operands", &MF);
488 const bool isFunctionFailedISel = Props.hasFailedISel();
493 if (isFunctionFailedISel)
496 isFunctionRegBankSelected = Props.hasRegBankSelected();
497 isFunctionSelected = Props.hasSelected();
498 isFunctionTracksDebugUserValues = Props.hasTracksDebugUserValues();
502 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
506 LiveVars = LVWrapper ? &LVWrapper->getLV() :
nullptr;
508 LiveStks = LSWrapper ? &LSWrapper->getLS() :
nullptr;
510 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
523 verifyProperties(MF);
525 visitMachineFunctionBefore();
527 visitMachineBasicBlockBefore(&
MBB);
531 bool InBundle =
false;
534 if (
MI.getParent() != &
MBB) {
535 report(
"Bad instruction parent pointer", &
MBB);
536 OS <<
"Instruction: " <<
MI;
541 if (InBundle && !
MI.isBundledWithPred())
542 report(
"Missing BundledPred flag, "
543 "BundledSucc was set on predecessor",
545 if (!InBundle &&
MI.isBundledWithPred())
546 report(
"BundledPred flag is set, "
547 "but BundledSucc not set on predecessor",
551 if (!
MI.isInsideBundle()) {
553 visitMachineBundleAfter(CurBundle);
555 visitMachineBundleBefore(CurBundle);
556 }
else if (!CurBundle)
557 report(
"No bundle header", &
MI);
558 visitMachineInstrBefore(&
MI);
559 for (
unsigned I = 0,
E =
MI.getNumOperands();
I !=
E; ++
I) {
561 if (
Op.getParent() != &
MI) {
564 report(
"Instruction has operand with wrong parent set", &
MI);
567 visitMachineOperand(&
Op,
I);
571 InBundle =
MI.isBundledWithSucc();
574 visitMachineBundleAfter(CurBundle);
576 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
577 visitMachineBasicBlockAfter(&
MBB);
579 visitMachineFunctionAfter();
589 return !ReportedErrs.hasError();
592void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
595 if (ReportedErrs.increment()) {
597 OS <<
"# " << Banner <<
'\n';
599 if (LiveInts !=
nullptr)
602 MF->
print(OS, Indexes);
605 OS <<
"*** Bad machine code: " << msg <<
" ***\n"
606 <<
"- function: " << MF->
getName() <<
'\n';
613 <<
" (" << (
const void *)
MBB <<
')';
615 OS <<
" [" << Indexes->getMBBStartIdx(
MBB) <<
';'
616 << Indexes->getMBBEndIdx(
MBB) <<
')';
620void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
622 report(msg,
MI->getParent());
623 OS <<
"- instruction: ";
624 if (Indexes && Indexes->hasIndex(*
MI))
625 OS << Indexes->getInstructionIndex(*
MI) <<
'\t';
629void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
630 unsigned MONum,
LLT MOVRegType) {
633 OS <<
"- operand " << MONum <<
": ";
639 report(
Msg.str().c_str(),
MI);
642void MachineVerifier::report_context(
SlotIndex Pos)
const {
643 OS <<
"- at: " << Pos <<
'\n';
646void MachineVerifier::report_context(
const LiveInterval &LI)
const {
647 OS <<
"- interval: " << LI <<
'\n';
650void MachineVerifier::report_context(
const LiveRange &LR,
653 report_context_liverange(LR);
654 report_context_vreg_regunit(VRegOrUnit);
656 report_context_lanemask(LaneMask);
660 OS <<
"- segment: " << S <<
'\n';
663void MachineVerifier::report_context(
const VNInfo &VNI)
const {
664 OS <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
667void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
668 OS <<
"- liverange: " << LR <<
'\n';
671void MachineVerifier::report_context(
MCPhysReg PReg)
const {
672 OS <<
"- p. register: " <<
printReg(PReg,
TRI) <<
'\n';
675void MachineVerifier::report_context_vreg(
Register VReg)
const {
676 OS <<
"- v. register: " <<
printReg(VReg,
TRI) <<
'\n';
679void MachineVerifier::report_context_vreg_regunit(
689void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
694 BBInfo &MInfo = MBBInfoMap[
MBB];
695 if (!MInfo.reachable) {
696 MInfo.reachable =
true;
702void MachineVerifier::visitMachineFunctionBefore() {
705 :
TRI->getReservedRegs(*MF);
708 markReachable(&MF->
front());
711 FunctionBlocks.
clear();
712 for (
const auto &
MBB : *MF) {
714 BBInfo &MInfo = MBBInfoMap[&
MBB];
718 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
722 report(
"MBB has duplicate entries in its successor list.", &
MBB);
730 verifyStackProtector();
737 return !
MBB.phis().empty();
743 FirstTerminator =
nullptr;
744 FirstNonPHI =
nullptr;
750 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
753 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
754 "inlineasm-br-indirect-target.",
756 report_context(LI.PhysReg);
763 report(
"ir-block-address-taken is associated with basic block not used by "
772 LandingPadSuccs.
insert(succ);
773 if (!FunctionBlocks.
count(succ))
774 report(
"MBB has successor that isn't part of the function.",
MBB);
775 if (!MBBInfoMap[succ].Preds.
count(
MBB)) {
776 report(
"Inconsistent CFG",
MBB);
777 OS <<
"MBB is not in the predecessor list of the successor "
784 if (!FunctionBlocks.
count(Pred))
785 report(
"MBB has predecessor that isn't part of the function.",
MBB);
786 if (!MBBInfoMap[Pred].Succs.
count(
MBB)) {
787 report(
"Inconsistent CFG",
MBB);
788 OS <<
"MBB is not in the successor list of the predecessor "
796 if (LandingPadSuccs.
size() > 1 &&
800 report(
"MBB has more than one landing pad successor",
MBB);
813 report(
"MBB exits via unconditional fall-through but ends with a "
814 "barrier instruction!",
MBB);
817 report(
"MBB exits via unconditional fall-through but has a condition!",
823 report(
"MBB exits via unconditional branch but doesn't contain "
824 "any instructions!",
MBB);
826 report(
"MBB exits via unconditional branch but doesn't end with a "
827 "barrier instruction!",
MBB);
829 report(
"MBB exits via unconditional branch but the branch isn't a "
830 "terminator instruction!",
MBB);
835 report(
"MBB exits via conditional branch/fall-through but doesn't "
836 "contain any instructions!",
MBB);
838 report(
"MBB exits via conditional branch/fall-through but ends with a "
839 "barrier instruction!",
MBB);
841 report(
"MBB exits via conditional branch/fall-through but the branch "
842 "isn't a terminator instruction!",
MBB);
844 }
else if (
TBB && FBB) {
848 report(
"MBB exits via conditional branch/branch but doesn't "
849 "contain any instructions!",
MBB);
851 report(
"MBB exits via conditional branch/branch but doesn't end with a "
852 "barrier instruction!",
MBB);
854 report(
"MBB exits via conditional branch/branch but the branch "
855 "isn't a terminator instruction!",
MBB);
858 report(
"MBB exits via conditional branch/branch but there's no "
862 report(
"analyzeBranch returned invalid data!",
MBB);
868 report(
"MBB exits via jump or conditional branch, but its target isn't a "
872 report(
"MBB exits via conditional branch, but its target isn't a CFG "
879 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
884 if (!
Cond.empty() && !FBB) {
887 report(
"MBB conditionally falls through out of function!",
MBB);
889 report(
"MBB exits via conditional branch/fall-through but the CFG "
890 "successors don't match the actual successors!",
897 if (SuccMBB ==
TBB || SuccMBB == FBB)
905 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
907 report(
"MBB has unexpected successors which are not branch targets, "
908 "fallthrough, EHPads, or inlineasm_br targets.",
916 if (!LI.PhysReg.isPhysical()) {
917 report(
"MBB live-in list contains non-physical register",
MBB);
920 regsLive.insert_range(
TRI->subregs_inclusive(LI.PhysReg));
927 regsLive.insert_range(
TRI->subregs_inclusive(
I));
933 lastIndex = Indexes->getMBBStartIdx(
MBB);
938void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
939 if (Indexes && Indexes->hasIndex(*
MI)) {
941 if (!(idx > lastIndex)) {
942 report(
"Instruction index out of order",
MI);
943 OS <<
"Last instruction was at " << lastIndex <<
'\n';
949 if (
MI->isTerminator()) {
950 if (!FirstTerminator)
951 FirstTerminator =
MI;
952 }
else if (FirstTerminator) {
955 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
956 report(
"Non-terminator instruction after the first terminator",
MI);
957 OS <<
"First terminator was:\t" << *FirstTerminator;
966 if (
MI->getNumOperands() < 2) {
967 report(
"Too few operands on inline asm",
MI);
970 if (!
MI->getOperand(0).isSymbol())
971 report(
"Asm string must be an external symbol",
MI);
972 if (!
MI->getOperand(1).isImm())
973 report(
"Asm flags must be an immediate",
MI);
978 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
984 for (
unsigned e =
MI->getNumOperands(); OpNo < e; OpNo +=
NumOps) {
990 NumOps = 1 +
F.getNumOperandRegisters();
993 if (OpNo >
MI->getNumOperands())
994 report(
"Missing operands in last group",
MI);
997 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
1001 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
1004 report(
"Expected implicit register after groups", &MO, OpNo);
1007 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
1020 if (!IndirectTargetMBB) {
1021 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1026 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1030 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1036bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1041 const auto Reg = Op.getReg();
1042 if (Reg.isPhysical())
1044 return !MRI.getType(Reg).isScalar();
1047 report(
"All register operands must have scalar types", &
MI);
1054bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1057 report(
"operand types must be all-vector or all-scalar",
MI);
1067 report(
"operand types must preserve number of vector elements",
MI);
1074bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1075 auto Opcode =
MI->getOpcode();
1076 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1077 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1079 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1081 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1082 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1083 if (NoSideEffects && DeclHasSideEffects) {
1085 " used with intrinsic that accesses memory"),
1089 if (!NoSideEffects && !DeclHasSideEffects) {
1090 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1098bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1099 auto Opcode =
MI->getOpcode();
1100 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1101 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1103 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1105 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1106 bool DeclIsConvergent =
Attrs.hasAttribute(Attribute::Convergent);
1107 if (NotConvergent && DeclIsConvergent) {
1108 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1112 if (!NotConvergent && !DeclIsConvergent) {
1114 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1123void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1124 if (isFunctionSelected)
1125 report(
"Unexpected generic instruction in a Selected function",
MI);
1128 unsigned NumOps =
MI->getNumOperands();
1131 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1132 bool HasMBB =
false;
1141 report(
"Branch instruction is missing a basic block operand or "
1142 "isIndirectBranch property",
1149 for (
unsigned I = 0,
E = std::min(
MCID.getNumOperands(),
NumOps);
1151 if (!
MCID.operands()[
I].isGenericType())
1155 size_t TypeIdx =
MCID.operands()[
I].getGenericTypeIndex();
1156 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1160 report(
"generic instruction must use register operands",
MI);
1170 if (!Types[TypeIdx].
isValid())
1171 Types[TypeIdx] = OpTy;
1172 else if (Types[TypeIdx] != OpTy)
1173 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1176 report(
"Generic instruction is missing a virtual register type", MO,
I);
1181 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1184 report(
"Generic instruction cannot have physical register", MO,
I);
1188 if (
MI->getNumOperands() <
MCID.getNumOperands())
1196 unsigned Opc =
MI->getOpcode();
1198 case TargetOpcode::G_ASSERT_SEXT:
1199 case TargetOpcode::G_ASSERT_ZEXT: {
1200 std::string OpcName =
1201 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1202 if (!
MI->getOperand(2).isImm()) {
1203 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1210 int64_t
Imm =
MI->getOperand(2).getImm();
1212 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1217 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1225 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1226 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1234 Twine(OpcName,
" source and destination register classes must match"),
1242 case TargetOpcode::G_CONSTANT:
1243 case TargetOpcode::G_FCONSTANT: {
1246 report(
"Instruction cannot use a vector result type",
MI);
1248 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1249 if (!
MI->getOperand(1).isCImm()) {
1250 report(
"G_CONSTANT operand must be cimm",
MI);
1256 report(
"inconsistent constant size",
MI);
1258 if (!
MI->getOperand(1).isFPImm()) {
1259 report(
"G_FCONSTANT operand must be fpimm",
MI);
1266 report(
"inconsistent constant size",
MI);
1272 case TargetOpcode::G_LOAD:
1273 case TargetOpcode::G_STORE:
1274 case TargetOpcode::G_ZEXTLOAD:
1275 case TargetOpcode::G_SEXTLOAD:
1276 case TargetOpcode::G_FPEXTLOAD:
1277 case TargetOpcode::G_FPTRUNCSTORE: {
1281 report(
"Generic memory instruction must access a pointer",
MI);
1285 if (!
MI->hasOneMemOperand()) {
1286 report(
"Generic instruction accessing memory must have one mem operand",
1293 report(
"Generic extload must have a narrower memory type",
MI);
1297 report(
"Generic truncstore must have a narrower memory type",
MI);
1298 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1301 report(
"load memory size cannot exceed result size",
MI);
1312 report(
"range is incompatible with the result type",
MI);
1315 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1318 report(
"store memory size cannot exceed value size",
MI);
1325 report(
"atomic store cannot use acquire ordering",
MI);
1330 report(
"atomic load cannot use release ordering",
MI);
1336 case TargetOpcode::G_PHI: {
1342 LLT Ty = MRI->getType(MO.getReg());
1343 if (!Ty.isValid() || (Ty != DstTy))
1347 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1352 case TargetOpcode::G_BITCAST: {
1359 report(
"bitcast cannot convert between pointers and other types",
MI);
1362 report(
"bitcast sizes must match",
MI);
1376 report(
"bitcast must change the type",
MI);
1380 case TargetOpcode::G_INTTOPTR:
1381 case TargetOpcode::G_PTRTOINT:
1382 case TargetOpcode::G_ADDRSPACE_CAST: {
1388 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1393 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1395 report(
"inttoptr result type must be a pointer",
MI);
1397 report(
"inttoptr source type must not be a pointer",
MI);
1398 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1400 report(
"ptrtoint source type must be a pointer",
MI);
1402 report(
"ptrtoint result type must not be a pointer",
MI);
1404 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1406 report(
"addrspacecast types must be pointers",
MI);
1409 report(
"addrspacecast must convert different address spaces",
MI);
1415 case TargetOpcode::G_PTR_ADD: {
1418 LLT OffsetTy = MRI->
getType(
MI->getOperand(2).getReg());
1423 report(
"gep first operand must be a pointer",
MI);
1426 report(
"gep offset operand must not be a pointer",
MI);
1431 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1433 report(
"gep offset operand must match index size for address space",
1441 case TargetOpcode::G_PTRMASK: {
1449 report(
"ptrmask result type must be a pointer",
MI);
1452 report(
"ptrmask mask type must be an integer",
MI);
1454 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1457 case TargetOpcode::G_SEXT:
1458 case TargetOpcode::G_ZEXT:
1459 case TargetOpcode::G_ANYEXT:
1460 case TargetOpcode::G_TRUNC:
1461 case TargetOpcode::G_TRUNC_SSAT_S:
1462 case TargetOpcode::G_TRUNC_SSAT_U:
1463 case TargetOpcode::G_TRUNC_USAT_U:
1464 case TargetOpcode::G_FPEXT:
1465 case TargetOpcode::G_FPTRUNC: {
1471 assert(
MCID.getNumOperands() == 2 &&
"Expected 2 operands G_*{EXT,TRUNC}");
1478 report(
"Generic extend/truncate can not operate on pointers",
MI);
1480 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1484 switch (
MI->getOpcode()) {
1486 if (DstSize <= SrcSize)
1487 report(
"Generic extend has destination type no larger than source",
MI);
1489 case TargetOpcode::G_TRUNC:
1490 case TargetOpcode::G_TRUNC_SSAT_S:
1491 case TargetOpcode::G_TRUNC_SSAT_U:
1492 case TargetOpcode::G_TRUNC_USAT_U:
1493 case TargetOpcode::G_FPTRUNC:
1494 if (DstSize >= SrcSize)
1495 report(
"Generic truncate has destination type no smaller than source",
1501 case TargetOpcode::G_SELECT: {
1509 verifyVectorElementMatch(SelTy, CondTy,
MI);
1512 case TargetOpcode::G_MERGE_VALUES: {
1520 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1522 const unsigned NumOps =
MI->getNumOperands();
1524 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1526 for (
unsigned I = 2;
I !=
NumOps; ++
I) {
1527 if (MRI->
getType(
MI->getOperand(
I).getReg()) != SrcTy)
1528 report(
"G_MERGE_VALUES source types do not match",
MI);
1533 case TargetOpcode::G_UNMERGE_VALUES: {
1534 unsigned NumDsts =
MI->getNumOperands() - 1;
1536 for (
unsigned i = 1; i < NumDsts; ++i) {
1537 if (MRI->
getType(
MI->getOperand(i).getReg()) != DstTy) {
1538 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1543 LLT SrcTy = MRI->
getType(
MI->getOperand(NumDsts).getReg());
1551 report(
"G_UNMERGE_VALUES source operand does not match vector "
1552 "destination operands",
1559 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1560 "destination operands",
1565 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1566 "destination operands",
1572 case TargetOpcode::G_BUILD_VECTOR: {
1576 LLT SrcEltTy = MRI->
getType(
MI->getOperand(1).getReg());
1578 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1583 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1586 report(
"G_BUILD_VECTOR must have an operand for each element",
MI);
1590 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1594 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1598 LLT SrcEltTy = MRI->
getType(
MI->getOperand(1).getReg());
1600 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1604 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1607 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1612 case TargetOpcode::G_CONCAT_VECTORS: {
1618 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1621 if (
MI->getNumOperands() < 3)
1622 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1626 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1629 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1632 case TargetOpcode::G_ICMP:
1633 case TargetOpcode::G_FCMP: {
1640 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1644 case TargetOpcode::G_SCMP:
1645 case TargetOpcode::G_UCMP: {
1650 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1655 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1660 report(
"Result type must be at least 2 bits wide",
MI);
1667 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1673 case TargetOpcode::G_EXTRACT: {
1675 if (!
SrcOp.isReg()) {
1676 report(
"extract source must be a register",
MI);
1682 report(
"extract offset must be a constant",
MI);
1688 if (SrcSize == DstSize)
1689 report(
"extract source must be larger than result",
MI);
1691 if (DstSize +
OffsetOp.getImm() > SrcSize)
1692 report(
"extract reads past end of register",
MI);
1695 case TargetOpcode::G_INSERT: {
1697 if (!
SrcOp.isReg()) {
1698 report(
"insert source must be a register",
MI);
1704 report(
"insert offset must be a constant",
MI);
1711 if (DstSize <= SrcSize)
1712 report(
"inserted size must be smaller than total register",
MI);
1714 if (SrcSize +
OffsetOp.getImm() > DstSize)
1715 report(
"insert writes past end of register",
MI);
1719 case TargetOpcode::G_JUMP_TABLE: {
1720 if (!
MI->getOperand(1).isJTI())
1721 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1724 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1727 case TargetOpcode::G_BRJT: {
1729 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1731 if (!
MI->getOperand(1).isJTI())
1732 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1734 const auto &IdxOp =
MI->getOperand(2);
1736 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1739 case TargetOpcode::G_INTRINSIC:
1740 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1741 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1742 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1747 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1751 if (!verifyGIntrinsicSideEffects(
MI))
1753 if (!verifyGIntrinsicConvergence(
MI))
1758 case TargetOpcode::G_SEXT_INREG: {
1759 if (!
MI->getOperand(2).isImm()) {
1760 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1765 int64_t
Imm =
MI->getOperand(2).getImm();
1767 report(
"G_SEXT_INREG size must be >= 1",
MI);
1769 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1772 case TargetOpcode::G_BSWAP: {
1775 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1778 case TargetOpcode::G_VSCALE: {
1779 if (!
MI->getOperand(1).isCImm()) {
1780 report(
"G_VSCALE operand must be cimm",
MI);
1783 if (
MI->getOperand(1).getCImm()->isZero()) {
1784 report(
"G_VSCALE immediate cannot be zero",
MI);
1789 case TargetOpcode::G_STEP_VECTOR: {
1790 if (!
MI->getOperand(1).isCImm()) {
1791 report(
"operand must be cimm",
MI);
1795 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1796 report(
"step must be > 0",
MI);
1802 report(
"Destination type must be a scalable vector",
MI);
1808 report(
"Destination element type must be scalar",
MI);
1812 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1814 report(
"step bitwidth differs from result type element bitwidth",
MI);
1819 case TargetOpcode::G_INSERT_SUBVECTOR: {
1821 if (!Src0Op.
isReg()) {
1822 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1827 if (!Src1Op.
isReg()) {
1828 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1833 if (!IndexOp.
isImm()) {
1834 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1842 report(
"Destination type must be a vector",
MI);
1847 report(
"Second source must be a vector",
MI);
1852 report(
"Element type of vectors must be the same",
MI);
1857 report(
"Cannot insert a scalable vector into a fixed length vector",
MI);
1861 bool IsMixedFixedIntoScalable =
1864 if (!IsMixedFixedIntoScalable &&
1867 report(
"Second source must be smaller than destination vector",
MI);
1871 uint64_t Idx = IndexOp.
getImm();
1873 if (IndexOp.
getImm() % Src1MinLen != 0) {
1874 report(
"Index must be a multiple of the second source vector's "
1875 "minimum vector length",
1881 if (Idx >= DstMinLen ||
1882 (!IsMixedFixedIntoScalable && Idx + Src1MinLen > DstMinLen)) {
1883 report(
"Subvector type and index must not cause insert to overrun the "
1884 "vector being inserted into",
1891 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1893 if (!
SrcOp.isReg()) {
1894 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1899 if (!IndexOp.
isImm()) {
1900 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1908 report(
"Destination type must be a vector",
MI);
1913 report(
"Source must be a vector",
MI);
1918 report(
"Element type of vectors must be the same",
MI);
1923 report(
"Cannot extract a scalable vector from a fixed length vector",
MI);
1929 report(
"Destination vector must be smaller than source vector",
MI);
1933 uint64_t Idx = IndexOp.
getImm();
1935 if (Idx % DstMinLen != 0) {
1936 report(
"Index must be a multiple of the destination vector's minimum "
1942 bool IsMixedFixedFromScalable =
1945 if (Idx >= SrcMinLen ||
1946 (!IsMixedFixedFromScalable && Idx + DstMinLen > SrcMinLen)) {
1947 report(
"Destination type and index must not cause extract to overrun the "
1955 case TargetOpcode::G_SHUFFLE_VECTOR: {
1958 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1966 if (Src0Ty != Src1Ty)
1967 report(
"Source operands must be the same type",
MI);
1970 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1974 report(
"G_SHUFFLE_VECTOR must have vector src",
MI);
1978 report(
"G_SHUFFLE_VECTOR must have vector dst",
MI);
1989 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1990 report(
"Wrong result type for shufflemask",
MI);
1992 for (
int Idx : MaskIdxes) {
1996 if (Idx >= 2 * SrcNumElts)
1997 report(
"Out of bounds shuffle index",
MI);
2003 case TargetOpcode::G_SPLAT_VECTOR: {
2008 report(
"Destination type must be a scalable vector",
MI);
2013 report(
"Source type must be a scalar or pointer",
MI);
2019 report(
"Element type of the destination must be the same size or smaller "
2020 "than the source type",
2027 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
2033 report(
"Destination type must be a scalar or pointer",
MI);
2038 report(
"First source must be a vector",
MI);
2042 auto TLI = MF->getSubtarget().getTargetLowering();
2043 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2044 report(
"Index type must match VectorIdxTy",
MI);
2050 case TargetOpcode::G_INSERT_VECTOR_ELT: {
2057 report(
"Destination type must be a vector",
MI);
2061 if (VecTy != DstTy) {
2062 report(
"Destination type and vector type must match",
MI);
2067 report(
"Inserted element must be a scalar or pointer",
MI);
2071 auto TLI = MF->getSubtarget().getTargetLowering();
2072 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2073 report(
"Index type must match VectorIdxTy",
MI);
2079 case TargetOpcode::G_DYN_STACKALLOC: {
2085 report(
"dst operand 0 must be a pointer type",
MI);
2090 report(
"src operand 1 must be a scalar reg type",
MI);
2094 if (!AlignOp.
isImm()) {
2095 report(
"src operand 2 must be an immediate type",
MI);
2100 case TargetOpcode::G_MEMCPY_INLINE:
2101 case TargetOpcode::G_MEMCPY:
2102 case TargetOpcode::G_MEMMOVE: {
2104 if (MMOs.
size() != 2) {
2105 report(
"memcpy/memmove must have 2 memory operands",
MI);
2111 report(
"wrong memory operand types",
MI);
2116 report(
"inconsistent memory operand sizes",
MI);
2118 LLT DstPtrTy = MRI->
getType(
MI->getOperand(0).getReg());
2119 LLT SrcPtrTy = MRI->
getType(
MI->getOperand(1).getReg());
2122 report(
"memory instruction operand must be a pointer",
MI);
2127 report(
"inconsistent store address space",
MI);
2129 report(
"inconsistent load address space",
MI);
2131 if (
Opc != TargetOpcode::G_MEMCPY_INLINE)
2132 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2133 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2137 case TargetOpcode::G_BZERO:
2138 case TargetOpcode::G_MEMSET:
2139 case TargetOpcode::G_MEMSET_INLINE: {
2141 std::string
Name =
Opc == TargetOpcode::G_MEMSET ?
"memset"
2142 :
Opc == TargetOpcode::G_MEMSET_INLINE ?
"memset_inline"
2144 if (MMOs.
size() != 1) {
2145 report(
Twine(Name,
" must have 1 memory operand"),
MI);
2150 report(
Twine(Name,
" memory operand must be a store"),
MI);
2154 LLT DstPtrTy = MRI->
getType(
MI->getOperand(0).getReg());
2156 report(
Twine(Name,
" operand must be a pointer"),
MI);
2161 report(
"inconsistent " +
Twine(Name,
" address space"),
MI);
2163 if (
Opc != TargetOpcode::G_MEMSET_INLINE) {
2164 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2165 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2166 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2171 case TargetOpcode::G_UBSANTRAP: {
2173 if (!
MI->getOperand(0).isImm()) {
2174 report(
"Crash kind must be an immediate", &KindOp, 0);
2177 int64_t
Kind =
MI->getOperand(0).getImm();
2179 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2182 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2183 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2188 report(
"Vector reduction requires a scalar destination type",
MI);
2190 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2192 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2195 case TargetOpcode::G_VECREDUCE_FADD:
2196 case TargetOpcode::G_VECREDUCE_FMUL:
2197 case TargetOpcode::G_VECREDUCE_FMAX:
2198 case TargetOpcode::G_VECREDUCE_FMIN:
2199 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2200 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2201 case TargetOpcode::G_VECREDUCE_ADD:
2202 case TargetOpcode::G_VECREDUCE_MUL:
2203 case TargetOpcode::G_VECREDUCE_AND:
2204 case TargetOpcode::G_VECREDUCE_OR:
2205 case TargetOpcode::G_VECREDUCE_XOR:
2206 case TargetOpcode::G_VECREDUCE_SMAX:
2207 case TargetOpcode::G_VECREDUCE_SMIN:
2208 case TargetOpcode::G_VECREDUCE_UMAX:
2209 case TargetOpcode::G_VECREDUCE_UMIN: {
2212 report(
"Vector reduction requires a scalar destination type",
MI);
2216 case TargetOpcode::G_SBFX:
2217 case TargetOpcode::G_UBFX: {
2220 report(
"Bitfield extraction is not supported on vectors",
MI);
2225 case TargetOpcode::G_SHL:
2226 case TargetOpcode::G_LSHR:
2227 case TargetOpcode::G_ASHR:
2228 case TargetOpcode::G_ROTR:
2229 case TargetOpcode::G_ROTL: {
2233 report(
"Shifts and rotates require operands to be either all scalars or "
2240 case TargetOpcode::G_LLROUND:
2241 case TargetOpcode::G_LROUND: {
2248 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2250 verifyAllRegOpsScalar(*
MI, *MRI);
2253 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2258 case TargetOpcode::G_IS_FPCLASS: {
2262 report(
"Destination must be a scalar or vector of scalars",
MI);
2268 report(
"Source must be a scalar or vector of scalars",
MI);
2271 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2274 if (!TestMO.
isImm()) {
2275 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2280 report(
"Incorrect floating-point class set (operand 2)",
MI);
2285 case TargetOpcode::G_PREFETCH: {
2288 report(
"addr operand must be a pointer", &AddrOp, 0);
2292 if (!RWOp.
isImm() || (uint64_t)RWOp.
getImm() >= 2) {
2293 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2297 if (!LocalityOp.
isImm() || (uint64_t)LocalityOp.
getImm() >= 4) {
2298 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2302 if (!CacheTypeOp.
isImm() || (uint64_t)CacheTypeOp.
getImm() >= 2) {
2303 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2308 case TargetOpcode::G_ASSERT_ALIGN: {
2309 if (
MI->getOperand(2).getImm() < 1)
2310 report(
"alignment immediate must be >= 1",
MI);
2313 case TargetOpcode::G_CONSTANT_POOL: {
2314 if (!
MI->getOperand(1).isCPI())
2315 report(
"Src operand 1 must be a constant pool index",
MI);
2317 report(
"Dst operand 0 must be a pointer",
MI);
2320 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2323 report(
"addr operand must be a pointer", &AddrOp, 1);
2326 case TargetOpcode::G_SMIN:
2327 case TargetOpcode::G_SMAX:
2328 case TargetOpcode::G_UMIN:
2329 case TargetOpcode::G_UMAX: {
2330 const LLT DstTy = MRI->
getType(
MI->getOperand(0).getReg());
2332 report(
"Generic smin/smax/umin/umax does not support pointer operands",
2341void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2343 if (
MI->getNumOperands() <
MCID.getNumOperands()) {
2344 report(
"Too few operands",
MI);
2345 OS <<
MCID.getNumOperands() <<
" operands expected, but "
2346 <<
MI->getNumOperands() <<
" given.\n";
2350 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2353 if (MF->getProperties().hasNoPHIs())
2354 report(
"Found PHI instruction with NoPHIs property set",
MI);
2357 report(
"Found PHI instruction after non-PHI",
MI);
2358 }
else if (FirstNonPHI ==
nullptr)
2362 if (
MI->isInlineAsm())
2363 verifyInlineAsm(
MI);
2366 if (
TII->isUnspillableTerminator(
MI)) {
2367 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2368 report(
"Unspillable Terminator does not define a reg",
MI);
2372 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2378 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2379 if (!
MI->getDebugLoc())
2380 report(
"Missing DebugLoc for debug instruction",
MI);
2384 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2385 report(
"Metadata instruction should not have a value tracking number",
MI);
2389 if (
Op->isLoad() && !
MI->mayLoad())
2390 report(
"Missing mayLoad flag",
MI);
2391 if (
Op->isStore() && !
MI->mayStore())
2392 report(
"Missing mayStore flag",
MI);
2398 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2399 if (
MI->isDebugOrPseudoInstr()) {
2401 report(
"Debug instruction has a slot index",
MI);
2402 }
else if (
MI->isInsideBundle()) {
2404 report(
"Instruction inside bundle has a slot index",
MI);
2407 report(
"Missing slot index",
MI);
2411 unsigned Opc =
MCID.getOpcode();
2413 verifyPreISelGenericInstruction(
MI);
2422 switch (
MI->getOpcode()) {
2423 case TargetOpcode::COPY: {
2433 if (SrcTy != DstTy) {
2434 report(
"Copy Instruction is illegal with mismatching types",
MI);
2435 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2449 if (!hasPhysRegClassForType(*
TRI, SrcReg, DstTy))
2450 SrcSize =
TRI->getRegSizeInBits(SrcReg, *MRI);
2452 SrcSize =
TRI->getRegSizeInBits(SrcReg, *MRI);
2456 if (!hasPhysRegClassForType(*
TRI, DstReg, SrcTy))
2457 DstSize =
TRI->getRegSizeInBits(DstReg, *MRI);
2459 DstSize =
TRI->getRegSizeInBits(DstReg, *MRI);
2477 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2478 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2479 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2484 case TargetOpcode::COPY_LANEMASK: {
2492 if (
DstOp.getSubReg())
2493 report(
"COPY_LANEMASK must not use a subregister index", &
DstOp, 0);
2495 if (
SrcOp.getSubReg())
2496 report(
"COPY_LANEMASK must not use a subregister index", &
SrcOp, 1);
2498 if (LaneMask.
none())
2499 report(
"COPY_LANEMASK must read at least one lane",
MI);
2511 if (SrcMaxLaneMask == LaneMask)
2512 report(
"COPY_LANEMASK cannot be used to do full copy",
MI);
2517 if (SrcMaxLaneMask < LaneMask)
2518 report(
"COPY_LANEMASK attempts to read from the lanes that "
2519 "don't exist in the source register",
2524 case TargetOpcode::STATEPOINT: {
2526 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2527 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2528 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2529 report(
"meta operands to STATEPOINT not constant!",
MI);
2533 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2534 if (
Offset >=
MI->getNumOperands()) {
2535 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2538 if (!
MI->getOperand(
Offset - 1).isImm() ||
2539 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2541 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2543 VerifyStackMapConstant(SO.getCCIdx());
2544 VerifyStackMapConstant(SO.getFlagsIdx());
2545 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2546 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2547 VerifyStackMapConstant(SO.getNumAllocaIdx());
2548 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2552 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2553 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2554 for (
unsigned Idx = 0; Idx <
MI->getNumDefs(); Idx++) {
2556 if (!
MI->isRegTiedToUseOperand(Idx, &UseOpIdx)) {
2557 report(
"STATEPOINT defs expected to be tied",
MI);
2560 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2561 report(
"STATEPOINT def tied to non-gc operand",
MI);
2568 case TargetOpcode::INSERT_SUBREG: {
2569 unsigned InsertedSize;
2570 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2571 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2573 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *MRI);
2574 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2575 if (SubRegSize < InsertedSize) {
2576 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2577 "size than the subreg it was inserted into",
MI);
2581 case TargetOpcode::REG_SEQUENCE: {
2582 unsigned NumOps =
MI->getNumOperands();
2584 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2588 for (
unsigned I = 1;
I !=
NumOps;
I += 2) {
2593 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2595 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2596 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2597 report(
"Invalid subregister index operand for REG_SEQUENCE",
2602 Register DstReg =
MI->getOperand(0).getReg();
2604 report(
"REG_SEQUENCE does not support physical register results",
MI);
2606 if (
MI->getOperand(0).getSubReg())
2607 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2615MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2618 unsigned NumDefs =
MCID.getNumDefs();
2619 if (
MCID.getOpcode() == TargetOpcode::PATCHPOINT)
2620 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2623 if (MONum < NumDefs) {
2626 report(
"Explicit definition must be a register", MO, MONum);
2627 else if (!MO->
isDef() && !
MCOI.isOptionalDef())
2628 report(
"Explicit definition marked as use", MO, MONum);
2630 report(
"Explicit definition marked as implicit", MO, MONum);
2631 }
else if (MONum <
MCID.getNumOperands()) {
2635 bool IsOptional =
MI->isVariadic() && MONum ==
MCID.getNumOperands() - 1;
2638 if (MO->
isDef() && !
MCOI.isOptionalDef() && !
MCID.variadicOpsAreDefs())
2639 report(
"Explicit operand marked as def", MO, MONum);
2641 report(
"Explicit operand marked as implicit", MO, MONum);
2647 report(
"Expected a register operand.", MO, MONum);
2651 !
TII->isPCRelRegisterOperandLegal(*MO)))
2652 report(
"Expected a non-register operand.", MO, MONum);
2659 report(
"Tied use must be a register", MO, MONum);
2661 report(
"Operand should be tied", MO, MONum);
2662 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2663 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2666 if (!MOTied.
isReg())
2667 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2670 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2673 report(
"Explicit operand should not be tied", MO, MONum);
2674 }
else if (!
MI->isVariadic()) {
2677 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2683 report(
"Early clobber must be a register",
MI);
2685 report(
"Missing earlyClobber flag",
MI);
2692 if (
MI->isDebugInstr() && MO->
isUse()) {
2694 report(
"Register operand must be marked debug", MO, MONum);
2696 report(
"Register operand must not be marked debug", MO, MONum);
2703 checkLiveness(MO, MONum);
2707 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2711 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2713 if (!OtherMO.
isReg())
2714 report(
"Must be tied to a register", MO, MONum);
2716 report(
"Missing tie flags on tied operand", MO, MONum);
2717 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2718 report(
"Inconsistent tie links", MO, MONum);
2719 if (MONum <
MCID.getNumDefs()) {
2720 if (OtherIdx <
MCID.getNumOperands()) {
2722 report(
"Explicit def tied to explicit use without tie constraint",
2726 report(
"Explicit def should be tied to implicit use", MO, MONum);
2739 if (MF->getProperties().hasTiedOpsRewritten() && MO->
isUse() &&
2740 MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2741 Reg !=
MI->getOperand(DefIdx).getReg())
2742 report(
"Two-address instruction operands must be identical", MO, MONum);
2749 report(
"Illegal subregister index for physical register", MO, MONum);
2752 if (MONum <
MCID.getNumOperands()) {
2754 if (!DRC->contains(
Reg)) {
2755 report(
"Illegal physical register for instruction", MO, MONum);
2757 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2763 report(
"isRenamable set on reserved register", MO, MONum);
2780 report(
"Generic virtual register use cannot be undef", MO, MONum);
2787 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2790 if (isFunctionSelected) {
2791 report(
"Generic virtual register invalid in a Selected function",
2799 report(
"Generic virtual register must have a valid type", MO,
2808 if (!RegBank && isFunctionRegBankSelected) {
2809 report(
"Generic virtual register must have a bank in a "
2810 "RegBankSelected function",
2818 report(
"Register bank is too small for virtual register", MO,
2820 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2828 report(
"Generic virtual register does not allow subregister index", MO,
2837 MONum <
MCID.getNumOperands() &&
TII->getRegClass(
MCID, MONum)) {
2838 report(
"Virtual register does not match instruction constraint", MO,
2840 OS <<
"Expect register class "
2841 <<
TRI->getRegClassName(
TII->getRegClass(
MCID, MONum))
2842 <<
" but got nothing\n";
2849 if (!
TRI->isSubRegValidForRegClass(RC, SubIdx)) {
2850 report(
"Invalid subregister index for virtual register", MO, MONum);
2851 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2852 <<
" does not support subreg index "
2853 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2856 if (MONum >=
MCID.getNumOperands())
2865 if (SubIdx &&
TRI->getMatchingSuperRegClass(RC, DRC, SubIdx) != RC) {
2866 report(
"Illegal virtual register for instruction", MO, MONum);
2867 OS <<
TRI->getRegClassName(RC) <<
"." <<
TRI->getSubRegIndexName(SubIdx)
2868 <<
" cannot be used for " <<
TRI->getRegClassName(DRC)
2874 report(
"Illegal virtual register for instruction", MO, MONum);
2875 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2876 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2889 report(
"PHI operand is not in the CFG", MO, MONum);
2893 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2894 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2897 SlotIndex Idx = LiveInts->getInstructionIndex(*
MI);
2904 if (MayStore && MayLoad) {
2917 if (MayLoad == MayStore)
2918 report(
"Missing fixed stack memoperand.",
MI);
2921 report(
"Instruction loads from dead spill slot", MO, MONum);
2922 OS <<
"Live stack: " << LI <<
'\n';
2925 report(
"Instruction stores to dead spill slot", MO, MONum);
2926 OS <<
"Live stack: " << LI <<
'\n';
2932 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2933 report(
"CFI instruction has invalid index", MO, MONum);
2941void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2949 report(
"invalid live range", MO, MONum);
2950 report_context_liverange(LR);
2951 report_context_vreg_regunit(VRegOrUnit);
2952 report_context(UseIdx);
2961 report(
"No live segment at use", MO, MONum);
2962 report_context_liverange(LR);
2963 report_context_vreg_regunit(VRegOrUnit);
2964 report_context(UseIdx);
2967 report(
"Live range continues after kill flag", MO, MONum);
2968 report_context_liverange(LR);
2969 report_context_vreg_regunit(VRegOrUnit);
2971 report_context_lanemask(LaneMask);
2972 report_context(UseIdx);
2976void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2983 report(
"invalid live range", MO, MONum);
2984 report_context_liverange(LR);
2985 report_context_vreg_regunit(VRegOrUnit);
2987 report_context_lanemask(LaneMask);
2988 report_context(DefIdx);
3000 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
3002 (VNI->def != DefIdx &&
3003 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
3004 report(
"Inconsistent valno->def", MO, MONum);
3005 report_context_liverange(LR);
3006 report_context_vreg_regunit(VRegOrUnit);
3008 report_context_lanemask(LaneMask);
3009 report_context(*VNI);
3010 report_context(DefIdx);
3013 report(
"No live segment at def", MO, MONum);
3014 report_context_liverange(LR);
3015 report_context_vreg_regunit(VRegOrUnit);
3017 report_context_lanemask(LaneMask);
3018 report_context(DefIdx);
3030 if (SubRangeCheck || MO->
getSubReg() == 0) {
3031 report(
"Live range continues after dead def flag", MO, MONum);
3032 report_context_liverange(LR);
3033 report_context_vreg_regunit(VRegOrUnit);
3035 report_context_lanemask(LaneMask);
3041void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
3044 const unsigned SubRegIdx = MO->
getSubReg();
3048 if (LiveInts->hasInterval(
Reg)) {
3049 LI = &LiveInts->getInterval(
Reg);
3052 report(
"Live interval for subreg operand has no subranges", MO, MONum);
3054 report(
"Virtual register has no live interval", MO, MONum);
3061 addRegWithSubRegs(regsKilled,
Reg);
3067 !
MI->isBundledWithPred()) {
3070 report(
"Kill missing from LiveVariables", MO, MONum);
3074 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3078 UseIdx = LiveInts->getMBBEndIdx(
3079 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
3081 UseIdx = LiveInts->getInstructionIndex(*
MI);
3088 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3089 checkLivenessAtUse(MO, MONum, UseIdx, *LR,
VirtRegOrUnit(Unit));
3099 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3103 if ((MOMask & SR.LaneMask).none())
3109 LiveInMask |= SR.LaneMask;
3112 if ((LiveInMask & MOMask).
none()) {
3113 report(
"No live subrange at use", MO, MONum);
3114 report_context(*LI);
3115 report_context(UseIdx);
3118 if (
MI->isPHI() && LiveInMask != MOMask) {
3119 report(
"Not all lanes of PHI source live at use", MO, MONum);
3120 report_context(*LI);
3121 report_context(UseIdx);
3128 if (!regsLive.count(
Reg)) {
3131 bool Bad = !isReserved(
Reg);
3136 if (regsLive.count(SubReg)) {
3148 if (!MOP.isReg() || !MOP.isImplicit())
3151 if (!MOP.getReg().isPhysical())
3154 if (MOP.getReg() !=
Reg &&
3155 all_of(
TRI->regunits(
Reg), [&](
const MCRegUnit RegUnit) {
3156 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3163 report(
"Using an undefined physical register", MO, MONum);
3165 report(
"Reading virtual register without a def", MO, MONum);
3167 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3171 if (MInfo.regsKilled.count(
Reg))
3172 report(
"Using a killed virtual register", MO, MONum);
3173 else if (!
MI->isPHI())
3174 MInfo.vregsLiveIn.insert(std::make_pair(
Reg,
MI));
3183 addRegWithSubRegs(regsDead,
Reg);
3185 addRegWithSubRegs(regsDefined,
Reg);
3190 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3192 report(
"Subreg def in SSA form", MO, MONum);
3196 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3197 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3205 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3208 if ((SR.LaneMask & MOMask).none())
3223void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3224 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3225 set_union(MInfo.regsKilled, regsKilled);
3226 set_subtract(regsLive, regsKilled); regsKilled.clear();
3228 while (!regMasks.empty()) {
3229 const uint32_t *
Mask = regMasks.pop_back_val();
3233 regsDead.push_back(
Reg);
3236 set_union(regsLive, regsDefined); regsDefined.clear();
3241 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3246 if (!(stop > lastIndex)) {
3247 report(
"Block ends before last instruction index",
MBB);
3248 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3264 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3266 filterAndAdd(FromRegSet, VRegsBuffer);
3271 template <
typename RegSetT>
3272 bool filterAndAdd(
const RegSetT &FromRegSet,
3273 SmallVectorImpl<Register> &ToVRegs) {
3274 unsigned SparseUniverse = Sparse.size();
3275 unsigned NewSparseUniverse = SparseUniverse;
3276 unsigned NewDenseSize =
Dense.size();
3277 size_t Begin = ToVRegs.
size();
3282 if (Index < SparseUniverseMax) {
3283 if (Index < SparseUniverse && Sparse.test(Index))
3285 NewSparseUniverse = std::max(NewSparseUniverse, Index + 1);
3293 size_t End = ToVRegs.
size();
3300 Sparse.resize(NewSparseUniverse);
3301 Dense.reserve(NewDenseSize);
3302 for (
unsigned I = Begin;
I < End; ++
I) {
3305 if (Index < SparseUniverseMax)
3314 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3325 DenseSet<Register>
Dense;
3334class FilteringVRegSet {
3341 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3346 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3349 return Filter.filterAndAdd(RS, VRegs);
3351 using const_iterator =
decltype(VRegs)::const_iterator;
3352 const_iterator
begin()
const {
return VRegs.
begin(); }
3353 const_iterator
end()
const {
return VRegs.
end(); }
3354 size_t size()
const {
return VRegs.
size(); }
3361void MachineVerifier::calcRegsPassed() {
3368 FilteringVRegSet VRegs;
3369 BBInfo &
Info = MBBInfoMap[MB];
3372 VRegs.addToFilter(
Info.regsKilled);
3373 VRegs.addToFilter(
Info.regsLiveOut);
3375 const BBInfo &PredInfo = MBBInfoMap[Pred];
3376 if (!PredInfo.reachable)
3379 VRegs.add(PredInfo.regsLiveOut);
3380 VRegs.add(PredInfo.vregsPassed);
3382 Info.vregsPassed.reserve(VRegs.size());
3383 Info.vregsPassed.insert_range(VRegs);
3390void MachineVerifier::calcRegsRequired() {
3393 for (
const auto &
MBB : *MF) {
3394 BBInfo &MInfo = MBBInfoMap[&
MBB];
3396 BBInfo &PInfo = MBBInfoMap[Pred];
3397 if (PInfo.addRequired(MInfo.vregsLiveIn))
3403 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3405 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3412 BBInfo &PInfo = MBBInfoMap[Pred];
3413 if (PInfo.addRequired(
Reg))
3421 while (!todo.
empty()) {
3424 BBInfo &MInfo = MBBInfoMap[
MBB];
3428 BBInfo &SInfo = MBBInfoMap[Pred];
3429 if (SInfo.addRequired(MInfo.vregsRequired))
3438 BBInfo &MInfo = MBBInfoMap[&
MBB];
3448 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3453 report(
"Unexpected flag on PHI operand", &MODef, 0);
3456 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3458 for (
unsigned I = 1,
E =
Phi.getNumOperands();
I !=
E;
I += 2) {
3461 report(
"Expected PHI operand to be a register", &MO0,
I);
3466 report(
"Unexpected flag on PHI operand", &MO0,
I);
3470 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3476 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3480 if (MInfo.reachable) {
3482 BBInfo &PrInfo = MBBInfoMap[&Pre];
3483 if (!MO0.
isUndef() && PrInfo.reachable &&
3484 !PrInfo.isLiveOut(MO0.
getReg()))
3485 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3490 if (MInfo.reachable) {
3492 if (!seen.
count(Pred)) {
3493 report(
"Missing PHI operand", &Phi);
3495 <<
" is a predecessor according to the CFG.\n";
3504 std::function<
void(
const Twine &Message)> FailureCB,
3509 for (
const auto &
MBB : MF) {
3511 for (
const auto &
MI :
MBB.instrs())
3521void MachineVerifier::visitMachineFunctionAfter() {
3522 auto FailureCB = [
this](
const Twine &Message) {
3523 report(Message.str().c_str(), MF);
3536 for (
const auto &
MBB : *MF) {
3537 BBInfo &MInfo = MBBInfoMap[&
MBB];
3538 for (
Register VReg : MInfo.vregsRequired)
3539 if (MInfo.regsKilled.count(VReg)) {
3540 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3541 OS <<
"Virtual register " <<
printReg(VReg)
3542 <<
" is used after the block.\n";
3547 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3548 for (
Register VReg : MInfo.vregsRequired) {
3549 report(
"Virtual register defs don't dominate all uses.", MF);
3550 report_context_vreg(VReg);
3555 verifyLiveVariables();
3557 verifyLiveIntervals();
3567 for (
const auto &
MBB : *MF)
3571 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3574 BBInfo &PInfo = MBBInfoMap[Pred];
3575 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3576 report(
"Live in register not found to be live out from predecessor.",
3578 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3584 for (
auto CSInfo : MF->getCallSitesInfo())
3585 if (!CSInfo.first->isCall())
3586 report(
"Call site info referencing instruction that is not call", MF);
3590 if (MF->getFunction().getSubprogram()) {
3592 for (
const auto &
MBB : *MF) {
3593 for (
const auto &
MI :
MBB) {
3594 if (
auto Num =
MI.peekDebugInstrNum()) {
3597 report(
"Instruction has a duplicated value tracking number", &
MI);
3604void MachineVerifier::verifyLiveVariables() {
3605 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3609 for (
const auto &
MBB : *MF) {
3610 BBInfo &MInfo = MBBInfoMap[&
MBB];
3613 if (MInfo.vregsRequired.count(
Reg)) {
3615 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3617 <<
" must be live through the block.\n";
3621 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3623 <<
" is not needed live through the block.\n";
3630void MachineVerifier::verifyLiveIntervals() {
3631 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3639 if (!LiveInts->hasInterval(
Reg)) {
3640 report(
"Missing live interval for virtual register", MF);
3646 assert(
Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3647 verifyLiveInterval(LI);
3651 for (MCRegUnit Unit :
TRI->regunits())
3652 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3656void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3666 report(
"Value not live at VNInfo def and not marked unused", MF);
3667 report_context(LR, VRegOrUnit, LaneMask);
3668 report_context(*VNI);
3672 if (DefVNI != VNI) {
3673 report(
"Live segment at def has different VNInfo", MF);
3674 report_context(LR, VRegOrUnit, LaneMask);
3675 report_context(*VNI);
3681 report(
"Invalid VNInfo definition index", MF);
3682 report_context(LR, VRegOrUnit, LaneMask);
3683 report_context(*VNI);
3688 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3689 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3690 report_context(LR, VRegOrUnit, LaneMask);
3691 report_context(*VNI);
3699 report(
"No instruction at VNInfo def index",
MBB);
3700 report_context(LR, VRegOrUnit, LaneMask);
3701 report_context(*VNI);
3705 bool hasDef =
false;
3706 bool isEarlyClobber =
false;
3708 if (!MOI->isReg() || !MOI->isDef())
3714 if (!MOI->getReg().isPhysical() ||
3718 if (LaneMask.
any() &&
3719 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3722 if (MOI->isEarlyClobber())
3723 isEarlyClobber =
true;
3727 report(
"Defining instruction does not modify register",
MI);
3728 report_context(LR, VRegOrUnit, LaneMask);
3729 report_context(*VNI);
3734 if (isEarlyClobber) {
3736 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3737 report_context(LR, VRegOrUnit, LaneMask);
3738 report_context(*VNI);
3741 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3742 report_context(LR, VRegOrUnit, LaneMask);
3743 report_context(*VNI);
3747void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3753 assert(VNI &&
"Live segment has no valno");
3756 report(
"Foreign valno in live segment", MF);
3757 report_context(LR, VRegOrUnit, LaneMask);
3759 report_context(*VNI);
3763 report(
"Live segment valno is marked unused", MF);
3764 report_context(LR, VRegOrUnit, LaneMask);
3770 report(
"Bad start of live segment, no basic block", MF);
3771 report_context(LR, VRegOrUnit, LaneMask);
3777 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3778 report_context(LR, VRegOrUnit, LaneMask);
3785 report(
"Bad end of live segment, no basic block", MF);
3786 report_context(LR, VRegOrUnit, LaneMask);
3792 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3802 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3803 report_context(LR, VRegOrUnit, LaneMask);
3810 report(
"Live segment ends at B slot of an instruction", EndMBB);
3811 report_context(LR, VRegOrUnit, LaneMask);
3819 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3820 report_context(LR, VRegOrUnit, LaneMask);
3830 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3831 report(
"Live segment ending at early clobber slot must be "
3832 "redefined by an EC def in the same instruction",
3834 report_context(LR, VRegOrUnit, LaneMask);
3844 bool hasRead =
false;
3845 bool hasSubRegDef =
false;
3846 bool hasDeadDef =
false;
3848 if (!MOI->isReg() || MOI->getReg() != VRegOrUnit.
asVirtualReg())
3850 unsigned Sub = MOI->getSubReg();
3855 hasSubRegDef =
true;
3864 if (LaneMask.
any() && (LaneMask & SLM).none())
3866 if (MOI->readsReg())
3873 if (LaneMask.
none() && !hasDeadDef) {
3875 "Instruction ending live segment on dead slot has no dead flag",
3877 report_context(LR, VRegOrUnit, LaneMask);
3885 LaneMask.
any() || !hasSubRegDef) {
3886 report(
"Instruction ending live segment doesn't read the register",
3888 report_context(LR, VRegOrUnit, LaneMask);
3908 if (LaneMask.
any()) {
3914 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3917 if (&*MFI == EndMBB)
3925 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3929 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3931 if (MFI->isEHPad()) {
3934 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3945 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3948 report(
"Register not marked live out of predecessor", Pred);
3949 report_context(LR, VRegOrUnit, LaneMask);
3950 report_context(*VNI);
3952 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3958 if (!IsPHI && PVNI != VNI) {
3959 report(
"Different value live out of predecessor", Pred);
3960 report_context(LR, VRegOrUnit, LaneMask);
3961 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3964 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3967 if (&*MFI == EndMBB)
3973void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
3977 verifyLiveRangeValue(LR, VNI, VRegOrUnit, LaneMask);
3980 verifyLiveRangeSegment(LR,
I, VRegOrUnit, LaneMask);
3983void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3992 if ((Mask & SR.LaneMask).any()) {
3993 report(
"Lane masks of sub ranges overlap in live interval", MF);
3996 if ((SR.LaneMask & ~MaxMask).any()) {
3997 report(
"Subrange lanemask is invalid", MF);
4001 report(
"Subrange must not be empty", MF);
4004 Mask |= SR.LaneMask;
4007 report(
"A Subrange is not covered by the main range", MF);
4015 unsigned NumComp = ConEQ.Classify(LI);
4017 report(
"Multiple connected components in live interval", MF);
4019 for (
unsigned comp = 0; comp != NumComp; ++comp) {
4020 OS << comp <<
": valnos";
4022 if (comp == ConEQ.getEqClass(
I))
4035struct StackStateOfBB {
4036 StackStateOfBB() =
default;
4037 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
4038 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
4039 ExitIsSetup(ExitSetup) {}
4044 bool EntryIsSetup =
false;
4045 bool ExitIsSetup =
false;
4053void MachineVerifier::verifyStackFrame() {
4054 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
4055 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
4056 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
4060 SPState.
resize(MF->getNumBlockIDs());
4067 DFI != DFE; ++DFI) {
4070 StackStateOfBB BBState;
4072 if (DFI.getPathLength() >= 2) {
4075 "DFS stack predecessor is already visited.\n");
4076 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
4077 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
4078 BBState.ExitValue = BBState.EntryValue;
4079 BBState.ExitIsSetup = BBState.EntryIsSetup;
4083 report(
"Call frame size on entry does not match value computed from "
4087 <<
" does not match value computed from predecessor "
4088 << -BBState.EntryValue <<
'\n';
4092 for (
const auto &
I : *
MBB) {
4093 if (
I.getOpcode() == FrameSetupOpcode) {
4094 if (BBState.ExitIsSetup)
4095 report(
"FrameSetup is after another FrameSetup", &
I);
4096 if (!MRI->
isSSA() && !MF->getFrameInfo().adjustsStack())
4097 report(
"AdjustsStack not set in presence of a frame pseudo "
4098 "instruction.", &
I);
4099 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
4100 BBState.ExitIsSetup =
true;
4103 if (
I.getOpcode() == FrameDestroyOpcode) {
4104 int Size =
TII->getFrameTotalSize(
I);
4105 if (!BBState.ExitIsSetup)
4106 report(
"FrameDestroy is not after a FrameSetup", &
I);
4107 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
4109 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
4110 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
4111 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
4112 << AbsSPAdj <<
">.\n";
4114 if (!MRI->
isSSA() && !MF->getFrameInfo().adjustsStack())
4115 report(
"AdjustsStack not set in presence of a frame pseudo "
4116 "instruction.", &
I);
4117 BBState.ExitValue +=
Size;
4118 BBState.ExitIsSetup =
false;
4126 if (Reachable.
count(Pred) &&
4127 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4128 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4129 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4131 << SPState[Pred->
getNumber()].ExitValue <<
", "
4132 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4134 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4141 if (Reachable.
count(Succ) &&
4142 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4143 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4144 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4146 << SPState[Succ->getNumber()].EntryValue <<
", "
4147 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4149 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4155 if (BBState.ExitIsSetup)
4156 report(
"A return block ends with a FrameSetup.",
MBB);
4157 if (BBState.ExitValue)
4158 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
4163void MachineVerifier::verifyStackProtector() {
4172 bool StackGrowsDown =
4199 if (SPStart < ObjEnd && ObjStart < SPEnd) {
4200 report(
"Stack protector overlaps with another stack object", MF);
4203 if ((StackGrowsDown && SPStart <= ObjStart) ||
4204 (!StackGrowsDown && SPStart >= ObjStart)) {
4205 report(
"Stack protector is not the top-most object on the stack", MF);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isLoad(int Opcode)
static bool isStore(int Opcode)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file implements the BitVector class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
const HexagonInstrInfo * TII
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
A common definition of LaneBitmask for use in TableGen and CodeGen.
Implement a low-level type suitable for MachineInstr level instruction selection.
print mir2vec MIR2Vec Vocabulary Printer Pass
This file declares the MIR specialization of the GenericConvergenceVerifier template.
Register const TargetRegisterInfo * TRI
static void verifyConvergenceControl(const MachineFunction &MF, MachineDominatorTree &DT, std::function< void(const Twine &Message)> FailureCB, raw_ostream &OS)
static bool hasPHIs(const MachineFunction &MF)
Promote Memory to Register
modulo schedule Modulo Schedule test pass
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
SI Optimize VGPR LiveRange
SmallPtrSet< BasicBlock *, 0 > BlockSet
This file defines generic set operations that may be used on set's of different types,...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
static unsigned getSize(unsigned Kind)
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
const fltSemantics & getSemantics() const
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
This class holds the attributes for a particular argument, parameter, function, or return value.
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
void clear()
Removes all bits from the bitvector.
iterator_range< const_set_bits_iterator > set_bits() const
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
This is the shared class of boolean and integer constants.
IntegerType * getIntegerType() const
Variant of the getType() method to always return an IntegerType, which reduces the amount of casting ...
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
A parsed version of the target data layout string in and methods for querying it.
Implements a dense probed hash-table based set.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Base class for user error types.
FunctionPass class - This class is used to implement most global optimizations.
const Function & getFunction() const
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
void verify(const DominatorTreeT &DT)
void visit(const BlockT &BB)
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr unsigned getScalarSizeInBits() const
constexpr bool isFloatOrFloatVector() const
constexpr bool isScalar() const
constexpr Kind getKind() const
LLT getScalarType() const
constexpr bool isPointerVector() const
constexpr FpSemantics getFpSemantics() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
constexpr bool isPointerOrPointerVector() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
LLVM_ABI void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
void print(raw_ostream &O, const Module *=nullptr) const override
Implement the dump method.
Result of a LiveRange query.
bool isDeadDef() const
Return true if this instruction has a dead def.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
VNInfo * valueOut() const
Return the value leaving the instruction, if any.
bool isKill() const
Return true if the live-in value is killed by this instruction.
static LLVM_ABI bool isJointlyDominated(const MachineBasicBlock *MBB, ArrayRef< SlotIndex > Defs, const SlotIndexes &Indexes)
A diagnostic function to check if the end of the block MBB is jointly dominated by the blocks corresp...
This class represents the liveness of a register, stack slot, etc.
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
Segments::const_iterator const_iterator
bool liveAt(SlotIndex index) const
LLVM_ABI bool covers(const LiveRange &Other) const
Returns true if all segments of the Other live range are completely covered by this live range.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
bool verify() const
Walk the range and assert if any invariants fail to hold.
unsigned getNumValNums() const
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
LLVM_ABI VarInfo & getVarInfo(Register Reg)
getVarInfo - Return the VarInfo structure for the specified VIRTUAL register.
TypeSize getValue() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
ExceptionHandling getExceptionHandlingType() const
Describe properties that are true of each instruction in the target description file.
This holds information about one operand of a machine instruction, indicating the register class for ...
MCRegAliasIterator enumerates all registers aliasing Reg.
bool hasSuperClassEq(const MCRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
Wrapper class representing physical registers. Should be passed by value.
const MDOperand & getOperand(unsigned I) const
bool isValid() const
isValid - Returns true until all the operands have been visited.
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
unsigned pred_size() const
bool isEHPad() const
Returns true if the block is a landing pad.
iterator_range< livein_iterator > liveins() const
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
bool isIRBlockAddressTaken() const
Test whether this block is the target of an IR BlockAddress.
unsigned succ_size() const
BasicBlock * getAddressTakenIRBlock() const
Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
unsigned getCallFrameSize() const
Return the call frame size on entry to this basic block.
iterator_range< succ_iterator > successors()
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int getStackProtectorIndex() const
Return the index for the stack protector object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
LLVM_ABI BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isReturn(QueryType Type=AnyInBundle) const
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
const PseudoSourceValue * getPseudoValue() const
LLT getMemoryType() const
Return the memory type of the memory reference.
const MDNode * getRanges() const
Return the range tag for the memory reference.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
LocationSize getSizeInBits() const
Return the size in bits of the memory reference.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isIntrinsicID() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
ArrayRef< int > getShuffleMask() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isValidExcessOperand() const
Return true if this operand can validly be appended to an arbitrary operand list.
bool isShuffleMask() const
LLVM_ABI void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr) const
Print the MachineOperand to os.
LaneBitmask getLaneMask() const
unsigned getCFIIndex() const
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool isEarlyClobber() const
Register getReg() const
getReg - Returns the register number.
bool isInternalRead() const
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
use_nodbg_iterator use_nodbg_begin(Register RegNo) const
LLVM_ABI void verifyUseLists() const
Verify the use list of all registers.
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
static use_nodbg_iterator use_nodbg_end()
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
bool reservedRegsFrozen() const
reservedRegsFrozen - Returns true after freezeReservedRegs() was called to ensure the set of reserved...
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
bool reg_nodbg_empty(Register RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions.
const RegisterBank * getRegBankOrNull(Register Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
bool shouldTrackSubRegLiveness(const TargetRegisterClass &RC) const
Returns true if liveness for register class RC should be tracked at the subregister level.
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
LLVM_ABI bool isReservedRegUnit(MCRegUnit Unit) const
Returns true when the given register unit is considered reserved.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
LLVM_ABI LaneBitmask getMaxLaneMaskForVReg(Register Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Pass interface - Implemented by all 'passes'.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Holds all the information related to register banks.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
This class implements the register bank concept.
const char * getName() const
Get a user friendly name of this register bank.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr unsigned id() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SlotIndex - An opaque wrapper around machine indexes.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level Statepoint operands.
Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static constexpr TypeSize getZero()
VNInfo - Value Number Information.
bool isUnused() const
Returns true if this value is unused.
unsigned id
The ID number of this value.
SlotIndex def
The index of the defining instruction.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
LLVM Value Representation.
Wrapper class representing a virtual register or register unit.
constexpr bool isVirtualReg() const
constexpr MCRegUnit asMCRegUnit() const
constexpr Register asVirtualReg() const
std::pair< iterator, bool > insert(const ValueT &V)
constexpr bool isNonZero() const
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class implements an extremely fast bulk output stream that can only output to a stream.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
NodeAddr< DefNode * > Def
NodeAddr< PhiNode * > Phi
NodeAddr< FuncNode * > Func
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
@ SjLj
setjmp/longjmp based exceptions
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void set_subtract(S1Ty &S1, const S2Ty &S2)
set_subtract(A, B) - Compute A := A - B
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
bool isPreISelGenericOptimizationHint(unsigned Opcode)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
LLVM_ABI FunctionPass * createMachineVerifierPass(const std::string &Banner)
createMachineVerifierPass - This pass verifies cenerated machine code instructions for correctness.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void verifyMachineFunction(const std::string &Banner, const MachineFunction &MF)
auto reverse(ContainerTy &&C)
detail::ValueMatchesPoly< M > HasValue(M Matcher)
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
GenericConvergenceVerifier< MachineSSAContext > MachineConvergenceVerifier
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
Implement std::hash so that hash_code can be used in STL containers.
static constexpr LaneBitmask getAll()
constexpr bool none() const
constexpr bool any() const
static constexpr LaneBitmask getNone()
This represents a simple continuous liveness interval for a value.
VarInfo - This represents the regions where a virtual register is live in the program.
Pair of physical register and lane mask.