103 assert(
Reg.isPhysical() &&
"reg must be a physical register");
104 assert(Ty.isValid() &&
"expected a valid type");
107 if (
TRI.isTypeLegalForClass(*RC, Ty))
111 return RC.contains(Reg) && TRI.isTypeLegalForClass(RC, Ty);
115struct MachineVerifier {
117 raw_ostream *OS,
bool AbortOnError =
true)
118 : MFAM(&MFAM), OS(OS ? *OS :
nulls()), Banner(
b),
119 ReportedErrs(AbortOnError) {}
121 MachineVerifier(
Pass *
pass,
const char *b, raw_ostream *OS,
122 bool AbortOnError =
true)
123 : PASS(
pass), OS(OS ? *OS :
nulls()), Banner(
b),
124 ReportedErrs(AbortOnError) {}
126 MachineVerifier(
const char *b, LiveIntervals *LiveInts, LiveStacks *LiveStks,
127 SlotIndexes *Indexes, raw_ostream *OS,
128 bool AbortOnError =
true)
129 : OS(OS ? *OS :
nulls()), Banner(
b), LiveInts(LiveInts),
130 LiveStks(LiveStks), Indexes(Indexes), ReportedErrs(AbortOnError) {}
136 Pass *
const PASS =
nullptr;
140 const TargetMachine *TM =
nullptr;
141 const TargetInstrInfo *TII =
nullptr;
142 const TargetRegisterInfo *TRI =
nullptr;
143 const MachineRegisterInfo *MRI =
nullptr;
144 const RegisterBankInfo *RBI =
nullptr;
147 bool isFunctionRegBankSelected =
false;
148 bool isFunctionSelected =
false;
149 bool isFunctionTracksDebugUserValues =
false;
151 using RegVector = SmallVector<Register, 16>;
152 using RegMaskVector = SmallVector<const uint32_t *, 4>;
153 using RegSet = DenseSet<Register>;
154 using RegMap = DenseMap<Register, const MachineInstr *>;
155 using BlockSet = SmallPtrSet<const MachineBasicBlock *, 8>;
157 const MachineInstr *FirstNonPHI =
nullptr;
158 const MachineInstr *FirstTerminator =
nullptr;
159 BlockSet FunctionBlocks;
161 BitVector regsReserved;
163 RegVector regsDefined, regsDead, regsKilled;
164 RegMaskVector regMasks;
169 void addRegWithSubRegs(RegVector &RV,
Register Reg) {
177 bool reachable =
false;
198 RegSet vregsRequired;
210 if (regsLiveOut.count(
Reg))
216 bool addRequired(
const RegSet &RS) {
224 bool addRequired(
const RegMap &RM) {
226 for (
const auto &
I : RM)
233 return regsLiveOut.count(
Reg) || vregsPassed.count(
Reg);
238 DenseMap<const MachineBasicBlock *, BBInfo> MBBInfoMap;
241 return Reg.
id() < regsReserved.size() && regsReserved.test(
Reg.
id());
245 return Reg.
id() < TRI->getNumRegs() && TRI->isInAllocatableClass(
Reg) &&
246 !regsReserved.test(
Reg.
id());
250 LiveIntervals *LiveInts =
nullptr;
251 LiveStacks *LiveStks =
nullptr;
252 SlotIndexes *Indexes =
nullptr;
256 class ReportedErrors {
257 unsigned NumReported = 0;
262 ReportedErrors(
bool AbortOnError) : AbortOnError(AbortOnError) {}
269 " machine code errors.");
272 ReportedErrorsLock->unlock();
282 ReportedErrorsLock->lock();
284 return NumReported == 1;
288 bool hasError() {
return NumReported; }
290 ReportedErrors ReportedErrs;
295 MachineDominatorTree DT;
297 void visitMachineFunctionBefore();
298 void visitMachineBasicBlockBefore(
const MachineBasicBlock *
MBB);
299 void visitMachineBundleBefore(
const MachineInstr *
MI);
304 bool verifyAllRegOpsScalar(
const MachineInstr &
MI,
305 const MachineRegisterInfo &MRI);
306 bool verifyVectorElementMatch(LLT Ty0, LLT Ty1,
const MachineInstr *
MI);
308 bool verifyGIntrinsicSideEffects(
const MachineInstr *
MI);
309 bool verifyGIntrinsicConvergence(
const MachineInstr *
MI);
310 void verifyPreISelGenericInstruction(
const MachineInstr *
MI);
312 void visitMachineInstrBefore(
const MachineInstr *
MI);
313 void visitMachineOperand(
const MachineOperand *MO,
unsigned MONum);
314 void visitMachineBundleAfter(
const MachineInstr *
MI);
315 void visitMachineBasicBlockAfter(
const MachineBasicBlock *
MBB);
316 void visitMachineFunctionAfter();
319 void report(
const char *msg,
const MachineBasicBlock *
MBB);
320 void report(
const char *msg,
const MachineInstr *
MI);
321 void report(
const char *msg,
const MachineOperand *MO,
unsigned MONum,
322 LLT MOVRegType = LLT{});
323 void report(
const Twine &
Msg,
const MachineInstr *
MI);
325 void report_context(
const LiveInterval &LI)
const;
326 void report_context(
const LiveRange &LR, VirtRegOrUnit VRegOrUnit,
327 LaneBitmask LaneMask)
const;
328 void report_context(
const LiveRange::Segment &S)
const;
329 void report_context(
const VNInfo &VNI)
const;
330 void report_context(SlotIndex Pos)
const;
331 void report_context(
MCPhysReg PhysReg)
const;
332 void report_context_liverange(
const LiveRange &LR)
const;
333 void report_context_lanemask(LaneBitmask LaneMask)
const;
334 void report_context_vreg(
Register VReg)
const;
335 void report_context_vreg_regunit(VirtRegOrUnit VRegOrUnit)
const;
337 void verifyInlineAsm(
const MachineInstr *
MI);
339 void checkLiveness(
const MachineOperand *MO,
unsigned MONum);
340 void checkLivenessAtUse(
const MachineOperand *MO,
unsigned MONum,
342 VirtRegOrUnit VRegOrUnit,
344 void checkLivenessAtDef(
const MachineOperand *MO,
unsigned MONum,
346 VirtRegOrUnit VRegOrUnit,
bool SubRangeCheck =
false,
349 void markReachable(
const MachineBasicBlock *
MBB);
350 void calcRegsPassed();
351 void checkPHIOps(
const MachineBasicBlock &
MBB);
353 void calcRegsRequired();
354 void verifyLiveIntervals();
355 void verifyLiveInterval(
const LiveInterval &);
356 void verifyLiveRangeValue(
const LiveRange &,
const VNInfo *, VirtRegOrUnit,
358 void verifyLiveRangeSegment(
const LiveRange &,
359 const LiveRange::const_iterator
I, VirtRegOrUnit,
361 void verifyLiveRange(
const LiveRange &, VirtRegOrUnit,
364 void verifyStackFrame();
366 void verifyStackProtector();
368 void verifySlotIndexes()
const;
375 const std::string Banner;
377 MachineVerifierLegacyPass(std::string banner = std::string())
378 : MachineFunctionPass(ID), Banner(std::
move(banner)) {}
380 void getAnalysisUsage(AnalysisUsage &AU)
const override {
395 MachineVerifier(
this, Banner.c_str(), &
errs()).verify(MF);
410 MachineVerifier(MFAM, Banner.c_str(), &
errs()).verify(MF);
414char MachineVerifierLegacyPass::ID = 0;
417 "Verify generated machine code",
false,
false)
420 return new MachineVerifierLegacyPass(Banner);
429 MachineVerifier(
nullptr, Banner.c_str(), &
errs()).verify(MF);
433 bool AbortOnError)
const {
434 return MachineVerifier(p, Banner, OS, AbortOnError).verify(*
this);
439 bool AbortOnError)
const {
440 return MachineVerifier(MFAM, Banner, OS, AbortOnError).verify(*
this);
445 bool AbortOnError)
const {
446 return MachineVerifier(Banner, LiveInts,
nullptr, Indexes, OS,
451void MachineVerifier::verifySlotIndexes()
const {
452 if (Indexes ==
nullptr)
469 report(
"Function has NoVRegs property but there are VReg operands", &MF);
481 const bool isFunctionFailedISel = Props.hasFailedISel();
486 if (isFunctionFailedISel)
489 isFunctionRegBankSelected = Props.hasRegBankSelected();
490 isFunctionSelected = Props.hasSelected();
491 isFunctionTracksDebugUserValues = Props.hasTracksDebugUserValues();
495 LiveInts = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
497 LiveStks = LSWrapper ? &LSWrapper->getLS() :
nullptr;
499 Indexes = SIWrapper ? &SIWrapper->getSI() :
nullptr;
510 verifyProperties(MF);
512 visitMachineFunctionBefore();
514 visitMachineBasicBlockBefore(&
MBB);
518 bool InBundle =
false;
521 if (
MI.getParent() != &
MBB) {
522 report(
"Bad instruction parent pointer", &
MBB);
523 OS <<
"Instruction: " <<
MI;
528 if (InBundle && !
MI.isBundledWithPred())
529 report(
"Missing BundledPred flag, "
530 "BundledSucc was set on predecessor",
532 if (!InBundle &&
MI.isBundledWithPred())
533 report(
"BundledPred flag is set, "
534 "but BundledSucc not set on predecessor",
538 if (!
MI.isInsideBundle()) {
540 visitMachineBundleAfter(CurBundle);
542 visitMachineBundleBefore(CurBundle);
543 }
else if (!CurBundle)
544 report(
"No bundle header", &
MI);
545 visitMachineInstrBefore(&
MI);
546 for (
unsigned I = 0,
E =
MI.getNumOperands();
I !=
E; ++
I) {
548 if (
Op.getParent() != &
MI) {
551 report(
"Instruction has operand with wrong parent set", &
MI);
554 visitMachineOperand(&
Op,
I);
558 InBundle =
MI.isBundledWithSucc();
561 visitMachineBundleAfter(CurBundle);
563 report(
"BundledSucc flag set on last instruction in block", &
MBB.
back());
564 visitMachineBasicBlockAfter(&
MBB);
566 visitMachineFunctionAfter();
576 return !ReportedErrs.hasError();
579void MachineVerifier::report(
const char *msg,
const MachineFunction *MF) {
582 if (ReportedErrs.increment()) {
584 OS <<
"# " << Banner <<
'\n';
586 if (LiveInts !=
nullptr)
589 MF->
print(OS, Indexes);
592 OS <<
"*** Bad machine code: " << msg <<
" ***\n"
593 <<
"- function: " << MF->
getName() <<
'\n';
600 <<
" (" << (
const void *)
MBB <<
')';
602 OS <<
" [" << Indexes->getMBBStartIdx(
MBB) <<
';'
603 << Indexes->getMBBEndIdx(
MBB) <<
')';
607void MachineVerifier::report(
const char *msg,
const MachineInstr *
MI) {
609 report(msg,
MI->getParent());
610 OS <<
"- instruction: ";
611 if (Indexes && Indexes->hasIndex(*
MI))
612 OS << Indexes->getInstructionIndex(*
MI) <<
'\t';
616void MachineVerifier::report(
const char *msg,
const MachineOperand *MO,
617 unsigned MONum,
LLT MOVRegType) {
620 OS <<
"- operand " << MONum <<
": ";
626 report(
Msg.str().c_str(),
MI);
629void MachineVerifier::report_context(
SlotIndex Pos)
const {
630 OS <<
"- at: " << Pos <<
'\n';
633void MachineVerifier::report_context(
const LiveInterval &LI)
const {
634 OS <<
"- interval: " << LI <<
'\n';
637void MachineVerifier::report_context(
const LiveRange &LR,
640 report_context_liverange(LR);
641 report_context_vreg_regunit(VRegOrUnit);
643 report_context_lanemask(LaneMask);
647 OS <<
"- segment: " << S <<
'\n';
650void MachineVerifier::report_context(
const VNInfo &VNI)
const {
651 OS <<
"- ValNo: " << VNI.
id <<
" (def " << VNI.
def <<
")\n";
654void MachineVerifier::report_context_liverange(
const LiveRange &LR)
const {
655 OS <<
"- liverange: " << LR <<
'\n';
658void MachineVerifier::report_context(
MCPhysReg PReg)
const {
659 OS <<
"- p. register: " <<
printReg(PReg,
TRI) <<
'\n';
662void MachineVerifier::report_context_vreg(
Register VReg)
const {
663 OS <<
"- v. register: " <<
printReg(VReg,
TRI) <<
'\n';
666void MachineVerifier::report_context_vreg_regunit(
676void MachineVerifier::report_context_lanemask(
LaneBitmask LaneMask)
const {
681 BBInfo &MInfo = MBBInfoMap[
MBB];
682 if (!MInfo.reachable) {
683 MInfo.reachable =
true;
689void MachineVerifier::visitMachineFunctionBefore() {
692 :
TRI->getReservedRegs(*MF);
695 markReachable(&MF->
front());
698 FunctionBlocks.
clear();
699 for (
const auto &
MBB : *MF) {
701 BBInfo &MInfo = MBBInfoMap[&
MBB];
705 report(
"MBB has duplicate entries in its predecessor list.", &
MBB);
709 report(
"MBB has duplicate entries in its successor list.", &
MBB);
717 verifyStackProtector();
724 return !
MBB.phis().empty();
730 FirstTerminator =
nullptr;
731 FirstNonPHI =
nullptr;
737 if (isAllocatable(LI.PhysReg) && !
MBB->
isEHPad() &&
740 report(
"MBB has allocatable live-in, but isn't entry, landing-pad, or "
741 "inlineasm-br-indirect-target.",
743 report_context(LI.PhysReg);
750 report(
"ir-block-address-taken is associated with basic block not used by "
759 LandingPadSuccs.
insert(succ);
760 if (!FunctionBlocks.
count(succ))
761 report(
"MBB has successor that isn't part of the function.",
MBB);
762 if (!MBBInfoMap[succ].Preds.
count(
MBB)) {
763 report(
"Inconsistent CFG",
MBB);
764 OS <<
"MBB is not in the predecessor list of the successor "
771 if (!FunctionBlocks.
count(Pred))
772 report(
"MBB has predecessor that isn't part of the function.",
MBB);
773 if (!MBBInfoMap[Pred].Succs.
count(
MBB)) {
774 report(
"Inconsistent CFG",
MBB);
775 OS <<
"MBB is not in the successor list of the predecessor "
783 if (LandingPadSuccs.
size() > 1 &&
787 report(
"MBB has more than one landing pad successor",
MBB);
799 report(
"MBB exits via unconditional fall-through but ends with a "
800 "barrier instruction!",
MBB);
803 report(
"MBB exits via unconditional fall-through but has a condition!",
809 report(
"MBB exits via unconditional branch but doesn't contain "
810 "any instructions!",
MBB);
812 report(
"MBB exits via unconditional branch but doesn't end with a "
813 "barrier instruction!",
MBB);
815 report(
"MBB exits via unconditional branch but the branch isn't a "
816 "terminator instruction!",
MBB);
821 report(
"MBB exits via conditional branch/fall-through but doesn't "
822 "contain any instructions!",
MBB);
824 report(
"MBB exits via conditional branch/fall-through but ends with a "
825 "barrier instruction!",
MBB);
827 report(
"MBB exits via conditional branch/fall-through but the branch "
828 "isn't a terminator instruction!",
MBB);
830 }
else if (
TBB && FBB) {
834 report(
"MBB exits via conditional branch/branch but doesn't "
835 "contain any instructions!",
MBB);
837 report(
"MBB exits via conditional branch/branch but doesn't end with a "
838 "barrier instruction!",
MBB);
840 report(
"MBB exits via conditional branch/branch but the branch "
841 "isn't a terminator instruction!",
MBB);
844 report(
"MBB exits via conditional branch/branch but there's no "
848 report(
"analyzeBranch returned invalid data!",
MBB);
854 report(
"MBB exits via jump or conditional branch, but its target isn't a "
858 report(
"MBB exits via conditional branch, but its target isn't a CFG "
873 report(
"MBB conditionally falls through out of function!",
MBB);
875 report(
"MBB exits via conditional branch/fall-through but the CFG "
876 "successors don't match the actual successors!",
883 if (SuccMBB ==
TBB || SuccMBB == FBB)
891 if (SuccMBB->isEHPad() || SuccMBB->isInlineAsmBrIndirectTarget())
893 report(
"MBB has unexpected successors which are not branch targets, "
894 "fallthrough, EHPads, or inlineasm_br targets.",
902 if (!LI.PhysReg.isPhysical()) {
903 report(
"MBB live-in list contains non-physical register",
MBB);
906 regsLive.insert_range(
TRI->subregs_inclusive(LI.PhysReg));
913 regsLive.insert_range(
TRI->subregs_inclusive(
I));
919 lastIndex = Indexes->getMBBStartIdx(
MBB);
924void MachineVerifier::visitMachineBundleBefore(
const MachineInstr *
MI) {
925 if (Indexes && Indexes->hasIndex(*
MI)) {
927 if (!(idx > lastIndex)) {
928 report(
"Instruction index out of order",
MI);
929 OS <<
"Last instruction was at " << lastIndex <<
'\n';
935 if (
MI->isTerminator()) {
936 if (!FirstTerminator)
937 FirstTerminator =
MI;
938 }
else if (FirstTerminator) {
941 if (FirstTerminator->
getOpcode() != TargetOpcode::G_INVOKE_REGION_START) {
942 report(
"Non-terminator instruction after the first terminator",
MI);
943 OS <<
"First terminator was:\t" << *FirstTerminator;
952 if (
MI->getNumOperands() < 2) {
953 report(
"Too few operands on inline asm",
MI);
956 if (!
MI->getOperand(0).isSymbol())
957 report(
"Asm string must be an external symbol",
MI);
958 if (!
MI->getOperand(1).isImm())
959 report(
"Asm flags must be an immediate",
MI);
964 report(
"Unknown asm flags", &
MI->getOperand(1), 1);
970 for (
unsigned e =
MI->getNumOperands(); OpNo < e; OpNo +=
NumOps) {
976 NumOps = 1 +
F.getNumOperandRegisters();
979 if (OpNo >
MI->getNumOperands())
980 report(
"Missing operands in last group",
MI);
983 if (OpNo < MI->getNumOperands() &&
MI->getOperand(OpNo).isMetadata())
987 for (
unsigned e =
MI->getNumOperands(); OpNo < e; ++OpNo) {
990 report(
"Expected implicit register after groups", &MO, OpNo);
993 if (
MI->getOpcode() == TargetOpcode::INLINEASM_BR) {
1006 if (!IndirectTargetMBB) {
1007 report(
"INLINEASM_BR indirect target does not exist", &MO, i);
1012 report(
"INLINEASM_BR indirect target missing from successor list", &MO,
1016 report(
"INLINEASM_BR indirect target predecessor list missing parent",
1022bool MachineVerifier::verifyAllRegOpsScalar(
const MachineInstr &
MI,
1027 const auto Reg = Op.getReg();
1028 if (Reg.isPhysical())
1030 return !MRI.getType(Reg).isScalar();
1033 report(
"All register operands must have scalar types", &
MI);
1040bool MachineVerifier::verifyVectorElementMatch(
LLT Ty0,
LLT Ty1,
1043 report(
"operand types must be all-vector or all-scalar",
MI);
1053 report(
"operand types must preserve number of vector elements",
MI);
1060bool MachineVerifier::verifyGIntrinsicSideEffects(
const MachineInstr *
MI) {
1061 auto Opcode =
MI->getOpcode();
1062 bool NoSideEffects = Opcode == TargetOpcode::G_INTRINSIC ||
1063 Opcode == TargetOpcode::G_INTRINSIC_CONVERGENT;
1065 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1067 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1068 bool DeclHasSideEffects = !
Attrs.getMemoryEffects().doesNotAccessMemory();
1069 if (NoSideEffects && DeclHasSideEffects) {
1071 " used with intrinsic that accesses memory"),
1075 if (!NoSideEffects && !DeclHasSideEffects) {
1076 report(
Twine(
TII->getName(Opcode),
" used with readnone intrinsic"),
MI);
1084bool MachineVerifier::verifyGIntrinsicConvergence(
const MachineInstr *
MI) {
1085 auto Opcode =
MI->getOpcode();
1086 bool NotConvergent = Opcode == TargetOpcode::G_INTRINSIC ||
1087 Opcode == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS;
1089 if (IntrID != 0 && IntrID < Intrinsic::num_intrinsics) {
1091 MF->getFunction().getContext(),
static_cast<Intrinsic::ID>(IntrID));
1092 bool DeclIsConvergent =
Attrs.hasAttribute(Attribute::Convergent);
1093 if (NotConvergent && DeclIsConvergent) {
1094 report(
Twine(
TII->getName(Opcode),
" used with a convergent intrinsic"),
1098 if (!NotConvergent && !DeclIsConvergent) {
1100 Twine(
TII->getName(Opcode),
" used with a non-convergent intrinsic"),
1109void MachineVerifier::verifyPreISelGenericInstruction(
const MachineInstr *
MI) {
1110 if (isFunctionSelected)
1111 report(
"Unexpected generic instruction in a Selected function",
MI);
1114 unsigned NumOps =
MI->getNumOperands();
1117 if (
MI->isBranch() && !
MI->isIndirectBranch()) {
1118 bool HasMBB =
false;
1127 report(
"Branch instruction is missing a basic block operand or "
1128 "isIndirectBranch property",
1135 for (
unsigned I = 0,
E = std::min(
MCID.getNumOperands(),
NumOps);
1137 if (!
MCID.operands()[
I].isGenericType())
1141 size_t TypeIdx =
MCID.operands()[
I].getGenericTypeIndex();
1142 Types.resize(std::max(TypeIdx + 1,
Types.size()));
1146 report(
"generic instruction must use register operands",
MI);
1156 if (!Types[TypeIdx].
isValid())
1157 Types[TypeIdx] = OpTy;
1158 else if (Types[TypeIdx] != OpTy)
1159 report(
"Type mismatch in generic instruction", MO,
I, OpTy);
1162 report(
"Generic instruction is missing a virtual register type", MO,
I);
1167 for (
unsigned I = 0;
I <
MI->getNumOperands(); ++
I) {
1170 report(
"Generic instruction cannot have physical register", MO,
I);
1174 if (
MI->getNumOperands() <
MCID.getNumOperands())
1182 unsigned Opc =
MI->getOpcode();
1184 case TargetOpcode::G_ASSERT_SEXT:
1185 case TargetOpcode::G_ASSERT_ZEXT: {
1186 std::string OpcName =
1187 Opc == TargetOpcode::G_ASSERT_ZEXT ?
"G_ASSERT_ZEXT" :
"G_ASSERT_SEXT";
1188 if (!
MI->getOperand(2).isImm()) {
1189 report(
Twine(OpcName,
" expects an immediate operand #2"),
MI);
1196 int64_t
Imm =
MI->getOperand(2).getImm();
1198 report(
Twine(OpcName,
" size must be >= 1"),
MI);
1203 report(
Twine(OpcName,
" size must be less than source bit width"),
MI);
1211 if ((SrcRB && DstRB && SrcRB != DstRB) || (DstRB && !SrcRB)) {
1212 report(
Twine(OpcName,
" cannot change register bank"),
MI);
1220 Twine(OpcName,
" source and destination register classes must match"),
1228 case TargetOpcode::G_CONSTANT:
1229 case TargetOpcode::G_FCONSTANT: {
1232 report(
"Instruction cannot use a vector result type",
MI);
1234 if (
MI->getOpcode() == TargetOpcode::G_CONSTANT) {
1235 if (!
MI->getOperand(1).isCImm()) {
1236 report(
"G_CONSTANT operand must be cimm",
MI);
1242 report(
"inconsistent constant size",
MI);
1244 if (!
MI->getOperand(1).isFPImm()) {
1245 report(
"G_FCONSTANT operand must be fpimm",
MI);
1252 report(
"inconsistent constant size",
MI);
1258 case TargetOpcode::G_LOAD:
1259 case TargetOpcode::G_STORE:
1260 case TargetOpcode::G_ZEXTLOAD:
1261 case TargetOpcode::G_SEXTLOAD:
1262 case TargetOpcode::G_FPEXTLOAD:
1263 case TargetOpcode::G_FPTRUNCSTORE: {
1267 report(
"Generic memory instruction must access a pointer",
MI);
1271 if (!
MI->hasOneMemOperand()) {
1272 report(
"Generic instruction accessing memory must have one mem operand",
1279 report(
"Generic extload must have a narrower memory type",
MI);
1283 report(
"Generic truncstore must have a narrower memory type",
MI);
1284 }
else if (
MI->getOpcode() == TargetOpcode::G_LOAD) {
1287 report(
"load memory size cannot exceed result size",
MI);
1298 report(
"range is incompatible with the result type",
MI);
1301 }
else if (
MI->getOpcode() == TargetOpcode::G_STORE) {
1304 report(
"store memory size cannot exceed value size",
MI);
1311 report(
"atomic store cannot use acquire ordering",
MI);
1316 report(
"atomic load cannot use release ordering",
MI);
1322 case TargetOpcode::G_PHI: {
1328 LLT Ty = MRI->getType(MO.getReg());
1329 if (!Ty.isValid() || (Ty != DstTy))
1333 report(
"Generic Instruction G_PHI has operands with incompatible/missing "
1338 case TargetOpcode::G_BITCAST: {
1345 report(
"bitcast cannot convert between pointers and other types",
MI);
1348 report(
"bitcast sizes must match",
MI);
1362 report(
"bitcast must change the type",
MI);
1366 case TargetOpcode::G_INTTOPTR:
1367 case TargetOpcode::G_PTRTOINT:
1368 case TargetOpcode::G_ADDRSPACE_CAST: {
1374 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1379 if (
MI->getOpcode() == TargetOpcode::G_INTTOPTR) {
1381 report(
"inttoptr result type must be a pointer",
MI);
1383 report(
"inttoptr source type must not be a pointer",
MI);
1384 }
else if (
MI->getOpcode() == TargetOpcode::G_PTRTOINT) {
1386 report(
"ptrtoint source type must be a pointer",
MI);
1388 report(
"ptrtoint result type must not be a pointer",
MI);
1390 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST);
1392 report(
"addrspacecast types must be pointers",
MI);
1395 report(
"addrspacecast must convert different address spaces",
MI);
1401 case TargetOpcode::G_PTR_ADD: {
1404 LLT OffsetTy = MRI->
getType(
MI->getOperand(2).getReg());
1409 report(
"gep first operand must be a pointer",
MI);
1412 report(
"gep offset operand must not be a pointer",
MI);
1417 unsigned IndexSizeInBits =
DL.getIndexSize(AS) * 8;
1419 report(
"gep offset operand must match index size for address space",
1427 case TargetOpcode::G_PTRMASK: {
1435 report(
"ptrmask result type must be a pointer",
MI);
1438 report(
"ptrmask mask type must be an integer",
MI);
1440 verifyVectorElementMatch(DstTy, MaskTy,
MI);
1443 case TargetOpcode::G_SEXT:
1444 case TargetOpcode::G_ZEXT:
1445 case TargetOpcode::G_ANYEXT:
1446 case TargetOpcode::G_TRUNC:
1447 case TargetOpcode::G_TRUNC_SSAT_S:
1448 case TargetOpcode::G_TRUNC_SSAT_U:
1449 case TargetOpcode::G_TRUNC_USAT_U:
1450 case TargetOpcode::G_FPEXT:
1451 case TargetOpcode::G_FPTRUNC: {
1457 assert(
MCID.getNumOperands() == 2 &&
"Expected 2 operands G_*{EXT,TRUNC}");
1464 report(
"Generic extend/truncate can not operate on pointers",
MI);
1466 verifyVectorElementMatch(DstTy, SrcTy,
MI);
1470 switch (
MI->getOpcode()) {
1472 if (DstSize <= SrcSize)
1473 report(
"Generic extend has destination type no larger than source",
MI);
1475 case TargetOpcode::G_TRUNC:
1476 case TargetOpcode::G_TRUNC_SSAT_S:
1477 case TargetOpcode::G_TRUNC_SSAT_U:
1478 case TargetOpcode::G_TRUNC_USAT_U:
1479 case TargetOpcode::G_FPTRUNC:
1480 if (DstSize >= SrcSize)
1481 report(
"Generic truncate has destination type no smaller than source",
1487 case TargetOpcode::G_SELECT: {
1495 verifyVectorElementMatch(SelTy, CondTy,
MI);
1498 case TargetOpcode::G_MERGE_VALUES: {
1506 report(
"G_MERGE_VALUES cannot operate on vectors",
MI);
1508 const unsigned NumOps =
MI->getNumOperands();
1510 report(
"G_MERGE_VALUES result size is inconsistent",
MI);
1512 for (
unsigned I = 2;
I !=
NumOps; ++
I) {
1513 if (MRI->
getType(
MI->getOperand(
I).getReg()) != SrcTy)
1514 report(
"G_MERGE_VALUES source types do not match",
MI);
1519 case TargetOpcode::G_UNMERGE_VALUES: {
1520 unsigned NumDsts =
MI->getNumOperands() - 1;
1522 for (
unsigned i = 1; i < NumDsts; ++i) {
1523 if (MRI->
getType(
MI->getOperand(i).getReg()) != DstTy) {
1524 report(
"G_UNMERGE_VALUES destination types do not match",
MI);
1529 LLT SrcTy = MRI->
getType(
MI->getOperand(NumDsts).getReg());
1537 report(
"G_UNMERGE_VALUES source operand does not match vector "
1538 "destination operands",
1545 report(
"G_UNMERGE_VALUES vector source operand does not match scalar "
1546 "destination operands",
1551 report(
"G_UNMERGE_VALUES scalar source operand does not match scalar "
1552 "destination operands",
1558 case TargetOpcode::G_BUILD_VECTOR: {
1562 LLT SrcEltTy = MRI->
getType(
MI->getOperand(1).getReg());
1564 report(
"G_BUILD_VECTOR must produce a vector from scalar operands",
MI);
1569 report(
"G_BUILD_VECTOR result element type must match source type",
MI);
1572 report(
"G_BUILD_VECTOR must have an operand for each element",
MI);
1576 report(
"G_BUILD_VECTOR source operand types are not homogeneous",
MI);
1580 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1584 LLT SrcEltTy = MRI->
getType(
MI->getOperand(1).getReg());
1586 report(
"G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
1590 report(
"G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
1593 report(
"G_BUILD_VECTOR_TRUNC source operand types are not larger than "
1598 case TargetOpcode::G_CONCAT_VECTORS: {
1604 report(
"G_CONCAT_VECTOR requires vector source and destination operands",
1607 if (
MI->getNumOperands() < 3)
1608 report(
"G_CONCAT_VECTOR requires at least 2 source operands",
MI);
1612 report(
"G_CONCAT_VECTOR source operand types are not homogeneous",
MI);
1615 report(
"G_CONCAT_VECTOR num dest and source elements should match",
MI);
1618 case TargetOpcode::G_ICMP:
1619 case TargetOpcode::G_FCMP: {
1626 report(
"Generic vector icmp/fcmp must preserve number of lanes",
MI);
1630 case TargetOpcode::G_SCMP:
1631 case TargetOpcode::G_UCMP: {
1636 report(
"Generic scmp/ucmp does not support pointers as operands",
MI);
1641 report(
"Generic scmp/ucmp does not support pointers as a result",
MI);
1646 report(
"Result type must be at least 2 bits wide",
MI);
1653 report(
"Generic vector scmp/ucmp must preserve number of lanes",
MI);
1659 case TargetOpcode::G_EXTRACT: {
1661 if (!
SrcOp.isReg()) {
1662 report(
"extract source must be a register",
MI);
1668 report(
"extract offset must be a constant",
MI);
1674 if (SrcSize == DstSize)
1675 report(
"extract source must be larger than result",
MI);
1677 if (DstSize +
OffsetOp.getImm() > SrcSize)
1678 report(
"extract reads past end of register",
MI);
1681 case TargetOpcode::G_INSERT: {
1683 if (!
SrcOp.isReg()) {
1684 report(
"insert source must be a register",
MI);
1690 report(
"insert offset must be a constant",
MI);
1697 if (DstSize <= SrcSize)
1698 report(
"inserted size must be smaller than total register",
MI);
1700 if (SrcSize +
OffsetOp.getImm() > DstSize)
1701 report(
"insert writes past end of register",
MI);
1705 case TargetOpcode::G_JUMP_TABLE: {
1706 if (!
MI->getOperand(1).isJTI())
1707 report(
"G_JUMP_TABLE source operand must be a jump table index",
MI);
1710 report(
"G_JUMP_TABLE dest operand must have a pointer type",
MI);
1713 case TargetOpcode::G_BRJT: {
1715 report(
"G_BRJT src operand 0 must be a pointer type",
MI);
1717 if (!
MI->getOperand(1).isJTI())
1718 report(
"G_BRJT src operand 1 must be a jump table index",
MI);
1720 const auto &IdxOp =
MI->getOperand(2);
1722 report(
"G_BRJT src operand 2 must be a scalar reg type",
MI);
1725 case TargetOpcode::G_INTRINSIC:
1726 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1727 case TargetOpcode::G_INTRINSIC_CONVERGENT:
1728 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: {
1733 report(
"G_INTRINSIC first src operand must be an intrinsic ID",
MI);
1737 if (!verifyGIntrinsicSideEffects(
MI))
1739 if (!verifyGIntrinsicConvergence(
MI))
1744 case TargetOpcode::G_SEXT_INREG: {
1745 if (!
MI->getOperand(2).isImm()) {
1746 report(
"G_SEXT_INREG expects an immediate operand #2",
MI);
1751 int64_t
Imm =
MI->getOperand(2).getImm();
1753 report(
"G_SEXT_INREG size must be >= 1",
MI);
1755 report(
"G_SEXT_INREG size must be less than source bit width",
MI);
1758 case TargetOpcode::G_BSWAP: {
1761 report(
"G_BSWAP size must be a multiple of 16 bits",
MI);
1764 case TargetOpcode::G_VSCALE: {
1765 if (!
MI->getOperand(1).isCImm()) {
1766 report(
"G_VSCALE operand must be cimm",
MI);
1769 if (
MI->getOperand(1).getCImm()->isZero()) {
1770 report(
"G_VSCALE immediate cannot be zero",
MI);
1775 case TargetOpcode::G_STEP_VECTOR: {
1776 if (!
MI->getOperand(1).isCImm()) {
1777 report(
"operand must be cimm",
MI);
1781 if (!
MI->getOperand(1).getCImm()->getValue().isStrictlyPositive()) {
1782 report(
"step must be > 0",
MI);
1788 report(
"Destination type must be a scalable vector",
MI);
1794 report(
"Destination element type must be scalar",
MI);
1798 if (
MI->getOperand(1).getCImm()->getBitWidth() !=
1800 report(
"step bitwidth differs from result type element bitwidth",
MI);
1805 case TargetOpcode::G_INSERT_SUBVECTOR: {
1807 if (!Src0Op.
isReg()) {
1808 report(
"G_INSERT_SUBVECTOR first source must be a register",
MI);
1813 if (!Src1Op.
isReg()) {
1814 report(
"G_INSERT_SUBVECTOR second source must be a register",
MI);
1819 if (!IndexOp.
isImm()) {
1820 report(
"G_INSERT_SUBVECTOR index must be an immediate",
MI);
1828 report(
"Destination type must be a vector",
MI);
1833 report(
"Second source must be a vector",
MI);
1838 report(
"Element type of vectors must be the same",
MI);
1843 report(
"Cannot insert a scalable vector into a fixed length vector",
MI);
1847 bool IsMixedFixedIntoScalable =
1850 if (!IsMixedFixedIntoScalable &&
1853 report(
"Second source must be smaller than destination vector",
MI);
1859 if (IndexOp.
getImm() % Src1MinLen != 0) {
1860 report(
"Index must be a multiple of the second source vector's "
1861 "minimum vector length",
1867 if (Idx >= DstMinLen ||
1868 (!IsMixedFixedIntoScalable && Idx + Src1MinLen > DstMinLen)) {
1869 report(
"Subvector type and index must not cause insert to overrun the "
1870 "vector being inserted into",
1877 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1879 if (!
SrcOp.isReg()) {
1880 report(
"G_EXTRACT_SUBVECTOR first source must be a register",
MI);
1885 if (!IndexOp.
isImm()) {
1886 report(
"G_EXTRACT_SUBVECTOR index must be an immediate",
MI);
1894 report(
"Destination type must be a vector",
MI);
1899 report(
"Source must be a vector",
MI);
1904 report(
"Element type of vectors must be the same",
MI);
1909 report(
"Cannot extract a scalable vector from a fixed length vector",
MI);
1915 report(
"Destination vector must be smaller than source vector",
MI);
1921 if (Idx % DstMinLen != 0) {
1922 report(
"Index must be a multiple of the destination vector's minimum "
1928 bool IsMixedFixedFromScalable =
1931 if (Idx >= SrcMinLen ||
1932 (!IsMixedFixedFromScalable && Idx + DstMinLen > SrcMinLen)) {
1933 report(
"Destination type and index must not cause extract to overrun the "
1941 case TargetOpcode::G_SHUFFLE_VECTOR: {
1944 report(
"Incorrect mask operand type for G_SHUFFLE_VECTOR",
MI);
1952 if (Src0Ty != Src1Ty)
1953 report(
"Source operands must be the same type",
MI);
1956 report(
"G_SHUFFLE_VECTOR cannot change element type",
MI);
1960 report(
"G_SHUFFLE_VECTOR must have vector src",
MI);
1964 report(
"G_SHUFFLE_VECTOR must have vector dst",
MI);
1975 if (
static_cast<int>(MaskIdxes.
size()) != DstNumElts)
1976 report(
"Wrong result type for shufflemask",
MI);
1978 for (
int Idx : MaskIdxes) {
1982 if (Idx >= 2 * SrcNumElts)
1983 report(
"Out of bounds shuffle index",
MI);
1989 case TargetOpcode::G_SPLAT_VECTOR: {
1994 report(
"Destination type must be a scalable vector",
MI);
1999 report(
"Source type must be a scalar or pointer",
MI);
2005 report(
"Element type of the destination must be the same size or smaller "
2006 "than the source type",
2013 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
2019 report(
"Destination type must be a scalar or pointer",
MI);
2024 report(
"First source must be a vector",
MI);
2028 auto TLI = MF->getSubtarget().getTargetLowering();
2029 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2030 report(
"Index type must match VectorIdxTy",
MI);
2036 case TargetOpcode::G_INSERT_VECTOR_ELT: {
2043 report(
"Destination type must be a vector",
MI);
2047 if (VecTy != DstTy) {
2048 report(
"Destination type and vector type must match",
MI);
2053 report(
"Inserted element must be a scalar or pointer",
MI);
2057 auto TLI = MF->getSubtarget().getTargetLowering();
2058 if (IdxTy.
getSizeInBits() != TLI->getVectorIdxWidth(MF->getDataLayout())) {
2059 report(
"Index type must match VectorIdxTy",
MI);
2065 case TargetOpcode::G_DYN_STACKALLOC: {
2071 report(
"dst operand 0 must be a pointer type",
MI);
2076 report(
"src operand 1 must be a scalar reg type",
MI);
2080 if (!AlignOp.
isImm()) {
2081 report(
"src operand 2 must be an immediate type",
MI);
2086 case TargetOpcode::G_MEMCPY_INLINE:
2087 case TargetOpcode::G_MEMCPY:
2088 case TargetOpcode::G_MEMMOVE: {
2090 if (MMOs.
size() != 2) {
2091 report(
"memcpy/memmove must have 2 memory operands",
MI);
2097 report(
"wrong memory operand types",
MI);
2102 report(
"inconsistent memory operand sizes",
MI);
2104 LLT DstPtrTy = MRI->
getType(
MI->getOperand(0).getReg());
2105 LLT SrcPtrTy = MRI->
getType(
MI->getOperand(1).getReg());
2108 report(
"memory instruction operand must be a pointer",
MI);
2113 report(
"inconsistent store address space",
MI);
2115 report(
"inconsistent load address space",
MI);
2117 if (
Opc != TargetOpcode::G_MEMCPY_INLINE)
2118 if (!
MI->getOperand(3).isImm() || (
MI->getOperand(3).getImm() & ~1LL))
2119 report(
"'tail' flag (operand 3) must be an immediate 0 or 1",
MI);
2123 case TargetOpcode::G_BZERO:
2124 case TargetOpcode::G_MEMSET:
2125 case TargetOpcode::G_MEMSET_INLINE: {
2127 std::string
Name =
Opc == TargetOpcode::G_MEMSET ?
"memset"
2128 :
Opc == TargetOpcode::G_MEMSET_INLINE ?
"memset_inline"
2130 if (MMOs.
size() != 1) {
2131 report(
Twine(Name,
" must have 1 memory operand"),
MI);
2136 report(
Twine(Name,
" memory operand must be a store"),
MI);
2140 LLT DstPtrTy = MRI->
getType(
MI->getOperand(0).getReg());
2142 report(
Twine(Name,
" operand must be a pointer"),
MI);
2147 report(
"inconsistent " +
Twine(Name,
" address space"),
MI);
2149 if (
Opc != TargetOpcode::G_MEMSET_INLINE) {
2150 if (!
MI->getOperand(
MI->getNumOperands() - 1).isImm() ||
2151 (
MI->getOperand(
MI->getNumOperands() - 1).getImm() & ~1LL))
2152 report(
"'tail' flag (last operand) must be an immediate 0 or 1",
MI);
2157 case TargetOpcode::G_UBSANTRAP: {
2159 if (!
MI->getOperand(0).isImm()) {
2160 report(
"Crash kind must be an immediate", &KindOp, 0);
2163 int64_t
Kind =
MI->getOperand(0).getImm();
2165 report(
"Crash kind must be 8 bit wide", &KindOp, 0);
2168 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
2169 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
2174 report(
"Vector reduction requires a scalar destination type",
MI);
2176 report(
"Sequential FADD/FMUL vector reduction requires a scalar 1st operand",
MI);
2178 report(
"Sequential FADD/FMUL vector reduction must have a vector 2nd operand",
MI);
2181 case TargetOpcode::G_VECREDUCE_FADD:
2182 case TargetOpcode::G_VECREDUCE_FMUL:
2183 case TargetOpcode::G_VECREDUCE_FMAX:
2184 case TargetOpcode::G_VECREDUCE_FMIN:
2185 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
2186 case TargetOpcode::G_VECREDUCE_FMINIMUM:
2187 case TargetOpcode::G_VECREDUCE_FMAXIMUMNUM:
2188 case TargetOpcode::G_VECREDUCE_FMINIMUMNUM:
2189 case TargetOpcode::G_VECREDUCE_ADD:
2190 case TargetOpcode::G_VECREDUCE_MUL:
2191 case TargetOpcode::G_VECREDUCE_AND:
2192 case TargetOpcode::G_VECREDUCE_OR:
2193 case TargetOpcode::G_VECREDUCE_XOR:
2194 case TargetOpcode::G_VECREDUCE_SMAX:
2195 case TargetOpcode::G_VECREDUCE_SMIN:
2196 case TargetOpcode::G_VECREDUCE_UMAX:
2197 case TargetOpcode::G_VECREDUCE_UMIN: {
2200 report(
"Vector reduction requires a scalar destination type",
MI);
2204 case TargetOpcode::G_SBFX:
2205 case TargetOpcode::G_UBFX: {
2208 report(
"Bitfield extraction is not supported on vectors",
MI);
2213 case TargetOpcode::G_SHL:
2214 case TargetOpcode::G_LSHR:
2215 case TargetOpcode::G_ASHR:
2216 case TargetOpcode::G_ROTR:
2217 case TargetOpcode::G_ROTL: {
2221 report(
"Shifts and rotates require operands to be either all scalars or "
2228 case TargetOpcode::G_LLROUND:
2229 case TargetOpcode::G_LROUND: {
2236 report(
Twine(
Op,
" operand must not be a pointer type"),
MI);
2238 verifyAllRegOpsScalar(*
MI, *MRI);
2241 verifyVectorElementMatch(SrcTy, DstTy,
MI);
2246 case TargetOpcode::G_IS_FPCLASS: {
2250 report(
"Destination must be a scalar or vector of scalars",
MI);
2256 report(
"Source must be a scalar or vector of scalars",
MI);
2259 if (!verifyVectorElementMatch(DestTy, SrcTy,
MI))
2262 if (!TestMO.
isImm()) {
2263 report(
"floating-point class set (operand 2) must be an immediate",
MI);
2268 report(
"Incorrect floating-point class set (operand 2)",
MI);
2273 case TargetOpcode::G_PREFETCH: {
2276 report(
"addr operand must be a pointer", &AddrOp, 0);
2281 report(
"rw operand must be an immediate 0-1", &RWOp, 1);
2286 report(
"locality operand must be an immediate 0-3", &LocalityOp, 2);
2291 report(
"cache type operand must be an immediate 0-1", &CacheTypeOp, 3);
2296 case TargetOpcode::G_ASSERT_ALIGN: {
2297 if (
MI->getOperand(2).getImm() < 1)
2298 report(
"alignment immediate must be >= 1",
MI);
2301 case TargetOpcode::G_CONSTANT_POOL: {
2302 if (!
MI->getOperand(1).isCPI())
2303 report(
"Src operand 1 must be a constant pool index",
MI);
2305 report(
"Dst operand 0 must be a pointer",
MI);
2308 case TargetOpcode::G_PTRAUTH_GLOBAL_VALUE: {
2311 report(
"addr operand must be a pointer", &AddrOp, 1);
2314 case TargetOpcode::G_SMIN:
2315 case TargetOpcode::G_SMAX:
2316 case TargetOpcode::G_UMIN:
2317 case TargetOpcode::G_UMAX: {
2318 const LLT DstTy = MRI->
getType(
MI->getOperand(0).getReg());
2320 report(
"Generic smin/smax/umin/umax does not support pointer operands",
2329void MachineVerifier::visitMachineInstrBefore(
const MachineInstr *
MI) {
2331 if (
MI->getNumOperands() <
MCID.getNumOperands()) {
2332 report(
"Too few operands",
MI);
2333 OS <<
MCID.getNumOperands() <<
" operands expected, but "
2334 <<
MI->getNumOperands() <<
" given.\n";
2338 report(
"NoConvergent flag expected only on convergent instructions.",
MI);
2341 if (MF->getProperties().hasNoPHIs())
2342 report(
"Found PHI instruction with NoPHIs property set",
MI);
2345 report(
"Found PHI instruction after non-PHI",
MI);
2346 }
else if (FirstNonPHI ==
nullptr)
2350 if (
MI->isInlineAsm())
2351 verifyInlineAsm(
MI);
2354 if (
TII->isUnspillableTerminator(
MI)) {
2355 if (!
MI->getOperand(0).isReg() || !
MI->getOperand(0).isDef())
2356 report(
"Unspillable Terminator does not define a reg",
MI);
2360 report(
"Unspillable Terminator expected to have at most one use!",
MI);
2366 if (
MI->isDebugValue() &&
MI->getNumOperands() == 4)
2367 if (!
MI->getDebugLoc())
2368 report(
"Missing DebugLoc for debug instruction",
MI);
2372 if (
MI->isMetaInstruction() &&
MI->peekDebugInstrNum())
2373 report(
"Metadata instruction should not have a value tracking number",
MI);
2377 if (
Op->isLoad() && !
MI->mayLoad())
2378 report(
"Missing mayLoad flag",
MI);
2379 if (
Op->isStore() && !
MI->mayStore())
2380 report(
"Missing mayStore flag",
MI);
2386 bool mapped = !LiveInts->isNotInMIMap(*
MI);
2387 if (
MI->isDebugOrPseudoInstr()) {
2389 report(
"Debug instruction has a slot index",
MI);
2390 }
else if (
MI->isInsideBundle()) {
2392 report(
"Instruction inside bundle has a slot index",
MI);
2395 report(
"Missing slot index",
MI);
2399 unsigned Opc =
MCID.getOpcode();
2401 verifyPreISelGenericInstruction(
MI);
2410 switch (
MI->getOpcode()) {
2411 case TargetOpcode::COPY: {
2421 if (SrcTy != DstTy) {
2422 report(
"Copy Instruction is illegal with mismatching types",
MI);
2423 OS <<
"Def = " << DstTy <<
", Src = " << SrcTy <<
'\n';
2437 if (!hasPhysRegClassForType(*
TRI, SrcReg, DstTy))
2438 SrcSize =
TRI->getRegSizeInBits(SrcReg, *MRI);
2440 SrcSize =
TRI->getRegSizeInBits(SrcReg, *MRI);
2444 if (!hasPhysRegClassForType(*
TRI, DstReg, SrcTy))
2445 DstSize =
TRI->getRegSizeInBits(DstReg, *MRI);
2447 DstSize =
TRI->getRegSizeInBits(DstReg, *MRI);
2465 if (!
DstOp.getSubReg() && !
SrcOp.getSubReg()) {
2466 report(
"Copy Instruction is illegal with mismatching sizes",
MI);
2467 OS <<
"Def Size = " << DstSize <<
", Src Size = " << SrcSize <<
'\n';
2472 case TargetOpcode::COPY_LANEMASK: {
2480 if (
DstOp.getSubReg())
2481 report(
"COPY_LANEMASK must not use a subregister index", &
DstOp, 0);
2483 if (
SrcOp.getSubReg())
2484 report(
"COPY_LANEMASK must not use a subregister index", &
SrcOp, 1);
2486 if (LaneMask.
none())
2487 report(
"COPY_LANEMASK must read at least one lane",
MI);
2499 if (SrcMaxLaneMask == LaneMask)
2500 report(
"COPY_LANEMASK cannot be used to do full copy",
MI);
2505 if (SrcMaxLaneMask < LaneMask)
2506 report(
"COPY_LANEMASK attempts to read from the lanes that "
2507 "don't exist in the source register",
2512 case TargetOpcode::STATEPOINT: {
2514 if (!
MI->getOperand(SO.getIDPos()).isImm() ||
2515 !
MI->getOperand(SO.getNBytesPos()).isImm() ||
2516 !
MI->getOperand(SO.getNCallArgsPos()).isImm()) {
2517 report(
"meta operands to STATEPOINT not constant!",
MI);
2521 auto VerifyStackMapConstant = [&](
unsigned Offset) {
2522 if (
Offset >=
MI->getNumOperands()) {
2523 report(
"stack map constant to STATEPOINT is out of range!",
MI);
2526 if (!
MI->getOperand(
Offset - 1).isImm() ||
2527 MI->getOperand(
Offset - 1).getImm() != StackMaps::ConstantOp ||
2529 report(
"stack map constant to STATEPOINT not well formed!",
MI);
2531 VerifyStackMapConstant(SO.getCCIdx());
2532 VerifyStackMapConstant(SO.getFlagsIdx());
2533 VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
2534 VerifyStackMapConstant(SO.getNumGCPtrIdx());
2535 VerifyStackMapConstant(SO.getNumAllocaIdx());
2536 VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
2540 unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
2541 unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
2542 for (
unsigned Idx = 0;
Idx <
MI->getNumDefs();
Idx++) {
2544 if (!
MI->isRegTiedToUseOperand(Idx, &UseOpIdx)) {
2545 report(
"STATEPOINT defs expected to be tied",
MI);
2548 if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
2549 report(
"STATEPOINT def tied to non-gc operand",
MI);
2556 case TargetOpcode::INSERT_SUBREG: {
2557 unsigned InsertedSize;
2558 if (
unsigned SubIdx =
MI->getOperand(2).getSubReg())
2559 InsertedSize =
TRI->getSubRegIdxSize(SubIdx);
2561 InsertedSize =
TRI->getRegSizeInBits(
MI->getOperand(2).getReg(), *MRI);
2562 unsigned SubRegSize =
TRI->getSubRegIdxSize(
MI->getOperand(3).getImm());
2563 if (SubRegSize < InsertedSize) {
2564 report(
"INSERT_SUBREG expected inserted value to have equal or lesser "
2565 "size than the subreg it was inserted into",
MI);
2569 case TargetOpcode::REG_SEQUENCE: {
2570 unsigned NumOps =
MI->getNumOperands();
2572 report(
"Invalid number of operands for REG_SEQUENCE",
MI);
2576 for (
unsigned I = 1;
I !=
NumOps;
I += 2) {
2581 report(
"Invalid register operand for REG_SEQUENCE", &RegOp,
I);
2583 if (!SubRegOp.
isImm() || SubRegOp.
getImm() == 0 ||
2584 SubRegOp.
getImm() >=
TRI->getNumSubRegIndices()) {
2585 report(
"Invalid subregister index operand for REG_SEQUENCE",
2590 Register DstReg =
MI->getOperand(0).getReg();
2592 report(
"REG_SEQUENCE does not support physical register results",
MI);
2594 if (
MI->getOperand(0).getSubReg())
2595 report(
"Invalid subreg result for REG_SEQUENCE",
MI);
2603MachineVerifier::visitMachineOperand(
const MachineOperand *MO,
unsigned MONum) {
2606 unsigned NumDefs =
MCID.getNumDefs();
2607 if (
MCID.getOpcode() == TargetOpcode::PATCHPOINT)
2608 NumDefs = (MONum == 0 && MO->
isReg()) ? NumDefs : 0;
2611 if (MONum < NumDefs) {
2614 report(
"Explicit definition must be a register", MO, MONum);
2615 else if (!MO->
isDef() && !
MCOI.isOptionalDef())
2616 report(
"Explicit definition marked as use", MO, MONum);
2618 report(
"Explicit definition marked as implicit", MO, MONum);
2619 }
else if (MONum <
MCID.getNumOperands()) {
2623 bool IsOptional =
MI->isVariadic() && MONum ==
MCID.getNumOperands() - 1;
2626 if (MO->
isDef() && !
MCOI.isOptionalDef() && !
MCID.variadicOpsAreDefs())
2627 report(
"Explicit operand marked as def", MO, MONum);
2629 report(
"Explicit operand marked as implicit", MO, MONum);
2635 report(
"Expected a register operand.", MO, MONum);
2639 !
TII->isPCRelRegisterOperandLegal(*
MI, MONum)))
2640 report(
"Expected a non-register operand.", MO, MONum);
2647 report(
"Tied use must be a register", MO, MONum);
2649 report(
"Operand should be tied", MO, MONum);
2650 else if (
unsigned(TiedTo) !=
MI->findTiedOperandIdx(MONum))
2651 report(
"Tied def doesn't match MCInstrDesc", MO, MONum);
2654 if (!MOTied.
isReg())
2655 report(
"Tied counterpart must be a register", &MOTied, TiedTo);
2658 report(
"Tied physical registers must match.", &MOTied, TiedTo);
2661 report(
"Explicit operand should not be tied", MO, MONum);
2662 }
else if (!
MI->isVariadic()) {
2665 report(
"Extra explicit operand on non-variadic instruction", MO, MONum);
2671 report(
"Early clobber must be a register",
MI);
2673 report(
"Missing earlyClobber flag",
MI);
2680 if (
MI->isDebugInstr() && MO->
isUse()) {
2682 report(
"Register operand must be marked debug", MO, MONum);
2684 report(
"Register operand must not be marked debug", MO, MONum);
2691 checkLiveness(MO, MONum);
2695 report(
"Undef virtual register def operands require a subregister", MO, MONum);
2699 unsigned OtherIdx =
MI->findTiedOperandIdx(MONum);
2701 if (!OtherMO.
isReg())
2702 report(
"Must be tied to a register", MO, MONum);
2704 report(
"Missing tie flags on tied operand", MO, MONum);
2705 if (
MI->findTiedOperandIdx(OtherIdx) != MONum)
2706 report(
"Inconsistent tie links", MO, MONum);
2712 return &Other != MO && Other.isUndef() && Other.getReg() == Reg &&
2713 Other.getSubReg() == MO->getSubReg();
2715 report(
"Tied undef use shares a virtual register with another read", MO,
2718 if (MONum <
MCID.getNumDefs()) {
2719 if (OtherIdx <
MCID.getNumOperands()) {
2721 report(
"Explicit def tied to explicit use without tie constraint",
2725 report(
"Explicit def should be tied to implicit use", MO, MONum);
2738 if (MF->getProperties().hasTiedOpsRewritten() && MO->
isUse() &&
2739 MI->isRegTiedToDefOperand(MONum, &DefIdx) &&
2740 Reg !=
MI->getOperand(DefIdx).getReg())
2741 report(
"Two-address instruction operands must be identical", MO, MONum);
2748 report(
"Illegal subregister index for physical register", MO, MONum);
2751 if (MONum <
MCID.getNumOperands()) {
2753 if (!DRC->contains(
Reg)) {
2754 report(
"Illegal physical register for instruction", MO, MONum);
2756 <<
TRI->getRegClassName(DRC) <<
" register.\n";
2762 report(
"isRenamable set on reserved register", MO, MONum);
2779 report(
"Generic virtual register use cannot be undef", MO, MONum);
2786 if (isFunctionTracksDebugUserValues || !MO->
isUse() ||
2789 if (isFunctionSelected) {
2790 report(
"Generic virtual register invalid in a Selected function",
2798 report(
"Generic virtual register must have a valid type", MO,
2807 if (!RegBank && isFunctionRegBankSelected) {
2808 report(
"Generic virtual register must have a bank in a "
2809 "RegBankSelected function",
2817 report(
"Register bank is too small for virtual register", MO,
2819 OS <<
"Register bank " << RegBank->
getName() <<
" too small("
2827 report(
"Generic virtual register does not allow subregister index", MO,
2836 MONum <
MCID.getNumOperands() &&
TII->getRegClass(
MCID, MONum)) {
2837 report(
"Virtual register does not match instruction constraint", MO,
2839 OS <<
"Expect register class "
2840 <<
TRI->getRegClassName(
TII->getRegClass(
MCID, MONum))
2841 <<
" but got nothing\n";
2848 if (!
TRI->isSubRegValidForRegClass(RC, SubIdx)) {
2849 report(
"Invalid subregister index for virtual register", MO, MONum);
2850 OS <<
"Register class " <<
TRI->getRegClassName(RC)
2851 <<
" does not support subreg index "
2852 <<
TRI->getSubRegIndexName(SubIdx) <<
'\n';
2855 if (MONum >=
MCID.getNumOperands())
2864 if (SubIdx &&
TRI->getMatchingSuperRegClass(RC, DRC, SubIdx) != RC) {
2865 report(
"Illegal virtual register for instruction", MO, MONum);
2866 OS <<
TRI->getRegClassName(RC) <<
"." <<
TRI->getSubRegIndexName(SubIdx)
2867 <<
" cannot be used for " <<
TRI->getRegClassName(DRC)
2873 report(
"Illegal virtual register for instruction", MO, MONum);
2874 OS <<
"Expected a " <<
TRI->getRegClassName(DRC)
2875 <<
" register, but got a " <<
TRI->getRegClassName(RC)
2888 report(
"PHI operand is not in the CFG", MO, MONum);
2892 if (LiveStks && LiveStks->hasInterval(MO->
getIndex()) &&
2893 LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
2903 if (MayStore && MayLoad) {
2916 if (MayLoad == MayStore)
2917 report(
"Missing fixed stack memoperand.",
MI);
2919 if (MayLoad && !LI.
liveAt(
Idx.getRegSlot(
true))) {
2920 report(
"Instruction loads from dead spill slot", MO, MONum);
2921 OS <<
"Live stack: " << LI <<
'\n';
2923 if (MayStore && !LI.
liveAt(
Idx.getRegSlot())) {
2924 report(
"Instruction stores to dead spill slot", MO, MONum);
2925 OS <<
"Live stack: " << LI <<
'\n';
2931 if (MO->
getCFIIndex() >= MF->getFrameInstructions().size())
2932 report(
"CFI instruction has invalid index", MO, MONum);
2940void MachineVerifier::checkLivenessAtUse(
const MachineOperand *MO,
2948 report(
"invalid live range", MO, MONum);
2949 report_context_liverange(LR);
2950 report_context_vreg_regunit(VRegOrUnit);
2951 report_context(UseIdx);
2960 report(
"No live segment at use", MO, MONum);
2961 report_context_liverange(LR);
2962 report_context_vreg_regunit(VRegOrUnit);
2963 report_context(UseIdx);
2966 report(
"Live range continues after kill flag", MO, MONum);
2967 report_context_liverange(LR);
2968 report_context_vreg_regunit(VRegOrUnit);
2970 report_context_lanemask(LaneMask);
2971 report_context(UseIdx);
2975void MachineVerifier::checkLivenessAtDef(
const MachineOperand *MO,
2982 report(
"invalid live range", MO, MONum);
2983 report_context_liverange(LR);
2984 report_context_vreg_regunit(VRegOrUnit);
2986 report_context_lanemask(LaneMask);
2987 report_context(DefIdx);
2999 if (((SubRangeCheck || MO->
getSubReg() == 0) && VNI->def != DefIdx) ||
3001 (VNI->def != DefIdx &&
3002 (!VNI->def.isEarlyClobber() || !DefIdx.
isRegister()))) {
3003 report(
"Inconsistent valno->def", MO, MONum);
3004 report_context_liverange(LR);
3005 report_context_vreg_regunit(VRegOrUnit);
3007 report_context_lanemask(LaneMask);
3008 report_context(*VNI);
3009 report_context(DefIdx);
3012 report(
"No live segment at def", MO, MONum);
3013 report_context_liverange(LR);
3014 report_context_vreg_regunit(VRegOrUnit);
3016 report_context_lanemask(LaneMask);
3017 report_context(DefIdx);
3029 if (SubRangeCheck || MO->
getSubReg() == 0) {
3030 report(
"Live range continues after dead def flag", MO, MONum);
3031 report_context_liverange(LR);
3032 report_context_vreg_regunit(VRegOrUnit);
3034 report_context_lanemask(LaneMask);
3040void MachineVerifier::checkLiveness(
const MachineOperand *MO,
unsigned MONum) {
3043 const unsigned SubRegIdx = MO->
getSubReg();
3047 if (LiveInts->hasInterval(
Reg)) {
3048 LI = &LiveInts->getInterval(
Reg);
3051 report(
"Live interval for subreg operand has no subranges", MO, MONum);
3053 report(
"Virtual register has no live interval", MO, MONum);
3060 addRegWithSubRegs(regsKilled,
Reg);
3063 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3067 UseIdx = LiveInts->getMBBEndIdx(
3068 MI->getOperand(MONum + 1).getMBB()).getPrevSlot();
3070 UseIdx = LiveInts->getInstructionIndex(*
MI);
3077 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3078 checkLivenessAtUse(MO, MONum, UseIdx, *LR,
VirtRegOrUnit(Unit));
3088 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3092 if ((MOMask & SR.LaneMask).none())
3098 LiveInMask |= SR.LaneMask;
3101 if ((LiveInMask & MOMask).
none()) {
3102 report(
"No live subrange at use", MO, MONum);
3103 report_context(*LI);
3104 report_context(UseIdx);
3107 if (
MI->isPHI() && LiveInMask != MOMask) {
3108 report(
"Not all lanes of PHI source live at use", MO, MONum);
3109 report_context(*LI);
3110 report_context(UseIdx);
3117 if (!regsLive.count(
Reg)) {
3120 bool Bad = !isReserved(
Reg);
3125 if (regsLive.count(SubReg)) {
3137 if (!MOP.isReg() || !MOP.isImplicit())
3140 if (!MOP.getReg().isPhysical())
3143 if (MOP.getReg() !=
Reg &&
3144 all_of(
TRI->regunits(
Reg), [&](
const MCRegUnit RegUnit) {
3145 return llvm::is_contained(TRI->regunits(MOP.getReg()),
3152 report(
"Using an undefined physical register", MO, MONum);
3154 report(
"Reading virtual register without a def", MO, MONum);
3156 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3160 if (MInfo.regsKilled.count(
Reg))
3161 report(
"Using a killed virtual register", MO, MONum);
3162 else if (!
MI->isPHI())
3163 MInfo.vregsLiveIn.insert(std::make_pair(
Reg,
MI));
3172 addRegWithSubRegs(regsDead,
Reg);
3174 addRegWithSubRegs(regsDefined,
Reg);
3179 report(
"Multiple virtual register defs in SSA form", MO, MONum);
3181 report(
"Subreg def in SSA form", MO, MONum);
3185 if (LiveInts && !LiveInts->isNotInMIMap(*
MI)) {
3186 SlotIndex DefIdx = LiveInts->getInstructionIndex(*
MI);
3194 ?
TRI->getSubRegIndexLaneMask(SubRegIdx)
3197 if ((SR.LaneMask & MOMask).none())
3212void MachineVerifier::visitMachineBundleAfter(
const MachineInstr *
MI) {
3213 BBInfo &MInfo = MBBInfoMap[
MI->getParent()];
3214 set_union(MInfo.regsKilled, regsKilled);
3215 set_subtract(regsLive, regsKilled); regsKilled.clear();
3217 while (!regMasks.empty()) {
3218 const uint32_t *
Mask = regMasks.pop_back_val();
3222 regsDead.push_back(
Reg);
3225 set_union(regsLive, regsDefined); regsDefined.clear();
3230 MBBInfoMap[
MBB].regsLiveOut = regsLive;
3235 if (!(stop > lastIndex)) {
3236 report(
"Block ends before last instruction index",
MBB);
3237 OS <<
"Block ends at " << stop <<
" last instruction was at " << lastIndex
3253 template <
typename RegSetT>
void add(
const RegSetT &FromRegSet) {
3255 filterAndAdd(FromRegSet, VRegsBuffer);
3260 template <
typename RegSetT>
3261 bool filterAndAdd(
const RegSetT &FromRegSet,
3262 SmallVectorImpl<Register> &ToVRegs) {
3263 unsigned SparseUniverse = Sparse.size();
3264 unsigned NewSparseUniverse = SparseUniverse;
3265 unsigned NewDenseSize =
Dense.size();
3266 size_t Begin = ToVRegs.
size();
3271 if (Index < SparseUniverseMax) {
3272 if (Index < SparseUniverse && Sparse.test(Index))
3274 NewSparseUniverse = std::max(NewSparseUniverse, Index + 1);
3289 Sparse.resize(NewSparseUniverse);
3290 Dense.reserve(NewDenseSize);
3291 for (
unsigned I = Begin;
I <
End; ++
I) {
3294 if (Index < SparseUniverseMax)
3303 static constexpr unsigned SparseUniverseMax = 10 * 1024 * 8;
3314 DenseSet<Register>
Dense;
3323class FilteringVRegSet {
3330 template <
typename RegSetT>
void addToFilter(
const RegSetT &RS) {
3335 template <
typename RegSetT>
bool add(
const RegSetT &RS) {
3338 return Filter.filterAndAdd(RS, VRegs);
3340 using const_iterator =
decltype(VRegs)::const_iterator;
3341 const_iterator
begin()
const {
return VRegs.
begin(); }
3342 const_iterator
end()
const {
return VRegs.
end(); }
3343 size_t size()
const {
return VRegs.
size(); }
3350void MachineVerifier::calcRegsPassed() {
3357 FilteringVRegSet VRegs;
3358 BBInfo &
Info = MBBInfoMap[MB];
3361 VRegs.addToFilter(
Info.regsKilled);
3362 VRegs.addToFilter(
Info.regsLiveOut);
3364 const BBInfo &PredInfo = MBBInfoMap[Pred];
3365 if (!PredInfo.reachable)
3368 VRegs.add(PredInfo.regsLiveOut);
3369 VRegs.add(PredInfo.vregsPassed);
3371 Info.vregsPassed.reserve(VRegs.size());
3372 Info.vregsPassed.insert_range(VRegs);
3379void MachineVerifier::calcRegsRequired() {
3382 for (
const auto &
MBB : *MF) {
3383 BBInfo &MInfo = MBBInfoMap[&
MBB];
3385 BBInfo &PInfo = MBBInfoMap[Pred];
3386 if (PInfo.addRequired(MInfo.vregsLiveIn))
3392 for (
unsigned i = 1, e =
MI.getNumOperands(); i != e; i += 2) {
3394 if (!
MI.getOperand(i).isReg() || !
MI.getOperand(i).readsReg())
3401 BBInfo &PInfo = MBBInfoMap[Pred];
3402 if (PInfo.addRequired(
Reg))
3410 while (!todo.
empty()) {
3413 BBInfo &MInfo = MBBInfoMap[
MBB];
3417 BBInfo &SInfo = MBBInfoMap[Pred];
3418 if (SInfo.addRequired(MInfo.vregsRequired))
3427 BBInfo &MInfo = MBBInfoMap[&
MBB];
3437 report(
"Expected first PHI operand to be a register def", &MODef, 0);
3442 report(
"Unexpected flag on PHI operand", &MODef, 0);
3445 report(
"Expected first PHI operand to be a virtual register", &MODef, 0);
3447 for (
unsigned I = 1,
E =
Phi.getNumOperands();
I !=
E;
I += 2) {
3450 report(
"Expected PHI operand to be a register", &MO0,
I);
3455 report(
"Unexpected flag on PHI operand", &MO0,
I);
3459 report(
"Expected PHI operand to be a basic block", &MO1,
I + 1);
3465 report(
"PHI input is not a predecessor block", &MO1,
I + 1);
3469 if (MInfo.reachable) {
3471 BBInfo &PrInfo = MBBInfoMap[&Pre];
3472 if (!MO0.
isUndef() && PrInfo.reachable &&
3473 !PrInfo.isLiveOut(MO0.
getReg()))
3474 report(
"PHI operand is not live-out from predecessor", &MO0,
I);
3479 if (MInfo.reachable) {
3481 if (!seen.
count(Pred)) {
3482 report(
"Missing PHI operand", &Phi);
3484 <<
" is a predecessor according to the CFG.\n";
3493 std::function<
void(
const Twine &Message)> FailureCB,
3498 for (
const auto &
MBB : MF) {
3500 for (
const auto &
MI :
MBB.instrs())
3510void MachineVerifier::visitMachineFunctionAfter() {
3511 auto FailureCB = [
this](
const Twine &Message) {
3512 report(Message.str().c_str(), MF);
3525 for (
const auto &
MBB : *MF) {
3526 BBInfo &MInfo = MBBInfoMap[&
MBB];
3527 for (
Register VReg : MInfo.vregsRequired)
3528 if (MInfo.regsKilled.count(VReg)) {
3529 report(
"Virtual register killed in block, but needed live out.", &
MBB);
3530 OS <<
"Virtual register " <<
printReg(VReg)
3531 <<
" is used after the block.\n";
3536 BBInfo &MInfo = MBBInfoMap[&MF->front()];
3537 for (
Register VReg : MInfo.vregsRequired) {
3538 report(
"Virtual register defs don't dominate all uses.", MF);
3539 report_context_vreg(VReg);
3544 verifyLiveIntervals();
3554 for (
const auto &
MBB : *MF)
3558 if (hasAliases || isAllocatable(LiveInReg) || isReserved(LiveInReg))
3561 BBInfo &PInfo = MBBInfoMap[Pred];
3562 if (!PInfo.regsLiveOut.count(LiveInReg)) {
3563 report(
"Live in register not found to be live out from predecessor.",
3565 OS <<
TRI->getName(LiveInReg) <<
" not found to be live out from "
3571 for (
auto CSInfo : MF->getCallSitesInfo())
3572 if (!CSInfo.first->isCall())
3573 report(
"Call site info referencing instruction that is not call", MF);
3577 if (MF->getFunction().getSubprogram()) {
3579 for (
const auto &
MBB : *MF) {
3580 for (
const auto &
MI :
MBB) {
3581 if (
auto Num =
MI.peekDebugInstrNum()) {
3584 report(
"Instruction has a duplicated value tracking number", &
MI);
3591void MachineVerifier::verifyLiveIntervals() {
3592 assert(LiveInts &&
"Don't call verifyLiveIntervals without LiveInts");
3600 if (!LiveInts->hasInterval(
Reg)) {
3601 report(
"Missing live interval for virtual register", MF);
3607 assert(
Reg == LI.
reg() &&
"Invalid reg to interval mapping");
3608 verifyLiveInterval(LI);
3612 for (MCRegUnit Unit :
TRI->regunits())
3613 if (
const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3617void MachineVerifier::verifyLiveRangeValue(
const LiveRange &LR,
3627 report(
"Value not live at VNInfo def and not marked unused", MF);
3628 report_context(LR, VRegOrUnit, LaneMask);
3629 report_context(*VNI);
3633 if (DefVNI != VNI) {
3634 report(
"Live segment at def has different VNInfo", MF);
3635 report_context(LR, VRegOrUnit, LaneMask);
3636 report_context(*VNI);
3642 report(
"Invalid VNInfo definition index", MF);
3643 report_context(LR, VRegOrUnit, LaneMask);
3644 report_context(*VNI);
3649 if (VNI->
def != LiveInts->getMBBStartIdx(
MBB)) {
3650 report(
"PHIDef VNInfo is not defined at MBB start",
MBB);
3651 report_context(LR, VRegOrUnit, LaneMask);
3652 report_context(*VNI);
3660 report(
"No instruction at VNInfo def index",
MBB);
3661 report_context(LR, VRegOrUnit, LaneMask);
3662 report_context(*VNI);
3666 bool hasDef =
false;
3667 bool isEarlyClobber =
false;
3669 if (!MOI->isReg() || !MOI->isDef())
3675 if (!MOI->getReg().isPhysical() ||
3679 if (LaneMask.
any() &&
3680 (
TRI->getSubRegIndexLaneMask(MOI->getSubReg()) & LaneMask).none())
3683 if (MOI->isEarlyClobber())
3684 isEarlyClobber =
true;
3688 report(
"Defining instruction does not modify register",
MI);
3689 report_context(LR, VRegOrUnit, LaneMask);
3690 report_context(*VNI);
3695 if (isEarlyClobber) {
3697 report(
"Early clobber def must be at an early-clobber slot",
MBB);
3698 report_context(LR, VRegOrUnit, LaneMask);
3699 report_context(*VNI);
3702 report(
"Non-PHI, non-early clobber def must be at a register slot",
MBB);
3703 report_context(LR, VRegOrUnit, LaneMask);
3704 report_context(*VNI);
3708void MachineVerifier::verifyLiveRangeSegment(
const LiveRange &LR,
3714 assert(VNI &&
"Live segment has no valno");
3717 report(
"Foreign valno in live segment", MF);
3718 report_context(LR, VRegOrUnit, LaneMask);
3720 report_context(*VNI);
3724 report(
"Live segment valno is marked unused", MF);
3725 report_context(LR, VRegOrUnit, LaneMask);
3731 report(
"Bad start of live segment, no basic block", MF);
3732 report_context(LR, VRegOrUnit, LaneMask);
3738 report(
"Live segment must begin at MBB entry or valno def",
MBB);
3739 report_context(LR, VRegOrUnit, LaneMask);
3746 report(
"Bad end of live segment, no basic block", MF);
3747 report_context(LR, VRegOrUnit, LaneMask);
3753 if (S.
end != LiveInts->getMBBEndIdx(EndMBB)) {
3763 report(
"Live segment doesn't end at a valid instruction", EndMBB);
3764 report_context(LR, VRegOrUnit, LaneMask);
3771 report(
"Live segment ends at B slot of an instruction", EndMBB);
3772 report_context(LR, VRegOrUnit, LaneMask);
3780 report(
"Live segment ending at dead slot spans instructions", EndMBB);
3781 report_context(LR, VRegOrUnit, LaneMask);
3791 if (
I + 1 == LR.
end() || (
I + 1)->start != S.
end) {
3792 report(
"Live segment ending at early clobber slot must be "
3793 "redefined by an EC def in the same instruction",
3795 report_context(LR, VRegOrUnit, LaneMask);
3805 bool hasRead =
false;
3806 bool hasSubRegDef =
false;
3807 bool hasDeadDef =
false;
3809 if (!MOI->isReg() || MOI->getReg() != VRegOrUnit.
asVirtualReg())
3811 unsigned Sub = MOI->getSubReg();
3816 hasSubRegDef =
true;
3825 if (LaneMask.
any() && (LaneMask & SLM).none())
3827 if (MOI->readsReg())
3834 if (LaneMask.
none() && !hasDeadDef) {
3836 "Instruction ending live segment on dead slot has no dead flag",
3838 report_context(LR, VRegOrUnit, LaneMask);
3846 LaneMask.
any() || !hasSubRegDef) {
3847 report(
"Instruction ending live segment doesn't read the register",
3849 report_context(LR, VRegOrUnit, LaneMask);
3869 if (LaneMask.
any()) {
3875 assert(LiveInts->isLiveInToMBB(LR, &*MFI));
3878 if (&*MFI == EndMBB)
3886 VNI->
def == LiveInts->getMBBStartIdx(&*MFI);
3890 SlotIndex PEnd = LiveInts->getMBBEndIdx(Pred);
3892 if (MFI->isEHPad()) {
3895 PEnd = Indexes->getInstructionIndex(
MI).getBoundaryIndex();
3906 if (!PVNI && (LaneMask.
none() || !IsPHI)) {
3909 report(
"Register not marked live out of predecessor", Pred);
3910 report_context(LR, VRegOrUnit, LaneMask);
3911 report_context(*VNI);
3913 << LiveInts->getMBBStartIdx(&*MFI) <<
", not live before " << PEnd
3919 if (!IsPHI && PVNI != VNI) {
3920 report(
"Different value live out of predecessor", Pred);
3921 report_context(LR, VRegOrUnit, LaneMask);
3922 OS <<
"Valno #" << PVNI->
id <<
" live out of "
3925 << LiveInts->getMBBStartIdx(&*MFI) <<
'\n';
3928 if (&*MFI == EndMBB)
3934void MachineVerifier::verifyLiveRange(
const LiveRange &LR,
3938 verifyLiveRangeValue(LR, VNI, VRegOrUnit, LaneMask);
3941 verifyLiveRangeSegment(LR,
I, VRegOrUnit, LaneMask);
3944void MachineVerifier::verifyLiveInterval(
const LiveInterval &LI) {
3953 if ((Mask & SR.LaneMask).any()) {
3954 report(
"Lane masks of sub ranges overlap in live interval", MF);
3957 if ((SR.LaneMask & ~MaxMask).any()) {
3958 report(
"Subrange lanemask is invalid", MF);
3962 report(
"Subrange must not be empty", MF);
3965 Mask |= SR.LaneMask;
3968 report(
"A Subrange is not covered by the main range", MF);
3976 unsigned NumComp = ConEQ.Classify(LI);
3978 report(
"Multiple connected components in live interval", MF);
3980 for (
unsigned comp = 0; comp != NumComp; ++comp) {
3981 OS << comp <<
": valnos";
3983 if (comp == ConEQ.getEqClass(
I))
3996struct StackStateOfBB {
3997 StackStateOfBB() =
default;
3998 StackStateOfBB(
int EntryVal,
int ExitVal,
bool EntrySetup,
bool ExitSetup)
3999 : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
4000 ExitIsSetup(ExitSetup) {}
4005 bool EntryIsSetup =
false;
4006 bool ExitIsSetup =
false;
4014void MachineVerifier::verifyStackFrame() {
4015 unsigned FrameSetupOpcode =
TII->getCallFrameSetupOpcode();
4016 unsigned FrameDestroyOpcode =
TII->getCallFrameDestroyOpcode();
4017 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
4021 SPState.
resize(MF->getNumBlockIDs());
4028 DFI != DFE; ++DFI) {
4031 StackStateOfBB BBState;
4033 if (DFI.getPathLength() >= 2) {
4036 "DFS stack predecessor is already visited.\n");
4037 BBState.EntryValue = SPState[StackPred->
getNumber()].ExitValue;
4038 BBState.EntryIsSetup = SPState[StackPred->
getNumber()].ExitIsSetup;
4039 BBState.ExitValue = BBState.EntryValue;
4040 BBState.ExitIsSetup = BBState.EntryIsSetup;
4044 report(
"Call frame size on entry does not match value computed from "
4048 <<
" does not match value computed from predecessor "
4049 << -BBState.EntryValue <<
'\n';
4053 for (
const auto &
I : *
MBB) {
4054 if (
I.getOpcode() == FrameSetupOpcode) {
4055 if (BBState.ExitIsSetup)
4056 report(
"FrameSetup is after another FrameSetup", &
I);
4057 if (!MRI->
isSSA() && !MF->getFrameInfo().adjustsStack())
4058 report(
"AdjustsStack not set in presence of a frame pseudo "
4059 "instruction.", &
I);
4060 BBState.ExitValue -=
TII->getFrameTotalSize(
I);
4061 BBState.ExitIsSetup =
true;
4064 if (
I.getOpcode() == FrameDestroyOpcode) {
4065 int Size =
TII->getFrameTotalSize(
I);
4066 if (!BBState.ExitIsSetup)
4067 report(
"FrameDestroy is not after a FrameSetup", &
I);
4068 int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
4070 if (BBState.ExitIsSetup && AbsSPAdj !=
Size) {
4071 report(
"FrameDestroy <n> is after FrameSetup <m>", &
I);
4072 OS <<
"FrameDestroy <" <<
Size <<
"> is after FrameSetup <"
4073 << AbsSPAdj <<
">.\n";
4075 if (!MRI->
isSSA() && !MF->getFrameInfo().adjustsStack())
4076 report(
"AdjustsStack not set in presence of a frame pseudo "
4077 "instruction.", &
I);
4078 BBState.ExitValue +=
Size;
4079 BBState.ExitIsSetup =
false;
4087 if (Reachable.
count(Pred) &&
4088 (SPState[Pred->
getNumber()].ExitValue != BBState.EntryValue ||
4089 SPState[Pred->
getNumber()].ExitIsSetup != BBState.EntryIsSetup)) {
4090 report(
"The exit stack state of a predecessor is inconsistent.",
MBB);
4092 << SPState[Pred->
getNumber()].ExitValue <<
", "
4093 << SPState[Pred->
getNumber()].ExitIsSetup <<
"), while "
4095 << BBState.EntryValue <<
", " << BBState.EntryIsSetup <<
").\n";
4102 if (Reachable.
count(Succ) &&
4103 (SPState[Succ->getNumber()].EntryValue != BBState.ExitValue ||
4104 SPState[Succ->getNumber()].EntryIsSetup != BBState.ExitIsSetup)) {
4105 report(
"The entry stack state of a successor is inconsistent.",
MBB);
4107 << SPState[Succ->getNumber()].EntryValue <<
", "
4108 << SPState[Succ->getNumber()].EntryIsSetup <<
"), while "
4110 << BBState.ExitValue <<
", " << BBState.ExitIsSetup <<
").\n";
4116 if (BBState.ExitIsSetup)
4117 report(
"A return block ends with a FrameSetup.",
MBB);
4118 if (BBState.ExitValue)
4119 report(
"A return block ends with a nonzero stack adjustment.",
MBB);
4124void MachineVerifier::verifyStackProtector() {
4133 bool StackGrowsDown =
4160 if (SPStart < ObjEnd && ObjStart < SPEnd) {
4161 report(
"Stack protector overlaps with another stack object", MF);
4164 if ((StackGrowsDown && SPStart <= ObjStart) ||
4165 (!StackGrowsDown && SPStart >= ObjStart)) {
4166 report(
"Stack protector is not the top-most object on the stack", MF);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isLoad(int Opcode)
static bool isStore(int Opcode)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file implements the BitVector class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
const HexagonInstrInfo * TII
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
A common definition of LaneBitmask for use in TableGen and CodeGen.
Implement a low-level type suitable for MachineInstr level instruction selection.
print mir2vec MIR2Vec Vocabulary Printer Pass
This file declares the MIR specialization of the GenericConvergenceVerifier template.
Register const TargetRegisterInfo * TRI
static void verifyConvergenceControl(const MachineFunction &MF, MachineDominatorTree &DT, std::function< void(const Twine &Message)> FailureCB, raw_ostream &OS)
static bool hasPHIs(const MachineFunction &MF)
Promote Memory to Register
modulo schedule Modulo Schedule test pass
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
SI Optimize VGPR LiveRange
SmallPtrSet< BasicBlock *, 0 > BlockSet
This file defines generic set operations that may be used on set's of different types,...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
static unsigned getSize(unsigned Kind)
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
const fltSemantics & getSemantics() const
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
This class holds the attributes for a particular argument, parameter, function, or return value.
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
void clear()
Removes all bits from the bitvector.
iterator_range< const_set_bits_iterator > set_bits() const
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
This is the shared class of boolean and integer constants.
IntegerType * getIntegerType() const
Variant of the getType() method to always return an IntegerType, which reduces the amount of casting ...
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
A parsed version of the target data layout string in and methods for querying it.
Implements a dense probed hash-table based set.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Base class for user error types.
FunctionPass class - This class is used to implement most global optimizations.
const Function & getFunction() const
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
void verify(const DominatorTreeT &DT)
void visit(const BlockT &BB)
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr unsigned getScalarSizeInBits() const
constexpr bool isFloatOrFloatVector() const
constexpr bool isScalar() const
constexpr Kind getKind() const
LLT getScalarType() const
constexpr bool isPointerVector() const
constexpr FpSemantics getFpSemantics() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
constexpr bool isPointerOrPointerVector() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
LLVM_ABI void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
void print(raw_ostream &O, const Module *=nullptr) const override
Implement the dump method.
Result of a LiveRange query.
bool isDeadDef() const
Return true if this instruction has a dead def.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
VNInfo * valueOut() const
Return the value leaving the instruction, if any.
bool isKill() const
Return true if the live-in value is killed by this instruction.
static LLVM_ABI bool isJointlyDominated(const MachineBasicBlock *MBB, ArrayRef< SlotIndex > Defs, const SlotIndexes &Indexes)
A diagnostic function to check if the end of the block MBB is jointly dominated by the blocks corresp...
This class represents the liveness of a register, stack slot, etc.
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
Segments::const_iterator const_iterator
bool liveAt(SlotIndex index) const
LLVM_ABI bool covers(const LiveRange &Other) const
Returns true if all segments of the Other live range are completely covered by this live range.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
bool verify() const
Walk the range and assert if any invariants fail to hold.
unsigned getNumValNums() const
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
TypeSize getValue() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
ExceptionHandling getExceptionHandlingType() const
Describe properties that are true of each instruction in the target description file.
This holds information about one operand of a machine instruction, indicating the register class for ...
MCRegAliasIterator enumerates all registers aliasing Reg.
bool hasSuperClassEq(const MCRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
Wrapper class representing physical registers. Should be passed by value.
const MDOperand & getOperand(unsigned I) const
bool isValid() const
isValid - Returns true until all the operands have been visited.
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
unsigned pred_size() const
bool isEHPad() const
Returns true if the block is a landing pad.
iterator_range< livein_iterator > liveins() const
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
bool isIRBlockAddressTaken() const
Test whether this block is the target of an IR BlockAddress.
unsigned succ_size() const
BasicBlock * getAddressTakenIRBlock() const
Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
unsigned getCallFrameSize() const
Return the call frame size on entry to this basic block.
iterator_range< succ_iterator > successors()
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int getStackProtectorIndex() const
Return the index for the stack protector object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
LLVM_ABI BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isReturn(QueryType Type=AnyInBundle) const
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
const PseudoSourceValue * getPseudoValue() const
LLT getMemoryType() const
Return the memory type of the memory reference.
const MDNode * getRanges() const
Return the range tag for the memory reference.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
LocationSize getSizeInBits() const
Return the size in bits of the memory reference.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isIntrinsicID() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
ArrayRef< int > getShuffleMask() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isValidExcessOperand() const
Return true if this operand can validly be appended to an arbitrary operand list.
bool isShuffleMask() const
LLVM_ABI void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr) const
Print the MachineOperand to os.
LaneBitmask getLaneMask() const
unsigned getCFIIndex() const
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool isEarlyClobber() const
Register getReg() const
getReg - Returns the register number.
bool isInternalRead() const
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
use_nodbg_iterator use_nodbg_begin(Register RegNo) const
LLVM_ABI void verifyUseLists() const
Verify the use list of all registers.
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
static use_nodbg_iterator use_nodbg_end()
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
bool reservedRegsFrozen() const
reservedRegsFrozen - Returns true after freezeReservedRegs() was called to ensure the set of reserved...
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
bool reg_nodbg_empty(Register RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions.
const RegisterBank * getRegBankOrNull(Register Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
bool shouldTrackSubRegLiveness(const TargetRegisterClass &RC) const
Returns true if liveness for register class RC should be tracked at the subregister level.
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
LLVM_ABI bool isReservedRegUnit(MCRegUnit Unit) const
Returns true when the given register unit is considered reserved.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
LLVM_ABI LaneBitmask getMaxLaneMaskForVReg(Register Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Pass interface - Implemented by all 'passes'.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Holds all the information related to register banks.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
This class implements the register bank concept.
const char * getName() const
Get a user friendly name of this register bank.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr unsigned id() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SlotIndex - An opaque wrapper around machine indexes.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level Statepoint operands.
Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static constexpr TypeSize getZero()
Value * getOperand(unsigned i) const
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.
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void set_subtract(S1Ty &S1, const S2Ty &S2)
set_subtract(A, B) - Compute A := A - B
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
bool isPreISelGenericOptimizationHint(unsigned Opcode)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
LLVM_ABI FunctionPass * createMachineVerifierPass(const std::string &Banner)
createMachineVerifierPass - This pass verifies cenerated machine code instructions for correctness.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void verifyMachineFunction(const std::string &Banner, const MachineFunction &MF)
auto reverse(ContainerTy &&C)
detail::ValueMatchesPoly< M > HasValue(M Matcher)
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
GenericConvergenceVerifier< MachineSSAContext > MachineConvergenceVerifier
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
@ SjLj
setjmp/longjmp based exceptions
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
@ End
Run the machine verifier once, at the end of the pipeline.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
Implement std::hash so that hash_code can be used in STL containers.
static constexpr LaneBitmask getAll()
constexpr bool none() const
constexpr bool any() const
static constexpr LaneBitmask getNone()
This represents a simple continuous liveness interval for a value.
Pair of physical register and lane mask.