102struct MachineVerifier {
104 raw_ostream *OS,
bool AbortOnError =
true)
105 : MFAM(&MFAM), OS(OS ? *OS :
nulls()), Banner(
b),
106 ReportedErrs(AbortOnError) {}
108 MachineVerifier(
Pass *
pass,
const char *b, raw_ostream *OS,
109 bool AbortOnError =
true)
110 : PASS(
pass), OS(OS ? *OS :
nulls()), Banner(
b),
111 ReportedErrs(AbortOnError) {}
113 MachineVerifier(
const char *b, LiveVariables *LiveVars,
114 LiveIntervals *LiveInts, LiveStacks *LiveStks,
115 SlotIndexes *Indexes, raw_ostream *OS,
116 bool AbortOnError =
true)
117 : OS(OS ? *OS :
nulls()), Banner(
b), LiveVars(LiveVars),
118 LiveInts(LiveInts), LiveStks(LiveStks), Indexes(Indexes),
119 ReportedErrs(AbortOnError) {}
122 bool verify(
const MachineFunction &MF);
125 Pass *
const PASS =
nullptr;
128 const MachineFunction *MF =
nullptr;
129 const TargetMachine *TM =
nullptr;
130 const TargetInstrInfo *TII =
nullptr;
131 const TargetRegisterInfo *TRI =
nullptr;
132 const MachineRegisterInfo *MRI =
nullptr;
133 const RegisterBankInfo *RBI =
nullptr;
136 bool isFunctionRegBankSelected =
false;
137 bool isFunctionSelected =
false;
138 bool isFunctionTracksDebugUserValues =
false;
140 using RegVector = SmallVector<Register, 16>;
141 using RegMaskVector = SmallVector<const uint32_t *, 4>;
142 using RegSet = DenseSet<Register>;
143 using RegMap = DenseMap<Register, const MachineInstr *>;
144 using BlockSet = SmallPtrSet<const MachineBasicBlock *, 8>;
146 const MachineInstr *FirstNonPHI =
nullptr;
147 const MachineInstr *FirstTerminator =
nullptr;
148 BlockSet FunctionBlocks;
150 BitVector regsReserved;
152 RegVector regsDefined, regsDead, regsKilled;
153 RegMaskVector regMasks;
158 void addRegWithSubRegs(RegVector &RV,
Register Reg) {
166 bool reachable =
false;
187 RegSet vregsRequired;
199 if (regsLiveOut.count(
Reg))
201 return vregsRequired.insert(
Reg).second;
205 bool addRequired(
const RegSet &RS) {
213 bool addRequired(
const RegMap &RM) {
215 for (
const auto &
I : RM)
222 return regsLiveOut.count(
Reg) || vregsPassed.count(
Reg);
227 DenseMap<const MachineBasicBlock *, BBInfo> MBBInfoMap;
230 return Reg.
id() < regsReserved.size() && regsReserved.test(
Reg.
id());
234 return Reg.
id() < TRI->getNumRegs() && TRI->isInAllocatableClass(
Reg) &&
235 !regsReserved.test(
Reg.
id());
239 LiveVariables *LiveVars =
nullptr;
240 LiveIntervals *LiveInts =
nullptr;
241 LiveStacks *LiveStks =
nullptr;
242 SlotIndexes *Indexes =
nullptr;
246 class ReportedErrors {
247 unsigned NumReported = 0;
252 ReportedErrors(
bool AbortOnError) : AbortOnError(AbortOnError) {}
259 " machine code errors.");
262 ReportedErrorsLock->unlock();
272 ReportedErrorsLock->lock();
274 return NumReported == 1;
278 bool hasError() {
return NumReported; }
280 ReportedErrors ReportedErrs;
285 MachineDominatorTree DT;
287 void visitMachineFunctionBefore();
288 void visitMachineBasicBlockBefore(
const MachineBasicBlock *
MBB);
289 void visitMachineBundleBefore(
const MachineInstr *
MI);
294 bool verifyAllRegOpsScalar(
const MachineInstr &
MI,
295 const MachineRegisterInfo &MRI);
296 bool verifyVectorElementMatch(LLT Ty0, LLT Ty1,
const MachineInstr *
MI);
298 bool verifyGIntrinsicSideEffects(
const MachineInstr *
MI);
299 bool verifyGIntrinsicConvergence(
const MachineInstr *
MI);
300 void verifyPreISelGenericInstruction(
const MachineInstr *
MI);
302 void visitMachineInstrBefore(
const MachineInstr *
MI);
303 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
304 void visitMachineBundleAfter(
const MachineInstr *
MI);
305 void visitMachineBasicBlockAfter(
const MachineBasicBlock *
MBB);
306 void visitMachineFunctionAfter();
308 void report(
const char *msg,
const MachineFunction *MF);
309 void report(
const char *msg,
const MachineBasicBlock *
MBB);
310 void report(
const char *msg,
const MachineInstr *
MI);
311 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
312 LLT MOVRegType = LLT{});
313 void report(
const Twine &Msg,
const MachineInstr *
MI);
315 void report_context(
const LiveInterval &LI)
const;
316 void report_context(
const LiveRange &LR, VirtRegOrUnit VRegOrUnit,
317 LaneBitmask LaneMask)
const;
318 void report_context(
const LiveRange::Segment &S)
const;
319 void report_context(
const VNInfo &VNI)
const;
320 void report_context(SlotIndex Pos)
const;
321 void report_context(
MCPhysReg PhysReg)
const;
322 void report_context_liverange(
const LiveRange &LR)
const;
323 void report_context_lanemask(LaneBitmask LaneMask)
const;
324 void report_context_vreg(
Register VReg)
const;
325 void report_context_vreg_regunit(VirtRegOrUnit VRegOrUnit)
const;
327 void verifyInlineAsm(
const MachineInstr *
MI);
329 void checkLiveness(
const MachineOperand *MO,
unsigned MONum);
330 void checkLivenessAtUse(
const MachineOperand *MO,
unsigned MONum,
332 VirtRegOrUnit VRegOrUnit,
334 void checkLivenessAtDef(
const MachineOperand *MO,
unsigned MONum,
336 VirtRegOrUnit VRegOrUnit,
bool SubRangeCheck =
false,
339 void markReachable(
const MachineBasicBlock *
MBB);
340 void calcRegsPassed();
341 void checkPHIOps(
const MachineBasicBlock &
MBB);
343 void calcRegsRequired();
344 void verifyLiveVariables();
345 void verifyLiveIntervals();
346 void verifyLiveInterval(
const LiveInterval &);
347 void verifyLiveRangeValue(
const LiveRange &,
const VNInfo *, VirtRegOrUnit,
349 void verifyLiveRangeSegment(
const LiveRange &,
350 const LiveRange::const_iterator
I, VirtRegOrUnit,
352 void verifyLiveRange(
const LiveRange &, VirtRegOrUnit,
355 void verifyStackFrame();
357 void verifyStackProtector();
359 void verifySlotIndexes()
const;
360 void verifyProperties(
const MachineFunction &MF);
366 const std::string Banner;
368 MachineVerifierLegacyPass(std::string banner = std::string())
369 : MachineFunctionPass(ID), Banner(std::
move(banner)) {}
371 void getAnalysisUsage(AnalysisUsage &AU)
const override {
380 bool runOnMachineFunction(MachineFunction &MF)
override {
387 MachineVerifier(
this, Banner.c_str(), &
errs()).verify(MF);
402 MachineVerifier(MFAM, Banner.c_str(), &
errs()).verify(MF);
406char MachineVerifierLegacyPass::ID = 0;
409 "Verify generated machine code",
false,
false)
412 return new MachineVerifierLegacyPass(Banner);
422 MachineVerifier(
nullptr, Banner.c_str(), &
errs()).verify(MF);
426 bool AbortOnError)
const {
427 return MachineVerifier(p, Banner, OS, AbortOnError).verify(*
this);
432 bool AbortOnError)
const {
433 return MachineVerifier(MFAM, Banner, OS, AbortOnError).verify(*
this);
438 bool AbortOnError)
const {
439 return MachineVerifier(Banner,
nullptr, LiveInts,
440 nullptr, Indexes, OS, AbortOnError)
444void MachineVerifier::verifySlotIndexes()
const {
445 if (Indexes ==
nullptr)
462 report(
"Function has NoVRegs property but there are VReg operands", &MF);
474 const bool isFunctionFailedISel = Props.hasFailedISel();
479 if (isFunctionFailedISel)
482 isFunctionRegBankSelected = Props.hasRegBankSelected();
483 isFunctionSelected = Props.hasSelected();
484 isFunctionTracksDebugUserValues = Props.hasTracksDebugUserValues();
488 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
492 LiveVars = LVWrapper ? &LVWrapper->getLV() :
nullptr;
494 LiveStks = LSWrapper ? &LSWrapper->getLS() :
nullptr;
496 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
509 verifyProperties(MF);
511 visitMachineFunctionBefore();
513 visitMachineBasicBlockBefore(&
MBB);
517 bool InBundle =
false;
520 if (
MI.getParent() != &
MBB) {
521 report(
"Bad instruction parent pointer", &
MBB);
522 OS <<
"Instruction: " <<
MI;
527 if (InBundle && !
MI.isBundledWithPred())
528 report(
"Missing BundledPred flag, "
529 "BundledSucc was set on predecessor",
531 if (!InBundle &&
MI.isBundledWithPred())
532 report(
"BundledPred flag is set, "
533 "but BundledSucc not set on predecessor",
537 if (!
MI.isInsideBundle()) {
539 visitMachineBundleAfter(CurBundle);
541 visitMachineBundleBefore(CurBundle);
542 }
else if (!CurBundle)
543 report(
"No bundle header", &
MI);
544 visitMachineInstrBefore(&
MI);
545 for (
unsigned I = 0,
E =
MI.getNumOperands();
I !=
E; ++
I) {
547 if (
Op.getParent() != &
MI) {
550 report(
"Instruction has operand with wrong parent set", &
MI);
553 visitMachineOperand(&
Op,
I);
557 InBundle =
MI.isBundledWithSucc();
560 visitMachineBundleAfter(CurBundle);
562 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
563 visitMachineBasicBlockAfter(&
MBB);
565 visitMachineFunctionAfter();
575 return !ReportedErrs.hasError();
578void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
581 if (ReportedErrs.increment()) {
583 OS <<
"# " << Banner <<
'\n';
585 if (LiveInts !=
nullptr)
588 MF->
print(OS, Indexes);
591 OS <<
"*** Bad machine code: " << msg <<
" ***\n"
592 <<
"- function: " << MF->
getName() <<
'\n';
599 <<
" (" << (
const void *)
MBB <<
')';
601 OS <<
" [" << Indexes->getMBBStartIdx(
MBB) <<
';'
602 << Indexes->getMBBEndIdx(
MBB) <<
')';
606void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
608 report(msg,
MI->getParent());
609 OS <<
"- instruction: ";
610 if (Indexes && Indexes->hasIndex(*
MI))
611 OS << Indexes->getInstructionIndex(*
MI) <<
'\t';
615void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
616 unsigned MONum,
LLT MOVRegType) {
619 OS <<
"- operand " << MONum <<
": ";
625 report(Msg.
str().c_str(),
MI);
628void MachineVerifier::report_context(
SlotIndex Pos)
const {
629 OS <<
"- at: " << Pos <<
'\n';
632void MachineVerifier::report_context(
const LiveInterval &LI)
const {
633 OS <<
"- interval: " << LI <<
'\n';
636void MachineVerifier::report_context(
const LiveRange &LR,
639 report_context_liverange(LR);
640 report_context_vreg_regunit(VRegOrUnit);
642 report_context_lanemask(LaneMask);
646 OS <<
"- segment: " << S <<
'\n';
649void MachineVerifier::report_context(
const VNInfo &VNI)
const {
650 OS <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
653void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
654 OS <<
"- liverange: " << LR <<
'\n';
657void MachineVerifier::report_context(
MCPhysReg PReg)
const {
658 OS <<
"- p. register: " <<
printReg(PReg,
TRI) <<
'\n';
661void MachineVerifier::report_context_vreg(
Register VReg)
const {
662 OS <<
"- v. register: " <<
printReg(VReg,
TRI) <<
'\n';
665void MachineVerifier::report_context_vreg_regunit(
675void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
680 BBInfo &MInfo = MBBInfoMap[
MBB];
681 if (!MInfo.reachable) {
682 MInfo.reachable =
true;
688void MachineVerifier::visitMachineFunctionBefore() {
691 :
TRI->getReservedRegs(*MF);
694 markReachable(&MF->
front());
697 FunctionBlocks.clear();
698 for (
const auto &
MBB : *MF) {
699 FunctionBlocks.insert(&
MBB);
700 BBInfo &MInfo = MBBInfoMap[&
MBB];
704 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
708 report(
"MBB has duplicate entries in its successor list.", &
MBB);
716 verifyStackProtector();
722 FirstTerminator =
nullptr;
723 FirstNonPHI =
nullptr;
729 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
732 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
733 "inlineasm-br-indirect-target.",
735 report_context(LI.PhysReg);
742 report(
"ir-block-address-taken is associated with basic block not used by "
751 LandingPadSuccs.
insert(succ);
752 if (!FunctionBlocks.count(succ))
753 report(
"MBB has successor that isn't part of the function.",
MBB);
754 if (!MBBInfoMap[succ].Preds.count(
MBB)) {
755 report(
"Inconsistent CFG",
MBB);
756 OS <<
"MBB is not in the predecessor list of the successor "
763 if (!FunctionBlocks.count(Pred))
764 report(
"MBB has predecessor that isn't part of the function.",
MBB);
765 if (!MBBInfoMap[Pred].Succs.count(
MBB)) {
766 report(
"Inconsistent CFG",
MBB);
767 OS <<
"MBB is not in the successor list of the predecessor "
775 if (LandingPadSuccs.
size() > 1 &&
779 report(
"MBB has more than one landing pad successor",
MBB);
792 report(
"MBB exits via unconditional fall-through but ends with a "
793 "barrier instruction!",
MBB);
796 report(
"MBB exits via unconditional fall-through but has a condition!",
802 report(
"MBB exits via unconditional branch but doesn't contain "
803 "any instructions!",
MBB);
805 report(
"MBB exits via unconditional branch but doesn't end with a "
806 "barrier instruction!",
MBB);
808 report(
"MBB exits via unconditional branch but the branch isn't a "
809 "terminator instruction!",
MBB);
814 report(
"MBB exits via conditional branch/fall-through but doesn't "
815 "contain any instructions!",
MBB);
817 report(
"MBB exits via conditional branch/fall-through but ends with a "
818 "barrier instruction!",
MBB);
820 report(
"MBB exits via conditional branch/fall-through but the branch "
821 "isn't a terminator instruction!",
MBB);
823 }
else if (
TBB && FBB) {
827 report(
"MBB exits via conditional branch/branch but doesn't "
828 "contain any instructions!",
MBB);
830 report(
"MBB exits via conditional branch/branch but doesn't end with a "
831 "barrier instruction!",
MBB);
833 report(
"MBB exits via conditional branch/branch but the branch "
834 "isn't a terminator instruction!",
MBB);
837 report(
"MBB exits via conditional branch/branch but there's no "
841 report(
"analyzeBranch returned invalid data!",
MBB);
847 report(
"MBB exits via jump or conditional branch, but its target isn't a "
851 report(
"MBB exits via conditional branch, but its target isn't a CFG "
858 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
863 if (!
Cond.empty() && !FBB) {
866 report(
"MBB conditionally falls through out of function!",
MBB);
868 report(
"MBB exits via conditional branch/fall-through but the CFG "
869 "successors don't match the actual successors!",
876 if (SuccMBB ==
TBB || SuccMBB == FBB)
884 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
886 report(
"MBB has unexpected successors which are not branch targets, "
887 "fallthrough, EHPads, or inlineasm_br targets.",
895 if (!LI.PhysReg.isPhysical()) {
896 report(
"MBB live-in list contains non-physical register",
MBB);
899 regsLive.insert_range(
TRI->subregs_inclusive(LI.PhysReg));
906 regsLive.insert_range(
TRI->subregs_inclusive(
I));
912 lastIndex = Indexes->getMBBStartIdx(
MBB);
917void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
918 if (Indexes && Indexes->hasIndex(*
MI)) {
920 if (!(idx > lastIndex)) {
921 report(
"Instruction index out of order",
MI);
922 OS <<
"Last instruction was at " << lastIndex <<
'\n';
928 if (
MI->isTerminator()) {
929 if (!FirstTerminator)
930 FirstTerminator =
MI;
931 }
else if (FirstTerminator) {
934 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
935 report(
"Non-terminator instruction after the first terminator",
MI);
936 OS <<
"First terminator was:\t" << *FirstTerminator;
945 if (
MI->getNumOperands() < 2) {
946 report(
"Too few operands on inline asm",
MI);
949 if (!
MI->getOperand(0).isSymbol())
950 report(
"Asm string must be an external symbol",
MI);
951 if (!
MI->getOperand(1).isImm())
952 report(
"Asm flags must be an immediate",
MI);
957 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
963 for (
unsigned e =
MI->getNumOperands(); OpNo < e; OpNo +=
NumOps) {
969 NumOps = 1 +
F.getNumOperandRegisters();
972 if (OpNo >
MI->getNumOperands())
973 report(
"Missing operands in last group",
MI);
976 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
980 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
983 report(
"Expected implicit register after groups", &MO, OpNo);
986 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
999 if (!IndirectTargetMBB) {
1000 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1005 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1009 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1015bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1020 const auto Reg = Op.getReg();
1021 if (Reg.isPhysical())
1023 return !MRI.getType(Reg).isScalar();
1026 report(
"All register operands must have scalar types", &
MI);
1033bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1036 report(
"operand types must be all-vector or all-scalar",
MI);
1046 report(
"operand types must preserve number of vector elements",
MI);
1053bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1054 auto Opcode =
MI->getOpcode();
1055 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1056 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1058 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1060 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1061 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1062 if (NoSideEffects && DeclHasSideEffects) {
1064 " used with intrinsic that accesses memory"),
1068 if (!NoSideEffects && !DeclHasSideEffects) {
1069 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1077bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1078 auto Opcode =
MI->getOpcode();
1079 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1080 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1082 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1084 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1085 bool DeclIsConvergent =
Attrs.hasAttribute(Attribute::Convergent);
1086 if (NotConvergent && DeclIsConvergent) {
1087 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1091 if (!NotConvergent && !DeclIsConvergent) {
1093 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1102void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1103 if (isFunctionSelected)
1104 report(
"Unexpected generic instruction in a Selected function",
MI);
1107 unsigned NumOps =
MI->getNumOperands();
1110 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1111 bool HasMBB =
false;
1120 report(
"Branch instruction is missing a basic block operand or "
1121 "isIndirectBranch property",
1128 for (
unsigned I = 0,
E = std::min(
MCID.getNumOperands(),
NumOps);
1130 if (!
MCID.operands()[
I].isGenericType())
1134 size_t TypeIdx =
MCID.operands()[
I].getGenericTypeIndex();
1135 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1139 report(
"generic instruction must use register operands",
MI);
1149 if (!Types[TypeIdx].
isValid())
1150 Types[TypeIdx] = OpTy;
1151 else if (Types[TypeIdx] != OpTy)
1152 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1155 report(
"Generic instruction is missing a virtual register type", MO,
I);
1160 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1163 report(
"Generic instruction cannot have physical register", MO,
I);
1167 if (
MI->getNumOperands() <
MCID.getNumOperands())
1175 unsigned Opc =
MI->getOpcode();
1177 case TargetOpcode::G_ASSERT_SEXT:
1178 case TargetOpcode::G_ASSERT_ZEXT: {
1179 std::string OpcName =
1180 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1181 if (!
MI->getOperand(2).isImm()) {
1182 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1189 int64_t
Imm =
MI->getOperand(2).getImm();
1191 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1196 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1204 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1205 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1213 Twine(OpcName,
" source and destination register classes must match"),
1221 case TargetOpcode::G_CONSTANT:
1222 case TargetOpcode::G_FCONSTANT: {
1225 report(
"Instruction cannot use a vector result type",
MI);
1227 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1228 if (!
MI->getOperand(1).isCImm()) {
1229 report(
"G_CONSTANT operand must be cimm",
MI);
1235 report(
"inconsistent constant size",
MI);
1237 if (!
MI->getOperand(1).isFPImm()) {
1238 report(
"G_FCONSTANT operand must be fpimm",
MI);
1245 report(
"inconsistent constant size",
MI);
1251 case TargetOpcode::G_LOAD:
1252 case TargetOpcode::G_STORE:
1253 case TargetOpcode::G_ZEXTLOAD:
1254 case TargetOpcode::G_SEXTLOAD: {
1258 report(
"Generic memory instruction must access a pointer",
MI);
1262 if (!
MI->hasOneMemOperand()) {
1263 report(
"Generic instruction accessing memory must have one mem operand",
1267 if (
MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
1268 MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
1271 report(
"Generic extload must have a narrower memory type",
MI);
1272 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1275 report(
"load memory size cannot exceed result size",
MI);
1286 report(
"range is incompatible with the result type",
MI);
1289 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1292 report(
"store memory size cannot exceed value size",
MI);
1296 if (
Opc == TargetOpcode::G_STORE) {
1299 report(
"atomic store cannot use acquire ordering",
MI);
1304 report(
"atomic load cannot use release ordering",
MI);
1310 case TargetOpcode::G_PHI: {
1316 LLT Ty = MRI->getType(MO.getReg());
1317 if (!Ty.isValid() || (Ty != DstTy))
1321 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1326 case TargetOpcode::G_BITCAST: {
1333 report(
"bitcast cannot convert between pointers and other types",
MI);
1336 report(
"bitcast sizes must match",
MI);
1348 report(
"bitcast must change the type",
MI);
1352 case TargetOpcode::G_INTTOPTR:
1353 case TargetOpcode::G_PTRTOINT:
1354 case TargetOpcode::G_ADDRSPACE_CAST: {
1360 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1365 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1367 report(
"inttoptr result type must be a pointer",
MI);
1369 report(
"inttoptr source type must not be a pointer",
MI);
1370 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1372 report(
"ptrtoint source type must be a pointer",
MI);
1374 report(
"ptrtoint result type must not be a pointer",
MI);
1376 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1378 report(
"addrspacecast types must be pointers",
MI);
1381 report(
"addrspacecast must convert different address spaces",
MI);
1387 case TargetOpcode::G_PTR_ADD: {
1390 LLT OffsetTy = MRI->
getType(
MI->getOperand(2).getReg());
1395 report(
"gep first operand must be a pointer",
MI);
1398 report(
"gep offset operand must not be a pointer",
MI);
1403 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1405 report(
"gep offset operand must match index size for address space",
1413 case TargetOpcode::G_PTRMASK: {
1421 report(
"ptrmask result type must be a pointer",
MI);
1424 report(
"ptrmask mask type must be an integer",
MI);
1426 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1429 case TargetOpcode::G_SEXT:
1430 case TargetOpcode::G_ZEXT:
1431 case TargetOpcode::G_ANYEXT:
1432 case TargetOpcode::G_TRUNC:
1433 case TargetOpcode::G_TRUNC_SSAT_S:
1434 case TargetOpcode::G_TRUNC_SSAT_U:
1435 case TargetOpcode::G_TRUNC_USAT_U:
1436 case TargetOpcode::G_FPEXT:
1437 case TargetOpcode::G_FPTRUNC: {
1443 assert(
MCID.getNumOperands() == 2 &&
"Expected 2 operands G_*{EXT,TRUNC}");
1450 report(
"Generic extend/truncate can not operate on pointers",
MI);
1452 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1456 switch (
MI->getOpcode()) {
1458 if (DstSize <= SrcSize)
1459 report(
"Generic extend has destination type no larger than source",
MI);
1461 case TargetOpcode::G_TRUNC:
1462 case TargetOpcode::G_TRUNC_SSAT_S:
1463 case TargetOpcode::G_TRUNC_SSAT_U:
1464 case TargetOpcode::G_TRUNC_USAT_U:
1465 case TargetOpcode::G_FPTRUNC:
1466 if (DstSize >= SrcSize)
1467 report(
"Generic truncate has destination type no smaller than source",
1473 case TargetOpcode::G_SELECT: {
1481 verifyVectorElementMatch(SelTy, CondTy,
MI);
1484 case TargetOpcode::G_MERGE_VALUES: {
1492 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1494 const unsigned NumOps =
MI->getNumOperands();
1496 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1498 for (
unsigned I = 2;
I !=
NumOps; ++
I) {
1499 if (MRI->
getType(
MI->getOperand(
I).getReg()) != SrcTy)
1500 report(
"G_MERGE_VALUES source types do not match",
MI);
1505 case TargetOpcode::G_UNMERGE_VALUES: {
1506 unsigned NumDsts =
MI->getNumOperands() - 1;
1508 for (
unsigned i = 1; i < NumDsts; ++i) {
1509 if (MRI->
getType(
MI->getOperand(i).getReg()) != DstTy) {
1510 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1515 LLT SrcTy = MRI->
getType(
MI->getOperand(NumDsts).getReg());
1523 report(
"G_UNMERGE_VALUES source operand does not match vector "
1524 "destination operands",
1531 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1532 "destination operands",
1537 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1538 "destination operands",
1544 case TargetOpcode::G_BUILD_VECTOR: {
1548 LLT SrcEltTy = MRI->
getType(
MI->getOperand(1).getReg());
1550 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1555 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1558 report(
"G_BUILD_VECTOR must have an operand for each element",
MI);
1562 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1566 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1570 LLT SrcEltTy = MRI->
getType(
MI->getOperand(1).getReg());
1572 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1576 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1579 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1584 case TargetOpcode::G_CONCAT_VECTORS: {
1590 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1593 if (
MI->getNumOperands() < 3)
1594 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1598 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1601 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1604 case TargetOpcode::G_ICMP:
1605 case TargetOpcode::G_FCMP: {
1612 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1616 case TargetOpcode::G_SCMP:
1617 case TargetOpcode::G_UCMP: {
1622 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1627 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1632 report(
"Result type must be at least 2 bits wide",
MI);
1639 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1645 case TargetOpcode::G_EXTRACT: {
1647 if (!
SrcOp.isReg()) {
1648 report(
"extract source must be a register",
MI);
1654 report(
"extract offset must be a constant",
MI);
1660 if (SrcSize == DstSize)
1661 report(
"extract source must be larger than result",
MI);
1663 if (DstSize +
OffsetOp.getImm() > SrcSize)
1664 report(
"extract reads past end of register",
MI);
1667 case TargetOpcode::G_INSERT: {
1669 if (!
SrcOp.isReg()) {
1670 report(
"insert source must be a register",
MI);
1676 report(
"insert offset must be a constant",
MI);
1683 if (DstSize <= SrcSize)
1684 report(
"inserted size must be smaller than total register",
MI);
1686 if (SrcSize +
OffsetOp.getImm() > DstSize)
1687 report(
"insert writes past end of register",
MI);
1691 case TargetOpcode::G_JUMP_TABLE: {
1692 if (!
MI->getOperand(1).isJTI())
1693 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1696 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1699 case TargetOpcode::G_BRJT: {
1701 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1703 if (!
MI->getOperand(1).isJTI())
1704 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1706 const auto &IdxOp =
MI->getOperand(2);
1708 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1711 case TargetOpcode::G_INTRINSIC:
1712 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1713 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1714 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1719 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1723 if (!verifyGIntrinsicSideEffects(
MI))
1725 if (!verifyGIntrinsicConvergence(
MI))
1730 case TargetOpcode::G_SEXT_INREG: {
1731 if (!
MI->getOperand(2).isImm()) {
1732 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1737 int64_t
Imm =
MI->getOperand(2).getImm();
1739 report(
"G_SEXT_INREG size must be >= 1",
MI);
1741 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1744 case TargetOpcode::G_BSWAP: {
1747 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1750 case TargetOpcode::G_VSCALE: {
1751 if (!
MI->getOperand(1).isCImm()) {
1752 report(
"G_VSCALE operand must be cimm",
MI);
1755 if (
MI->getOperand(1).getCImm()->isZero()) {
1756 report(
"G_VSCALE immediate cannot be zero",
MI);
1761 case TargetOpcode::G_STEP_VECTOR: {
1762 if (!
MI->getOperand(1).isCImm()) {
1763 report(
"operand must be cimm",
MI);
1767 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1768 report(
"step must be > 0",
MI);
1774 report(
"Destination type must be a scalable vector",
MI);
1780 report(
"Destination element type must be scalar",
MI);
1784 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1786 report(
"step bitwidth differs from result type element bitwidth",
MI);
1791 case TargetOpcode::G_INSERT_SUBVECTOR: {
1793 if (!Src0Op.
isReg()) {
1794 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1799 if (!Src1Op.
isReg()) {
1800 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1805 if (!IndexOp.
isImm()) {
1806 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1814 report(
"Destination type must be a vector",
MI);
1819 report(
"Second source must be a vector",
MI);
1824 report(
"Element type of vectors must be the same",
MI);
1829 report(
"Vector types must both be fixed or both be scalable",
MI);
1835 report(
"Second source must be smaller than destination vector",
MI);
1839 uint64_t Idx = IndexOp.
getImm();
1841 if (IndexOp.
getImm() % Src1MinLen != 0) {
1842 report(
"Index must be a multiple of the second source vector's "
1843 "minimum vector length",
1849 if (Idx >= DstMinLen || Idx + Src1MinLen > DstMinLen) {
1850 report(
"Subvector type and index must not cause insert to overrun the "
1851 "vector being inserted into",
1858 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1860 if (!
SrcOp.isReg()) {
1861 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1866 if (!IndexOp.
isImm()) {
1867 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1875 report(
"Destination type must be a vector",
MI);
1880 report(
"Source must be a vector",
MI);
1885 report(
"Element type of vectors must be the same",
MI);
1890 report(
"Vector types must both be fixed or both be scalable",
MI);
1896 report(
"Destination vector must be smaller than source vector",
MI);
1900 uint64_t Idx = IndexOp.
getImm();
1902 if (Idx % DstMinLen != 0) {
1903 report(
"Index must be a multiple of the destination vector's minimum "
1910 if (Idx >= SrcMinLen || Idx + DstMinLen > SrcMinLen) {
1911 report(
"Destination type and index must not cause extract to overrun the "
1919 case TargetOpcode::G_SHUFFLE_VECTOR: {
1922 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1930 if (Src0Ty != Src1Ty)
1931 report(
"Source operands must be the same type",
MI);
1934 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1938 report(
"G_SHUFFLE_VECTOR must have vector src",
MI);
1942 report(
"G_SHUFFLE_VECTOR must have vector dst",
MI);
1953 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1954 report(
"Wrong result type for shufflemask",
MI);
1956 for (
int Idx : MaskIdxes) {
1960 if (Idx >= 2 * SrcNumElts)
1961 report(
"Out of bounds shuffle index",
MI);
1967 case TargetOpcode::G_SPLAT_VECTOR: {
1972 report(
"Destination type must be a scalable vector",
MI);
1977 report(
"Source type must be a scalar or pointer",
MI);
1983 report(
"Element type of the destination must be the same size or smaller "
1984 "than the source type",
1991 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1997 report(
"Destination type must be a scalar or pointer",
MI);
2002 report(
"First source must be a vector",
MI);
2006 auto TLI = MF->getSubtarget().getTargetLowering();
2007 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2008 report(
"Index type must match VectorIdxTy",
MI);
2014 case TargetOpcode::G_INSERT_VECTOR_ELT: {
2021 report(
"Destination type must be a vector",
MI);
2025 if (VecTy != DstTy) {
2026 report(
"Destination type and vector type must match",
MI);
2031 report(
"Inserted element must be a scalar or pointer",
MI);
2035 auto TLI = MF->getSubtarget().getTargetLowering();
2036 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2037 report(
"Index type must match VectorIdxTy",
MI);
2043 case TargetOpcode::G_DYN_STACKALLOC: {
2049 report(
"dst operand 0 must be a pointer type",
MI);
2054 report(
"src operand 1 must be a scalar reg type",
MI);
2058 if (!AlignOp.
isImm()) {
2059 report(
"src operand 2 must be an immediate type",
MI);
2064 case TargetOpcode::G_MEMCPY_INLINE:
2065 case TargetOpcode::G_MEMCPY:
2066 case TargetOpcode::G_MEMMOVE: {
2068 if (MMOs.
size() != 2) {
2069 report(
"memcpy/memmove must have 2 memory operands",
MI);
2075 report(
"wrong memory operand types",
MI);
2080 report(
"inconsistent memory operand sizes",
MI);
2082 LLT DstPtrTy = MRI->
getType(
MI->getOperand(0).getReg());
2083 LLT SrcPtrTy = MRI->
getType(
MI->getOperand(1).getReg());
2086 report(
"memory instruction operand must be a pointer",
MI);
2091 report(
"inconsistent store address space",
MI);
2093 report(
"inconsistent load address space",
MI);
2095 if (
Opc != TargetOpcode::G_MEMCPY_INLINE)
2096 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2097 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2101 case TargetOpcode::G_BZERO:
2102 case TargetOpcode::G_MEMSET: {
2104 std::string
Name =
Opc == TargetOpcode::G_MEMSET ?
"memset" :
"bzero";
2105 if (MMOs.
size() != 1) {
2106 report(
Twine(Name,
" must have 1 memory operand"),
MI);
2111 report(
Twine(Name,
" memory operand must be a store"),
MI);
2115 LLT DstPtrTy = MRI->
getType(
MI->getOperand(0).getReg());
2117 report(
Twine(Name,
" operand must be a pointer"),
MI);
2122 report(
"inconsistent " +
Twine(Name,
" address space"),
MI);
2124 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2125 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2126 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2130 case TargetOpcode::G_UBSANTRAP: {
2132 if (!
MI->getOperand(0).isImm()) {
2133 report(
"Crash kind must be an immediate", &KindOp, 0);
2136 int64_t
Kind =
MI->getOperand(0).getImm();
2138 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2141 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2142 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2147 report(
"Vector reduction requires a scalar destination type",
MI);
2149 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2151 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2154 case TargetOpcode::G_VECREDUCE_FADD:
2155 case TargetOpcode::G_VECREDUCE_FMUL:
2156 case TargetOpcode::G_VECREDUCE_FMAX:
2157 case TargetOpcode::G_VECREDUCE_FMIN:
2158 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2159 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2160 case TargetOpcode::G_VECREDUCE_ADD:
2161 case TargetOpcode::G_VECREDUCE_MUL:
2162 case TargetOpcode::G_VECREDUCE_AND:
2163 case TargetOpcode::G_VECREDUCE_OR:
2164 case TargetOpcode::G_VECREDUCE_XOR:
2165 case TargetOpcode::G_VECREDUCE_SMAX:
2166 case TargetOpcode::G_VECREDUCE_SMIN:
2167 case TargetOpcode::G_VECREDUCE_UMAX:
2168 case TargetOpcode::G_VECREDUCE_UMIN: {
2171 report(
"Vector reduction requires a scalar destination type",
MI);
2175 case TargetOpcode::G_SBFX:
2176 case TargetOpcode::G_UBFX: {
2179 report(
"Bitfield extraction is not supported on vectors",
MI);
2184 case TargetOpcode::G_SHL:
2185 case TargetOpcode::G_LSHR:
2186 case TargetOpcode::G_ASHR:
2187 case TargetOpcode::G_ROTR:
2188 case TargetOpcode::G_ROTL: {
2192 report(
"Shifts and rotates require operands to be either all scalars or "
2199 case TargetOpcode::G_LLROUND:
2200 case TargetOpcode::G_LROUND: {
2207 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2209 verifyAllRegOpsScalar(*
MI, *MRI);
2212 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2217 case TargetOpcode::G_IS_FPCLASS: {
2221 report(
"Destination must be a scalar or vector of scalars",
MI);
2227 report(
"Source must be a scalar or vector of scalars",
MI);
2230 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2233 if (!TestMO.
isImm()) {
2234 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2239 report(
"Incorrect floating-point class set (operand 2)",
MI);
2244 case TargetOpcode::G_PREFETCH: {
2247 report(
"addr operand must be a pointer", &AddrOp, 0);
2251 if (!RWOp.
isImm() || (uint64_t)RWOp.
getImm() >= 2) {
2252 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2256 if (!LocalityOp.
isImm() || (uint64_t)LocalityOp.
getImm() >= 4) {
2257 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2261 if (!CacheTypeOp.
isImm() || (uint64_t)CacheTypeOp.
getImm() >= 2) {
2262 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2267 case TargetOpcode::G_ASSERT_ALIGN: {
2268 if (
MI->getOperand(2).getImm() < 1)
2269 report(
"alignment immediate must be >= 1",
MI);
2272 case TargetOpcode::G_CONSTANT_POOL: {
2273 if (!
MI->getOperand(1).isCPI())
2274 report(
"Src operand 1 must be a constant pool index",
MI);
2276 report(
"Dst operand 0 must be a pointer",
MI);
2279 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2282 report(
"addr operand must be a pointer", &AddrOp, 1);
2285 case TargetOpcode::G_SMIN:
2286 case TargetOpcode::G_SMAX:
2287 case TargetOpcode::G_UMIN:
2288 case TargetOpcode::G_UMAX: {
2289 const LLT DstTy = MRI->
getType(
MI->getOperand(0).getReg());
2291 report(
"Generic smin/smax/umin/umax does not support pointer operands",
2300void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2302 if (
MI->getNumOperands() <
MCID.getNumOperands()) {
2303 report(
"Too few operands",
MI);
2304 OS <<
MCID.getNumOperands() <<
" operands expected, but "
2305 <<
MI->getNumOperands() <<
" given.\n";
2309 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2312 if (MF->getProperties().hasNoPHIs())
2313 report(
"Found PHI instruction with NoPHIs property set",
MI);
2316 report(
"Found PHI instruction after non-PHI",
MI);
2317 }
else if (FirstNonPHI ==
nullptr)
2321 if (
MI->isInlineAsm())
2322 verifyInlineAsm(
MI);
2325 if (
TII->isUnspillableTerminator(
MI)) {
2326 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2327 report(
"Unspillable Terminator does not define a reg",
MI);
2329 if (
Def.isVirtual() && !MF->getProperties().hasNoPHIs() &&
2331 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2337 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2338 if (!
MI->getDebugLoc())
2339 report(
"Missing DebugLoc for debug instruction",
MI);
2343 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2344 report(
"Metadata instruction should not have a value tracking number",
MI);
2348 if (
Op->isLoad() && !
MI->mayLoad())
2349 report(
"Missing mayLoad flag",
MI);
2350 if (
Op->isStore() && !
MI->mayStore())
2351 report(
"Missing mayStore flag",
MI);
2357 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2358 if (
MI->isDebugOrPseudoInstr()) {
2360 report(
"Debug instruction has a slot index",
MI);
2361 }
else if (
MI->isInsideBundle()) {
2363 report(
"Instruction inside bundle has a slot index",
MI);
2366 report(
"Missing slot index",
MI);
2370 unsigned Opc =
MCID.getOpcode();
2372 verifyPreISelGenericInstruction(
MI);
2381 switch (
MI->getOpcode()) {
2382 case TargetOpcode::COPY: {
2392 if (SrcTy != DstTy) {
2393 report(
"Copy Instruction is illegal with mismatching types",
MI);
2394 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2409 TRI->getMinimalPhysRegClassLLT(SrcReg, DstTy);
2411 SrcSize =
TRI->getRegSizeInBits(SrcReg, *MRI);
2413 SrcSize =
TRI->getRegSizeInBits(SrcReg, *MRI);
2418 TRI->getMinimalPhysRegClassLLT(DstReg, SrcTy);
2420 DstSize =
TRI->getRegSizeInBits(DstReg, *MRI);
2422 DstSize =
TRI->getRegSizeInBits(DstReg, *MRI);
2440 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2441 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2442 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2447 case TargetOpcode::COPY_LANEMASK: {
2455 if (
DstOp.getSubReg())
2456 report(
"COPY_LANEMASK must not use a subregister index", &
DstOp, 0);
2458 if (
SrcOp.getSubReg())
2459 report(
"COPY_LANEMASK must not use a subregister index", &
SrcOp, 1);
2461 if (LaneMask.
none())
2462 report(
"COPY_LANEMASK must read at least one lane",
MI);
2474 if (SrcMaxLaneMask == LaneMask)
2475 report(
"COPY_LANEMASK cannot be used to do full copy",
MI);
2480 if (SrcMaxLaneMask < LaneMask)
2481 report(
"COPY_LANEMASK attempts to read from the lanes that "
2482 "don't exist in the source register",
2487 case TargetOpcode::STATEPOINT: {
2489 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2490 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2491 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2492 report(
"meta operands to STATEPOINT not constant!",
MI);
2496 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2497 if (
Offset >=
MI->getNumOperands()) {
2498 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2501 if (!
MI->getOperand(
Offset - 1).isImm() ||
2502 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2504 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2506 VerifyStackMapConstant(SO.getCCIdx());
2507 VerifyStackMapConstant(SO.getFlagsIdx());
2508 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2509 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2510 VerifyStackMapConstant(SO.getNumAllocaIdx());
2511 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2515 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2516 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2517 for (
unsigned Idx = 0; Idx <
MI->getNumDefs(); Idx++) {
2519 if (!
MI->isRegTiedToUseOperand(Idx, &UseOpIdx)) {
2520 report(
"STATEPOINT defs expected to be tied",
MI);
2523 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2524 report(
"STATEPOINT def tied to non-gc operand",
MI);
2531 case TargetOpcode::INSERT_SUBREG: {
2532 unsigned InsertedSize;
2533 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2534 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2536 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *MRI);
2537 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2538 if (SubRegSize < InsertedSize) {
2539 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2540 "size than the subreg it was inserted into",
MI);
2544 case TargetOpcode::REG_SEQUENCE: {
2545 unsigned NumOps =
MI->getNumOperands();
2547 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2551 for (
unsigned I = 1;
I !=
NumOps;
I += 2) {
2556 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2558 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2559 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2560 report(
"Invalid subregister index operand for REG_SEQUENCE",
2565 Register DstReg =
MI->getOperand(0).getReg();
2567 report(
"REG_SEQUENCE does not support physical register results",
MI);
2569 if (
MI->getOperand(0).getSubReg())
2570 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2578MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2581 unsigned NumDefs =
MCID.getNumDefs();
2582 if (
MCID.getOpcode() == TargetOpcode::PATCHPOINT)
2583 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2586 if (MONum < NumDefs) {
2589 report(
"Explicit definition must be a register", MO, MONum);
2590 else if (!MO->
isDef() && !
MCOI.isOptionalDef())
2591 report(
"Explicit definition marked as use", MO, MONum);
2593 report(
"Explicit definition marked as implicit", MO, MONum);
2594 }
else if (MONum <
MCID.getNumOperands()) {
2598 bool IsOptional =
MI->isVariadic() && MONum ==
MCID.getNumOperands() - 1;
2601 if (MO->
isDef() && !
MCOI.isOptionalDef() && !
MCID.variadicOpsAreDefs())
2602 report(
"Explicit operand marked as def", MO, MONum);
2604 report(
"Explicit operand marked as implicit", MO, MONum);
2610 report(
"Expected a register operand.", MO, MONum);
2614 !
TII->isPCRelRegisterOperandLegal(*MO)))
2615 report(
"Expected a non-register operand.", MO, MONum);
2622 report(
"Tied use must be a register", MO, MONum);
2624 report(
"Operand should be tied", MO, MONum);
2625 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2626 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2629 if (!MOTied.
isReg())
2630 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2633 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2636 report(
"Explicit operand should not be tied", MO, MONum);
2637 }
else if (!
MI->isVariadic()) {
2640 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2646 report(
"Early clobber must be a register",
MI);
2648 report(
"Missing earlyClobber flag",
MI);
2655 if (
MI->isDebugInstr() && MO->
isUse()) {
2657 report(
"Register operand must be marked debug", MO, MONum);
2659 report(
"Register operand must not be marked debug", MO, MONum);
2666 checkLiveness(MO, MONum);
2670 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2674 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2676 if (!OtherMO.
isReg())
2677 report(
"Must be tied to a register", MO, MONum);
2679 report(
"Missing tie flags on tied operand", MO, MONum);
2680 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2681 report(
"Inconsistent tie links", MO, MONum);
2682 if (MONum <
MCID.getNumDefs()) {
2683 if (OtherIdx <
MCID.getNumOperands()) {
2685 report(
"Explicit def tied to explicit use without tie constraint",
2689 report(
"Explicit def should be tied to implicit use", MO, MONum);
2702 if (MF->getProperties().hasTiedOpsRewritten() && MO->
isUse() &&
2703 MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2704 Reg !=
MI->getOperand(DefIdx).getReg())
2705 report(
"Two-address instruction operands must be identical", MO, MONum);
2712 report(
"Illegal subregister index for physical register", MO, MONum);
2715 if (MONum <
MCID.getNumOperands()) {
2717 if (!DRC->contains(
Reg)) {
2718 report(
"Illegal physical register for instruction", MO, MONum);
2720 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2726 report(
"isRenamable set on reserved register", MO, MONum);
2743 report(
"Generic virtual register use cannot be undef", MO, MONum);
2750 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2753 if (isFunctionSelected) {
2754 report(
"Generic virtual register invalid in a Selected function",
2762 report(
"Generic virtual register must have a valid type", MO,
2771 if (!RegBank && isFunctionRegBankSelected) {
2772 report(
"Generic virtual register must have a bank in a "
2773 "RegBankSelected function",
2781 report(
"Register bank is too small for virtual register", MO,
2783 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2791 report(
"Generic virtual register does not allow subregister index", MO,
2800 MONum <
MCID.getNumOperands() &&
TII->getRegClass(
MCID, MONum)) {
2801 report(
"Virtual register does not match instruction constraint", MO,
2803 OS <<
"Expect register class "
2804 <<
TRI->getRegClassName(
TII->getRegClass(
MCID, MONum))
2805 <<
" but got nothing\n";
2812 if (!
TRI->isSubRegValidForRegClass(RC, SubIdx)) {
2813 report(
"Invalid subregister index for virtual register", MO, MONum);
2814 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2815 <<
" does not support subreg index "
2816 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2819 if (MONum >=
MCID.getNumOperands())
2828 if (SubIdx &&
TRI->getMatchingSuperRegClass(RC, DRC, SubIdx) != RC) {
2829 report(
"Illegal virtual register for instruction", MO, MONum);
2830 OS <<
TRI->getRegClassName(RC) <<
"." <<
TRI->getSubRegIndexName(SubIdx)
2831 <<
" cannot be used for " <<
TRI->getRegClassName(DRC)
2837 report(
"Illegal virtual register for instruction", MO, MONum);
2838 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2839 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2852 report(
"PHI operand is not in the CFG", MO, MONum);
2856 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2857 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2860 SlotIndex Idx = LiveInts->getInstructionIndex(*
MI);
2867 if (MayStore && MayLoad) {
2880 if (MayLoad == MayStore)
2881 report(
"Missing fixed stack memoperand.",
MI);
2884 report(
"Instruction loads from dead spill slot", MO, MONum);
2885 OS <<
"Live stack: " << LI <<
'\n';
2888 report(
"Instruction stores to dead spill slot", MO, MONum);
2889 OS <<
"Live stack: " << LI <<
'\n';
2895 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2896 report(
"CFI instruction has invalid index", MO, MONum);
2904void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2912 report(
"invalid live range", MO, MONum);
2913 report_context_liverange(LR);
2914 report_context_vreg_regunit(VRegOrUnit);
2915 report_context(UseIdx);
2924 report(
"No live segment at use", MO, MONum);
2925 report_context_liverange(LR);
2926 report_context_vreg_regunit(VRegOrUnit);
2927 report_context(UseIdx);
2930 report(
"Live range continues after kill flag", MO, MONum);
2931 report_context_liverange(LR);
2932 report_context_vreg_regunit(VRegOrUnit);
2934 report_context_lanemask(LaneMask);
2935 report_context(UseIdx);
2939void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2946 report(
"invalid live range", MO, MONum);
2947 report_context_liverange(LR);
2948 report_context_vreg_regunit(VRegOrUnit);
2950 report_context_lanemask(LaneMask);
2951 report_context(DefIdx);
2963 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
2965 (VNI->def != DefIdx &&
2966 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
2967 report(
"Inconsistent valno->def", MO, MONum);
2968 report_context_liverange(LR);
2969 report_context_vreg_regunit(VRegOrUnit);
2971 report_context_lanemask(LaneMask);
2972 report_context(*VNI);
2973 report_context(DefIdx);
2976 report(
"No live segment at def", MO, MONum);
2977 report_context_liverange(LR);
2978 report_context_vreg_regunit(VRegOrUnit);
2980 report_context_lanemask(LaneMask);
2981 report_context(DefIdx);
2993 if (SubRangeCheck || MO->
getSubReg() == 0) {
2994 report(
"Live range continues after dead def flag", MO, MONum);
2995 report_context_liverange(LR);
2996 report_context_vreg_regunit(VRegOrUnit);
2998 report_context_lanemask(LaneMask);
3004void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
3007 const unsigned SubRegIdx = MO->
getSubReg();
3011 if (LiveInts->hasInterval(
Reg)) {
3012 LI = &LiveInts->getInterval(
Reg);
3015 report(
"Live interval for subreg operand has no subranges", MO, MONum);
3017 report(
"Virtual register has no live interval", MO, MONum);
3024 addRegWithSubRegs(regsKilled,
Reg);
3030 !
MI->isBundledWithPred()) {
3033 report(
"Kill missing from LiveVariables", MO, MONum);
3037 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3041 UseIdx = LiveInts->getMBBEndIdx(
3042 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
3044 UseIdx = LiveInts->getInstructionIndex(*
MI);
3051 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3052 checkLivenessAtUse(MO, MONum, UseIdx, *LR,
VirtRegOrUnit(Unit));
3062 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3066 if ((MOMask & SR.LaneMask).none())
3072 LiveInMask |= SR.LaneMask;
3075 if ((LiveInMask & MOMask).
none()) {
3076 report(
"No live subrange at use", MO, MONum);
3077 report_context(*LI);
3078 report_context(UseIdx);
3081 if (
MI->isPHI() && LiveInMask != MOMask) {
3082 report(
"Not all lanes of PHI source live at use", MO, MONum);
3083 report_context(*LI);
3084 report_context(UseIdx);
3091 if (!regsLive.count(
Reg)) {
3094 bool Bad = !isReserved(
Reg);
3099 if (regsLive.count(SubReg)) {
3111 if (!MOP.isReg() || !MOP.isImplicit())
3114 if (!MOP.getReg().isPhysical())
3117 if (MOP.getReg() !=
Reg &&
3118 all_of(
TRI->regunits(
Reg), [&](
const MCRegUnit RegUnit) {
3119 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3126 report(
"Using an undefined physical register", MO, MONum);
3128 report(
"Reading virtual register without a def", MO, MONum);
3130 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3134 if (MInfo.regsKilled.count(
Reg))
3135 report(
"Using a killed virtual register", MO, MONum);
3136 else if (!
MI->isPHI())
3137 MInfo.vregsLiveIn.insert(std::make_pair(
Reg,
MI));
3146 addRegWithSubRegs(regsDead,
Reg);
3148 addRegWithSubRegs(regsDefined,
Reg);
3153 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3155 report(
"Subreg def in SSA form", MO, MONum);
3159 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3160 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3168 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3171 if ((SR.LaneMask & MOMask).none())
3186void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3187 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3188 set_union(MInfo.regsKilled, regsKilled);
3189 set_subtract(regsLive, regsKilled); regsKilled.clear();
3191 while (!regMasks.empty()) {
3192 const uint32_t *
Mask = regMasks.pop_back_val();
3196 regsDead.push_back(
Reg);
3199 set_union(regsLive, regsDefined); regsDefined.clear();
3204 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3209 if (!(stop > lastIndex)) {
3210 report(
"Block ends before last instruction index",
MBB);
3211 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3227 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3229 filterAndAdd(FromRegSet, VRegsBuffer);
3234 template <
typename RegSetT>
3235 bool filterAndAdd(
const RegSetT &FromRegSet,
3236 SmallVectorImpl<Register> &ToVRegs) {
3237 unsigned SparseUniverse = Sparse.size();
3238 unsigned NewSparseUniverse = SparseUniverse;
3239 unsigned NewDenseSize =
Dense.size();
3240 size_t Begin = ToVRegs.
size();
3245 if (Index < SparseUniverseMax) {
3246 if (Index < SparseUniverse && Sparse.test(Index))
3248 NewSparseUniverse = std::max(NewSparseUniverse, Index + 1);
3256 size_t End = ToVRegs.
size();
3263 Sparse.resize(NewSparseUniverse);
3264 Dense.reserve(NewDenseSize);
3265 for (
unsigned I = Begin;
I < End; ++
I) {
3268 if (Index < SparseUniverseMax)
3277 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3288 DenseSet<Register>
Dense;
3297class FilteringVRegSet {
3304 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3309 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3312 return Filter.filterAndAdd(RS, VRegs);
3314 using const_iterator =
decltype(VRegs)::const_iterator;
3315 const_iterator
begin()
const {
return VRegs.
begin(); }
3316 const_iterator
end()
const {
return VRegs.
end(); }
3317 size_t size()
const {
return VRegs.
size(); }
3324void MachineVerifier::calcRegsPassed() {
3331 FilteringVRegSet VRegs;
3332 BBInfo &
Info = MBBInfoMap[MB];
3335 VRegs.addToFilter(
Info.regsKilled);
3336 VRegs.addToFilter(
Info.regsLiveOut);
3338 const BBInfo &PredInfo = MBBInfoMap[Pred];
3339 if (!PredInfo.reachable)
3342 VRegs.add(PredInfo.regsLiveOut);
3343 VRegs.add(PredInfo.vregsPassed);
3345 Info.vregsPassed.reserve(VRegs.size());
3346 Info.vregsPassed.insert_range(VRegs);
3353void MachineVerifier::calcRegsRequired() {
3356 for (
const auto &
MBB : *MF) {
3357 BBInfo &MInfo = MBBInfoMap[&
MBB];
3359 BBInfo &PInfo = MBBInfoMap[Pred];
3360 if (PInfo.addRequired(MInfo.vregsLiveIn))
3366 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3368 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3375 BBInfo &PInfo = MBBInfoMap[Pred];
3376 if (PInfo.addRequired(
Reg))
3384 while (!todo.
empty()) {
3387 BBInfo &MInfo = MBBInfoMap[
MBB];
3391 BBInfo &SInfo = MBBInfoMap[Pred];
3392 if (SInfo.addRequired(MInfo.vregsRequired))
3401 BBInfo &MInfo = MBBInfoMap[&
MBB];
3411 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3416 report(
"Unexpected flag on PHI operand", &MODef, 0);
3419 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3421 for (
unsigned I = 1,
E =
Phi.getNumOperands();
I !=
E;
I += 2) {
3424 report(
"Expected PHI operand to be a register", &MO0,
I);
3429 report(
"Unexpected flag on PHI operand", &MO0,
I);
3433 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3439 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3443 if (MInfo.reachable) {
3445 BBInfo &PrInfo = MBBInfoMap[&Pre];
3446 if (!MO0.
isUndef() && PrInfo.reachable &&
3447 !PrInfo.isLiveOut(MO0.
getReg()))
3448 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3453 if (MInfo.reachable) {
3455 if (!seen.
count(Pred)) {
3456 report(
"Missing PHI operand", &Phi);
3458 <<
" is a predecessor according to the CFG.\n";
3467 std::function<
void(
const Twine &Message)> FailureCB,
3472 for (
const auto &
MBB : MF) {
3474 for (
const auto &
MI :
MBB.instrs())
3484void MachineVerifier::visitMachineFunctionAfter() {
3485 auto FailureCB = [
this](
const Twine &Message) {
3486 report(Message.str().c_str(), MF);
3499 for (
const auto &
MBB : *MF) {
3500 BBInfo &MInfo = MBBInfoMap[&
MBB];
3501 for (
Register VReg : MInfo.vregsRequired)
3502 if (MInfo.regsKilled.count(VReg)) {
3503 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3504 OS <<
"Virtual register " <<
printReg(VReg)
3505 <<
" is used after the block.\n";
3510 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3511 for (
Register VReg : MInfo.vregsRequired) {
3512 report(
"Virtual register defs don't dominate all uses.", MF);
3513 report_context_vreg(VReg);
3518 verifyLiveVariables();
3520 verifyLiveIntervals();
3530 for (
const auto &
MBB : *MF)
3534 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3537 BBInfo &PInfo = MBBInfoMap[Pred];
3538 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3539 report(
"Live in register not found to be live out from predecessor.",
3541 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3547 for (
auto CSInfo : MF->getCallSitesInfo())
3548 if (!CSInfo.first->isCall())
3549 report(
"Call site info referencing instruction that is not call", MF);
3553 if (MF->getFunction().getSubprogram()) {
3555 for (
const auto &
MBB : *MF) {
3556 for (
const auto &
MI :
MBB) {
3557 if (
auto Num =
MI.peekDebugInstrNum()) {
3560 report(
"Instruction has a duplicated value tracking number", &
MI);
3567void MachineVerifier::verifyLiveVariables() {
3568 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3572 for (
const auto &
MBB : *MF) {
3573 BBInfo &MInfo = MBBInfoMap[&
MBB];
3576 if (MInfo.vregsRequired.count(
Reg)) {
3578 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3580 <<
" must be live through the block.\n";
3584 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3586 <<
" is not needed live through the block.\n";
3593void MachineVerifier::verifyLiveIntervals() {
3594 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3602 if (!LiveInts->hasInterval(
Reg)) {
3603 report(
"Missing live interval for virtual register", MF);
3609 assert(
Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3610 verifyLiveInterval(LI);
3614 for (MCRegUnit Unit :
TRI->regunits())
3615 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3619void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3629 report(
"Value not live at VNInfo def and not marked unused", MF);
3630 report_context(LR, VRegOrUnit, LaneMask);
3631 report_context(*VNI);
3635 if (DefVNI != VNI) {
3636 report(
"Live segment at def has different VNInfo", MF);
3637 report_context(LR, VRegOrUnit, LaneMask);
3638 report_context(*VNI);
3644 report(
"Invalid VNInfo definition index", MF);
3645 report_context(LR, VRegOrUnit, LaneMask);
3646 report_context(*VNI);
3651 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3652 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3653 report_context(LR, VRegOrUnit, LaneMask);
3654 report_context(*VNI);
3662 report(
"No instruction at VNInfo def index",
MBB);
3663 report_context(LR, VRegOrUnit, LaneMask);
3664 report_context(*VNI);
3668 bool hasDef =
false;
3669 bool isEarlyClobber =
false;
3671 if (!MOI->isReg() || !MOI->isDef())
3677 if (!MOI->getReg().isPhysical() ||
3681 if (LaneMask.
any() &&
3682 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3685 if (MOI->isEarlyClobber())
3686 isEarlyClobber =
true;
3690 report(
"Defining instruction does not modify register",
MI);
3691 report_context(LR, VRegOrUnit, LaneMask);
3692 report_context(*VNI);
3697 if (isEarlyClobber) {
3699 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3700 report_context(LR, VRegOrUnit, LaneMask);
3701 report_context(*VNI);
3704 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3705 report_context(LR, VRegOrUnit, LaneMask);
3706 report_context(*VNI);
3710void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3716 assert(VNI &&
"Live segment has no valno");
3719 report(
"Foreign valno in live segment", MF);
3720 report_context(LR, VRegOrUnit, LaneMask);
3722 report_context(*VNI);
3726 report(
"Live segment valno is marked unused", MF);
3727 report_context(LR, VRegOrUnit, LaneMask);
3733 report(
"Bad start of live segment, no basic block", MF);
3734 report_context(LR, VRegOrUnit, LaneMask);
3740 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3741 report_context(LR, VRegOrUnit, LaneMask);
3748 report(
"Bad end of live segment, no basic block", MF);
3749 report_context(LR, VRegOrUnit, LaneMask);
3755 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3765 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3766 report_context(LR, VRegOrUnit, LaneMask);
3773 report(
"Live segment ends at B slot of an instruction", EndMBB);
3774 report_context(LR, VRegOrUnit, LaneMask);
3782 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3783 report_context(LR, VRegOrUnit, LaneMask);
3793 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3794 report(
"Live segment ending at early clobber slot must be "
3795 "redefined by an EC def in the same instruction",
3797 report_context(LR, VRegOrUnit, LaneMask);
3807 bool hasRead =
false;
3808 bool hasSubRegDef =
false;
3809 bool hasDeadDef =
false;
3811 if (!MOI->isReg() || MOI->getReg() != VRegOrUnit.
asVirtualReg())
3813 unsigned Sub = MOI->getSubReg();
3818 hasSubRegDef =
true;
3827 if (LaneMask.
any() && (LaneMask & SLM).none())
3829 if (MOI->readsReg())
3836 if (LaneMask.
none() && !hasDeadDef) {
3838 "Instruction ending live segment on dead slot has no dead flag",
3840 report_context(LR, VRegOrUnit, LaneMask);
3848 LaneMask.
any() || !hasSubRegDef) {
3849 report(
"Instruction ending live segment doesn't read the register",
3851 report_context(LR, VRegOrUnit, LaneMask);
3871 if (LaneMask.
any()) {
3877 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3880 if (&*MFI == EndMBB)
3888 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3892 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3894 if (MFI->isEHPad()) {
3897 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3908 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3911 report(
"Register not marked live out of predecessor", Pred);
3912 report_context(LR, VRegOrUnit, LaneMask);
3913 report_context(*VNI);
3915 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3921 if (!IsPHI && PVNI != VNI) {
3922 report(
"Different value live out of predecessor", Pred);
3923 report_context(LR, VRegOrUnit, LaneMask);
3924 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3927 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3930 if (&*MFI == EndMBB)
3936void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
3940 verifyLiveRangeValue(LR, VNI, VRegOrUnit, LaneMask);
3943 verifyLiveRangeSegment(LR,
I, VRegOrUnit, LaneMask);
3946void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3955 if ((Mask & SR.LaneMask).any()) {
3956 report(
"Lane masks of sub ranges overlap in live interval", MF);
3959 if ((SR.LaneMask & ~MaxMask).any()) {
3960 report(
"Subrange lanemask is invalid", MF);
3964 report(
"Subrange must not be empty", MF);
3967 Mask |= SR.LaneMask;
3970 report(
"A Subrange is not covered by the main range", MF);
3978 unsigned NumComp = ConEQ.Classify(LI);
3980 report(
"Multiple connected components in live interval", MF);
3982 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3983 OS << comp <<
": valnos";
3985 if (comp == ConEQ.getEqClass(
I))
3998struct StackStateOfBB {
3999 StackStateOfBB() =
default;
4000 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
4001 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
4002 ExitIsSetup(ExitSetup) {}
4007 bool EntryIsSetup =
false;
4008 bool ExitIsSetup =
false;
4016void MachineVerifier::verifyStackFrame() {
4017 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
4018 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
4019 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
4023 SPState.
resize(MF->getNumBlockIDs());
4030 DFI != DFE; ++DFI) {
4033 StackStateOfBB BBState;
4035 if (DFI.getPathLength() >= 2) {
4038 "DFS stack predecessor is already visited.\n");
4039 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
4040 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
4041 BBState.ExitValue = BBState.EntryValue;
4042 BBState.ExitIsSetup = BBState.EntryIsSetup;
4046 report(
"Call frame size on entry does not match value computed from "
4050 <<
" does not match value computed from predecessor "
4051 << -BBState.EntryValue <<
'\n';
4055 for (
const auto &
I : *
MBB) {
4056 if (
I.getOpcode() == FrameSetupOpcode) {
4057 if (BBState.ExitIsSetup)
4058 report(
"FrameSetup is after another FrameSetup", &
I);
4059 if (!MRI->
isSSA() && !MF->getFrameInfo().adjustsStack())
4060 report(
"AdjustsStack not set in presence of a frame pseudo "
4061 "instruction.", &
I);
4062 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
4063 BBState.ExitIsSetup =
true;
4066 if (
I.getOpcode() == FrameDestroyOpcode) {
4067 int Size =
TII->getFrameTotalSize(
I);
4068 if (!BBState.ExitIsSetup)
4069 report(
"FrameDestroy is not after a FrameSetup", &
I);
4070 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
4072 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
4073 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
4074 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
4075 << AbsSPAdj <<
">.\n";
4077 if (!MRI->
isSSA() && !MF->getFrameInfo().adjustsStack())
4078 report(
"AdjustsStack not set in presence of a frame pseudo "
4079 "instruction.", &
I);
4080 BBState.ExitValue +=
Size;
4081 BBState.ExitIsSetup =
false;
4089 if (Reachable.
count(Pred) &&
4090 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4091 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4092 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4094 << SPState[Pred->
getNumber()].ExitValue <<
", "
4095 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4097 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4104 if (Reachable.
count(Succ) &&
4105 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4106 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4107 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4109 << SPState[Succ->getNumber()].EntryValue <<
", "
4110 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4112 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4118 if (BBState.ExitIsSetup)
4119 report(
"A return block ends with a FrameSetup.",
MBB);
4120 if (BBState.ExitValue)
4121 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
4126void MachineVerifier::verifyStackProtector() {
4135 bool StackGrowsDown =
4162 if (SPStart < ObjEnd && ObjStart < SPEnd) {
4163 report(
"Stack protector overlaps with another stack object", MF);
4166 if ((StackGrowsDown && SPStart <= ObjStart) ||
4167 (!StackGrowsDown && SPStart >= ObjStart)) {
4168 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)
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
std::unordered_set< BasicBlock * > BlockSet
This file defines generic set operations that may be used on set's of different types,...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
static unsigned getSize(unsigned Kind)
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - 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()
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 isScalar() const
constexpr Kind getKind() const
LLT getScalarType() const
constexpr bool isPointerVector() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
constexpr bool isPointerOrPointerVector() const
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.
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.
StringRef - Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
bool hasSuperClassEq(const TargetRegisterClass *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.
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
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.
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.
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.