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() {
690 regsReserved =
MRI->reservedRegsFrozen() ?
MRI->getReservedRegs()
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);
712 MRI->verifyUseLists();
716 verifyStackProtector();
722 FirstTerminator =
nullptr;
723 FirstNonPHI =
nullptr;
725 if (!MF->getProperties().hasNoPHIs() &&
MRI->tracksLiveness()) {
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 &&
780 report(
"MBB has more than one landing pad successor",
MBB);
793 report(
"MBB exits via unconditional fall-through but ends with a "
794 "barrier instruction!",
MBB);
797 report(
"MBB exits via unconditional fall-through but has a condition!",
803 report(
"MBB exits via unconditional branch but doesn't contain "
804 "any instructions!",
MBB);
806 report(
"MBB exits via unconditional branch but doesn't end with a "
807 "barrier instruction!",
MBB);
809 report(
"MBB exits via unconditional branch but the branch isn't a "
810 "terminator instruction!",
MBB);
815 report(
"MBB exits via conditional branch/fall-through but doesn't "
816 "contain any instructions!",
MBB);
818 report(
"MBB exits via conditional branch/fall-through but ends with a "
819 "barrier instruction!",
MBB);
821 report(
"MBB exits via conditional branch/fall-through but the branch "
822 "isn't a terminator instruction!",
MBB);
824 }
else if (
TBB && FBB) {
828 report(
"MBB exits via conditional branch/branch but doesn't "
829 "contain any instructions!",
MBB);
831 report(
"MBB exits via conditional branch/branch but doesn't end with a "
832 "barrier instruction!",
MBB);
834 report(
"MBB exits via conditional branch/branch but the branch "
835 "isn't a terminator instruction!",
MBB);
838 report(
"MBB exits via conditional branch/branch but there's no "
842 report(
"analyzeBranch returned invalid data!",
MBB);
848 report(
"MBB exits via jump or conditional branch, but its target isn't a "
852 report(
"MBB exits via conditional branch, but its target isn't a CFG "
859 bool Fallthrough = !
TBB || (!
Cond.empty() && !FBB);
864 if (!
Cond.empty() && !FBB) {
867 report(
"MBB conditionally falls through out of function!",
MBB);
869 report(
"MBB exits via conditional branch/fall-through but the CFG "
870 "successors don't match the actual successors!",
877 if (SuccMBB ==
TBB || SuccMBB == FBB)
885 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
887 report(
"MBB has unexpected successors which are not branch targets, "
888 "fallthrough, EHPads, or inlineasm_br targets.",
894 if (
MRI->tracksLiveness()) {
896 if (!LI.PhysReg.isPhysical()) {
897 report(
"MBB live-in list contains non-physical register",
MBB);
900 regsLive.insert_range(
TRI->subregs_inclusive(LI.PhysReg));
907 regsLive.insert_range(
TRI->subregs_inclusive(
I));
913 lastIndex = Indexes->getMBBStartIdx(
MBB);
918void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
919 if (Indexes && Indexes->hasIndex(*
MI)) {
921 if (!(idx > lastIndex)) {
922 report(
"Instruction index out of order",
MI);
923 OS <<
"Last instruction was at " << lastIndex <<
'\n';
929 if (
MI->isTerminator()) {
930 if (!FirstTerminator)
931 FirstTerminator =
MI;
932 }
else if (FirstTerminator) {
935 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
936 report(
"Non-terminator instruction after the first terminator",
MI);
937 OS <<
"First terminator was:\t" << *FirstTerminator;
946 if (
MI->getNumOperands() < 2) {
947 report(
"Too few operands on inline asm",
MI);
950 if (!
MI->getOperand(0).isSymbol())
951 report(
"Asm string must be an external symbol",
MI);
952 if (!
MI->getOperand(1).isImm())
953 report(
"Asm flags must be an immediate",
MI);
958 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
964 for (
unsigned e =
MI->getNumOperands(); OpNo < e; OpNo +=
NumOps) {
970 NumOps = 1 +
F.getNumOperandRegisters();
973 if (OpNo >
MI->getNumOperands())
974 report(
"Missing operands in last group",
MI);
977 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
981 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
984 report(
"Expected implicit register after groups", &MO, OpNo);
987 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
1000 if (!IndirectTargetMBB) {
1001 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1006 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1010 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1016bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1021 const auto Reg = Op.getReg();
1022 if (Reg.isPhysical())
1024 return !MRI.getType(Reg).isScalar();
1027 report(
"All register operands must have scalar types", &
MI);
1034bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1037 report(
"operand types must be all-vector or all-scalar",
MI);
1047 report(
"operand types must preserve number of vector elements",
MI);
1054bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1055 auto Opcode =
MI->getOpcode();
1056 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1057 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1059 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1061 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1062 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1063 if (NoSideEffects && DeclHasSideEffects) {
1065 " used with intrinsic that accesses memory"),
1069 if (!NoSideEffects && !DeclHasSideEffects) {
1070 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1078bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1079 auto Opcode =
MI->getOpcode();
1080 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1081 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1083 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1085 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1086 bool DeclIsConvergent =
Attrs.hasAttribute(Attribute::Convergent);
1087 if (NotConvergent && DeclIsConvergent) {
1088 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1092 if (!NotConvergent && !DeclIsConvergent) {
1094 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1103void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1104 if (isFunctionSelected)
1105 report(
"Unexpected generic instruction in a Selected function",
MI);
1108 unsigned NumOps =
MI->getNumOperands();
1111 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1112 bool HasMBB =
false;
1121 report(
"Branch instruction is missing a basic block operand or "
1122 "isIndirectBranch property",
1129 for (
unsigned I = 0,
E = std::min(
MCID.getNumOperands(),
NumOps);
1131 if (!
MCID.operands()[
I].isGenericType())
1135 size_t TypeIdx =
MCID.operands()[
I].getGenericTypeIndex();
1136 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1140 report(
"generic instruction must use register operands",
MI);
1150 if (!Types[TypeIdx].
isValid())
1151 Types[TypeIdx] = OpTy;
1152 else if (Types[TypeIdx] != OpTy)
1153 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1156 report(
"Generic instruction is missing a virtual register type", MO,
I);
1161 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1164 report(
"Generic instruction cannot have physical register", MO,
I);
1168 if (
MI->getNumOperands() <
MCID.getNumOperands())
1176 unsigned Opc =
MI->getOpcode();
1178 case TargetOpcode::G_ASSERT_SEXT:
1179 case TargetOpcode::G_ASSERT_ZEXT: {
1180 std::string OpcName =
1181 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1182 if (!
MI->getOperand(2).isImm()) {
1183 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1189 LLT SrcTy =
MRI->getType(Src);
1190 int64_t
Imm =
MI->getOperand(2).getImm();
1192 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1197 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1205 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1206 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1212 if (DstRC && DstRC !=
MRI->getRegClassOrNull(Src)) {
1214 Twine(OpcName,
" source and destination register classes must match"),
1222 case TargetOpcode::G_CONSTANT:
1223 case TargetOpcode::G_FCONSTANT: {
1224 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1226 report(
"Instruction cannot use a vector result type",
MI);
1228 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1229 if (!
MI->getOperand(1).isCImm()) {
1230 report(
"G_CONSTANT operand must be cimm",
MI);
1236 report(
"inconsistent constant size",
MI);
1238 if (!
MI->getOperand(1).isFPImm()) {
1239 report(
"G_FCONSTANT operand must be fpimm",
MI);
1246 report(
"inconsistent constant size",
MI);
1252 case TargetOpcode::G_LOAD:
1253 case TargetOpcode::G_STORE:
1254 case TargetOpcode::G_ZEXTLOAD:
1255 case TargetOpcode::G_SEXTLOAD: {
1256 LLT ValTy =
MRI->getType(
MI->getOperand(0).getReg());
1257 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1259 report(
"Generic memory instruction must access a pointer",
MI);
1263 if (!
MI->hasOneMemOperand()) {
1264 report(
"Generic instruction accessing memory must have one mem operand",
1268 if (
MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
1269 MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
1272 report(
"Generic extload must have a narrower memory type",
MI);
1273 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1276 report(
"load memory size cannot exceed result size",
MI);
1287 report(
"range is incompatible with the result type",
MI);
1290 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1293 report(
"store memory size cannot exceed value size",
MI);
1297 if (
Opc == TargetOpcode::G_STORE) {
1300 report(
"atomic store cannot use acquire ordering",
MI);
1305 report(
"atomic load cannot use release ordering",
MI);
1311 case TargetOpcode::G_PHI: {
1312 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1317 LLT Ty = MRI->getType(MO.getReg());
1318 if (!Ty.isValid() || (Ty != DstTy))
1322 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1327 case TargetOpcode::G_BITCAST: {
1328 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1329 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1334 report(
"bitcast cannot convert between pointers and other types",
MI);
1337 report(
"bitcast sizes must match",
MI);
1340 report(
"bitcast must change the type",
MI);
1344 case TargetOpcode::G_INTTOPTR:
1345 case TargetOpcode::G_PTRTOINT:
1346 case TargetOpcode::G_ADDRSPACE_CAST: {
1347 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1348 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1352 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1357 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1359 report(
"inttoptr result type must be a pointer",
MI);
1361 report(
"inttoptr source type must not be a pointer",
MI);
1362 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1364 report(
"ptrtoint source type must be a pointer",
MI);
1366 report(
"ptrtoint result type must not be a pointer",
MI);
1368 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1370 report(
"addrspacecast types must be pointers",
MI);
1373 report(
"addrspacecast must convert different address spaces",
MI);
1379 case TargetOpcode::G_PTR_ADD: {
1380 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1381 LLT PtrTy =
MRI->getType(
MI->getOperand(1).getReg());
1382 LLT OffsetTy =
MRI->getType(
MI->getOperand(2).getReg());
1387 report(
"gep first operand must be a pointer",
MI);
1390 report(
"gep offset operand must not be a pointer",
MI);
1395 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1397 report(
"gep offset operand must match index size for address space",
1405 case TargetOpcode::G_PTRMASK: {
1406 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1407 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1408 LLT MaskTy =
MRI->getType(
MI->getOperand(2).getReg());
1413 report(
"ptrmask result type must be a pointer",
MI);
1416 report(
"ptrmask mask type must be an integer",
MI);
1418 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1421 case TargetOpcode::G_SEXT:
1422 case TargetOpcode::G_ZEXT:
1423 case TargetOpcode::G_ANYEXT:
1424 case TargetOpcode::G_TRUNC:
1425 case TargetOpcode::G_TRUNC_SSAT_S:
1426 case TargetOpcode::G_TRUNC_SSAT_U:
1427 case TargetOpcode::G_TRUNC_USAT_U:
1428 case TargetOpcode::G_FPEXT:
1429 case TargetOpcode::G_FPTRUNC: {
1435 assert(
MCID.getNumOperands() == 2 &&
"Expected 2 operands G_*{EXT,TRUNC}");
1436 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1437 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1442 report(
"Generic extend/truncate can not operate on pointers",
MI);
1444 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1448 switch (
MI->getOpcode()) {
1450 if (DstSize <= SrcSize)
1451 report(
"Generic extend has destination type no larger than source",
MI);
1453 case TargetOpcode::G_TRUNC:
1454 case TargetOpcode::G_TRUNC_SSAT_S:
1455 case TargetOpcode::G_TRUNC_SSAT_U:
1456 case TargetOpcode::G_TRUNC_USAT_U:
1457 case TargetOpcode::G_FPTRUNC:
1458 if (DstSize >= SrcSize)
1459 report(
"Generic truncate has destination type no smaller than source",
1465 case TargetOpcode::G_SELECT: {
1466 LLT SelTy =
MRI->getType(
MI->getOperand(0).getReg());
1467 LLT CondTy =
MRI->getType(
MI->getOperand(1).getReg());
1473 verifyVectorElementMatch(SelTy, CondTy,
MI);
1476 case TargetOpcode::G_MERGE_VALUES: {
1481 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1482 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1484 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1486 const unsigned NumOps =
MI->getNumOperands();
1488 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1490 for (
unsigned I = 2;
I !=
NumOps; ++
I) {
1491 if (
MRI->getType(
MI->getOperand(
I).getReg()) != SrcTy)
1492 report(
"G_MERGE_VALUES source types do not match",
MI);
1497 case TargetOpcode::G_UNMERGE_VALUES: {
1498 unsigned NumDsts =
MI->getNumOperands() - 1;
1499 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1500 for (
unsigned i = 1; i < NumDsts; ++i) {
1501 if (
MRI->getType(
MI->getOperand(i).getReg()) != DstTy) {
1502 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1507 LLT SrcTy =
MRI->getType(
MI->getOperand(NumDsts).getReg());
1515 report(
"G_UNMERGE_VALUES source operand does not match vector "
1516 "destination operands",
1523 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1524 "destination operands",
1529 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1530 "destination operands",
1536 case TargetOpcode::G_BUILD_VECTOR: {
1539 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1540 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1542 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1547 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1550 report(
"G_BUILD_VECTOR must have an operand for each element",
MI);
1553 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1554 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1558 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1561 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1562 LLT SrcEltTy =
MRI->getType(
MI->getOperand(1).getReg());
1564 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1567 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1568 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1571 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1576 case TargetOpcode::G_CONCAT_VECTORS: {
1579 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1580 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1582 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1585 if (
MI->getNumOperands() < 3)
1586 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1589 if (
MRI->getType(
MI->getOperand(1).getReg()) !=
MRI->getType(MO.
getReg()))
1590 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1593 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1596 case TargetOpcode::G_ICMP:
1597 case TargetOpcode::G_FCMP: {
1598 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1599 LLT SrcTy =
MRI->getType(
MI->getOperand(2).getReg());
1604 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1608 case TargetOpcode::G_SCMP:
1609 case TargetOpcode::G_UCMP: {
1610 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1611 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1614 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1619 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1624 report(
"Result type must be at least 2 bits wide",
MI);
1631 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1637 case TargetOpcode::G_EXTRACT: {
1639 if (!
SrcOp.isReg()) {
1640 report(
"extract source must be a register",
MI);
1646 report(
"extract offset must be a constant",
MI);
1650 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1652 if (SrcSize == DstSize)
1653 report(
"extract source must be larger than result",
MI);
1655 if (DstSize +
OffsetOp.getImm() > SrcSize)
1656 report(
"extract reads past end of register",
MI);
1659 case TargetOpcode::G_INSERT: {
1661 if (!
SrcOp.isReg()) {
1662 report(
"insert source must be a register",
MI);
1668 report(
"insert offset must be a constant",
MI);
1672 unsigned DstSize =
MRI->getType(
MI->getOperand(0).getReg()).getSizeInBits();
1675 if (DstSize <= SrcSize)
1676 report(
"inserted size must be smaller than total register",
MI);
1678 if (SrcSize +
OffsetOp.getImm() > DstSize)
1679 report(
"insert writes past end of register",
MI);
1683 case TargetOpcode::G_JUMP_TABLE: {
1684 if (!
MI->getOperand(1).isJTI())
1685 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1686 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1688 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1691 case TargetOpcode::G_BRJT: {
1692 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
1693 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1695 if (!
MI->getOperand(1).isJTI())
1696 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1698 const auto &IdxOp =
MI->getOperand(2);
1699 if (!IdxOp.isReg() ||
MRI->getType(IdxOp.getReg()).isPointer())
1700 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1703 case TargetOpcode::G_INTRINSIC:
1704 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1705 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1706 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1711 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1715 if (!verifyGIntrinsicSideEffects(
MI))
1717 if (!verifyGIntrinsicConvergence(
MI))
1722 case TargetOpcode::G_SEXT_INREG: {
1723 if (!
MI->getOperand(2).isImm()) {
1724 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1728 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1729 int64_t
Imm =
MI->getOperand(2).getImm();
1731 report(
"G_SEXT_INREG size must be >= 1",
MI);
1733 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1736 case TargetOpcode::G_BSWAP: {
1737 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1739 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1742 case TargetOpcode::G_VSCALE: {
1743 if (!
MI->getOperand(1).isCImm()) {
1744 report(
"G_VSCALE operand must be cimm",
MI);
1747 if (
MI->getOperand(1).getCImm()->isZero()) {
1748 report(
"G_VSCALE immediate cannot be zero",
MI);
1753 case TargetOpcode::G_STEP_VECTOR: {
1754 if (!
MI->getOperand(1).isCImm()) {
1755 report(
"operand must be cimm",
MI);
1759 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1760 report(
"step must be > 0",
MI);
1764 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1766 report(
"Destination type must be a scalable vector",
MI);
1772 report(
"Destination element type must be scalar",
MI);
1776 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1778 report(
"step bitwidth differs from result type element bitwidth",
MI);
1783 case TargetOpcode::G_INSERT_SUBVECTOR: {
1785 if (!Src0Op.
isReg()) {
1786 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1791 if (!Src1Op.
isReg()) {
1792 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1797 if (!IndexOp.
isImm()) {
1798 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1802 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1806 report(
"Destination type must be a vector",
MI);
1811 report(
"Second source must be a vector",
MI);
1816 report(
"Element type of vectors must be the same",
MI);
1821 report(
"Vector types must both be fixed or both be scalable",
MI);
1827 report(
"Second source must be smaller than destination vector",
MI);
1831 uint64_t Idx = IndexOp.
getImm();
1833 if (IndexOp.
getImm() % Src1MinLen != 0) {
1834 report(
"Index must be a multiple of the second source vector's "
1835 "minimum vector length",
1841 if (Idx >= DstMinLen || Idx + Src1MinLen > DstMinLen) {
1842 report(
"Subvector type and index must not cause insert to overrun the "
1843 "vector being inserted into",
1850 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1852 if (!
SrcOp.isReg()) {
1853 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1858 if (!IndexOp.
isImm()) {
1859 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1863 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1867 report(
"Destination type must be a vector",
MI);
1872 report(
"Source must be a vector",
MI);
1877 report(
"Element type of vectors must be the same",
MI);
1882 report(
"Vector types must both be fixed or both be scalable",
MI);
1888 report(
"Destination vector must be smaller than source vector",
MI);
1892 uint64_t Idx = IndexOp.
getImm();
1894 if (Idx % DstMinLen != 0) {
1895 report(
"Index must be a multiple of the destination vector's minimum "
1902 if (Idx >= SrcMinLen || Idx + DstMinLen > SrcMinLen) {
1903 report(
"Destination type and index must not cause extract to overrun the "
1911 case TargetOpcode::G_SHUFFLE_VECTOR: {
1914 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1918 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1919 LLT Src0Ty =
MRI->getType(
MI->getOperand(1).getReg());
1920 LLT Src1Ty =
MRI->getType(
MI->getOperand(2).getReg());
1922 if (Src0Ty != Src1Ty)
1923 report(
"Source operands must be the same type",
MI);
1926 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1930 report(
"G_SHUFFLE_VECTOR must have vector src",
MI);
1934 report(
"G_SHUFFLE_VECTOR must have vector dst",
MI);
1945 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1946 report(
"Wrong result type for shufflemask",
MI);
1948 for (
int Idx : MaskIdxes) {
1952 if (Idx >= 2 * SrcNumElts)
1953 report(
"Out of bounds shuffle index",
MI);
1959 case TargetOpcode::G_SPLAT_VECTOR: {
1960 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1961 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1964 report(
"Destination type must be a scalable vector",
MI);
1969 report(
"Source type must be a scalar or pointer",
MI);
1975 report(
"Element type of the destination must be the same size or smaller "
1976 "than the source type",
1983 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1984 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
1985 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
1986 LLT IdxTy =
MRI->getType(
MI->getOperand(2).getReg());
1989 report(
"Destination type must be a scalar or pointer",
MI);
1994 report(
"First source must be a vector",
MI);
1998 auto TLI = MF->getSubtarget().getTargetLowering();
1999 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2000 report(
"Index type must match VectorIdxTy",
MI);
2006 case TargetOpcode::G_INSERT_VECTOR_ELT: {
2007 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2008 LLT VecTy =
MRI->getType(
MI->getOperand(1).getReg());
2009 LLT ScaTy =
MRI->getType(
MI->getOperand(2).getReg());
2010 LLT IdxTy =
MRI->getType(
MI->getOperand(3).getReg());
2013 report(
"Destination type must be a vector",
MI);
2017 if (VecTy != DstTy) {
2018 report(
"Destination type and vector type must match",
MI);
2023 report(
"Inserted element must be a scalar or pointer",
MI);
2027 auto TLI = MF->getSubtarget().getTargetLowering();
2028 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2029 report(
"Index type must match VectorIdxTy",
MI);
2035 case TargetOpcode::G_DYN_STACKALLOC: {
2041 report(
"dst operand 0 must be a pointer type",
MI);
2045 if (!AllocOp.
isReg() || !
MRI->getType(AllocOp.
getReg()).isScalar()) {
2046 report(
"src operand 1 must be a scalar reg type",
MI);
2050 if (!AlignOp.
isImm()) {
2051 report(
"src operand 2 must be an immediate type",
MI);
2056 case TargetOpcode::G_MEMCPY_INLINE:
2057 case TargetOpcode::G_MEMCPY:
2058 case TargetOpcode::G_MEMMOVE: {
2060 if (MMOs.
size() != 2) {
2061 report(
"memcpy/memmove must have 2 memory operands",
MI);
2067 report(
"wrong memory operand types",
MI);
2072 report(
"inconsistent memory operand sizes",
MI);
2074 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2075 LLT SrcPtrTy =
MRI->getType(
MI->getOperand(1).getReg());
2078 report(
"memory instruction operand must be a pointer",
MI);
2083 report(
"inconsistent store address space",
MI);
2085 report(
"inconsistent load address space",
MI);
2087 if (
Opc != TargetOpcode::G_MEMCPY_INLINE)
2088 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2089 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2093 case TargetOpcode::G_BZERO:
2094 case TargetOpcode::G_MEMSET: {
2096 std::string
Name =
Opc == TargetOpcode::G_MEMSET ?
"memset" :
"bzero";
2097 if (MMOs.
size() != 1) {
2098 report(
Twine(Name,
" must have 1 memory operand"),
MI);
2103 report(
Twine(Name,
" memory operand must be a store"),
MI);
2107 LLT DstPtrTy =
MRI->getType(
MI->getOperand(0).getReg());
2109 report(
Twine(Name,
" operand must be a pointer"),
MI);
2114 report(
"inconsistent " +
Twine(Name,
" address space"),
MI);
2116 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2117 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2118 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2122 case TargetOpcode::G_UBSANTRAP: {
2124 if (!
MI->getOperand(0).isImm()) {
2125 report(
"Crash kind must be an immediate", &KindOp, 0);
2128 int64_t
Kind =
MI->getOperand(0).getImm();
2130 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2133 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2134 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2135 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2136 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2137 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2139 report(
"Vector reduction requires a scalar destination type",
MI);
2141 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2143 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2146 case TargetOpcode::G_VECREDUCE_FADD:
2147 case TargetOpcode::G_VECREDUCE_FMUL:
2148 case TargetOpcode::G_VECREDUCE_FMAX:
2149 case TargetOpcode::G_VECREDUCE_FMIN:
2150 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2151 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2152 case TargetOpcode::G_VECREDUCE_ADD:
2153 case TargetOpcode::G_VECREDUCE_MUL:
2154 case TargetOpcode::G_VECREDUCE_AND:
2155 case TargetOpcode::G_VECREDUCE_OR:
2156 case TargetOpcode::G_VECREDUCE_XOR:
2157 case TargetOpcode::G_VECREDUCE_SMAX:
2158 case TargetOpcode::G_VECREDUCE_SMIN:
2159 case TargetOpcode::G_VECREDUCE_UMAX:
2160 case TargetOpcode::G_VECREDUCE_UMIN: {
2161 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2163 report(
"Vector reduction requires a scalar destination type",
MI);
2167 case TargetOpcode::G_SBFX:
2168 case TargetOpcode::G_UBFX: {
2169 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2171 report(
"Bitfield extraction is not supported on vectors",
MI);
2176 case TargetOpcode::G_SHL:
2177 case TargetOpcode::G_LSHR:
2178 case TargetOpcode::G_ASHR:
2179 case TargetOpcode::G_ROTR:
2180 case TargetOpcode::G_ROTL: {
2181 LLT Src1Ty =
MRI->getType(
MI->getOperand(1).getReg());
2182 LLT Src2Ty =
MRI->getType(
MI->getOperand(2).getReg());
2184 report(
"Shifts and rotates require operands to be either all scalars or "
2191 case TargetOpcode::G_LLROUND:
2192 case TargetOpcode::G_LROUND: {
2193 LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2194 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2199 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2201 verifyAllRegOpsScalar(*
MI, *
MRI);
2204 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2209 case TargetOpcode::G_IS_FPCLASS: {
2210 LLT DestTy =
MRI->getType(
MI->getOperand(0).getReg());
2213 report(
"Destination must be a scalar or vector of scalars",
MI);
2216 LLT SrcTy =
MRI->getType(
MI->getOperand(1).getReg());
2219 report(
"Source must be a scalar or vector of scalars",
MI);
2222 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2225 if (!TestMO.
isImm()) {
2226 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2231 report(
"Incorrect floating-point class set (operand 2)",
MI);
2236 case TargetOpcode::G_PREFETCH: {
2238 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer()) {
2239 report(
"addr operand must be a pointer", &AddrOp, 0);
2243 if (!RWOp.
isImm() || (uint64_t)RWOp.
getImm() >= 2) {
2244 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2248 if (!LocalityOp.
isImm() || (uint64_t)LocalityOp.
getImm() >= 4) {
2249 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2253 if (!CacheTypeOp.
isImm() || (uint64_t)CacheTypeOp.
getImm() >= 2) {
2254 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2259 case TargetOpcode::G_ASSERT_ALIGN: {
2260 if (
MI->getOperand(2).getImm() < 1)
2261 report(
"alignment immediate must be >= 1",
MI);
2264 case TargetOpcode::G_CONSTANT_POOL: {
2265 if (!
MI->getOperand(1).isCPI())
2266 report(
"Src operand 1 must be a constant pool index",
MI);
2267 if (!
MRI->getType(
MI->getOperand(0).getReg()).isPointer())
2268 report(
"Dst operand 0 must be a pointer",
MI);
2271 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2273 if (!AddrOp.
isReg() || !
MRI->getType(AddrOp.
getReg()).isPointer())
2274 report(
"addr operand must be a pointer", &AddrOp, 1);
2277 case TargetOpcode::G_SMIN:
2278 case TargetOpcode::G_SMAX:
2279 case TargetOpcode::G_UMIN:
2280 case TargetOpcode::G_UMAX: {
2281 const LLT DstTy =
MRI->getType(
MI->getOperand(0).getReg());
2283 report(
"Generic smin/smax/umin/umax does not support pointer operands",
2292void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2294 if (
MI->getNumOperands() <
MCID.getNumOperands()) {
2295 report(
"Too few operands",
MI);
2296 OS <<
MCID.getNumOperands() <<
" operands expected, but "
2297 <<
MI->getNumOperands() <<
" given.\n";
2301 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2304 if (MF->getProperties().hasNoPHIs())
2305 report(
"Found PHI instruction with NoPHIs property set",
MI);
2308 report(
"Found PHI instruction after non-PHI",
MI);
2309 }
else if (FirstNonPHI ==
nullptr)
2313 if (
MI->isInlineAsm())
2314 verifyInlineAsm(
MI);
2317 if (
TII->isUnspillableTerminator(
MI)) {
2318 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2319 report(
"Unspillable Terminator does not define a reg",
MI);
2321 if (
Def.isVirtual() && !MF->getProperties().hasNoPHIs() &&
2322 std::distance(
MRI->use_nodbg_begin(Def),
MRI->use_nodbg_end()) > 1)
2323 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2329 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2330 if (!
MI->getDebugLoc())
2331 report(
"Missing DebugLoc for debug instruction",
MI);
2335 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2336 report(
"Metadata instruction should not have a value tracking number",
MI);
2340 if (
Op->isLoad() && !
MI->mayLoad())
2341 report(
"Missing mayLoad flag",
MI);
2342 if (
Op->isStore() && !
MI->mayStore())
2343 report(
"Missing mayStore flag",
MI);
2349 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2350 if (
MI->isDebugOrPseudoInstr()) {
2352 report(
"Debug instruction has a slot index",
MI);
2353 }
else if (
MI->isInsideBundle()) {
2355 report(
"Instruction inside bundle has a slot index",
MI);
2358 report(
"Missing slot index",
MI);
2362 unsigned Opc =
MCID.getOpcode();
2364 verifyPreISelGenericInstruction(
MI);
2373 switch (
MI->getOpcode()) {
2374 case TargetOpcode::COPY: {
2380 LLT DstTy =
MRI->getType(DstReg);
2381 LLT SrcTy =
MRI->getType(SrcReg);
2384 if (SrcTy != DstTy) {
2385 report(
"Copy Instruction is illegal with mismatching types",
MI);
2386 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2401 TRI->getMinimalPhysRegClassLLT(SrcReg, DstTy);
2403 SrcSize =
TRI->getRegSizeInBits(SrcReg, *
MRI);
2405 SrcSize =
TRI->getRegSizeInBits(SrcReg, *
MRI);
2410 TRI->getMinimalPhysRegClassLLT(DstReg, SrcTy);
2412 DstSize =
TRI->getRegSizeInBits(DstReg, *
MRI);
2414 DstSize =
TRI->getRegSizeInBits(DstReg, *
MRI);
2432 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2433 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2434 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2439 case TargetOpcode::COPY_LANEMASK: {
2447 if (
DstOp.getSubReg())
2448 report(
"COPY_LANEMASK must not use a subregister index", &
DstOp, 0);
2450 if (
SrcOp.getSubReg())
2451 report(
"COPY_LANEMASK must not use a subregister index", &
SrcOp, 1);
2453 if (LaneMask.
none())
2454 report(
"COPY_LANEMASK must read at least one lane",
MI);
2461 SrcMaxLaneMask =
MRI->getMaxLaneMaskForVReg(SrcReg);
2466 if (SrcMaxLaneMask == LaneMask)
2467 report(
"COPY_LANEMASK cannot be used to do full copy",
MI);
2472 if (SrcMaxLaneMask < LaneMask)
2473 report(
"COPY_LANEMASK attempts to read from the lanes that "
2474 "don't exist in the source register",
2479 case TargetOpcode::STATEPOINT: {
2481 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2482 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2483 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2484 report(
"meta operands to STATEPOINT not constant!",
MI);
2488 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2489 if (
Offset >=
MI->getNumOperands()) {
2490 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2493 if (!
MI->getOperand(
Offset - 1).isImm() ||
2494 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2496 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2498 VerifyStackMapConstant(SO.getCCIdx());
2499 VerifyStackMapConstant(SO.getFlagsIdx());
2500 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2501 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2502 VerifyStackMapConstant(SO.getNumAllocaIdx());
2503 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2507 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2508 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2509 for (
unsigned Idx = 0; Idx <
MI->getNumDefs(); Idx++) {
2511 if (!
MI->isRegTiedToUseOperand(Idx, &UseOpIdx)) {
2512 report(
"STATEPOINT defs expected to be tied",
MI);
2515 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2516 report(
"STATEPOINT def tied to non-gc operand",
MI);
2523 case TargetOpcode::INSERT_SUBREG: {
2524 unsigned InsertedSize;
2525 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2526 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2528 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *
MRI);
2529 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2530 if (SubRegSize < InsertedSize) {
2531 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2532 "size than the subreg it was inserted into",
MI);
2536 case TargetOpcode::REG_SEQUENCE: {
2537 unsigned NumOps =
MI->getNumOperands();
2539 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2543 for (
unsigned I = 1;
I !=
NumOps;
I += 2) {
2548 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2550 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2551 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2552 report(
"Invalid subregister index operand for REG_SEQUENCE",
2557 Register DstReg =
MI->getOperand(0).getReg();
2559 report(
"REG_SEQUENCE does not support physical register results",
MI);
2561 if (
MI->getOperand(0).getSubReg())
2562 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2570MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2573 unsigned NumDefs =
MCID.getNumDefs();
2574 if (
MCID.getOpcode() == TargetOpcode::PATCHPOINT)
2575 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2578 if (MONum < NumDefs) {
2581 report(
"Explicit definition must be a register", MO, MONum);
2582 else if (!MO->
isDef() && !
MCOI.isOptionalDef())
2583 report(
"Explicit definition marked as use", MO, MONum);
2585 report(
"Explicit definition marked as implicit", MO, MONum);
2586 }
else if (MONum <
MCID.getNumOperands()) {
2590 bool IsOptional =
MI->isVariadic() && MONum ==
MCID.getNumOperands() - 1;
2593 if (MO->
isDef() && !
MCOI.isOptionalDef() && !
MCID.variadicOpsAreDefs())
2594 report(
"Explicit operand marked as def", MO, MONum);
2596 report(
"Explicit operand marked as implicit", MO, MONum);
2602 report(
"Expected a register operand.", MO, MONum);
2606 !
TII->isPCRelRegisterOperandLegal(*MO)))
2607 report(
"Expected a non-register operand.", MO, MONum);
2614 report(
"Tied use must be a register", MO, MONum);
2616 report(
"Operand should be tied", MO, MONum);
2617 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2618 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2621 if (!MOTied.
isReg())
2622 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2625 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2628 report(
"Explicit operand should not be tied", MO, MONum);
2629 }
else if (!
MI->isVariadic()) {
2632 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2638 report(
"Early clobber must be a register",
MI);
2640 report(
"Missing earlyClobber flag",
MI);
2647 if (
MI->isDebugInstr() && MO->
isUse()) {
2649 report(
"Register operand must be marked debug", MO, MONum);
2651 report(
"Register operand must not be marked debug", MO, MONum);
2657 if (
MRI->tracksLiveness() && !
MI->isDebugInstr())
2658 checkLiveness(MO, MONum);
2662 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2666 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2668 if (!OtherMO.
isReg())
2669 report(
"Must be tied to a register", MO, MONum);
2671 report(
"Missing tie flags on tied operand", MO, MONum);
2672 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2673 report(
"Inconsistent tie links", MO, MONum);
2674 if (MONum <
MCID.getNumDefs()) {
2675 if (OtherIdx <
MCID.getNumOperands()) {
2677 report(
"Explicit def tied to explicit use without tie constraint",
2681 report(
"Explicit def should be tied to implicit use", MO, MONum);
2694 if (MF->getProperties().hasTiedOpsRewritten() && MO->
isUse() &&
2695 MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2696 Reg !=
MI->getOperand(DefIdx).getReg())
2697 report(
"Two-address instruction operands must be identical", MO, MONum);
2704 report(
"Illegal subregister index for physical register", MO, MONum);
2707 if (MONum <
MCID.getNumOperands()) {
2709 if (!DRC->contains(
Reg)) {
2710 report(
"Illegal physical register for instruction", MO, MONum);
2712 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2717 if (
MRI->isReserved(
Reg)) {
2718 report(
"isRenamable set on reserved register", MO, MONum);
2735 report(
"Generic virtual register use cannot be undef", MO, MONum);
2742 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2743 !
MI->isDebugValue() || !
MRI->def_empty(
Reg)) {
2745 if (isFunctionSelected) {
2746 report(
"Generic virtual register invalid in a Selected function",
2754 report(
"Generic virtual register must have a valid type", MO,
2763 if (!RegBank && isFunctionRegBankSelected) {
2764 report(
"Generic virtual register must have a bank in a "
2765 "RegBankSelected function",
2773 report(
"Register bank is too small for virtual register", MO,
2775 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2783 report(
"Generic virtual register does not allow subregister index", MO,
2792 MONum <
MCID.getNumOperands() &&
TII->getRegClass(
MCID, MONum)) {
2793 report(
"Virtual register does not match instruction constraint", MO,
2795 OS <<
"Expect register class "
2796 <<
TRI->getRegClassName(
TII->getRegClass(
MCID, MONum))
2797 <<
" but got nothing\n";
2805 TRI->getSubClassWithSubReg(RC, SubIdx);
2807 report(
"Invalid subregister index for virtual register", MO, MONum);
2808 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2809 <<
" does not support subreg index "
2810 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2814 report(
"Invalid register class for subregister index", MO, MONum);
2815 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2816 <<
" does not fully support subreg index "
2817 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2821 if (MONum <
MCID.getNumOperands()) {
2825 TRI->getLargestLegalSuperClass(RC, *MF);
2827 report(
"No largest legal super class exists.", MO, MONum);
2830 DRC =
TRI->getMatchingSuperRegClass(SuperRC, DRC, SubIdx);
2832 report(
"No matching super-reg register class.", MO, MONum);
2837 report(
"Illegal virtual register for instruction", MO, MONum);
2838 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2839 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2854 report(
"PHI operand is not in the CFG", MO, MONum);
2858 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2859 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2862 SlotIndex Idx = LiveInts->getInstructionIndex(*
MI);
2870 for (
auto *MMO :
MI->memoperands()) {
2872 if (PSV ==
nullptr)
continue;
2875 if (
Value ==
nullptr)
continue;
2876 if (
Value->getFrameIndex() != FI)
continue;
2885 report(
"Missing fixed stack memoperand.",
MI);
2888 report(
"Instruction loads from dead spill slot", MO, MONum);
2889 OS <<
"Live stack: " << LI <<
'\n';
2892 report(
"Instruction stores to dead spill slot", MO, MONum);
2893 OS <<
"Live stack: " << LI <<
'\n';
2899 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2900 report(
"CFI instruction has invalid index", MO, MONum);
2908void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2916 report(
"invalid live range", MO, MONum);
2917 report_context_liverange(LR);
2918 report_context_vreg_regunit(VRegOrUnit);
2919 report_context(UseIdx);
2928 report(
"No live segment at use", MO, MONum);
2929 report_context_liverange(LR);
2930 report_context_vreg_regunit(VRegOrUnit);
2931 report_context(UseIdx);
2934 report(
"Live range continues after kill flag", MO, MONum);
2935 report_context_liverange(LR);
2936 report_context_vreg_regunit(VRegOrUnit);
2938 report_context_lanemask(LaneMask);
2939 report_context(UseIdx);
2943void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2950 report(
"invalid live range", MO, MONum);
2951 report_context_liverange(LR);
2952 report_context_vreg_regunit(VRegOrUnit);
2954 report_context_lanemask(LaneMask);
2955 report_context(DefIdx);
2967 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
2969 (VNI->def != DefIdx &&
2970 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
2971 report(
"Inconsistent valno->def", MO, MONum);
2972 report_context_liverange(LR);
2973 report_context_vreg_regunit(VRegOrUnit);
2975 report_context_lanemask(LaneMask);
2976 report_context(*VNI);
2977 report_context(DefIdx);
2980 report(
"No live segment at def", MO, MONum);
2981 report_context_liverange(LR);
2982 report_context_vreg_regunit(VRegOrUnit);
2984 report_context_lanemask(LaneMask);
2985 report_context(DefIdx);
2997 if (SubRangeCheck || MO->
getSubReg() == 0) {
2998 report(
"Live range continues after dead def flag", MO, MONum);
2999 report_context_liverange(LR);
3000 report_context_vreg_regunit(VRegOrUnit);
3002 report_context_lanemask(LaneMask);
3008void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
3011 const unsigned SubRegIdx = MO->
getSubReg();
3015 if (LiveInts->hasInterval(
Reg)) {
3016 LI = &LiveInts->getInterval(
Reg);
3019 report(
"Live interval for subreg operand has no subranges", MO, MONum);
3021 report(
"Virtual register has no live interval", MO, MONum);
3028 addRegWithSubRegs(regsKilled,
Reg);
3034 !
MI->isBundledWithPred()) {
3037 report(
"Kill missing from LiveVariables", MO, MONum);
3041 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3045 UseIdx = LiveInts->getMBBEndIdx(
3046 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
3048 UseIdx = LiveInts->getInstructionIndex(*
MI);
3053 if (
MRI->isReservedRegUnit(Unit))
3055 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3056 checkLivenessAtUse(MO, MONum, UseIdx, *LR,
VirtRegOrUnit(Unit));
3066 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3067 :
MRI->getMaxLaneMaskForVReg(
Reg);
3070 if ((MOMask & SR.LaneMask).none())
3076 LiveInMask |= SR.LaneMask;
3079 if ((LiveInMask & MOMask).
none()) {
3080 report(
"No live subrange at use", MO, MONum);
3081 report_context(*LI);
3082 report_context(UseIdx);
3085 if (
MI->isPHI() && LiveInMask != MOMask) {
3086 report(
"Not all lanes of PHI source live at use", MO, MONum);
3087 report_context(*LI);
3088 report_context(UseIdx);
3095 if (!regsLive.count(
Reg)) {
3098 bool Bad = !isReserved(
Reg);
3103 if (regsLive.count(
SubReg)) {
3115 if (!MOP.isReg() || !MOP.isImplicit())
3118 if (!MOP.getReg().isPhysical())
3121 if (MOP.getReg() !=
Reg &&
3122 all_of(
TRI->regunits(
Reg), [&](
const MCRegUnit RegUnit) {
3123 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3130 report(
"Using an undefined physical register", MO, MONum);
3131 }
else if (
MRI->def_empty(
Reg)) {
3132 report(
"Reading virtual register without a def", MO, MONum);
3134 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3138 if (MInfo.regsKilled.count(
Reg))
3139 report(
"Using a killed virtual register", MO, MONum);
3140 else if (!
MI->isPHI())
3141 MInfo.vregsLiveIn.insert(std::make_pair(
Reg,
MI));
3150 addRegWithSubRegs(regsDead,
Reg);
3152 addRegWithSubRegs(regsDefined,
Reg);
3156 std::next(
MRI->def_begin(
Reg)) !=
MRI->def_end())
3157 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3160 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3161 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3169 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3170 :
MRI->getMaxLaneMaskForVReg(
Reg);
3172 if ((SR.LaneMask & MOMask).none())
3187void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3188 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3189 set_union(MInfo.regsKilled, regsKilled);
3190 set_subtract(regsLive, regsKilled); regsKilled.clear();
3192 while (!regMasks.empty()) {
3193 const uint32_t *
Mask = regMasks.pop_back_val();
3197 regsDead.push_back(
Reg);
3200 set_union(regsLive, regsDefined); regsDefined.clear();
3205 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3210 if (!(stop > lastIndex)) {
3211 report(
"Block ends before last instruction index",
MBB);
3212 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3228 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3230 filterAndAdd(FromRegSet, VRegsBuffer);
3235 template <
typename RegSetT>
3236 bool filterAndAdd(
const RegSetT &FromRegSet,
3237 SmallVectorImpl<Register> &ToVRegs) {
3238 unsigned SparseUniverse = Sparse.size();
3239 unsigned NewSparseUniverse = SparseUniverse;
3240 unsigned NewDenseSize =
Dense.size();
3241 size_t Begin = ToVRegs.
size();
3246 if (Index < SparseUniverseMax) {
3247 if (Index < SparseUniverse && Sparse.test(Index))
3249 NewSparseUniverse = std::max(NewSparseUniverse, Index + 1);
3257 size_t End = ToVRegs.
size();
3264 Sparse.resize(NewSparseUniverse);
3265 Dense.reserve(NewDenseSize);
3266 for (
unsigned I = Begin;
I < End; ++
I) {
3269 if (Index < SparseUniverseMax)
3278 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3289 DenseSet<Register>
Dense;
3298class FilteringVRegSet {
3305 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3310 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3313 return Filter.filterAndAdd(RS, VRegs);
3315 using const_iterator =
decltype(VRegs)::const_iterator;
3316 const_iterator
begin()
const {
return VRegs.
begin(); }
3317 const_iterator
end()
const {
return VRegs.
end(); }
3318 size_t size()
const {
return VRegs.
size(); }
3325void MachineVerifier::calcRegsPassed() {
3332 FilteringVRegSet VRegs;
3333 BBInfo &
Info = MBBInfoMap[MB];
3336 VRegs.addToFilter(
Info.regsKilled);
3337 VRegs.addToFilter(
Info.regsLiveOut);
3339 const BBInfo &PredInfo = MBBInfoMap[Pred];
3340 if (!PredInfo.reachable)
3343 VRegs.add(PredInfo.regsLiveOut);
3344 VRegs.add(PredInfo.vregsPassed);
3346 Info.vregsPassed.reserve(VRegs.size());
3347 Info.vregsPassed.insert_range(VRegs);
3354void MachineVerifier::calcRegsRequired() {
3357 for (
const auto &
MBB : *MF) {
3358 BBInfo &MInfo = MBBInfoMap[&
MBB];
3360 BBInfo &PInfo = MBBInfoMap[Pred];
3361 if (PInfo.addRequired(MInfo.vregsLiveIn))
3367 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3369 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3376 BBInfo &PInfo = MBBInfoMap[Pred];
3377 if (PInfo.addRequired(
Reg))
3385 while (!todo.
empty()) {
3388 BBInfo &MInfo = MBBInfoMap[
MBB];
3392 BBInfo &SInfo = MBBInfoMap[Pred];
3393 if (SInfo.addRequired(MInfo.vregsRequired))
3402 BBInfo &MInfo = MBBInfoMap[&
MBB];
3412 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3417 report(
"Unexpected flag on PHI operand", &MODef, 0);
3420 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3422 for (
unsigned I = 1,
E =
Phi.getNumOperands();
I !=
E;
I += 2) {
3425 report(
"Expected PHI operand to be a register", &MO0,
I);
3430 report(
"Unexpected flag on PHI operand", &MO0,
I);
3434 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3440 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3444 if (MInfo.reachable) {
3446 BBInfo &PrInfo = MBBInfoMap[&Pre];
3447 if (!MO0.
isUndef() && PrInfo.reachable &&
3448 !PrInfo.isLiveOut(MO0.
getReg()))
3449 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3454 if (MInfo.reachable) {
3456 if (!seen.
count(Pred)) {
3457 report(
"Missing PHI operand", &Phi);
3459 <<
" is a predecessor according to the CFG.\n";
3468 std::function<
void(
const Twine &Message)> FailureCB,
3473 for (
const auto &
MBB : MF) {
3475 for (
const auto &
MI :
MBB.instrs())
3485void MachineVerifier::visitMachineFunctionAfter() {
3486 auto FailureCB = [
this](
const Twine &Message) {
3487 report(Message.str().c_str(), MF);
3500 for (
const auto &
MBB : *MF) {
3501 BBInfo &MInfo = MBBInfoMap[&
MBB];
3502 for (
Register VReg : MInfo.vregsRequired)
3503 if (MInfo.regsKilled.count(VReg)) {
3504 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3505 OS <<
"Virtual register " <<
printReg(VReg)
3506 <<
" is used after the block.\n";
3511 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3512 for (
Register VReg : MInfo.vregsRequired) {
3513 report(
"Virtual register defs don't dominate all uses.", MF);
3514 report_context_vreg(VReg);
3519 verifyLiveVariables();
3521 verifyLiveIntervals();
3530 if (
MRI->tracksLiveness())
3531 for (
const auto &
MBB : *MF)
3535 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3538 BBInfo &PInfo = MBBInfoMap[Pred];
3539 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3540 report(
"Live in register not found to be live out from predecessor.",
3542 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3548 for (
auto CSInfo : MF->getCallSitesInfo())
3549 if (!CSInfo.first->isCall())
3550 report(
"Call site info referencing instruction that is not call", MF);
3554 if (MF->getFunction().getSubprogram()) {
3556 for (
const auto &
MBB : *MF) {
3557 for (
const auto &
MI :
MBB) {
3558 if (
auto Num =
MI.peekDebugInstrNum()) {
3561 report(
"Instruction has a duplicated value tracking number", &
MI);
3568void MachineVerifier::verifyLiveVariables() {
3569 assert(LiveVars &&
"Don't call verifyLiveVariables without LiveVars");
3570 for (
unsigned I = 0,
E =
MRI->getNumVirtRegs();
I !=
E; ++
I) {
3573 for (
const auto &
MBB : *MF) {
3574 BBInfo &MInfo = MBBInfoMap[&
MBB];
3577 if (MInfo.vregsRequired.count(
Reg)) {
3579 report(
"LiveVariables: Block missing from AliveBlocks", &
MBB);
3581 <<
" must be live through the block.\n";
3585 report(
"LiveVariables: Block should not be in AliveBlocks", &
MBB);
3587 <<
" is not needed live through the block.\n";
3594void MachineVerifier::verifyLiveIntervals() {
3595 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3596 for (
unsigned I = 0,
E =
MRI->getNumVirtRegs();
I !=
E; ++
I) {
3600 if (
MRI->reg_nodbg_empty(
Reg))
3603 if (!LiveInts->hasInterval(
Reg)) {
3604 report(
"Missing live interval for virtual register", MF);
3610 assert(
Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3611 verifyLiveInterval(LI);
3615 for (MCRegUnit Unit :
TRI->regunits())
3616 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3620void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3630 report(
"Value not live at VNInfo def and not marked unused", MF);
3631 report_context(LR, VRegOrUnit, LaneMask);
3632 report_context(*VNI);
3636 if (DefVNI != VNI) {
3637 report(
"Live segment at def has different VNInfo", MF);
3638 report_context(LR, VRegOrUnit, LaneMask);
3639 report_context(*VNI);
3645 report(
"Invalid VNInfo definition index", MF);
3646 report_context(LR, VRegOrUnit, LaneMask);
3647 report_context(*VNI);
3652 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3653 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3654 report_context(LR, VRegOrUnit, LaneMask);
3655 report_context(*VNI);
3663 report(
"No instruction at VNInfo def index",
MBB);
3664 report_context(LR, VRegOrUnit, LaneMask);
3665 report_context(*VNI);
3669 bool hasDef =
false;
3670 bool isEarlyClobber =
false;
3672 if (!MOI->isReg() || !MOI->isDef())
3678 if (!MOI->getReg().isPhysical() ||
3682 if (LaneMask.
any() &&
3683 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3686 if (MOI->isEarlyClobber())
3687 isEarlyClobber =
true;
3691 report(
"Defining instruction does not modify register",
MI);
3692 report_context(LR, VRegOrUnit, LaneMask);
3693 report_context(*VNI);
3698 if (isEarlyClobber) {
3700 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3701 report_context(LR, VRegOrUnit, LaneMask);
3702 report_context(*VNI);
3705 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3706 report_context(LR, VRegOrUnit, LaneMask);
3707 report_context(*VNI);
3711void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3717 assert(VNI &&
"Live segment has no valno");
3720 report(
"Foreign valno in live segment", MF);
3721 report_context(LR, VRegOrUnit, LaneMask);
3723 report_context(*VNI);
3727 report(
"Live segment valno is marked unused", MF);
3728 report_context(LR, VRegOrUnit, LaneMask);
3734 report(
"Bad start of live segment, no basic block", MF);
3735 report_context(LR, VRegOrUnit, LaneMask);
3741 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3742 report_context(LR, VRegOrUnit, LaneMask);
3749 report(
"Bad end of live segment, no basic block", MF);
3750 report_context(LR, VRegOrUnit, LaneMask);
3756 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3766 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3767 report_context(LR, VRegOrUnit, LaneMask);
3774 report(
"Live segment ends at B slot of an instruction", EndMBB);
3775 report_context(LR, VRegOrUnit, LaneMask);
3783 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3784 report_context(LR, VRegOrUnit, LaneMask);
3794 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3795 report(
"Live segment ending at early clobber slot must be "
3796 "redefined by an EC def in the same instruction",
3798 report_context(LR, VRegOrUnit, LaneMask);
3808 bool hasRead =
false;
3809 bool hasSubRegDef =
false;
3810 bool hasDeadDef =
false;
3812 if (!MOI->isReg() || MOI->getReg() != VRegOrUnit.
asVirtualReg())
3814 unsigned Sub = MOI->getSubReg();
3819 hasSubRegDef =
true;
3828 if (LaneMask.
any() && (LaneMask & SLM).none())
3830 if (MOI->readsReg())
3837 if (LaneMask.
none() && !hasDeadDef) {
3839 "Instruction ending live segment on dead slot has no dead flag",
3841 report_context(LR, VRegOrUnit, LaneMask);
3849 LaneMask.
any() || !hasSubRegDef) {
3850 report(
"Instruction ending live segment doesn't read the register",
3852 report_context(LR, VRegOrUnit, LaneMask);
3872 if (LaneMask.
any()) {
3878 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3881 if (&*MFI == EndMBB)
3889 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3893 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3895 if (MFI->isEHPad()) {
3898 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3909 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3912 report(
"Register not marked live out of predecessor", Pred);
3913 report_context(LR, VRegOrUnit, LaneMask);
3914 report_context(*VNI);
3916 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3922 if (!IsPHI && PVNI != VNI) {
3923 report(
"Different value live out of predecessor", Pred);
3924 report_context(LR, VRegOrUnit, LaneMask);
3925 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3928 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3931 if (&*MFI == EndMBB)
3937void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
3941 verifyLiveRangeValue(LR, VNI, VRegOrUnit, LaneMask);
3944 verifyLiveRangeSegment(LR,
I, VRegOrUnit, LaneMask);
3947void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3956 if ((Mask & SR.LaneMask).any()) {
3957 report(
"Lane masks of sub ranges overlap in live interval", MF);
3960 if ((SR.LaneMask & ~MaxMask).any()) {
3961 report(
"Subrange lanemask is invalid", MF);
3965 report(
"Subrange must not be empty", MF);
3968 Mask |= SR.LaneMask;
3971 report(
"A Subrange is not covered by the main range", MF);
3979 unsigned NumComp = ConEQ.Classify(LI);
3981 report(
"Multiple connected components in live interval", MF);
3983 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3984 OS << comp <<
": valnos";
3986 if (comp == ConEQ.getEqClass(
I))
3999struct StackStateOfBB {
4000 StackStateOfBB() =
default;
4001 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
4002 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
4003 ExitIsSetup(ExitSetup) {}
4008 bool EntryIsSetup =
false;
4009 bool ExitIsSetup =
false;
4017void MachineVerifier::verifyStackFrame() {
4018 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
4019 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
4020 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
4024 SPState.
resize(MF->getNumBlockIDs());
4031 DFI != DFE; ++DFI) {
4034 StackStateOfBB BBState;
4036 if (DFI.getPathLength() >= 2) {
4039 "DFS stack predecessor is already visited.\n");
4040 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
4041 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
4042 BBState.ExitValue = BBState.EntryValue;
4043 BBState.ExitIsSetup = BBState.EntryIsSetup;
4047 report(
"Call frame size on entry does not match value computed from "
4051 <<
" does not match value computed from predecessor "
4052 << -BBState.EntryValue <<
'\n';
4056 for (
const auto &
I : *
MBB) {
4057 if (
I.getOpcode() == FrameSetupOpcode) {
4058 if (BBState.ExitIsSetup)
4059 report(
"FrameSetup is after another FrameSetup", &
I);
4060 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
4061 report(
"AdjustsStack not set in presence of a frame pseudo "
4062 "instruction.", &
I);
4063 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
4064 BBState.ExitIsSetup =
true;
4067 if (
I.getOpcode() == FrameDestroyOpcode) {
4068 int Size =
TII->getFrameTotalSize(
I);
4069 if (!BBState.ExitIsSetup)
4070 report(
"FrameDestroy is not after a FrameSetup", &
I);
4071 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
4073 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
4074 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
4075 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
4076 << AbsSPAdj <<
">.\n";
4078 if (!
MRI->isSSA() && !MF->getFrameInfo().adjustsStack())
4079 report(
"AdjustsStack not set in presence of a frame pseudo "
4080 "instruction.", &
I);
4081 BBState.ExitValue +=
Size;
4082 BBState.ExitIsSetup =
false;
4090 if (Reachable.
count(Pred) &&
4091 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4092 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4093 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4095 << SPState[Pred->
getNumber()].ExitValue <<
", "
4096 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4098 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4105 if (Reachable.
count(Succ) &&
4106 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4107 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4108 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4110 << SPState[Succ->getNumber()].EntryValue <<
", "
4111 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4113 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4119 if (BBState.ExitIsSetup)
4120 report(
"A return block ends with a FrameSetup.",
MBB);
4121 if (BBState.ExitValue)
4122 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
4127void MachineVerifier::verifyStackProtector() {
4136 bool StackGrowsDown =
4163 if (SPStart < ObjEnd && ObjStart < SPEnd) {
4164 report(
"Stack protector overlaps with another stack object", MF);
4167 if ((StackGrowsDown && SPStart <= ObjStart) ||
4168 (!StackGrowsDown && SPStart >= ObjStart)) {
4169 report(
"Stack protector is not the top-most object on the stack", MF);
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isLoad(int Opcode)
static bool isStore(int Opcode)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file implements the BitVector class.
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
hexagon widen Hexagon Store false hexagon widen loads
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
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 if the block is well formed or null if the block is not well forme...
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.
A specialized PseudoSourceValue for holding FixedStack values, which must include a frame index.
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 bool isPointerVector() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
constexpr bool isPointerOrPointerVector() const
constexpr LLT getScalarType() const
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
LLVM_ABI void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
void print(raw_ostream &O, const Module *=nullptr) const override
Implement the dump method.
Result of a LiveRange query.
bool isDeadDef() const
Return true if this instruction has a dead def.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
VNInfo * valueOut() const
Return the value leaving the instruction, if any.
bool isKill() const
Return true if the live-in value is killed by this instruction.
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,...
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.
Special value supplied for machine level alias analysis.
Holds all the information related to register banks.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
This class implements the register bank concept.
const char * getName() const
Get a user friendly name of this register bank.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ 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.
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.