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"
135 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
136 "scopes are not dominating"));
170 if (isa<Instruction>(V)) {
174 V.printAsOperand(*
OS,
true,
MST);
242 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
248 *
OS <<
A->getAsString() <<
'\n';
268 for (
const T &V : Vs)
272 template <
typename T1,
typename... Ts>
273 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
278 template <
typename... Ts>
void WriteTs() {}
287 *
OS << Message <<
'\n';
295 template <
typename T1,
typename... Ts>
305 *
OS << Message <<
'\n';
311 template <
typename T1,
typename... Ts>
345 Type *LandingPadResultTy;
352 bool HasDebugInfo =
false;
395 SawFrameEscape(
false), TBAAVerifyHelper(this) {
396 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
403 "An instance of this class only works with a specific module!");
415 if (!BB.empty() && BB.back().isTerminator())
419 *
OS <<
"Basic Block in function '" <<
F.getName()
420 <<
"' does not have terminator!\n";
421 BB.printAsOperand(*
OS,
true, MST);
427 auto FailureCB = [
this](
const Twine &Message) {
435 verifySiblingFuncletUnwinds();
438 ConvergenceVerifyHelper.
verify(DT);
440 InstsInThisBlock.
clear();
442 LandingPadResultTy =
nullptr;
443 SawFrameEscape =
false;
444 SiblingFuncletInfo.
clear();
445 verifyNoAliasScopeDecl();
446 NoAliasScopeDecls.
clear();
457 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
462 verifyFrameRecoverIndices();
464 visitGlobalVariable(GV);
467 visitGlobalAlias(GA);
470 visitGlobalIFunc(GI);
473 visitNamedMDNode(NMD);
476 visitComdat(SMEC.getValue());
480 visitModuleCommandLines();
482 verifyCompileUnits();
484 verifyDeoptimizeCallingConvs();
485 DISubprogramAttachments.
clear();
491 enum class AreDebugLocsAllowed {
No,
Yes };
495 enum class RangeLikeMetadataKind {
510 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
514 void visitComdat(
const Comdat &
C);
515 void visitModuleIdents();
516 void visitModuleCommandLines();
517 void visitModuleFlags();
518 void visitModuleFlag(
const MDNode *
Op,
521 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
525 RangeLikeMetadataKind Kind);
530 void visitCallStackMetadata(
MDNode *MD);
536 void visitAnnotationMetadata(
MDNode *Annotation);
537 void visitAliasScopeMetadata(
const MDNode *MD);
538 void visitAliasScopeListMetadata(
const MDNode *MD);
539 void visitAccessGroupMetadata(
const MDNode *MD);
541 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
542#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
543#include "llvm/IR/Metadata.def"
544 void visitDIScope(
const DIScope &
N);
568 void checkPtrToAddr(
Type *SrcTy,
Type *DestTy,
const Value &V);
573 void visitPHINode(
PHINode &PN);
582 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
619 void verifySwiftErrorCall(
CallBase &Call,
const Value *SwiftErrorVal);
620 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
622 void verifyMustTailCall(
CallInst &CI);
623 bool verifyAttributeCount(
AttributeList Attrs,
unsigned Params);
629 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
630 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
632 void visitConstantExprsRecursively(
const Constant *EntryC);
635 void verifyInlineAsmCall(
const CallBase &Call);
636 void verifyStatepoint(
const CallBase &Call);
637 void verifyFrameRecoverIndices();
638 void verifySiblingFuncletUnwinds();
641 template <
typename ValueOrMetadata>
642 void verifyFragmentExpression(
const DIVariable &V,
644 ValueOrMetadata *
Desc);
649 void verifyCompileUnits();
653 void verifyDeoptimizeCallingConvs();
655 void verifyAttachedCallBundle(
const CallBase &Call,
659 void verifyNoAliasScopeDecl();
665#define Check(C, ...) \
668 CheckFailed(__VA_ARGS__); \
675#define CheckDI(C, ...) \
678 DebugInfoCheckFailed(__VA_ARGS__); \
686 CheckDI(
I.DebugMarker->MarkedInstr == &
I,
687 "Instruction has invalid DebugMarker", &
I);
688 CheckDI(!isa<PHINode>(&
I) || !
I.hasDbgRecords(),
689 "PHI Node must not have any attached DbgRecords", &
I);
692 "DbgRecord had invalid DebugMarker", &
I, &DR);
695 visitMDNode(*Loc, AreDebugLocsAllowed::Yes);
696 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR)) {
700 verifyFragmentExpression(*DVR);
701 verifyNotEntryValue(*DVR);
702 }
else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
710 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
711 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
723 while (!WorkList.
empty()) {
725 if (!Visited.
insert(Cur).second)
732void Verifier::visitGlobalValue(
const GlobalValue &GV) {
734 "Global is external, but doesn't have external or weak linkage!", &GV);
736 if (
const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
737 if (
const MDNode *Associated =
738 GO->getMetadata(LLVMContext::MD_associated)) {
739 Check(Associated->getNumOperands() == 1,
740 "associated metadata must have one operand", &GV, Associated);
741 const Metadata *
Op = Associated->getOperand(0).get();
742 Check(
Op,
"associated metadata must have a global value", GO, Associated);
744 const auto *VM = dyn_cast_or_null<ValueAsMetadata>(
Op);
745 Check(VM,
"associated metadata must be ValueAsMetadata", GO, Associated);
747 Check(isa<PointerType>(VM->getValue()->getType()),
748 "associated value must be pointer typed", GV, Associated);
751 Check(isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
752 "associated metadata must point to a GlobalObject", GO, Stripped);
753 Check(Stripped != GO,
754 "global values should not associate to themselves", GO,
760 if (
const MDNode *AbsoluteSymbol =
761 GO->getMetadata(LLVMContext::MD_absolute_symbol)) {
762 verifyRangeLikeMetadata(*GO, AbsoluteSymbol,
763 DL.getIntPtrType(GO->getType()),
764 RangeLikeMetadataKind::AbsoluteSymbol);
769 "Only global variables can have appending linkage!", &GV);
774 "Only global arrays can have appending linkage!", GVar);
778 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
782 "dllexport GlobalValue must have default or protected visibility",
787 "dllimport GlobalValue must have default visibility", &GV);
788 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
794 "Global is marked as dllimport, but not external", &GV);
799 "GlobalValue with local linkage or non-default "
800 "visibility must be dso_local!",
805 if (!
I->getParent() || !
I->getParent()->getParent())
806 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
808 else if (
I->getParent()->getParent()->getParent() != &M)
809 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
810 I->getParent()->getParent(),
811 I->getParent()->getParent()->getParent());
813 }
else if (
const Function *
F = dyn_cast<Function>(V)) {
814 if (
F->getParent() != &M)
815 CheckFailed(
"Global is used by function in a different module", &GV, &M,
828 "huge alignment values are unsupported", &GV);
833 "Global variable initializer type does not match global "
837 "Global variable initializer must be sized", &GV);
843 "'common' global must have a zero initializer!", &GV);
846 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
851 GV.
getName() ==
"llvm.global_dtors")) {
853 "invalid linkage for intrinsic global variable", &GV);
855 "invalid uses of intrinsic global variable", &GV);
859 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
860 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
866 "wrong type for intrinsic global variable", &GV);
868 "the third field of the element type is mandatory, "
869 "specify ptr null to migrate from the obsoleted 2-field form");
877 GV.
getName() ==
"llvm.compiler.used")) {
879 "invalid linkage for intrinsic global variable", &GV);
881 "invalid uses of intrinsic global variable", &GV);
883 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
884 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
885 Check(PTy,
"wrong type for intrinsic global variable", &GV);
889 Check(InitArray,
"wrong initalizer for intrinsic global variable",
893 Check(isa<GlobalVariable>(V) || isa<Function>(V) ||
897 Twine(
"members of ") + GV.
getName() +
" must be named", V);
906 for (
auto *MD : MDs) {
907 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
908 visitDIGlobalVariableExpression(*GVE);
910 CheckDI(
false,
"!dbg attachment of global variable must be a "
911 "DIGlobalVariableExpression");
921 "Global @" + GV.
getName() +
" has illegal target extension type",
925 visitGlobalValue(GV);
932 visitGlobalValue(GV);
938 visitAliaseeSubExpr(Visited, GA,
C);
944 Check(isa<GlobalValue>(
C) &&
945 cast<GlobalValue>(
C).hasAvailableExternallyLinkage(),
946 "available_externally alias must point to available_externally "
950 if (
const auto *GV = dyn_cast<GlobalValue>(&
C)) {
956 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
957 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
959 Check(!GA2->isInterposable(),
960 "Alias cannot point to an interposable alias", &GA);
968 if (
const auto *CE = dyn_cast<ConstantExpr>(&
C))
969 visitConstantExprsRecursively(CE);
971 for (
const Use &U :
C.operands()) {
973 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
974 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
975 else if (
const auto *C2 = dyn_cast<Constant>(V))
976 visitAliaseeSubExpr(Visited, GA, *C2);
980void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
982 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
983 "weak_odr, external, or available_externally linkage!",
986 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
988 "Alias and aliasee types should match!", &GA);
990 Check(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
991 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
993 visitAliaseeSubExpr(GA, *Aliasee);
995 visitGlobalValue(GA);
998void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
1000 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
1001 "weak_odr, or external linkage!",
1006 Check(
Resolver,
"IFunc must have a Function resolver", &GI);
1008 "IFunc resolver must be a definition", &GI);
1014 Check(isa<PointerType>(
Resolver->getFunctionType()->getReturnType()),
1015 "IFunc resolver must return a pointer", &GI);
1018 "IFunc resolver has incorrect type", &GI);
1021void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1026 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1028 if (NMD.
getName() ==
"llvm.dbg.cu")
1029 CheckDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
1034 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1038void Verifier::visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
1041 if (!MDNodes.
insert(&MD).second)
1045 "MDNode context does not match Module context!", &MD);
1050 case Metadata::MDTupleKind:
1052#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1053 case Metadata::CLASS##Kind: \
1054 visit##CLASS(cast<CLASS>(MD)); \
1056#include "llvm/IR/Metadata.def"
1062 Check(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
1064 CheckDI(!isa<DILocation>(
Op) || AllowLocs == AreDebugLocsAllowed::Yes,
1065 "DILocation not allowed within this metadata node", &MD,
Op);
1066 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
1067 visitMDNode(*
N, AllowLocs);
1070 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
1071 visitValueAsMetadata(*V,
nullptr);
1084 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1086 auto *
L = dyn_cast<LocalAsMetadata>(&MD);
1090 Check(
F,
"function-local metadata used outside a function", L);
1095 if (
Instruction *
I = dyn_cast<Instruction>(
L->getValue())) {
1096 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1097 ActualF =
I->getParent()->getParent();
1098 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(
L->getValue()))
1100 else if (
Argument *
A = dyn_cast<Argument>(
L->getValue()))
1101 ActualF =
A->getParent();
1102 assert(ActualF &&
"Unimplemented function local metadata case!");
1104 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1109 visitValueAsMetadata(*VAM,
F);
1114 if (
auto *
N = dyn_cast<MDNode>(MD)) {
1115 visitMDNode(*
N, AreDebugLocsAllowed::No);
1121 if (!MDNodes.
insert(MD).second)
1124 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
1125 visitValueAsMetadata(*V,
F);
1127 if (
auto *AL = dyn_cast<DIArgList>(MD))
1128 visitDIArgList(*AL,
F);
1135void Verifier::visitDILocation(
const DILocation &
N) {
1136 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1137 "location requires a valid scope", &
N,
N.getRawScope());
1138 if (
auto *IA =
N.getRawInlinedAt())
1139 CheckDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
1140 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1141 CheckDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1148void Verifier::visitDIScope(
const DIScope &
N) {
1149 if (
auto *
F =
N.getRawFile())
1150 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1154 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1157 auto *LBound =
N.getRawLowerBound();
1158 CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||
1159 isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1160 "LowerBound must be signed constant or DIVariable or DIExpression",
1162 auto *UBound =
N.getRawUpperBound();
1163 CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) ||
1164 isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1165 "UpperBound must be signed constant or DIVariable or DIExpression",
1167 auto *Stride =
N.getRawStride();
1168 CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) ||
1169 isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1170 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1171 auto *Bias =
N.getRawBias();
1172 CheckDI(!Bias || isa<ConstantAsMetadata>(Bias) || isa<DIVariable>(Bias) ||
1173 isa<DIExpression>(Bias),
1174 "Bias must be signed constant or DIVariable or DIExpression", &
N);
1176 auto *
Size =
N.getRawSizeInBits();
1178 "SizeInBits must be a constant");
1181void Verifier::visitDISubrange(
const DISubrange &
N) {
1182 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1183 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1184 "Subrange can have any one of count or upperBound", &
N);
1185 auto *CBound =
N.getRawCountNode();
1186 CheckDI(!CBound || isa<ConstantAsMetadata>(CBound) ||
1187 isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1188 "Count must be signed constant or DIVariable or DIExpression", &
N);
1189 auto Count =
N.getCount();
1190 CheckDI(!Count || !isa<ConstantInt *>(Count) ||
1191 cast<ConstantInt *>(Count)->getSExtValue() >= -1,
1192 "invalid subrange count", &
N);
1193 auto *LBound =
N.getRawLowerBound();
1194 CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||
1195 isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1196 "LowerBound must be signed constant or DIVariable or DIExpression",
1198 auto *UBound =
N.getRawUpperBound();
1199 CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) ||
1200 isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1201 "UpperBound must be signed constant or DIVariable or DIExpression",
1203 auto *Stride =
N.getRawStride();
1204 CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) ||
1205 isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1206 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1210 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1211 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1212 "GenericSubrange can have any one of count or upperBound", &
N);
1213 auto *CBound =
N.getRawCountNode();
1214 CheckDI(!CBound || isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1215 "Count must be signed constant or DIVariable or DIExpression", &
N);
1216 auto *LBound =
N.getRawLowerBound();
1217 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1218 CheckDI(isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1219 "LowerBound must be signed constant or DIVariable or DIExpression",
1221 auto *UBound =
N.getRawUpperBound();
1222 CheckDI(!UBound || isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1223 "UpperBound must be signed constant or DIVariable or DIExpression",
1225 auto *Stride =
N.getRawStride();
1226 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1227 CheckDI(isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1228 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1232 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1236 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1237 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1238 N.getTag() == dwarf::DW_TAG_string_type,
1241 auto *
Size =
N.getRawSizeInBits();
1243 "SizeInBits must be a constant");
1247 visitDIBasicType(
N);
1249 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type,
"invalid tag", &
N);
1250 CheckDI(
N.getEncoding() == dwarf::DW_ATE_signed_fixed ||
1251 N.getEncoding() == dwarf::DW_ATE_unsigned_fixed,
1252 "invalid encoding", &
N);
1256 "invalid kind", &
N);
1258 N.getFactorRaw() == 0,
1259 "factor should be 0 for rationals", &
N);
1261 (
N.getNumeratorRaw() == 0 &&
N.getDenominatorRaw() == 0),
1262 "numerator and denominator should be 0 for non-rationals", &
N);
1266 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1267 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1275 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1276 N.getTag() == dwarf::DW_TAG_pointer_type ||
1277 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1278 N.getTag() == dwarf::DW_TAG_reference_type ||
1279 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1280 N.getTag() == dwarf::DW_TAG_const_type ||
1281 N.getTag() == dwarf::DW_TAG_immutable_type ||
1282 N.getTag() == dwarf::DW_TAG_volatile_type ||
1283 N.getTag() == dwarf::DW_TAG_restrict_type ||
1284 N.getTag() == dwarf::DW_TAG_atomic_type ||
1285 N.getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ||
1286 N.getTag() == dwarf::DW_TAG_member ||
1287 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1288 N.getTag() == dwarf::DW_TAG_inheritance ||
1289 N.getTag() == dwarf::DW_TAG_friend ||
1290 N.getTag() == dwarf::DW_TAG_set_type ||
1291 N.getTag() == dwarf::DW_TAG_template_alias,
1293 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1294 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1295 N.getRawExtraData());
1298 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1299 if (
auto *
T =
N.getRawBaseType()) {
1300 auto *
Enum = dyn_cast_or_null<DICompositeType>(
T);
1301 auto *
Subrange = dyn_cast_or_null<DISubrangeType>(
T);
1302 auto *
Basic = dyn_cast_or_null<DIBasicType>(
T);
1304 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1305 (Subrange &&
Subrange->getTag() == dwarf::DW_TAG_subrange_type) ||
1306 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1307 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1308 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1309 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1310 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1311 "invalid set base type", &
N,
T);
1317 N.getRawBaseType());
1319 if (
N.getDWARFAddressSpace()) {
1320 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1321 N.getTag() == dwarf::DW_TAG_reference_type ||
1322 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1323 "DWARF address space only applies to pointer or reference types",
1327 auto *
Size =
N.getRawSizeInBits();
1329 isa<DIExpression>(
Size),
1330 "SizeInBits must be a constant or DIVariable or DIExpression");
1335 return ((Flags & DINode::FlagLValueReference) &&
1336 (Flags & DINode::FlagRValueReference)) ||
1337 ((Flags & DINode::FlagTypePassByValue) &&
1338 (Flags & DINode::FlagTypePassByReference));
1341void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1342 auto *Params = dyn_cast<MDTuple>(&RawParams);
1343 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1345 CheckDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
1354 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1355 N.getTag() == dwarf::DW_TAG_structure_type ||
1356 N.getTag() == dwarf::DW_TAG_union_type ||
1357 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1358 N.getTag() == dwarf::DW_TAG_class_type ||
1359 N.getTag() == dwarf::DW_TAG_variant_part ||
1360 N.getTag() == dwarf::DW_TAG_variant ||
1361 N.getTag() == dwarf::DW_TAG_namelist,
1366 N.getRawBaseType());
1368 CheckDI(!
N.getRawElements() || isa<MDTuple>(
N.getRawElements()),
1369 "invalid composite elements", &
N,
N.getRawElements());
1371 N.getRawVTableHolder());
1373 "invalid reference flags", &
N);
1374 unsigned DIBlockByRefStruct = 1 << 4;
1375 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1376 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1378 "DISubprogram contains null entry in `elements` field", &
N);
1381 const DINodeArray
Elements =
N.getElements();
1383 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1384 "invalid vector, expected one element of type subrange", &
N);
1387 if (
auto *Params =
N.getRawTemplateParams())
1388 visitTemplateParams(
N, *Params);
1390 if (
auto *
D =
N.getRawDiscriminator()) {
1391 CheckDI(isa<DIDerivedType>(
D) &&
N.getTag() == dwarf::DW_TAG_variant_part,
1392 "discriminator can only appear on variant part");
1395 if (
N.getRawDataLocation()) {
1396 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1397 "dataLocation can only appear in array type");
1400 if (
N.getRawAssociated()) {
1401 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1402 "associated can only appear in array type");
1405 if (
N.getRawAllocated()) {
1406 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1407 "allocated can only appear in array type");
1410 if (
N.getRawRank()) {
1411 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1412 "rank can only appear in array type");
1415 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1416 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1419 auto *
Size =
N.getRawSizeInBits();
1421 isa<DIExpression>(
Size),
1422 "SizeInBits must be a constant or DIVariable or DIExpression");
1426 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1427 if (
auto *Types =
N.getRawTypeArray()) {
1428 CheckDI(isa<MDTuple>(Types),
"invalid composite elements", &
N, Types);
1429 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1430 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1434 "invalid reference flags", &
N);
1437void Verifier::visitDIFile(
const DIFile &
N) {
1438 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1439 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1442 "invalid checksum kind", &
N);
1444 switch (Checksum->Kind) {
1455 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1457 "invalid checksum", &
N);
1462 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1463 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1467 CheckDI(
N.getRawFile() && isa<DIFile>(
N.getRawFile()),
"invalid file", &
N,
1469 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1473 "invalid emission kind", &
N);
1475 if (
auto *Array =
N.getRawEnumTypes()) {
1476 CheckDI(isa<MDTuple>(Array),
"invalid enum list", &
N, Array);
1477 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1478 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
1479 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1480 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1483 if (
auto *Array =
N.getRawRetainedTypes()) {
1484 CheckDI(isa<MDTuple>(Array),
"invalid retained type list", &
N, Array);
1485 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1487 Op && (isa<DIType>(
Op) || (isa<DISubprogram>(
Op) &&
1488 !cast<DISubprogram>(
Op)->isDefinition())),
1489 "invalid retained type", &
N,
Op);
1492 if (
auto *Array =
N.getRawGlobalVariables()) {
1493 CheckDI(isa<MDTuple>(Array),
"invalid global variable list", &
N, Array);
1494 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1495 CheckDI(
Op && (isa<DIGlobalVariableExpression>(
Op)),
1496 "invalid global variable ref", &
N,
Op);
1499 if (
auto *Array =
N.getRawImportedEntities()) {
1500 CheckDI(isa<MDTuple>(Array),
"invalid imported entity list", &
N, Array);
1501 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1502 CheckDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1506 if (
auto *Array =
N.getRawMacros()) {
1507 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1509 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1516 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1518 if (
auto *
F =
N.getRawFile())
1519 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1521 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1522 if (
auto *
T =
N.getRawType())
1523 CheckDI(isa<DISubroutineType>(
T),
"invalid subroutine type", &
N,
T);
1524 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1525 N.getRawContainingType());
1526 if (
auto *Params =
N.getRawTemplateParams())
1527 visitTemplateParams(
N, *Params);
1528 if (
auto *S =
N.getRawDeclaration())
1529 CheckDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1530 "invalid subprogram declaration", &
N, S);
1531 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1532 auto *
Node = dyn_cast<MDTuple>(RawNode);
1533 CheckDI(
Node,
"invalid retained nodes list", &
N, RawNode);
1535 CheckDI(
Op && (isa<DILocalVariable>(
Op) || isa<DILabel>(
Op) ||
1536 isa<DIImportedEntity>(
Op)),
1537 "invalid retained nodes, expected DILocalVariable, DILabel or "
1543 "invalid reference flags", &
N);
1545 auto *Unit =
N.getRawUnit();
1546 if (
N.isDefinition()) {
1548 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1549 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1550 CheckDI(isa<DICompileUnit>(Unit),
"invalid unit type", &
N, Unit);
1553 auto *CT = dyn_cast_or_null<DICompositeType>(
N.getRawScope());
1554 if (CT && CT->getRawIdentifier() &&
1555 M.getContext().isODRUniquingDebugTypes())
1557 "definition subprograms cannot be nested within DICompositeType "
1558 "when enabling ODR",
1562 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1564 "subprogram declaration must not have a declaration field");
1567 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1568 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1569 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1571 CheckDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1575 if (
N.areAllCallsDescribed())
1577 "DIFlagAllCallsDescribed must be attached to a definition");
1581 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1582 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1583 "invalid local scope", &
N,
N.getRawScope());
1584 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1585 CheckDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1589 visitDILexicalBlockBase(
N);
1592 "cannot have column info without line info", &
N);
1596 visitDILexicalBlockBase(
N);
1600 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1601 if (
auto *S =
N.getRawScope())
1602 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1603 if (
auto *S =
N.getRawDecl())
1604 CheckDI(isa<DIGlobalVariable>(S),
"invalid declaration", &
N, S);
1608 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1609 if (
auto *S =
N.getRawScope())
1610 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1613void Verifier::visitDIMacro(
const DIMacro &
N) {
1616 "invalid macinfo type", &
N);
1617 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1618 if (!
N.getValue().empty()) {
1619 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1625 "invalid macinfo type", &
N);
1626 if (
auto *
F =
N.getRawFile())
1627 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1629 if (
auto *Array =
N.getRawElements()) {
1630 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1631 for (
Metadata *
Op :
N.getElements()->operands()) {
1632 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1637void Verifier::visitDIModule(
const DIModule &
N) {
1638 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1639 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1647 visitDITemplateParameter(
N);
1649 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1653void Verifier::visitDITemplateValueParameter(
1655 visitDITemplateParameter(
N);
1657 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1658 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1659 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1663void Verifier::visitDIVariable(
const DIVariable &
N) {
1664 if (
auto *S =
N.getRawScope())
1665 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1666 if (
auto *
F =
N.getRawFile())
1667 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1674 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1677 if (
N.isDefinition())
1678 CheckDI(
N.getType(),
"missing global variable type", &
N);
1679 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1680 CheckDI(isa<DIDerivedType>(Member),
1681 "invalid static data member declaration", &
N, Member);
1690 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1691 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1692 "local variable requires a valid scope", &
N,
N.getRawScope());
1693 if (
auto Ty =
N.getType())
1694 CheckDI(!isa<DISubroutineType>(Ty),
"invalid type", &
N,
N.getType());
1697void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1698 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1699 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1702void Verifier::visitDILabel(
const DILabel &
N) {
1703 if (
auto *S =
N.getRawScope())
1704 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1705 if (
auto *
F =
N.getRawFile())
1706 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1708 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1709 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1710 "label requires a valid scope", &
N,
N.getRawScope());
1714 CheckDI(
N.isValid(),
"invalid expression", &
N);
1717void Verifier::visitDIGlobalVariableExpression(
1721 visitDIGlobalVariable(*Var);
1723 visitDIExpression(*Expr);
1724 if (
auto Fragment = Expr->getFragmentInfo())
1725 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1730 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1731 if (
auto *
T =
N.getRawType())
1733 if (
auto *
F =
N.getRawFile())
1734 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1738 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1739 N.getTag() == dwarf::DW_TAG_imported_declaration,
1741 if (
auto *S =
N.getRawScope())
1742 CheckDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1747void Verifier::visitComdat(
const Comdat &
C) {
1750 if (
TT.isOSBinFormatCOFF())
1756void Verifier::visitModuleIdents() {
1757 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1764 Check(
N->getNumOperands() == 1,
1765 "incorrect number of operands in llvm.ident metadata",
N);
1766 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1767 (
"invalid value for llvm.ident metadata entry operand"
1768 "(the operand should be a string)"),
1773void Verifier::visitModuleCommandLines() {
1774 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1782 Check(
N->getNumOperands() == 1,
1783 "incorrect number of operands in llvm.commandline metadata",
N);
1784 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1785 (
"invalid value for llvm.commandline metadata entry operand"
1786 "(the operand should be a string)"),
1791void Verifier::visitModuleFlags() {
1801 visitModuleFlag(MDN, SeenIDs, Requirements);
1802 if (MDN->getNumOperands() != 3)
1804 if (
const auto *FlagName = dyn_cast_or_null<MDString>(MDN->getOperand(1))) {
1805 if (FlagName->getString() ==
"aarch64-elf-pauthabi-platform") {
1806 if (
const auto *PAP =
1807 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1808 PAuthABIPlatform = PAP->getZExtValue();
1809 }
else if (FlagName->getString() ==
"aarch64-elf-pauthabi-version") {
1810 if (
const auto *PAV =
1811 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1812 PAuthABIVersion = PAV->getZExtValue();
1817 if ((PAuthABIPlatform ==
uint64_t(-1)) != (PAuthABIVersion ==
uint64_t(-1)))
1818 CheckFailed(
"either both or no 'aarch64-elf-pauthabi-platform' and "
1819 "'aarch64-elf-pauthabi-version' module flags must be present");
1822 for (
const MDNode *Requirement : Requirements) {
1823 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1824 const Metadata *ReqValue = Requirement->getOperand(1);
1828 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1833 if (
Op->getOperand(2) != ReqValue) {
1834 CheckFailed((
"invalid requirement on flag, "
1835 "flag does not have the required value"),
1843Verifier::visitModuleFlag(
const MDNode *
Op,
1849 "incorrect number of operands in module flag",
Op);
1852 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0)),
1853 "invalid behavior operand in module flag (expected constant integer)",
1856 "invalid behavior operand in module flag (unexpected constant)",
1859 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(1));
1860 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
1872 auto *
V = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1873 Check(V &&
V->getValue().isNonNegative(),
1874 "invalid value for 'min' module flag (expected constant non-negative "
1881 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2)),
1882 "invalid value for 'max' module flag (expected constant integer)",
1892 "invalid value for 'require' module flag (expected metadata pair)",
1895 (
"invalid value for 'require' module flag "
1896 "(first value operand should be a string)"),
1897 Value->getOperand(0));
1908 Check(isa<MDNode>(
Op->getOperand(2)),
1909 "invalid value for 'append'-type module flag "
1910 "(expected a metadata node)",
1920 "module flag identifiers must be unique (or of 'require' type)",
ID);
1923 if (
ID->getString() ==
"wchar_size") {
1925 = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1926 Check(
Value,
"wchar_size metadata requires constant integer argument");
1929 if (
ID->getString() ==
"Linker Options") {
1933 Check(
M.getNamedMetadata(
"llvm.linker.options"),
1934 "'Linker Options' named metadata no longer supported");
1937 if (
ID->getString() ==
"SemanticInterposition") {
1939 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1941 "SemanticInterposition metadata requires constant integer argument");
1944 if (
ID->getString() ==
"CG Profile") {
1945 for (
const MDOperand &MDO : cast<MDNode>(
Op->getOperand(2))->operands())
1946 visitModuleFlagCGProfileEntry(MDO);
1950void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1951 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1954 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1955 Check(
F && isa<Function>(
F->getValue()->stripPointerCasts()),
1956 "expected a Function or null", FuncMDO);
1958 auto Node = dyn_cast_or_null<MDNode>(MDO);
1959 Check(
Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1960 CheckFunction(
Node->getOperand(0));
1961 CheckFunction(
Node->getOperand(1));
1962 auto Count = dyn_cast_or_null<ConstantAsMetadata>(
Node->getOperand(2));
1963 Check(Count && Count->getType()->isIntegerTy(),
1964 "expected an integer constant",
Node->getOperand(2));
1970 if (
A.isStringAttribute()) {
1971#define GET_ATTR_NAMES
1972#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
1973#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1974 if (A.getKindAsString() == #DISPLAY_NAME) { \
1975 auto V = A.getValueAsString(); \
1976 if (!(V.empty() || V == "true" || V == "false")) \
1977 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
1981#include "llvm/IR/Attributes.inc"
1986 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
1997 if (!
Attrs.hasAttributes())
2000 verifyAttributeTypes(Attrs, V);
2003 Check(Attr.isStringAttribute() ||
2005 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
2008 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
2009 unsigned AttrCount =
2010 Attrs.getNumAttributes() -
Attrs.hasAttribute(Attribute::Range);
2011 Check(AttrCount == 1,
2012 "Attribute 'immarg' is incompatible with other attributes except the "
2013 "'range' attribute",
2019 unsigned AttrCount = 0;
2020 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
2021 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
2022 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
2023 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
2024 Attrs.hasAttribute(Attribute::InReg);
2025 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
2026 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
2027 Check(AttrCount <= 1,
2028 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
2029 "'byref', and 'sret' are incompatible!",
2032 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
2033 Attrs.hasAttribute(Attribute::ReadOnly)),
2035 "'inalloca and readonly' are incompatible!",
2038 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
2039 Attrs.hasAttribute(Attribute::Returned)),
2041 "'sret and returned' are incompatible!",
2044 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
2045 Attrs.hasAttribute(Attribute::SExt)),
2047 "'zeroext and signext' are incompatible!",
2050 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
2051 Attrs.hasAttribute(Attribute::ReadOnly)),
2053 "'readnone and readonly' are incompatible!",
2056 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
2057 Attrs.hasAttribute(Attribute::WriteOnly)),
2059 "'readnone and writeonly' are incompatible!",
2062 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
2063 Attrs.hasAttribute(Attribute::WriteOnly)),
2065 "'readonly and writeonly' are incompatible!",
2068 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
2069 Attrs.hasAttribute(Attribute::AlwaysInline)),
2071 "'noinline and alwaysinline' are incompatible!",
2074 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2075 Attrs.hasAttribute(Attribute::ReadNone)),
2076 "Attributes writable and readnone are incompatible!", V);
2078 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2079 Attrs.hasAttribute(Attribute::ReadOnly)),
2080 "Attributes writable and readonly are incompatible!", V);
2084 if (!Attr.isStringAttribute() &&
2085 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2086 CheckFailed(
"Attribute '" + Attr.getAsString() +
2087 "' applied to incompatible type!", V);
2092 if (isa<PointerType>(Ty)) {
2093 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2094 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2096 "huge alignment values are unsupported", V);
2098 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2102 "Attribute 'byval' does not support unsized types!", V);
2106 "'byval' argument has illegal target extension type", V);
2107 Check(
DL.getTypeAllocSize(ByValTy).getKnownMinValue() < (1ULL << 32),
2108 "huge 'byval' arguments are unsupported", V);
2110 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2112 Check(
Attrs.getByRefType()->isSized(&Visited),
2113 "Attribute 'byref' does not support unsized types!", V);
2114 Check(
DL.getTypeAllocSize(
Attrs.getByRefType()).getKnownMinValue() <
2116 "huge 'byref' arguments are unsupported", V);
2118 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2120 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2121 "Attribute 'inalloca' does not support unsized types!", V);
2122 Check(
DL.getTypeAllocSize(
Attrs.getInAllocaType()).getKnownMinValue() <
2124 "huge 'inalloca' arguments are unsupported", V);
2126 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2128 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2129 "Attribute 'preallocated' does not support unsized types!", V);
2131 DL.getTypeAllocSize(
Attrs.getPreallocatedType()).getKnownMinValue() <
2133 "huge 'preallocated' arguments are unsupported", V);
2137 if (
Attrs.hasAttribute(Attribute::Initializes)) {
2138 auto Inits =
Attrs.getAttribute(Attribute::Initializes).getInitializes();
2139 Check(!Inits.empty(),
"Attribute 'initializes' does not support empty list",
2142 "Attribute 'initializes' does not support unordered ranges", V);
2145 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2146 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2147 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2150 "Invalid value for 'nofpclass' test mask", V);
2152 if (
Attrs.hasAttribute(Attribute::Range)) {
2154 Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2156 "Range bit width must match type bit width!", V);
2162 if (
Attrs.hasFnAttr(Attr)) {
2166 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2173 const Value *V,
bool IsIntrinsic,
2175 if (
Attrs.isEmpty())
2178 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2180 "Attribute list does not match Module context!", &Attrs, V);
2181 for (
const auto &AttrSet : Attrs) {
2182 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
2183 "Attribute set does not match Module context!", &AttrSet, V);
2184 for (
const auto &
A : AttrSet) {
2185 Check(
A.hasParentContext(Context),
2186 "Attribute does not match Module context!", &
A, V);
2191 bool SawNest =
false;
2192 bool SawReturned =
false;
2193 bool SawSRet =
false;
2194 bool SawSwiftSelf =
false;
2195 bool SawSwiftAsync =
false;
2196 bool SawSwiftError =
false;
2203 "Attribute '" +
RetAttr.getAsString() +
2204 "' does not apply to function return values",
2207 unsigned MaxParameterWidth = 0;
2208 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2210 if (
auto *VT = dyn_cast<FixedVectorType>(Ty)) {
2211 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2212 if (
Size > MaxParameterWidth)
2213 MaxParameterWidth =
Size;
2217 GetMaxParameterWidth(FT->getReturnType());
2218 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2221 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2222 Type *Ty = FT->getParamType(i);
2227 "immarg attribute only applies to intrinsics", V);
2230 "Attribute 'elementtype' can only be applied to intrinsics"
2235 verifyParameterAttrs(ArgAttrs, Ty, V);
2236 GetMaxParameterWidth(Ty);
2239 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2244 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2246 "Incompatible argument and return types for 'returned' attribute",
2252 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2253 Check(i == 0 || i == 1,
2254 "Attribute 'sret' is not on first or second parameter!", V);
2259 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2260 SawSwiftSelf =
true;
2264 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2265 SawSwiftAsync =
true;
2269 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2270 SawSwiftError =
true;
2274 Check(i == FT->getNumParams() - 1,
2275 "inalloca isn't on the last parameter!", V);
2279 if (!
Attrs.hasFnAttrs())
2282 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2286 "Attribute '" +
FnAttr.getAsString() +
2287 "' does not apply to functions!",
2290 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2291 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2292 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2294 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2296 "Attribute 'optnone' requires 'noinline'!", V);
2298 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2299 "Attributes 'optsize and optnone' are incompatible!", V);
2302 "Attributes 'minsize and optnone' are incompatible!", V);
2304 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2305 "Attributes 'optdebug and optnone' are incompatible!", V);
2308 Check(!(
Attrs.hasFnAttr(Attribute::SanitizeRealtime) &&
2309 Attrs.hasFnAttr(Attribute::SanitizeRealtimeBlocking)),
2311 "'sanitize_realtime and sanitize_realtime_blocking' are incompatible!",
2314 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2315 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2316 "Attributes 'optsize and optdebug' are incompatible!", V);
2319 "Attributes 'minsize and optdebug' are incompatible!", V);
2322 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2324 "Attribute writable and memory without argmem: write are incompatible!",
2327 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2328 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2329 "Attributes 'aarch64_pstate_sm_enabled and "
2330 "aarch64_pstate_sm_compatible' are incompatible!",
2334 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2335 Attrs.hasFnAttr(
"aarch64_inout_za") +
2336 Attrs.hasFnAttr(
"aarch64_out_za") +
2337 Attrs.hasFnAttr(
"aarch64_preserves_za") +
2338 Attrs.hasFnAttr(
"aarch64_za_state_agnostic")) <= 1,
2339 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2340 "'aarch64_inout_za', 'aarch64_preserves_za' and "
2341 "'aarch64_za_state_agnostic' are mutually exclusive",
2345 Attrs.hasFnAttr(
"aarch64_in_zt0") +
2346 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2347 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2348 Attrs.hasFnAttr(
"aarch64_preserves_zt0") +
2349 Attrs.hasFnAttr(
"aarch64_za_state_agnostic")) <= 1,
2350 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2351 "'aarch64_inout_zt0', 'aarch64_preserves_zt0' and "
2352 "'aarch64_za_state_agnostic' are mutually exclusive",
2355 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2358 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2361 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2363 if (ParamNo >= FT->getNumParams()) {
2364 CheckFailed(
"'allocsize' " +
Name +
" argument is out of bounds", V);
2368 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2369 CheckFailed(
"'allocsize' " +
Name +
2370 " argument must refer to an integer parameter",
2378 if (!CheckParam(
"element size",
Args->first))
2381 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2385 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2393 "'allockind()' requires exactly one of alloc, realloc, and free");
2397 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2398 "or aligned modifiers.");
2400 if ((K & ZeroedUninit) == ZeroedUninit)
2401 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2406 Check(!S.
empty(),
"'alloc-variant-zeroed' must not be empty");
2414 "'alloc-variant-zeroed' must name a function belonging to the "
2415 "same 'alloc-family'");
2418 (
Variant->getFnAttribute(Attribute::AllocKind).getAllocKind() &
2420 "'alloc-variant-zeroed' must name a function with "
2421 "'allockind(\"zeroed\")'");
2424 "'alloc-variant-zeroed' must name a function with the same "
2429 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2430 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2432 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2434 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2435 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2436 if (VScaleMax && VScaleMin > VScaleMax)
2437 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2439 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2442 if (
Attribute FPAttr =
Attrs.getFnAttr(
"frame-pointer"); FPAttr.isValid()) {
2444 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none" &&
FP !=
"reserved")
2445 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2449 if (
TT.isX86() && MaxParameterWidth >= 512) {
2450 Attribute TargetFeaturesAttr =
Attrs.getFnAttr(
"target-features");
2451 if (TargetFeaturesAttr.
isValid()) {
2454 "512-bit vector arguments require 'evex512' for AVX512", V);
2458 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2459 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2460 if (
Attrs.hasFnAttr(
"patchable-function-entry-section"))
2461 Check(!
Attrs.getFnAttr(
"patchable-function-entry-section")
2464 "\"patchable-function-entry-section\" must not be empty");
2465 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2467 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2469 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2470 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2473 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2475 if (S !=
"a_key" && S !=
"b_key")
2476 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2478 if (
auto AA =
Attrs.getFnAttr(
"sign-return-address"); !AA.isValid()) {
2480 "'sign-return-address-key' present without `sign-return-address`");
2484 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2486 if (S !=
"" && S !=
"true" && S !=
"false")
2488 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2491 if (
auto A =
Attrs.getFnAttr(
"branch-protection-pauth-lr");
A.isValid()) {
2493 if (S !=
"" && S !=
"true" && S !=
"false")
2495 "invalid value for 'branch-protection-pauth-lr' attribute: " + S, V);
2498 if (
auto A =
Attrs.getFnAttr(
"guarded-control-stack");
A.isValid()) {
2500 if (S !=
"" && S !=
"true" && S !=
"false")
2501 CheckFailed(
"invalid value for 'guarded-control-stack' attribute: " + S,
2505 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2509 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2512 if (
auto A =
Attrs.getFnAttr(
"denormal-fp-math");
A.isValid()) {
2515 CheckFailed(
"invalid value for 'denormal-fp-math' attribute: " + S, V);
2518 if (
auto A =
Attrs.getFnAttr(
"denormal-fp-math-f32");
A.isValid()) {
2521 CheckFailed(
"invalid value for 'denormal-fp-math-f32' attribute: " + S,
2526void Verifier::verifyFunctionMetadata(
2527 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2528 for (
const auto &Pair : MDs) {
2529 if (Pair.first == LLVMContext::MD_prof) {
2530 MDNode *MD = Pair.second;
2532 CheckFailed(
"'unknown' !prof metadata should appear only on "
2533 "instructions supporting the 'branch_weights' metadata",
2538 "!prof annotations should have no less than 2 operands", MD);
2541 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2544 "expected string with name of the !prof annotation", MD);
2549 "first operand should be 'function_entry_count'"
2550 " or 'synthetic_function_entry_count'",
2554 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2557 "expected integer argument to function_entry_count", MD);
2558 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2559 MDNode *MD = Pair.second;
2561 "!kcfi_type must have exactly one operand", MD);
2562 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2565 "expected a constant operand for !kcfi_type", MD);
2567 Check(isa<ConstantInt>(
C) && isa<IntegerType>(
C->getType()),
2568 "expected a constant integer operand for !kcfi_type", MD);
2570 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2575void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2576 if (!ConstantExprVisited.
insert(EntryC).second)
2580 Stack.push_back(EntryC);
2582 while (!
Stack.empty()) {
2586 if (
const auto *CE = dyn_cast<ConstantExpr>(
C))
2587 visitConstantExpr(CE);
2589 if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C))
2590 visitConstantPtrAuth(CPA);
2592 if (
const auto *GV = dyn_cast<GlobalValue>(
C)) {
2595 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2601 for (
const Use &U :
C->operands()) {
2602 const auto *OpC = dyn_cast<Constant>(U);
2605 if (!ConstantExprVisited.
insert(OpC).second)
2607 Stack.push_back(OpC);
2612void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2613 if (
CE->getOpcode() == Instruction::BitCast)
2616 "Invalid bitcast", CE);
2617 else if (
CE->getOpcode() == Instruction::PtrToAddr)
2618 checkPtrToAddr(
CE->getOperand(0)->getType(),
CE->getType(), *CE);
2623 "signed ptrauth constant base pointer must have pointer type");
2626 "signed ptrauth constant must have same type as its base pointer");
2629 "signed ptrauth constant key must be i32 constant integer");
2632 "signed ptrauth constant address discriminator must be a pointer");
2635 "signed ptrauth constant discriminator must be i64 constant integer");
2638bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
2641 return Attrs.getNumAttrSets() <= Params + 2;
2644void Verifier::verifyInlineAsmCall(
const CallBase &Call) {
2647 unsigned LabelNo = 0;
2658 if (CI.isIndirect) {
2659 const Value *Arg =
Call.getArgOperand(ArgNo);
2661 "Operand for indirect constraint must have pointer type", &Call);
2664 "Operand for indirect constraint must have elementtype attribute",
2667 Check(!
Call.paramHasAttr(ArgNo, Attribute::ElementType),
2668 "Elementtype attribute can only be applied for indirect "
2676 if (
auto *CallBr = dyn_cast<CallBrInst>(&Call)) {
2677 Check(LabelNo == CallBr->getNumIndirectDests(),
2678 "Number of label constraints does not match number of callbr dests",
2681 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
2687void Verifier::verifyStatepoint(
const CallBase &Call) {
2688 assert(
Call.getIntrinsicID() == Intrinsic::experimental_gc_statepoint);
2690 Check(!
Call.doesNotAccessMemory() && !
Call.onlyReadsMemory() &&
2691 !
Call.onlyAccessesArgMemory(),
2692 "gc.statepoint must read and write all memory to preserve "
2693 "reordering restrictions required by safepoint semantics",
2696 const int64_t NumPatchBytes =
2697 cast<ConstantInt>(
Call.getArgOperand(1))->getSExtValue();
2698 assert(isInt<32>(NumPatchBytes) &&
"NumPatchBytesV is an i32!");
2699 Check(NumPatchBytes >= 0,
2700 "gc.statepoint number of patchable bytes must be "
2704 Type *TargetElemType =
Call.getParamElementType(2);
2705 Check(TargetElemType,
2706 "gc.statepoint callee argument must have elementtype attribute", Call);
2707 FunctionType *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
2708 Check(TargetFuncType,
2709 "gc.statepoint callee elementtype must be function type", Call);
2711 const int NumCallArgs = cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue();
2712 Check(NumCallArgs >= 0,
2713 "gc.statepoint number of arguments to underlying call "
2716 const int NumParams = (int)TargetFuncType->getNumParams();
2717 if (TargetFuncType->isVarArg()) {
2718 Check(NumCallArgs >= NumParams,
2719 "gc.statepoint mismatch in number of vararg call args", Call);
2722 Check(TargetFuncType->getReturnType()->isVoidTy(),
2723 "gc.statepoint doesn't support wrapping non-void "
2724 "vararg functions yet",
2727 Check(NumCallArgs == NumParams,
2728 "gc.statepoint mismatch in number of call args", Call);
2731 = cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue();
2733 "unknown flag used in gc.statepoint flags argument", Call);
2738 for (
int i = 0; i < NumParams; i++) {
2739 Type *ParamType = TargetFuncType->getParamType(i);
2740 Type *ArgType =
Call.getArgOperand(5 + i)->getType();
2741 Check(ArgType == ParamType,
2742 "gc.statepoint call argument does not match wrapped "
2746 if (TargetFuncType->isVarArg()) {
2749 "Attribute 'sret' cannot be used for vararg call arguments!", Call);
2753 const int EndCallArgsInx = 4 + NumCallArgs;
2755 const Value *NumTransitionArgsV =
Call.getArgOperand(EndCallArgsInx + 1);
2756 Check(isa<ConstantInt>(NumTransitionArgsV),
2757 "gc.statepoint number of transition arguments "
2758 "must be constant integer",
2760 const int NumTransitionArgs =
2761 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
2762 Check(NumTransitionArgs == 0,
2763 "gc.statepoint w/inline transition bundle is deprecated", Call);
2764 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2766 const Value *NumDeoptArgsV =
Call.getArgOperand(EndTransitionArgsInx + 1);
2767 Check(isa<ConstantInt>(NumDeoptArgsV),
2768 "gc.statepoint number of deoptimization arguments "
2769 "must be constant integer",
2771 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
2772 Check(NumDeoptArgs == 0,
2773 "gc.statepoint w/inline deopt operands is deprecated", Call);
2775 const int ExpectedNumArgs = 7 + NumCallArgs;
2776 Check(ExpectedNumArgs == (
int)
Call.arg_size(),
2777 "gc.statepoint too many arguments", Call);
2782 for (
const User *U :
Call.users()) {
2783 const CallInst *UserCall = dyn_cast<const CallInst>(U);
2784 Check(UserCall,
"illegal use of statepoint token", Call, U);
2787 Check(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),
2788 "gc.result or gc.relocate are the only value uses "
2789 "of a gc.statepoint",
2791 if (isa<GCResultInst>(UserCall)) {
2793 "gc.result connected to wrong gc.statepoint", Call, UserCall);
2794 }
else if (isa<GCRelocateInst>(Call)) {
2796 "gc.relocate connected to wrong gc.statepoint", Call, UserCall);
2810void Verifier::verifyFrameRecoverIndices() {
2811 for (
auto &Counts : FrameEscapeInfo) {
2813 unsigned EscapedObjectCount = Counts.second.first;
2814 unsigned MaxRecoveredIndex = Counts.second.second;
2815 Check(MaxRecoveredIndex <= EscapedObjectCount,
2816 "all indices passed to llvm.localrecover must be less than the "
2817 "number of arguments passed to llvm.localescape in the parent "
2825 if (
auto *
II = dyn_cast<InvokeInst>(Terminator))
2826 UnwindDest =
II->getUnwindDest();
2827 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2828 UnwindDest = CSI->getUnwindDest();
2830 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2834void Verifier::verifySiblingFuncletUnwinds() {
2837 for (
const auto &Pair : SiblingFuncletInfo) {
2839 if (Visited.
count(PredPad))
2845 if (
Active.count(SuccPad)) {
2851 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2852 if (CycleTerminator != CyclePad)
2855 }
while (CyclePad != SuccPad);
2856 Check(
false,
"EH pads can't handle each other's exceptions",
2860 if (!Visited.
insert(SuccPad).second)
2864 auto TermI = SiblingFuncletInfo.find(PredPad);
2865 if (TermI == SiblingFuncletInfo.end())
2878void Verifier::visitFunction(
const Function &
F) {
2879 visitGlobalValue(
F);
2883 unsigned NumArgs =
F.arg_size();
2885 Check(&Context == &
F.getContext(),
2886 "Function context does not match Module context!", &
F);
2888 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
2889 Check(FT->getNumParams() == NumArgs,
2890 "# formal arguments must match # of arguments for function type!", &
F,
2892 Check(
F.getReturnType()->isFirstClassType() ||
2893 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
2894 "Functions cannot return aggregate values!", &
F);
2896 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
2897 "Invalid struct return type!", &
F);
2901 "huge alignment values are unsupported", &
F);
2906 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
2907 "Attribute after last parameter!", &
F);
2909 bool IsIntrinsic =
F.isIntrinsic();
2912 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
2918 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2920 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
2921 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
2924 "Attribute 'aarch64_zt0_undef' can only be applied to a callsite.");
2926 if (
Attrs.hasFnAttr(Attribute::Naked))
2928 Check(Arg.use_empty(),
"cannot use argument of naked function", &Arg);
2933 switch (
F.getCallingConv()) {
2938 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
2939 "Calling convention parameter requires byval", &
F);
2946 Check(
F.getReturnType()->isVoidTy(),
2947 "Calling convention requires void return type", &
F);
2954 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
2956 const unsigned StackAS =
DL.getAllocaAddrSpace();
2959 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
2960 "Calling convention disallows byval", &
F);
2961 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
2962 "Calling convention disallows preallocated", &
F);
2963 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
2964 "Calling convention disallows inalloca", &
F);
2966 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
2969 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
2970 "Calling convention disallows stack byref", &
F);
2984 "Calling convention does not support varargs or "
2985 "perfect forwarding!",
2989 Check(!
F.arg_empty() &&
F.arg_begin()->getType()->isIntegerTy(1),
2990 "Calling convention requires first argument to be i1", &
F);
2991 Check(!
F.arg_begin()->hasInRegAttr(),
2992 "Calling convention requires first argument to not be inreg", &
F);
2994 "Calling convention does not support varargs or "
2995 "perfect forwarding!",
3003 Check(Arg.getType() == FT->getParamType(i),
3004 "Argument value does not match function argument type!", &Arg,
3005 FT->getParamType(i));
3006 Check(Arg.getType()->isFirstClassType(),
3007 "Function arguments must have first-class types!", &Arg);
3009 Check(!Arg.getType()->isMetadataTy(),
3010 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
3011 Check(!Arg.getType()->isTokenLikeTy(),
3012 "Function takes token but isn't an intrinsic", &Arg, &
F);
3013 Check(!Arg.getType()->isX86_AMXTy(),
3014 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
3018 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
3019 verifySwiftErrorValue(&Arg);
3025 Check(!
F.getReturnType()->isTokenLikeTy(),
3026 "Function returns a token but isn't an intrinsic", &
F);
3027 Check(!
F.getReturnType()->isX86_AMXTy(),
3028 "Function returns a x86_amx but isn't an intrinsic", &
F);
3033 F.getAllMetadata(MDs);
3034 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
3035 verifyFunctionMetadata(MDs);
3038 if (
F.hasPersonalityFn()) {
3039 auto *Per = dyn_cast<Function>(
F.getPersonalityFn()->stripPointerCasts());
3041 Check(Per->getParent() ==
F.getParent(),
3042 "Referencing personality function in another module!", &
F,
3043 F.getParent(), Per, Per->getParent());
3047 BlockEHFuncletColors.
clear();
3049 if (
F.isMaterializable()) {
3051 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
3053 }
else if (
F.isDeclaration()) {
3054 for (
const auto &
I : MDs) {
3056 CheckDI(
I.first != LLVMContext::MD_dbg ||
3057 !cast<DISubprogram>(
I.second)->isDistinct(),
3058 "function declaration may only have a unique !dbg attachment",
3060 Check(
I.first != LLVMContext::MD_prof,
3061 "function declaration may not have a !prof attachment", &
F);
3064 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
3066 Check(!
F.hasPersonalityFn(),
3067 "Function declaration shouldn't have a personality routine", &
F);
3071 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
3076 "Entry block to function must not have predecessors!", Entry);
3079 if (
Entry->hasAddressTaken()) {
3081 "blockaddress may not be used with the entry block!", Entry);
3084 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
3085 NumKCFIAttachments = 0;
3087 for (
const auto &
I : MDs) {
3089 auto AllowLocs = AreDebugLocsAllowed::No;
3093 case LLVMContext::MD_dbg: {
3094 ++NumDebugAttachments;
3095 CheckDI(NumDebugAttachments == 1,
3096 "function must have a single !dbg attachment", &
F,
I.second);
3097 CheckDI(isa<DISubprogram>(
I.second),
3098 "function !dbg attachment must be a subprogram", &
F,
I.second);
3099 CheckDI(cast<DISubprogram>(
I.second)->isDistinct(),
3100 "function definition may only have a distinct !dbg attachment",
3103 auto *
SP = cast<DISubprogram>(
I.second);
3104 const Function *&AttachedTo = DISubprogramAttachments[
SP];
3105 CheckDI(!AttachedTo || AttachedTo == &
F,
3106 "DISubprogram attached to more than one function", SP, &
F);
3108 AllowLocs = AreDebugLocsAllowed::Yes;
3111 case LLVMContext::MD_prof:
3112 ++NumProfAttachments;
3113 Check(NumProfAttachments == 1,
3114 "function must have a single !prof attachment", &
F,
I.second);
3116 case LLVMContext::MD_kcfi_type:
3117 ++NumKCFIAttachments;
3118 Check(NumKCFIAttachments == 1,
3119 "function must have a single !kcfi_type attachment", &
F,
3125 visitMDNode(*
I.second, AllowLocs);
3133 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
3135 if (
F.hasAddressTaken(&U,
false,
true,
false,
3137 Check(
false,
"Invalid user of intrinsic instruction!", U);
3141 switch (
F.getIntrinsicID()) {
3142 case Intrinsic::experimental_gc_get_pointer_base: {
3144 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
3145 Check(isa<PointerType>(
F.getReturnType()),
3146 "gc.get.pointer.base must return a pointer",
F);
3147 Check(FT->getParamType(0) ==
F.getReturnType(),
3148 "gc.get.pointer.base operand and result must be of the same type",
F);
3151 case Intrinsic::experimental_gc_get_pointer_offset: {
3153 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
3154 Check(isa<PointerType>(FT->getParamType(0)),
3155 "gc.get.pointer.offset operand must be a pointer",
F);
3156 Check(
F.getReturnType()->isIntegerTy(),
3157 "gc.get.pointer.offset must return integer",
F);
3162 auto *
N =
F.getSubprogram();
3163 HasDebugInfo = (
N !=
nullptr);
3182 CheckDI(Parent && isa<DILocalScope>(Parent),
3183 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
3186 Check(Scope,
"Failed to find DILocalScope",
DL);
3188 if (!Seen.
insert(Scope).second)
3195 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
3199 "!dbg attachment points at wrong subprogram for function",
N, &
F,
3203 for (
auto &
I : BB) {
3204 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
3206 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
3208 VisitDebugLoc(
I, dyn_cast_or_null<MDNode>(MD->
getOperand(i)));
3209 if (BrokenDebugInfo)
3216void Verifier::visitBasicBlock(
BasicBlock &BB) {
3217 InstsInThisBlock.
clear();
3218 ConvergenceVerifyHelper.
visit(BB);
3225 if (isa<PHINode>(BB.
front())) {
3230 Check(PN.getNumIncomingValues() == Preds.size(),
3231 "PHINode should have one entry for each predecessor of its "
3232 "parent basic block!",
3237 Values.
reserve(PN.getNumIncomingValues());
3238 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3240 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3243 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3248 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3249 Values[i].second == Values[i - 1].second,
3250 "PHI node has multiple entries for the same basic block with "
3251 "different incoming values!",
3252 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3256 Check(Values[i].first == Preds[i],
3257 "PHI node entries do not match predecessors!", &PN,
3258 Values[i].first, Preds[i]);
3266 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3270 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3276 Check(&
I ==
I.getParent()->getTerminator(),
3277 "Terminator found in the middle of a basic block!",
I.getParent());
3281void Verifier::visitBranchInst(
BranchInst &BI) {
3284 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3289void Verifier::visitReturnInst(
ReturnInst &RI) {
3292 if (
F->getReturnType()->isVoidTy())
3294 "Found return instr that returns non-void in Function of void "
3296 &RI,
F->getReturnType());
3299 "Function return type does not match operand "
3300 "type of return inst!",
3301 &RI,
F->getReturnType());
3308void Verifier::visitSwitchInst(
SwitchInst &SI) {
3309 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3312 Type *SwitchTy =
SI.getCondition()->getType();
3314 for (
auto &Case :
SI.cases()) {
3315 Check(isa<ConstantInt>(
SI.getOperand(Case.getCaseIndex() * 2 + 2)),
3316 "Case value is not a constant integer.", &SI);
3317 Check(Case.getCaseValue()->getType() == SwitchTy,
3318 "Switch constants must all be same type as switch value!", &SI);
3320 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3328 "Indirectbr operand must have pointer type!", &BI);
3331 "Indirectbr destinations must all have pointer type!", &BI);
3336void Verifier::visitCallBrInst(
CallBrInst &CBI) {
3337 Check(CBI.
isInlineAsm(),
"Callbr is currently only used for asm-goto!", &CBI);
3339 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3341 verifyInlineAsmCall(CBI);
3345void Verifier::visitSelectInst(
SelectInst &SI) {
3348 "Invalid operands for select instruction!", &SI);
3350 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3351 "Select values must have same type as select instruction!", &SI);
3359 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3364 Type *SrcTy =
I.getOperand(0)->getType();
3365 Type *DestTy =
I.getType();
3374 "trunc source and destination must both be a vector or neither", &
I);
3375 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3380void Verifier::visitZExtInst(
ZExtInst &
I) {
3382 Type *SrcTy =
I.getOperand(0)->getType();
3383 Type *DestTy =
I.getType();
3389 "zext source and destination must both be a vector or neither", &
I);
3393 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3398void Verifier::visitSExtInst(
SExtInst &
I) {
3400 Type *SrcTy =
I.getOperand(0)->getType();
3401 Type *DestTy =
I.getType();
3410 "sext source and destination must both be a vector or neither", &
I);
3411 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3418 Type *SrcTy =
I.getOperand(0)->getType();
3419 Type *DestTy =
I.getType();
3427 "fptrunc source and destination must both be a vector or neither", &
I);
3428 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3435 Type *SrcTy =
I.getOperand(0)->getType();
3436 Type *DestTy =
I.getType();
3445 "fpext source and destination must both be a vector or neither", &
I);
3446 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3453 Type *SrcTy =
I.getOperand(0)->getType();
3454 Type *DestTy =
I.getType();
3459 Check(SrcVec == DstVec,
3460 "UIToFP source and dest must both be vector or scalar", &
I);
3462 "UIToFP source must be integer or integer vector", &
I);
3466 if (SrcVec && DstVec)
3467 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3468 cast<VectorType>(DestTy)->getElementCount(),
3469 "UIToFP source and dest vector length mismatch", &
I);
3476 Type *SrcTy =
I.getOperand(0)->getType();
3477 Type *DestTy =
I.getType();
3482 Check(SrcVec == DstVec,
3483 "SIToFP source and dest must both be vector or scalar", &
I);
3485 "SIToFP source must be integer or integer vector", &
I);
3489 if (SrcVec && DstVec)
3490 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3491 cast<VectorType>(DestTy)->getElementCount(),
3492 "SIToFP source and dest vector length mismatch", &
I);
3499 Type *SrcTy =
I.getOperand(0)->getType();
3500 Type *DestTy =
I.getType();
3505 Check(SrcVec == DstVec,
3506 "FPToUI source and dest must both be vector or scalar", &
I);
3509 "FPToUI result must be integer or integer vector", &
I);
3511 if (SrcVec && DstVec)
3512 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3513 cast<VectorType>(DestTy)->getElementCount(),
3514 "FPToUI source and dest vector length mismatch", &
I);
3521 Type *SrcTy =
I.getOperand(0)->getType();
3522 Type *DestTy =
I.getType();
3527 Check(SrcVec == DstVec,
3528 "FPToSI source and dest must both be vector or scalar", &
I);
3531 "FPToSI result must be integer or integer vector", &
I);
3533 if (SrcVec && DstVec)
3534 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3535 cast<VectorType>(DestTy)->getElementCount(),
3536 "FPToSI source and dest vector length mismatch", &
I);
3541void Verifier::checkPtrToAddr(
Type *SrcTy,
Type *DestTy,
const Value &V) {
3548 auto *VSrc = cast<VectorType>(SrcTy);
3549 auto *VDest = cast<VectorType>(DestTy);
3550 Check(VSrc->getElementCount() == VDest->getElementCount(),
3551 "PtrToAddr vector length mismatch", V);
3554 Type *AddrTy =
DL.getAddressType(SrcTy);
3555 Check(AddrTy == DestTy,
"PtrToAddr result must be address width", V);
3559 checkPtrToAddr(
I.getOperand(0)->getType(),
I.getType(),
I);
3565 Type *SrcTy =
I.getOperand(0)->getType();
3566 Type *DestTy =
I.getType();
3575 auto *VSrc = cast<VectorType>(SrcTy);
3576 auto *VDest = cast<VectorType>(DestTy);
3577 Check(VSrc->getElementCount() == VDest->getElementCount(),
3578 "PtrToInt Vector length mismatch", &
I);
3586 Type *SrcTy =
I.getOperand(0)->getType();
3587 Type *DestTy =
I.getType();
3595 auto *VSrc = cast<VectorType>(SrcTy);
3596 auto *VDest = cast<VectorType>(DestTy);
3597 Check(VSrc->getElementCount() == VDest->getElementCount(),
3598 "IntToPtr Vector length mismatch", &
I);
3606 "Invalid bitcast", &
I);
3611 Type *SrcTy =
I.getOperand(0)->getType();
3612 Type *DestTy =
I.getType();
3619 "AddrSpaceCast must be between different address spaces", &
I);
3620 if (
auto *SrcVTy = dyn_cast<VectorType>(SrcTy))
3621 Check(SrcVTy->getElementCount() ==
3622 cast<VectorType>(DestTy)->getElementCount(),
3623 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3629void Verifier::visitPHINode(
PHINode &PN) {
3636 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
3645 "PHI node operands are not the same type as the result!", &PN);
3653void Verifier::visitCallBase(
CallBase &Call) {
3654 Check(
Call.getCalledOperand()->getType()->isPointerTy(),
3655 "Called function must be a pointer!", Call);
3659 if (FTy->isVarArg())
3660 Check(
Call.arg_size() >= FTy->getNumParams(),
3661 "Called function requires more parameters than were provided!", Call);
3663 Check(
Call.arg_size() == FTy->getNumParams(),
3664 "Incorrect number of arguments passed to called function!", Call);
3667 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3668 Check(
Call.getArgOperand(i)->getType() == FTy->getParamType(i),
3669 "Call parameter type does not match function signature!",
3670 Call.getArgOperand(i), FTy->getParamType(i), Call);
3674 Check(verifyAttributeCount(Attrs,
Call.arg_size()),
3675 "Attribute after last parameter!", Call);
3678 dyn_cast<Function>(
Call.getCalledOperand()->stripPointerCasts());
3682 "Intrinsic called with incompatible signature", Call);
3686 "calling convention does not permit calls", Call);
3692 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
3695 Align ABIAlign =
DL.getABITypeAlign(Ty);
3697 "Incorrect alignment of " + Message +
" to called function!", Call);
3701 VerifyTypeAlign(FTy->getReturnType(),
"return type");
3702 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3703 Type *Ty = FTy->getParamType(i);
3704 VerifyTypeAlign(Ty,
"argument passed");
3708 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
3712 "speculatable attribute may not apply to call sites", Call);
3715 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
3716 Check(
Call.getIntrinsicID() == Intrinsic::call_preallocated_arg,
3717 "preallocated as a call site attribute can only be on "
3718 "llvm.call.preallocated.arg");
3722 verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic,
Call.isInlineAsm());
3727 if (
Call.hasInAllocaArgument()) {
3728 Value *InAllocaArg =
Call.getArgOperand(FTy->getNumParams() - 1);
3730 Check(AI->isUsedWithInAlloca(),
3731 "inalloca argument for call has mismatched alloca", AI, Call);
3737 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3738 if (
Call.paramHasAttr(i, Attribute::SwiftError)) {
3739 Value *SwiftErrorArg =
Call.getArgOperand(i);
3741 Check(AI->isSwiftError(),
3742 "swifterror argument for call has mismatched alloca", AI, Call);
3745 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
3746 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
3747 SwiftErrorArg, Call);
3748 Check(ArgI->hasSwiftErrorAttr(),
3749 "swifterror argument for call has mismatched parameter", ArgI,
3753 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
3756 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
3757 "immarg may not apply only to call sites",
Call.getArgOperand(i),
3761 if (
Call.paramHasAttr(i, Attribute::ImmArg)) {
3763 Check(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),
3764 "immarg operand has non-immediate parameter", ArgVal, Call);
3768 if (
Call.paramHasAttr(i, Attribute::Range)) {
3769 if (
auto *CI = dyn_cast<ConstantInt>(ArgVal)) {
3771 Call.getParamAttr(i, Attribute::Range).getValueAsConstantRange();
3773 "immarg value " +
Twine(CI->getValue().getSExtValue()) +
3781 if (
Call.paramHasAttr(i, Attribute::Preallocated)) {
3785 bool isMustTail =
Call.isMustTailCall();
3786 Check(hasOB != isMustTail,
3787 "preallocated operand either requires a preallocated bundle or "
3788 "the call to be musttail (but not both)",
3793 if (FTy->isVarArg()) {
3795 bool SawNest =
false;
3796 bool SawReturned =
false;
3798 for (
unsigned Idx = 0;
Idx < FTy->getNumParams(); ++
Idx) {
3799 if (
Attrs.hasParamAttr(
Idx, Attribute::Nest))
3801 if (
Attrs.hasParamAttr(
Idx, Attribute::Returned))
3806 for (
unsigned Idx = FTy->getNumParams();
Idx <
Call.arg_size(); ++
Idx) {
3809 verifyParameterAttrs(ArgAttrs, Ty, &Call);
3812 Check(!SawNest,
"More than one parameter has attribute nest!", Call);
3817 Check(!SawReturned,
"More than one parameter has attribute returned!",
3820 "Incompatible argument and return types for 'returned' "
3828 if (
Call.getIntrinsicID() != Intrinsic::experimental_gc_statepoint)
3830 "Attribute 'sret' cannot be used for vararg call arguments!",
3835 "inalloca isn't on the last argument!", Call);
3841 for (
Type *ParamTy : FTy->params()) {
3842 Check(!ParamTy->isMetadataTy(),
3843 "Function has metadata parameter but isn't an intrinsic", Call);
3844 Check(!ParamTy->isTokenLikeTy(),
3845 "Function has token parameter but isn't an intrinsic", Call);
3850 if (!
Call.getCalledFunction()) {
3851 Check(!FTy->getReturnType()->isTokenLikeTy(),
3852 "Return type cannot be token for indirect call!");
3853 Check(!FTy->getReturnType()->isX86_AMXTy(),
3854 "Return type cannot be x86_amx for indirect call!");
3858 visitIntrinsicCall(
ID, Call);
3863 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
3864 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
3865 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
3866 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
3867 FoundAttachedCallBundle =
false;
3868 for (
unsigned i = 0, e =
Call.getNumOperandBundles(); i < e; ++i) {
3872 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles", Call);
3873 FoundDeoptBundle =
true;
3875 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
3877 FoundGCTransitionBundle =
true;
3879 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles", Call);
3880 FoundFuncletBundle =
true;
3882 "Expected exactly one funclet bundle operand", Call);
3884 "Funclet bundle operands should correspond to a FuncletPadInst",
3887 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
3889 FoundCFGuardTargetBundle =
true;
3891 "Expected exactly one cfguardtarget bundle operand", Call);
3893 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles", Call);
3894 FoundPtrauthBundle =
true;
3896 "Expected exactly two ptrauth bundle operands", Call);
3898 BU.
Inputs[0]->getType()->isIntegerTy(32),
3899 "Ptrauth bundle key operand must be an i32 constant", Call);
3901 "Ptrauth bundle discriminator operand must be an i64", Call);
3903 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles", Call);
3904 FoundKCFIBundle =
true;
3905 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
3908 BU.
Inputs[0]->getType()->isIntegerTy(32),
3909 "Kcfi bundle operand must be an i32 constant", Call);
3911 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
3913 FoundPreallocatedBundle =
true;
3915 "Expected exactly one preallocated bundle operand", Call);
3916 auto Input = dyn_cast<IntrinsicInst>(BU.
Inputs.front());
3918 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
3919 "\"preallocated\" argument must be a token from "
3920 "llvm.call.preallocated.setup",
3923 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles", Call);
3924 FoundGCLiveBundle =
true;
3926 Check(!FoundAttachedCallBundle,
3927 "Multiple \"clang.arc.attachedcall\" operand bundles", Call);
3928 FoundAttachedCallBundle =
true;
3929 verifyAttachedCallBundle(Call, BU);
3934 Check(!(
Call.getCalledFunction() && FoundPtrauthBundle),
3935 "Direct call cannot have a ptrauth bundle", Call);
3942 if (
Call.getFunction()->getSubprogram() &&
Call.getCalledFunction() &&
3943 !
Call.getCalledFunction()->isInterposable() &&
3944 !
Call.getCalledFunction()->isDeclaration() &&
3945 Call.getCalledFunction()->getSubprogram())
3947 "inlinable function call in a function with "
3948 "debug info must have a !dbg location",
3951 if (
Call.isInlineAsm())
3952 verifyInlineAsmCall(Call);
3954 ConvergenceVerifyHelper.
visit(Call);
3959void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
3962 Twine(
"inalloca attribute not allowed in ") + Context);
3964 Twine(
"inreg attribute not allowed in ") + Context);
3965 Check(!
Attrs.contains(Attribute::SwiftError),
3966 Twine(
"swifterror attribute not allowed in ") + Context);
3967 Check(!
Attrs.contains(Attribute::Preallocated),
3968 Twine(
"preallocated attribute not allowed in ") + Context);
3970 Twine(
"byref attribute not allowed in ") + Context);
3982 return PL->getAddressSpace() == PR->getAddressSpace();
3987 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3988 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
3989 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
3992 for (
auto AK : ABIAttrs) {
3993 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
3995 Copy.addAttribute(Attr);
3999 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
4000 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
4001 Attrs.hasParamAttr(
I, Attribute::ByRef)))
4002 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
4006void Verifier::verifyMustTailCall(
CallInst &CI) {
4012 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
4013 "cannot guarantee tail call due to mismatched varargs", &CI);
4015 "cannot guarantee tail call due to mismatched return types", &CI);
4019 "cannot guarantee tail call due to mismatched calling conv", &CI);
4025 Value *RetVal = &CI;
4029 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
4031 "bitcast following musttail call must use the call", BI);
4038 Check(Ret,
"musttail call must precede a ret with an optional bitcast", &CI);
4039 Check(!
Ret->getReturnValue() ||
Ret->getReturnValue() == RetVal ||
4040 isa<UndefValue>(
Ret->getReturnValue()),
4041 "musttail call result must be returned", Ret);
4052 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
4055 verifyTailCCMustTailAttrs(ABIAttrs, Context);
4057 for (
unsigned I = 0, E = CalleeTy->getNumParams();
I != E; ++
I) {
4060 verifyTailCCMustTailAttrs(ABIAttrs, Context);
4063 Check(!CallerTy->isVarArg(),
Twine(
"cannot guarantee ") + CCName +
4064 " tail call for varargs function");
4072 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
4073 "cannot guarantee tail call due to mismatched parameter counts", &CI);
4074 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
4077 "cannot guarantee tail call due to mismatched parameter types", &CI);
4083 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
4086 Check(CallerABIAttrs == CalleeABIAttrs,
4087 "cannot guarantee tail call due to mismatched ABI impacting "
4088 "function attributes",
4093void Verifier::visitCallInst(
CallInst &CI) {
4097 verifyMustTailCall(CI);
4106 II.getUnwindDest()->isEHPad(),
4107 "The unwind destination does not have an exception handling instruction!",
4116 Check(
U.getType() ==
U.getOperand(0)->getType(),
4117 "Unary operators must have same type for"
4118 "operands and result!",
4121 switch (
U.getOpcode()) {
4124 case Instruction::FNeg:
4125 Check(
U.getType()->isFPOrFPVectorTy(),
4126 "FNeg operator only works with float types!", &U);
4139 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
4140 "Both operands to a binary operator are not of the same type!", &
B);
4142 switch (
B.getOpcode()) {
4145 case Instruction::Add:
4146 case Instruction::Sub:
4147 case Instruction::Mul:
4148 case Instruction::SDiv:
4149 case Instruction::UDiv:
4150 case Instruction::SRem:
4151 case Instruction::URem:
4152 Check(
B.getType()->isIntOrIntVectorTy(),
4153 "Integer arithmetic operators only work with integral types!", &
B);
4154 Check(
B.getType() ==
B.getOperand(0)->getType(),
4155 "Integer arithmetic operators must have same type "
4156 "for operands and result!",
4161 case Instruction::FAdd:
4162 case Instruction::FSub:
4163 case Instruction::FMul:
4164 case Instruction::FDiv:
4165 case Instruction::FRem:
4166 Check(
B.getType()->isFPOrFPVectorTy(),
4167 "Floating-point arithmetic operators only work with "
4168 "floating-point types!",
4170 Check(
B.getType() ==
B.getOperand(0)->getType(),
4171 "Floating-point arithmetic operators must have same type "
4172 "for operands and result!",
4176 case Instruction::And:
4177 case Instruction::Or:
4178 case Instruction::Xor:
4179 Check(
B.getType()->isIntOrIntVectorTy(),
4180 "Logical operators only work with integral types!", &
B);
4181 Check(
B.getType() ==
B.getOperand(0)->getType(),
4182 "Logical operators must have same type for operands and result!", &
B);
4184 case Instruction::Shl:
4185 case Instruction::LShr:
4186 case Instruction::AShr:
4187 Check(
B.getType()->isIntOrIntVectorTy(),
4188 "Shifts only work with integral types!", &
B);
4189 Check(
B.getType() ==
B.getOperand(0)->getType(),
4190 "Shift return type must be same as operands!", &
B);
4199void Verifier::visitICmpInst(
ICmpInst &IC) {
4203 Check(Op0Ty == Op1Ty,
4204 "Both operands to ICmp instruction are not of the same type!", &IC);
4207 "Invalid operand types for ICmp instruction", &IC);
4214void Verifier::visitFCmpInst(
FCmpInst &FC) {
4216 Type *Op0Ty =
FC.getOperand(0)->getType();
4217 Type *Op1Ty =
FC.getOperand(1)->getType();
4218 Check(Op0Ty == Op1Ty,
4219 "Both operands to FCmp instruction are not of the same type!", &FC);
4224 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
4231 "Invalid extractelement operands!", &EI);
4238 "Invalid insertelement operands!", &IE);
4245 "Invalid shufflevector operands!", &SV);
4250 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4252 Check(isa<PointerType>(TargetTy),
4253 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4254 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4256 if (
auto *STy = dyn_cast<StructType>(
GEP.getSourceElementType())) {
4258 "getelementptr cannot target structure that contains scalable vector"
4265 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4266 "GEP indexes must be integers", &
GEP);
4269 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4271 PointerType *PtrTy = dyn_cast<PointerType>(
GEP.getType()->getScalarType());
4273 Check(PtrTy &&
GEP.getResultElementType() == ElTy,
4274 "GEP is not of right type for indices!", &
GEP, ElTy);
4276 if (
auto *GEPVTy = dyn_cast<VectorType>(
GEP.getType())) {
4279 if (
GEP.getPointerOperandType()->isVectorTy())
4282 cast<VectorType>(
GEP.getPointerOperandType())->getElementCount(),
4283 "Vector GEP result width doesn't match operand's", &
GEP);
4285 Type *IndexTy =
Idx->getType();
4286 if (
auto *IndexVTy = dyn_cast<VectorType>(IndexTy)) {
4288 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4291 "All GEP indices should be of integer type");
4295 Check(
GEP.getAddressSpace() == PtrTy->getAddressSpace(),
4296 "GEP address space doesn't match type", &
GEP);
4302 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4308 Type *Ty, RangeLikeMetadataKind Kind) {
4309 unsigned NumOperands =
Range->getNumOperands();
4310 Check(NumOperands % 2 == 0,
"Unfinished range!",
Range);
4311 unsigned NumRanges = NumOperands / 2;
4312 Check(NumRanges >= 1,
"It should have at least one range!",
Range);
4315 for (
unsigned i = 0; i < NumRanges; ++i) {
4317 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i));
4318 Check(
Low,
"The lower limit must be an integer!",
Low);
4320 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i + 1));
4323 Check(
High->getType() ==
Low->getType(),
"Range pair types must match!",
4326 if (Kind == RangeLikeMetadataKind::NoaliasAddrspace) {
4328 "noalias.addrspace type must be i32!", &
I);
4331 "Range types must match instruction type!", &
I);
4340 "The upper and lower limits cannot be the same value", &
I);
4343 Check(!CurRange.isEmptySet() &&
4344 (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4345 !CurRange.isFullSet()),
4346 "Range must not be empty!",
Range);
4348 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4349 "Intervals are overlapping",
Range);
4350 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4357 if (NumRanges > 2) {
4359 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(0))->getValue();
4361 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(1))->getValue();
4363 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4364 "Intervals are overlapping",
Range);
4372 "precondition violation");
4373 verifyRangeLikeMetadata(
I,
Range, Ty, RangeLikeMetadataKind::Range);
4379 "precondition violation");
4380 verifyRangeLikeMetadata(
I,
Range, Ty,
4381 RangeLikeMetadataKind::NoaliasAddrspace);
4385 unsigned Size =
DL.getTypeSizeInBits(Ty);
4386 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4388 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4391void Verifier::visitLoadInst(
LoadInst &LI) {
4393 Check(PTy,
"Load operand must be a pointer.", &LI);
4397 "huge alignment values are unsupported", &LI);
4399 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4403 "Load cannot have Release ordering", &LI);
4405 "atomic load operand must have integer, pointer, or floating point "
4408 checkAtomicMemAccessSize(ElTy, &LI);
4411 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4417void Verifier::visitStoreInst(
StoreInst &SI) {
4418 PointerType *PTy = dyn_cast<PointerType>(
SI.getOperand(1)->getType());
4419 Check(PTy,
"Store operand must be a pointer.", &SI);
4420 Type *ElTy =
SI.getOperand(0)->getType();
4423 "huge alignment values are unsupported", &SI);
4425 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4426 if (
SI.isAtomic()) {
4429 "Store cannot have Acquire ordering", &SI);
4431 "atomic store operand must have integer, pointer, or floating point "
4434 checkAtomicMemAccessSize(ElTy, &SI);
4437 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4443void Verifier::verifySwiftErrorCall(
CallBase &Call,
4444 const Value *SwiftErrorVal) {
4446 if (
I.value() == SwiftErrorVal) {
4447 Check(
Call.paramHasAttr(
I.index(), Attribute::SwiftError),
4448 "swifterror value when used in a callsite should be marked "
4449 "with swifterror attribute",
4450 SwiftErrorVal, Call);
4455void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4458 for (
const User *U : SwiftErrorVal->
users()) {
4459 Check(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
4461 "swifterror value can only be loaded and stored from, or "
4462 "as a swifterror argument!",
4465 if (
auto StoreI = dyn_cast<StoreInst>(U))
4466 Check(StoreI->getOperand(1) == SwiftErrorVal,
4467 "swifterror value should be the second operand when used "
4470 if (
auto *Call = dyn_cast<CallBase>(U))
4471 verifySwiftErrorCall(*
const_cast<CallBase *
>(Call), SwiftErrorVal);
4475void Verifier::visitAllocaInst(
AllocaInst &AI) {
4478 Check(Ty->
isSized(&Visited),
"Cannot allocate unsized type", &AI);
4482 "Alloca has illegal target extension type", &AI);
4484 "Alloca array size must have integer type", &AI);
4487 "huge alignment values are unsupported", &AI);
4493 "swifterror alloca must not be array allocation", &AI);
4494 verifySwiftErrorValue(&AI);
4497 if (
TT.isAMDGPU()) {
4499 "alloca on amdgpu must be in addrspace(5)", &AI);
4508 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4509 checkAtomicMemAccessSize(ElTy, &CXI);
4515 "atomicrmw instructions cannot be unordered.", &RMWI);
4522 " operand must have integer or floating point type!",
4527 " operand must have floating-point or fixed vector of floating-point "
4533 " operand must have integer type!",
4536 checkAtomicMemAccessSize(ElTy, &RMWI);
4538 "Invalid binary operation!", &RMWI);
4542void Verifier::visitFenceInst(
FenceInst &FI) {
4548 "fence instructions may only have acquire, release, acq_rel, or "
4549 "seq_cst ordering.",
4557 "Invalid ExtractValueInst operands!", &EVI);
4566 "Invalid InsertValueInst operands!", &IVI);
4572 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
4573 return FPI->getParentPad();
4575 return cast<CatchSwitchInst>(EHPad)->getParentPad();
4584 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4586 if (
auto *LPI = dyn_cast<LandingPadInst>(&
I)) {
4591 const auto *
II = dyn_cast<InvokeInst>(PredBB->getTerminator());
4592 Check(
II &&
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4593 "Block containing LandingPadInst must be jumped to "
4594 "only by the unwind edge of an invoke.",
4599 if (
auto *CPI = dyn_cast<CatchPadInst>(&
I)) {
4602 "Block containg CatchPadInst must be jumped to "
4603 "only by its catchswitch.",
4605 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
4606 "Catchswitch cannot unwind to one of its catchpads",
4607 CPI->getCatchSwitch(), CPI);
4618 if (
auto *
II = dyn_cast<InvokeInst>(TI)) {
4619 Check(
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4620 "EH pad must be jumped to via an unwind edge", ToPad,
II);
4622 dyn_cast<Function>(
II->getCalledOperand()->stripPointerCasts());
4623 if (CalledFn && CalledFn->isIntrinsic() &&
II->doesNotThrow() &&
4627 FromPad = Bundle->Inputs[0];
4630 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
4631 FromPad = CRI->getOperand(0);
4632 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
4633 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
4636 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
4642 Check(FromPad != ToPad,
4643 "EH pad cannot handle exceptions raised within it", FromPad, TI);
4644 if (FromPad == ToPadParent) {
4648 Check(!isa<ConstantTokenNone>(FromPad),
4649 "A single unwind edge may only enter one EH pad", TI);
4650 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
4655 Check(isa<FuncletPadInst>(FromPad) || isa<CatchSwitchInst>(FromPad),
4656 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
4665 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
4667 visitEHPadPredecessors(LPI);
4669 if (!LandingPadResultTy)
4670 LandingPadResultTy = LPI.
getType();
4673 "The landingpad instruction should have a consistent result type "
4674 "inside a function.",
4678 Check(
F->hasPersonalityFn(),
4679 "LandingPadInst needs to be in a function with a personality.", &LPI);
4684 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
4690 "Catch operand does not have pointer type!", &LPI);
4692 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
4694 "Filter operand is not an array of constants!", &LPI);
4701void Verifier::visitResumeInst(
ResumeInst &RI) {
4703 "ResumeInst needs to be in a function with a personality.", &RI);
4705 if (!LandingPadResultTy)
4709 "The resume instruction should have a consistent result type "
4710 "inside a function.",
4720 Check(
F->hasPersonalityFn(),
4721 "CatchPadInst needs to be in a function with a personality.", &CPI);
4724 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
4730 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
4732 visitEHPadPredecessors(CPI);
4738 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
4748 Check(
F->hasPersonalityFn(),
4749 "CleanupPadInst needs to be in a function with a personality.", &CPI);
4754 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
4757 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4758 "CleanupPadInst has an invalid parent.", &CPI);
4760 visitEHPadPredecessors(CPI);
4765 User *FirstUser =
nullptr;
4766 Value *FirstUnwindPad =
nullptr;
4770 while (!Worklist.empty()) {
4773 "FuncletPadInst must not be nested within itself", CurrentPad);
4774 Value *UnresolvedAncestorPad =
nullptr;
4777 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
4778 UnwindDest = CRI->getUnwindDest();
4779 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
4784 if (CSI->unwindsToCaller())
4786 UnwindDest = CSI->getUnwindDest();
4787 }
else if (
auto *
II = dyn_cast<InvokeInst>(U)) {
4788 UnwindDest =
II->getUnwindDest();
4789 }
else if (isa<CallInst>(U)) {
4794 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
4798 Worklist.push_back(CPI);
4801 Check(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
4809 if (!cast<Instruction>(UnwindPad)->isEHPad())
4813 if (UnwindParent == CurrentPad)
4819 Value *ExitedPad = CurrentPad;
4822 if (ExitedPad == &FPI) {
4827 UnresolvedAncestorPad = &FPI;
4831 if (ExitedParent == UnwindParent) {
4835 UnresolvedAncestorPad = ExitedParent;
4838 ExitedPad = ExitedParent;
4839 }
while (!isa<ConstantTokenNone>(ExitedPad));
4844 UnresolvedAncestorPad = &FPI;
4851 Check(UnwindPad == FirstUnwindPad,
4852 "Unwind edges out of a funclet "
4853 "pad must have the same unwind "
4855 &FPI, U, FirstUser);
4858 FirstUnwindPad = UnwindPad;
4860 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
4862 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
4867 if (CurrentPad != &FPI)
4870 if (UnresolvedAncestorPad) {
4871 if (CurrentPad == UnresolvedAncestorPad) {
4875 assert(CurrentPad == &FPI);
4883 Value *ResolvedPad = CurrentPad;
4884 while (!Worklist.empty()) {
4885 Value *UnclePad = Worklist.back();
4889 while (ResolvedPad != AncestorPad) {
4891 if (ResolvedParent == UnresolvedAncestorPad) {
4894 ResolvedPad = ResolvedParent;
4898 if (ResolvedPad != AncestorPad)
4901 Worklist.pop_back();
4906 if (FirstUnwindPad) {
4907 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
4908 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
4909 Value *SwitchUnwindPad;
4910 if (SwitchUnwindDest)
4914 Check(SwitchUnwindPad == FirstUnwindPad,
4915 "Unwind edges out of a catch must have the same unwind dest as "
4916 "the parent catchswitch",
4917 &FPI, FirstUser, CatchSwitch);
4928 Check(
F->hasPersonalityFn(),
4929 "CatchSwitchInst needs to be in a function with a personality.",
4935 "CatchSwitchInst not the first non-PHI instruction in the block.",
4939 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4940 "CatchSwitchInst has an invalid parent.", ParentPad);
4944 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4945 "CatchSwitchInst must unwind to an EH block which is not a "
4951 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
4955 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
4958 Check(isa<CatchPadInst>(Handler->getFirstNonPHIIt()),
4959 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
4962 visitEHPadPredecessors(CatchSwitch);
4968 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
4973 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4974 "CleanupReturnInst must unwind to an EH block which is not a "
4982void Verifier::verifyDominatesUse(
Instruction &
I,
unsigned i) {
4988 if (
II->getNormalDest() ==
II->getUnwindDest())
4999 if (!isa<PHINode>(
I) && InstsInThisBlock.
count(
Op))
5002 const Use &
U =
I.getOperandUse(i);
5007 Check(
I.getType()->isPointerTy(),
5008 "dereferenceable, dereferenceable_or_null "
5009 "apply only to pointer types",
5011 Check((isa<LoadInst>(
I) || isa<IntToPtrInst>(
I)),
5012 "dereferenceable, dereferenceable_or_null apply only to load"
5013 " and inttoptr instructions, use attributes for calls or invokes",
5016 "dereferenceable, dereferenceable_or_null "
5017 "take one operand!",
5022 "dereferenceable_or_null metadata value must be an i64!",
5027 auto GetBranchingTerminatorNumOperands = [&]() {
5028 unsigned ExpectedNumOperands = 0;
5031 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
5032 ExpectedNumOperands =
SI->getNumSuccessors();
5033 else if (isa<CallInst>(&
I))
5034 ExpectedNumOperands = 1;
5036 ExpectedNumOperands = IBI->getNumDestinations();
5037 else if (isa<SelectInst>(&
I))
5038 ExpectedNumOperands = 2;
5039 else if (
CallBrInst *CI = dyn_cast<CallBrInst>(&
I))
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);
5053 Check(GetBranchingTerminatorNumOperands() != 0 || isa<InvokeInst>(
I),
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);
5068 if (isa<InvokeInst>(&
I)) {
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);
5084 Check(mdconst::dyn_extract<ConstantInt>(MDO),
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);
5112 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
5117 bool ExpectedInstTy =
5118 isa<AllocaInst>(
I) || isa<StoreInst>(
I) || isa<IntrinsicInst>(
I);
5119 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
5126 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
5129 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(
User))
5130 CheckDI(DAI->getFunction() ==
I.getFunction(),
5131 "dbg.assign not in same function as inst", DAI, &
I);
5135 cast<DIAssignID>(MD)->getAllDbgVariableRecordUsers()) {
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);
5145 "!mmra metadata attached to unexpected instruction kind",
I, MD);
5155 Check(isa<MDTuple>(MD),
"!mmra expected to be a metadata tuple",
I, MD);
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);
5168 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op),
5169 "call stack metadata operand should be constant integer",
Op);
5173 Check(isa<CallBase>(
I),
"!memprof metadata should only exist on calls", &
I);
5175 "!memprof annotations should have at least 1 metadata operand "
5180 for (
auto &MIBOp : MD->
operands()) {
5181 MDNode *MIB = dyn_cast<MDNode>(MIBOp);
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 "
5219 return mdconst::hasa<ConstantInt>(Op);
5221 "Not all !memprof MemInfoBlock operands 2 to N are MDNode with "
5222 "ConstantInt operands",
5229 Check(isa<CallBase>(
I),
"!callsite metadata should only exist on calls", &
I);
5232 visitCallStackMetadata(MD);
5236 if (
auto *VAL = dyn_cast<ValueAsMetadata>(MD))
5237 return isa<ConstantInt>(VAL->getValue());
5242 Check(isa<CallBase>(
I),
"!callee_type metadata should only exist on calls",
5246 "The callee_type metadata must be a list of type metadata nodes",
Op);
5247 auto *TypeMD = cast<MDNode>(
Op);
5248 Check(TypeMD->getNumOperands() == 2,
5249 "Well-formed generalized type metadata must contain exactly two "
5253 mdconst::extract<ConstantInt>(TypeMD->getOperand(0))->isZero(),
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) {
5263 Check(isa<MDTuple>(Annotation),
"annotation must be a tuple");
5265 "annotation must have at least one operand");
5267 bool TupleOfStrings =
5268 isa<MDTuple>(
Op.get()) &&
5269 all_of(cast<MDTuple>(
Op)->operands(), [](
auto &Annotation) {
5272 Check(isa<MDString>(
Op.get()) || TupleOfStrings,
5273 "operands must be a string or a tuple of strings");
5277void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
5279 Check(NumOps >= 2 && NumOps <= 3,
"scope must have two or three operands",
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);
5294 isa<MDString>(
Domain->getOperand(0)),
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) {
5303 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
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))
5320 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
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);
5331 Check(BB,
"Instruction not embedded in basic block!", &
I);
5333 if (!isa<PHINode>(
I)) {
5334 for (
User *U :
I.users()) {
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);
5351 Check(!
I.getType()->isMetadataTy() || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5352 "Invalid use of metadata!", &
I);
5357 for (
Use &U :
I.uses()) {
5358 if (
Instruction *Used = dyn_cast<Instruction>(
U.getUser()))
5360 "Instruction referencing"
5361 " instruction not embedded in a basic block!",
5364 CheckFailed(
"Use of instruction is not an instruction!", U);
5371 const CallBase *CBI = dyn_cast<CallBase>(&
I);
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);
5382 if (
Function *
F = dyn_cast<Function>(
I.getOperand(i))) {
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);
5399 Check(!
F->isIntrinsic() || isa<CallInst>(
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());
5424 }
else if (
BasicBlock *OpBB = dyn_cast<BasicBlock>(
I.getOperand(i))) {
5426 "Referring to a basic block in another function!", &
I);
5427 }
else if (
Argument *OpArg = dyn_cast<Argument>(
I.getOperand(i))) {
5429 "Referring to an argument in another function!", &
I);
5430 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(
I.getOperand(i))) {
5431 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5433 }
else if (
Instruction *OpInst = dyn_cast<Instruction>(
I.getOperand(i))) {
5435 "Referring to an instruction in another function!", &
I);
5436 verifyDominatesUse(
I, i);
5437 }
else if (isa<InlineAsm>(
I.getOperand(i))) {
5438 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5439 "Cannot take the address of an inline asm!", &
I);
5440 }
else if (
auto *CPA = dyn_cast<ConstantPtrAuth>(
I.getOperand(i))) {
5441 visitConstantExprsRecursively(CPA);
5442 }
else if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(
I.getOperand(i))) {
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);
5456 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
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)) {
5468 Check(isa<LoadInst>(
I) || isa<CallInst>(
I) || isa<InvokeInst>(
I),
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)) {
5474 Check(isa<LoadInst>(
I) || isa<StoreInst>(
I) || isa<AtomicRMWInst>(
I) ||
5475 isa<AtomicCmpXchgInst>(
I) || isa<CallInst>(
I),
5476 "noalias.addrspace are only for memory operations!", &
I);
5477 visitNoaliasAddrspaceMetadata(
I,
Range,
I.getType());
5480 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
5481 Check(isa<LoadInst>(
I) || isa<StoreInst>(
I),
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 *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
5504 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
5505 visitAliasScopeListMetadata(MD);
5506 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
5507 visitAliasScopeListMetadata(MD);
5509 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
5510 visitAccessGroupMetadata(MD);
5512 if (
MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
5513 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
5516 "align applies only to load instructions, "
5517 "use attributes for calls or invokes",
5519 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
5520 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
5522 "align metadata value must be an i64!", &
I);
5527 "alignment is larger that implementation defined limit", &
I);
5530 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
5531 visitProfMetadata(
I, MD);
5533 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
5534 visitMemProfMetadata(
I, MD);
5536 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
5537 visitCallsiteMetadata(
I, MD);
5539 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_callee_type))
5540 visitCalleeTypeMetadata(
I, MD);
5542 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
5543 visitDIAssignIDMetadata(
I, MD);
5545 if (
MDNode *MMRA =
I.getMetadata(LLVMContext::MD_mmra))
5546 visitMMRAMetadata(
I, MMRA);
5548 if (
MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
5549 visitAnnotationMetadata(Annotation);
5551 if (
MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
5552 CheckDI(isa<DILocation>(
N),
"invalid !dbg metadata attachment", &
I,
N);
5553 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
5555 if (
auto *
DL = dyn_cast<DILocation>(
N)) {
5556 if (
DL->getAtomGroup()) {
5557 CheckDI(
DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
5558 "DbgLoc uses atomGroup but DISubprogram doesn't have Key "
5559 "Instructions enabled",
5560 DL,
DL->getScope()->getSubprogram());
5566 I.getAllMetadata(MDs);
5567 for (
auto Attachment : MDs) {
5568 unsigned Kind = Attachment.first;
5570 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
5571 ? AreDebugLocsAllowed::Yes
5572 : AreDebugLocsAllowed::No;
5573 visitMDNode(*Attachment.second, AllowLocs);
5582 Check(
IF->isDeclaration(),
"Intrinsic functions should never be defined!",
5588 bool IsVarArg = IFTy->isVarArg();
5599 "Intrinsic has incorrect return type!", IF);
5601 "Intrinsic has incorrect argument type!", IF);
5606 "Intrinsic was not defined with variable arguments!", IF);
5609 "Callsite was not defined with variable arguments!", IF);
5618 const std::string ExpectedName =
5620 Check(ExpectedName ==
IF->getName(),
5621 "Intrinsic name not mangled correctly for type arguments! "
5629 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
5630 visitMetadataAsValue(*MD,
Call.getCaller());
5631 if (
auto *Const = dyn_cast<Constant>(V))
5633 "const x86_amx is not allowed in argument!");
5639 case Intrinsic::assume: {
5640 for (
auto &Elem :
Call.bundle_op_infos()) {
5641 unsigned ArgCount = Elem.End - Elem.Begin;
5644 if (Elem.Tag->getKey() ==
"separate_storage") {
5645 Check(ArgCount == 2,
5646 "separate_storage assumptions should have 2 arguments", Call);
5647 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy() &&
5648 Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(),
5649 "arguments to separate_storage assumptions should be pointers",
5653 Check(Elem.Tag->getKey() ==
"ignore" ||
5655 "tags must be valid attribute names", Call);
5658 if (Kind == Attribute::Alignment) {
5659 Check(ArgCount <= 3 && ArgCount >= 2,
5660 "alignment assumptions should have 2 or 3 arguments", Call);
5661 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5662 "first argument should be a pointer", Call);
5663 Check(
Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5664 "second argument should be an integer", Call);
5666 Check(
Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(),
5667 "third argument should be an integer if present", Call);
5670 if (Kind == Attribute::Dereferenceable) {
5671 Check(ArgCount == 2,
5672 "dereferenceable assumptions should have 2 arguments", Call);
5673 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5674 "first argument should be a pointer", Call);
5675 Check(
Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5676 "second argument should be an integer", Call);
5679 Check(ArgCount <= 2,
"too many arguments", Call);
5683 Check(ArgCount == 2,
"this attribute should have 2 arguments", Call);
5684 Check(isa<ConstantInt>(
Call.getOperand(Elem.Begin + 1)),
5685 "the second argument should be a constant integral value", Call);
5687 Check((ArgCount) == 1,
"this attribute should have one argument", Call);
5689 Check((ArgCount) == 0,
"this attribute has no argument", Call);
5694 case Intrinsic::ucmp:
5695 case Intrinsic::scmp: {
5696 Type *SrcTy =
Call.getOperand(0)->getType();
5700 "result type must be at least 2 bits wide", Call);
5702 bool IsDestTypeVector = DestTy->
isVectorTy();
5704 "ucmp/scmp argument and result types must both be either vector or "
5707 if (IsDestTypeVector) {
5708 auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
5709 auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
5710 Check(SrcVecLen == DestVecLen,
5711 "return type and arguments must have the same number of "
5717 case Intrinsic::coro_id: {
5718 auto *InfoArg =
Call.getArgOperand(3)->stripPointerCasts();
5719 if (isa<ConstantPointerNull>(InfoArg))
5721 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
5723 "info argument of llvm.coro.id must refer to an initialized "
5726 Check(isa<ConstantStruct>(
Init) || isa<ConstantArray>(
Init),
5727 "info argument of llvm.coro.id must refer to either a struct or "
5731 case Intrinsic::is_fpclass: {
5734 "unsupported bits for llvm.is.fpclass test mask");
5737 case Intrinsic::fptrunc_round: {
5740 auto *MAV = dyn_cast<MetadataAsValue>(
Call.getOperand(1));
5742 MD = MAV->getMetadata();
5744 Check(MD !=
nullptr,
"missing rounding mode argument", Call);
5746 Check(isa<MDString>(MD),
5747 (
"invalid value for llvm.fptrunc.round metadata operand"
5748 " (the operand should be a string)"),
5751 std::optional<RoundingMode> RoundMode =
5754 "unsupported rounding mode argument", Call);
5757#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
5758#include "llvm/IR/VPIntrinsics.def"
5759#undef BEGIN_REGISTER_VP_INTRINSIC
5760 visitVPIntrinsic(cast<VPIntrinsic>(Call));
5762#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
5763 case Intrinsic::INTRINSIC:
5764#include "llvm/IR/ConstrainedOps.def"
5766 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call));
5768 case Intrinsic::dbg_declare:
5769 case Intrinsic::dbg_value:
5770 case Intrinsic::dbg_assign:
5771 case Intrinsic::dbg_label:
5778 case Intrinsic::memcpy:
5779 case Intrinsic::memcpy_inline:
5780 case Intrinsic::memmove:
5781 case Intrinsic::memset:
5782 case Intrinsic::memset_inline:
5784 case Intrinsic::experimental_memset_pattern: {
5785 const auto Memset = cast<MemSetPatternInst>(&Call);
5786 Check(Memset->getValue()->getType()->isSized(),
5787 "unsized types cannot be used as memset patterns", Call);
5790 case Intrinsic::memcpy_element_unordered_atomic:
5791 case Intrinsic::memmove_element_unordered_atomic:
5792 case Intrinsic::memset_element_unordered_atomic: {
5793 const auto *AMI = cast<AnyMemIntrinsic>(&Call);
5796 cast<ConstantInt>(AMI->getRawElementSizeInBytes());
5799 "element size of the element-wise atomic memory intrinsic "
5800 "must be a power of 2",
5803 auto IsValidAlignment = [&](
MaybeAlign Alignment) {
5804 return Alignment && ElementSizeVal.
ule(Alignment->value());
5806 Check(IsValidAlignment(AMI->getDestAlign()),
5807 "incorrect alignment of the destination argument", Call);
5808 if (
const auto *AMT = dyn_cast<AnyMemTransferInst>(AMI)) {
5809 Check(IsValidAlignment(AMT->getSourceAlign()),
5810 "incorrect alignment of the source argument", Call);
5814 case Intrinsic::call_preallocated_setup: {
5815 auto *NumArgs = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5816 Check(NumArgs !=
nullptr,
5817 "llvm.call.preallocated.setup argument must be a constant");
5818 bool FoundCall =
false;
5820 auto *UseCall = dyn_cast<CallBase>(U);
5821 Check(UseCall !=
nullptr,
5822 "Uses of llvm.call.preallocated.setup must be calls");
5824 if (IID == Intrinsic::call_preallocated_arg) {
5825 auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5826 Check(AllocArgIndex !=
nullptr,
5827 "llvm.call.preallocated.alloc arg index must be a constant");
5828 auto AllocArgIndexInt = AllocArgIndex->getValue();
5829 Check(AllocArgIndexInt.sge(0) &&
5830 AllocArgIndexInt.slt(NumArgs->getValue()),
5831 "llvm.call.preallocated.alloc arg index must be between 0 and "
5833 "llvm.call.preallocated.setup's argument count");
5834 }
else if (IID == Intrinsic::call_preallocated_teardown) {
5837 Check(!FoundCall,
"Can have at most one call corresponding to a "
5838 "llvm.call.preallocated.setup");
5840 size_t NumPreallocatedArgs = 0;
5841 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
5842 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
5843 ++NumPreallocatedArgs;
5846 Check(NumPreallocatedArgs != 0,
5847 "cannot use preallocated intrinsics on a call without "
5848 "preallocated arguments");
5849 Check(NumArgs->equalsInt(NumPreallocatedArgs),
5850 "llvm.call.preallocated.setup arg size must be equal to number "
5851 "of preallocated arguments "
5861 auto PreallocatedBundle =
5863 Check(PreallocatedBundle,
5864 "Use of llvm.call.preallocated.setup outside intrinsics "
5865 "must be in \"preallocated\" operand bundle");
5866 Check(PreallocatedBundle->Inputs.front().get() == &Call,
5867 "preallocated bundle must have token from corresponding "
5868 "llvm.call.preallocated.setup");
5873 case Intrinsic::call_preallocated_arg: {
5874 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5876 Token->getIntrinsicID() == Intrinsic::call_preallocated_setup,
5877 "llvm.call.preallocated.arg token argument must be a "
5878 "llvm.call.preallocated.setup");
5879 Check(
Call.hasFnAttr(Attribute::Preallocated),
5880 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
5881 "call site attribute");
5884 case Intrinsic::call_preallocated_teardown: {
5885 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5887 Token->getIntrinsicID() == Intrinsic::call_preallocated_setup,
5888 "llvm.call.preallocated.teardown token argument must be a "
5889 "llvm.call.preallocated.setup");
5892 case Intrinsic::gcroot:
5893 case Intrinsic::gcwrite:
5894 case Intrinsic::gcread:
5895 if (
ID == Intrinsic::gcroot) {
5897 dyn_cast<AllocaInst>(
Call.getArgOperand(0)->stripPointerCasts());
5898 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.", Call);
5899 Check(isa<Constant>(
Call.getArgOperand(1)),
5900 "llvm.gcroot parameter #2 must be a constant.", Call);
5902 Check(!isa<ConstantPointerNull>(
Call.getArgOperand(1)),
5903 "llvm.gcroot parameter #1 must either be a pointer alloca, "
5904 "or argument #2 must be a non-null constant.",
5909 Check(
Call.getParent()->getParent()->hasGC(),
5910 "Enclosing function does not use GC.", Call);
5912 case Intrinsic::init_trampoline:
5913 Check(isa<Function>(
Call.getArgOperand(1)->stripPointerCasts()),
5914 "llvm.init_trampoline parameter #2 must resolve to a function.",
5917 case Intrinsic::prefetch:
5918 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
5919 "rw argument to llvm.prefetch must be 0-1", Call);
5920 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
5921 "locality argument to llvm.prefetch must be 0-3", Call);
5922 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
5923 "cache type argument to llvm.prefetch must be 0-1", Call);
5925 case Intrinsic::stackprotector:
5926 Check(isa<AllocaInst>(
Call.getArgOperand(1)->stripPointerCasts()),
5927 "llvm.stackprotector parameter #2 must resolve to an alloca.", Call);
5929 case Intrinsic::localescape: {
5933 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
5936 if (isa<ConstantPointerNull>(Arg))
5938 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
5940 "llvm.localescape only accepts static allocas", Call);
5943 SawFrameEscape =
true;
5946 case Intrinsic::localrecover: {
5947 Value *FnArg =
Call.getArgOperand(0)->stripPointerCasts();
5948 Function *Fn = dyn_cast<Function>(FnArg);
5950 "llvm.localrecover first "
5951 "argument must be function defined in this module",
5953 auto *IdxArg = cast<ConstantInt>(
Call.getArgOperand(2));
5954 auto &
Entry = FrameEscapeInfo[Fn];
5956 std::max(
uint64_t(
Entry.second), IdxArg->getLimitedValue(~0U) + 1));
5960 case Intrinsic::experimental_gc_statepoint:
5961 if (
auto *CI = dyn_cast<CallInst>(&Call))
5962 Check(!CI->isInlineAsm(),
5963 "gc.statepoint support for inline assembly unimplemented", CI);
5964 Check(
Call.getParent()->getParent()->hasGC(),
5965 "Enclosing function does not use GC.", Call);
5967 verifyStatepoint(Call);
5969 case Intrinsic::experimental_gc_result: {
5970 Check(
Call.getParent()->getParent()->hasGC(),
5971 "Enclosing function does not use GC.", Call);
5973 auto *Statepoint =
Call.getArgOperand(0);
5974 if (isa<UndefValue>(Statepoint))
5978 const auto *StatepointCall = dyn_cast<CallBase>(Statepoint);
5979 Check(StatepointCall && StatepointCall->getIntrinsicID() ==
5980 Intrinsic::experimental_gc_statepoint,
5981 "gc.result operand #1 must be from a statepoint", Call,
5982 Call.getArgOperand(0));
5985 auto *TargetFuncType =
5986 cast<FunctionType>(StatepointCall->getParamElementType(2));
5987 Check(
Call.getType() == TargetFuncType->getReturnType(),
5988 "gc.result result type does not match wrapped callee", Call);
5991 case Intrinsic::experimental_gc_relocate: {
5992 Check(
Call.arg_size() == 3,
"wrong number of arguments", Call);
5994 Check(isa<PointerType>(
Call.getType()->getScalarType()),
5995 "gc.relocate must return a pointer or a vector of pointers", Call);
6001 dyn_cast<LandingPadInst>(
Call.getArgOperand(0))) {
6004 LandingPad->
getParent()->getUniquePredecessor();
6008 Check(InvokeBB,
"safepoints should have unique landingpads",
6009 LandingPad->getParent());
6013 "gc relocate should be linked to a statepoint", InvokeBB);
6018 auto *Token =
Call.getArgOperand(0);
6019 Check(isa<GCStatepointInst>(Token) || isa<UndefValue>(Token),
6020 "gc relocate is incorrectly tied to the statepoint", Call, Token);
6024 const Value &StatepointCall = *cast<GCRelocateInst>(Call).getStatepoint();
6029 "gc.relocate operand #2 must be integer offset", Call);
6032 Check(isa<ConstantInt>(Derived),
6033 "gc.relocate operand #3 must be integer offset", Call);
6035 const uint64_t BaseIndex = cast<ConstantInt>(
Base)->getZExtValue();
6036 const uint64_t DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
6039 if (isa<UndefValue>(StatepointCall))
6041 if (
auto Opt = cast<GCStatepointInst>(StatepointCall)
6043 Check(BaseIndex < Opt->Inputs.size(),
6044 "gc.relocate: statepoint base index out of bounds", Call);
6045 Check(DerivedIndex < Opt->Inputs.size(),
6046 "gc.relocate: statepoint derived index out of bounds", Call);
6054 auto *ResultType =
Call.getType();
6059 "gc.relocate: relocated value must be a pointer", Call);
6060 Check(DerivedType->isPtrOrPtrVectorTy(),
6061 "gc.relocate: relocated value must be a pointer", Call);
6063 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
6064 "gc.relocate: vector relocates to vector and pointer to pointer",
6067 ResultType->getPointerAddressSpace() ==
6068 DerivedType->getPointerAddressSpace(),
6069 "gc.relocate: relocating a pointer shouldn't change its address space",
6073 Check(GC,
"gc.relocate: calling function must have GCStrategy",
6074 Call.getFunction());
6076 auto isGCPtr = [&
GC](
Type *PTy) {
6077 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
6079 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer", Call);
6081 "gc.relocate: relocated value must be a gc pointer", Call);
6082 Check(isGCPtr(DerivedType),
6083 "gc.relocate: relocated value must be a gc pointer", Call);
6087 case Intrinsic::experimental_patchpoint: {
6089 Check(
Call.getType()->isSingleValueType(),
6090 "patchpoint: invalid return type used with anyregcc", Call);
6094 case Intrinsic::eh_exceptioncode:
6095 case Intrinsic::eh_exceptionpointer: {
6096 Check(isa<CatchPadInst>(
Call.getArgOperand(0)),
6097 "eh.exceptionpointer argument must be a catchpad", Call);
6100 case Intrinsic::get_active_lane_mask: {
6102 "get_active_lane_mask: must return a "
6105 auto *ElemTy =
Call.getType()->getScalarType();
6106 Check(ElemTy->isIntegerTy(1),
6107 "get_active_lane_mask: element type is not "
6112 case Intrinsic::experimental_get_vector_length: {
6115 "get_vector_length: VF must be positive", Call);
6118 case Intrinsic::masked_load: {
6119 Check(
Call.getType()->isVectorTy(),
"masked_load: must return a vector",
6124 Value *PassThru =
Call.getArgOperand(3);
6125 Check(
Mask->getType()->isVectorTy(),
"masked_load: mask must be vector",
6128 "masked_load: alignment must be a power of 2", Call);
6130 "masked_load: pass through and return type must match", Call);
6131 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
6132 cast<VectorType>(
Call.getType())->getElementCount(),
6133 "masked_load: vector mask must be same length as return", Call);
6136 case Intrinsic::masked_store: {
6140 Check(
Mask->getType()->isVectorTy(),
"masked_store: mask must be vector",
6143 "masked_store: alignment must be a power of 2", Call);
6144 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
6145 cast<VectorType>(Val->
getType())->getElementCount(),
6146 "masked_store: vector mask must be same length as value", Call);
6150 case Intrinsic::masked_gather: {
6151 const APInt &Alignment =
6154 "masked_gather: alignment must be 0 or a power of 2", Call);
6157 case Intrinsic::masked_scatter: {
6158 const APInt &Alignment =
6159 cast<ConstantInt>(
Call.getArgOperand(2))->getValue();
6161 "masked_scatter: alignment must be 0 or a power of 2", Call);
6165 case Intrinsic::experimental_guard: {
6166 Check(isa<CallInst>(Call),
"experimental_guard cannot be invoked", Call);
6168 "experimental_guard must have exactly one "
6169 "\"deopt\" operand bundle");
6173 case Intrinsic::experimental_deoptimize: {
6174 Check(isa<CallInst>(Call),
"experimental_deoptimize cannot be invoked",
6177 "experimental_deoptimize must have exactly one "
6178 "\"deopt\" operand bundle");
6179 Check(
Call.getType() ==
Call.getFunction()->getReturnType(),
6180 "experimental_deoptimize return type must match caller return type");
6182 if (isa<CallInst>(Call)) {
6183 auto *RI = dyn_cast<ReturnInst>(
Call.getNextNode());
6185 "calls to experimental_deoptimize must be followed by a return");
6187 if (!
Call.getType()->isVoidTy() && RI)
6188 Check(RI->getReturnValue() == &Call,
6189 "calls to experimental_deoptimize must be followed by a return "
6190 "of the value computed by experimental_deoptimize");
6195 case Intrinsic::vastart: {
6197 "va_start called in a non-varargs function");
6200 case Intrinsic::get_dynamic_area_offset: {
6201 auto *IntTy = dyn_cast<IntegerType>(
Call.getType());
6202 Check(IntTy &&
DL.getPointerSizeInBits(
DL.getAllocaAddrSpace()) ==
6203 IntTy->getBitWidth(),
6204 "get_dynamic_area_offset result type must be scalar integer matching "
6205 "alloca address space width",
6209 case Intrinsic::vector_reduce_and:
6210 case Intrinsic::vector_reduce_or:
6211 case Intrinsic::vector_reduce_xor:
6212 case Intrinsic::vector_reduce_add:
6213 case Intrinsic::vector_reduce_mul:
6214 case Intrinsic::vector_reduce_smax:
6215 case Intrinsic::vector_reduce_smin:
6216 case Intrinsic::vector_reduce_umax:
6217 case Intrinsic::vector_reduce_umin: {
6218 Type *ArgTy =
Call.getArgOperand(0)->getType();
6220 "Intrinsic has incorrect argument type!");
6223 case Intrinsic::vector_reduce_fmax:
6224 case Intrinsic::vector_reduce_fmin: {
6225 Type *ArgTy =
Call.getArgOperand(0)->getType();
6227 "Intrinsic has incorrect argument type!");
6230 case Intrinsic::vector_reduce_fadd:
6231 case Intrinsic::vector_reduce_fmul: {
6234 Type *ArgTy =
Call.getArgOperand(1)->getType();
6236 "Intrinsic has incorrect argument type!");
6239 case Intrinsic::smul_fix:
6240 case Intrinsic::smul_fix_sat:
6241 case Intrinsic::umul_fix:
6242 case Intrinsic::umul_fix_sat:
6243 case Intrinsic::sdiv_fix:
6244 case Intrinsic::sdiv_fix_sat:
6245 case Intrinsic::udiv_fix:
6246 case Intrinsic::udiv_fix_sat: {
6250 "first operand of [us][mul|div]_fix[_sat] must be an int type or "
6253 "second operand of [us][mul|div]_fix[_sat] must be an int type or "
6256 auto *Op3 = cast<ConstantInt>(
Call.getArgOperand(2));
6257 Check(Op3->getType()->isIntegerTy(),
6258 "third operand of [us][mul|div]_fix[_sat] must be an int type");
6259 Check(Op3->getBitWidth() <= 32,
6260 "third operand of [us][mul|div]_fix[_sat] must fit within 32 bits");
6262 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
6263 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
6265 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
6269 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
6270 "to the width of the operands");
6274 case Intrinsic::lrint:
6275 case Intrinsic::llrint:
6276 case Intrinsic::lround:
6277 case Intrinsic::llround: {
6278 Type *ValTy =
Call.getArgOperand(0)->getType();
6280 auto *VTy = dyn_cast<VectorType>(ValTy);
6281 auto *RTy = dyn_cast<VectorType>(ResultTy);
6283 ExpectedName +
": argument must be floating-point or vector "
6284 "of floating-points, and result must be integer or "
6285 "vector of integers",
6288 ExpectedName +
": argument and result disagree on vector use", &Call);
6290 Check(VTy->getElementCount() == RTy->getElementCount(),
6291 ExpectedName +
": argument must be same length as result", &Call);
6295 case Intrinsic::bswap: {
6298 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &Call);
6301 case Intrinsic::invariant_start: {
6302 ConstantInt *InvariantSize = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
6303 Check(InvariantSize &&
6305 "invariant_start parameter must be -1, 0 or a positive number",
6309 case Intrinsic::matrix_multiply:
6310 case Intrinsic::matrix_transpose:
6311 case Intrinsic::matrix_column_major_load:
6312 case Intrinsic::matrix_column_major_store: {
6318 Type *Op0ElemTy =
nullptr;
6319 Type *Op1ElemTy =
nullptr;
6321 case Intrinsic::matrix_multiply: {
6322 NumRows = cast<ConstantInt>(
Call.getArgOperand(2));
6324 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
6325 Check(cast<FixedVectorType>(
Call.getArgOperand(0)->getType())
6326 ->getNumElements() ==
6328 "First argument of a matrix operation does not match specified "
6330 Check(cast<FixedVectorType>(
Call.getArgOperand(1)->getType())
6331 ->getNumElements() ==
6333 "Second argument of a matrix operation does not match specified "
6336 ResultTy = cast<VectorType>(
Call.getType());
6338 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6340 cast<VectorType>(
Call.getArgOperand(1)->getType())->getElementType();
6343 case Intrinsic::matrix_transpose:
6344 NumRows = cast<ConstantInt>(
Call.getArgOperand(1));
6345 NumColumns = cast<ConstantInt>(
Call.getArgOperand(2));
6346 ResultTy = cast<VectorType>(
Call.getType());
6348 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6350 case Intrinsic::matrix_column_major_load: {
6351 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(1));
6352 NumRows = cast<ConstantInt>(
Call.getArgOperand(3));
6353 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
6354 ResultTy = cast<VectorType>(
Call.getType());
6357 case Intrinsic::matrix_column_major_store: {
6358 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(2));
6359 NumRows = cast<ConstantInt>(
Call.getArgOperand(4));
6360 NumColumns = cast<ConstantInt>(
Call.getArgOperand(5));
6361 ResultTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
6363 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6370 Check(ResultTy->getElementType()->isIntegerTy() ||
6371 ResultTy->getElementType()->isFloatingPointTy(),
6372 "Result type must be an integer or floating-point type!", IF);
6375 Check(ResultTy->getElementType() == Op0ElemTy,
6376 "Vector element type mismatch of the result and first operand "
6381 Check(ResultTy->getElementType() == Op1ElemTy,
6382 "Vector element type mismatch of the result and second operand "
6388 "Result of a matrix operation does not fit in the returned vector!");
6392 "Stride must be greater or equal than the number of rows!", IF);
6396 case Intrinsic::vector_splice: {
6398 int64_t
Idx = cast<ConstantInt>(
Call.getArgOperand(2))->getSExtValue();
6399 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
6400 if (
Call.getParent() &&
Call.getParent()->getParent()) {
6402 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
6403 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
6405 Check((
Idx < 0 && std::abs(
Idx) <= KnownMinNumElements) ||
6406 (
Idx >= 0 &&
Idx < KnownMinNumElements),
6407 "The splice index exceeds the range [-VL, VL-1] where VL is the "
6408 "known minimum number of elements in the vector. For scalable "
6409 "vectors the minimum number of elements is determined from "
6414 case Intrinsic::stepvector: {
6416 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
6417 VecTy->getScalarSizeInBits() >= 8,
6418 "stepvector only supported for vectors of integers "
6419 "with a bitwidth of at least 8.",
6423 case Intrinsic::experimental_vector_match: {
6432 Check(Op1Ty && Op2Ty && MaskTy,
"Operands must be vectors.", &Call);
6433 Check(isa<FixedVectorType>(Op2Ty),
6434 "Second operand must be a fixed length vector.", &Call);
6435 Check(Op1Ty->getElementType()->isIntegerTy(),
6436 "First operand must be a vector of integers.", &Call);
6437 Check(Op1Ty->getElementType() == Op2Ty->getElementType(),
6438 "First two operands must have the same element type.", &Call);
6439 Check(Op1Ty->getElementCount() == MaskTy->getElementCount(),
6440 "First operand and mask must have the same number of elements.",
6442 Check(MaskTy->getElementType()->isIntegerTy(1),
6443 "Mask must be a vector of i1's.", &Call);
6444 Check(
Call.getType() == MaskTy,
"Return type must match the mask type.",
6448 case Intrinsic::vector_insert: {
6452 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6459 Check(VecTy->getElementType() == SubVecTy->getElementType(),
6460 "vector_insert parameters must have the same element "
6464 "vector_insert index must be a constant multiple of "
6465 "the subvector's known minimum vector length.");
6473 "subvector operand of vector_insert would overrun the "
6474 "vector being inserted into.");
6478 case Intrinsic::vector_extract: {
6481 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6489 Check(ResultTy->getElementType() == VecTy->getElementType(),
6490 "vector_extract result must have the same element "
6491 "type as the input vector.",
6494 "vector_extract index must be a constant multiple of "
6495 "the result type's known minimum vector length.");
6503 "vector_extract would overrun.");
6507 case Intrinsic::experimental_vector_partial_reduce_add: {
6508 VectorType *AccTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
6509 VectorType *VecTy = cast<VectorType>(
Call.getArgOperand(1)->getType());
6511 unsigned VecWidth = VecTy->getElementCount().getKnownMinValue();
6512 unsigned AccWidth = AccTy->getElementCount().getKnownMinValue();
6514 Check((VecWidth % AccWidth) == 0,
6515 "Invalid vector widths for partial "
6516 "reduction. The width of the input vector "
6517 "must be a positive integer multiple of "
6518 "the width of the accumulator vector.");
6521 case Intrinsic::experimental_noalias_scope_decl: {
6522 NoAliasScopeDecls.
push_back(cast<IntrinsicInst>(&Call));
6525 case Intrinsic::preserve_array_access_index:
6526 case Intrinsic::preserve_struct_access_index:
6527 case Intrinsic::aarch64_ldaxr:
6528 case Intrinsic::aarch64_ldxr:
6529 case Intrinsic::arm_ldaex:
6530 case Intrinsic::arm_ldrex: {
6531 Type *ElemTy =
Call.getParamElementType(0);
6532 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
6536 case Intrinsic::aarch64_stlxr:
6537 case Intrinsic::aarch64_stxr:
6538 case Intrinsic::arm_stlex:
6539 case Intrinsic::arm_strex: {
6540 Type *ElemTy =
Call.getAttributes().getParamElementType(1);
6542 "Intrinsic requires elementtype attribute on second argument.",
6546 case Intrinsic::aarch64_prefetch: {
6547 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
6548 "write argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6549 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
6550 "target argument to llvm.aarch64.prefetch must be 0-3", Call);
6551 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
6552 "stream argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6553 Check(cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue() < 2,
6554 "isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6557 case Intrinsic::callbr_landingpad: {
6558 const auto *CBR = dyn_cast<CallBrInst>(
Call.getOperand(0));
6559 Check(CBR,
"intrinstic requires callbr operand", &Call);
6566 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &Call);
6570 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
6575 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
6576 "block in indirect destination list",
6579 Check(&
First == &Call,
"No other instructions may proceed intrinsic",
6583 case Intrinsic::amdgcn_cs_chain: {
6584 auto CallerCC =
Call.getCaller()->getCallingConv();
6591 CheckFailed(
"Intrinsic can only be used from functions with the "
6592 "amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6593 "calling conventions",
6598 Check(
Call.paramHasAttr(2, Attribute::InReg),
6599 "SGPR arguments must have the `inreg` attribute", &Call);
6600 Check(!
Call.paramHasAttr(3, Attribute::InReg),
6601 "VGPR arguments must not have the `inreg` attribute", &Call);
6603 auto *Next =
Call.getNextNode();
6604 bool IsAMDUnreachable = Next && isa<IntrinsicInst>(Next) &&
6605 cast<IntrinsicInst>(Next)->getIntrinsicID() ==
6606 Intrinsic::amdgcn_unreachable;
6607 Check(Next && (isa<UnreachableInst>(Next) || IsAMDUnreachable),
6608 "llvm.amdgcn.cs.chain must be followed by unreachable", &Call);
6611 case Intrinsic::amdgcn_init_exec_from_input: {
6612 const Argument *Arg = dyn_cast<Argument>(
Call.getOperand(0));
6614 "only inreg arguments to the parent function are valid as inputs to "
6619 case Intrinsic::amdgcn_set_inactive_chain_arg: {
6620 auto CallerCC =
Call.getCaller()->getCallingConv();
6626 CheckFailed(
"Intrinsic can only be used from functions with the "
6627 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6628 "calling conventions",
6633 unsigned InactiveIdx = 1;
6634 Check(!
Call.paramHasAttr(InactiveIdx, Attribute::InReg),
6635 "Value for inactive lanes must not have the `inreg` attribute",
6637 Check(isa<Argument>(
Call.getArgOperand(InactiveIdx)),
6638 "Value for inactive lanes must be a function argument", &Call);
6639 Check(!cast<Argument>(
Call.getArgOperand(InactiveIdx))->hasInRegAttr(),
6640 "Value for inactive lanes must be a VGPR function argument", &Call);
6643 case Intrinsic::amdgcn_call_whole_wave: {
6644 auto F = dyn_cast<Function>(
Call.getArgOperand(0));
6645 Check(
F,
"Indirect whole wave calls are not allowed", &Call);
6649 "Callee must have the amdgpu_gfx_whole_wave calling convention",
6652 Check(!
F->isVarArg(),
"Variadic whole wave calls are not allowed", &Call);
6655 "Call argument count must match callee argument count", &Call);
6659 Check(
F->arg_begin()->getType()->isIntegerTy(1),
6660 "Callee must have i1 as its first argument", &Call);
6661 for (
auto [CallArg, FuncArg] :
6663 Check(CallArg->getType() == FuncArg.getType(),
6664 "Argument types must match", &Call);
6667 Check(
Call.paramHasAttr(FuncArg.getArgNo(), Attribute::InReg) ==
6668 FuncArg.hasInRegAttr(),
6669 "Argument inreg attributes must match", &Call);
6673 case Intrinsic::amdgcn_s_prefetch_data: {
6676 Call.getArgOperand(0)->getType()->getPointerAddressSpace()),
6677 "llvm.amdgcn.s.prefetch.data only supports global or constant memory");
6680 case Intrinsic::amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
6681 case Intrinsic::amdgcn_mfma_scale_f32_32x32x64_f8f6f4: {
6685 uint64_t CBSZ = cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue();
6686 uint64_t BLGP = cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue();
6687 Check(CBSZ <= 4,
"invalid value for cbsz format", Call,
6688 Call.getArgOperand(3));
6689 Check(BLGP <= 4,
"invalid value for blgp format", Call,
6690 Call.getArgOperand(4));
6693 auto getFormatNumRegs = [](
unsigned FormatVal) {
6694 switch (FormatVal) {
6709 if (!Ty || !Ty->getElementType()->
isIntegerTy(32))
6711 unsigned NumElts = Ty->getNumElements();
6712 return NumElts == 4 || NumElts == 6 || NumElts == 8;
6715 auto *Src0Ty = dyn_cast<FixedVectorType>(Src0->
getType());
6716 auto *Src1Ty = dyn_cast<FixedVectorType>(Src1->
getType());
6717 Check(isValidSrcASrcBVector(Src0Ty),
6718 "operand 0 must be 4, 6 or 8 element i32 vector", &Call, Src0);
6719 Check(isValidSrcASrcBVector(Src1Ty),
6720 "operand 1 must be 4, 6 or 8 element i32 vector", &Call, Src1);
6723 Check(Src0Ty->getNumElements() >= getFormatNumRegs(CBSZ),
6724 "invalid vector type for format", &Call, Src0,
Call.getArgOperand(3));
6725 Check(Src1Ty->getNumElements() >= getFormatNumRegs(BLGP),
6726 "invalid vector type for format", &Call, Src1,
Call.getArgOperand(5));
6729 case Intrinsic::amdgcn_wmma_f32_16x16x128_f8f6f4:
6730 case Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4:
6731 case Intrinsic::amdgcn_wmma_scale16_f32_16x16x128_f8f6f4: {
6735 unsigned FmtA = cast<ConstantInt>(
Call.getArgOperand(0))->getZExtValue();
6736 unsigned FmtB = cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue();
6737 Check(FmtA <= 4,
"invalid value for matrix format", Call,
6738 Call.getArgOperand(0));
6739 Check(FmtB <= 4,
"invalid value for matrix format", Call,
6740 Call.getArgOperand(2));
6743 auto getFormatNumRegs = [](
unsigned FormatVal) {
6744 switch (FormatVal) {
6759 if (!Ty || !Ty->getElementType()->
isIntegerTy(32))
6761 unsigned NumElts = Ty->getNumElements();
6762 return NumElts == 16 || NumElts == 12 || NumElts == 8;
6765 auto *Src0Ty = dyn_cast<FixedVectorType>(Src0->
getType());
6766 auto *Src1Ty = dyn_cast<FixedVectorType>(Src1->
getType());
6767 Check(isValidSrcASrcBVector(Src0Ty),
6768 "operand 1 must be 8, 12 or 16 element i32 vector", &Call, Src0);
6769 Check(isValidSrcASrcBVector(Src1Ty),
6770 "operand 3 must be 8, 12 or 16 element i32 vector", &Call, Src1);
6773 Check(Src0Ty->getNumElements() >= getFormatNumRegs(FmtA),
6774 "invalid vector type for format", &Call, Src0,
Call.getArgOperand(0));
6775 Check(Src1Ty->getNumElements() >= getFormatNumRegs(FmtB),
6776 "invalid vector type for format", &Call, Src1,
Call.getArgOperand(2));
6779 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
6780 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
6782 unsigned RegCount = cast<ConstantInt>(V)->getZExtValue();
6783 Check(RegCount % 8 == 0,
6784 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6787 case Intrinsic::experimental_convergence_entry:
6788 case Intrinsic::experimental_convergence_anchor:
6790 case Intrinsic::experimental_convergence_loop:
6792 case Intrinsic::ptrmask: {
6793 Type *Ty0 =
Call.getArgOperand(0)->getType();
6794 Type *Ty1 =
Call.getArgOperand(1)->getType();
6796 "llvm.ptrmask intrinsic first argument must be pointer or vector "
6801 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
6804 Check(cast<VectorType>(Ty0)->getElementCount() ==
6805 cast<VectorType>(Ty1)->getElementCount(),
6806 "llvm.ptrmask intrinsic arguments must have the same number of "
6810 "llvm.ptrmask intrinsic second argument bitwidth must match "
6811 "pointer index type size of first argument",
6815 case Intrinsic::thread_pointer: {
6816 Check(
Call.getType()->getPointerAddressSpace() ==
6817 DL.getDefaultGlobalsAddressSpace(),
6818 "llvm.thread.pointer intrinsic return type must be for the globals "
6823 case Intrinsic::threadlocal_address: {
6824 const Value &Arg0 = *
Call.getArgOperand(0);
6825 Check(isa<GlobalValue>(Arg0),
6826 "llvm.threadlocal.address first argument must be a GlobalValue");
6827 Check(cast<GlobalValue>(Arg0).isThreadLocal(),
6828 "llvm.threadlocal.address operand isThreadLocal() must be true");
6831 case Intrinsic::lifetime_start:
6832 case Intrinsic::lifetime_end: {
6834 Check(isa<AllocaInst>(
Ptr) || isa<PoisonValue>(
Ptr),
6835 "llvm.lifetime.start/end can only be used on alloca or poison",
6844 if (
F->hasPersonalityFn() &&
6848 if (BlockEHFuncletColors.
empty())
6852 bool InEHFunclet =
false;
6857 if (
auto It = ColorFirstBB->getFirstNonPHIIt();
6858 It != ColorFirstBB->end())
6859 if (isa_and_nonnull<FuncletPadInst>(&*It))
6863 bool HasToken =
false;
6864 for (
unsigned I = 0, E =
Call.getNumOperandBundles();
I != E; ++
I)
6870 Check(HasToken,
"Missing funclet token on intrinsic call", &Call);
6883 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
6886 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
6890 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
6896 "invalid #dbg_label intrinsic variable", &DLR, DLR.
getRawLabel());
6900 if (!isa<DILocation>(
N))
6909 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DLR, BB,
F);
6913 if (!LabelSP || !LocSP)
6917 "mismatched subprogram between #dbg_label label and !dbg attachment",
6918 &DLR, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6919 Loc->getScope()->getSubprogram());
6929 "invalid #dbg record type", &DVR, DVR.
getType(), BB,
F);
6935 CheckDI(MD && (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6936 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands())),
6937 "invalid #dbg record address/value", &DVR, MD, BB,
F);
6938 if (
auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
6939 visitValueAsMetadata(*VAM,
F);
6942 Type *Ty = VAM->getValue()->getType();
6944 "location of #dbg_declare must be a pointer or int", &DVR, MD, BB,
6947 }
else if (
auto *AL = dyn_cast<DIArgList>(MD)) {
6948 visitDIArgList(*AL,
F);
6962 "invalid #dbg_assign DIAssignID", &DVR, DVR.
getRawAssignID(), BB,
6965 AreDebugLocsAllowed::No);
6972 isa<ValueAsMetadata>(RawAddr) ||
6973 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6974 "invalid #dbg_assign address", &DVR, DVR.
getRawAddress(), BB,
F);
6975 if (
auto *VAM = dyn_cast<ValueAsMetadata>(RawAddr))
6976 visitValueAsMetadata(*VAM,
F);
6979 "invalid #dbg_assign address expression", &DVR,
6986 "inst not in same function as #dbg_assign",
I, &DVR, BB,
F);
6995 CheckDI(isa_and_nonnull<DILocation>(DLNode),
"invalid #dbg record DILocation",
6996 &DVR, DLNode, BB,
F);
7002 if (!VarSP || !LocSP)
7006 "mismatched subprogram between #dbg record variable and DILocation",
7008 Loc->getScope()->getSubprogram(), BB,
F);
7013void Verifier::visitVPIntrinsic(
VPIntrinsic &VPI) {
7014 if (
auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
7015 auto *
RetTy = cast<VectorType>(VPCast->getType());
7016 auto *ValTy = cast<VectorType>(VPCast->getOperand(0)->getType());
7017 Check(
RetTy->getElementCount() == ValTy->getElementCount(),
7018 "VP cast intrinsic first argument and result vector lengths must be "
7022 switch (VPCast->getIntrinsicID()) {
7025 case Intrinsic::vp_trunc:
7027 "llvm.vp.trunc intrinsic first argument and result element type "
7031 "llvm.vp.trunc intrinsic the bit size of first argument must be "
7032 "larger than the bit size of the return type",
7035 case Intrinsic::vp_zext:
7036 case Intrinsic::vp_sext:
7038 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
7039 "element type must be integer",
7042 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
7043 "argument must be smaller than the bit size of the return type",
7046 case Intrinsic::vp_fptoui:
7047 case Intrinsic::vp_fptosi:
7048 case Intrinsic::vp_lrint:
7049 case Intrinsic::vp_llrint:
7052 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
7053 "type must be floating-point and result element type must be integer",
7056 case Intrinsic::vp_uitofp:
7057 case Intrinsic::vp_sitofp:
7060 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
7061 "type must be integer and result element type must be floating-point",
7064 case Intrinsic::vp_fptrunc:
7066 "llvm.vp.fptrunc intrinsic first argument and result element type "
7067 "must be floating-point",
7070 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
7071 "larger than the bit size of the return type",
7074 case Intrinsic::vp_fpext:
7076 "llvm.vp.fpext intrinsic first argument and result element type "
7077 "must be floating-point",
7080 "llvm.vp.fpext intrinsic the bit size of first argument must be "
7081 "smaller than the bit size of the return type",
7084 case Intrinsic::vp_ptrtoint:
7086 "llvm.vp.ptrtoint intrinsic first argument element type must be "
7087 "pointer and result element type must be integer",
7090 case Intrinsic::vp_inttoptr:
7092 "llvm.vp.inttoptr intrinsic first argument element type must be "
7093 "integer and result element type must be pointer",
7100 case Intrinsic::vp_fcmp: {
7101 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
7103 "invalid predicate for VP FP comparison intrinsic", &VPI);
7106 case Intrinsic::vp_icmp: {
7107 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
7109 "invalid predicate for VP integer comparison intrinsic", &VPI);
7112 case Intrinsic::vp_is_fpclass: {
7113 auto TestMask = cast<ConstantInt>(VPI.
getOperand(1));
7115 "unsupported bits for llvm.vp.is.fpclass test mask");
7118 case Intrinsic::experimental_vp_splice: {
7121 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
7124 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
7125 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
7127 Check((
Idx < 0 && std::abs(
Idx) <= KnownMinNumElements) ||
7128 (
Idx >= 0 &&
Idx < KnownMinNumElements),
7129 "The splice index exceeds the range [-VL, VL-1] where VL is the "
7130 "known minimum number of elements in the vector. For scalable "
7131 "vectors the minimum number of elements is determined from "
7141 bool HasRoundingMD =
7145 NumOperands += (1 + HasRoundingMD);
7148 if (isa<ConstrainedFPCmpIntrinsic>(FPI))
7151 "invalid arguments for constrained FP intrinsic", &FPI);
7154 case Intrinsic::experimental_constrained_lrint:
7155 case Intrinsic::experimental_constrained_llrint: {
7159 "Intrinsic does not support vectors", &FPI);
7163 case Intrinsic::experimental_constrained_lround:
7164 case Intrinsic::experimental_constrained_llround: {
7168 "Intrinsic does not support vectors", &FPI);
7172 case Intrinsic::experimental_constrained_fcmp:
7173 case Intrinsic::experimental_constrained_fcmps: {
7174 auto Pred = cast<ConstrainedFPCmpIntrinsic>(&FPI)->getPredicate();
7176 "invalid predicate for constrained FP comparison intrinsic", &FPI);
7180 case Intrinsic::experimental_constrained_fptosi:
7181 case Intrinsic::experimental_constrained_fptoui: {
7185 "Intrinsic first argument must be floating point", &FPI);
7186 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
7187 SrcEC = cast<VectorType>(OperandT)->getElementCount();
7192 "Intrinsic first argument and result disagree on vector use", &FPI);
7194 "Intrinsic result must be an integer", &FPI);
7195 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
7196 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
7197 "Intrinsic first argument and result vector lengths must be equal",
7203 case Intrinsic::experimental_constrained_sitofp:
7204 case Intrinsic::experimental_constrained_uitofp: {
7208 "Intrinsic first argument must be integer", &FPI);
7209 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
7210 SrcEC = cast<VectorType>(OperandT)->getElementCount();
7215 "Intrinsic first argument and result disagree on vector use", &FPI);
7217 "Intrinsic result must be a floating point", &FPI);
7218 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
7219 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
7220 "Intrinsic first argument and result vector lengths must be equal",
7226 case Intrinsic::experimental_constrained_fptrunc:
7227 case Intrinsic::experimental_constrained_fpext: {
7233 "Intrinsic first argument must be FP or FP vector", &FPI);
7235 "Intrinsic result must be FP or FP vector", &FPI);
7237 "Intrinsic first argument and result disagree on vector use", &FPI);
7239 Check(cast<VectorType>(OperandTy)->getElementCount() ==
7240 cast<VectorType>(ResultTy)->getElementCount(),
7241 "Intrinsic first argument and result vector lengths must be equal",
7244 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
7246 "Intrinsic first argument's type must be larger than result type",
7250 "Intrinsic first argument's type must be smaller than result type",
7266 "invalid exception behavior argument", &FPI);
7267 if (HasRoundingMD) {
7278 if (!V || !E || !E->
isValid())
7292 if (
V->isArtificial())
7295 verifyFragmentExpression(*V, *Fragment, &DVR);
7298template <
typename ValueOrMetadata>
7299void Verifier::verifyFragmentExpression(
const DIVariable &V,
7301 ValueOrMetadata *
Desc) {
7304 auto VarSize =
V.getSizeInBits();
7310 CheckDI(FragSize + FragOffset <= *VarSize,
7311 "fragment is larger than or outside of variable",
Desc, &V);
7312 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
7327 CheckDI(Var,
"#dbg record without variable");
7329 unsigned ArgNo = Var->
getArg();
7335 if (DebugFnArgs.
size() < ArgNo)
7336 DebugFnArgs.
resize(ArgNo,
nullptr);
7338 auto *Prev = DebugFnArgs[ArgNo - 1];
7339 DebugFnArgs[ArgNo - 1] = Var;
7340 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DVR,
7353 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
7357 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
7358 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
7363 "Entry values are only allowed in MIR unless they target a "
7364 "swiftasync Argument",
7368void Verifier::verifyCompileUnits() {
7372 if (
M.getContext().isODRUniquingDebugTypes())
7374 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
7378 for (
const auto *
CU : CUVisited)
7383void Verifier::verifyDeoptimizeCallingConvs() {
7384 if (DeoptimizeDeclarations.
empty())
7388 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
7389 Check(
First->getCallingConv() ==
F->getCallingConv(),
7390 "All llvm.experimental.deoptimize declarations must have the same "
7391 "calling convention",
7396void Verifier::verifyAttachedCallBundle(
const CallBase &Call,
7400 Check((FTy->getReturnType()->isPointerTy() ||
7401 (
Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())),
7402 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
7403 "function returning a pointer or a non-returning function that has a "
7408 "operand bundle \"clang.arc.attachedcall\" requires one function as "
7412 auto *Fn = cast<Function>(BU.
Inputs.front());
7416 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
7417 IID == Intrinsic::objc_claimAutoreleasedReturnValue ||
7418 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
7419 "invalid function argument", Call);
7422 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
7423 FnName ==
"objc_claimAutoreleasedReturnValue" ||
7424 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
7425 "invalid function argument", Call);
7429void Verifier::verifyNoAliasScopeDecl() {
7430 if (NoAliasScopeDecls.
empty())
7434 for (
auto *
II : NoAliasScopeDecls) {
7435 assert(
II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
7436 "Not a llvm.experimental.noalias.scope.decl ?");
7437 const auto *ScopeListMV = dyn_cast<MetadataAsValue>(
7439 Check(ScopeListMV !=
nullptr,
7440 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
7444 const auto *ScopeListMD = dyn_cast<MDNode>(ScopeListMV->getMetadata());
7445 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode",
II);
7446 Check(ScopeListMD->getNumOperands() == 1,
7447 "!id.scope.list must point to a list with a single scope",
II);
7448 visitAliasScopeListMetadata(ScopeListMD);
7459 const auto *ScopeListMV = cast<MetadataAsValue>(
7461 return &cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
7467 return GetScope(Lhs) < GetScope(Rhs);
7474 auto ItCurrent = NoAliasScopeDecls.begin();
7475 while (ItCurrent != NoAliasScopeDecls.end()) {
7476 auto CurScope = GetScope(*ItCurrent);
7477 auto ItNext = ItCurrent;
7480 }
while (ItNext != NoAliasScopeDecls.end() &&
7481 GetScope(*ItNext) == CurScope);
7486 if (ItNext - ItCurrent < 32)
7491 "llvm.experimental.noalias.scope.decl dominates another one "
7492 "with the same scope",
7510 return !V.verify(
F);
7514 bool *BrokenDebugInfo) {
7518 bool Broken =
false;
7520 Broken |= !V.verify(
F);
7522 Broken |= !V.verify();
7523 if (BrokenDebugInfo)
7524 *BrokenDebugInfo = V.hasBrokenDebugInfo();
7535 std::unique_ptr<Verifier> V;
7536 bool FatalErrors =
true;
7541 explicit VerifierLegacyPass(
bool FatalErrors)
7543 FatalErrors(FatalErrors) {
7547 bool doInitialization(
Module &M)
override {
7548 V = std::make_unique<Verifier>(
7554 if (!
V->verify(
F) && FatalErrors) {
7555 errs() <<
"in function " <<
F.getName() <<
'\n';
7561 bool doFinalization(
Module &M)
override {
7562 bool HasErrors =
false;
7564 if (
F.isDeclaration())
7565 HasErrors |= !
V->verify(
F);
7567 HasErrors |= !
V->verify();
7568 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
7581template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
7586#define CheckTBAA(C, ...) \
7589 CheckFailed(__VA_ARGS__); \
7597TBAAVerifier::TBAABaseNodeSummary
7601 CheckFailed(
"Base nodes must have at least two operands", &
I, BaseNode);
7605 auto Itr = TBAABaseNodes.find(BaseNode);
7606 if (Itr != TBAABaseNodes.end())
7609 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
7610 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
7612 assert(InsertResult.second &&
"We just checked!");
7616TBAAVerifier::TBAABaseNodeSummary
7619 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
7623 return isValidScalarTBAANode(BaseNode)
7624 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
7630 CheckFailed(
"Access tag nodes must have the number of operands that is a "
7631 "multiple of 3!", BaseNode);
7636 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
7644 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7646 if (!TypeSizeNode) {
7647 CheckFailed(
"Type size nodes must be constants!", &
I, BaseNode);
7653 if (!IsNewFormat && !isa<MDString>(BaseNode->
getOperand(0))) {
7654 CheckFailed(
"Struct tag nodes have a string as their first operand",
7661 std::optional<APInt> PrevOffset;
7666 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7667 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7669 Idx += NumOpsPerField) {
7672 if (!isa<MDNode>(FieldTy)) {
7673 CheckFailed(
"Incorrect field entry in struct type node!", &
I, BaseNode);
7678 auto *OffsetEntryCI =
7679 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
7680 if (!OffsetEntryCI) {
7681 CheckFailed(
"Offset entries must be constants!", &
I, BaseNode);
7687 BitWidth = OffsetEntryCI->getBitWidth();
7689 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
7691 "Bitwidth between the offsets and struct type entries must match", &
I,
7703 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
7706 CheckFailed(
"Offsets must be increasing!", &
I, BaseNode);
7710 PrevOffset = OffsetEntryCI->getValue();
7713 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7715 if (!MemberSizeNode) {
7716 CheckFailed(
"Member size entries must be constants!", &
I, BaseNode);
7723 return Failed ? InvalidNode
7724 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
7745 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
7746 return Parent && Visited.
insert(Parent).second &&
7750bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
7751 auto ResultIt = TBAAScalarNodes.find(MD);
7752 if (ResultIt != TBAAScalarNodes.end())
7753 return ResultIt->second;
7757 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
7759 assert(InsertResult.second &&
"Just checked!");
7778 return cast<MDNode>(BaseNode->
getOperand(1));
7780 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7781 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7783 Idx += NumOpsPerField) {
7784 auto *OffsetEntryCI =
7785 mdconst::extract<ConstantInt>(BaseNode->
getOperand(
Idx + 1));
7786 if (OffsetEntryCI->getValue().ugt(
Offset)) {
7787 if (
Idx == FirstFieldOpNo) {
7788 CheckFailed(
"Could not find TBAA parent in struct type node", &
I,
7793 unsigned PrevIdx =
Idx - NumOpsPerField;
7794 auto *PrevOffsetEntryCI =
7795 mdconst::extract<ConstantInt>(BaseNode->
getOperand(PrevIdx + 1));
7796 Offset -= PrevOffsetEntryCI->getValue();
7797 return cast<MDNode>(BaseNode->
getOperand(PrevIdx));
7802 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
7804 Offset -= LastOffsetEntryCI->getValue();
7805 return cast<MDNode>(BaseNode->
getOperand(LastIdx));
7809 if (!
Type ||
Type->getNumOperands() < 3)
7814 return isa_and_nonnull<MDNode>(
Type->getOperand(0));
7821 CheckTBAA(isa<LoadInst>(
I) || isa<StoreInst>(
I) || isa<CallInst>(
I) ||
7822 isa<VAArgInst>(
I) || isa<AtomicRMWInst>(
I) ||
7823 isa<AtomicCmpXchgInst>(
I),
7824 "This instruction shall not have a TBAA access tag!", &
I);
7826 bool IsStructPathTBAA =
7830 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
7840 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
7843 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
7848 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7850 CheckTBAA(AccessSizeNode,
"Access size field must be a constant", &
I, MD);
7854 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
7856 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
7859 "Immutability tag on struct tag metadata must be a constant", &
I,
7862 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
7863 "Immutability part of the struct tag metadata must be either 0 or 1",
7868 "Malformed struct tag metadata: base and access-type "
7869 "should be non-null and point to Metadata nodes",
7870 &
I, MD, BaseNode, AccessType);
7873 CheckTBAA(isValidScalarTBAANode(AccessType),
7874 "Access type node must be a valid scalar type", &
I, MD,
7878 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
7879 CheckTBAA(OffsetCI,
"Offset must be constant integer", &
I, MD);
7882 bool SeenAccessTypeInPath =
false;
7887 BaseNode = getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset,
7889 if (!StructPath.
insert(BaseNode).second) {
7890 CheckFailed(
"Cycle detected in struct path", &
I, MD);
7895 unsigned BaseNodeBitWidth;
7896 std::tie(
Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(
I, BaseNode,
7904 SeenAccessTypeInPath |= BaseNode == AccessType;
7906 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
7907 CheckTBAA(
Offset == 0,
"Offset not zero at the point of scalar access",
7911 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
7912 (IsNewFormat && BaseNodeBitWidth == ~0u),
7913 "Access bit-width not the same as description bit-width", &
I, MD,
7914 BaseNodeBitWidth,
Offset.getBitWidth());
7916 if (IsNewFormat && SeenAccessTypeInPath)
7920 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!", &
I,
7925char VerifierLegacyPass::ID = 0;
7926INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
7929 return new VerifierLegacyPass(FatalErrors);
7947 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
7955 if (res.IRBroken && FatalErrors)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU address space definition.
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
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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.
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
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)
#define Check(C,...)
We know that cond should be true, if not print an error message.
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 DISubprogram * getSubprogram(Metadata *LocalScope)
Carefully grab the subprogram from a local scope.
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 bool isContiguous(const ConstantRange &A, const ConstantRange &B)
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.
an instruction to allocate memory on the stack
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.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class represents an incoming formal argument to a Function.
LLVM_ABI bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
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
static LLVM_ABI Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static LLVM_ABI bool canUseAsRetAttr(AttrKind Kind)
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
static LLVM_ABI bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
static LLVM_ABI bool canUseAsFnAttr(AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
static bool isIntAttrKind(AttrKind Kind)
static LLVM_ABI bool canUseAsParamAttr(AttrKind Kind)
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.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
const Instruction & front() const
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
Conditional or Unconditional Branch instruction.
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.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
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...
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
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)
ConstantArray - Constant Array Declarations.
A constant value that is initialized with an expression using other constant values.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
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.
A signed pointer, in the ptrauth sense.
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.
This is an important base class in LLVM.
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
This is the common base class for constrained floating point intrinsics.
LLVM_ABI std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
LLVM_ABI std::optional< RoundingMode > getRoundingMode() const
LLVM_ABI unsigned getNonMetadataArgCount() const
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
static LLVM_ABI std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
LLVM_ABI bool isValid() const
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
A pair of DIGlobalVariable and DIExpression.
DIGlobalVariable * getVariable() const
DIExpression * getExpression() const
An imported module (C++ using directive or similar).
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata * getRawScope() const
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Tagged DWARF-like metadata node.
Base class for scope-like contexts.
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
Type array for a subprogram.
Base class for template parameters.
Base class for variables.
Metadata * getRawType() const
Metadata * getRawScope() const
This class represents an Operation in the Expression.
uint64_t getNumOperands() const
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.label instruction.
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)
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
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.
An instruction for ordering other memory operations.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Class to represent fixed width SIMD vectors.
Value * getParentPad() const
Convenience accessors.
FunctionPass class - This class is used to implement most global optimizations.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool hasPersonalityFn() const
Check whether this function has a personality function.
const std::string & getGC() const
Represents calls to the gc.relocate intrinsic.
LLVM_ABI Value * getBasePtr() const
LLVM_ABI Value * getDerivedPtr() const
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
void verify(const DominatorTreeT &DT)
void visit(const BlockT &BB)
Generic tagged DWARF-like metadata node.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
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.
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.
Indirect Branch Instruction.
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.
This instruction inserts a struct field of array element value into an aggregate value.
Value * getAggregateOperand()
ArrayRef< unsigned > getIndices() const
Base class for instruction visitors.
RetTy visitTerminator(Instruction &I)
RetTy visitCallBase(CallBase &I)
void visitFunction(Function &F)
void visitBasicBlock(BasicBlock &BB)
void visit(Iterator Start, Iterator End)
RetTy visitFuncletPadInst(FuncletPadInst &I)
void visitInstruction(Instruction &I)
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
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.
A wrapper class for inspecting calls to intrinsic functions.
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
The landingpad instruction holds all of the information necessary to generate correct exception handl...
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.
An instruction for reading from memory.
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
Tracking metadata reference owned by Metadata.
LLVM_ABI StringRef getString() const
Typed, array-like tuple of metadata.
This class implements a map that also provides access to all stored values in a deterministic order.
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
@ Warning
Emits a warning if two values disagree.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
@ Min
Takes the min of the two values, which are required to be integers.
@ Append
Appends the two values, which are required to be metadata nodes.
@ Max
Takes the max of the two values, which are required to be integers.
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.
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...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
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.
Simple wrapper around std::function<void(raw_ostream&)>.
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.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Resume the propagation of an exception.
Value * getValue() const
Convenience accessor.
Return a value (possibly void), from a function.
This class represents a sign extension of integer types.
This class represents a cast from signed integer to floating point.
This class represents the LLVM 'select' instruction.
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.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
An instruction for storing to memory.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
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.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
static constexpr size_t npos
Class to represent struct types.
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.
Verify that the TBAA Metadatas are valid.
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.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
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 canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
bool isArrayTy() const
True if this is an instance of ArrayType.
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.
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...
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
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.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isTokenLikeTy() const
Returns true if this is 'token' or a token-like target type.s.
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.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element 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.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isMetadataTy() const
Return true if this is 'metadata'.
This class represents a cast unsigned integer to floating point.
A Use represents the edge between a Value definition and its users.
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...
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
iterator_range< user_iterator > materialized_users()
Type * getType() const
All values are typed, get the type of this value.
static constexpr uint64_t MaximumAlignment
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
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 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.
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool isFlatGlobalAddrSpace(unsigned AS)
LLVM_ABI AttributeMask typeIncompatible(Type *Ty, AttributeSet AS, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
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.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ X86_INTR
x86 hardware interrupt context.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ C
The default llvm calling convention, compatible with C.
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 "Constrained Floating-Point Intrinsics" that take ...
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...
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.
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.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
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 isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
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)
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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.
@ ArgMem
Access to memory via argument pointers.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI FunctionPass * createVerifierPass(bool FatalErrors=true)
@ Dynamic
Denotes mode unknown at compile time.
@ MaskAll
A bitmask that includes all valid flags.
constexpr unsigned BitWidth
DenormalMode parseDenormalFPAttribute(StringRef Str)
Returns the denormal mode to use for inputs and outputs.
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)
LLVM_ABI bool isExplicitlyUnknownBranchWeightsMetadata(const MDNode &MD)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
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.
static LLVM_ABI const fltSemantics & IEEEsingle() LLVM_READNONE
This struct is a compact representation of a valid (non-zero power of two) alignment.
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...
Description of the encoding of one expression Op.
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
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
A lightweight accessor for an operand bundle meant to be passed around by value.
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).