94#include "llvm/IR/IntrinsicsAArch64.h"
95#include "llvm/IR/IntrinsicsAMDGPU.h"
96#include "llvm/IR/IntrinsicsARM.h"
97#include "llvm/IR/IntrinsicsNVPTX.h"
98#include "llvm/IR/IntrinsicsWebAssembly.h"
136 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
137 "scopes are not dominating"));
162 *
OS <<
"; ModuleID = '" << M->getModuleIdentifier() <<
"'\n";
175 V.printAsOperand(*
OS,
true,
MST);
180 void Write(
const DbgRecord *DR) {
214 template <
class T>
void Write(
const MDTupleTypedArrayWrapper<T> &MD) {
218 void Write(
const NamedMDNode *NMD) {
231 void Write(
const Comdat *
C) {
237 void Write(
const APInt *AI) {
243 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
249 *
OS <<
A->getAsString() <<
'\n';
253 void Write(
const AttributeSet *AS) {
260 void Write(
const AttributeList *AL) {
266 void Write(Printable
P) { *
OS <<
P <<
'\n'; }
268 template <
typename T>
void Write(ArrayRef<T> Vs) {
269 for (
const T &V : Vs)
273 template <
typename T1,
typename... Ts>
274 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
279 template <
typename... Ts>
void WriteTs() {}
288 *
OS << Message <<
'\n';
296 template <
typename T1,
typename... Ts>
306 *
OS << Message <<
'\n';
312 template <
typename T1,
typename... Ts>
334 SmallPtrSet<Instruction *, 16> InstsInThisBlock;
337 SmallPtrSet<const Metadata *, 32> MDNodes;
340 DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments;
343 SmallPtrSet<const Metadata *, 2> CUVisited;
346 Type *LandingPadResultTy;
353 bool HasDebugInfo =
false;
357 DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo;
361 MapVector<Instruction *, Instruction *> SiblingFuncletInfo;
365 DenseMap<BasicBlock *, ColorVector> BlockEHFuncletColors;
368 SmallPtrSet<const Constant *, 32> ConstantExprVisited;
374 SmallPtrSet<const void *, 32> AttributeListsVisited;
380 SmallPtrSet<const Value *, 32> GlobalValueVisited;
385 TBAAVerifier TBAAVerifyHelper;
390 void checkAtomicMemAccessSize(
Type *Ty,
const Instruction *
I);
393 explicit Verifier(raw_ostream *OS,
bool ShouldTreatBrokenDebugInfoAsError,
395 : VerifierSupport(OS,
M), LandingPadResultTy(nullptr),
396 SawFrameEscape(
false), TBAAVerifyHelper(this) {
397 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
400 bool hasBrokenDebugInfo()
const {
return BrokenDebugInfo; }
402 bool verify(
const Function &
F) {
403 llvm::TimeTraceScope timeScope(
"Verifier");
405 "An instance of this class only works with a specific module!");
414 DT.recalculate(
const_cast<Function &
>(
F));
416 for (
const BasicBlock &BB :
F) {
417 if (!BB.empty() && BB.back().isTerminator())
421 *OS <<
"Basic Block in function '" <<
F.getName()
422 <<
"' does not have terminator!\n";
423 BB.printAsOperand(*OS,
true, MST);
429 auto FailureCB = [
this](
const Twine &Message) {
430 this->CheckFailed(Message);
432 ConvergenceVerifyHelper.initialize(OS, FailureCB,
F);
437 verifySiblingFuncletUnwinds();
439 if (ConvergenceVerifyHelper.sawTokens())
440 ConvergenceVerifyHelper.verify(DT);
442 InstsInThisBlock.clear();
444 LandingPadResultTy =
nullptr;
445 SawFrameEscape =
false;
446 SiblingFuncletInfo.clear();
447 verifyNoAliasScopeDecl();
448 NoAliasScopeDecls.clear();
458 for (
const Function &
F : M)
459 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
460 DeoptimizeDeclarations.push_back(&
F);
464 verifyFrameRecoverIndices();
465 for (
const GlobalVariable &GV :
M.globals())
466 visitGlobalVariable(GV);
468 for (
const GlobalAlias &GA :
M.aliases())
469 visitGlobalAlias(GA);
471 for (
const GlobalIFunc &GI :
M.ifuncs())
472 visitGlobalIFunc(GI);
474 for (
const NamedMDNode &NMD :
M.named_metadata())
475 visitNamedMDNode(NMD);
477 for (
const StringMapEntry<Comdat> &SMEC :
M.getComdatSymbolTable())
478 visitComdat(SMEC.getValue());
482 visitModuleCommandLines();
484 verifyCompileUnits();
486 verifyDeoptimizeCallingConvs();
487 DISubprogramAttachments.clear();
493 enum class AreDebugLocsAllowed {
No,
Yes };
497 enum class RangeLikeMetadataKind {
504 void visitGlobalValue(
const GlobalValue &GV);
505 void visitGlobalVariable(
const GlobalVariable &GV);
506 void visitGlobalAlias(
const GlobalAlias &GA);
507 void visitGlobalIFunc(
const GlobalIFunc &GI);
508 void visitAliaseeSubExpr(
const GlobalAlias &
A,
const Constant &
C);
509 void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited,
510 const GlobalAlias &
A,
const Constant &
C);
511 void visitNamedMDNode(
const NamedMDNode &NMD);
512 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
513 void visitMetadataAsValue(
const MetadataAsValue &MD, Function *
F);
514 void visitValueAsMetadata(
const ValueAsMetadata &MD, Function *
F);
515 void visitDIArgList(
const DIArgList &AL, Function *
F);
516 void visitComdat(
const Comdat &
C);
517 void visitModuleIdents();
518 void visitModuleCommandLines();
519 void visitModuleFlags();
520 void visitModuleFlag(
const MDNode *
Op,
521 DenseMap<const MDString *, const MDNode *> &SeenIDs,
522 SmallVectorImpl<const MDNode *> &Requirements);
523 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
524 void visitFunction(
const Function &
F);
525 void visitBasicBlock(BasicBlock &BB);
526 void verifyRangeLikeMetadata(
const Value &V,
const MDNode *
Range,
Type *Ty,
527 RangeLikeMetadataKind Kind);
528 void visitRangeMetadata(Instruction &
I, MDNode *
Range,
Type *Ty);
529 void visitNoaliasAddrspaceMetadata(Instruction &
I, MDNode *
Range,
Type *Ty);
530 void visitDereferenceableMetadata(Instruction &
I, MDNode *MD);
531 void visitNofreeMetadata(Instruction &
I, MDNode *MD);
532 void visitProfMetadata(Instruction &
I, MDNode *MD);
533 void visitCallStackMetadata(MDNode *MD);
534 void visitMemProfMetadata(Instruction &
I, MDNode *MD);
535 void visitCallsiteMetadata(Instruction &
I, MDNode *MD);
536 void visitCalleeTypeMetadata(Instruction &
I, MDNode *MD);
537 void visitDIAssignIDMetadata(Instruction &
I, MDNode *MD);
538 void visitMMRAMetadata(Instruction &
I, MDNode *MD);
539 void visitAnnotationMetadata(MDNode *Annotation);
540 void visitAliasScopeMetadata(
const MDNode *MD);
541 void visitAliasScopeListMetadata(
const MDNode *MD);
542 void visitAccessGroupMetadata(
const MDNode *MD);
544 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
545#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
546#include "llvm/IR/Metadata.def"
547 void visitDIScope(
const DIScope &
N);
571 void checkPtrToAddr(
Type *SrcTy,
Type *DestTy,
const Value &V);
576 void visitPHINode(
PHINode &PN);
585 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
586 void visitCallInst(CallInst &CI);
587 void visitInvokeInst(InvokeInst &
II);
588 void visitGetElementPtrInst(GetElementPtrInst &
GEP);
589 void visitLoadInst(LoadInst &LI);
590 void visitStoreInst(StoreInst &SI);
591 void verifyDominatesUse(Instruction &
I,
unsigned i);
592 void visitInstruction(Instruction &
I);
593 void visitTerminator(Instruction &
I);
594 void visitBranchInst(BranchInst &BI);
595 void visitReturnInst(ReturnInst &RI);
596 void visitSwitchInst(SwitchInst &SI);
597 void visitIndirectBrInst(IndirectBrInst &BI);
598 void visitCallBrInst(CallBrInst &CBI);
599 void visitSelectInst(SelectInst &SI);
600 void visitUserOp1(Instruction &
I);
601 void visitUserOp2(Instruction &
I) { visitUserOp1(
I); }
603 void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI);
604 void visitVPIntrinsic(VPIntrinsic &VPI);
605 void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI);
606 void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
607 void visitAtomicRMWInst(AtomicRMWInst &RMWI);
608 void visitFenceInst(FenceInst &FI);
609 void visitAllocaInst(AllocaInst &AI);
610 void visitExtractValueInst(ExtractValueInst &EVI);
611 void visitInsertValueInst(InsertValueInst &IVI);
612 void visitEHPadPredecessors(Instruction &
I);
613 void visitLandingPadInst(LandingPadInst &LPI);
614 void visitResumeInst(ResumeInst &RI);
615 void visitCatchPadInst(CatchPadInst &CPI);
616 void visitCatchReturnInst(CatchReturnInst &CatchReturn);
617 void visitCleanupPadInst(CleanupPadInst &CPI);
618 void visitFuncletPadInst(FuncletPadInst &FPI);
619 void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
620 void visitCleanupReturnInst(CleanupReturnInst &CRI);
622 void verifySwiftErrorCall(CallBase &
Call,
const Value *SwiftErrorVal);
623 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
624 void verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs, StringRef
Context);
625 void verifyMustTailCall(CallInst &CI);
626 bool verifyAttributeCount(AttributeList Attrs,
unsigned Params);
627 void verifyAttributeTypes(AttributeSet Attrs,
const Value *V);
628 void verifyParameterAttrs(AttributeSet Attrs,
Type *Ty,
const Value *V);
629 void checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr,
631 void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
632 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
633 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
635 void visitConstantExprsRecursively(
const Constant *EntryC);
636 void visitConstantExpr(
const ConstantExpr *CE);
637 void visitConstantPtrAuth(
const ConstantPtrAuth *CPA);
638 void verifyInlineAsmCall(
const CallBase &
Call);
639 void verifyStatepoint(
const CallBase &
Call);
640 void verifyFrameRecoverIndices();
641 void verifySiblingFuncletUnwinds();
643 void verifyFragmentExpression(
const DbgVariableRecord &
I);
644 template <
typename ValueOrMetadata>
645 void verifyFragmentExpression(
const DIVariable &V,
647 ValueOrMetadata *
Desc);
648 void verifyFnArgs(
const DbgVariableRecord &DVR);
649 void verifyNotEntryValue(
const DbgVariableRecord &
I);
652 void verifyCompileUnits();
656 void verifyDeoptimizeCallingConvs();
658 void verifyAttachedCallBundle(
const CallBase &
Call,
659 const OperandBundleUse &BU);
662 void verifyNoAliasScopeDecl();
668#define Check(C, ...) \
671 CheckFailed(__VA_ARGS__); \
678#define CheckDI(C, ...) \
681 DebugInfoCheckFailed(__VA_ARGS__); \
689 CheckDI(
I.DebugMarker->MarkedInstr == &
I,
690 "Instruction has invalid DebugMarker", &
I);
692 "PHI Node must not have any attached DbgRecords", &
I);
695 "DbgRecord had invalid DebugMarker", &
I, &DR);
698 visitMDNode(*
Loc, AreDebugLocsAllowed::Yes);
703 verifyFragmentExpression(*DVR);
704 verifyNotEntryValue(*DVR);
711void Verifier::visit(Instruction &
I) {
713 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
714 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
726 while (!WorkList.
empty()) {
728 if (!Visited.
insert(Cur).second)
735void Verifier::visitGlobalValue(
const GlobalValue &GV) {
737 "Global is external, but doesn't have external or weak linkage!", &GV);
740 if (
const MDNode *Associated =
741 GO->getMetadata(LLVMContext::MD_associated)) {
742 Check(Associated->getNumOperands() == 1,
743 "associated metadata must have one operand", &GV, Associated);
744 const Metadata *
Op = Associated->getOperand(0).get();
745 Check(
Op,
"associated metadata must have a global value", GO, Associated);
748 Check(VM,
"associated metadata must be ValueAsMetadata", GO, Associated);
751 "associated value must be pointer typed", GV, Associated);
753 const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases();
755 "associated metadata must point to a GlobalObject", GO, Stripped);
756 Check(Stripped != GO,
757 "global values should not associate to themselves", GO,
763 if (
const MDNode *AbsoluteSymbol =
764 GO->getMetadata(LLVMContext::MD_absolute_symbol)) {
765 verifyRangeLikeMetadata(*GO, AbsoluteSymbol,
766 DL.getIntPtrType(GO->getType()),
767 RangeLikeMetadataKind::AbsoluteSymbol);
772 "Only global variables can have appending linkage!", &GV);
777 "Only global arrays can have appending linkage!", GVar);
781 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
785 "dllexport GlobalValue must have default or protected visibility",
790 "dllimport GlobalValue must have default visibility", &GV);
791 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
797 "Global is marked as dllimport, but not external", &GV);
802 "GlobalValue with local linkage or non-default "
803 "visibility must be dso_local!",
808 if (!
I->getParent() || !
I->getParent()->getParent())
809 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
811 else if (
I->getParent()->getParent()->getParent() != &M)
812 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
813 I->getParent()->getParent(),
814 I->getParent()->getParent()->getParent());
817 if (
F->getParent() != &M)
818 CheckFailed(
"Global is used by function in a different module", &GV, &M,
826void Verifier::visitGlobalVariable(
const GlobalVariable &GV) {
830 Check(
A->value() <= Value::MaximumAlignment,
831 "huge alignment values are unsupported", &GV);
836 "Global variable initializer type does not match global "
840 "Global variable initializer must be sized", &GV);
846 "'common' global must have a zero initializer!", &GV);
849 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
854 GV.
getName() ==
"llvm.global_dtors")) {
856 "invalid linkage for intrinsic global variable", &GV);
858 "invalid uses of intrinsic global variable", &GV);
865 PointerType::get(
Context,
DL.getProgramAddressSpace());
869 "wrong type for intrinsic global variable", &GV);
871 "the third field of the element type is mandatory, "
872 "specify ptr null to migrate from the obsoleted 2-field form");
880 GV.
getName() ==
"llvm.compiler.used")) {
882 "invalid linkage for intrinsic global variable", &GV);
884 "invalid uses of intrinsic global variable", &GV);
888 Check(PTy,
"wrong type for intrinsic global variable", &GV);
892 Check(InitArray,
"wrong initalizer for intrinsic global variable",
898 Twine(
"invalid ") + GV.
getName() +
" member", V);
900 Twine(
"members of ") + GV.
getName() +
" must be named", V);
909 for (
auto *MD : MDs) {
911 visitDIGlobalVariableExpression(*GVE);
913 CheckDI(
false,
"!dbg attachment of global variable must be a "
914 "DIGlobalVariableExpression");
924 "Global @" + GV.
getName() +
" has illegal target extension type",
928 visitGlobalValue(GV);
935 visitGlobalValue(GV);
938void Verifier::visitAliaseeSubExpr(
const GlobalAlias &GA,
const Constant &
C) {
939 SmallPtrSet<const GlobalAlias*, 4> Visited;
941 visitAliaseeSubExpr(Visited, GA,
C);
944void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited,
945 const GlobalAlias &GA,
const Constant &
C) {
949 "available_externally alias must point to available_externally "
960 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
962 Check(!GA2->isInterposable(),
963 "Alias cannot point to an interposable alias", &GA);
972 visitConstantExprsRecursively(CE);
974 for (
const Use &U :
C.operands()) {
977 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
979 visitAliaseeSubExpr(Visited, GA, *C2);
983void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
985 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
986 "weak_odr, external, or available_externally linkage!",
989 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
991 "Alias and aliasee types should match!", &GA);
994 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
996 visitAliaseeSubExpr(GA, *Aliasee);
998 visitGlobalValue(GA);
1001void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
1003 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
1004 "weak_odr, or external linkage!",
1009 Check(Resolver,
"IFunc must have a Function resolver", &GI);
1011 "IFunc resolver must be a definition", &GI);
1018 "IFunc resolver must return a pointer", &GI);
1021 "IFunc resolver has incorrect type", &GI);
1024void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1029 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1030 for (
const MDNode *MD : NMD.
operands()) {
1031 if (NMD.
getName() ==
"llvm.dbg.cu")
1037 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1041void Verifier::visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
1044 if (!MDNodes.
insert(&MD).second)
1048 "MDNode context does not match Module context!", &MD);
1053 case Metadata::MDTupleKind:
1055#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1056 case Metadata::CLASS##Kind: \
1057 visit##CLASS(cast<CLASS>(MD)); \
1059#include "llvm/IR/Metadata.def"
1068 "DILocation not allowed within this metadata node", &MD,
Op);
1070 visitMDNode(*
N, AllowLocs);
1074 visitValueAsMetadata(*V,
nullptr);
1084void Verifier::visitValueAsMetadata(
const ValueAsMetadata &MD, Function *
F) {
1087 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1093 Check(
F,
"function-local metadata used outside a function", L);
1099 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1105 assert(ActualF &&
"Unimplemented function local metadata case!");
1107 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1110void Verifier::visitDIArgList(
const DIArgList &AL, Function *
F) {
1111 for (
const ValueAsMetadata *VAM :
AL.getArgs())
1112 visitValueAsMetadata(*VAM,
F);
1115void Verifier::visitMetadataAsValue(
const MetadataAsValue &MDV, Function *
F) {
1118 visitMDNode(*
N, AreDebugLocsAllowed::No);
1124 if (!MDNodes.
insert(MD).second)
1128 visitValueAsMetadata(*V,
F);
1131 visitDIArgList(*AL,
F);
1138void Verifier::visitDILocation(
const DILocation &
N) {
1140 "location requires a valid scope", &
N,
N.getRawScope());
1141 if (
auto *IA =
N.getRawInlinedAt())
1144 CheckDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1147void Verifier::visitGenericDINode(
const GenericDINode &
N) {
1151void Verifier::visitDIScope(
const DIScope &
N) {
1152 if (
auto *
F =
N.getRawFile())
1156void Verifier::visitDISubrangeType(
const DISubrangeType &
N) {
1157 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1160 auto *LBound =
N.getRawLowerBound();
1163 "LowerBound must be signed constant or DIVariable or DIExpression",
1165 auto *UBound =
N.getRawUpperBound();
1168 "UpperBound must be signed constant or DIVariable or DIExpression",
1170 auto *Stride =
N.getRawStride();
1173 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1174 auto *Bias =
N.getRawBias();
1177 "Bias must be signed constant or DIVariable or DIExpression", &
N);
1179 auto *
Size =
N.getRawSizeInBits();
1181 "SizeInBits must be a constant");
1184void Verifier::visitDISubrange(
const DISubrange &
N) {
1185 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1186 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1187 "Subrange can have any one of count or upperBound", &
N);
1188 auto *CBound =
N.getRawCountNode();
1191 "Count must be signed constant or DIVariable or DIExpression", &
N);
1192 auto Count =
N.getCount();
1195 "invalid subrange count", &
N);
1196 auto *LBound =
N.getRawLowerBound();
1199 "LowerBound must be signed constant or DIVariable or DIExpression",
1201 auto *UBound =
N.getRawUpperBound();
1204 "UpperBound must be signed constant or DIVariable or DIExpression",
1206 auto *Stride =
N.getRawStride();
1209 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1212void Verifier::visitDIGenericSubrange(
const DIGenericSubrange &
N) {
1213 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1214 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1215 "GenericSubrange can have any one of count or upperBound", &
N);
1216 auto *CBound =
N.getRawCountNode();
1218 "Count must be signed constant or DIVariable or DIExpression", &
N);
1219 auto *LBound =
N.getRawLowerBound();
1220 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1222 "LowerBound must be signed constant or DIVariable or DIExpression",
1224 auto *UBound =
N.getRawUpperBound();
1226 "UpperBound must be signed constant or DIVariable or DIExpression",
1228 auto *Stride =
N.getRawStride();
1229 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1231 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1234void Verifier::visitDIEnumerator(
const DIEnumerator &
N) {
1235 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1238void Verifier::visitDIBasicType(
const DIBasicType &
N) {
1239 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1240 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1241 N.getTag() == dwarf::DW_TAG_string_type,
1244 auto *
Size =
N.getRawSizeInBits();
1246 "SizeInBits must be a constant");
1249void Verifier::visitDIFixedPointType(
const DIFixedPointType &
N) {
1250 visitDIBasicType(
N);
1252 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type,
"invalid tag", &
N);
1253 CheckDI(
N.getEncoding() == dwarf::DW_ATE_signed_fixed ||
1254 N.getEncoding() == dwarf::DW_ATE_unsigned_fixed,
1255 "invalid encoding", &
N);
1259 "invalid kind", &
N);
1261 N.getFactorRaw() == 0,
1262 "factor should be 0 for rationals", &
N);
1264 (
N.getNumeratorRaw() == 0 &&
N.getDenominatorRaw() == 0),
1265 "numerator and denominator should be 0 for non-rationals", &
N);
1268void Verifier::visitDIStringType(
const DIStringType &
N) {
1269 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1270 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1274void Verifier::visitDIDerivedType(
const DIDerivedType &
N) {
1278 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1279 N.getTag() == dwarf::DW_TAG_pointer_type ||
1280 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1281 N.getTag() == dwarf::DW_TAG_reference_type ||
1282 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1283 N.getTag() == dwarf::DW_TAG_const_type ||
1284 N.getTag() == dwarf::DW_TAG_immutable_type ||
1285 N.getTag() == dwarf::DW_TAG_volatile_type ||
1286 N.getTag() == dwarf::DW_TAG_restrict_type ||
1287 N.getTag() == dwarf::DW_TAG_atomic_type ||
1288 N.getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ||
1289 N.getTag() == dwarf::DW_TAG_member ||
1290 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1291 N.getTag() == dwarf::DW_TAG_inheritance ||
1292 N.getTag() == dwarf::DW_TAG_friend ||
1293 N.getTag() == dwarf::DW_TAG_set_type ||
1294 N.getTag() == dwarf::DW_TAG_template_alias,
1296 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1297 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1298 N.getRawExtraData());
1301 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1302 if (
auto *
T =
N.getRawBaseType()) {
1307 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1308 (Subrange &&
Subrange->getTag() == dwarf::DW_TAG_subrange_type) ||
1309 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1310 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1311 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1312 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1313 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1314 "invalid set base type", &
N,
T);
1320 N.getRawBaseType());
1322 if (
N.getDWARFAddressSpace()) {
1323 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1324 N.getTag() == dwarf::DW_TAG_reference_type ||
1325 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1326 "DWARF address space only applies to pointer or reference types",
1330 auto *
Size =
N.getRawSizeInBits();
1333 "SizeInBits must be a constant or DIVariable or DIExpression");
1338 return ((Flags & DINode::FlagLValueReference) &&
1339 (Flags & DINode::FlagRValueReference)) ||
1340 ((Flags & DINode::FlagTypePassByValue) &&
1341 (Flags & DINode::FlagTypePassByReference));
1344void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1346 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1353void Verifier::visitDICompositeType(
const DICompositeType &
N) {
1357 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1358 N.getTag() == dwarf::DW_TAG_structure_type ||
1359 N.getTag() == dwarf::DW_TAG_union_type ||
1360 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1361 N.getTag() == dwarf::DW_TAG_class_type ||
1362 N.getTag() == dwarf::DW_TAG_variant_part ||
1363 N.getTag() == dwarf::DW_TAG_variant ||
1364 N.getTag() == dwarf::DW_TAG_namelist,
1369 N.getRawBaseType());
1372 "invalid composite elements", &
N,
N.getRawElements());
1374 N.getRawVTableHolder());
1376 "invalid reference flags", &
N);
1377 unsigned DIBlockByRefStruct = 1 << 4;
1378 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1379 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1381 "DISubprogram contains null entry in `elements` field", &
N);
1384 const DINodeArray
Elements =
N.getElements();
1386 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1387 "invalid vector, expected one element of type subrange", &
N);
1390 if (
auto *Params =
N.getRawTemplateParams())
1391 visitTemplateParams(
N, *Params);
1393 if (
auto *
D =
N.getRawDiscriminator()) {
1395 "discriminator can only appear on variant part");
1398 if (
N.getRawDataLocation()) {
1399 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1400 "dataLocation can only appear in array type");
1403 if (
N.getRawAssociated()) {
1404 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1405 "associated can only appear in array type");
1408 if (
N.getRawAllocated()) {
1409 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1410 "allocated can only appear in array type");
1413 if (
N.getRawRank()) {
1414 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1415 "rank can only appear in array type");
1418 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1419 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1422 auto *
Size =
N.getRawSizeInBits();
1425 "SizeInBits must be a constant or DIVariable or DIExpression");
1428void Verifier::visitDISubroutineType(
const DISubroutineType &
N) {
1429 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1430 if (
auto *Types =
N.getRawTypeArray()) {
1432 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1433 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1437 "invalid reference flags", &
N);
1440void Verifier::visitDIFile(
const DIFile &
N) {
1441 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1442 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1444 CheckDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,
1445 "invalid checksum kind", &
N);
1447 switch (Checksum->Kind) {
1458 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1460 "invalid checksum", &
N);
1464void Verifier::visitDICompileUnit(
const DICompileUnit &
N) {
1465 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1466 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1472 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1476 "invalid emission kind", &
N);
1478 if (
auto *Array =
N.getRawEnumTypes()) {
1480 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1482 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1483 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1486 if (
auto *Array =
N.getRawRetainedTypes()) {
1488 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1492 "invalid retained type", &
N,
Op);
1495 if (
auto *Array =
N.getRawGlobalVariables()) {
1497 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1499 "invalid global variable ref", &
N,
Op);
1502 if (
auto *Array =
N.getRawImportedEntities()) {
1504 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1509 if (
auto *Array =
N.getRawMacros()) {
1518void Verifier::visitDISubprogram(
const DISubprogram &
N) {
1519 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1521 if (
auto *
F =
N.getRawFile())
1524 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1525 if (
auto *
T =
N.getRawType())
1527 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1528 N.getRawContainingType());
1529 if (
auto *Params =
N.getRawTemplateParams())
1530 visitTemplateParams(
N, *Params);
1531 if (
auto *S =
N.getRawDeclaration())
1533 "invalid subprogram declaration", &
N, S);
1534 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1536 CheckDI(Node,
"invalid retained nodes list", &
N, RawNode);
1540 "invalid retained nodes, expected DILocalVariable, DILabel or "
1546 "invalid reference flags", &
N);
1548 auto *Unit =
N.getRawUnit();
1549 if (
N.isDefinition()) {
1551 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1552 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1557 if (CT && CT->getRawIdentifier() &&
1558 M.getContext().isODRUniquingDebugTypes())
1560 "definition subprograms cannot be nested within DICompositeType "
1561 "when enabling ODR",
1565 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1567 "subprogram declaration must not have a declaration field");
1570 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1572 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1578 if (
N.areAllCallsDescribed())
1580 "DIFlagAllCallsDescribed must be attached to a definition");
1583void Verifier::visitDILexicalBlockBase(
const DILexicalBlockBase &
N) {
1584 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1586 "invalid local scope", &
N,
N.getRawScope());
1588 CheckDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1591void Verifier::visitDILexicalBlock(
const DILexicalBlock &
N) {
1592 visitDILexicalBlockBase(
N);
1595 "cannot have column info without line info", &
N);
1598void Verifier::visitDILexicalBlockFile(
const DILexicalBlockFile &
N) {
1599 visitDILexicalBlockBase(
N);
1602void Verifier::visitDICommonBlock(
const DICommonBlock &
N) {
1603 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1604 if (
auto *S =
N.getRawScope())
1606 if (
auto *S =
N.getRawDecl())
1610void Verifier::visitDINamespace(
const DINamespace &
N) {
1611 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1612 if (
auto *S =
N.getRawScope())
1616void Verifier::visitDIMacro(
const DIMacro &
N) {
1619 "invalid macinfo type", &
N);
1620 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1621 if (!
N.getValue().empty()) {
1622 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1626void Verifier::visitDIMacroFile(
const DIMacroFile &
N) {
1628 "invalid macinfo type", &
N);
1629 if (
auto *
F =
N.getRawFile())
1632 if (
auto *Array =
N.getRawElements()) {
1634 for (
Metadata *
Op :
N.getElements()->operands()) {
1640void Verifier::visitDIModule(
const DIModule &
N) {
1641 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1642 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1645void Verifier::visitDITemplateParameter(
const DITemplateParameter &
N) {
1649void Verifier::visitDITemplateTypeParameter(
const DITemplateTypeParameter &
N) {
1650 visitDITemplateParameter(
N);
1652 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1656void Verifier::visitDITemplateValueParameter(
1657 const DITemplateValueParameter &
N) {
1658 visitDITemplateParameter(
N);
1660 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1661 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1662 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1666void Verifier::visitDIVariable(
const DIVariable &
N) {
1667 if (
auto *S =
N.getRawScope())
1669 if (
auto *
F =
N.getRawFile())
1673void Verifier::visitDIGlobalVariable(
const DIGlobalVariable &
N) {
1677 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1680 if (
N.isDefinition())
1681 CheckDI(
N.getType(),
"missing global variable type", &
N);
1682 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1684 "invalid static data member declaration", &
N, Member);
1688void Verifier::visitDILocalVariable(
const DILocalVariable &
N) {
1693 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1695 "local variable requires a valid scope", &
N,
N.getRawScope());
1696 if (
auto Ty =
N.getType())
1700void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1701 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1702 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1705void Verifier::visitDILabel(
const DILabel &
N) {
1706 if (
auto *S =
N.getRawScope())
1708 if (
auto *
F =
N.getRawFile())
1711 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1713 "label requires a valid scope", &
N,
N.getRawScope());
1716void Verifier::visitDIExpression(
const DIExpression &
N) {
1717 CheckDI(
N.isValid(),
"invalid expression", &
N);
1720void Verifier::visitDIGlobalVariableExpression(
1721 const DIGlobalVariableExpression &GVE) {
1724 visitDIGlobalVariable(*Var);
1726 visitDIExpression(*Expr);
1727 if (
auto Fragment = Expr->getFragmentInfo())
1728 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1732void Verifier::visitDIObjCProperty(
const DIObjCProperty &
N) {
1733 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1734 if (
auto *
T =
N.getRawType())
1736 if (
auto *
F =
N.getRawFile())
1740void Verifier::visitDIImportedEntity(
const DIImportedEntity &
N) {
1741 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1742 N.getTag() == dwarf::DW_TAG_imported_declaration,
1744 if (
auto *S =
N.getRawScope())
1750void Verifier::visitComdat(
const Comdat &
C) {
1753 if (
TT.isOSBinFormatCOFF())
1754 if (
const GlobalValue *GV =
M.getNamedValue(
C.getName()))
1759void Verifier::visitModuleIdents() {
1760 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1766 for (
const MDNode *
N : Idents->
operands()) {
1767 Check(
N->getNumOperands() == 1,
1768 "incorrect number of operands in llvm.ident metadata",
N);
1770 (
"invalid value for llvm.ident metadata entry operand"
1771 "(the operand should be a string)"),
1776void Verifier::visitModuleCommandLines() {
1777 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1784 for (
const MDNode *
N : CommandLines->
operands()) {
1785 Check(
N->getNumOperands() == 1,
1786 "incorrect number of operands in llvm.commandline metadata",
N);
1788 (
"invalid value for llvm.commandline metadata entry operand"
1789 "(the operand should be a string)"),
1794void Verifier::visitModuleFlags() {
1795 const NamedMDNode *
Flags =
M.getModuleFlagsMetadata();
1799 DenseMap<const MDString*, const MDNode*> SeenIDs;
1801 uint64_t PAuthABIPlatform = -1;
1802 uint64_t PAuthABIVersion = -1;
1803 for (
const MDNode *MDN :
Flags->operands()) {
1804 visitModuleFlag(MDN, SeenIDs, Requirements);
1805 if (MDN->getNumOperands() != 3)
1808 if (FlagName->getString() ==
"aarch64-elf-pauthabi-platform") {
1809 if (
const auto *PAP =
1811 PAuthABIPlatform = PAP->getZExtValue();
1812 }
else if (FlagName->getString() ==
"aarch64-elf-pauthabi-version") {
1813 if (
const auto *PAV =
1815 PAuthABIVersion = PAV->getZExtValue();
1820 if ((PAuthABIPlatform == uint64_t(-1)) != (PAuthABIVersion == uint64_t(-1)))
1821 CheckFailed(
"either both or no 'aarch64-elf-pauthabi-platform' and "
1822 "'aarch64-elf-pauthabi-version' module flags must be present");
1825 for (
const MDNode *Requirement : Requirements) {
1827 const Metadata *ReqValue = Requirement->getOperand(1);
1829 const MDNode *
Op = SeenIDs.
lookup(Flag);
1831 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1836 if (
Op->getOperand(2) != ReqValue) {
1837 CheckFailed((
"invalid requirement on flag, "
1838 "flag does not have the required value"),
1846Verifier::visitModuleFlag(
const MDNode *
Op,
1847 DenseMap<const MDString *, const MDNode *> &SeenIDs,
1848 SmallVectorImpl<const MDNode *> &Requirements) {
1852 "incorrect number of operands in module flag",
Op);
1853 Module::ModFlagBehavior MFB;
1854 if (!Module::isValidModFlagBehavior(
Op->getOperand(0), MFB)) {
1856 "invalid behavior operand in module flag (expected constant integer)",
1859 "invalid behavior operand in module flag (unexpected constant)",
1863 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
1869 case Module::Warning:
1870 case Module::Override:
1876 Check(V &&
V->getValue().isNonNegative(),
1877 "invalid value for 'min' module flag (expected constant non-negative "
1885 "invalid value for 'max' module flag (expected constant integer)",
1890 case Module::Require: {
1895 "invalid value for 'require' module flag (expected metadata pair)",
1898 (
"invalid value for 'require' module flag "
1899 "(first value operand should be a string)"),
1900 Value->getOperand(0));
1908 case Module::Append:
1909 case Module::AppendUnique: {
1912 "invalid value for 'append'-type module flag "
1913 "(expected a metadata node)",
1920 if (MFB != Module::Require) {
1923 "module flag identifiers must be unique (or of 'require' type)",
ID);
1926 if (
ID->getString() ==
"wchar_size") {
1929 Check(
Value,
"wchar_size metadata requires constant integer argument");
1932 if (
ID->getString() ==
"Linker Options") {
1936 Check(
M.getNamedMetadata(
"llvm.linker.options"),
1937 "'Linker Options' named metadata no longer supported");
1940 if (
ID->getString() ==
"SemanticInterposition") {
1941 ConstantInt *
Value =
1944 "SemanticInterposition metadata requires constant integer argument");
1947 if (
ID->getString() ==
"CG Profile") {
1948 for (
const MDOperand &MDO :
cast<MDNode>(
Op->getOperand(2))->operands())
1949 visitModuleFlagCGProfileEntry(MDO);
1953void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1954 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1959 "expected a Function or null", FuncMDO);
1962 Check(Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1963 CheckFunction(
Node->getOperand(0));
1964 CheckFunction(
Node->getOperand(1));
1967 "expected an integer constant",
Node->getOperand(2));
1970void Verifier::verifyAttributeTypes(AttributeSet Attrs,
const Value *V) {
1973 if (
A.isStringAttribute()) {
1974#define GET_ATTR_NAMES
1975#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
1976#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1977 if (A.getKindAsString() == #DISPLAY_NAME) { \
1978 auto V = A.getValueAsString(); \
1979 if (!(V.empty() || V == "true" || V == "false")) \
1980 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
1984#include "llvm/IR/Attributes.inc"
1988 if (
A.isIntAttribute() != Attribute::isIntAttrKind(
A.getKindAsEnum())) {
1989 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
1998void Verifier::verifyParameterAttrs(AttributeSet Attrs,
Type *Ty,
2000 if (!
Attrs.hasAttributes())
2003 verifyAttributeTypes(Attrs, V);
2006 Check(Attr.isStringAttribute() ||
2007 Attribute::canUseAsParamAttr(Attr.getKindAsEnum()),
2008 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
2011 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
2012 unsigned AttrCount =
2013 Attrs.getNumAttributes() -
Attrs.hasAttribute(Attribute::Range);
2014 Check(AttrCount == 1,
2015 "Attribute 'immarg' is incompatible with other attributes except the "
2016 "'range' attribute",
2022 unsigned AttrCount = 0;
2023 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
2024 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
2025 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
2026 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
2027 Attrs.hasAttribute(Attribute::InReg);
2028 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
2029 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
2030 Check(AttrCount <= 1,
2031 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
2032 "'byref', and 'sret' are incompatible!",
2035 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
2036 Attrs.hasAttribute(Attribute::ReadOnly)),
2038 "'inalloca and readonly' are incompatible!",
2041 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
2042 Attrs.hasAttribute(Attribute::Returned)),
2044 "'sret and returned' are incompatible!",
2047 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
2048 Attrs.hasAttribute(Attribute::SExt)),
2050 "'zeroext and signext' are incompatible!",
2053 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
2054 Attrs.hasAttribute(Attribute::ReadOnly)),
2056 "'readnone and readonly' are incompatible!",
2059 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
2060 Attrs.hasAttribute(Attribute::WriteOnly)),
2062 "'readnone and writeonly' are incompatible!",
2065 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
2066 Attrs.hasAttribute(Attribute::WriteOnly)),
2068 "'readonly and writeonly' are incompatible!",
2071 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
2072 Attrs.hasAttribute(Attribute::AlwaysInline)),
2074 "'noinline and alwaysinline' are incompatible!",
2077 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2078 Attrs.hasAttribute(Attribute::ReadNone)),
2079 "Attributes writable and readnone are incompatible!", V);
2081 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2082 Attrs.hasAttribute(Attribute::ReadOnly)),
2083 "Attributes writable and readonly are incompatible!", V);
2085 AttributeMask IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty, Attrs);
2087 if (!Attr.isStringAttribute() &&
2088 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2089 CheckFailed(
"Attribute '" + Attr.getAsString() +
2090 "' applied to incompatible type!", V);
2096 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2097 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2098 Check(AttrAlign.
value() <= Value::MaximumAlignment,
2099 "huge alignment values are unsupported", V);
2101 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2103 SmallPtrSet<Type *, 4> Visited;
2105 "Attribute 'byval' does not support unsized types!", V);
2109 "'byval' argument has illegal target extension type", V);
2110 Check(
DL.getTypeAllocSize(ByValTy).getKnownMinValue() < (1ULL << 32),
2111 "huge 'byval' arguments are unsupported", V);
2113 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2114 SmallPtrSet<Type *, 4> Visited;
2115 Check(
Attrs.getByRefType()->isSized(&Visited),
2116 "Attribute 'byref' does not support unsized types!", V);
2117 Check(
DL.getTypeAllocSize(
Attrs.getByRefType()).getKnownMinValue() <
2119 "huge 'byref' arguments are unsupported", V);
2121 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2122 SmallPtrSet<Type *, 4> Visited;
2123 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2124 "Attribute 'inalloca' does not support unsized types!", V);
2125 Check(
DL.getTypeAllocSize(
Attrs.getInAllocaType()).getKnownMinValue() <
2127 "huge 'inalloca' arguments are unsupported", V);
2129 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2130 SmallPtrSet<Type *, 4> Visited;
2131 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2132 "Attribute 'preallocated' does not support unsized types!", V);
2134 DL.getTypeAllocSize(
Attrs.getPreallocatedType()).getKnownMinValue() <
2136 "huge 'preallocated' arguments are unsupported", V);
2140 if (
Attrs.hasAttribute(Attribute::Initializes)) {
2141 auto Inits =
Attrs.getAttribute(Attribute::Initializes).getInitializes();
2142 Check(!Inits.empty(),
"Attribute 'initializes' does not support empty list",
2145 "Attribute 'initializes' does not support unordered ranges", V);
2148 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2149 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2150 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2153 "Invalid value for 'nofpclass' test mask", V);
2155 if (
Attrs.hasAttribute(Attribute::Range)) {
2156 const ConstantRange &CR =
2157 Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2159 "Range bit width must match type bit width!", V);
2163void Verifier::checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr,
2165 if (
Attrs.hasFnAttr(Attr)) {
2166 StringRef S =
Attrs.getFnAttr(Attr).getValueAsString();
2169 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2175void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
2176 const Value *V,
bool IsIntrinsic,
2178 if (
Attrs.isEmpty())
2181 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2183 "Attribute list does not match Module context!", &Attrs, V);
2184 for (
const auto &AttrSet : Attrs) {
2185 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(
Context),
2186 "Attribute set does not match Module context!", &AttrSet, V);
2187 for (
const auto &
A : AttrSet) {
2189 "Attribute does not match Module context!", &
A, V);
2194 bool SawNest =
false;
2195 bool SawReturned =
false;
2196 bool SawSRet =
false;
2197 bool SawSwiftSelf =
false;
2198 bool SawSwiftAsync =
false;
2199 bool SawSwiftError =
false;
2202 AttributeSet RetAttrs =
Attrs.getRetAttrs();
2205 Attribute::canUseAsRetAttr(
RetAttr.getKindAsEnum()),
2206 "Attribute '" +
RetAttr.getAsString() +
2207 "' does not apply to function return values",
2210 unsigned MaxParameterWidth = 0;
2211 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2214 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2215 if (
Size > MaxParameterWidth)
2216 MaxParameterWidth =
Size;
2220 GetMaxParameterWidth(FT->getReturnType());
2221 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2224 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2225 Type *Ty = FT->getParamType(i);
2226 AttributeSet ArgAttrs =
Attrs.getParamAttrs(i);
2230 "immarg attribute only applies to intrinsics", V);
2233 "Attribute 'elementtype' can only be applied to intrinsics"
2238 verifyParameterAttrs(ArgAttrs, Ty, V);
2239 GetMaxParameterWidth(Ty);
2242 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2247 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2249 "Incompatible argument and return types for 'returned' attribute",
2255 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2256 Check(i == 0 || i == 1,
2257 "Attribute 'sret' is not on first or second parameter!", V);
2262 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2263 SawSwiftSelf =
true;
2267 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2268 SawSwiftAsync =
true;
2272 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2273 SawSwiftError =
true;
2277 Check(i == FT->getNumParams() - 1,
2278 "inalloca isn't on the last parameter!", V);
2282 if (!
Attrs.hasFnAttrs())
2285 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2288 Attribute::canUseAsFnAttr(
FnAttr.getKindAsEnum()),
2289 "Attribute '" +
FnAttr.getAsString() +
2290 "' does not apply to functions!",
2293 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2294 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2295 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2297 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2299 "Attribute 'optnone' requires 'noinline'!", V);
2301 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2302 "Attributes 'optsize and optnone' are incompatible!", V);
2305 "Attributes 'minsize and optnone' are incompatible!", V);
2307 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2308 "Attributes 'optdebug and optnone' are incompatible!", V);
2311 Check(!(
Attrs.hasFnAttr(Attribute::SanitizeRealtime) &&
2312 Attrs.hasFnAttr(Attribute::SanitizeRealtimeBlocking)),
2314 "'sanitize_realtime and sanitize_realtime_blocking' are incompatible!",
2317 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2318 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2319 "Attributes 'optsize and optdebug' are incompatible!", V);
2322 "Attributes 'minsize and optdebug' are incompatible!", V);
2325 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2326 isModSet(
Attrs.getMemoryEffects().getModRef(IRMemLocation::ArgMem)),
2327 "Attribute writable and memory without argmem: write are incompatible!",
2330 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2331 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2332 "Attributes 'aarch64_pstate_sm_enabled and "
2333 "aarch64_pstate_sm_compatible' are incompatible!",
2337 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2338 Attrs.hasFnAttr(
"aarch64_inout_za") +
2339 Attrs.hasFnAttr(
"aarch64_out_za") +
2340 Attrs.hasFnAttr(
"aarch64_preserves_za") +
2341 Attrs.hasFnAttr(
"aarch64_za_state_agnostic")) <= 1,
2342 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2343 "'aarch64_inout_za', 'aarch64_preserves_za' and "
2344 "'aarch64_za_state_agnostic' are mutually exclusive",
2348 Attrs.hasFnAttr(
"aarch64_in_zt0") +
2349 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2350 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2351 Attrs.hasFnAttr(
"aarch64_preserves_zt0") +
2352 Attrs.hasFnAttr(
"aarch64_za_state_agnostic")) <= 1,
2353 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2354 "'aarch64_inout_zt0', 'aarch64_preserves_zt0' and "
2355 "'aarch64_za_state_agnostic' are mutually exclusive",
2358 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2361 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2364 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2365 auto CheckParam = [&](StringRef
Name,
unsigned ParamNo) {
2366 if (ParamNo >= FT->getNumParams()) {
2367 CheckFailed(
"'allocsize' " + Name +
" argument is out of bounds", V);
2371 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2372 CheckFailed(
"'allocsize' " + Name +
2373 " argument must refer to an integer parameter",
2381 if (!CheckParam(
"element size",
Args->first))
2384 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2388 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2391 K & (AllocFnKind::Alloc | AllocFnKind::Realloc | AllocFnKind::Free);
2393 {AllocFnKind::Alloc, AllocFnKind::Realloc, AllocFnKind::Free},
2396 "'allockind()' requires exactly one of alloc, realloc, and free");
2397 if ((
Type == AllocFnKind::Free) &&
2398 ((K & (AllocFnKind::Uninitialized | AllocFnKind::Zeroed |
2399 AllocFnKind::Aligned)) != AllocFnKind::Unknown))
2400 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2401 "or aligned modifiers.");
2402 AllocFnKind ZeroedUninit = AllocFnKind::Uninitialized | AllocFnKind::Zeroed;
2403 if ((K & ZeroedUninit) == ZeroedUninit)
2404 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2408 StringRef S =
A.getValueAsString();
2409 Check(!S.
empty(),
"'alloc-variant-zeroed' must not be empty");
2417 "'alloc-variant-zeroed' must name a function belonging to the "
2418 "same 'alloc-family'");
2421 (
Variant->getFnAttribute(Attribute::AllocKind).getAllocKind() &
2422 AllocFnKind::Zeroed) != AllocFnKind::Unknown,
2423 "'alloc-variant-zeroed' must name a function with "
2424 "'allockind(\"zeroed\")'");
2427 "'alloc-variant-zeroed' must name a function with the same "
2432 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2433 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2435 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2437 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2438 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2439 if (VScaleMax && VScaleMin > VScaleMax)
2440 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2442 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2445 if (
Attribute FPAttr =
Attrs.getFnAttr(
"frame-pointer"); FPAttr.isValid()) {
2446 StringRef
FP = FPAttr.getValueAsString();
2447 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none" &&
FP !=
"reserved")
2448 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2451 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2452 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2453 if (
Attrs.hasFnAttr(
"patchable-function-entry-section"))
2454 Check(!
Attrs.getFnAttr(
"patchable-function-entry-section")
2457 "\"patchable-function-entry-section\" must not be empty");
2458 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2460 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2461 StringRef S =
A.getValueAsString();
2462 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2463 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2466 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2467 StringRef S =
A.getValueAsString();
2468 if (S !=
"a_key" && S !=
"b_key")
2469 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2471 if (
auto AA =
Attrs.getFnAttr(
"sign-return-address"); !AA.isValid()) {
2473 "'sign-return-address-key' present without `sign-return-address`");
2477 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2478 StringRef S =
A.getValueAsString();
2479 if (S !=
"" && S !=
"true" && S !=
"false")
2481 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2484 if (
auto A =
Attrs.getFnAttr(
"branch-protection-pauth-lr");
A.isValid()) {
2485 StringRef S =
A.getValueAsString();
2486 if (S !=
"" && S !=
"true" && S !=
"false")
2488 "invalid value for 'branch-protection-pauth-lr' attribute: " + S, V);
2491 if (
auto A =
Attrs.getFnAttr(
"guarded-control-stack");
A.isValid()) {
2492 StringRef S =
A.getValueAsString();
2493 if (S !=
"" && S !=
"true" && S !=
"false")
2494 CheckFailed(
"invalid value for 'guarded-control-stack' attribute: " + S,
2498 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2499 StringRef S =
A.getValueAsString();
2502 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2505 if (
auto A =
Attrs.getFnAttr(
"denormal-fp-math");
A.isValid()) {
2506 StringRef S =
A.getValueAsString();
2508 CheckFailed(
"invalid value for 'denormal-fp-math' attribute: " + S, V);
2511 if (
auto A =
Attrs.getFnAttr(
"denormal-fp-math-f32");
A.isValid()) {
2512 StringRef S =
A.getValueAsString();
2514 CheckFailed(
"invalid value for 'denormal-fp-math-f32' attribute: " + S,
2519void Verifier::verifyFunctionMetadata(
2520 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2521 for (
const auto &Pair : MDs) {
2522 if (Pair.first == LLVMContext::MD_prof) {
2523 MDNode *MD = Pair.second;
2530 "!prof annotations should have no less than 2 operands", MD);
2533 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2536 "expected string with name of the !prof annotation", MD);
2541 "first operand should be 'function_entry_count'"
2542 " or 'synthetic_function_entry_count'",
2546 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2549 "expected integer argument to function_entry_count", MD);
2550 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2551 MDNode *MD = Pair.second;
2553 "!kcfi_type must have exactly one operand", MD);
2554 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2557 "expected a constant operand for !kcfi_type", MD);
2560 "expected a constant integer operand for !kcfi_type", MD);
2562 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2567void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2568 if (!ConstantExprVisited.
insert(EntryC).second)
2572 Stack.push_back(EntryC);
2574 while (!
Stack.empty()) {
2579 visitConstantExpr(CE);
2582 visitConstantPtrAuth(CPA);
2587 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2593 for (
const Use &U :
C->operands()) {
2597 if (!ConstantExprVisited.
insert(OpC).second)
2599 Stack.push_back(OpC);
2604void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2605 if (
CE->getOpcode() == Instruction::BitCast)
2608 "Invalid bitcast", CE);
2609 else if (
CE->getOpcode() == Instruction::PtrToAddr)
2610 checkPtrToAddr(
CE->getOperand(0)->getType(),
CE->getType(), *CE);
2613void Verifier::visitConstantPtrAuth(
const ConstantPtrAuth *CPA) {
2615 "signed ptrauth constant base pointer must have pointer type");
2618 "signed ptrauth constant must have same type as its base pointer");
2621 "signed ptrauth constant key must be i32 constant integer");
2624 "signed ptrauth constant address discriminator must be a pointer");
2627 "signed ptrauth constant discriminator must be i64 constant integer");
2630bool Verifier::verifyAttributeCount(AttributeList Attrs,
unsigned Params) {
2633 return Attrs.getNumAttrSets() <= Params + 2;
2636void Verifier::verifyInlineAsmCall(
const CallBase &
Call) {
2639 unsigned LabelNo = 0;
2640 for (
const InlineAsm::ConstraintInfo &CI :
IA->ParseConstraints()) {
2650 if (CI.isIndirect) {
2653 "Operand for indirect constraint must have pointer type", &
Call);
2656 "Operand for indirect constraint must have elementtype attribute",
2660 "Elementtype attribute can only be applied for indirect "
2669 Check(LabelNo == CallBr->getNumIndirectDests(),
2670 "Number of label constraints does not match number of callbr dests",
2673 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
2679void Verifier::verifyStatepoint(
const CallBase &
Call) {
2684 "gc.statepoint must read and write all memory to preserve "
2685 "reordering restrictions required by safepoint semantics",
2688 const int64_t NumPatchBytes =
2691 Check(NumPatchBytes >= 0,
2692 "gc.statepoint number of patchable bytes must be "
2697 Check(TargetElemType,
2698 "gc.statepoint callee argument must have elementtype attribute",
Call);
2700 Check(TargetFuncType,
2701 "gc.statepoint callee elementtype must be function type",
Call);
2704 Check(NumCallArgs >= 0,
2705 "gc.statepoint number of arguments to underlying call "
2708 const int NumParams = (int)TargetFuncType->getNumParams();
2709 if (TargetFuncType->isVarArg()) {
2710 Check(NumCallArgs >= NumParams,
2711 "gc.statepoint mismatch in number of vararg call args",
Call);
2714 Check(TargetFuncType->getReturnType()->isVoidTy(),
2715 "gc.statepoint doesn't support wrapping non-void "
2716 "vararg functions yet",
2719 Check(NumCallArgs == NumParams,
2720 "gc.statepoint mismatch in number of call args",
Call);
2722 const uint64_t
Flags
2724 Check((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0,
2725 "unknown flag used in gc.statepoint flags argument",
Call);
2730 for (
int i = 0; i < NumParams; i++) {
2731 Type *ParamType = TargetFuncType->getParamType(i);
2733 Check(ArgType == ParamType,
2734 "gc.statepoint call argument does not match wrapped "
2738 if (TargetFuncType->isVarArg()) {
2739 AttributeSet ArgAttrs =
Attrs.getParamAttrs(5 + i);
2741 "Attribute 'sret' cannot be used for vararg call arguments!",
Call);
2745 const int EndCallArgsInx = 4 + NumCallArgs;
2749 "gc.statepoint number of transition arguments "
2750 "must be constant integer",
2752 const int NumTransitionArgs =
2754 Check(NumTransitionArgs == 0,
2755 "gc.statepoint w/inline transition bundle is deprecated",
Call);
2756 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2760 "gc.statepoint number of deoptimization arguments "
2761 "must be constant integer",
2764 Check(NumDeoptArgs == 0,
2765 "gc.statepoint w/inline deopt operands is deprecated",
Call);
2767 const int ExpectedNumArgs = 7 + NumCallArgs;
2769 "gc.statepoint too many arguments",
Call);
2776 Check(UserCall,
"illegal use of statepoint token",
Call, U);
2780 "gc.result or gc.relocate are the only value uses "
2781 "of a gc.statepoint",
2785 "gc.result connected to wrong gc.statepoint",
Call, UserCall);
2788 "gc.relocate connected to wrong gc.statepoint",
Call, UserCall);
2802void Verifier::verifyFrameRecoverIndices() {
2803 for (
auto &Counts : FrameEscapeInfo) {
2805 unsigned EscapedObjectCount = Counts.second.first;
2806 unsigned MaxRecoveredIndex = Counts.second.second;
2807 Check(MaxRecoveredIndex <= EscapedObjectCount,
2808 "all indices passed to llvm.localrecover must be less than the "
2809 "number of arguments passed to llvm.localescape in the parent "
2818 UnwindDest =
II->getUnwindDest();
2820 UnwindDest = CSI->getUnwindDest();
2826void Verifier::verifySiblingFuncletUnwinds() {
2827 llvm::TimeTraceScope timeScope(
"Verifier verify sibling funclet unwinds");
2828 SmallPtrSet<Instruction *, 8> Visited;
2829 SmallPtrSet<Instruction *, 8>
Active;
2830 for (
const auto &Pair : SiblingFuncletInfo) {
2832 if (Visited.
count(PredPad))
2838 if (
Active.count(SuccPad)) {
2841 SmallVector<Instruction *, 8> CycleNodes;
2844 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2845 if (CycleTerminator != CyclePad)
2848 }
while (CyclePad != SuccPad);
2849 Check(
false,
"EH pads can't handle each other's exceptions",
2853 if (!Visited.
insert(SuccPad).second)
2857 auto TermI = SiblingFuncletInfo.find(PredPad);
2858 if (TermI == SiblingFuncletInfo.end())
2871void Verifier::visitFunction(
const Function &
F) {
2872 visitGlobalValue(
F);
2875 FunctionType *FT =
F.getFunctionType();
2876 unsigned NumArgs =
F.arg_size();
2879 "Function context does not match Module context!", &
F);
2881 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
2882 Check(FT->getNumParams() == NumArgs,
2883 "# formal arguments must match # of arguments for function type!", &
F,
2885 Check(
F.getReturnType()->isFirstClassType() ||
2886 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
2887 "Functions cannot return aggregate values!", &
F);
2889 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
2890 "Invalid struct return type!", &
F);
2892 if (MaybeAlign
A =
F.getAlign()) {
2893 Check(
A->value() <= Value::MaximumAlignment,
2894 "huge alignment values are unsupported", &
F);
2897 AttributeList
Attrs =
F.getAttributes();
2899 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
2900 "Attribute after last parameter!", &
F);
2902 bool IsIntrinsic =
F.isIntrinsic();
2905 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
2911 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2913 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
2914 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
2917 "Attribute 'aarch64_zt0_undef' can only be applied to a callsite.");
2919 if (
Attrs.hasFnAttr(Attribute::Naked))
2920 for (
const Argument &Arg :
F.args())
2921 Check(Arg.use_empty(),
"cannot use argument of naked function", &Arg);
2926 switch (
F.getCallingConv()) {
2928 case CallingConv::C:
2930 case CallingConv::X86_INTR: {
2931 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
2932 "Calling convention parameter requires byval", &
F);
2935 case CallingConv::AMDGPU_KERNEL:
2936 case CallingConv::SPIR_KERNEL:
2937 case CallingConv::AMDGPU_CS_Chain:
2938 case CallingConv::AMDGPU_CS_ChainPreserve:
2939 Check(
F.getReturnType()->isVoidTy(),
2940 "Calling convention requires void return type", &
F);
2942 case CallingConv::AMDGPU_VS:
2943 case CallingConv::AMDGPU_HS:
2944 case CallingConv::AMDGPU_GS:
2945 case CallingConv::AMDGPU_PS:
2946 case CallingConv::AMDGPU_CS:
2947 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
2948 if (
F.getCallingConv() != CallingConv::SPIR_KERNEL) {
2949 const unsigned StackAS =
DL.getAllocaAddrSpace();
2951 for (
const Argument &Arg :
F.args()) {
2952 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
2953 "Calling convention disallows byval", &
F);
2954 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
2955 "Calling convention disallows preallocated", &
F);
2956 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
2957 "Calling convention disallows inalloca", &
F);
2959 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
2962 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
2963 "Calling convention disallows stack byref", &
F);
2971 case CallingConv::Fast:
2972 case CallingConv::Cold:
2973 case CallingConv::Intel_OCL_BI:
2974 case CallingConv::PTX_Kernel:
2975 case CallingConv::PTX_Device:
2977 "Calling convention does not support varargs or "
2978 "perfect forwarding!",
2981 case CallingConv::AMDGPU_Gfx_WholeWave:
2982 Check(!
F.arg_empty() &&
F.arg_begin()->getType()->isIntegerTy(1),
2983 "Calling convention requires first argument to be i1", &
F);
2984 Check(!
F.arg_begin()->hasInRegAttr(),
2985 "Calling convention requires first argument to not be inreg", &
F);
2987 "Calling convention does not support varargs or "
2988 "perfect forwarding!",
2995 for (
const Argument &Arg :
F.args()) {
2996 Check(Arg.getType() == FT->getParamType(i),
2997 "Argument value does not match function argument type!", &Arg,
2998 FT->getParamType(i));
2999 Check(Arg.getType()->isFirstClassType(),
3000 "Function arguments must have first-class types!", &Arg);
3002 Check(!Arg.getType()->isMetadataTy(),
3003 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
3004 Check(!Arg.getType()->isTokenLikeTy(),
3005 "Function takes token but isn't an intrinsic", &Arg, &
F);
3006 Check(!Arg.getType()->isX86_AMXTy(),
3007 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
3011 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
3012 verifySwiftErrorValue(&Arg);
3018 Check(!
F.getReturnType()->isTokenLikeTy(),
3019 "Function returns a token but isn't an intrinsic", &
F);
3020 Check(!
F.getReturnType()->isX86_AMXTy(),
3021 "Function returns a x86_amx but isn't an intrinsic", &
F);
3026 F.getAllMetadata(MDs);
3027 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
3028 verifyFunctionMetadata(MDs);
3031 if (
F.hasPersonalityFn()) {
3034 Check(Per->getParent() ==
F.getParent(),
3035 "Referencing personality function in another module!", &
F,
3036 F.getParent(), Per, Per->getParent());
3040 BlockEHFuncletColors.
clear();
3042 if (
F.isMaterializable()) {
3044 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
3046 }
else if (
F.isDeclaration()) {
3047 for (
const auto &
I : MDs) {
3049 CheckDI(
I.first != LLVMContext::MD_dbg ||
3051 "function declaration may only have a unique !dbg attachment",
3053 Check(
I.first != LLVMContext::MD_prof,
3054 "function declaration may not have a !prof attachment", &
F);
3057 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
3059 Check(!
F.hasPersonalityFn(),
3060 "Function declaration shouldn't have a personality routine", &
F);
3064 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
3069 "Entry block to function must not have predecessors!", Entry);
3072 if (
Entry->hasAddressTaken()) {
3074 "blockaddress may not be used with the entry block!", Entry);
3077 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
3078 NumKCFIAttachments = 0;
3080 for (
const auto &
I : MDs) {
3082 auto AllowLocs = AreDebugLocsAllowed::No;
3086 case LLVMContext::MD_dbg: {
3087 ++NumDebugAttachments;
3088 CheckDI(NumDebugAttachments == 1,
3089 "function must have a single !dbg attachment", &
F,
I.second);
3091 "function !dbg attachment must be a subprogram", &
F,
I.second);
3093 "function definition may only have a distinct !dbg attachment",
3097 const Function *&AttachedTo = DISubprogramAttachments[
SP];
3098 CheckDI(!AttachedTo || AttachedTo == &
F,
3099 "DISubprogram attached to more than one function", SP, &
F);
3101 AllowLocs = AreDebugLocsAllowed::Yes;
3104 case LLVMContext::MD_prof:
3105 ++NumProfAttachments;
3106 Check(NumProfAttachments == 1,
3107 "function must have a single !prof attachment", &
F,
I.second);
3109 case LLVMContext::MD_kcfi_type:
3110 ++NumKCFIAttachments;
3111 Check(NumKCFIAttachments == 1,
3112 "function must have a single !kcfi_type attachment", &
F,
3118 visitMDNode(*
I.second, AllowLocs);
3126 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
3128 if (
F.hasAddressTaken(&U,
false,
true,
false,
3130 Check(
false,
"Invalid user of intrinsic instruction!", U);
3134 switch (
F.getIntrinsicID()) {
3135 case Intrinsic::experimental_gc_get_pointer_base: {
3136 FunctionType *FT =
F.getFunctionType();
3137 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
3139 "gc.get.pointer.base must return a pointer",
F);
3140 Check(FT->getParamType(0) ==
F.getReturnType(),
3141 "gc.get.pointer.base operand and result must be of the same type",
F);
3144 case Intrinsic::experimental_gc_get_pointer_offset: {
3145 FunctionType *FT =
F.getFunctionType();
3146 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
3148 "gc.get.pointer.offset operand must be a pointer",
F);
3149 Check(
F.getReturnType()->isIntegerTy(),
3150 "gc.get.pointer.offset must return integer",
F);
3155 auto *
N =
F.getSubprogram();
3156 HasDebugInfo = (
N !=
nullptr);
3164 SmallPtrSet<const MDNode *, 32> Seen;
3176 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
3178 DILocalScope *
Scope =
DL->getInlinedAtScope();
3179 Check(Scope,
"Failed to find DILocalScope",
DL);
3181 if (!Seen.
insert(Scope).second)
3184 DISubprogram *
SP =
Scope->getSubprogram();
3188 if ((Scope != SP) && !Seen.
insert(SP).second)
3192 "!dbg attachment points at wrong subprogram for function",
N, &
F,
3196 for (
auto &
I : BB) {
3197 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
3199 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
3202 if (BrokenDebugInfo)
3209void Verifier::visitBasicBlock(BasicBlock &BB) {
3210 InstsInThisBlock.
clear();
3211 ConvergenceVerifyHelper.
visit(BB);
3222 for (
const PHINode &PN : BB.
phis()) {
3223 Check(PN.getNumIncomingValues() == Preds.size(),
3224 "PHINode should have one entry for each predecessor of its "
3225 "parent basic block!",
3230 Values.
reserve(PN.getNumIncomingValues());
3231 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3233 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3236 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3241 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3242 Values[i].second == Values[i - 1].second,
3243 "PHI node has multiple entries for the same basic block with "
3244 "different incoming values!",
3245 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3249 Check(Values[i].first == Preds[i],
3250 "PHI node entries do not match predecessors!", &PN,
3251 Values[i].first, Preds[i]);
3259 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3263 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3267void Verifier::visitTerminator(Instruction &
I) {
3269 Check(&
I ==
I.getParent()->getTerminator(),
3270 "Terminator found in the middle of a basic block!",
I.getParent());
3271 visitInstruction(
I);
3274void Verifier::visitBranchInst(BranchInst &BI) {
3277 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3279 visitTerminator(BI);
3282void Verifier::visitReturnInst(ReturnInst &RI) {
3285 if (
F->getReturnType()->isVoidTy())
3287 "Found return instr that returns non-void in Function of void "
3289 &RI,
F->getReturnType());
3292 "Function return type does not match operand "
3293 "type of return inst!",
3294 &RI,
F->getReturnType());
3298 visitTerminator(RI);
3301void Verifier::visitSwitchInst(SwitchInst &SI) {
3302 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3305 Type *SwitchTy =
SI.getCondition()->getType();
3306 SmallPtrSet<ConstantInt*, 32>
Constants;
3307 for (
auto &Case :
SI.cases()) {
3309 "Case value is not a constant integer.", &SI);
3310 Check(Case.getCaseValue()->getType() == SwitchTy,
3311 "Switch constants must all be same type as switch value!", &SI);
3313 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3316 visitTerminator(SI);
3319void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
3321 "Indirectbr operand must have pointer type!", &BI);
3324 "Indirectbr destinations must all have pointer type!", &BI);
3326 visitTerminator(BI);
3329void Verifier::visitCallBrInst(CallBrInst &CBI) {
3330 Check(CBI.
isInlineAsm(),
"Callbr is currently only used for asm-goto!", &CBI);
3332 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3334 verifyInlineAsmCall(CBI);
3335 visitTerminator(CBI);
3338void Verifier::visitSelectInst(SelectInst &SI) {
3341 "Invalid operands for select instruction!", &SI);
3343 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3344 "Select values must have same type as select instruction!", &SI);
3345 visitInstruction(SI);
3351void Verifier::visitUserOp1(Instruction &
I) {
3352 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3355void Verifier::visitTruncInst(TruncInst &
I) {
3357 Type *SrcTy =
I.getOperand(0)->getType();
3358 Type *DestTy =
I.getType();
3367 "trunc source and destination must both be a vector or neither", &
I);
3368 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3370 visitInstruction(
I);
3373void Verifier::visitZExtInst(ZExtInst &
I) {
3375 Type *SrcTy =
I.getOperand(0)->getType();
3376 Type *DestTy =
I.getType();
3382 "zext source and destination must both be a vector or neither", &
I);
3386 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3388 visitInstruction(
I);
3391void Verifier::visitSExtInst(SExtInst &
I) {
3393 Type *SrcTy =
I.getOperand(0)->getType();
3394 Type *DestTy =
I.getType();
3403 "sext source and destination must both be a vector or neither", &
I);
3404 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3406 visitInstruction(
I);
3409void Verifier::visitFPTruncInst(FPTruncInst &
I) {
3411 Type *SrcTy =
I.getOperand(0)->getType();
3412 Type *DestTy =
I.getType();
3420 "fptrunc source and destination must both be a vector or neither", &
I);
3421 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3423 visitInstruction(
I);
3426void Verifier::visitFPExtInst(FPExtInst &
I) {
3428 Type *SrcTy =
I.getOperand(0)->getType();
3429 Type *DestTy =
I.getType();
3438 "fpext source and destination must both be a vector or neither", &
I);
3439 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3441 visitInstruction(
I);
3444void Verifier::visitUIToFPInst(UIToFPInst &
I) {
3446 Type *SrcTy =
I.getOperand(0)->getType();
3447 Type *DestTy =
I.getType();
3452 Check(SrcVec == DstVec,
3453 "UIToFP source and dest must both be vector or scalar", &
I);
3455 "UIToFP source must be integer or integer vector", &
I);
3459 if (SrcVec && DstVec)
3462 "UIToFP source and dest vector length mismatch", &
I);
3464 visitInstruction(
I);
3467void Verifier::visitSIToFPInst(SIToFPInst &
I) {
3469 Type *SrcTy =
I.getOperand(0)->getType();
3470 Type *DestTy =
I.getType();
3475 Check(SrcVec == DstVec,
3476 "SIToFP source and dest must both be vector or scalar", &
I);
3478 "SIToFP source must be integer or integer vector", &
I);
3482 if (SrcVec && DstVec)
3485 "SIToFP source and dest vector length mismatch", &
I);
3487 visitInstruction(
I);
3490void Verifier::visitFPToUIInst(FPToUIInst &
I) {
3492 Type *SrcTy =
I.getOperand(0)->getType();
3493 Type *DestTy =
I.getType();
3498 Check(SrcVec == DstVec,
3499 "FPToUI source and dest must both be vector or scalar", &
I);
3502 "FPToUI result must be integer or integer vector", &
I);
3504 if (SrcVec && DstVec)
3507 "FPToUI source and dest vector length mismatch", &
I);
3509 visitInstruction(
I);
3512void Verifier::visitFPToSIInst(FPToSIInst &
I) {
3514 Type *SrcTy =
I.getOperand(0)->getType();
3515 Type *DestTy =
I.getType();
3520 Check(SrcVec == DstVec,
3521 "FPToSI source and dest must both be vector or scalar", &
I);
3524 "FPToSI result must be integer or integer vector", &
I);
3526 if (SrcVec && DstVec)
3529 "FPToSI source and dest vector length mismatch", &
I);
3531 visitInstruction(
I);
3534void Verifier::checkPtrToAddr(
Type *SrcTy,
Type *DestTy,
const Value &V) {
3543 Check(VSrc->getElementCount() == VDest->getElementCount(),
3544 "PtrToAddr vector length mismatch", V);
3547 Type *AddrTy =
DL.getAddressType(SrcTy);
3548 Check(AddrTy == DestTy,
"PtrToAddr result must be address width", V);
3551void Verifier::visitPtrToAddrInst(PtrToAddrInst &
I) {
3552 checkPtrToAddr(
I.getOperand(0)->getType(),
I.getType(),
I);
3553 visitInstruction(
I);
3556void Verifier::visitPtrToIntInst(PtrToIntInst &
I) {
3558 Type *SrcTy =
I.getOperand(0)->getType();
3559 Type *DestTy =
I.getType();
3570 Check(VSrc->getElementCount() == VDest->getElementCount(),
3571 "PtrToInt Vector length mismatch", &
I);
3574 visitInstruction(
I);
3577void Verifier::visitIntToPtrInst(IntToPtrInst &
I) {
3579 Type *SrcTy =
I.getOperand(0)->getType();
3580 Type *DestTy =
I.getType();
3590 Check(VSrc->getElementCount() == VDest->getElementCount(),
3591 "IntToPtr Vector length mismatch", &
I);
3593 visitInstruction(
I);
3596void Verifier::visitBitCastInst(BitCastInst &
I) {
3599 "Invalid bitcast", &
I);
3600 visitInstruction(
I);
3603void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &
I) {
3604 Type *SrcTy =
I.getOperand(0)->getType();
3605 Type *DestTy =
I.getType();
3612 "AddrSpaceCast must be between different address spaces", &
I);
3614 Check(SrcVTy->getElementCount() ==
3616 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3617 visitInstruction(
I);
3622void Verifier::visitPHINode(PHINode &PN) {
3629 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
3638 "PHI node operands are not the same type as the result!", &PN);
3643 visitInstruction(PN);
3646void Verifier::visitCallBase(CallBase &
Call) {
3648 "Called function must be a pointer!",
Call);
3652 if (FTy->isVarArg())
3654 "Called function requires more parameters than were provided!",
Call);
3657 "Incorrect number of arguments passed to called function!",
Call);
3660 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3662 "Call parameter type does not match function signature!",
3668 "Attribute after last parameter!",
Call);
3675 "Intrinsic called with incompatible signature",
Call);
3679 "calling convention does not permit calls",
Call);
3685 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
3688 Align ABIAlign =
DL.getABITypeAlign(Ty);
3689 Check(ABIAlign.
value() <= Value::MaximumAlignment,
3690 "Incorrect alignment of " + Message +
" to called function!",
Call);
3694 VerifyTypeAlign(FTy->getReturnType(),
"return type");
3695 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3696 Type *Ty = FTy->getParamType(i);
3697 VerifyTypeAlign(Ty,
"argument passed");
3701 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
3705 "speculatable attribute may not apply to call sites",
Call);
3708 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
3710 "preallocated as a call site attribute can only be on "
3711 "llvm.call.preallocated.arg");
3723 Check(AI->isUsedWithInAlloca(),
3724 "inalloca argument for call has mismatched alloca", AI,
Call);
3730 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3734 Check(AI->isSwiftError(),
3735 "swifterror argument for call has mismatched alloca", AI,
Call);
3739 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
3740 SwiftErrorArg,
Call);
3741 Check(ArgI->hasSwiftErrorAttr(),
3742 "swifterror argument for call has mismatched parameter", ArgI,
3746 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
3749 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
3757 "immarg operand has non-immediate parameter", ArgVal,
Call);
3763 const ConstantRange &CR =
3766 "immarg value " + Twine(CI->getValue().getSExtValue()) +
3779 Check(hasOB != isMustTail,
3780 "preallocated operand either requires a preallocated bundle or "
3781 "the call to be musttail (but not both)",
3786 if (FTy->isVarArg()) {
3788 bool SawNest =
false;
3789 bool SawReturned =
false;
3791 for (
unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
3792 if (
Attrs.hasParamAttr(Idx, Attribute::Nest))
3794 if (
Attrs.hasParamAttr(Idx, Attribute::Returned))
3799 for (
unsigned Idx = FTy->getNumParams(); Idx <
Call.
arg_size(); ++Idx) {
3801 AttributeSet ArgAttrs =
Attrs.getParamAttrs(Idx);
3802 verifyParameterAttrs(ArgAttrs, Ty, &
Call);
3805 Check(!SawNest,
"More than one parameter has attribute nest!",
Call);
3810 Check(!SawReturned,
"More than one parameter has attribute returned!",
3813 "Incompatible argument and return types for 'returned' "
3823 "Attribute 'sret' cannot be used for vararg call arguments!",
3828 "inalloca isn't on the last argument!",
Call);
3834 for (
Type *ParamTy : FTy->params()) {
3835 Check(!ParamTy->isMetadataTy(),
3836 "Function has metadata parameter but isn't an intrinsic",
Call);
3837 Check(!ParamTy->isTokenLikeTy(),
3838 "Function has token parameter but isn't an intrinsic",
Call);
3844 Check(!FTy->getReturnType()->isTokenLikeTy(),
3845 "Return type cannot be token for indirect call!");
3846 Check(!FTy->getReturnType()->isX86_AMXTy(),
3847 "Return type cannot be x86_amx for indirect call!");
3851 visitIntrinsicCall(
ID,
Call);
3856 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
3857 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
3858 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
3859 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
3860 FoundAttachedCallBundle =
false;
3865 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles",
Call);
3866 FoundDeoptBundle =
true;
3868 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
3870 FoundGCTransitionBundle =
true;
3872 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles",
Call);
3873 FoundFuncletBundle =
true;
3875 "Expected exactly one funclet bundle operand",
Call);
3877 "Funclet bundle operands should correspond to a FuncletPadInst",
3880 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
3882 FoundCFGuardTargetBundle =
true;
3884 "Expected exactly one cfguardtarget bundle operand",
Call);
3886 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles",
Call);
3887 FoundPtrauthBundle =
true;
3889 "Expected exactly two ptrauth bundle operands",
Call);
3891 BU.
Inputs[0]->getType()->isIntegerTy(32),
3892 "Ptrauth bundle key operand must be an i32 constant",
Call);
3894 "Ptrauth bundle discriminator operand must be an i64",
Call);
3896 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles",
Call);
3897 FoundKCFIBundle =
true;
3898 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
3901 BU.
Inputs[0]->getType()->isIntegerTy(32),
3902 "Kcfi bundle operand must be an i32 constant",
Call);
3904 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
3906 FoundPreallocatedBundle =
true;
3908 "Expected exactly one preallocated bundle operand",
Call);
3911 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
3912 "\"preallocated\" argument must be a token from "
3913 "llvm.call.preallocated.setup",
3916 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles",
Call);
3917 FoundGCLiveBundle =
true;
3919 Check(!FoundAttachedCallBundle,
3920 "Multiple \"clang.arc.attachedcall\" operand bundles",
Call);
3921 FoundAttachedCallBundle =
true;
3922 verifyAttachedCallBundle(
Call, BU);
3928 "Direct call cannot have a ptrauth bundle",
Call);
3940 "inlinable function call in a function with "
3941 "debug info must have a !dbg location",
3945 verifyInlineAsmCall(
Call);
3949 visitInstruction(
Call);
3952void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
3955 Twine(
"inalloca attribute not allowed in ") +
Context);
3957 Twine(
"inreg attribute not allowed in ") +
Context);
3958 Check(!
Attrs.contains(Attribute::SwiftError),
3959 Twine(
"swifterror attribute not allowed in ") +
Context);
3960 Check(!
Attrs.contains(Attribute::Preallocated),
3961 Twine(
"preallocated attribute not allowed in ") +
Context);
3963 Twine(
"byref attribute not allowed in ") +
Context);
3975 return PL->getAddressSpace() == PR->getAddressSpace();
3980 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3981 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
3982 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
3984 AttrBuilder Copy(
C);
3985 for (
auto AK : ABIAttrs) {
3986 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
3988 Copy.addAttribute(Attr);
3992 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
3993 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
3994 Attrs.hasParamAttr(
I, Attribute::ByRef)))
3995 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
3999void Verifier::verifyMustTailCall(CallInst &CI) {
4003 FunctionType *CallerTy =
F->getFunctionType();
4005 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
4006 "cannot guarantee tail call due to mismatched varargs", &CI);
4008 "cannot guarantee tail call due to mismatched return types", &CI);
4012 "cannot guarantee tail call due to mismatched calling conv", &CI);
4018 Value *RetVal = &CI;
4024 "bitcast following musttail call must use the call", BI);
4031 Check(Ret,
"musttail call must precede a ret with an optional bitcast", &CI);
4032 Check(!
Ret->getReturnValue() ||
Ret->getReturnValue() == RetVal ||
4034 "musttail call result must be returned", Ret);
4036 AttributeList CallerAttrs =
F->getAttributes();
4041 CI.
getCallingConv() == CallingConv::Tail ?
"tailcc" :
"swifttailcc";
4045 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
4047 SmallString<32>
Context{CCName, StringRef(
" musttail caller")};
4048 verifyTailCCMustTailAttrs(ABIAttrs,
Context);
4050 for (
unsigned I = 0,
E = CalleeTy->getNumParams();
I !=
E; ++
I) {
4052 SmallString<32>
Context{CCName, StringRef(
" musttail callee")};
4053 verifyTailCCMustTailAttrs(ABIAttrs,
Context);
4056 Check(!CallerTy->isVarArg(), Twine(
"cannot guarantee ") + CCName +
4057 " tail call for varargs function");
4065 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
4066 "cannot guarantee tail call due to mismatched parameter counts", &CI);
4067 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
4070 "cannot guarantee tail call due to mismatched parameter types", &CI);
4076 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
4079 Check(CallerABIAttrs == CalleeABIAttrs,
4080 "cannot guarantee tail call due to mismatched ABI impacting "
4081 "function attributes",
4086void Verifier::visitCallInst(CallInst &CI) {
4090 verifyMustTailCall(CI);
4093void Verifier::visitInvokeInst(InvokeInst &
II) {
4099 II.getUnwindDest()->isEHPad(),
4100 "The unwind destination does not have an exception handling instruction!",
4103 visitTerminator(
II);
4108void Verifier::visitUnaryOperator(UnaryOperator &U) {
4109 Check(
U.getType() ==
U.getOperand(0)->getType(),
4110 "Unary operators must have same type for"
4111 "operands and result!",
4114 switch (
U.getOpcode()) {
4117 case Instruction::FNeg:
4118 Check(
U.getType()->isFPOrFPVectorTy(),
4119 "FNeg operator only works with float types!", &U);
4125 visitInstruction(U);
4131void Verifier::visitBinaryOperator(BinaryOperator &
B) {
4132 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
4133 "Both operands to a binary operator are not of the same type!", &
B);
4135 switch (
B.getOpcode()) {
4138 case Instruction::Add:
4139 case Instruction::Sub:
4140 case Instruction::Mul:
4141 case Instruction::SDiv:
4142 case Instruction::UDiv:
4143 case Instruction::SRem:
4144 case Instruction::URem:
4145 Check(
B.getType()->isIntOrIntVectorTy(),
4146 "Integer arithmetic operators only work with integral types!", &
B);
4147 Check(
B.getType() ==
B.getOperand(0)->getType(),
4148 "Integer arithmetic operators must have same type "
4149 "for operands and result!",
4154 case Instruction::FAdd:
4155 case Instruction::FSub:
4156 case Instruction::FMul:
4157 case Instruction::FDiv:
4158 case Instruction::FRem:
4159 Check(
B.getType()->isFPOrFPVectorTy(),
4160 "Floating-point arithmetic operators only work with "
4161 "floating-point types!",
4163 Check(
B.getType() ==
B.getOperand(0)->getType(),
4164 "Floating-point arithmetic operators must have same type "
4165 "for operands and result!",
4169 case Instruction::And:
4170 case Instruction::Or:
4171 case Instruction::Xor:
4172 Check(
B.getType()->isIntOrIntVectorTy(),
4173 "Logical operators only work with integral types!", &
B);
4174 Check(
B.getType() ==
B.getOperand(0)->getType(),
4175 "Logical operators must have same type for operands and result!", &
B);
4177 case Instruction::Shl:
4178 case Instruction::LShr:
4179 case Instruction::AShr:
4180 Check(
B.getType()->isIntOrIntVectorTy(),
4181 "Shifts only work with integral types!", &
B);
4182 Check(
B.getType() ==
B.getOperand(0)->getType(),
4183 "Shift return type must be same as operands!", &
B);
4189 visitInstruction(
B);
4192void Verifier::visitICmpInst(ICmpInst &IC) {
4196 Check(Op0Ty == Op1Ty,
4197 "Both operands to ICmp instruction are not of the same type!", &IC);
4200 "Invalid operand types for ICmp instruction", &IC);
4204 visitInstruction(IC);
4207void Verifier::visitFCmpInst(FCmpInst &FC) {
4209 Type *Op0Ty =
FC.getOperand(0)->getType();
4210 Type *Op1Ty =
FC.getOperand(1)->getType();
4211 Check(Op0Ty == Op1Ty,
4212 "Both operands to FCmp instruction are not of the same type!", &FC);
4217 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
4219 visitInstruction(FC);
4222void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
4224 "Invalid extractelement operands!", &EI);
4225 visitInstruction(EI);
4228void Verifier::visitInsertElementInst(InsertElementInst &IE) {
4231 "Invalid insertelement operands!", &IE);
4232 visitInstruction(IE);
4235void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
4238 "Invalid shufflevector operands!", &SV);
4239 visitInstruction(SV);
4242void Verifier::visitGetElementPtrInst(GetElementPtrInst &
GEP) {
4243 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4246 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4247 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4251 "getelementptr cannot target structure that contains scalable vector"
4256 SmallVector<Value *, 16> Idxs(
GEP.indices());
4258 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4259 "GEP indexes must be integers", &
GEP);
4262 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4266 Check(PtrTy &&
GEP.getResultElementType() == ElTy,
4267 "GEP is not of right type for indices!", &
GEP, ElTy);
4271 ElementCount GEPWidth = GEPVTy->getElementCount();
4272 if (
GEP.getPointerOperandType()->isVectorTy())
4276 "Vector GEP result width doesn't match operand's", &
GEP);
4277 for (
Value *Idx : Idxs) {
4278 Type *IndexTy = Idx->getType();
4280 ElementCount IndexWidth = IndexVTy->getElementCount();
4281 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4284 "All GEP indices should be of integer type");
4288 Check(
GEP.getAddressSpace() == PtrTy->getAddressSpace(),
4289 "GEP address space doesn't match type", &
GEP);
4291 visitInstruction(
GEP);
4295 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4300void Verifier::verifyRangeLikeMetadata(
const Value &
I,
const MDNode *
Range,
4301 Type *Ty, RangeLikeMetadataKind Kind) {
4302 unsigned NumOperands =
Range->getNumOperands();
4303 Check(NumOperands % 2 == 0,
"Unfinished range!",
Range);
4304 unsigned NumRanges = NumOperands / 2;
4305 Check(NumRanges >= 1,
"It should have at least one range!",
Range);
4307 ConstantRange LastRange(1,
true);
4308 for (
unsigned i = 0; i < NumRanges; ++i) {
4311 Check(
Low,
"The lower limit must be an integer!",
Low);
4316 Check(
High->getType() ==
Low->getType(),
"Range pair types must match!",
4319 if (Kind == RangeLikeMetadataKind::NoaliasAddrspace) {
4321 "noalias.addrspace type must be i32!", &
I);
4324 "Range types must match instruction type!", &
I);
4327 APInt HighV =
High->getValue();
4328 APInt LowV =
Low->getValue();
4333 "The upper and lower limits cannot be the same value", &
I);
4335 ConstantRange CurRange(LowV, HighV);
4336 Check(!CurRange.isEmptySet() &&
4337 (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4338 !CurRange.isFullSet()),
4339 "Range must not be empty!",
Range);
4341 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4342 "Intervals are overlapping",
Range);
4343 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4348 LastRange = ConstantRange(LowV, HighV);
4350 if (NumRanges > 2) {
4355 ConstantRange FirstRange(FirstLow, FirstHigh);
4356 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4357 "Intervals are overlapping",
Range);
4363void Verifier::visitRangeMetadata(Instruction &
I, MDNode *
Range,
Type *Ty) {
4365 "precondition violation");
4366 verifyRangeLikeMetadata(
I,
Range, Ty, RangeLikeMetadataKind::Range);
4369void Verifier::visitNoaliasAddrspaceMetadata(Instruction &
I, MDNode *
Range,
4372 "precondition violation");
4373 verifyRangeLikeMetadata(
I,
Range, Ty,
4374 RangeLikeMetadataKind::NoaliasAddrspace);
4377void Verifier::checkAtomicMemAccessSize(
Type *Ty,
const Instruction *
I) {
4378 unsigned Size =
DL.getTypeSizeInBits(Ty);
4379 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4381 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4384void Verifier::visitLoadInst(LoadInst &LI) {
4386 Check(PTy,
"Load operand must be a pointer.", &LI);
4389 Check(
A->value() <= Value::MaximumAlignment,
4390 "huge alignment values are unsupported", &LI);
4392 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4395 LI.
getOrdering() != AtomicOrdering::AcquireRelease,
4396 "Load cannot have Release ordering", &LI);
4398 "atomic load operand must have integer, pointer, or floating point "
4401 checkAtomicMemAccessSize(ElTy, &LI);
4404 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4407 visitInstruction(LI);
4410void Verifier::visitStoreInst(StoreInst &SI) {
4412 Check(PTy,
"Store operand must be a pointer.", &SI);
4413 Type *ElTy =
SI.getOperand(0)->getType();
4414 if (MaybeAlign
A =
SI.getAlign()) {
4415 Check(
A->value() <= Value::MaximumAlignment,
4416 "huge alignment values are unsupported", &SI);
4418 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4419 if (
SI.isAtomic()) {
4420 Check(
SI.getOrdering() != AtomicOrdering::Acquire &&
4421 SI.getOrdering() != AtomicOrdering::AcquireRelease,
4422 "Store cannot have Acquire ordering", &SI);
4424 "atomic store operand must have integer, pointer, or floating point "
4427 checkAtomicMemAccessSize(ElTy, &SI);
4430 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4432 visitInstruction(SI);
4436void Verifier::verifySwiftErrorCall(CallBase &
Call,
4437 const Value *SwiftErrorVal) {
4439 if (
I.value() == SwiftErrorVal) {
4441 "swifterror value when used in a callsite should be marked "
4442 "with swifterror attribute",
4443 SwiftErrorVal,
Call);
4448void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4451 for (
const User *U : SwiftErrorVal->
users()) {
4454 "swifterror value can only be loaded and stored from, or "
4455 "as a swifterror argument!",
4459 Check(StoreI->getOperand(1) == SwiftErrorVal,
4460 "swifterror value should be the second operand when used "
4464 verifySwiftErrorCall(*
const_cast<CallBase *
>(
Call), SwiftErrorVal);
4468void Verifier::visitAllocaInst(AllocaInst &AI) {
4470 SmallPtrSet<Type*, 4> Visited;
4471 Check(Ty->
isSized(&Visited),
"Cannot allocate unsized type", &AI);
4475 "Alloca has illegal target extension type", &AI);
4477 "Alloca array size must have integer type", &AI);
4479 Check(
A->value() <= Value::MaximumAlignment,
4480 "huge alignment values are unsupported", &AI);
4486 "swifterror alloca must not be array allocation", &AI);
4487 verifySwiftErrorValue(&AI);
4490 if (
TT.isAMDGPU()) {
4492 "alloca on amdgpu must be in addrspace(5)", &AI);
4495 visitInstruction(AI);
4498void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) {
4501 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4502 checkAtomicMemAccessSize(ElTy, &CXI);
4503 visitInstruction(CXI);
4506void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
4508 "atomicrmw instructions cannot be unordered.", &RMWI);
4515 " operand must have integer or floating point type!",
4520 " operand must have floating-point or fixed vector of floating-point "
4526 " operand must have integer type!",
4529 checkAtomicMemAccessSize(ElTy, &RMWI);
4531 "Invalid binary operation!", &RMWI);
4532 visitInstruction(RMWI);
4535void Verifier::visitFenceInst(FenceInst &FI) {
4537 Check(Ordering == AtomicOrdering::Acquire ||
4538 Ordering == AtomicOrdering::Release ||
4539 Ordering == AtomicOrdering::AcquireRelease ||
4540 Ordering == AtomicOrdering::SequentiallyConsistent,
4541 "fence instructions may only have acquire, release, acq_rel, or "
4542 "seq_cst ordering.",
4544 visitInstruction(FI);
4547void Verifier::visitExtractValueInst(ExtractValueInst &EVI) {
4550 "Invalid ExtractValueInst operands!", &EVI);
4552 visitInstruction(EVI);
4555void Verifier::visitInsertValueInst(InsertValueInst &IVI) {
4559 "Invalid InsertValueInst operands!", &IVI);
4561 visitInstruction(IVI);
4566 return FPI->getParentPad();
4571void Verifier::visitEHPadPredecessors(Instruction &
I) {
4577 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4585 Check(
II &&
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4586 "Block containing LandingPadInst must be jumped to "
4587 "only by the unwind edge of an invoke.",
4595 "Block containg CatchPadInst must be jumped to "
4596 "only by its catchswitch.",
4598 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
4599 "Catchswitch cannot unwind to one of its catchpads",
4600 CPI->getCatchSwitch(), CPI);
4612 Check(
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4613 "EH pad must be jumped to via an unwind edge", ToPad,
II);
4616 if (CalledFn && CalledFn->isIntrinsic() &&
II->doesNotThrow() &&
4620 FromPad = Bundle->Inputs[0];
4624 FromPad = CRI->getOperand(0);
4625 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
4629 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
4633 SmallPtrSet<Value *, 8> Seen;
4635 Check(FromPad != ToPad,
4636 "EH pad cannot handle exceptions raised within it", FromPad, TI);
4637 if (FromPad == ToPadParent) {
4642 "A single unwind edge may only enter one EH pad", TI);
4643 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
4649 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
4654void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
4658 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
4660 visitEHPadPredecessors(LPI);
4662 if (!LandingPadResultTy)
4663 LandingPadResultTy = LPI.
getType();
4666 "The landingpad instruction should have a consistent result type "
4667 "inside a function.",
4671 Check(
F->hasPersonalityFn(),
4672 "LandingPadInst needs to be in a function with a personality.", &LPI);
4677 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
4683 "Catch operand does not have pointer type!", &LPI);
4685 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
4687 "Filter operand is not an array of constants!", &LPI);
4691 visitInstruction(LPI);
4694void Verifier::visitResumeInst(ResumeInst &RI) {
4696 "ResumeInst needs to be in a function with a personality.", &RI);
4698 if (!LandingPadResultTy)
4702 "The resume instruction should have a consistent result type "
4703 "inside a function.",
4706 visitTerminator(RI);
4709void Verifier::visitCatchPadInst(CatchPadInst &CPI) {
4713 Check(
F->hasPersonalityFn(),
4714 "CatchPadInst needs to be in a function with a personality.", &CPI);
4717 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
4723 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
4725 visitEHPadPredecessors(CPI);
4726 visitFuncletPadInst(CPI);
4729void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) {
4731 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
4734 visitTerminator(CatchReturn);
4737void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
4741 Check(
F->hasPersonalityFn(),
4742 "CleanupPadInst needs to be in a function with a personality.", &CPI);
4747 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
4751 "CleanupPadInst has an invalid parent.", &CPI);
4753 visitEHPadPredecessors(CPI);
4754 visitFuncletPadInst(CPI);
4757void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) {
4758 User *FirstUser =
nullptr;
4759 Value *FirstUnwindPad =
nullptr;
4761 SmallPtrSet<FuncletPadInst *, 8> Seen;
4763 while (!Worklist.empty()) {
4764 FuncletPadInst *CurrentPad = Worklist.pop_back_val();
4766 "FuncletPadInst must not be nested within itself", CurrentPad);
4767 Value *UnresolvedAncestorPad =
nullptr;
4768 for (User *U : CurrentPad->
users()) {
4771 UnwindDest = CRI->getUnwindDest();
4777 if (CSI->unwindsToCaller())
4779 UnwindDest = CSI->getUnwindDest();
4781 UnwindDest =
II->getUnwindDest();
4791 Worklist.push_back(CPI);
4806 if (UnwindParent == CurrentPad)
4812 Value *ExitedPad = CurrentPad;
4815 if (ExitedPad == &FPI) {
4820 UnresolvedAncestorPad = &FPI;
4824 if (ExitedParent == UnwindParent) {
4828 UnresolvedAncestorPad = ExitedParent;
4831 ExitedPad = ExitedParent;
4837 UnresolvedAncestorPad = &FPI;
4844 Check(UnwindPad == FirstUnwindPad,
4845 "Unwind edges out of a funclet "
4846 "pad must have the same unwind "
4848 &FPI, U, FirstUser);
4851 FirstUnwindPad = UnwindPad;
4860 if (CurrentPad != &FPI)
4863 if (UnresolvedAncestorPad) {
4864 if (CurrentPad == UnresolvedAncestorPad) {
4868 assert(CurrentPad == &FPI);
4876 Value *ResolvedPad = CurrentPad;
4877 while (!Worklist.empty()) {
4878 Value *UnclePad = Worklist.back();
4882 while (ResolvedPad != AncestorPad) {
4884 if (ResolvedParent == UnresolvedAncestorPad) {
4887 ResolvedPad = ResolvedParent;
4891 if (ResolvedPad != AncestorPad)
4894 Worklist.pop_back();
4899 if (FirstUnwindPad) {
4901 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
4902 Value *SwitchUnwindPad;
4903 if (SwitchUnwindDest)
4907 Check(SwitchUnwindPad == FirstUnwindPad,
4908 "Unwind edges out of a catch must have the same unwind dest as "
4909 "the parent catchswitch",
4910 &FPI, FirstUser, CatchSwitch);
4914 visitInstruction(FPI);
4917void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) {
4921 Check(
F->hasPersonalityFn(),
4922 "CatchSwitchInst needs to be in a function with a personality.",
4928 "CatchSwitchInst not the first non-PHI instruction in the block.",
4933 "CatchSwitchInst has an invalid parent.", ParentPad);
4938 "CatchSwitchInst must unwind to an EH block which is not a "
4944 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
4948 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
4950 for (BasicBlock *Handler : CatchSwitch.
handlers()) {
4952 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
4955 visitEHPadPredecessors(CatchSwitch);
4956 visitTerminator(CatchSwitch);
4959void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
4961 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
4967 "CleanupReturnInst must unwind to an EH block which is not a "
4972 visitTerminator(CRI);
4975void Verifier::verifyDominatesUse(Instruction &
I,
unsigned i) {
4981 if (
II->getNormalDest() ==
II->getUnwindDest())
4995 const Use &
U =
I.getOperandUse(i);
4996 Check(DT.dominates(
Op, U),
"Instruction does not dominate all uses!",
Op, &
I);
4999void Verifier::visitDereferenceableMetadata(Instruction&
I, MDNode* MD) {
5000 Check(
I.getType()->isPointerTy(),
5001 "dereferenceable, dereferenceable_or_null "
5002 "apply only to pointer types",
5005 "dereferenceable, dereferenceable_or_null apply only to load"
5006 " and inttoptr instructions, use attributes for calls or invokes",
5009 "dereferenceable, dereferenceable_or_null "
5010 "take one operand!",
5015 "dereferenceable_or_null metadata value must be an i64!",
5019void Verifier::visitNofreeMetadata(Instruction &
I, MDNode *MD) {
5020 Check(
I.getType()->isPointerTy(),
"nofree applies only to pointer types", &
I);
5026void Verifier::visitProfMetadata(Instruction &
I, MDNode *MD) {
5027 auto GetBranchingTerminatorNumOperands = [&]() {
5028 unsigned ExpectedNumOperands = 0;
5032 ExpectedNumOperands =
SI->getNumSuccessors();
5034 ExpectedNumOperands = 1;
5036 ExpectedNumOperands = IBI->getNumDestinations();
5038 ExpectedNumOperands = 2;
5041 return ExpectedNumOperands;
5044 "!prof annotations should have at least 1 operand", MD);
5046 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null", MD);
5048 "expected string with name of the !prof annotation", MD);
5054 "'unknown' !prof should only appear on instructions on which "
5055 "'branch_weights' would",
5058 "'unknown' !prof should have no additional operands", MD);
5063 "!prof annotations should have no less than 2 operands", MD);
5069 Check(NumBranchWeights == 1 || NumBranchWeights == 2,
5070 "Wrong number of InvokeInst branch_weights operands", MD);
5072 const unsigned ExpectedNumOperands = GetBranchingTerminatorNumOperands();
5073 if (ExpectedNumOperands == 0)
5074 CheckFailed(
"!prof branch_weights are not allowed for this instruction",
5077 Check(NumBranchWeights == ExpectedNumOperands,
"Wrong number of operands",
5083 Check(MDO,
"second operand should not be null", MD);
5085 "!prof brunch_weights operand is not a const int");
5090 Check(KindInt,
"VP !prof missing kind argument", MD);
5093 Check(Kind >= InstrProfValueKind::IPVK_First &&
5094 Kind <= InstrProfValueKind::IPVK_Last,
5095 "Invalid VP !prof kind", MD);
5097 "VP !prof should have an even number "
5098 "of arguments after 'VP'",
5100 if (Kind == InstrProfValueKind::IPVK_IndirectCallTarget ||
5101 Kind == InstrProfValueKind::IPVK_MemOPSize)
5103 "VP !prof indirect call or memop size expected to be applied to "
5104 "CallBase instructions only",
5107 CheckFailed(
"expected either branch_weights or VP profile name", MD);
5111void Verifier::visitDIAssignIDMetadata(Instruction &
I, MDNode *MD) {
5112 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
5117 bool ExpectedInstTy =
5119 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
5124 for (
auto *User : AsValue->users()) {
5126 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
5130 CheckDI(DAI->getFunction() ==
I.getFunction(),
5131 "dbg.assign not in same function as inst", DAI, &
I);
5134 for (DbgVariableRecord *DVR :
5137 "!DIAssignID should only be used by Assign DVRs.", MD, DVR);
5138 CheckDI(DVR->getFunction() ==
I.getFunction(),
5139 "DVRAssign not in same function as inst", DVR, &
I);
5143void Verifier::visitMMRAMetadata(Instruction &
I, MDNode *MD) {
5145 "!mmra metadata attached to unexpected instruction kind",
I, MD);
5156 for (
const MDOperand &MDOp : MD->
operands())
5158 "!mmra metadata tuple operand is not an MMRA tag",
I, MDOp.get());
5161void Verifier::visitCallStackMetadata(MDNode *MD) {
5165 "call stack metadata should have at least 1 operand", MD);
5169 "call stack metadata operand should be constant integer",
Op);
5172void Verifier::visitMemProfMetadata(Instruction &
I, MDNode *MD) {
5175 "!memprof annotations should have at least 1 metadata operand "
5180 for (
auto &MIBOp : MD->
operands()) {
5186 "Each !memprof MemInfoBlock should have at least 2 operands", MIB);
5190 "!memprof MemInfoBlock first operand should not be null", MIB);
5192 "!memprof MemInfoBlock first operand should be an MDNode", MIB);
5194 visitCallStackMetadata(StackMD);
5201 "!memprof MemInfoBlock second operand should be an MDString",
5210 Check(OpNode,
"Not all !memprof MemInfoBlock operands 2 to N are MDNode",
5213 "Not all !memprof MemInfoBlock operands 2 to N are MDNode with 2 "
5218 [](
const MDOperand &
Op) {
5219 return mdconst::hasa<ConstantInt>(Op);
5221 "Not all !memprof MemInfoBlock operands 2 to N are MDNode with "
5222 "ConstantInt operands",
5228void Verifier::visitCallsiteMetadata(Instruction &
I, MDNode *MD) {
5232 visitCallStackMetadata(MD);
5241void Verifier::visitCalleeTypeMetadata(Instruction &
I, MDNode *MD) {
5246 "The callee_type metadata must be a list of type metadata nodes",
Op);
5248 Check(TypeMD->getNumOperands() == 2,
5249 "Well-formed generalized type metadata must contain exactly two "
5254 "The first operand of type metadata for functions must be zero",
Op);
5255 Check(TypeMD->hasGeneralizedMDString(),
5256 "Only generalized type metadata can be part of the callee_type "
5262void Verifier::visitAnnotationMetadata(MDNode *Annotation) {
5265 "annotation must have at least one operand");
5267 bool TupleOfStrings =
5273 "operands must be a string or a tuple of strings");
5277void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
5282 "first scope operand must be self-referential or string", MD);
5285 "third scope operand must be string (if used)", MD);
5288 Check(
Domain !=
nullptr,
"second scope operand must be MDNode", MD);
5290 unsigned NumDomainOps =
Domain->getNumOperands();
5291 Check(NumDomainOps >= 1 && NumDomainOps <= 2,
5292 "domain must have one or two operands",
Domain);
5295 "first domain operand must be self-referential or string",
Domain);
5296 if (NumDomainOps == 2)
5298 "second domain operand must be string (if used)",
Domain);
5301void Verifier::visitAliasScopeListMetadata(
const MDNode *MD) {
5304 Check(OpMD !=
nullptr,
"scope list must consist of MDNodes", MD);
5305 visitAliasScopeMetadata(OpMD);
5309void Verifier::visitAccessGroupMetadata(
const MDNode *MD) {
5310 auto IsValidAccessScope = [](
const MDNode *MD) {
5315 if (IsValidAccessScope(MD))
5321 Check(OpMD !=
nullptr,
"Access scope list must consist of MDNodes", MD);
5322 Check(IsValidAccessScope(OpMD),
5323 "Access scope list contains invalid access scope", MD);
5329void Verifier::visitInstruction(Instruction &
I) {
5331 Check(BB,
"Instruction not embedded in basic block!", &
I);
5334 for (User *U :
I.users()) {
5335 Check(U != (User *)&
I || !DT.isReachableFromEntry(BB),
5336 "Only PHI nodes may reference their own value!", &
I);
5341 Check(!
I.getType()->isVoidTy() || !
I.hasName(),
5342 "Instruction has a name, but provides a void value!", &
I);
5346 Check(
I.getType()->isVoidTy() ||
I.getType()->isFirstClassType(),
5347 "Instruction returns a non-scalar type!", &
I);
5352 "Invalid use of metadata!", &
I);
5357 for (Use &U :
I.uses()) {
5360 "Instruction referencing"
5361 " instruction not embedded in a basic block!",
5364 CheckFailed(
"Use of instruction is not an instruction!", U);
5373 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
5374 Check(
I.getOperand(i) !=
nullptr,
"Instruction has null operand!", &
I);
5378 if (!
I.getOperand(i)->getType()->isFirstClassType()) {
5379 Check(
false,
"Instruction operands must be first-class values!", &
I);
5385 auto IsAttachedCallOperand = [](
Function *
F,
const CallBase *CBI,
5387 return CBI && CBI->isOperandBundleOfType(
5395 Check((!
F->isIntrinsic() ||
5396 (CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i)) ||
5397 IsAttachedCallOperand(
F, CBI, i)),
5398 "Cannot take the address of an intrinsic!", &
I);
5400 F->getIntrinsicID() == Intrinsic::donothing ||
5401 F->getIntrinsicID() == Intrinsic::seh_try_begin ||
5402 F->getIntrinsicID() == Intrinsic::seh_try_end ||
5403 F->getIntrinsicID() == Intrinsic::seh_scope_begin ||
5404 F->getIntrinsicID() == Intrinsic::seh_scope_end ||
5405 F->getIntrinsicID() == Intrinsic::coro_resume ||
5406 F->getIntrinsicID() == Intrinsic::coro_destroy ||
5407 F->getIntrinsicID() == Intrinsic::coro_await_suspend_void ||
5408 F->getIntrinsicID() == Intrinsic::coro_await_suspend_bool ||
5409 F->getIntrinsicID() == Intrinsic::coro_await_suspend_handle ||
5410 F->getIntrinsicID() ==
5411 Intrinsic::experimental_patchpoint_void ||
5412 F->getIntrinsicID() == Intrinsic::experimental_patchpoint ||
5413 F->getIntrinsicID() == Intrinsic::fake_use ||
5414 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
5415 F->getIntrinsicID() == Intrinsic::wasm_throw ||
5416 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
5417 IsAttachedCallOperand(
F, CBI, i),
5418 "Cannot invoke an intrinsic other than donothing, patchpoint, "
5419 "statepoint, coro_resume, coro_destroy, clang.arc.attachedcall or "
5422 Check(
F->getParent() == &M,
"Referencing function in another module!", &
I,
5423 &M,
F,
F->getParent());
5426 "Referring to a basic block in another function!", &
I);
5429 "Referring to an argument in another function!", &
I);
5431 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5435 "Referring to an instruction in another function!", &
I);
5436 verifyDominatesUse(
I, i);
5438 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5439 "Cannot take the address of an inline asm!", &
I);
5441 visitConstantExprsRecursively(CPA);
5443 if (
CE->getType()->isPtrOrPtrVectorTy()) {
5446 visitConstantExprsRecursively(CE);
5451 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_fpmath)) {
5452 Check(
I.getType()->isFPOrFPVectorTy(),
5453 "fpmath requires a floating point result!", &
I);
5455 if (ConstantFP *CFP0 =
5457 const APFloat &Accuracy = CFP0->getValueAPF();
5459 "fpmath accuracy must have float type", &
I);
5461 "fpmath accuracy not a positive number!", &
I);
5463 Check(
false,
"invalid fpmath accuracy!", &
I);
5467 if (MDNode *
Range =
I.getMetadata(LLVMContext::MD_range)) {
5469 "Ranges are only for loads, calls and invokes!", &
I);
5470 visitRangeMetadata(
I,
Range,
I.getType());
5473 if (MDNode *
Range =
I.getMetadata(LLVMContext::MD_noalias_addrspace)) {
5476 "noalias.addrspace are only for memory operations!", &
I);
5477 visitNoaliasAddrspaceMetadata(
I,
Range,
I.getType());
5480 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
5482 "invariant.group metadata is only for loads and stores", &
I);
5485 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_nonnull)) {
5486 Check(
I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
5489 "nonnull applies only to load instructions, use attributes"
5490 " for calls or invokes",
5495 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable))
5496 visitDereferenceableMetadata(
I, MD);
5498 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
5499 visitDereferenceableMetadata(
I, MD);
5501 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_nofree))
5502 visitNofreeMetadata(
I, MD);
5504 if (MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
5507 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
5508 visitAliasScopeListMetadata(MD);
5509 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
5510 visitAliasScopeListMetadata(MD);
5512 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
5513 visitAccessGroupMetadata(MD);
5515 if (MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
5516 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
5519 "align applies only to load instructions, "
5520 "use attributes for calls or invokes",
5522 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
5525 "align metadata value must be an i64!", &
I);
5529 Check(Align <= Value::MaximumAlignment,
5530 "alignment is larger that implementation defined limit", &
I);
5533 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
5534 visitProfMetadata(
I, MD);
5536 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
5537 visitMemProfMetadata(
I, MD);
5539 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
5540 visitCallsiteMetadata(
I, MD);
5542 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_callee_type))
5543 visitCalleeTypeMetadata(
I, MD);
5545 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
5546 visitDIAssignIDMetadata(
I, MD);
5548 if (MDNode *MMRA =
I.getMetadata(LLVMContext::MD_mmra))
5549 visitMMRAMetadata(
I, MMRA);
5551 if (MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
5552 visitAnnotationMetadata(Annotation);
5554 if (MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
5556 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
5559 if (
DL->getAtomGroup()) {
5560 CheckDI(
DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
5561 "DbgLoc uses atomGroup but DISubprogram doesn't have Key "
5562 "Instructions enabled",
5563 DL,
DL->getScope()->getSubprogram());
5569 I.getAllMetadata(MDs);
5570 for (
auto Attachment : MDs) {
5571 unsigned Kind = Attachment.first;
5573 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
5574 ? AreDebugLocsAllowed::Yes
5575 : AreDebugLocsAllowed::
No;
5576 visitMDNode(*Attachment.second, AllowLocs);
5585 Check(
IF->isDeclaration(),
"Intrinsic functions should never be defined!",
5590 FunctionType *IFTy =
IF->getFunctionType();
5591 bool IsVarArg = IFTy->isVarArg();
5602 "Intrinsic has incorrect return type!", IF);
5604 "Intrinsic has incorrect argument type!", IF);
5609 "Intrinsic was not defined with variable arguments!", IF);
5612 "Callsite was not defined with variable arguments!", IF);
5621 const std::string ExpectedName =
5623 Check(ExpectedName ==
IF->getName(),
5624 "Intrinsic name not mangled correctly for type arguments! "
5636 "const x86_amx is not allowed in argument!");
5642 case Intrinsic::assume: {
5644 unsigned ArgCount = Elem.End - Elem.Begin;
5647 if (Elem.Tag->getKey() ==
"separate_storage") {
5648 Check(ArgCount == 2,
5649 "separate_storage assumptions should have 2 arguments",
Call);
5652 "arguments to separate_storage assumptions should be pointers",
5656 Check(Elem.Tag->getKey() ==
"ignore" ||
5657 Attribute::isExistingAttribute(Elem.Tag->getKey()),
5658 "tags must be valid attribute names",
Call);
5659 Attribute::AttrKind
Kind =
5660 Attribute::getAttrKindFromName(Elem.Tag->getKey());
5661 if (Kind == Attribute::Alignment) {
5662 Check(ArgCount <= 3 && ArgCount >= 2,
5663 "alignment assumptions should have 2 or 3 arguments",
Call);
5665 "first argument should be a pointer",
Call);
5667 "second argument should be an integer",
Call);
5670 "third argument should be an integer if present",
Call);
5673 if (Kind == Attribute::Dereferenceable) {
5674 Check(ArgCount == 2,
5675 "dereferenceable assumptions should have 2 arguments",
Call);
5677 "first argument should be a pointer",
Call);
5679 "second argument should be an integer",
Call);
5682 Check(ArgCount <= 2,
"too many arguments",
Call);
5683 if (Kind == Attribute::None)
5685 if (Attribute::isIntAttrKind(Kind)) {
5686 Check(ArgCount == 2,
"this attribute should have 2 arguments",
Call);
5688 "the second argument should be a constant integral value",
Call);
5689 }
else if (Attribute::canUseAsParamAttr(Kind)) {
5690 Check((ArgCount) == 1,
"this attribute should have one argument",
Call);
5691 }
else if (Attribute::canUseAsFnAttr(Kind)) {
5692 Check((ArgCount) == 0,
"this attribute has no argument",
Call);
5697 case Intrinsic::ucmp:
5698 case Intrinsic::scmp: {
5703 "result type must be at least 2 bits wide",
Call);
5705 bool IsDestTypeVector = DestTy->
isVectorTy();
5707 "ucmp/scmp argument and result types must both be either vector or "
5710 if (IsDestTypeVector) {
5713 Check(SrcVecLen == DestVecLen,
5714 "return type and arguments must have the same number of "
5720 case Intrinsic::coro_id: {
5726 "info argument of llvm.coro.id must refer to an initialized "
5730 "info argument of llvm.coro.id must refer to either a struct or "
5734 case Intrinsic::is_fpclass: {
5737 "unsupported bits for llvm.is.fpclass test mask");
5740 case Intrinsic::fptrunc_round: {
5745 MD = MAV->getMetadata();
5747 Check(MD !=
nullptr,
"missing rounding mode argument",
Call);
5750 (
"invalid value for llvm.fptrunc.round metadata operand"
5751 " (the operand should be a string)"),
5754 std::optional<RoundingMode> RoundMode =
5756 Check(RoundMode && *RoundMode != RoundingMode::Dynamic,
5757 "unsupported rounding mode argument",
Call);
5760#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
5761#include "llvm/IR/VPIntrinsics.def"
5762#undef BEGIN_REGISTER_VP_INTRINSIC
5765#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
5766 case Intrinsic::INTRINSIC:
5767#include "llvm/IR/ConstrainedOps.def"
5771 case Intrinsic::dbg_declare:
5772 case Intrinsic::dbg_value:
5773 case Intrinsic::dbg_assign:
5774 case Intrinsic::dbg_label:
5781 case Intrinsic::memcpy:
5782 case Intrinsic::memcpy_inline:
5783 case Intrinsic::memmove:
5784 case Intrinsic::memset:
5785 case Intrinsic::memset_inline:
5787 case Intrinsic::experimental_memset_pattern: {
5789 Check(Memset->getValue()->getType()->isSized(),
5790 "unsized types cannot be used as memset patterns",
Call);
5793 case Intrinsic::memcpy_element_unordered_atomic:
5794 case Intrinsic::memmove_element_unordered_atomic:
5795 case Intrinsic::memset_element_unordered_atomic: {
5798 ConstantInt *ElementSizeCI =
5800 const APInt &ElementSizeVal = ElementSizeCI->
getValue();
5802 "element size of the element-wise atomic memory intrinsic "
5803 "must be a power of 2",
5806 auto IsValidAlignment = [&](MaybeAlign Alignment) {
5807 return Alignment && ElementSizeVal.
ule(Alignment->value());
5809 Check(IsValidAlignment(AMI->getDestAlign()),
5810 "incorrect alignment of the destination argument",
Call);
5812 Check(IsValidAlignment(AMT->getSourceAlign()),
5813 "incorrect alignment of the source argument",
Call);
5817 case Intrinsic::call_preallocated_setup: {
5819 Check(NumArgs !=
nullptr,
5820 "llvm.call.preallocated.setup argument must be a constant");
5821 bool FoundCall =
false;
5824 Check(UseCall !=
nullptr,
5825 "Uses of llvm.call.preallocated.setup must be calls");
5827 if (IID == Intrinsic::call_preallocated_arg) {
5829 Check(AllocArgIndex !=
nullptr,
5830 "llvm.call.preallocated.alloc arg index must be a constant");
5831 auto AllocArgIndexInt = AllocArgIndex->getValue();
5832 Check(AllocArgIndexInt.sge(0) &&
5833 AllocArgIndexInt.slt(NumArgs->getValue()),
5834 "llvm.call.preallocated.alloc arg index must be between 0 and "
5836 "llvm.call.preallocated.setup's argument count");
5837 }
else if (IID == Intrinsic::call_preallocated_teardown) {
5840 Check(!FoundCall,
"Can have at most one call corresponding to a "
5841 "llvm.call.preallocated.setup");
5843 size_t NumPreallocatedArgs = 0;
5844 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
5845 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
5846 ++NumPreallocatedArgs;
5849 Check(NumPreallocatedArgs != 0,
5850 "cannot use preallocated intrinsics on a call without "
5851 "preallocated arguments");
5852 Check(NumArgs->equalsInt(NumPreallocatedArgs),
5853 "llvm.call.preallocated.setup arg size must be equal to number "
5854 "of preallocated arguments "
5864 auto PreallocatedBundle =
5866 Check(PreallocatedBundle,
5867 "Use of llvm.call.preallocated.setup outside intrinsics "
5868 "must be in \"preallocated\" operand bundle");
5869 Check(PreallocatedBundle->Inputs.front().get() == &
Call,
5870 "preallocated bundle must have token from corresponding "
5871 "llvm.call.preallocated.setup");
5876 case Intrinsic::call_preallocated_arg: {
5879 Token->getIntrinsicID() == Intrinsic::call_preallocated_setup,
5880 "llvm.call.preallocated.arg token argument must be a "
5881 "llvm.call.preallocated.setup");
5883 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
5884 "call site attribute");
5887 case Intrinsic::call_preallocated_teardown: {
5890 Token->getIntrinsicID() == Intrinsic::call_preallocated_setup,
5891 "llvm.call.preallocated.teardown token argument must be a "
5892 "llvm.call.preallocated.setup");
5895 case Intrinsic::gcroot:
5896 case Intrinsic::gcwrite:
5897 case Intrinsic::gcread:
5898 if (
ID == Intrinsic::gcroot) {
5901 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.",
Call);
5903 "llvm.gcroot parameter #2 must be a constant.",
Call);
5906 "llvm.gcroot parameter #1 must either be a pointer alloca, "
5907 "or argument #2 must be a non-null constant.",
5913 "Enclosing function does not use GC.",
Call);
5915 case Intrinsic::init_trampoline:
5917 "llvm.init_trampoline parameter #2 must resolve to a function.",
5920 case Intrinsic::prefetch:
5922 "rw argument to llvm.prefetch must be 0-1",
Call);
5924 "locality argument to llvm.prefetch must be 0-3",
Call);
5926 "cache type argument to llvm.prefetch must be 0-1",
Call);
5928 case Intrinsic::stackprotector:
5930 "llvm.stackprotector parameter #2 must resolve to an alloca.",
Call);
5932 case Intrinsic::localescape: {
5936 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
5943 "llvm.localescape only accepts static allocas",
Call);
5946 SawFrameEscape =
true;
5949 case Intrinsic::localrecover: {
5953 "llvm.localrecover first "
5954 "argument must be function defined in this module",
5957 auto &
Entry = FrameEscapeInfo[Fn];
5958 Entry.second = unsigned(
5959 std::max(uint64_t(
Entry.second), IdxArg->getLimitedValue(~0U) + 1));
5963 case Intrinsic::experimental_gc_statepoint:
5965 Check(!CI->isInlineAsm(),
5966 "gc.statepoint support for inline assembly unimplemented", CI);
5968 "Enclosing function does not use GC.",
Call);
5970 verifyStatepoint(
Call);
5972 case Intrinsic::experimental_gc_result: {
5974 "Enclosing function does not use GC.",
Call);
5982 Check(StatepointCall && StatepointCall->getIntrinsicID() ==
5983 Intrinsic::experimental_gc_statepoint,
5984 "gc.result operand #1 must be from a statepoint",
Call,
5988 auto *TargetFuncType =
5991 "gc.result result type does not match wrapped callee",
Call);
5994 case Intrinsic::experimental_gc_relocate: {
5998 "gc.relocate must return a pointer or a vector of pointers",
Call);
6003 if (LandingPadInst *LandingPad =
6007 LandingPad->getParent()->getUniquePredecessor();
6011 Check(InvokeBB,
"safepoints should have unique landingpads",
6012 LandingPad->getParent());
6016 "gc relocate should be linked to a statepoint", InvokeBB);
6023 "gc relocate is incorrectly tied to the statepoint",
Call, Token);
6032 "gc.relocate operand #2 must be integer offset",
Call);
6036 "gc.relocate operand #3 must be integer offset",
Call);
6046 Check(BaseIndex < Opt->Inputs.size(),
6047 "gc.relocate: statepoint base index out of bounds",
Call);
6048 Check(DerivedIndex < Opt->Inputs.size(),
6049 "gc.relocate: statepoint derived index out of bounds",
Call);
6062 "gc.relocate: relocated value must be a pointer",
Call);
6063 Check(DerivedType->isPtrOrPtrVectorTy(),
6064 "gc.relocate: relocated value must be a pointer",
Call);
6066 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
6067 "gc.relocate: vector relocates to vector and pointer to pointer",
6070 ResultType->getPointerAddressSpace() ==
6071 DerivedType->getPointerAddressSpace(),
6072 "gc.relocate: relocating a pointer shouldn't change its address space",
6076 Check(GC,
"gc.relocate: calling function must have GCStrategy",
6079 auto isGCPtr = [&
GC](
Type *PTy) {
6080 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
6082 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer",
Call);
6084 "gc.relocate: relocated value must be a gc pointer",
Call);
6085 Check(isGCPtr(DerivedType),
6086 "gc.relocate: relocated value must be a gc pointer",
Call);
6090 case Intrinsic::experimental_patchpoint: {
6093 "patchpoint: invalid return type used with anyregcc",
Call);
6097 case Intrinsic::eh_exceptioncode:
6098 case Intrinsic::eh_exceptionpointer: {
6100 "eh.exceptionpointer argument must be a catchpad",
Call);
6103 case Intrinsic::get_active_lane_mask: {
6105 "get_active_lane_mask: must return a "
6109 Check(ElemTy->isIntegerTy(1),
6110 "get_active_lane_mask: element type is not "
6115 case Intrinsic::experimental_get_vector_length: {
6118 "get_vector_length: VF must be positive",
Call);
6121 case Intrinsic::masked_load: {
6128 Check(
Mask->getType()->isVectorTy(),
"masked_load: mask must be vector",
6131 "masked_load: alignment must be a power of 2",
Call);
6133 "masked_load: pass through and return type must match",
Call);
6136 "masked_load: vector mask must be same length as return",
Call);
6139 case Intrinsic::masked_store: {
6143 Check(
Mask->getType()->isVectorTy(),
"masked_store: mask must be vector",
6146 "masked_store: alignment must be a power of 2",
Call);
6149 "masked_store: vector mask must be same length as value",
Call);
6153 case Intrinsic::masked_gather: {
6154 const APInt &Alignment =
6157 "masked_gather: alignment must be 0 or a power of 2",
Call);
6160 case Intrinsic::masked_scatter: {
6161 const APInt &Alignment =
6164 "masked_scatter: alignment must be 0 or a power of 2",
Call);
6168 case Intrinsic::experimental_guard: {
6171 "experimental_guard must have exactly one "
6172 "\"deopt\" operand bundle");
6176 case Intrinsic::experimental_deoptimize: {
6180 "experimental_deoptimize must have exactly one "
6181 "\"deopt\" operand bundle");
6183 "experimental_deoptimize return type must match caller return type");
6188 "calls to experimental_deoptimize must be followed by a return");
6192 "calls to experimental_deoptimize must be followed by a return "
6193 "of the value computed by experimental_deoptimize");
6198 case Intrinsic::vastart: {
6200 "va_start called in a non-varargs function");
6203 case Intrinsic::get_dynamic_area_offset: {
6205 Check(IntTy &&
DL.getPointerSizeInBits(
DL.getAllocaAddrSpace()) ==
6206 IntTy->getBitWidth(),
6207 "get_dynamic_area_offset result type must be scalar integer matching "
6208 "alloca address space width",
6212 case Intrinsic::vector_reduce_and:
6213 case Intrinsic::vector_reduce_or:
6214 case Intrinsic::vector_reduce_xor:
6215 case Intrinsic::vector_reduce_add:
6216 case Intrinsic::vector_reduce_mul:
6217 case Intrinsic::vector_reduce_smax:
6218 case Intrinsic::vector_reduce_smin:
6219 case Intrinsic::vector_reduce_umax:
6220 case Intrinsic::vector_reduce_umin: {
6223 "Intrinsic has incorrect argument type!");
6226 case Intrinsic::vector_reduce_fmax:
6227 case Intrinsic::vector_reduce_fmin: {
6230 "Intrinsic has incorrect argument type!");
6233 case Intrinsic::vector_reduce_fadd:
6234 case Intrinsic::vector_reduce_fmul: {
6239 "Intrinsic has incorrect argument type!");
6242 case Intrinsic::smul_fix:
6243 case Intrinsic::smul_fix_sat:
6244 case Intrinsic::umul_fix:
6245 case Intrinsic::umul_fix_sat:
6246 case Intrinsic::sdiv_fix:
6247 case Intrinsic::sdiv_fix_sat:
6248 case Intrinsic::udiv_fix:
6249 case Intrinsic::udiv_fix_sat: {
6253 "first operand of [us][mul|div]_fix[_sat] must be an int type or "
6256 "second operand of [us][mul|div]_fix[_sat] must be an int type or "
6260 Check(Op3->getType()->isIntegerTy(),
6261 "third operand of [us][mul|div]_fix[_sat] must be an int type");
6262 Check(Op3->getBitWidth() <= 32,
6263 "third operand of [us][mul|div]_fix[_sat] must fit within 32 bits");
6265 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
6266 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
6268 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
6272 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
6273 "to the width of the operands");
6277 case Intrinsic::lrint:
6278 case Intrinsic::llrint:
6279 case Intrinsic::lround:
6280 case Intrinsic::llround: {
6286 ExpectedName +
": argument must be floating-point or vector "
6287 "of floating-points, and result must be integer or "
6288 "vector of integers",
6291 ExpectedName +
": argument and result disagree on vector use", &
Call);
6293 Check(VTy->getElementCount() == RTy->getElementCount(),
6294 ExpectedName +
": argument must be same length as result", &
Call);
6298 case Intrinsic::bswap: {
6301 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &
Call);
6304 case Intrinsic::invariant_start: {
6306 Check(InvariantSize &&
6308 "invariant_start parameter must be -1, 0 or a positive number",
6312 case Intrinsic::matrix_multiply:
6313 case Intrinsic::matrix_transpose:
6314 case Intrinsic::matrix_column_major_load:
6315 case Intrinsic::matrix_column_major_store: {
6317 ConstantInt *Stride =
nullptr;
6318 ConstantInt *NumRows;
6319 ConstantInt *NumColumns;
6321 Type *Op0ElemTy =
nullptr;
6322 Type *Op1ElemTy =
nullptr;
6324 case Intrinsic::matrix_multiply: {
6329 ->getNumElements() ==
6331 "First argument of a matrix operation does not match specified "
6334 ->getNumElements() ==
6336 "Second argument of a matrix operation does not match specified "
6346 case Intrinsic::matrix_transpose:
6353 case Intrinsic::matrix_column_major_load: {
6360 case Intrinsic::matrix_column_major_store: {
6373 Check(ResultTy->getElementType()->isIntegerTy() ||
6374 ResultTy->getElementType()->isFloatingPointTy(),
6375 "Result type must be an integer or floating-point type!", IF);
6378 Check(ResultTy->getElementType() == Op0ElemTy,
6379 "Vector element type mismatch of the result and first operand "
6384 Check(ResultTy->getElementType() == Op1ElemTy,
6385 "Vector element type mismatch of the result and second operand "
6391 "Result of a matrix operation does not fit in the returned vector!");
6395 "Stride must be greater or equal than the number of rows!", IF);
6399 case Intrinsic::vector_splice: {
6402 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
6405 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
6406 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
6408 Check((Idx < 0 && std::abs(Idx) <= KnownMinNumElements) ||
6409 (Idx >= 0 && Idx < KnownMinNumElements),
6410 "The splice index exceeds the range [-VL, VL-1] where VL is the "
6411 "known minimum number of elements in the vector. For scalable "
6412 "vectors the minimum number of elements is determined from "
6417 case Intrinsic::stepvector: {
6419 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
6420 VecTy->getScalarSizeInBits() >= 8,
6421 "stepvector only supported for vectors of integers "
6422 "with a bitwidth of at least 8.",
6426 case Intrinsic::experimental_vector_match: {
6435 Check(Op1Ty && Op2Ty && MaskTy,
"Operands must be vectors.", &
Call);
6437 "Second operand must be a fixed length vector.", &
Call);
6438 Check(Op1Ty->getElementType()->isIntegerTy(),
6439 "First operand must be a vector of integers.", &
Call);
6440 Check(Op1Ty->getElementType() == Op2Ty->getElementType(),
6441 "First two operands must have the same element type.", &
Call);
6442 Check(Op1Ty->getElementCount() == MaskTy->getElementCount(),
6443 "First operand and mask must have the same number of elements.",
6445 Check(MaskTy->getElementType()->isIntegerTy(1),
6446 "Mask must be a vector of i1's.", &
Call);
6451 case Intrinsic::vector_insert: {
6460 ElementCount VecEC = VecTy->getElementCount();
6461 ElementCount SubVecEC = SubVecTy->getElementCount();
6462 Check(VecTy->getElementType() == SubVecTy->getElementType(),
6463 "vector_insert parameters must have the same element "
6467 "vector_insert index must be a constant multiple of "
6468 "the subvector's known minimum vector length.");
6476 "subvector operand of vector_insert would overrun the "
6477 "vector being inserted into.");
6481 case Intrinsic::vector_extract: {
6489 ElementCount VecEC = VecTy->getElementCount();
6490 ElementCount ResultEC = ResultTy->getElementCount();
6492 Check(ResultTy->getElementType() == VecTy->getElementType(),
6493 "vector_extract result must have the same element "
6494 "type as the input vector.",
6497 "vector_extract index must be a constant multiple of "
6498 "the result type's known minimum vector length.");
6506 "vector_extract would overrun.");
6510 case Intrinsic::experimental_vector_partial_reduce_add: {
6514 unsigned VecWidth = VecTy->getElementCount().getKnownMinValue();
6515 unsigned AccWidth = AccTy->getElementCount().getKnownMinValue();
6517 Check((VecWidth % AccWidth) == 0,
6518 "Invalid vector widths for partial "
6519 "reduction. The width of the input vector "
6520 "must be a positive integer multiple of "
6521 "the width of the accumulator vector.");
6524 case Intrinsic::experimental_noalias_scope_decl: {
6528 case Intrinsic::preserve_array_access_index:
6529 case Intrinsic::preserve_struct_access_index:
6530 case Intrinsic::aarch64_ldaxr:
6531 case Intrinsic::aarch64_ldxr:
6532 case Intrinsic::arm_ldaex:
6533 case Intrinsic::arm_ldrex: {
6535 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
6539 case Intrinsic::aarch64_stlxr:
6540 case Intrinsic::aarch64_stxr:
6541 case Intrinsic::arm_stlex:
6542 case Intrinsic::arm_strex: {
6545 "Intrinsic requires elementtype attribute on second argument.",
6549 case Intrinsic::aarch64_prefetch: {
6551 "write argument to llvm.aarch64.prefetch must be 0 or 1",
Call);
6553 "target argument to llvm.aarch64.prefetch must be 0-3",
Call);
6555 "stream argument to llvm.aarch64.prefetch must be 0 or 1",
Call);
6557 "isdata argument to llvm.aarch64.prefetch must be 0 or 1",
Call);
6560 case Intrinsic::callbr_landingpad: {
6562 Check(CBR,
"intrinstic requires callbr operand", &
Call);
6569 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &
Call);
6573 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
6578 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
6579 "block in indirect destination list",
6582 Check(&
First == &
Call,
"No other instructions may proceed intrinsic",
6586 case Intrinsic::amdgcn_cs_chain: {
6589 case CallingConv::AMDGPU_CS:
6590 case CallingConv::AMDGPU_CS_Chain:
6591 case CallingConv::AMDGPU_CS_ChainPreserve:
6594 CheckFailed(
"Intrinsic can only be used from functions with the "
6595 "amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6596 "calling conventions",
6602 "SGPR arguments must have the `inreg` attribute", &
Call);
6604 "VGPR arguments must not have the `inreg` attribute", &
Call);
6609 Intrinsic::amdgcn_unreachable;
6611 "llvm.amdgcn.cs.chain must be followed by unreachable", &
Call);
6614 case Intrinsic::amdgcn_init_exec_from_input: {
6617 "only inreg arguments to the parent function are valid as inputs to "
6622 case Intrinsic::amdgcn_set_inactive_chain_arg: {
6625 case CallingConv::AMDGPU_CS_Chain:
6626 case CallingConv::AMDGPU_CS_ChainPreserve:
6629 CheckFailed(
"Intrinsic can only be used from functions with the "
6630 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6631 "calling conventions",
6636 unsigned InactiveIdx = 1;
6638 "Value for inactive lanes must not have the `inreg` attribute",
6641 "Value for inactive lanes must be a function argument", &
Call);
6643 "Value for inactive lanes must be a VGPR function argument", &
Call);
6646 case Intrinsic::amdgcn_call_whole_wave: {
6648 Check(
F,
"Indirect whole wave calls are not allowed", &
Call);
6650 CallingConv::ID CC =
F->getCallingConv();
6651 Check(CC == CallingConv::AMDGPU_Gfx_WholeWave,
6652 "Callee must have the amdgpu_gfx_whole_wave calling convention",
6655 Check(!
F->isVarArg(),
"Variadic whole wave calls are not allowed", &
Call);
6658 "Call argument count must match callee argument count", &
Call);
6662 Check(
F->arg_begin()->getType()->isIntegerTy(1),
6663 "Callee must have i1 as its first argument", &
Call);
6664 for (
auto [CallArg, FuncArg] :
6666 Check(CallArg->getType() == FuncArg.getType(),
6667 "Argument types must match", &
Call);
6671 FuncArg.hasInRegAttr(),
6672 "Argument inreg attributes must match", &
Call);
6676 case Intrinsic::amdgcn_s_prefetch_data: {
6680 "llvm.amdgcn.s.prefetch.data only supports global or constant memory");
6683 case Intrinsic::amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
6684 case Intrinsic::amdgcn_mfma_scale_f32_32x32x64_f8f6f4: {
6690 Check(CBSZ <= 4,
"invalid value for cbsz format",
Call,
6692 Check(BLGP <= 4,
"invalid value for blgp format",
Call,
6696 auto getFormatNumRegs = [](
unsigned FormatVal) {
6697 switch (FormatVal) {
6711 auto isValidSrcASrcBVector = [](FixedVectorType *Ty) {
6712 if (!Ty || !Ty->getElementType()->
isIntegerTy(32))
6714 unsigned NumElts = Ty->getNumElements();
6715 return NumElts == 4 || NumElts == 6 || NumElts == 8;
6720 Check(isValidSrcASrcBVector(Src0Ty),
6721 "operand 0 must be 4, 6 or 8 element i32 vector", &
Call, Src0);
6722 Check(isValidSrcASrcBVector(Src1Ty),
6723 "operand 1 must be 4, 6 or 8 element i32 vector", &
Call, Src1);
6726 Check(Src0Ty->getNumElements() >= getFormatNumRegs(CBSZ),
6728 Check(Src1Ty->getNumElements() >= getFormatNumRegs(BLGP),
6732 case Intrinsic::amdgcn_wmma_f32_16x16x128_f8f6f4:
6733 case Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4:
6734 case Intrinsic::amdgcn_wmma_scale16_f32_16x16x128_f8f6f4: {
6740 Check(FmtA <= 4,
"invalid value for matrix format",
Call,
6742 Check(FmtB <= 4,
"invalid value for matrix format",
Call,
6746 auto getFormatNumRegs = [](
unsigned FormatVal) {
6747 switch (FormatVal) {
6761 auto isValidSrcASrcBVector = [](FixedVectorType *Ty) {
6762 if (!Ty || !Ty->getElementType()->
isIntegerTy(32))
6764 unsigned NumElts = Ty->getNumElements();
6765 return NumElts == 16 || NumElts == 12 || NumElts == 8;
6770 Check(isValidSrcASrcBVector(Src0Ty),
6771 "operand 1 must be 8, 12 or 16 element i32 vector", &
Call, Src0);
6772 Check(isValidSrcASrcBVector(Src1Ty),
6773 "operand 3 must be 8, 12 or 16 element i32 vector", &
Call, Src1);
6776 Check(Src0Ty->getNumElements() >= getFormatNumRegs(FmtA),
6778 Check(Src1Ty->getNumElements() >= getFormatNumRegs(FmtB),
6782 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
6783 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
6784 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B:
6785 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
6786 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
6787 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
6792 "cooperative atomic intrinsics require a generic or global pointer",
6799 "cooperative atomic intrinsics require that the last argument is a "
6804 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
6805 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
6808 Check(RegCount % 8 == 0,
6809 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6812 case Intrinsic::experimental_convergence_entry:
6813 case Intrinsic::experimental_convergence_anchor:
6815 case Intrinsic::experimental_convergence_loop:
6817 case Intrinsic::ptrmask: {
6821 "llvm.ptrmask intrinsic first argument must be pointer or vector "
6826 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
6831 "llvm.ptrmask intrinsic arguments must have the same number of "
6835 "llvm.ptrmask intrinsic second argument bitwidth must match "
6836 "pointer index type size of first argument",
6840 case Intrinsic::thread_pointer: {
6842 DL.getDefaultGlobalsAddressSpace(),
6843 "llvm.thread.pointer intrinsic return type must be for the globals "
6848 case Intrinsic::threadlocal_address: {
6851 "llvm.threadlocal.address first argument must be a GlobalValue");
6853 "llvm.threadlocal.address operand isThreadLocal() must be true");
6856 case Intrinsic::lifetime_start:
6857 case Intrinsic::lifetime_end: {
6860 "llvm.lifetime.start/end can only be used on alloca or poison",
6869 if (
F->hasPersonalityFn() &&
6873 if (BlockEHFuncletColors.
empty())
6877 bool InEHFunclet =
false;
6881 for (BasicBlock *ColorFirstBB : CV)
6882 if (
auto It = ColorFirstBB->getFirstNonPHIIt();
6883 It != ColorFirstBB->end())
6888 bool HasToken =
false;
6895 Check(HasToken,
"Missing funclet token on intrinsic call", &
Call);
6919void Verifier::visit(DbgLabelRecord &DLR) {
6921 "invalid #dbg_label intrinsic variable", &DLR, DLR.
getRawLabel());
6934 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DLR, BB,
F);
6938 if (!LabelSP || !LocSP)
6942 "mismatched subprogram between #dbg_label label and !dbg attachment",
6943 &DLR, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6944 Loc->getScope()->getSubprogram());
6947void Verifier::visit(DbgVariableRecord &DVR) {
6951 CheckDI(DVR.
getType() == DbgVariableRecord::LocationType::Value ||
6952 DVR.
getType() == DbgVariableRecord::LocationType::Declare ||
6953 DVR.
getType() == DbgVariableRecord::LocationType::Assign,
6954 "invalid #dbg record type", &DVR, DVR.
getType(), BB,
F);
6962 "invalid #dbg record address/value", &DVR, MD, BB,
F);
6964 visitValueAsMetadata(*VAM,
F);
6967 Type *Ty = VAM->getValue()->getType();
6969 "location of #dbg_declare must be a pointer or int", &DVR, MD, BB,
6973 visitDIArgList(*AL,
F);
6987 "invalid #dbg_assign DIAssignID", &DVR, DVR.
getRawAssignID(), BB,
6990 AreDebugLocsAllowed::No);
6999 "invalid #dbg_assign address", &DVR, DVR.
getRawAddress(), BB,
F);
7001 visitValueAsMetadata(*VAM,
F);
7004 "invalid #dbg_assign address expression", &DVR,
7011 "inst not in same function as #dbg_assign",
I, &DVR, BB,
F);
7021 &DVR, DLNode, BB,
F);
7027 if (!VarSP || !LocSP)
7031 "mismatched subprogram between #dbg record variable and DILocation",
7033 Loc->getScope()->getSubprogram(), BB,
F);
7038void Verifier::visitVPIntrinsic(VPIntrinsic &VPI) {
7042 Check(RetTy->getElementCount() == ValTy->getElementCount(),
7043 "VP cast intrinsic first argument and result vector lengths must be "
7047 switch (VPCast->getIntrinsicID()) {
7050 case Intrinsic::vp_trunc:
7052 "llvm.vp.trunc intrinsic first argument and result element type "
7056 "llvm.vp.trunc intrinsic the bit size of first argument must be "
7057 "larger than the bit size of the return type",
7060 case Intrinsic::vp_zext:
7061 case Intrinsic::vp_sext:
7063 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
7064 "element type must be integer",
7067 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
7068 "argument must be smaller than the bit size of the return type",
7071 case Intrinsic::vp_fptoui:
7072 case Intrinsic::vp_fptosi:
7073 case Intrinsic::vp_lrint:
7074 case Intrinsic::vp_llrint:
7077 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
7078 "type must be floating-point and result element type must be integer",
7081 case Intrinsic::vp_uitofp:
7082 case Intrinsic::vp_sitofp:
7085 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
7086 "type must be integer and result element type must be floating-point",
7089 case Intrinsic::vp_fptrunc:
7091 "llvm.vp.fptrunc intrinsic first argument and result element type "
7092 "must be floating-point",
7095 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
7096 "larger than the bit size of the return type",
7099 case Intrinsic::vp_fpext:
7101 "llvm.vp.fpext intrinsic first argument and result element type "
7102 "must be floating-point",
7105 "llvm.vp.fpext intrinsic the bit size of first argument must be "
7106 "smaller than the bit size of the return type",
7109 case Intrinsic::vp_ptrtoint:
7111 "llvm.vp.ptrtoint intrinsic first argument element type must be "
7112 "pointer and result element type must be integer",
7115 case Intrinsic::vp_inttoptr:
7117 "llvm.vp.inttoptr intrinsic first argument element type must be "
7118 "integer and result element type must be pointer",
7125 case Intrinsic::vp_fcmp: {
7128 "invalid predicate for VP FP comparison intrinsic", &VPI);
7131 case Intrinsic::vp_icmp: {
7134 "invalid predicate for VP integer comparison intrinsic", &VPI);
7137 case Intrinsic::vp_is_fpclass: {
7140 "unsupported bits for llvm.vp.is.fpclass test mask");
7143 case Intrinsic::experimental_vp_splice: {
7146 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
7148 AttributeList
Attrs = VPI.
getParent()->getParent()->getAttributes();
7149 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
7150 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
7152 Check((Idx < 0 && std::abs(Idx) <= KnownMinNumElements) ||
7153 (Idx >= 0 && Idx < KnownMinNumElements),
7154 "The splice index exceeds the range [-VL, VL-1] where VL is the "
7155 "known minimum number of elements in the vector. For scalable "
7156 "vectors the minimum number of elements is determined from "
7164void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) {
7166 bool HasRoundingMD =
7170 NumOperands += (1 + HasRoundingMD);
7176 "invalid arguments for constrained FP intrinsic", &FPI);
7179 case Intrinsic::experimental_constrained_lrint:
7180 case Intrinsic::experimental_constrained_llrint: {
7184 "Intrinsic does not support vectors", &FPI);
7188 case Intrinsic::experimental_constrained_lround:
7189 case Intrinsic::experimental_constrained_llround: {
7193 "Intrinsic does not support vectors", &FPI);
7197 case Intrinsic::experimental_constrained_fcmp:
7198 case Intrinsic::experimental_constrained_fcmps: {
7201 "invalid predicate for constrained FP comparison intrinsic", &FPI);
7205 case Intrinsic::experimental_constrained_fptosi:
7206 case Intrinsic::experimental_constrained_fptoui: {
7210 "Intrinsic first argument must be floating point", &FPI);
7217 "Intrinsic first argument and result disagree on vector use", &FPI);
7219 "Intrinsic result must be an integer", &FPI);
7222 "Intrinsic first argument and result vector lengths must be equal",
7228 case Intrinsic::experimental_constrained_sitofp:
7229 case Intrinsic::experimental_constrained_uitofp: {
7233 "Intrinsic first argument must be integer", &FPI);
7240 "Intrinsic first argument and result disagree on vector use", &FPI);
7242 "Intrinsic result must be a floating point", &FPI);
7245 "Intrinsic first argument and result vector lengths must be equal",
7251 case Intrinsic::experimental_constrained_fptrunc:
7252 case Intrinsic::experimental_constrained_fpext: {
7258 "Intrinsic first argument must be FP or FP vector", &FPI);
7260 "Intrinsic result must be FP or FP vector", &FPI);
7262 "Intrinsic first argument and result disagree on vector use", &FPI);
7266 "Intrinsic first argument and result vector lengths must be equal",
7269 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
7271 "Intrinsic first argument's type must be larger than result type",
7275 "Intrinsic first argument's type must be smaller than result type",
7291 "invalid exception behavior argument", &FPI);
7292 if (HasRoundingMD) {
7298void Verifier::verifyFragmentExpression(
const DbgVariableRecord &DVR) {
7303 if (!V || !
E || !
E->isValid())
7307 auto Fragment =
E->getFragmentInfo();
7317 if (
V->isArtificial())
7320 verifyFragmentExpression(*V, *Fragment, &DVR);
7323template <
typename ValueOrMetadata>
7324void Verifier::verifyFragmentExpression(
const DIVariable &V,
7326 ValueOrMetadata *
Desc) {
7329 auto VarSize =
V.getSizeInBits();
7335 CheckDI(FragSize + FragOffset <= *VarSize,
7336 "fragment is larger than or outside of variable",
Desc, &V);
7337 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
7340void Verifier::verifyFnArgs(
const DbgVariableRecord &DVR) {
7352 CheckDI(Var,
"#dbg record without variable");
7354 unsigned ArgNo = Var->
getArg();
7360 if (DebugFnArgs.
size() < ArgNo)
7361 DebugFnArgs.
resize(ArgNo,
nullptr);
7363 auto *Prev = DebugFnArgs[ArgNo - 1];
7364 DebugFnArgs[ArgNo - 1] = Var;
7365 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DVR,
7369void Verifier::verifyNotEntryValue(
const DbgVariableRecord &DVR) {
7373 if (!
E || !
E->isValid())
7383 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
7388 "Entry values are only allowed in MIR unless they target a "
7389 "swiftasync Argument",
7393void Verifier::verifyCompileUnits() {
7397 if (
M.getContext().isODRUniquingDebugTypes())
7399 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
7400 SmallPtrSet<const Metadata *, 2> Listed;
7403 for (
const auto *CU : CUVisited)
7404 CheckDI(Listed.
count(CU),
"DICompileUnit not listed in llvm.dbg.cu", CU);
7408void Verifier::verifyDeoptimizeCallingConvs() {
7409 if (DeoptimizeDeclarations.
empty())
7413 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
7414 Check(
First->getCallingConv() ==
F->getCallingConv(),
7415 "All llvm.experimental.deoptimize declarations must have the same "
7416 "calling convention",
7421void Verifier::verifyAttachedCallBundle(
const CallBase &
Call,
7422 const OperandBundleUse &BU) {
7425 Check((FTy->getReturnType()->isPointerTy() ||
7427 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
7428 "function returning a pointer or a non-returning function that has a "
7433 "operand bundle \"clang.arc.attachedcall\" requires one function as "
7441 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
7442 IID == Intrinsic::objc_claimAutoreleasedReturnValue ||
7443 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
7444 "invalid function argument",
Call);
7446 StringRef FnName = Fn->
getName();
7447 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
7448 FnName ==
"objc_claimAutoreleasedReturnValue" ||
7449 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
7450 "invalid function argument",
Call);
7454void Verifier::verifyNoAliasScopeDecl() {
7455 if (NoAliasScopeDecls.
empty())
7459 for (
auto *
II : NoAliasScopeDecls) {
7460 assert(
II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
7461 "Not a llvm.experimental.noalias.scope.decl ?");
7464 Check(ScopeListMV !=
nullptr,
7465 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
7470 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode",
II);
7471 Check(ScopeListMD->getNumOperands() == 1,
7472 "!id.scope.list must point to a list with a single scope",
II);
7473 visitAliasScopeListMetadata(ScopeListMD);
7483 auto GetScope = [](IntrinsicInst *
II) {
7486 return &
cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
7491 auto Compare = [GetScope](IntrinsicInst *Lhs, IntrinsicInst *Rhs) {
7492 return GetScope(Lhs) < GetScope(Rhs);
7499 auto ItCurrent = NoAliasScopeDecls.begin();
7500 while (ItCurrent != NoAliasScopeDecls.end()) {
7501 auto CurScope = GetScope(*ItCurrent);
7502 auto ItNext = ItCurrent;
7505 }
while (ItNext != NoAliasScopeDecls.end() &&
7506 GetScope(*ItNext) == CurScope);
7511 if (ItNext - ItCurrent < 32)
7515 Check(!DT.dominates(
I, J),
7516 "llvm.experimental.noalias.scope.decl dominates another one "
7517 "with the same scope",
7531 Verifier V(OS,
true, *f.getParent());
7535 return !V.verify(
F);
7539 bool *BrokenDebugInfo) {
7541 Verifier V(OS, !BrokenDebugInfo, M);
7543 bool Broken =
false;
7545 Broken |= !V.verify(
F);
7547 Broken |= !V.verify();
7548 if (BrokenDebugInfo)
7549 *BrokenDebugInfo = V.hasBrokenDebugInfo();
7560 std::unique_ptr<Verifier> V;
7561 bool FatalErrors =
true;
7566 explicit VerifierLegacyPass(
bool FatalErrors)
7568 FatalErrors(FatalErrors) {
7572 bool doInitialization(
Module &M)
override {
7573 V = std::make_unique<Verifier>(
7579 if (!
V->verify(
F) && FatalErrors) {
7580 errs() <<
"in function " <<
F.getName() <<
'\n';
7586 bool doFinalization(
Module &M)
override {
7587 bool HasErrors =
false;
7588 for (Function &
F : M)
7589 if (
F.isDeclaration())
7590 HasErrors |= !
V->verify(
F);
7592 HasErrors |= !
V->verify();
7593 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
7598 void getAnalysisUsage(AnalysisUsage &AU)
const override {
7606template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
7608 return Diagnostic->CheckFailed(
Args...);
7611#define CheckTBAA(C, ...) \
7614 CheckFailed(__VA_ARGS__); \
7622TBAAVerifier::TBAABaseNodeSummary
7626 CheckFailed(
"Base nodes must have at least two operands", &
I, BaseNode);
7630 auto Itr = TBAABaseNodes.find(BaseNode);
7631 if (Itr != TBAABaseNodes.end())
7634 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
7635 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
7637 assert(InsertResult.second &&
"We just checked!");
7641TBAAVerifier::TBAABaseNodeSummary
7642TBAAVerifier::verifyTBAABaseNodeImpl(Instruction &
I,
const MDNode *BaseNode,
7644 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
7648 return isValidScalarTBAANode(BaseNode)
7649 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
7655 CheckFailed(
"Access tag nodes must have the number of operands that is a "
7656 "multiple of 3!", BaseNode);
7661 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
7671 if (!TypeSizeNode) {
7672 CheckFailed(
"Type size nodes must be constants!", &
I, BaseNode);
7679 CheckFailed(
"Struct tag nodes have a string as their first operand",
7686 std::optional<APInt> PrevOffset;
7691 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7692 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7693 for (
unsigned Idx = FirstFieldOpNo; Idx < BaseNode->
getNumOperands();
7694 Idx += NumOpsPerField) {
7695 const MDOperand &FieldTy = BaseNode->
getOperand(Idx);
7696 const MDOperand &FieldOffset = BaseNode->
getOperand(Idx + 1);
7698 CheckFailed(
"Incorrect field entry in struct type node!", &
I, BaseNode);
7703 auto *OffsetEntryCI =
7705 if (!OffsetEntryCI) {
7706 CheckFailed(
"Offset entries must be constants!", &
I, BaseNode);
7712 BitWidth = OffsetEntryCI->getBitWidth();
7714 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
7716 "Bitwidth between the offsets and struct type entries must match", &
I,
7728 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
7731 CheckFailed(
"Offsets must be increasing!", &
I, BaseNode);
7735 PrevOffset = OffsetEntryCI->getValue();
7740 if (!MemberSizeNode) {
7741 CheckFailed(
"Member size entries must be constants!", &
I, BaseNode);
7748 return Failed ? InvalidNode
7749 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
7771 return Parent && Visited.
insert(Parent).second &&
7775bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
7776 auto ResultIt = TBAAScalarNodes.find(MD);
7777 if (ResultIt != TBAAScalarNodes.end())
7778 return ResultIt->second;
7780 SmallPtrSet<const MDNode *, 4> Visited;
7782 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
7784 assert(InsertResult.second &&
"Just checked!");
7793MDNode *TBAAVerifier::getFieldNodeFromTBAABaseNode(Instruction &
I,
7794 const MDNode *BaseNode,
7805 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7806 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7807 for (
unsigned Idx = FirstFieldOpNo; Idx < BaseNode->
getNumOperands();
7808 Idx += NumOpsPerField) {
7809 auto *OffsetEntryCI =
7811 if (OffsetEntryCI->getValue().ugt(
Offset)) {
7812 if (Idx == FirstFieldOpNo) {
7813 CheckFailed(
"Could not find TBAA parent in struct type node", &
I,
7818 unsigned PrevIdx = Idx - NumOpsPerField;
7819 auto *PrevOffsetEntryCI =
7821 Offset -= PrevOffsetEntryCI->getValue();
7829 Offset -= LastOffsetEntryCI->getValue();
7834 if (!
Type ||
Type->getNumOperands() < 3)
7849 "This instruction shall not have a TBAA access tag!", &
I);
7851 bool IsStructPathTBAA =
7855 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
7865 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
7868 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
7875 CheckTBAA(AccessSizeNode,
"Access size field must be a constant", &
I, MD);
7879 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
7884 "Immutability tag on struct tag metadata must be a constant", &
I,
7887 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
7888 "Immutability part of the struct tag metadata must be either 0 or 1",
7893 "Malformed struct tag metadata: base and access-type "
7894 "should be non-null and point to Metadata nodes",
7895 &
I, MD, BaseNode, AccessType);
7898 CheckTBAA(isValidScalarTBAANode(AccessType),
7899 "Access type node must be a valid scalar type", &
I, MD,
7904 CheckTBAA(OffsetCI,
"Offset must be constant integer", &
I, MD);
7907 bool SeenAccessTypeInPath =
false;
7912 BaseNode = getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset,
7914 if (!StructPath.
insert(BaseNode).second) {
7915 CheckFailed(
"Cycle detected in struct path", &
I, MD);
7920 unsigned BaseNodeBitWidth;
7921 std::tie(
Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(
I, BaseNode,
7929 SeenAccessTypeInPath |= BaseNode == AccessType;
7931 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
7932 CheckTBAA(
Offset == 0,
"Offset not zero at the point of scalar access",
7936 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
7937 (IsNewFormat && BaseNodeBitWidth == ~0u),
7938 "Access bit-width not the same as description bit-width", &
I, MD,
7939 BaseNodeBitWidth,
Offset.getBitWidth());
7941 if (IsNewFormat && SeenAccessTypeInPath)
7945 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!", &
I,
7950char VerifierLegacyPass::ID = 0;
7951INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
7954 return new VerifierLegacyPass(FatalErrors);
7972 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
7980 if (res.IRBroken && FatalErrors)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU address space definition.
ArrayRef< TableEntry > TableRef
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis false
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares the LLVM IR specialization of the GenericConvergenceVerifier template.
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
static bool runOnFunction(Function &F, bool PostInlining)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file contains the declarations for profiling metadata utility functions.
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static unsigned getNumElements(Type *Ty)
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
verify safepoint Safepoint IR Verifier
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static bool IsScalarTBAANodeImpl(const MDNode *MD, SmallPtrSetImpl< const MDNode * > &Visited)
static bool isType(const Metadata *MD)
static Instruction * getSuccPad(Instruction *Terminator)
static bool isNewFormatTBAATypeNode(llvm::MDNode *Type)
#define CheckDI(C,...)
We know that a debug info condition should be true, if not print an error message.
static void forEachUser(const Value *User, SmallPtrSet< const Value *, 32 > &Visited, llvm::function_ref< bool(const Value *)> Callback)
static bool isDINode(const Metadata *MD)
static bool isScope(const Metadata *MD)
static cl::opt< bool > VerifyNoAliasScopeDomination("verify-noalias-scope-decl-dom", cl::Hidden, cl::init(false), cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical " "scopes are not dominating"))
static bool isTypeCongruent(Type *L, Type *R)
Two types are "congruent" if they are identical, or if they are both pointer types with different poi...
static bool isConstantIntMetadataOperand(const Metadata *MD)
static bool IsRootTBAANode(const MDNode *MD)
static Value * getParentPad(Value *EHPad)
static bool hasConflictingReferenceFlags(unsigned Flags)
Detect mutually exclusive flags.
static AttrBuilder getParameterABIAttributes(LLVMContext &C, unsigned I, AttributeList Attrs)
bool isFiniteNonZero() const
const fltSemantics & getSemantics() const
Class for arbitrary precision integers.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
bool isMinValue() const
Determine if this is the smallest unsigned value.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
int64_t getSExtValue() const
Get sign extended value.
bool isMaxValue() const
Determine if this is the largest unsigned value.
This class represents a conversion between pointers from one address space to another.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
LLVM_ABI bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
unsigned getAddressSpace() const
Return the address space for the allocation.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
const Value * getArraySize() const
Get the number of elements allocated.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_ABI bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
bool empty() const
empty - Check if the array is empty.
static bool isFPOperation(BinOp Op)
BinOp getOperation() const
static LLVM_ABI StringRef getOperationName(BinOp Op)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI const ConstantRange & getValueAsConstantRange() const
Return the attribute's value as a ConstantRange.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
const Instruction & front() const
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This class represents a no-op cast from one type to another.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
bool isConditional() const
Value * getCondition() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool doesNotAccessMemory(unsigned OpNo) const
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Get the attribute of a given kind from a given arg.
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
bool onlyReadsMemory(unsigned OpNo) const
Value * getCalledOperand() const
Type * getParamElementType(unsigned ArgNo) const
Extract the elementtype type for a parameter.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
bool doesNotReturn() const
Determine if the call cannot return.
LLVM_ABI bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
bool isMustTailCall() const
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
unsigned getNumHandlers() const
return the number of 'handlers' in this catchswitch instruction, except the default handler
Value * getParentPad() const
BasicBlock * getUnwindDest() const
handler_range handlers()
iteration adapter for range-for loops.
BasicBlock * getUnwindDest() const
bool isFPPredicate() const
bool isIntPredicate() const
static bool isIntPredicate(Predicate P)
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
Constant * getPointer() const
The pointer that is signed in this ptrauth signed pointer.
ConstantInt * getKey() const
The Key ID, an i32 constant.
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
static LLVM_ABI bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
static LLVM_ABI ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
LLVM_ABI std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
LLVM_ABI std::optional< RoundingMode > getRoundingMode() const
LLVM_ABI unsigned getNonMetadataArgCount() const
DbgVariableFragmentInfo FragmentInfo
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
DIGlobalVariable * getVariable() const
DIExpression * getExpression() const
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata * getRawScope() const
Base class for scope-like contexts.
Subprogram description. Uses SubclassData1.
Base class for template parameters.
Base class for variables.
Metadata * getRawType() const
Metadata * getRawScope() const
uint64_t getNumOperands() const
A parsed version of the target data layout string in and methods for querying it.
Records a position in IR for a source label (DILabel).
MDNode * getRawLabel() const
DILabel * getLabel() const
Base class for non-instruction debug metadata records that have positions within IR.
LLVM_ABI Function * getFunction()
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
DebugLoc getDebugLoc() const
LLVM_ABI const BasicBlock * getParent() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LocationType getType() const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
DIExpression * getExpression() const
Metadata * getRawAssignID() const
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
MDNode * getRawVariable() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
DIExpression * getAddressExpression() const
MDNode * getAsMDNode() const
Return this as a bar MDNode.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
This instruction compares its operands according to the predicate given to the constructor.
This class represents an extension of floating point types.
This class represents a cast from floating point to signed integer.
This class represents a cast from floating point to unsigned integer.
This class represents a truncation of floating point types.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Value * getParentPad() const
Convenience accessors.
FunctionPass class - This class is used to implement most global optimizations.
Type * getReturnType() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
DISubprogram * getSubprogram() const
Get the attached subprogram.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasPersonalityFn() const
Check whether this function has a personality function.
const Function & getFunction() const
const std::string & getGC() const
Type * getReturnType() const
Returns the type of the ret val.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
LLVM_ABI Value * getBasePtr() const
LLVM_ABI Value * getDerivedPtr() const
void visit(const BlockT &BB)
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
static bool isValidLinkage(LinkageTypes L)
const Constant * getAliasee() const
LLVM_ABI const Function * getResolverFunction() const
static bool isValidLinkage(LinkageTypes L)
const Constant * getResolver() const
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
bool hasExternalLinkage() const
bool isImplicitDSOLocal() const
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasValidDeclarationLinkage() const
LinkageTypes getLinkage() const
bool hasDefaultVisibility() const
bool hasPrivateLinkage() const
bool hasHiddenVisibility() const
bool hasExternalWeakLinkage() const
bool hasDLLImportStorageClass() const
bool hasDLLExportStorageClass() const
bool isDeclarationForLinker() const
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
LLVM_ABI bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
bool hasCommonLinkage() const
bool hasGlobalUnnamedAddr() const
bool hasAppendingLinkage() const
bool hasAvailableExternallyLinkage() const
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
This instruction compares its operands according to the predicate given to the constructor.
BasicBlock * getDestination(unsigned i)
Return the specified destination.
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
unsigned getNumSuccessors() const
This instruction inserts a single (scalar) element into a VectorType value.
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
Value * getAggregateOperand()
ArrayRef< unsigned > getIndices() const
Base class for instruction visitors.
void visit(Iterator Start, Iterator End)
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
This class represents a cast from an integer to a pointer.
static LLVM_ABI bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
@ OB_clang_arc_attachedcall
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
Align getAlign() const
Return the alignment of the access that is being performed.
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
bool isResolved() const
Check if node is fully resolved.
LLVMContext & getContext() const
LLVM_ABI StringRef getString() const
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI StringRef getName() const
LLVM_ABI void print(raw_ostream &ROS, bool IsForDebug=false) const
iterator_range< op_iterator > operands()
op_range incoming_values()
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
This class represents a cast from a pointer to an address (non-capturing ptrtoint).
This class represents a cast from a pointer to an integer.
Value * getValue() const
Convenience accessor.
This class represents a sign extension of integer types.
This class represents a cast from signed integer to floating point.
static LLVM_ABI const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
This instruction constructs a fixed permutation of two input vectors.
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
static LLVM_ABI void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
void insert_range(Range &&R)
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 reserve(size_type N)
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
static constexpr size_t npos
unsigned getNumElements() const
Random access to the elements.
LLVM_ABI Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Returns true if this struct contains a scalable vector.
LLVM_ABI bool visitTBAAMetadata(Instruction &I, const MDNode *MD)
Visit an instruction and return true if it is valid, return false if an invalid TBAA is attached.
Triple - Helper class for working with autoconf configuration names.
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
LLVM_ABI bool containsNonGlobalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a global...
bool isArrayTy() const
True if this is an instance of ArrayType.
LLVM_ABI bool containsNonLocalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a local.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
bool isLabelTy() const
Return true if this is 'label'.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isTokenLikeTy() const
Returns true if this is 'token' or a token-like target type.s.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSingleValueType() const
Return true if the type is a valid type for a register in codegen.
LLVM_ABI bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
bool isVoidTy() const
Return true if this is 'void'.
bool isMetadataTy() const
Return true if this is 'metadata'.
This class represents a cast unsigned integer to floating point.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
iterator_range< user_iterator > materialized_users()
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
iterator_range< user_iterator > users()
bool materialized_use_empty() const
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Check a module for errors, and report separate error states for IR and debug info errors.
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
This class represents zero extension of integer types.
constexpr bool isNonZero() const
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.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
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.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool isFlatGlobalAddrSpace(unsigned AS)
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
LLVM_ABI MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
MatchIntrinsicTypesResult
@ MatchIntrinsicTypes_NoMatchRet
@ MatchIntrinsicTypes_NoMatchArg
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
static const int NoAliasScopeDeclScopeArg
LLVM_ABI bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
std::variant< std::monostate, Loc::Single, Loc::Multi, Loc::MMI, Loc::EntryValue > Variant
Alias for the std::variant specialization base class of DbgVariable.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ System
Synchronized with respect to all concurrently executing threads.
LLVM_ABI std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
@ CE
Windows NT (Windows on ARM)
LLVM_ABI AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
initializer< Ty > init(const Ty &Val)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< NodeBase * > Node
friend class Instruction
Iterator for Instructions in a `BasicBlock.
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.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
FunctionAddr VTableAddr Value
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool canInstructionHaveMMRAs(const Instruction &I)
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
LLVM_ABI unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
LLVM_ABI bool isExplicitlyUnknownProfileMetadata(const MDNode &MD)
testing::Matcher< const detail::ErrorHolder & > Failed()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
bool isa_and_nonnull(const Y &Val)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
auto dyn_cast_or_null(const Y &Val)
GenericConvergenceVerifier< SSAContext > ConvergenceVerifier
LLVM_ABI void initializeVerifierLegacyPassPass(PassRegistry &)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool isModSet(const ModRefInfo MRI)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
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 bool isValueProfileMD(const MDNode *ProfileData)
Checks if an MDNode contains value profiling Metadata.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI unsigned getNumBranchWeights(const MDNode &ProfileData)
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI FunctionPass * createVerifierPass(bool FatalErrors=true)
FunctionAddr VTableAddr Next
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
TinyPtrVector< BasicBlock * > ColorVector
DenormalMode parseDenormalFPAttribute(StringRef Str)
Returns the denormal mode to use for inputs and outputs.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
LLVM_ABI std::unique_ptr< GCStrategy > getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
constexpr bool isCallableCC(CallingConv::ID CC)
LLVM_ABI bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
uint64_t value() const
This is a hole in the type system and should not be abused.
A special type used by analysis passes to provide an address that identifies that particular analysis...
static LLVM_ABI const char * SyntheticFunctionEntryCount
static LLVM_ABI const char * BranchWeights
static LLVM_ABI const char * FunctionEntryCount
static LLVM_ABI const char * UnknownBranchWeightsMarker
static LLVM_ABI const char * ValueProfile
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
void DebugInfoCheckFailed(const Twine &Message)
A debug info check failed.
VerifierSupport(raw_ostream *OS, const Module &M)
bool Broken
Track the brokenness of the module while recursively visiting.
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs)
A check failed (with values to print).
bool BrokenDebugInfo
Broken debug info can be "recovered" from by stripping the debug info.
bool TreatBrokenDebugInfoAsError
Whether to treat broken debug info as an error.
void CheckFailed(const Twine &Message)
A check failed, so printout out the condition and the message.
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs)
A debug info check failed (with values to print).