97#include "llvm/IR/IntrinsicsAArch64.h"
98#include "llvm/IR/IntrinsicsAMDGPU.h"
99#include "llvm/IR/IntrinsicsARM.h"
100#include "llvm/IR/IntrinsicsNVPTX.h"
101#include "llvm/IR/IntrinsicsWebAssembly.h"
136 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
137 "scopes are not dominating"));
165 void Write(
const Value *V) {
170 void Write(
const Value &V) {
171 if (isa<Instruction>(V)) {
175 V.printAsOperand(*
OS,
true,
MST);
225 void Write(
Type *
T) {
237 void Write(
const APInt *AI) {
243 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
249 *
OS <<
A->getAsString() <<
'\n';
269 for (
const T &V : Vs)
273 template <
typename T1,
typename... Ts>
274 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
279 template <
typename... Ts>
void WriteTs() {}
288 *
OS << Message <<
'\n';
296 template <
typename T1,
typename... Ts>
306 *
OS << Message <<
'\n';
312 template <
typename T1,
typename... Ts>
346 Type *LandingPadResultTy;
353 bool HasDebugInfo =
false;
396 SawFrameEscape(
false), TBAAVerifyHelper(this) {
397 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
404 "An instance of this class only works with a specific module!");
413 DT.recalculate(
const_cast<Function &
>(
F));
416 if (!BB.empty() && BB.back().isTerminator())
420 *
OS <<
"Basic Block in function '" <<
F.getName()
421 <<
"' does not have terminator!\n";
422 BB.printAsOperand(*
OS,
true, MST);
428 auto FailureCB = [
this](
const Twine &Message) {
436 verifySiblingFuncletUnwinds();
439 ConvergenceVerifyHelper.
verify(DT);
441 InstsInThisBlock.
clear();
443 LandingPadResultTy =
nullptr;
444 SawFrameEscape =
false;
445 SiblingFuncletInfo.
clear();
446 verifyNoAliasScopeDecl();
447 NoAliasScopeDecls.
clear();
458 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
463 verifyFrameRecoverIndices();
465 visitGlobalVariable(GV);
468 visitGlobalAlias(GA);
471 visitGlobalIFunc(GI);
474 visitNamedMDNode(NMD);
477 visitComdat(SMEC.getValue());
481 visitModuleCommandLines();
483 verifyCompileUnits();
485 verifyDeoptimizeCallingConvs();
486 DISubprogramAttachments.
clear();
492 enum class AreDebugLocsAllowed {
No,
Yes };
503 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
507 void visitComdat(
const Comdat &
C);
508 void visitModuleIdents();
509 void visitModuleCommandLines();
510 void visitModuleFlags();
511 void visitModuleFlag(
const MDNode *
Op,
514 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
518 bool IsAbsoluteSymbol);
522 void visitCallStackMetadata(
MDNode *MD);
527 void visitAnnotationMetadata(
MDNode *Annotation);
528 void visitAliasScopeMetadata(
const MDNode *MD);
529 void visitAliasScopeListMetadata(
const MDNode *MD);
530 void visitAccessGroupMetadata(
const MDNode *MD);
532 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
533#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
534#include "llvm/IR/Metadata.def"
535 void visitDIScope(
const DIScope &
N);
562 void visitPHINode(
PHINode &PN);
571 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
609 void verifySwiftErrorCall(
CallBase &Call,
const Value *SwiftErrorVal);
610 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
612 void verifyMustTailCall(
CallInst &CI);
613 bool verifyAttributeCount(
AttributeList Attrs,
unsigned Params);
619 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
620 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
622 void visitConstantExprsRecursively(
const Constant *EntryC);
625 void verifyInlineAsmCall(
const CallBase &Call);
626 void verifyStatepoint(
const CallBase &Call);
627 void verifyFrameRecoverIndices();
628 void verifySiblingFuncletUnwinds();
632 template <
typename ValueOrMetadata>
633 void verifyFragmentExpression(
const DIVariable &V,
635 ValueOrMetadata *
Desc);
642 void verifyCompileUnits();
646 void verifyDeoptimizeCallingConvs();
648 void verifyAttachedCallBundle(
const CallBase &Call,
652 void verifyNoAliasScopeDecl();
658#define Check(C, ...) \
661 CheckFailed(__VA_ARGS__); \
668#define CheckDI(C, ...) \
671 DebugInfoCheckFailed(__VA_ARGS__); \
679 CheckDI(
I.DebugMarker->MarkedInstr == &
I,
680 "Instruction has invalid DebugMarker", &
I);
681 CheckDI(!isa<PHINode>(&
I) || !
I.hasDbgRecords(),
682 "PHI Node must not have any attached DbgRecords", &
I);
685 "DbgRecord had invalid DebugMarker", &
I, &DR);
688 visitMDNode(*Loc, AreDebugLocsAllowed::Yes);
689 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR)) {
693 verifyFragmentExpression(*DVR);
694 verifyNotEntryValue(*DVR);
695 }
else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
703 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
704 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
717 while (!WorkList.
empty()) {
719 if (!Visited.
insert(Cur).second)
726void Verifier::visitGlobalValue(
const GlobalValue &GV) {
728 "Global is external, but doesn't have external or weak linkage!", &GV);
730 if (
const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
734 "huge alignment values are unsupported", GO);
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 verifyRangeMetadata(*GO, AbsoluteSymbol,
DL.getIntPtrType(GO->getType()),
768 "Only global variables can have appending linkage!", &GV);
773 "Only global arrays can have appending linkage!", GVar);
777 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
781 "dllexport GlobalValue must have default or protected visibility",
786 "dllimport GlobalValue must have default visibility", &GV);
787 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
793 "Global is marked as dllimport, but not external", &GV);
798 "GlobalValue with local linkage or non-default "
799 "visibility must be dso_local!",
804 if (!
I->getParent() || !
I->getParent()->getParent())
805 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
807 else if (
I->getParent()->getParent()->getParent() != &M)
808 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
809 I->getParent()->getParent(),
810 I->getParent()->getParent()->getParent());
812 }
else if (
const Function *
F = dyn_cast<Function>(V)) {
813 if (
F->getParent() != &M)
814 CheckFailed(
"Global is used by function in a different module", &GV, &M,
825 "Global variable initializer type does not match global "
832 "'common' global must have a zero initializer!", &GV);
835 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
840 GV.
getName() ==
"llvm.global_dtors")) {
842 "invalid linkage for intrinsic global variable", &GV);
844 "invalid uses of intrinsic global variable", &GV);
849 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
855 "wrong type for intrinsic global variable", &GV);
857 "the third field of the element type is mandatory, "
858 "specify ptr null to migrate from the obsoleted 2-field form");
866 GV.
getName() ==
"llvm.compiler.used")) {
868 "invalid linkage for intrinsic global variable", &GV);
870 "invalid uses of intrinsic global variable", &GV);
873 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
874 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
875 Check(PTy,
"wrong type for intrinsic global variable", &GV);
879 Check(InitArray,
"wrong initalizer for intrinsic global variable",
883 Check(isa<GlobalVariable>(V) || isa<Function>(V) ||
887 Twine(
"members of ") + GV.
getName() +
" must be named", V);
896 for (
auto *MD : MDs) {
897 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
898 visitDIGlobalVariableExpression(*GVE);
900 CheckDI(
false,
"!dbg attachment of global variable must be a "
901 "DIGlobalVariableExpression");
907 "Globals cannot contain scalable types", &GV);
911 if (
auto *TTy = dyn_cast<TargetExtType>(GV.
getValueType()))
913 "Global @" + GV.
getName() +
" has illegal target extension type",
917 visitGlobalValue(GV);
924 visitGlobalValue(GV);
930 visitAliaseeSubExpr(Visited, GA,
C);
936 Check(isa<GlobalValue>(
C) &&
937 cast<GlobalValue>(
C).hasAvailableExternallyLinkage(),
938 "available_externally alias must point to available_externally "
942 if (
const auto *GV = dyn_cast<GlobalValue>(&
C)) {
948 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
949 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
951 Check(!GA2->isInterposable(),
952 "Alias cannot point to an interposable alias", &GA);
960 if (
const auto *CE = dyn_cast<ConstantExpr>(&
C))
961 visitConstantExprsRecursively(CE);
963 for (
const Use &U :
C.operands()) {
965 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
966 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
967 else if (
const auto *C2 = dyn_cast<Constant>(V))
968 visitAliaseeSubExpr(Visited, GA, *C2);
972void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
974 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
975 "weak_odr, external, or available_externally linkage!",
978 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
980 "Alias and aliasee types should match!", &GA);
982 Check(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
983 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
985 visitAliaseeSubExpr(GA, *Aliasee);
987 visitGlobalValue(GA);
990void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
992 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
993 "weak_odr, or external linkage!",
1000 "IFunc resolver must be a definition", &GI);
1006 Check(isa<PointerType>(
Resolver->getFunctionType()->getReturnType()),
1007 "IFunc resolver must return a pointer", &GI);
1009 const Type *ResolverFuncTy =
1012 "IFunc resolver has incorrect type", &GI);
1015void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1020 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1022 if (NMD.
getName() ==
"llvm.dbg.cu")
1023 CheckDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
1028 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1032void Verifier::visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
1035 if (!MDNodes.
insert(&MD).second)
1039 "MDNode context does not match Module context!", &MD);
1044 case Metadata::MDTupleKind:
1046#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1047 case Metadata::CLASS##Kind: \
1048 visit##CLASS(cast<CLASS>(MD)); \
1050#include "llvm/IR/Metadata.def"
1056 Check(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
1058 CheckDI(!isa<DILocation>(
Op) || AllowLocs == AreDebugLocsAllowed::Yes,
1059 "DILocation not allowed within this metadata node", &MD,
Op);
1060 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
1061 visitMDNode(*
N, AllowLocs);
1064 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
1065 visitValueAsMetadata(*V,
nullptr);
1078 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1080 auto *
L = dyn_cast<LocalAsMetadata>(&MD);
1084 Check(
F,
"function-local metadata used outside a function", L);
1089 if (
Instruction *
I = dyn_cast<Instruction>(
L->getValue())) {
1090 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1091 ActualF =
I->getParent()->getParent();
1092 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(
L->getValue()))
1094 else if (
Argument *
A = dyn_cast<Argument>(
L->getValue()))
1095 ActualF =
A->getParent();
1096 assert(ActualF &&
"Unimplemented function local metadata case!");
1098 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1103 visitValueAsMetadata(*VAM,
F);
1108 if (
auto *
N = dyn_cast<MDNode>(MD)) {
1109 visitMDNode(*
N, AreDebugLocsAllowed::No);
1115 if (!MDNodes.
insert(MD).second)
1118 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
1119 visitValueAsMetadata(*V,
F);
1121 if (
auto *AL = dyn_cast<DIArgList>(MD))
1122 visitDIArgList(*AL,
F);
1129void Verifier::visitDILocation(
const DILocation &
N) {
1130 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1131 "location requires a valid scope", &
N,
N.getRawScope());
1132 if (
auto *IA =
N.getRawInlinedAt())
1133 CheckDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
1134 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1135 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1142void Verifier::visitDIScope(
const DIScope &
N) {
1143 if (
auto *
F =
N.getRawFile())
1144 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1147void Verifier::visitDISubrange(
const DISubrange &
N) {
1148 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1149 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1150 "Subrange can have any one of count or upperBound", &
N);
1151 auto *CBound =
N.getRawCountNode();
1152 CheckDI(!CBound || isa<ConstantAsMetadata>(CBound) ||
1153 isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1154 "Count must be signed constant or DIVariable or DIExpression", &
N);
1155 auto Count =
N.getCount();
1156 CheckDI(!Count || !isa<ConstantInt *>(Count) ||
1157 cast<ConstantInt *>(Count)->getSExtValue() >= -1,
1158 "invalid subrange count", &
N);
1159 auto *LBound =
N.getRawLowerBound();
1160 CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||
1161 isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1162 "LowerBound must be signed constant or DIVariable or DIExpression",
1164 auto *UBound =
N.getRawUpperBound();
1165 CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) ||
1166 isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1167 "UpperBound must be signed constant or DIVariable or DIExpression",
1169 auto *Stride =
N.getRawStride();
1170 CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) ||
1171 isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1172 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1176 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1177 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1178 "GenericSubrange can have any one of count or upperBound", &
N);
1179 auto *CBound =
N.getRawCountNode();
1180 CheckDI(!CBound || isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1181 "Count must be signed constant or DIVariable or DIExpression", &
N);
1182 auto *LBound =
N.getRawLowerBound();
1183 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1184 CheckDI(isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1185 "LowerBound must be signed constant or DIVariable or DIExpression",
1187 auto *UBound =
N.getRawUpperBound();
1188 CheckDI(!UBound || isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1189 "UpperBound must be signed constant or DIVariable or DIExpression",
1191 auto *Stride =
N.getRawStride();
1192 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1193 CheckDI(isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1194 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1198 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1202 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1203 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1204 N.getTag() == dwarf::DW_TAG_string_type,
1209 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1210 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1218 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1219 N.getTag() == dwarf::DW_TAG_pointer_type ||
1220 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1221 N.getTag() == dwarf::DW_TAG_reference_type ||
1222 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1223 N.getTag() == dwarf::DW_TAG_const_type ||
1224 N.getTag() == dwarf::DW_TAG_immutable_type ||
1225 N.getTag() == dwarf::DW_TAG_volatile_type ||
1226 N.getTag() == dwarf::DW_TAG_restrict_type ||
1227 N.getTag() == dwarf::DW_TAG_atomic_type ||
1228 N.getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ||
1229 N.getTag() == dwarf::DW_TAG_member ||
1230 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1231 N.getTag() == dwarf::DW_TAG_inheritance ||
1232 N.getTag() == dwarf::DW_TAG_friend ||
1233 N.getTag() == dwarf::DW_TAG_set_type ||
1234 N.getTag() == dwarf::DW_TAG_template_alias,
1236 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1237 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1238 N.getRawExtraData());
1241 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1242 if (
auto *
T =
N.getRawBaseType()) {
1243 auto *
Enum = dyn_cast_or_null<DICompositeType>(
T);
1244 auto *
Basic = dyn_cast_or_null<DIBasicType>(
T);
1246 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1247 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1248 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1249 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1250 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1251 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1252 "invalid set base type", &
N,
T);
1258 N.getRawBaseType());
1260 if (
N.getDWARFAddressSpace()) {
1261 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1262 N.getTag() == dwarf::DW_TAG_reference_type ||
1263 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1264 "DWARF address space only applies to pointer or reference types",
1271 return ((Flags & DINode::FlagLValueReference) &&
1272 (Flags & DINode::FlagRValueReference)) ||
1273 ((Flags & DINode::FlagTypePassByValue) &&
1274 (Flags & DINode::FlagTypePassByReference));
1277void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1278 auto *Params = dyn_cast<MDTuple>(&RawParams);
1279 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1281 CheckDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
1290 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1291 N.getTag() == dwarf::DW_TAG_structure_type ||
1292 N.getTag() == dwarf::DW_TAG_union_type ||
1293 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1294 N.getTag() == dwarf::DW_TAG_class_type ||
1295 N.getTag() == dwarf::DW_TAG_variant_part ||
1296 N.getTag() == dwarf::DW_TAG_namelist,
1301 N.getRawBaseType());
1303 CheckDI(!
N.getRawElements() || isa<MDTuple>(
N.getRawElements()),
1304 "invalid composite elements", &
N,
N.getRawElements());
1306 N.getRawVTableHolder());
1308 "invalid reference flags", &
N);
1309 unsigned DIBlockByRefStruct = 1 << 4;
1310 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1311 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1314 const DINodeArray
Elements =
N.getElements();
1316 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1317 "invalid vector, expected one element of type subrange", &
N);
1320 if (
auto *Params =
N.getRawTemplateParams())
1321 visitTemplateParams(
N, *Params);
1323 if (
auto *
D =
N.getRawDiscriminator()) {
1324 CheckDI(isa<DIDerivedType>(
D) &&
N.getTag() == dwarf::DW_TAG_variant_part,
1325 "discriminator can only appear on variant part");
1328 if (
N.getRawDataLocation()) {
1329 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1330 "dataLocation can only appear in array type");
1333 if (
N.getRawAssociated()) {
1334 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1335 "associated can only appear in array type");
1338 if (
N.getRawAllocated()) {
1339 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1340 "allocated can only appear in array type");
1343 if (
N.getRawRank()) {
1344 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1345 "rank can only appear in array type");
1348 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1349 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1354 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1355 if (
auto *Types =
N.getRawTypeArray()) {
1356 CheckDI(isa<MDTuple>(Types),
"invalid composite elements", &
N, Types);
1357 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1358 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1362 "invalid reference flags", &
N);
1365void Verifier::visitDIFile(
const DIFile &
N) {
1366 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1367 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1370 "invalid checksum kind", &
N);
1372 switch (Checksum->Kind) {
1383 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1385 "invalid checksum", &
N);
1390 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1391 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1395 CheckDI(
N.getRawFile() && isa<DIFile>(
N.getRawFile()),
"invalid file", &
N,
1397 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1401 "invalid emission kind", &
N);
1403 if (
auto *Array =
N.getRawEnumTypes()) {
1404 CheckDI(isa<MDTuple>(Array),
"invalid enum list", &
N, Array);
1405 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1406 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
1407 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1408 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1411 if (
auto *Array =
N.getRawRetainedTypes()) {
1412 CheckDI(isa<MDTuple>(Array),
"invalid retained type list", &
N, Array);
1413 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1415 Op && (isa<DIType>(
Op) || (isa<DISubprogram>(
Op) &&
1416 !cast<DISubprogram>(
Op)->isDefinition())),
1417 "invalid retained type", &
N,
Op);
1420 if (
auto *Array =
N.getRawGlobalVariables()) {
1421 CheckDI(isa<MDTuple>(Array),
"invalid global variable list", &
N, Array);
1422 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1423 CheckDI(
Op && (isa<DIGlobalVariableExpression>(
Op)),
1424 "invalid global variable ref", &
N,
Op);
1427 if (
auto *Array =
N.getRawImportedEntities()) {
1428 CheckDI(isa<MDTuple>(Array),
"invalid imported entity list", &
N, Array);
1429 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1430 CheckDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1434 if (
auto *Array =
N.getRawMacros()) {
1435 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1437 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1444 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1446 if (
auto *
F =
N.getRawFile())
1447 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1449 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1450 if (
auto *
T =
N.getRawType())
1451 CheckDI(isa<DISubroutineType>(
T),
"invalid subroutine type", &
N,
T);
1452 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1453 N.getRawContainingType());
1454 if (
auto *Params =
N.getRawTemplateParams())
1455 visitTemplateParams(
N, *Params);
1456 if (
auto *S =
N.getRawDeclaration())
1457 CheckDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1458 "invalid subprogram declaration", &
N, S);
1459 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1460 auto *
Node = dyn_cast<MDTuple>(RawNode);
1461 CheckDI(
Node,
"invalid retained nodes list", &
N, RawNode);
1463 CheckDI(
Op && (isa<DILocalVariable>(
Op) || isa<DILabel>(
Op) ||
1464 isa<DIImportedEntity>(
Op)),
1465 "invalid retained nodes, expected DILocalVariable, DILabel or "
1471 "invalid reference flags", &
N);
1473 auto *Unit =
N.getRawUnit();
1474 if (
N.isDefinition()) {
1476 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1477 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1478 CheckDI(isa<DICompileUnit>(Unit),
"invalid unit type", &
N, Unit);
1481 auto *CT = dyn_cast_or_null<DICompositeType>(
N.getRawScope());
1482 if (CT && CT->getRawIdentifier() &&
1483 M.getContext().isODRUniquingDebugTypes())
1485 "definition subprograms cannot be nested within DICompositeType "
1486 "when enabling ODR",
1490 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1492 "subprogram declaration must not have a declaration field");
1495 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1496 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1497 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1499 CheckDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1503 if (
N.areAllCallsDescribed())
1505 "DIFlagAllCallsDescribed must be attached to a definition");
1509 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1510 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1511 "invalid local scope", &
N,
N.getRawScope());
1512 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1513 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1517 visitDILexicalBlockBase(
N);
1520 "cannot have column info without line info", &
N);
1524 visitDILexicalBlockBase(
N);
1528 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1529 if (
auto *S =
N.getRawScope())
1530 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1531 if (
auto *S =
N.getRawDecl())
1532 CheckDI(isa<DIGlobalVariable>(S),
"invalid declaration", &
N, S);
1536 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1537 if (
auto *S =
N.getRawScope())
1538 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1541void Verifier::visitDIMacro(
const DIMacro &
N) {
1544 "invalid macinfo type", &
N);
1545 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1546 if (!
N.getValue().empty()) {
1547 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1553 "invalid macinfo type", &
N);
1554 if (
auto *
F =
N.getRawFile())
1555 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1557 if (
auto *Array =
N.getRawElements()) {
1558 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1559 for (
Metadata *
Op :
N.getElements()->operands()) {
1560 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1565void Verifier::visitDIModule(
const DIModule &
N) {
1566 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1567 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1575 visitDITemplateParameter(
N);
1577 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1581void Verifier::visitDITemplateValueParameter(
1583 visitDITemplateParameter(
N);
1585 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1586 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1587 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1591void Verifier::visitDIVariable(
const DIVariable &
N) {
1592 if (
auto *S =
N.getRawScope())
1593 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1594 if (
auto *
F =
N.getRawFile())
1595 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1602 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1605 if (
N.isDefinition())
1606 CheckDI(
N.getType(),
"missing global variable type", &
N);
1607 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1608 CheckDI(isa<DIDerivedType>(Member),
1609 "invalid static data member declaration", &
N, Member);
1618 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1619 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1620 "local variable requires a valid scope", &
N,
N.getRawScope());
1621 if (
auto Ty =
N.getType())
1622 CheckDI(!isa<DISubroutineType>(Ty),
"invalid type", &
N,
N.getType());
1625void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1626 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1627 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1630void Verifier::visitDILabel(
const DILabel &
N) {
1631 if (
auto *S =
N.getRawScope())
1632 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1633 if (
auto *
F =
N.getRawFile())
1634 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1636 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1637 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1638 "label requires a valid scope", &
N,
N.getRawScope());
1642 CheckDI(
N.isValid(),
"invalid expression", &
N);
1645void Verifier::visitDIGlobalVariableExpression(
1649 visitDIGlobalVariable(*Var);
1651 visitDIExpression(*Expr);
1652 if (
auto Fragment = Expr->getFragmentInfo())
1653 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1658 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1659 if (
auto *
T =
N.getRawType())
1661 if (
auto *
F =
N.getRawFile())
1662 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1666 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1667 N.getTag() == dwarf::DW_TAG_imported_declaration,
1669 if (
auto *S =
N.getRawScope())
1670 CheckDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1675void Verifier::visitComdat(
const Comdat &
C) {
1678 if (
TT.isOSBinFormatCOFF())
1684void Verifier::visitModuleIdents() {
1685 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1692 Check(
N->getNumOperands() == 1,
1693 "incorrect number of operands in llvm.ident metadata",
N);
1694 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1695 (
"invalid value for llvm.ident metadata entry operand"
1696 "(the operand should be a string)"),
1701void Verifier::visitModuleCommandLines() {
1702 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1710 Check(
N->getNumOperands() == 1,
1711 "incorrect number of operands in llvm.commandline metadata",
N);
1712 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1713 (
"invalid value for llvm.commandline metadata entry operand"
1714 "(the operand should be a string)"),
1719void Verifier::visitModuleFlags() {
1729 visitModuleFlag(MDN, SeenIDs, Requirements);
1730 if (MDN->getNumOperands() != 3)
1732 if (
const auto *FlagName = dyn_cast_or_null<MDString>(MDN->getOperand(1))) {
1733 if (FlagName->getString() ==
"aarch64-elf-pauthabi-platform") {
1734 if (
const auto *PAP =
1735 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1736 PAuthABIPlatform = PAP->getZExtValue();
1737 }
else if (FlagName->getString() ==
"aarch64-elf-pauthabi-version") {
1738 if (
const auto *PAV =
1739 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1740 PAuthABIVersion = PAV->getZExtValue();
1745 if ((PAuthABIPlatform ==
uint64_t(-1)) != (PAuthABIVersion ==
uint64_t(-1)))
1746 CheckFailed(
"either both or no 'aarch64-elf-pauthabi-platform' and "
1747 "'aarch64-elf-pauthabi-version' module flags must be present");
1750 for (
const MDNode *Requirement : Requirements) {
1751 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1752 const Metadata *ReqValue = Requirement->getOperand(1);
1756 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1761 if (
Op->getOperand(2) != ReqValue) {
1762 CheckFailed((
"invalid requirement on flag, "
1763 "flag does not have the required value"),
1771Verifier::visitModuleFlag(
const MDNode *
Op,
1777 "incorrect number of operands in module flag",
Op);
1780 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0)),
1781 "invalid behavior operand in module flag (expected constant integer)",
1784 "invalid behavior operand in module flag (unexpected constant)",
1787 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(1));
1788 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
1800 auto *
V = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1801 Check(V &&
V->getValue().isNonNegative(),
1802 "invalid value for 'min' module flag (expected constant non-negative "
1809 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2)),
1810 "invalid value for 'max' module flag (expected constant integer)",
1820 "invalid value for 'require' module flag (expected metadata pair)",
1823 (
"invalid value for 'require' module flag "
1824 "(first value operand should be a string)"),
1825 Value->getOperand(0));
1836 Check(isa<MDNode>(
Op->getOperand(2)),
1837 "invalid value for 'append'-type module flag "
1838 "(expected a metadata node)",
1848 "module flag identifiers must be unique (or of 'require' type)",
ID);
1851 if (
ID->getString() ==
"wchar_size") {
1853 = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1854 Check(
Value,
"wchar_size metadata requires constant integer argument");
1857 if (
ID->getString() ==
"Linker Options") {
1861 Check(
M.getNamedMetadata(
"llvm.linker.options"),
1862 "'Linker Options' named metadata no longer supported");
1865 if (
ID->getString() ==
"SemanticInterposition") {
1867 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1869 "SemanticInterposition metadata requires constant integer argument");
1872 if (
ID->getString() ==
"CG Profile") {
1873 for (
const MDOperand &MDO : cast<MDNode>(
Op->getOperand(2))->operands())
1874 visitModuleFlagCGProfileEntry(MDO);
1878void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1879 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1882 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1883 Check(
F && isa<Function>(
F->getValue()->stripPointerCasts()),
1884 "expected a Function or null", FuncMDO);
1886 auto Node = dyn_cast_or_null<MDNode>(MDO);
1887 Check(
Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1888 CheckFunction(
Node->getOperand(0));
1889 CheckFunction(
Node->getOperand(1));
1890 auto Count = dyn_cast_or_null<ConstantAsMetadata>(
Node->getOperand(2));
1891 Check(Count && Count->getType()->isIntegerTy(),
1892 "expected an integer constant",
Node->getOperand(2));
1898 if (
A.isStringAttribute()) {
1899#define GET_ATTR_NAMES
1900#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
1901#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1902 if (A.getKindAsString() == #DISPLAY_NAME) { \
1903 auto V = A.getValueAsString(); \
1904 if (!(V.empty() || V == "true" || V == "false")) \
1905 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
1909#include "llvm/IR/Attributes.inc"
1914 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
1925 if (!
Attrs.hasAttributes())
1928 verifyAttributeTypes(Attrs, V);
1931 Check(Attr.isStringAttribute() ||
1933 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
1936 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
1938 "Attribute 'immarg' is incompatible with other attributes", V);
1943 unsigned AttrCount = 0;
1944 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
1945 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
1946 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
1947 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
1948 Attrs.hasAttribute(Attribute::InReg);
1949 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
1950 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
1951 Check(AttrCount <= 1,
1952 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
1953 "'byref', and 'sret' are incompatible!",
1956 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
1957 Attrs.hasAttribute(Attribute::ReadOnly)),
1959 "'inalloca and readonly' are incompatible!",
1962 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
1963 Attrs.hasAttribute(Attribute::Returned)),
1965 "'sret and returned' are incompatible!",
1968 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
1969 Attrs.hasAttribute(Attribute::SExt)),
1971 "'zeroext and signext' are incompatible!",
1974 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1975 Attrs.hasAttribute(Attribute::ReadOnly)),
1977 "'readnone and readonly' are incompatible!",
1980 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1981 Attrs.hasAttribute(Attribute::WriteOnly)),
1983 "'readnone and writeonly' are incompatible!",
1986 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
1987 Attrs.hasAttribute(Attribute::WriteOnly)),
1989 "'readonly and writeonly' are incompatible!",
1992 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
1993 Attrs.hasAttribute(Attribute::AlwaysInline)),
1995 "'noinline and alwaysinline' are incompatible!",
1998 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
1999 Attrs.hasAttribute(Attribute::ReadNone)),
2000 "Attributes writable and readnone are incompatible!", V);
2002 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2003 Attrs.hasAttribute(Attribute::ReadOnly)),
2004 "Attributes writable and readonly are incompatible!", V);
2008 if (!Attr.isStringAttribute() &&
2009 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2010 CheckFailed(
"Attribute '" + Attr.getAsString() +
2011 "' applied to incompatible type!", V);
2016 if (isa<PointerType>(Ty)) {
2017 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2018 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2020 "huge alignment values are unsupported", V);
2022 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2024 Check(
Attrs.getByValType()->isSized(&Visited),
2025 "Attribute 'byval' does not support unsized types!", V);
2026 Check(
DL.getTypeAllocSize(
Attrs.getByValType()).getKnownMinValue() <
2028 "huge 'byval' arguments are unsupported", V);
2030 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2032 Check(
Attrs.getByRefType()->isSized(&Visited),
2033 "Attribute 'byref' does not support unsized types!", V);
2034 Check(
DL.getTypeAllocSize(
Attrs.getByRefType()).getKnownMinValue() <
2036 "huge 'byref' arguments are unsupported", V);
2038 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2040 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2041 "Attribute 'inalloca' does not support unsized types!", V);
2042 Check(
DL.getTypeAllocSize(
Attrs.getInAllocaType()).getKnownMinValue() <
2044 "huge 'inalloca' arguments are unsupported", V);
2046 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2048 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2049 "Attribute 'preallocated' does not support unsized types!", V);
2051 DL.getTypeAllocSize(
Attrs.getPreallocatedType()).getKnownMinValue() <
2053 "huge 'preallocated' arguments are unsupported", V);
2057 if (
Attrs.hasAttribute(Attribute::Initializes)) {
2058 auto Inits =
Attrs.getAttribute(Attribute::Initializes).getInitializes();
2059 Check(!Inits.empty(),
"Attribute 'initializes' does not support empty list",
2062 "Attribute 'initializes' does not support unordered ranges", V);
2065 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2066 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2067 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2070 "Invalid value for 'nofpclass' test mask", V);
2072 if (
Attrs.hasAttribute(Attribute::Range)) {
2074 Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2076 "Range bit width must match type bit width!", V);
2082 if (
Attrs.hasFnAttr(Attr)) {
2086 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2093 const Value *V,
bool IsIntrinsic,
2095 if (
Attrs.isEmpty())
2098 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2100 "Attribute list does not match Module context!", &Attrs, V);
2101 for (
const auto &AttrSet : Attrs) {
2102 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
2103 "Attribute set does not match Module context!", &AttrSet, V);
2104 for (
const auto &
A : AttrSet) {
2105 Check(
A.hasParentContext(Context),
2106 "Attribute does not match Module context!", &
A, V);
2111 bool SawNest =
false;
2112 bool SawReturned =
false;
2113 bool SawSRet =
false;
2114 bool SawSwiftSelf =
false;
2115 bool SawSwiftAsync =
false;
2116 bool SawSwiftError =
false;
2123 "Attribute '" +
RetAttr.getAsString() +
2124 "' does not apply to function return values",
2127 unsigned MaxParameterWidth = 0;
2128 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2130 if (
auto *VT = dyn_cast<FixedVectorType>(Ty)) {
2131 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2132 if (
Size > MaxParameterWidth)
2133 MaxParameterWidth =
Size;
2137 GetMaxParameterWidth(FT->getReturnType());
2138 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2141 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2142 Type *Ty = FT->getParamType(i);
2147 "immarg attribute only applies to intrinsics", V);
2150 "Attribute 'elementtype' can only be applied to intrinsics"
2155 verifyParameterAttrs(ArgAttrs, Ty, V);
2156 GetMaxParameterWidth(Ty);
2159 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2164 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2166 "Incompatible argument and return types for 'returned' attribute",
2172 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2173 Check(i == 0 || i == 1,
2174 "Attribute 'sret' is not on first or second parameter!", V);
2179 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2180 SawSwiftSelf =
true;
2184 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2185 SawSwiftAsync =
true;
2189 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2190 SawSwiftError =
true;
2194 Check(i == FT->getNumParams() - 1,
2195 "inalloca isn't on the last parameter!", V);
2199 if (!
Attrs.hasFnAttrs())
2202 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2206 "Attribute '" +
FnAttr.getAsString() +
2207 "' does not apply to functions!",
2210 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2211 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2212 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2214 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2216 "Attribute 'optnone' requires 'noinline'!", V);
2218 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2219 "Attributes 'optsize and optnone' are incompatible!", V);
2222 "Attributes 'minsize and optnone' are incompatible!", V);
2224 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2225 "Attributes 'optdebug and optnone' are incompatible!", V);
2228 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2229 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2230 "Attributes 'optsize and optdebug' are incompatible!", V);
2233 "Attributes 'minsize and optdebug' are incompatible!", V);
2236 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2238 "Attribute writable and memory without argmem: write are incompatible!",
2241 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2242 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2243 "Attributes 'aarch64_pstate_sm_enabled and "
2244 "aarch64_pstate_sm_compatible' are incompatible!",
2248 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2249 Attrs.hasFnAttr(
"aarch64_inout_za") +
2250 Attrs.hasFnAttr(
"aarch64_out_za") +
2251 Attrs.hasFnAttr(
"aarch64_preserves_za")) <= 1,
2252 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2253 "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive",
2257 (
Attrs.hasFnAttr(
"aarch64_new_zt0") +
Attrs.hasFnAttr(
"aarch64_in_zt0") +
2258 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2259 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2260 Attrs.hasFnAttr(
"aarch64_preserves_zt0")) <= 1,
2261 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2262 "'aarch64_inout_zt0' and 'aarch64_preserves_zt0' are mutually exclusive",
2265 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2268 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2271 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2273 if (ParamNo >= FT->getNumParams()) {
2274 CheckFailed(
"'allocsize' " +
Name +
" argument is out of bounds", V);
2278 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2279 CheckFailed(
"'allocsize' " +
Name +
2280 " argument must refer to an integer parameter",
2288 if (!CheckParam(
"element size",
Args->first))
2291 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2295 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2303 "'allockind()' requires exactly one of alloc, realloc, and free");
2307 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2308 "or aligned modifiers.");
2310 if ((K & ZeroedUninit) == ZeroedUninit)
2311 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2314 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2315 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2317 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2319 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2320 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2321 if (VScaleMax && VScaleMin > VScaleMax)
2322 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2324 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2327 if (
Attrs.hasFnAttr(
"frame-pointer")) {
2329 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none" &&
FP !=
"reserved")
2330 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2334 if (MaxParameterWidth >= 512 &&
Attrs.hasFnAttr(
"target-features") &&
2336 StringRef TF =
Attrs.getFnAttr(
"target-features").getValueAsString();
2338 "512-bit vector arguments require 'evex512' for AVX512", V);
2341 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2342 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2343 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2345 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2347 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2348 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2351 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2353 if (S !=
"a_key" && S !=
"b_key")
2354 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2356 if (
auto AA =
Attrs.getFnAttr(
"sign-return-address"); !AA.isValid()) {
2358 "'sign-return-address-key' present without `sign-return-address`");
2362 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2364 if (S !=
"" && S !=
"true" && S !=
"false")
2366 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2369 if (
auto A =
Attrs.getFnAttr(
"branch-protection-pauth-lr");
A.isValid()) {
2371 if (S !=
"" && S !=
"true" && S !=
"false")
2373 "invalid value for 'branch-protection-pauth-lr' attribute: " + S, V);
2376 if (
auto A =
Attrs.getFnAttr(
"guarded-control-stack");
A.isValid()) {
2378 if (S !=
"" && S !=
"true" && S !=
"false")
2379 CheckFailed(
"invalid value for 'guarded-control-stack' attribute: " + S,
2383 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2387 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2391void Verifier::verifyFunctionMetadata(
2392 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2393 for (
const auto &Pair : MDs) {
2394 if (Pair.first == LLVMContext::MD_prof) {
2395 MDNode *MD = Pair.second;
2397 "!prof annotations should have no less than 2 operands", MD);
2400 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2403 "expected string with name of the !prof annotation", MD);
2406 Check(ProfName ==
"function_entry_count" ||
2407 ProfName ==
"synthetic_function_entry_count",
2408 "first operand should be 'function_entry_count'"
2409 " or 'synthetic_function_entry_count'",
2413 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2416 "expected integer argument to function_entry_count", MD);
2417 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2418 MDNode *MD = Pair.second;
2420 "!kcfi_type must have exactly one operand", MD);
2421 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2424 "expected a constant operand for !kcfi_type", MD);
2426 Check(isa<ConstantInt>(
C) && isa<IntegerType>(
C->getType()),
2427 "expected a constant integer operand for !kcfi_type", MD);
2429 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2434void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2435 if (!ConstantExprVisited.
insert(EntryC).second)
2439 Stack.push_back(EntryC);
2441 while (!
Stack.empty()) {
2445 if (
const auto *CE = dyn_cast<ConstantExpr>(
C))
2446 visitConstantExpr(CE);
2448 if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C))
2449 visitConstantPtrAuth(CPA);
2451 if (
const auto *GV = dyn_cast<GlobalValue>(
C)) {
2454 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2460 for (
const Use &U :
C->operands()) {
2461 const auto *OpC = dyn_cast<Constant>(U);
2464 if (!ConstantExprVisited.
insert(OpC).second)
2466 Stack.push_back(OpC);
2471void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2472 if (
CE->getOpcode() == Instruction::BitCast)
2475 "Invalid bitcast", CE);
2480 "signed ptrauth constant base pointer must have pointer type");
2483 "signed ptrauth constant must have same type as its base pointer");
2486 "signed ptrauth constant key must be i32 constant integer");
2489 "signed ptrauth constant address discriminator must be a pointer");
2492 "signed ptrauth constant discriminator must be i64 constant integer");
2495bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
2498 return Attrs.getNumAttrSets() <= Params + 2;
2501void Verifier::verifyInlineAsmCall(
const CallBase &Call) {
2504 unsigned LabelNo = 0;
2515 if (CI.isIndirect) {
2516 const Value *Arg =
Call.getArgOperand(ArgNo);
2518 "Operand for indirect constraint must have pointer type", &Call);
2521 "Operand for indirect constraint must have elementtype attribute",
2524 Check(!
Call.paramHasAttr(ArgNo, Attribute::ElementType),
2525 "Elementtype attribute can only be applied for indirect "
2533 if (
auto *CallBr = dyn_cast<CallBrInst>(&Call)) {
2534 Check(LabelNo == CallBr->getNumIndirectDests(),
2535 "Number of label constraints does not match number of callbr dests",
2538 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
2544void Verifier::verifyStatepoint(
const CallBase &Call) {
2546 Call.getCalledFunction()->getIntrinsicID() ==
2547 Intrinsic::experimental_gc_statepoint);
2549 Check(!
Call.doesNotAccessMemory() && !
Call.onlyReadsMemory() &&
2550 !
Call.onlyAccessesArgMemory(),
2551 "gc.statepoint must read and write all memory to preserve "
2552 "reordering restrictions required by safepoint semantics",
2555 const int64_t NumPatchBytes =
2556 cast<ConstantInt>(
Call.getArgOperand(1))->getSExtValue();
2557 assert(isInt<32>(NumPatchBytes) &&
"NumPatchBytesV is an i32!");
2558 Check(NumPatchBytes >= 0,
2559 "gc.statepoint number of patchable bytes must be "
2563 Type *TargetElemType =
Call.getParamElementType(2);
2564 Check(TargetElemType,
2565 "gc.statepoint callee argument must have elementtype attribute", Call);
2566 FunctionType *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
2567 Check(TargetFuncType,
2568 "gc.statepoint callee elementtype must be function type", Call);
2570 const int NumCallArgs = cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue();
2571 Check(NumCallArgs >= 0,
2572 "gc.statepoint number of arguments to underlying call "
2575 const int NumParams = (int)TargetFuncType->getNumParams();
2576 if (TargetFuncType->isVarArg()) {
2577 Check(NumCallArgs >= NumParams,
2578 "gc.statepoint mismatch in number of vararg call args", Call);
2581 Check(TargetFuncType->getReturnType()->isVoidTy(),
2582 "gc.statepoint doesn't support wrapping non-void "
2583 "vararg functions yet",
2586 Check(NumCallArgs == NumParams,
2587 "gc.statepoint mismatch in number of call args", Call);
2590 = cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue();
2592 "unknown flag used in gc.statepoint flags argument", Call);
2597 for (
int i = 0; i < NumParams; i++) {
2598 Type *ParamType = TargetFuncType->getParamType(i);
2599 Type *ArgType =
Call.getArgOperand(5 + i)->getType();
2600 Check(ArgType == ParamType,
2601 "gc.statepoint call argument does not match wrapped "
2605 if (TargetFuncType->isVarArg()) {
2608 "Attribute 'sret' cannot be used for vararg call arguments!", Call);
2612 const int EndCallArgsInx = 4 + NumCallArgs;
2614 const Value *NumTransitionArgsV =
Call.getArgOperand(EndCallArgsInx + 1);
2615 Check(isa<ConstantInt>(NumTransitionArgsV),
2616 "gc.statepoint number of transition arguments "
2617 "must be constant integer",
2619 const int NumTransitionArgs =
2620 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
2621 Check(NumTransitionArgs == 0,
2622 "gc.statepoint w/inline transition bundle is deprecated", Call);
2623 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2625 const Value *NumDeoptArgsV =
Call.getArgOperand(EndTransitionArgsInx + 1);
2626 Check(isa<ConstantInt>(NumDeoptArgsV),
2627 "gc.statepoint number of deoptimization arguments "
2628 "must be constant integer",
2630 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
2631 Check(NumDeoptArgs == 0,
2632 "gc.statepoint w/inline deopt operands is deprecated", Call);
2634 const int ExpectedNumArgs = 7 + NumCallArgs;
2635 Check(ExpectedNumArgs == (
int)
Call.arg_size(),
2636 "gc.statepoint too many arguments", Call);
2641 for (
const User *U :
Call.users()) {
2642 const CallInst *UserCall = dyn_cast<const CallInst>(U);
2643 Check(UserCall,
"illegal use of statepoint token", Call, U);
2646 Check(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),
2647 "gc.result or gc.relocate are the only value uses "
2648 "of a gc.statepoint",
2650 if (isa<GCResultInst>(UserCall)) {
2652 "gc.result connected to wrong gc.statepoint", Call, UserCall);
2653 }
else if (isa<GCRelocateInst>(Call)) {
2655 "gc.relocate connected to wrong gc.statepoint", Call, UserCall);
2669void Verifier::verifyFrameRecoverIndices() {
2670 for (
auto &Counts : FrameEscapeInfo) {
2672 unsigned EscapedObjectCount = Counts.second.first;
2673 unsigned MaxRecoveredIndex = Counts.second.second;
2674 Check(MaxRecoveredIndex <= EscapedObjectCount,
2675 "all indices passed to llvm.localrecover must be less than the "
2676 "number of arguments passed to llvm.localescape in the parent "
2684 if (
auto *
II = dyn_cast<InvokeInst>(Terminator))
2685 UnwindDest =
II->getUnwindDest();
2686 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2687 UnwindDest = CSI->getUnwindDest();
2689 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2693void Verifier::verifySiblingFuncletUnwinds() {
2696 for (
const auto &Pair : SiblingFuncletInfo) {
2698 if (Visited.
count(PredPad))
2704 if (Active.
count(SuccPad)) {
2710 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2711 if (CycleTerminator != CyclePad)
2714 }
while (CyclePad != SuccPad);
2715 Check(
false,
"EH pads can't handle each other's exceptions",
2719 if (!Visited.
insert(SuccPad).second)
2723 auto TermI = SiblingFuncletInfo.find(PredPad);
2724 if (TermI == SiblingFuncletInfo.end())
2737void Verifier::visitFunction(
const Function &
F) {
2738 visitGlobalValue(
F);
2742 unsigned NumArgs =
F.arg_size();
2744 Check(&Context == &
F.getContext(),
2745 "Function context does not match Module context!", &
F);
2747 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
2748 Check(FT->getNumParams() == NumArgs,
2749 "# formal arguments must match # of arguments for function type!", &
F,
2751 Check(
F.getReturnType()->isFirstClassType() ||
2752 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
2753 "Functions cannot return aggregate values!", &
F);
2755 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
2756 "Invalid struct return type!", &
F);
2760 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
2761 "Attribute after last parameter!", &
F);
2763 CheckDI(
F.IsNewDbgInfoFormat ==
F.getParent()->IsNewDbgInfoFormat,
2764 "Function debug format should match parent module", &
F,
2765 F.IsNewDbgInfoFormat,
F.getParent(),
2766 F.getParent()->IsNewDbgInfoFormat);
2768 bool IsIntrinsic =
F.isIntrinsic();
2771 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
2777 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2779 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
2780 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
2785 switch (
F.getCallingConv()) {
2790 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
2791 "Calling convention parameter requires byval", &
F);
2798 Check(
F.getReturnType()->isVoidTy(),
2799 "Calling convention requires void return type", &
F);
2806 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
2808 const unsigned StackAS =
DL.getAllocaAddrSpace();
2811 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
2812 "Calling convention disallows byval", &
F);
2813 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
2814 "Calling convention disallows preallocated", &
F);
2815 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
2816 "Calling convention disallows inalloca", &
F);
2818 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
2821 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
2822 "Calling convention disallows stack byref", &
F);
2836 "Calling convention does not support varargs or "
2837 "perfect forwarding!",
2845 Check(Arg.getType() == FT->getParamType(i),
2846 "Argument value does not match function argument type!", &Arg,
2847 FT->getParamType(i));
2848 Check(Arg.getType()->isFirstClassType(),
2849 "Function arguments must have first-class types!", &Arg);
2851 Check(!Arg.getType()->isMetadataTy(),
2852 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
2853 Check(!Arg.getType()->isTokenTy(),
2854 "Function takes token but isn't an intrinsic", &Arg, &
F);
2855 Check(!Arg.getType()->isX86_AMXTy(),
2856 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
2860 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
2861 verifySwiftErrorValue(&Arg);
2867 Check(!
F.getReturnType()->isTokenTy(),
2868 "Function returns a token but isn't an intrinsic", &
F);
2869 Check(!
F.getReturnType()->isX86_AMXTy(),
2870 "Function returns a x86_amx but isn't an intrinsic", &
F);
2875 F.getAllMetadata(MDs);
2876 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
2877 verifyFunctionMetadata(MDs);
2880 if (
F.hasPersonalityFn()) {
2881 auto *Per = dyn_cast<Function>(
F.getPersonalityFn()->stripPointerCasts());
2883 Check(Per->getParent() ==
F.getParent(),
2884 "Referencing personality function in another module!", &
F,
2885 F.getParent(), Per, Per->getParent());
2889 BlockEHFuncletColors.
clear();
2891 if (
F.isMaterializable()) {
2893 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
2895 }
else if (
F.isDeclaration()) {
2896 for (
const auto &
I : MDs) {
2898 CheckDI(
I.first != LLVMContext::MD_dbg ||
2899 !cast<DISubprogram>(
I.second)->isDistinct(),
2900 "function declaration may only have a unique !dbg attachment",
2902 Check(
I.first != LLVMContext::MD_prof,
2903 "function declaration may not have a !prof attachment", &
F);
2906 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
2908 Check(!
F.hasPersonalityFn(),
2909 "Function declaration shouldn't have a personality routine", &
F);
2913 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
2918 "Entry block to function must not have predecessors!", Entry);
2921 if (
Entry->hasAddressTaken()) {
2923 "blockaddress may not be used with the entry block!", Entry);
2926 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
2927 NumKCFIAttachments = 0;
2929 for (
const auto &
I : MDs) {
2931 auto AllowLocs = AreDebugLocsAllowed::No;
2935 case LLVMContext::MD_dbg: {
2936 ++NumDebugAttachments;
2937 CheckDI(NumDebugAttachments == 1,
2938 "function must have a single !dbg attachment", &
F,
I.second);
2939 CheckDI(isa<DISubprogram>(
I.second),
2940 "function !dbg attachment must be a subprogram", &
F,
I.second);
2941 CheckDI(cast<DISubprogram>(
I.second)->isDistinct(),
2942 "function definition may only have a distinct !dbg attachment",
2945 auto *SP = cast<DISubprogram>(
I.second);
2946 const Function *&AttachedTo = DISubprogramAttachments[SP];
2947 CheckDI(!AttachedTo || AttachedTo == &
F,
2948 "DISubprogram attached to more than one function", SP, &
F);
2950 AllowLocs = AreDebugLocsAllowed::Yes;
2953 case LLVMContext::MD_prof:
2954 ++NumProfAttachments;
2955 Check(NumProfAttachments == 1,
2956 "function must have a single !prof attachment", &
F,
I.second);
2958 case LLVMContext::MD_kcfi_type:
2959 ++NumKCFIAttachments;
2960 Check(NumKCFIAttachments == 1,
2961 "function must have a single !kcfi_type attachment", &
F,
2967 visitMDNode(*
I.second, AllowLocs);
2975 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
2977 if (
F.hasAddressTaken(&U,
false,
true,
false,
2979 Check(
false,
"Invalid user of intrinsic instruction!", U);
2983 switch (
F.getIntrinsicID()) {
2984 case Intrinsic::experimental_gc_get_pointer_base: {
2986 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2987 Check(isa<PointerType>(
F.getReturnType()),
2988 "gc.get.pointer.base must return a pointer",
F);
2989 Check(FT->getParamType(0) ==
F.getReturnType(),
2990 "gc.get.pointer.base operand and result must be of the same type",
F);
2993 case Intrinsic::experimental_gc_get_pointer_offset: {
2995 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2996 Check(isa<PointerType>(FT->getParamType(0)),
2997 "gc.get.pointer.offset operand must be a pointer",
F);
2998 Check(
F.getReturnType()->isIntegerTy(),
2999 "gc.get.pointer.offset must return integer",
F);
3004 auto *
N =
F.getSubprogram();
3005 HasDebugInfo = (
N !=
nullptr);
3024 CheckDI(Parent && isa<DILocalScope>(Parent),
3025 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
3028 Check(Scope,
"Failed to find DILocalScope",
DL);
3030 if (!Seen.
insert(Scope).second)
3037 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
3041 "!dbg attachment points at wrong subprogram for function",
N, &
F,
3045 for (
auto &
I : BB) {
3046 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
3048 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
3050 VisitDebugLoc(
I, dyn_cast_or_null<MDNode>(MD->
getOperand(i)));
3051 if (BrokenDebugInfo)
3058void Verifier::visitBasicBlock(
BasicBlock &BB) {
3059 InstsInThisBlock.
clear();
3060 ConvergenceVerifyHelper.
visit(BB);
3067 if (isa<PHINode>(BB.
front())) {
3072 Check(PN.getNumIncomingValues() == Preds.size(),
3073 "PHINode should have one entry for each predecessor of its "
3074 "parent basic block!",
3079 Values.
reserve(PN.getNumIncomingValues());
3080 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3082 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3085 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3090 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3091 Values[i].second == Values[i - 1].second,
3092 "PHI node has multiple entries for the same basic block with "
3093 "different incoming values!",
3094 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3098 Check(Values[i].first == Preds[i],
3099 "PHI node entries do not match predecessors!", &PN,
3100 Values[i].first, Preds[i]);
3108 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3111 CheckDI(BB.IsNewDbgInfoFormat == BB.getParent()->IsNewDbgInfoFormat,
3112 "BB debug format should match parent function", &BB,
3113 BB.IsNewDbgInfoFormat, BB.getParent(),
3114 BB.getParent()->IsNewDbgInfoFormat);
3117 if (BB.IsNewDbgInfoFormat)
3118 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3124 Check(&
I ==
I.getParent()->getTerminator(),
3125 "Terminator found in the middle of a basic block!",
I.getParent());
3129void Verifier::visitBranchInst(
BranchInst &BI) {
3132 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3137void Verifier::visitReturnInst(
ReturnInst &RI) {
3140 if (
F->getReturnType()->isVoidTy())
3142 "Found return instr that returns non-void in Function of void "
3144 &RI,
F->getReturnType());
3147 "Function return type does not match operand "
3148 "type of return inst!",
3149 &RI,
F->getReturnType());
3156void Verifier::visitSwitchInst(
SwitchInst &SI) {
3157 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3160 Type *SwitchTy =
SI.getCondition()->getType();
3162 for (
auto &Case :
SI.cases()) {
3163 Check(isa<ConstantInt>(
SI.getOperand(Case.getCaseIndex() * 2 + 2)),
3164 "Case value is not a constant integer.", &SI);
3165 Check(Case.getCaseValue()->getType() == SwitchTy,
3166 "Switch constants must all be same type as switch value!", &SI);
3168 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3176 "Indirectbr operand must have pointer type!", &BI);
3179 "Indirectbr destinations must all have pointer type!", &BI);
3184void Verifier::visitCallBrInst(
CallBrInst &CBI) {
3185 Check(CBI.
isInlineAsm(),
"Callbr is currently only used for asm-goto!", &CBI);
3187 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3189 verifyInlineAsmCall(CBI);
3193void Verifier::visitSelectInst(
SelectInst &SI) {
3196 "Invalid operands for select instruction!", &SI);
3198 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3199 "Select values must have same type as select instruction!", &SI);
3207 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3212 Type *SrcTy =
I.getOperand(0)->getType();
3213 Type *DestTy =
I.getType();
3222 "trunc source and destination must both be a vector or neither", &
I);
3223 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3228void Verifier::visitZExtInst(
ZExtInst &
I) {
3230 Type *SrcTy =
I.getOperand(0)->getType();
3231 Type *DestTy =
I.getType();
3237 "zext source and destination must both be a vector or neither", &
I);
3241 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3246void Verifier::visitSExtInst(
SExtInst &
I) {
3248 Type *SrcTy =
I.getOperand(0)->getType();
3249 Type *DestTy =
I.getType();
3258 "sext source and destination must both be a vector or neither", &
I);
3259 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3266 Type *SrcTy =
I.getOperand(0)->getType();
3267 Type *DestTy =
I.getType();
3275 "fptrunc source and destination must both be a vector or neither", &
I);
3276 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3283 Type *SrcTy =
I.getOperand(0)->getType();
3284 Type *DestTy =
I.getType();
3293 "fpext source and destination must both be a vector or neither", &
I);
3294 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3301 Type *SrcTy =
I.getOperand(0)->getType();
3302 Type *DestTy =
I.getType();
3307 Check(SrcVec == DstVec,
3308 "UIToFP source and dest must both be vector or scalar", &
I);
3310 "UIToFP source must be integer or integer vector", &
I);
3314 if (SrcVec && DstVec)
3315 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3316 cast<VectorType>(DestTy)->getElementCount(),
3317 "UIToFP source and dest vector length mismatch", &
I);
3324 Type *SrcTy =
I.getOperand(0)->getType();
3325 Type *DestTy =
I.getType();
3330 Check(SrcVec == DstVec,
3331 "SIToFP source and dest must both be vector or scalar", &
I);
3333 "SIToFP source must be integer or integer vector", &
I);
3337 if (SrcVec && DstVec)
3338 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3339 cast<VectorType>(DestTy)->getElementCount(),
3340 "SIToFP source and dest vector length mismatch", &
I);
3347 Type *SrcTy =
I.getOperand(0)->getType();
3348 Type *DestTy =
I.getType();
3353 Check(SrcVec == DstVec,
3354 "FPToUI source and dest must both be vector or scalar", &
I);
3357 "FPToUI result must be integer or integer vector", &
I);
3359 if (SrcVec && DstVec)
3360 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3361 cast<VectorType>(DestTy)->getElementCount(),
3362 "FPToUI source and dest vector length mismatch", &
I);
3369 Type *SrcTy =
I.getOperand(0)->getType();
3370 Type *DestTy =
I.getType();
3375 Check(SrcVec == DstVec,
3376 "FPToSI source and dest must both be vector or scalar", &
I);
3379 "FPToSI result must be integer or integer vector", &
I);
3381 if (SrcVec && DstVec)
3382 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3383 cast<VectorType>(DestTy)->getElementCount(),
3384 "FPToSI source and dest vector length mismatch", &
I);
3391 Type *SrcTy =
I.getOperand(0)->getType();
3392 Type *DestTy =
I.getType();
3401 auto *VSrc = cast<VectorType>(SrcTy);
3402 auto *VDest = cast<VectorType>(DestTy);
3403 Check(VSrc->getElementCount() == VDest->getElementCount(),
3404 "PtrToInt Vector width mismatch", &
I);
3412 Type *SrcTy =
I.getOperand(0)->getType();
3413 Type *DestTy =
I.getType();
3421 auto *VSrc = cast<VectorType>(SrcTy);
3422 auto *VDest = cast<VectorType>(DestTy);
3423 Check(VSrc->getElementCount() == VDest->getElementCount(),
3424 "IntToPtr Vector width mismatch", &
I);
3432 "Invalid bitcast", &
I);
3437 Type *SrcTy =
I.getOperand(0)->getType();
3438 Type *DestTy =
I.getType();
3445 "AddrSpaceCast must be between different address spaces", &
I);
3446 if (
auto *SrcVTy = dyn_cast<VectorType>(SrcTy))
3447 Check(SrcVTy->getElementCount() ==
3448 cast<VectorType>(DestTy)->getElementCount(),
3449 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3455void Verifier::visitPHINode(
PHINode &PN) {
3462 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
3471 "PHI node operands are not the same type as the result!", &PN);
3479void Verifier::visitCallBase(
CallBase &Call) {
3480 Check(
Call.getCalledOperand()->getType()->isPointerTy(),
3481 "Called function must be a pointer!", Call);
3485 if (FTy->isVarArg())
3486 Check(
Call.arg_size() >= FTy->getNumParams(),
3487 "Called function requires more parameters than were provided!", Call);
3489 Check(
Call.arg_size() == FTy->getNumParams(),
3490 "Incorrect number of arguments passed to called function!", Call);
3493 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3494 Check(
Call.getArgOperand(i)->getType() == FTy->getParamType(i),
3495 "Call parameter type does not match function signature!",
3496 Call.getArgOperand(i), FTy->getParamType(i), Call);
3500 Check(verifyAttributeCount(Attrs,
Call.arg_size()),
3501 "Attribute after last parameter!", Call);
3504 dyn_cast<Function>(
Call.getCalledOperand()->stripPointerCasts());
3508 "Intrinsic called with incompatible signature", Call);
3512 auto CC =
Call.getCallingConv();
3515 "Direct calls to amdgpu_cs_chain/amdgpu_cs_chain_preserve functions "
3516 "not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.",
3523 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
3526 Align ABIAlign =
DL.getABITypeAlign(Ty);
3528 "Incorrect alignment of " + Message +
" to called function!", Call);
3532 VerifyTypeAlign(FTy->getReturnType(),
"return type");
3533 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3534 Type *Ty = FTy->getParamType(i);
3535 VerifyTypeAlign(Ty,
"argument passed");
3539 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
3543 "speculatable attribute may not apply to call sites", Call);
3546 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
3547 Check(
Call.getCalledFunction()->getIntrinsicID() ==
3548 Intrinsic::call_preallocated_arg,
3549 "preallocated as a call site attribute can only be on "
3550 "llvm.call.preallocated.arg");
3554 verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic,
Call.isInlineAsm());
3559 if (
Call.hasInAllocaArgument()) {
3560 Value *InAllocaArg =
Call.getArgOperand(FTy->getNumParams() - 1);
3562 Check(AI->isUsedWithInAlloca(),
3563 "inalloca argument for call has mismatched alloca", AI, Call);
3569 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3570 if (
Call.paramHasAttr(i, Attribute::SwiftError)) {
3571 Value *SwiftErrorArg =
Call.getArgOperand(i);
3573 Check(AI->isSwiftError(),
3574 "swifterror argument for call has mismatched alloca", AI, Call);
3577 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
3578 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
3579 SwiftErrorArg, Call);
3580 Check(ArgI->hasSwiftErrorAttr(),
3581 "swifterror argument for call has mismatched parameter", ArgI,
3585 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
3588 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
3589 "immarg may not apply only to call sites",
Call.getArgOperand(i),
3593 if (
Call.paramHasAttr(i, Attribute::ImmArg)) {
3595 Check(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),
3596 "immarg operand has non-immediate parameter", ArgVal, Call);
3599 if (
Call.paramHasAttr(i, Attribute::Preallocated)) {
3603 bool isMustTail =
Call.isMustTailCall();
3604 Check(hasOB != isMustTail,
3605 "preallocated operand either requires a preallocated bundle or "
3606 "the call to be musttail (but not both)",
3611 if (FTy->isVarArg()) {
3613 bool SawNest =
false;
3614 bool SawReturned =
false;
3616 for (
unsigned Idx = 0;
Idx < FTy->getNumParams(); ++
Idx) {
3617 if (
Attrs.hasParamAttr(
Idx, Attribute::Nest))
3619 if (
Attrs.hasParamAttr(
Idx, Attribute::Returned))
3624 for (
unsigned Idx = FTy->getNumParams();
Idx <
Call.arg_size(); ++
Idx) {
3627 verifyParameterAttrs(ArgAttrs, Ty, &Call);
3630 Check(!SawNest,
"More than one parameter has attribute nest!", Call);
3635 Check(!SawReturned,
"More than one parameter has attribute returned!",
3638 "Incompatible argument and return types for 'returned' "
3646 if (!
Call.getCalledFunction() ||
3647 Call.getCalledFunction()->getIntrinsicID() !=
3648 Intrinsic::experimental_gc_statepoint)
3650 "Attribute 'sret' cannot be used for vararg call arguments!",
3655 "inalloca isn't on the last argument!", Call);
3661 for (
Type *ParamTy : FTy->params()) {
3662 Check(!ParamTy->isMetadataTy(),
3663 "Function has metadata parameter but isn't an intrinsic", Call);
3664 Check(!ParamTy->isTokenTy(),
3665 "Function has token parameter but isn't an intrinsic", Call);
3670 if (!
Call.getCalledFunction()) {
3671 Check(!FTy->getReturnType()->isTokenTy(),
3672 "Return type cannot be token for indirect call!");
3673 Check(!FTy->getReturnType()->isX86_AMXTy(),
3674 "Return type cannot be x86_amx for indirect call!");
3679 visitIntrinsicCall(
ID, Call);
3684 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
3685 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
3686 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
3687 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
3688 FoundAttachedCallBundle =
false;
3689 for (
unsigned i = 0, e =
Call.getNumOperandBundles(); i < e; ++i) {
3693 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles", Call);
3694 FoundDeoptBundle =
true;
3696 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
3698 FoundGCTransitionBundle =
true;
3700 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles", Call);
3701 FoundFuncletBundle =
true;
3703 "Expected exactly one funclet bundle operand", Call);
3705 "Funclet bundle operands should correspond to a FuncletPadInst",
3708 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
3710 FoundCFGuardTargetBundle =
true;
3712 "Expected exactly one cfguardtarget bundle operand", Call);
3714 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles", Call);
3715 FoundPtrauthBundle =
true;
3717 "Expected exactly two ptrauth bundle operands", Call);
3719 BU.
Inputs[0]->getType()->isIntegerTy(32),
3720 "Ptrauth bundle key operand must be an i32 constant", Call);
3722 "Ptrauth bundle discriminator operand must be an i64", Call);
3724 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles", Call);
3725 FoundKCFIBundle =
true;
3726 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
3729 BU.
Inputs[0]->getType()->isIntegerTy(32),
3730 "Kcfi bundle operand must be an i32 constant", Call);
3732 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
3734 FoundPreallocatedBundle =
true;
3736 "Expected exactly one preallocated bundle operand", Call);
3737 auto Input = dyn_cast<IntrinsicInst>(BU.
Inputs.front());
3739 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
3740 "\"preallocated\" argument must be a token from "
3741 "llvm.call.preallocated.setup",
3744 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles", Call);
3745 FoundGCLiveBundle =
true;
3747 Check(!FoundAttachedCallBundle,
3748 "Multiple \"clang.arc.attachedcall\" operand bundles", Call);
3749 FoundAttachedCallBundle =
true;
3750 verifyAttachedCallBundle(Call, BU);
3755 Check(!(
Call.getCalledFunction() && FoundPtrauthBundle),
3756 "Direct call cannot have a ptrauth bundle", Call);
3763 if (
Call.getFunction()->getSubprogram() &&
Call.getCalledFunction() &&
3764 !
Call.getCalledFunction()->isInterposable() &&
3765 !
Call.getCalledFunction()->isDeclaration() &&
3766 Call.getCalledFunction()->getSubprogram())
3768 "inlinable function call in a function with "
3769 "debug info must have a !dbg location",
3772 if (
Call.isInlineAsm())
3773 verifyInlineAsmCall(Call);
3775 ConvergenceVerifyHelper.
visit(Call);
3780void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
3783 Twine(
"inalloca attribute not allowed in ") + Context);
3785 Twine(
"inreg attribute not allowed in ") + Context);
3786 Check(!
Attrs.contains(Attribute::SwiftError),
3787 Twine(
"swifterror attribute not allowed in ") + Context);
3788 Check(!
Attrs.contains(Attribute::Preallocated),
3789 Twine(
"preallocated attribute not allowed in ") + Context);
3791 Twine(
"byref attribute not allowed in ") + Context);
3803 return PL->getAddressSpace() == PR->getAddressSpace();
3808 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3809 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
3810 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
3813 for (
auto AK : ABIAttrs) {
3814 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
3816 Copy.addAttribute(Attr);
3820 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
3821 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
3822 Attrs.hasParamAttr(
I, Attribute::ByRef)))
3823 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
3827void Verifier::verifyMustTailCall(
CallInst &CI) {
3833 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
3834 "cannot guarantee tail call due to mismatched varargs", &CI);
3836 "cannot guarantee tail call due to mismatched return types", &CI);
3840 "cannot guarantee tail call due to mismatched calling conv", &CI);
3846 Value *RetVal = &CI;
3850 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
3852 "bitcast following musttail call must use the call", BI);
3859 Check(Ret,
"musttail call must precede a ret with an optional bitcast", &CI);
3860 Check(!
Ret->getReturnValue() ||
Ret->getReturnValue() == RetVal ||
3861 isa<UndefValue>(
Ret->getReturnValue()),
3862 "musttail call result must be returned", Ret);
3873 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3876 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3878 for (
unsigned I = 0, E = CalleeTy->getNumParams();
I != E; ++
I) {
3881 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3884 Check(!CallerTy->isVarArg(),
Twine(
"cannot guarantee ") + CCName +
3885 " tail call for varargs function");
3893 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
3894 "cannot guarantee tail call due to mismatched parameter counts", &CI);
3895 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3898 "cannot guarantee tail call due to mismatched parameter types", &CI);
3904 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3907 Check(CallerABIAttrs == CalleeABIAttrs,
3908 "cannot guarantee tail call due to mismatched ABI impacting "
3909 "function attributes",
3914void Verifier::visitCallInst(
CallInst &CI) {
3918 verifyMustTailCall(CI);
3927 II.getUnwindDest()->isEHPad(),
3928 "The unwind destination does not have an exception handling instruction!",
3937 Check(
U.getType() ==
U.getOperand(0)->getType(),
3938 "Unary operators must have same type for"
3939 "operands and result!",
3942 switch (
U.getOpcode()) {
3945 case Instruction::FNeg:
3946 Check(
U.getType()->isFPOrFPVectorTy(),
3947 "FNeg operator only works with float types!", &U);
3960 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
3961 "Both operands to a binary operator are not of the same type!", &
B);
3963 switch (
B.getOpcode()) {
3966 case Instruction::Add:
3967 case Instruction::Sub:
3968 case Instruction::Mul:
3969 case Instruction::SDiv:
3970 case Instruction::UDiv:
3971 case Instruction::SRem:
3972 case Instruction::URem:
3973 Check(
B.getType()->isIntOrIntVectorTy(),
3974 "Integer arithmetic operators only work with integral types!", &
B);
3975 Check(
B.getType() ==
B.getOperand(0)->getType(),
3976 "Integer arithmetic operators must have same type "
3977 "for operands and result!",
3982 case Instruction::FAdd:
3983 case Instruction::FSub:
3984 case Instruction::FMul:
3985 case Instruction::FDiv:
3986 case Instruction::FRem:
3987 Check(
B.getType()->isFPOrFPVectorTy(),
3988 "Floating-point arithmetic operators only work with "
3989 "floating-point types!",
3991 Check(
B.getType() ==
B.getOperand(0)->getType(),
3992 "Floating-point arithmetic operators must have same type "
3993 "for operands and result!",
3997 case Instruction::And:
3998 case Instruction::Or:
3999 case Instruction::Xor:
4000 Check(
B.getType()->isIntOrIntVectorTy(),
4001 "Logical operators only work with integral types!", &
B);
4002 Check(
B.getType() ==
B.getOperand(0)->getType(),
4003 "Logical operators must have same type for operands and result!", &
B);
4005 case Instruction::Shl:
4006 case Instruction::LShr:
4007 case Instruction::AShr:
4008 Check(
B.getType()->isIntOrIntVectorTy(),
4009 "Shifts only work with integral types!", &
B);
4010 Check(
B.getType() ==
B.getOperand(0)->getType(),
4011 "Shift return type must be same as operands!", &
B);
4020void Verifier::visitICmpInst(
ICmpInst &IC) {
4024 Check(Op0Ty == Op1Ty,
4025 "Both operands to ICmp instruction are not of the same type!", &IC);
4028 "Invalid operand types for ICmp instruction", &IC);
4035void Verifier::visitFCmpInst(
FCmpInst &FC) {
4037 Type *Op0Ty =
FC.getOperand(0)->getType();
4038 Type *Op1Ty =
FC.getOperand(1)->getType();
4039 Check(Op0Ty == Op1Ty,
4040 "Both operands to FCmp instruction are not of the same type!", &FC);
4045 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
4052 "Invalid extractelement operands!", &EI);
4059 "Invalid insertelement operands!", &IE);
4066 "Invalid shufflevector operands!", &SV);
4071 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4073 Check(isa<PointerType>(TargetTy),
4074 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4075 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4077 if (
auto *STy = dyn_cast<StructType>(
GEP.getSourceElementType())) {
4080 "getelementptr cannot target structure that contains scalable vector"
4087 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4088 "GEP indexes must be integers", &
GEP);
4091 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4093 Check(
GEP.getType()->isPtrOrPtrVectorTy() &&
4094 GEP.getResultElementType() == ElTy,
4095 "GEP is not of right type for indices!", &
GEP, ElTy);
4097 if (
auto *GEPVTy = dyn_cast<VectorType>(
GEP.getType())) {
4100 if (
GEP.getPointerOperandType()->isVectorTy())
4103 cast<VectorType>(
GEP.getPointerOperandType())->getElementCount(),
4104 "Vector GEP result width doesn't match operand's", &
GEP);
4106 Type *IndexTy =
Idx->getType();
4107 if (
auto *IndexVTy = dyn_cast<VectorType>(IndexTy)) {
4109 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4112 "All GEP indices should be of integer type");
4116 if (
auto *PTy = dyn_cast<PointerType>(
GEP.getType())) {
4117 Check(
GEP.getAddressSpace() == PTy->getAddressSpace(),
4118 "GEP address space doesn't match type", &
GEP);
4125 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4131 Type *Ty,
bool IsAbsoluteSymbol) {
4132 unsigned NumOperands =
Range->getNumOperands();
4133 Check(NumOperands % 2 == 0,
"Unfinished range!",
Range);
4134 unsigned NumRanges = NumOperands / 2;
4135 Check(NumRanges >= 1,
"It should have at least one range!",
Range);
4138 for (
unsigned i = 0; i < NumRanges; ++i) {
4140 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i));
4141 Check(
Low,
"The lower limit must be an integer!",
Low);
4143 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i + 1));
4147 "Range types must match instruction type!", &
I);
4155 "The upper and lower limits cannot be the same value", &
I);
4158 Check(!CurRange.isEmptySet() && (IsAbsoluteSymbol || !CurRange.isFullSet()),
4159 "Range must not be empty!",
Range);
4161 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4162 "Intervals are overlapping",
Range);
4163 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4170 if (NumRanges > 2) {
4172 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(0))->getValue();
4174 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(1))->getValue();
4176 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4177 "Intervals are overlapping",
Range);
4185 "precondition violation");
4186 verifyRangeMetadata(
I,
Range, Ty,
false);
4190 unsigned Size =
DL.getTypeSizeInBits(Ty);
4191 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4193 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4196void Verifier::visitLoadInst(
LoadInst &LI) {
4198 Check(PTy,
"Load operand must be a pointer.", &LI);
4202 "huge alignment values are unsupported", &LI);
4204 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4208 "Load cannot have Release ordering", &LI);
4210 "atomic load operand must have integer, pointer, or floating point "
4213 checkAtomicMemAccessSize(ElTy, &LI);
4216 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4222void Verifier::visitStoreInst(
StoreInst &SI) {
4223 PointerType *PTy = dyn_cast<PointerType>(
SI.getOperand(1)->getType());
4224 Check(PTy,
"Store operand must be a pointer.", &SI);
4225 Type *ElTy =
SI.getOperand(0)->getType();
4228 "huge alignment values are unsupported", &SI);
4230 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4231 if (
SI.isAtomic()) {
4234 "Store cannot have Acquire ordering", &SI);
4236 "atomic store operand must have integer, pointer, or floating point "
4239 checkAtomicMemAccessSize(ElTy, &SI);
4242 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4248void Verifier::verifySwiftErrorCall(
CallBase &Call,
4249 const Value *SwiftErrorVal) {
4251 if (
I.value() == SwiftErrorVal) {
4252 Check(
Call.paramHasAttr(
I.index(), Attribute::SwiftError),
4253 "swifterror value when used in a callsite should be marked "
4254 "with swifterror attribute",
4255 SwiftErrorVal, Call);
4260void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4263 for (
const User *U : SwiftErrorVal->
users()) {
4264 Check(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
4266 "swifterror value can only be loaded and stored from, or "
4267 "as a swifterror argument!",
4270 if (
auto StoreI = dyn_cast<StoreInst>(U))
4271 Check(StoreI->getOperand(1) == SwiftErrorVal,
4272 "swifterror value should be the second operand when used "
4275 if (
auto *Call = dyn_cast<CallBase>(U))
4276 verifySwiftErrorCall(*
const_cast<CallBase *
>(Call), SwiftErrorVal);
4280void Verifier::visitAllocaInst(
AllocaInst &AI) {
4283 "Cannot allocate unsized type", &AI);
4285 "Alloca array size must have integer type", &AI);
4288 "huge alignment values are unsupported", &AI);
4293 "swifterror alloca must have pointer type", &AI);
4295 "swifterror alloca must not be array allocation", &AI);
4296 verifySwiftErrorValue(&AI);
4305 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4306 checkAtomicMemAccessSize(ElTy, &CXI);
4312 "atomicrmw instructions cannot be unordered.", &RMWI);
4319 " operand must have integer or floating point type!",
4324 " operand must have floating-point or fixed vector of floating-point "
4330 " operand must have integer type!",
4333 checkAtomicMemAccessSize(ElTy, &RMWI);
4335 "Invalid binary operation!", &RMWI);
4339void Verifier::visitFenceInst(
FenceInst &FI) {
4345 "fence instructions may only have acquire, release, acq_rel, or "
4346 "seq_cst ordering.",
4354 "Invalid ExtractValueInst operands!", &EVI);
4363 "Invalid InsertValueInst operands!", &IVI);
4369 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
4370 return FPI->getParentPad();
4372 return cast<CatchSwitchInst>(EHPad)->getParentPad();
4381 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4383 if (
auto *LPI = dyn_cast<LandingPadInst>(&
I)) {
4388 const auto *
II = dyn_cast<InvokeInst>(PredBB->getTerminator());
4389 Check(
II &&
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4390 "Block containing LandingPadInst must be jumped to "
4391 "only by the unwind edge of an invoke.",
4396 if (
auto *CPI = dyn_cast<CatchPadInst>(&
I)) {
4399 "Block containg CatchPadInst must be jumped to "
4400 "only by its catchswitch.",
4402 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
4403 "Catchswitch cannot unwind to one of its catchpads",
4404 CPI->getCatchSwitch(), CPI);
4415 if (
auto *
II = dyn_cast<InvokeInst>(TI)) {
4416 Check(
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4417 "EH pad must be jumped to via an unwind edge", ToPad,
II);
4419 dyn_cast<Function>(
II->getCalledOperand()->stripPointerCasts());
4420 if (CalledFn && CalledFn->isIntrinsic() &&
II->doesNotThrow() &&
4424 FromPad = Bundle->Inputs[0];
4427 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
4428 FromPad = CRI->getOperand(0);
4429 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
4430 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
4433 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
4439 Check(FromPad != ToPad,
4440 "EH pad cannot handle exceptions raised within it", FromPad, TI);
4441 if (FromPad == ToPadParent) {
4445 Check(!isa<ConstantTokenNone>(FromPad),
4446 "A single unwind edge may only enter one EH pad", TI);
4447 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
4452 Check(isa<FuncletPadInst>(FromPad) || isa<CatchSwitchInst>(FromPad),
4453 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
4462 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
4464 visitEHPadPredecessors(LPI);
4466 if (!LandingPadResultTy)
4467 LandingPadResultTy = LPI.
getType();
4470 "The landingpad instruction should have a consistent result type "
4471 "inside a function.",
4475 Check(
F->hasPersonalityFn(),
4476 "LandingPadInst needs to be in a function with a personality.", &LPI);
4481 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
4487 "Catch operand does not have pointer type!", &LPI);
4489 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
4491 "Filter operand is not an array of constants!", &LPI);
4498void Verifier::visitResumeInst(
ResumeInst &RI) {
4500 "ResumeInst needs to be in a function with a personality.", &RI);
4502 if (!LandingPadResultTy)
4506 "The resume instruction should have a consistent result type "
4507 "inside a function.",
4517 Check(
F->hasPersonalityFn(),
4518 "CatchPadInst needs to be in a function with a personality.", &CPI);
4521 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
4527 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
4529 visitEHPadPredecessors(CPI);
4535 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
4545 Check(
F->hasPersonalityFn(),
4546 "CleanupPadInst needs to be in a function with a personality.", &CPI);
4551 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
4554 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4555 "CleanupPadInst has an invalid parent.", &CPI);
4557 visitEHPadPredecessors(CPI);
4562 User *FirstUser =
nullptr;
4563 Value *FirstUnwindPad =
nullptr;
4567 while (!Worklist.empty()) {
4570 "FuncletPadInst must not be nested within itself", CurrentPad);
4571 Value *UnresolvedAncestorPad =
nullptr;
4574 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
4575 UnwindDest = CRI->getUnwindDest();
4576 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
4581 if (CSI->unwindsToCaller())
4583 UnwindDest = CSI->getUnwindDest();
4584 }
else if (
auto *
II = dyn_cast<InvokeInst>(U)) {
4585 UnwindDest =
II->getUnwindDest();
4586 }
else if (isa<CallInst>(U)) {
4591 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
4595 Worklist.push_back(CPI);
4598 Check(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
4606 if (!cast<Instruction>(UnwindPad)->isEHPad())
4610 if (UnwindParent == CurrentPad)
4616 Value *ExitedPad = CurrentPad;
4619 if (ExitedPad == &FPI) {
4624 UnresolvedAncestorPad = &FPI;
4628 if (ExitedParent == UnwindParent) {
4632 UnresolvedAncestorPad = ExitedParent;
4635 ExitedPad = ExitedParent;
4636 }
while (!isa<ConstantTokenNone>(ExitedPad));
4641 UnresolvedAncestorPad = &FPI;
4648 Check(UnwindPad == FirstUnwindPad,
4649 "Unwind edges out of a funclet "
4650 "pad must have the same unwind "
4652 &FPI, U, FirstUser);
4655 FirstUnwindPad = UnwindPad;
4657 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
4659 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
4664 if (CurrentPad != &FPI)
4667 if (UnresolvedAncestorPad) {
4668 if (CurrentPad == UnresolvedAncestorPad) {
4672 assert(CurrentPad == &FPI);
4680 Value *ResolvedPad = CurrentPad;
4681 while (!Worklist.empty()) {
4682 Value *UnclePad = Worklist.back();
4686 while (ResolvedPad != AncestorPad) {
4688 if (ResolvedParent == UnresolvedAncestorPad) {
4691 ResolvedPad = ResolvedParent;
4695 if (ResolvedPad != AncestorPad)
4698 Worklist.pop_back();
4703 if (FirstUnwindPad) {
4704 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
4705 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
4706 Value *SwitchUnwindPad;
4707 if (SwitchUnwindDest)
4711 Check(SwitchUnwindPad == FirstUnwindPad,
4712 "Unwind edges out of a catch must have the same unwind dest as "
4713 "the parent catchswitch",
4714 &FPI, FirstUser, CatchSwitch);
4725 Check(
F->hasPersonalityFn(),
4726 "CatchSwitchInst needs to be in a function with a personality.",
4732 "CatchSwitchInst not the first non-PHI instruction in the block.",
4736 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4737 "CatchSwitchInst has an invalid parent.", ParentPad);
4741 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4742 "CatchSwitchInst must unwind to an EH block which is not a "
4748 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
4752 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
4755 Check(isa<CatchPadInst>(Handler->getFirstNonPHI()),
4756 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
4759 visitEHPadPredecessors(CatchSwitch);
4765 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
4770 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4771 "CleanupReturnInst must unwind to an EH block which is not a "
4779void Verifier::verifyDominatesUse(
Instruction &
I,
unsigned i) {
4785 if (
II->getNormalDest() ==
II->getUnwindDest())
4796 if (!isa<PHINode>(
I) && InstsInThisBlock.
count(
Op))
4799 const Use &
U =
I.getOperandUse(i);
4800 Check(DT.dominates(
Op, U),
"Instruction does not dominate all uses!",
Op, &
I);
4804 Check(
I.getType()->isPointerTy(),
4805 "dereferenceable, dereferenceable_or_null "
4806 "apply only to pointer types",
4808 Check((isa<LoadInst>(
I) || isa<IntToPtrInst>(
I)),
4809 "dereferenceable, dereferenceable_or_null apply only to load"
4810 " and inttoptr instructions, use attributes for calls or invokes",
4813 "dereferenceable, dereferenceable_or_null "
4814 "take one operand!",
4819 "dereferenceable_or_null metadata value must be an i64!",
4825 "!prof annotations should have no less than 2 operands", MD);
4828 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null", MD);
4830 "expected string with name of the !prof annotation", MD);
4835 if (ProfName ==
"branch_weights") {
4837 if (isa<InvokeInst>(&
I)) {
4838 Check(NumBranchWeights == 1 || NumBranchWeights == 2,
4839 "Wrong number of InvokeInst branch_weights operands", MD);
4841 unsigned ExpectedNumOperands = 0;
4844 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
4845 ExpectedNumOperands =
SI->getNumSuccessors();
4846 else if (isa<CallInst>(&
I))
4847 ExpectedNumOperands = 1;
4849 ExpectedNumOperands = IBI->getNumDestinations();
4850 else if (isa<SelectInst>(&
I))
4851 ExpectedNumOperands = 2;
4852 else if (
CallBrInst *CI = dyn_cast<CallBrInst>(&
I))
4855 CheckFailed(
"!prof branch_weights are not allowed for this instruction",
4858 Check(NumBranchWeights == ExpectedNumOperands,
"Wrong number of operands",
4864 Check(MDO,
"second operand should not be null", MD);
4865 Check(mdconst::dyn_extract<ConstantInt>(MDO),
4866 "!prof brunch_weights operand is not a const int");
4872 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
4873 bool ExpectedInstTy =
4874 isa<AllocaInst>(
I) || isa<StoreInst>(
I) || isa<MemIntrinsic>(
I);
4875 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
4882 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
4885 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(
User))
4886 CheckDI(DAI->getFunction() ==
I.getFunction(),
4887 "dbg.assign not in same function as inst", DAI, &
I);
4891 cast<DIAssignID>(MD)->getAllDbgVariableRecordUsers()) {
4893 "!DIAssignID should only be used by Assign DVRs.", MD, DVR);
4894 CheckDI(DVR->getFunction() ==
I.getFunction(),
4895 "DVRAssign not in same function as inst", DVR, &
I);
4901 "!mmra metadata attached to unexpected instruction kind",
I, MD);
4911 Check(isa<MDTuple>(MD),
"!mmra expected to be a metadata tuple",
I, MD);
4914 "!mmra metadata tuple operand is not an MMRA tag",
I, MDOp.get());
4917void Verifier::visitCallStackMetadata(
MDNode *MD) {
4921 "call stack metadata should have at least 1 operand", MD);
4924 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op),
4925 "call stack metadata operand should be constant integer",
Op);
4929 Check(isa<CallBase>(
I),
"!memprof metadata should only exist on calls", &
I);
4931 "!memprof annotations should have at least 1 metadata operand "
4936 for (
auto &MIBOp : MD->
operands()) {
4937 MDNode *MIB = dyn_cast<MDNode>(MIBOp);
4942 "Each !memprof MemInfoBlock should have at least 2 operands", MIB);
4946 "!memprof MemInfoBlock first operand should not be null", MIB);
4948 "!memprof MemInfoBlock first operand should be an MDNode", MIB);
4950 visitCallStackMetadata(StackMD);
4954 [](
const MDOperand &
Op) { return isa<MDString>(Op); }),
4955 "Not all !memprof MemInfoBlock operands 1 to N-1 are MDString", MIB);
4957 auto &LastOperand = MIB->
operands().back();
4958 Check(isa<MDString>(LastOperand) || mdconst::hasa<ConstantInt>(LastOperand),
4959 "Last !memprof MemInfoBlock operand not MDString or int", MIB);
4964 Check(isa<CallBase>(
I),
"!callsite metadata should only exist on calls", &
I);
4967 visitCallStackMetadata(MD);
4970void Verifier::visitAnnotationMetadata(
MDNode *Annotation) {
4971 Check(isa<MDTuple>(Annotation),
"annotation must be a tuple");
4973 "annotation must have at least one operand");
4975 bool TupleOfStrings =
4976 isa<MDTuple>(
Op.get()) &&
4977 all_of(cast<MDTuple>(
Op)->operands(), [](
auto &Annotation) {
4980 Check(isa<MDString>(
Op.get()) || TupleOfStrings,
4981 "operands must be a string or a tuple of strings");
4985void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
4987 Check(NumOps >= 2 && NumOps <= 3,
"scope must have two or three operands",
4990 "first scope operand must be self-referential or string", MD);
4993 "third scope operand must be string (if used)", MD);
4996 Check(
Domain !=
nullptr,
"second scope operand must be MDNode", MD);
4998 unsigned NumDomainOps =
Domain->getNumOperands();
4999 Check(NumDomainOps >= 1 && NumDomainOps <= 2,
5000 "domain must have one or two operands",
Domain);
5002 isa<MDString>(
Domain->getOperand(0)),
5003 "first domain operand must be self-referential or string",
Domain);
5004 if (NumDomainOps == 2)
5006 "second domain operand must be string (if used)",
Domain);
5009void Verifier::visitAliasScopeListMetadata(
const MDNode *MD) {
5011 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
5012 Check(OpMD !=
nullptr,
"scope list must consist of MDNodes", MD);
5013 visitAliasScopeMetadata(OpMD);
5017void Verifier::visitAccessGroupMetadata(
const MDNode *MD) {
5018 auto IsValidAccessScope = [](
const MDNode *MD) {
5023 if (IsValidAccessScope(MD))
5028 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
5029 Check(OpMD !=
nullptr,
"Access scope list must consist of MDNodes", MD);
5030 Check(IsValidAccessScope(OpMD),
5031 "Access scope list contains invalid access scope", MD);
5039 Check(BB,
"Instruction not embedded in basic block!", &
I);
5041 if (!isa<PHINode>(
I)) {
5042 for (
User *U :
I.users()) {
5043 Check(U != (
User *)&
I || !DT.isReachableFromEntry(BB),
5044 "Only PHI nodes may reference their own value!", &
I);
5049 Check(!
I.getType()->isVoidTy() || !
I.hasName(),
5050 "Instruction has a name, but provides a void value!", &
I);
5054 Check(
I.getType()->isVoidTy() ||
I.getType()->isFirstClassType(),
5055 "Instruction returns a non-scalar type!", &
I);
5059 Check(!
I.getType()->isMetadataTy() || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5060 "Invalid use of metadata!", &
I);
5065 for (
Use &U :
I.uses()) {
5066 if (
Instruction *Used = dyn_cast<Instruction>(
U.getUser()))
5068 "Instruction referencing"
5069 " instruction not embedded in a basic block!",
5072 CheckFailed(
"Use of instruction is not an instruction!", U);
5079 const CallBase *CBI = dyn_cast<CallBase>(&
I);
5081 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
5082 Check(
I.getOperand(i) !=
nullptr,
"Instruction has null operand!", &
I);
5086 if (!
I.getOperand(i)->getType()->isFirstClassType()) {
5087 Check(
false,
"Instruction operands must be first-class values!", &
I);
5090 if (
Function *
F = dyn_cast<Function>(
I.getOperand(i))) {
5095 return CBI && CBI->isOperandBundleOfType(
5103 Check((!
F->isIntrinsic() ||
5104 (CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i)) ||
5105 IsAttachedCallOperand(
F, CBI, i)),
5106 "Cannot take the address of an intrinsic!", &
I);
5107 Check(!
F->isIntrinsic() || isa<CallInst>(
I) ||
5108 F->getIntrinsicID() == Intrinsic::donothing ||
5109 F->getIntrinsicID() == Intrinsic::seh_try_begin ||
5110 F->getIntrinsicID() == Intrinsic::seh_try_end ||
5111 F->getIntrinsicID() == Intrinsic::seh_scope_begin ||
5112 F->getIntrinsicID() == Intrinsic::seh_scope_end ||
5113 F->getIntrinsicID() == Intrinsic::coro_resume ||
5114 F->getIntrinsicID() == Intrinsic::coro_destroy ||
5115 F->getIntrinsicID() == Intrinsic::coro_await_suspend_void ||
5116 F->getIntrinsicID() == Intrinsic::coro_await_suspend_bool ||
5117 F->getIntrinsicID() == Intrinsic::coro_await_suspend_handle ||
5118 F->getIntrinsicID() ==
5119 Intrinsic::experimental_patchpoint_void ||
5120 F->getIntrinsicID() == Intrinsic::experimental_patchpoint ||
5121 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
5122 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
5123 IsAttachedCallOperand(
F, CBI, i),
5124 "Cannot invoke an intrinsic other than donothing, patchpoint, "
5125 "statepoint, coro_resume, coro_destroy or clang.arc.attachedcall",
5127 Check(
F->getParent() == &M,
"Referencing function in another module!", &
I,
5128 &M,
F,
F->getParent());
5129 }
else if (
BasicBlock *OpBB = dyn_cast<BasicBlock>(
I.getOperand(i))) {
5131 "Referring to a basic block in another function!", &
I);
5132 }
else if (
Argument *OpArg = dyn_cast<Argument>(
I.getOperand(i))) {
5134 "Referring to an argument in another function!", &
I);
5135 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(
I.getOperand(i))) {
5136 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5138 }
else if (
Instruction *OpInst = dyn_cast<Instruction>(
I.getOperand(i))) {
5140 "Referring to an instruction in another function!", &
I);
5141 verifyDominatesUse(
I, i);
5142 }
else if (isa<InlineAsm>(
I.getOperand(i))) {
5143 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5144 "Cannot take the address of an inline asm!", &
I);
5145 }
else if (
auto *CPA = dyn_cast<ConstantPtrAuth>(
I.getOperand(i))) {
5146 visitConstantExprsRecursively(CPA);
5147 }
else if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(
I.getOperand(i))) {
5148 if (
CE->getType()->isPtrOrPtrVectorTy()) {
5151 visitConstantExprsRecursively(CE);
5156 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_fpmath)) {
5157 Check(
I.getType()->isFPOrFPVectorTy(),
5158 "fpmath requires a floating point result!", &
I);
5161 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
5162 const APFloat &Accuracy = CFP0->getValueAPF();
5164 "fpmath accuracy must have float type", &
I);
5166 "fpmath accuracy not a positive number!", &
I);
5168 Check(
false,
"invalid fpmath accuracy!", &
I);
5172 if (
MDNode *
Range =
I.getMetadata(LLVMContext::MD_range)) {
5173 Check(isa<LoadInst>(
I) || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5174 "Ranges are only for loads, calls and invokes!", &
I);
5175 visitRangeMetadata(
I,
Range,
I.getType());
5178 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
5179 Check(isa<LoadInst>(
I) || isa<StoreInst>(
I),
5180 "invariant.group metadata is only for loads and stores", &
I);
5183 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_nonnull)) {
5184 Check(
I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
5187 "nonnull applies only to load instructions, use attributes"
5188 " for calls or invokes",
5193 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable))
5194 visitDereferenceableMetadata(
I, MD);
5196 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
5197 visitDereferenceableMetadata(
I, MD);
5199 if (
MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
5202 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
5203 visitAliasScopeListMetadata(MD);
5204 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
5205 visitAliasScopeListMetadata(MD);
5207 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
5208 visitAccessGroupMetadata(MD);
5210 if (
MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
5211 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
5214 "align applies only to load instructions, "
5215 "use attributes for calls or invokes",
5217 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
5218 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
5220 "align metadata value must be an i64!", &
I);
5225 "alignment is larger that implementation defined limit", &
I);
5228 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
5229 visitProfMetadata(
I, MD);
5231 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
5232 visitMemProfMetadata(
I, MD);
5234 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
5235 visitCallsiteMetadata(
I, MD);
5237 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
5238 visitDIAssignIDMetadata(
I, MD);
5240 if (
MDNode *MMRA =
I.getMetadata(LLVMContext::MD_mmra))
5241 visitMMRAMetadata(
I, MMRA);
5243 if (
MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
5244 visitAnnotationMetadata(Annotation);
5246 if (
MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
5247 CheckDI(isa<DILocation>(
N),
"invalid !dbg metadata attachment", &
I,
N);
5248 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
5251 if (
auto *DII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
5252 verifyFragmentExpression(*DII);
5253 verifyNotEntryValue(*DII);
5257 I.getAllMetadata(MDs);
5258 for (
auto Attachment : MDs) {
5259 unsigned Kind = Attachment.first;
5261 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
5262 ? AreDebugLocsAllowed::Yes
5263 : AreDebugLocsAllowed::No;
5264 visitMDNode(*Attachment.second, AllowLocs);
5273 Check(
IF->isDeclaration(),
"Intrinsic functions should never be defined!",
5279 bool IsVarArg = IFTy->isVarArg();
5290 "Intrinsic has incorrect return type!", IF);
5292 "Intrinsic has incorrect argument type!", IF);
5297 "Intrinsic was not defined with variable arguments!", IF);
5300 "Callsite was not defined with variable arguments!", IF);
5309 const std::string ExpectedName =
5311 Check(ExpectedName ==
IF->getName(),
5312 "Intrinsic name not mangled correctly for type arguments! "
5320 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
5321 visitMetadataAsValue(*MD,
Call.getCaller());
5322 if (
auto *Const = dyn_cast<Constant>(V))
5324 "const x86_amx is not allowed in argument!");
5330 case Intrinsic::assume: {
5331 for (
auto &Elem :
Call.bundle_op_infos()) {
5332 unsigned ArgCount = Elem.End - Elem.Begin;
5335 if (Elem.Tag->getKey() ==
"separate_storage") {
5336 Check(ArgCount == 2,
5337 "separate_storage assumptions should have 2 arguments", Call);
5338 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy() &&
5339 Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(),
5340 "arguments to separate_storage assumptions should be pointers",
5344 Check(Elem.Tag->getKey() ==
"ignore" ||
5346 "tags must be valid attribute names", Call);
5349 if (Kind == Attribute::Alignment) {
5350 Check(ArgCount <= 3 && ArgCount >= 2,
5351 "alignment assumptions should have 2 or 3 arguments", Call);
5352 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5353 "first argument should be a pointer", Call);
5354 Check(
Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5355 "second argument should be an integer", Call);
5357 Check(
Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(),
5358 "third argument should be an integer if present", Call);
5361 Check(ArgCount <= 2,
"too many arguments", Call);
5365 Check(ArgCount == 2,
"this attribute should have 2 arguments", Call);
5366 Check(isa<ConstantInt>(
Call.getOperand(Elem.Begin + 1)),
5367 "the second argument should be a constant integral value", Call);
5369 Check((ArgCount) == 1,
"this attribute should have one argument", Call);
5371 Check((ArgCount) == 0,
"this attribute has no argument", Call);
5376 case Intrinsic::ucmp:
5377 case Intrinsic::scmp: {
5378 Type *SrcTy =
Call.getOperand(0)->getType();
5382 "result type must be at least 2 bits wide", Call);
5384 bool IsDestTypeVector = DestTy->
isVectorTy();
5386 "ucmp/scmp argument and result types must both be either vector or "
5389 if (IsDestTypeVector) {
5390 auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
5391 auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
5392 Check(SrcVecLen == DestVecLen,
5393 "return type and arguments must have the same number of "
5399 case Intrinsic::coro_id: {
5400 auto *InfoArg =
Call.getArgOperand(3)->stripPointerCasts();
5401 if (isa<ConstantPointerNull>(InfoArg))
5403 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
5405 "info argument of llvm.coro.id must refer to an initialized "
5408 Check(isa<ConstantStruct>(
Init) || isa<ConstantArray>(
Init),
5409 "info argument of llvm.coro.id must refer to either a struct or "
5413 case Intrinsic::is_fpclass: {
5416 "unsupported bits for llvm.is.fpclass test mask");
5419 case Intrinsic::fptrunc_round: {
5422 auto *MAV = dyn_cast<MetadataAsValue>(
Call.getOperand(1));
5424 MD = MAV->getMetadata();
5426 Check(MD !=
nullptr,
"missing rounding mode argument", Call);
5428 Check(isa<MDString>(MD),
5429 (
"invalid value for llvm.fptrunc.round metadata operand"
5430 " (the operand should be a string)"),
5433 std::optional<RoundingMode> RoundMode =
5436 "unsupported rounding mode argument", Call);
5439#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
5440#include "llvm/IR/VPIntrinsics.def"
5441#undef BEGIN_REGISTER_VP_INTRINSIC
5442 visitVPIntrinsic(cast<VPIntrinsic>(Call));
5444#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
5445 case Intrinsic::INTRINSIC:
5446#include "llvm/IR/ConstrainedOps.def"
5448 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call));
5450 case Intrinsic::dbg_declare:
5451 Check(isa<MetadataAsValue>(
Call.getArgOperand(0)),
5452 "invalid llvm.dbg.declare intrinsic call 1", Call);
5453 visitDbgIntrinsic(
"declare", cast<DbgVariableIntrinsic>(Call));
5455 case Intrinsic::dbg_value:
5456 visitDbgIntrinsic(
"value", cast<DbgVariableIntrinsic>(Call));
5458 case Intrinsic::dbg_assign:
5459 visitDbgIntrinsic(
"assign", cast<DbgVariableIntrinsic>(Call));
5461 case Intrinsic::dbg_label:
5462 visitDbgLabelIntrinsic(
"label", cast<DbgLabelInst>(Call));
5464 case Intrinsic::memcpy:
5465 case Intrinsic::memcpy_inline:
5466 case Intrinsic::memmove:
5467 case Intrinsic::memset:
5468 case Intrinsic::memset_inline: {
5471 case Intrinsic::memcpy_element_unordered_atomic:
5472 case Intrinsic::memmove_element_unordered_atomic:
5473 case Intrinsic::memset_element_unordered_atomic: {
5474 const auto *AMI = cast<AtomicMemIntrinsic>(&Call);
5477 cast<ConstantInt>(AMI->getRawElementSizeInBytes());
5480 "element size of the element-wise atomic memory intrinsic "
5481 "must be a power of 2",
5484 auto IsValidAlignment = [&](
MaybeAlign Alignment) {
5485 return Alignment && ElementSizeVal.
ule(Alignment->value());
5487 Check(IsValidAlignment(AMI->getDestAlign()),
5488 "incorrect alignment of the destination argument", Call);
5489 if (
const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
5490 Check(IsValidAlignment(AMT->getSourceAlign()),
5491 "incorrect alignment of the source argument", Call);
5495 case Intrinsic::call_preallocated_setup: {
5496 auto *NumArgs = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5497 Check(NumArgs !=
nullptr,
5498 "llvm.call.preallocated.setup argument must be a constant");
5499 bool FoundCall =
false;
5501 auto *UseCall = dyn_cast<CallBase>(U);
5502 Check(UseCall !=
nullptr,
5503 "Uses of llvm.call.preallocated.setup must be calls");
5504 const Function *Fn = UseCall->getCalledFunction();
5505 if (Fn && Fn->
getIntrinsicID() == Intrinsic::call_preallocated_arg) {
5506 auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5507 Check(AllocArgIndex !=
nullptr,
5508 "llvm.call.preallocated.alloc arg index must be a constant");
5509 auto AllocArgIndexInt = AllocArgIndex->getValue();
5510 Check(AllocArgIndexInt.sge(0) &&
5511 AllocArgIndexInt.slt(NumArgs->getValue()),
5512 "llvm.call.preallocated.alloc arg index must be between 0 and "
5514 "llvm.call.preallocated.setup's argument count");
5516 Intrinsic::call_preallocated_teardown) {
5519 Check(!FoundCall,
"Can have at most one call corresponding to a "
5520 "llvm.call.preallocated.setup");
5522 size_t NumPreallocatedArgs = 0;
5523 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
5524 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
5525 ++NumPreallocatedArgs;
5528 Check(NumPreallocatedArgs != 0,
5529 "cannot use preallocated intrinsics on a call without "
5530 "preallocated arguments");
5531 Check(NumArgs->equalsInt(NumPreallocatedArgs),
5532 "llvm.call.preallocated.setup arg size must be equal to number "
5533 "of preallocated arguments "
5543 auto PreallocatedBundle =
5545 Check(PreallocatedBundle,
5546 "Use of llvm.call.preallocated.setup outside intrinsics "
5547 "must be in \"preallocated\" operand bundle");
5548 Check(PreallocatedBundle->Inputs.front().get() == &Call,
5549 "preallocated bundle must have token from corresponding "
5550 "llvm.call.preallocated.setup");
5555 case Intrinsic::call_preallocated_arg: {
5556 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5557 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5558 Intrinsic::call_preallocated_setup,
5559 "llvm.call.preallocated.arg token argument must be a "
5560 "llvm.call.preallocated.setup");
5561 Check(
Call.hasFnAttr(Attribute::Preallocated),
5562 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
5563 "call site attribute");
5566 case Intrinsic::call_preallocated_teardown: {
5567 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5568 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5569 Intrinsic::call_preallocated_setup,
5570 "llvm.call.preallocated.teardown token argument must be a "
5571 "llvm.call.preallocated.setup");
5574 case Intrinsic::gcroot:
5575 case Intrinsic::gcwrite:
5576 case Intrinsic::gcread:
5577 if (
ID == Intrinsic::gcroot) {
5579 dyn_cast<AllocaInst>(
Call.getArgOperand(0)->stripPointerCasts());
5580 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.", Call);
5581 Check(isa<Constant>(
Call.getArgOperand(1)),
5582 "llvm.gcroot parameter #2 must be a constant.", Call);
5584 Check(!isa<ConstantPointerNull>(
Call.getArgOperand(1)),
5585 "llvm.gcroot parameter #1 must either be a pointer alloca, "
5586 "or argument #2 must be a non-null constant.",
5591 Check(
Call.getParent()->getParent()->hasGC(),
5592 "Enclosing function does not use GC.", Call);
5594 case Intrinsic::init_trampoline:
5595 Check(isa<Function>(
Call.getArgOperand(1)->stripPointerCasts()),
5596 "llvm.init_trampoline parameter #2 must resolve to a function.",
5599 case Intrinsic::prefetch:
5600 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
5601 "rw argument to llvm.prefetch must be 0-1", Call);
5602 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
5603 "locality argument to llvm.prefetch must be 0-3", Call);
5604 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
5605 "cache type argument to llvm.prefetch must be 0-1", Call);
5607 case Intrinsic::stackprotector:
5608 Check(isa<AllocaInst>(
Call.getArgOperand(1)->stripPointerCasts()),
5609 "llvm.stackprotector parameter #2 must resolve to an alloca.", Call);
5611 case Intrinsic::localescape: {
5615 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
5618 if (isa<ConstantPointerNull>(Arg))
5620 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
5622 "llvm.localescape only accepts static allocas", Call);
5625 SawFrameEscape =
true;
5628 case Intrinsic::localrecover: {
5629 Value *FnArg =
Call.getArgOperand(0)->stripPointerCasts();
5630 Function *Fn = dyn_cast<Function>(FnArg);
5632 "llvm.localrecover first "
5633 "argument must be function defined in this module",
5635 auto *IdxArg = cast<ConstantInt>(
Call.getArgOperand(2));
5636 auto &
Entry = FrameEscapeInfo[Fn];
5638 std::max(
uint64_t(
Entry.second), IdxArg->getLimitedValue(~0U) + 1));
5642 case Intrinsic::experimental_gc_statepoint:
5643 if (
auto *CI = dyn_cast<CallInst>(&Call))
5644 Check(!CI->isInlineAsm(),
5645 "gc.statepoint support for inline assembly unimplemented", CI);
5646 Check(
Call.getParent()->getParent()->hasGC(),
5647 "Enclosing function does not use GC.", Call);
5649 verifyStatepoint(Call);
5651 case Intrinsic::experimental_gc_result: {
5652 Check(
Call.getParent()->getParent()->hasGC(),
5653 "Enclosing function does not use GC.", Call);
5655 auto *Statepoint =
Call.getArgOperand(0);
5656 if (isa<UndefValue>(Statepoint))
5660 const auto *StatepointCall = dyn_cast<CallBase>(Statepoint);
5662 StatepointCall ? StatepointCall->getCalledFunction() :
nullptr;
5665 Intrinsic::experimental_gc_statepoint,
5666 "gc.result operand #1 must be from a statepoint", Call,
5667 Call.getArgOperand(0));
5670 auto *TargetFuncType =
5671 cast<FunctionType>(StatepointCall->getParamElementType(2));
5672 Check(
Call.getType() == TargetFuncType->getReturnType(),
5673 "gc.result result type does not match wrapped callee", Call);
5676 case Intrinsic::experimental_gc_relocate: {
5677 Check(
Call.arg_size() == 3,
"wrong number of arguments", Call);
5679 Check(isa<PointerType>(
Call.getType()->getScalarType()),
5680 "gc.relocate must return a pointer or a vector of pointers", Call);
5686 dyn_cast<LandingPadInst>(
Call.getArgOperand(0))) {
5689 LandingPad->
getParent()->getUniquePredecessor();
5693 Check(InvokeBB,
"safepoints should have unique landingpads",
5694 LandingPad->getParent());
5698 "gc relocate should be linked to a statepoint", InvokeBB);
5703 auto *Token =
Call.getArgOperand(0);
5704 Check(isa<GCStatepointInst>(Token) || isa<UndefValue>(Token),
5705 "gc relocate is incorrectly tied to the statepoint", Call, Token);
5709 const Value &StatepointCall = *cast<GCRelocateInst>(Call).getStatepoint();
5714 "gc.relocate operand #2 must be integer offset", Call);
5717 Check(isa<ConstantInt>(Derived),
5718 "gc.relocate operand #3 must be integer offset", Call);
5720 const uint64_t BaseIndex = cast<ConstantInt>(
Base)->getZExtValue();
5721 const uint64_t DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
5724 if (isa<UndefValue>(StatepointCall))
5726 if (
auto Opt = cast<GCStatepointInst>(StatepointCall)
5728 Check(BaseIndex < Opt->Inputs.size(),
5729 "gc.relocate: statepoint base index out of bounds", Call);
5730 Check(DerivedIndex < Opt->Inputs.size(),
5731 "gc.relocate: statepoint derived index out of bounds", Call);
5739 auto *ResultType =
Call.getType();
5744 "gc.relocate: relocated value must be a pointer", Call);
5745 Check(DerivedType->isPtrOrPtrVectorTy(),
5746 "gc.relocate: relocated value must be a pointer", Call);
5748 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
5749 "gc.relocate: vector relocates to vector and pointer to pointer",
5752 ResultType->getPointerAddressSpace() ==
5753 DerivedType->getPointerAddressSpace(),
5754 "gc.relocate: relocating a pointer shouldn't change its address space",
5758 Check(GC,
"gc.relocate: calling function must have GCStrategy",
5759 Call.getFunction());
5761 auto isGCPtr = [&
GC](
Type *PTy) {
5762 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
5764 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer", Call);
5766 "gc.relocate: relocated value must be a gc pointer", Call);
5767 Check(isGCPtr(DerivedType),
5768 "gc.relocate: relocated value must be a gc pointer", Call);
5772 case Intrinsic::experimental_patchpoint: {
5774 Check(
Call.getType()->isSingleValueType(),
5775 "patchpoint: invalid return type used with anyregcc", Call);
5779 case Intrinsic::eh_exceptioncode:
5780 case Intrinsic::eh_exceptionpointer: {
5781 Check(isa<CatchPadInst>(
Call.getArgOperand(0)),
5782 "eh.exceptionpointer argument must be a catchpad", Call);
5785 case Intrinsic::get_active_lane_mask: {
5787 "get_active_lane_mask: must return a "
5790 auto *ElemTy =
Call.getType()->getScalarType();
5791 Check(ElemTy->isIntegerTy(1),
5792 "get_active_lane_mask: element type is not "
5797 case Intrinsic::experimental_get_vector_length: {
5800 "get_vector_length: VF must be positive", Call);
5803 case Intrinsic::masked_load: {
5804 Check(
Call.getType()->isVectorTy(),
"masked_load: must return a vector",
5809 Value *PassThru =
Call.getArgOperand(3);
5810 Check(
Mask->getType()->isVectorTy(),
"masked_load: mask must be vector",
5813 "masked_load: alignment must be a power of 2", Call);
5815 "masked_load: pass through and return type must match", Call);
5816 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5817 cast<VectorType>(
Call.getType())->getElementCount(),
5818 "masked_load: vector mask must be same length as return", Call);
5821 case Intrinsic::masked_store: {
5825 Check(
Mask->getType()->isVectorTy(),
"masked_store: mask must be vector",
5828 "masked_store: alignment must be a power of 2", Call);
5829 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5830 cast<VectorType>(Val->
getType())->getElementCount(),
5831 "masked_store: vector mask must be same length as value", Call);
5835 case Intrinsic::masked_gather: {
5836 const APInt &Alignment =
5839 "masked_gather: alignment must be 0 or a power of 2", Call);
5842 case Intrinsic::masked_scatter: {
5843 const APInt &Alignment =
5844 cast<ConstantInt>(
Call.getArgOperand(2))->getValue();
5846 "masked_scatter: alignment must be 0 or a power of 2", Call);
5850 case Intrinsic::experimental_guard: {
5851 Check(isa<CallInst>(Call),
"experimental_guard cannot be invoked", Call);
5853 "experimental_guard must have exactly one "
5854 "\"deopt\" operand bundle");
5858 case Intrinsic::experimental_deoptimize: {
5859 Check(isa<CallInst>(Call),
"experimental_deoptimize cannot be invoked",
5862 "experimental_deoptimize must have exactly one "
5863 "\"deopt\" operand bundle");
5864 Check(
Call.getType() ==
Call.getFunction()->getReturnType(),
5865 "experimental_deoptimize return type must match caller return type");
5867 if (isa<CallInst>(Call)) {
5868 auto *RI = dyn_cast<ReturnInst>(
Call.getNextNode());
5870 "calls to experimental_deoptimize must be followed by a return");
5872 if (!
Call.getType()->isVoidTy() && RI)
5873 Check(RI->getReturnValue() == &Call,
5874 "calls to experimental_deoptimize must be followed by a return "
5875 "of the value computed by experimental_deoptimize");
5880 case Intrinsic::vastart: {
5882 "va_start called in a non-varargs function");
5885 case Intrinsic::vector_reduce_and:
5886 case Intrinsic::vector_reduce_or:
5887 case Intrinsic::vector_reduce_xor:
5888 case Intrinsic::vector_reduce_add:
5889 case Intrinsic::vector_reduce_mul:
5890 case Intrinsic::vector_reduce_smax:
5891 case Intrinsic::vector_reduce_smin:
5892 case Intrinsic::vector_reduce_umax:
5893 case Intrinsic::vector_reduce_umin: {
5894 Type *ArgTy =
Call.getArgOperand(0)->getType();
5896 "Intrinsic has incorrect argument type!");
5899 case Intrinsic::vector_reduce_fmax:
5900 case Intrinsic::vector_reduce_fmin: {
5901 Type *ArgTy =
Call.getArgOperand(0)->getType();
5903 "Intrinsic has incorrect argument type!");
5906 case Intrinsic::vector_reduce_fadd:
5907 case Intrinsic::vector_reduce_fmul: {
5910 Type *ArgTy =
Call.getArgOperand(1)->getType();
5912 "Intrinsic has incorrect argument type!");
5915 case Intrinsic::smul_fix:
5916 case Intrinsic::smul_fix_sat:
5917 case Intrinsic::umul_fix:
5918 case Intrinsic::umul_fix_sat:
5919 case Intrinsic::sdiv_fix:
5920 case Intrinsic::sdiv_fix_sat:
5921 case Intrinsic::udiv_fix:
5922 case Intrinsic::udiv_fix_sat: {
5926 "first operand of [us][mul|div]_fix[_sat] must be an int type or "
5929 "second operand of [us][mul|div]_fix[_sat] must be an int type or "
5932 auto *Op3 = cast<ConstantInt>(
Call.getArgOperand(2));
5933 Check(Op3->getType()->isIntegerTy(),
5934 "third operand of [us][mul|div]_fix[_sat] must be an int type");
5935 Check(Op3->getBitWidth() <= 32,
5936 "third operand of [us][mul|div]_fix[_sat] must fit within 32 bits");
5938 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
5939 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
5941 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
5945 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
5946 "to the width of the operands");
5950 case Intrinsic::lrint:
5951 case Intrinsic::llrint: {
5952 Type *ValTy =
Call.getArgOperand(0)->getType();
5956 "llvm.lrint, llvm.llrint: argument must be floating-point or vector "
5957 "of floating-points, and result must be integer or vector of integers",
5960 "llvm.lrint, llvm.llrint: argument and result disagree on vector use",
5963 Check(cast<VectorType>(ValTy)->getElementCount() ==
5964 cast<VectorType>(ResultTy)->getElementCount(),
5965 "llvm.lrint, llvm.llrint: argument must be same length as result",
5970 case Intrinsic::lround:
5971 case Intrinsic::llround: {
5972 Type *ValTy =
Call.getArgOperand(0)->getType();
5975 "Intrinsic does not support vectors", &Call);
5978 case Intrinsic::bswap: {
5981 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &Call);
5984 case Intrinsic::invariant_start: {
5985 ConstantInt *InvariantSize = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5986 Check(InvariantSize &&
5988 "invariant_start parameter must be -1, 0 or a positive number",
5992 case Intrinsic::matrix_multiply:
5993 case Intrinsic::matrix_transpose:
5994 case Intrinsic::matrix_column_major_load:
5995 case Intrinsic::matrix_column_major_store: {
6001 Type *Op0ElemTy =
nullptr;
6002 Type *Op1ElemTy =
nullptr;
6004 case Intrinsic::matrix_multiply: {
6005 NumRows = cast<ConstantInt>(
Call.getArgOperand(2));
6007 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
6008 Check(cast<FixedVectorType>(
Call.getArgOperand(0)->getType())
6009 ->getNumElements() ==
6011 "First argument of a matrix operation does not match specified "
6013 Check(cast<FixedVectorType>(
Call.getArgOperand(1)->getType())
6014 ->getNumElements() ==
6016 "Second argument of a matrix operation does not match specified "
6019 ResultTy = cast<VectorType>(
Call.getType());
6021 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6023 cast<VectorType>(
Call.getArgOperand(1)->getType())->getElementType();
6026 case Intrinsic::matrix_transpose:
6027 NumRows = cast<ConstantInt>(
Call.getArgOperand(1));
6028 NumColumns = cast<ConstantInt>(
Call.getArgOperand(2));
6029 ResultTy = cast<VectorType>(
Call.getType());
6031 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6033 case Intrinsic::matrix_column_major_load: {
6034 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(1));
6035 NumRows = cast<ConstantInt>(
Call.getArgOperand(3));
6036 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
6037 ResultTy = cast<VectorType>(
Call.getType());
6040 case Intrinsic::matrix_column_major_store: {
6041 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(2));
6042 NumRows = cast<ConstantInt>(
Call.getArgOperand(4));
6043 NumColumns = cast<ConstantInt>(
Call.getArgOperand(5));
6044 ResultTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
6046 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6053 Check(ResultTy->getElementType()->isIntegerTy() ||
6054 ResultTy->getElementType()->isFloatingPointTy(),
6055 "Result type must be an integer or floating-point type!", IF);
6058 Check(ResultTy->getElementType() == Op0ElemTy,
6059 "Vector element type mismatch of the result and first operand "
6064 Check(ResultTy->getElementType() == Op1ElemTy,
6065 "Vector element type mismatch of the result and second operand "
6071 "Result of a matrix operation does not fit in the returned vector!");
6075 "Stride must be greater or equal than the number of rows!", IF);
6079 case Intrinsic::vector_splice: {
6081 int64_t
Idx = cast<ConstantInt>(
Call.getArgOperand(2))->getSExtValue();
6082 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
6083 if (
Call.getParent() &&
Call.getParent()->getParent()) {
6085 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
6086 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
6088 Check((
Idx < 0 && std::abs(
Idx) <= KnownMinNumElements) ||
6089 (
Idx >= 0 &&
Idx < KnownMinNumElements),
6090 "The splice index exceeds the range [-VL, VL-1] where VL is the "
6091 "known minimum number of elements in the vector. For scalable "
6092 "vectors the minimum number of elements is determined from "
6097 case Intrinsic::experimental_stepvector: {
6099 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
6100 VecTy->getScalarSizeInBits() >= 8,
6101 "experimental_stepvector only supported for vectors of integers "
6102 "with a bitwidth of at least 8.",
6106 case Intrinsic::vector_insert: {
6110 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6117 Check(VecTy->getElementType() == SubVecTy->getElementType(),
6118 "vector_insert parameters must have the same element "
6122 "vector_insert index must be a constant multiple of "
6123 "the subvector's known minimum vector length.");
6131 "subvector operand of vector_insert would overrun the "
6132 "vector being inserted into.");
6136 case Intrinsic::vector_extract: {
6139 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6147 Check(ResultTy->getElementType() == VecTy->getElementType(),
6148 "vector_extract result must have the same element "
6149 "type as the input vector.",
6152 "vector_extract index must be a constant multiple of "
6153 "the result type's known minimum vector length.");
6161 "vector_extract would overrun.");
6165 case Intrinsic::experimental_vector_partial_reduce_add: {
6166 VectorType *AccTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
6167 VectorType *VecTy = cast<VectorType>(
Call.getArgOperand(1)->getType());
6169 unsigned VecWidth = VecTy->getElementCount().getKnownMinValue();
6170 unsigned AccWidth = AccTy->getElementCount().getKnownMinValue();
6172 Check((VecWidth % AccWidth) == 0,
6173 "Invalid vector widths for partial "
6174 "reduction. The width of the input vector "
6175 "must be a positive integer multiple of "
6176 "the width of the accumulator vector.");
6179 case Intrinsic::experimental_noalias_scope_decl: {
6180 NoAliasScopeDecls.
push_back(cast<IntrinsicInst>(&Call));
6183 case Intrinsic::preserve_array_access_index:
6184 case Intrinsic::preserve_struct_access_index:
6185 case Intrinsic::aarch64_ldaxr:
6186 case Intrinsic::aarch64_ldxr:
6187 case Intrinsic::arm_ldaex:
6188 case Intrinsic::arm_ldrex: {
6189 Type *ElemTy =
Call.getParamElementType(0);
6190 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
6194 case Intrinsic::aarch64_stlxr:
6195 case Intrinsic::aarch64_stxr:
6196 case Intrinsic::arm_stlex:
6197 case Intrinsic::arm_strex: {
6198 Type *ElemTy =
Call.getAttributes().getParamElementType(1);
6200 "Intrinsic requires elementtype attribute on second argument.",
6204 case Intrinsic::aarch64_prefetch: {
6205 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
6206 "write argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6207 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
6208 "target argument to llvm.aarch64.prefetch must be 0-3", Call);
6209 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
6210 "stream argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6211 Check(cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue() < 2,
6212 "isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6215 case Intrinsic::callbr_landingpad: {
6216 const auto *CBR = dyn_cast<CallBrInst>(
Call.getOperand(0));
6217 Check(CBR,
"intrinstic requires callbr operand", &Call);
6224 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &Call);
6228 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
6234 return IndDest == LandingPadBB;
6236 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
6237 "block in indirect destination list",
6240 Check(&
First == &Call,
"No other instructions may proceed intrinsic",
6244 case Intrinsic::amdgcn_cs_chain: {
6245 auto CallerCC =
Call.getCaller()->getCallingConv();
6252 CheckFailed(
"Intrinsic can only be used from functions with the "
6253 "amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6254 "calling conventions",
6259 Check(
Call.paramHasAttr(2, Attribute::InReg),
6260 "SGPR arguments must have the `inreg` attribute", &Call);
6261 Check(!
Call.paramHasAttr(3, Attribute::InReg),
6262 "VGPR arguments must not have the `inreg` attribute", &Call);
6265 case Intrinsic::amdgcn_set_inactive_chain_arg: {
6266 auto CallerCC =
Call.getCaller()->getCallingConv();
6272 CheckFailed(
"Intrinsic can only be used from functions with the "
6273 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6274 "calling conventions",
6279 unsigned InactiveIdx = 1;
6280 Check(!
Call.paramHasAttr(InactiveIdx, Attribute::InReg),
6281 "Value for inactive lanes must not have the `inreg` attribute",
6283 Check(isa<Argument>(
Call.getArgOperand(InactiveIdx)),
6284 "Value for inactive lanes must be a function argument", &Call);
6285 Check(!cast<Argument>(
Call.getArgOperand(InactiveIdx))->hasInRegAttr(),
6286 "Value for inactive lanes must be a VGPR function argument", &Call);
6289 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
6290 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
6292 unsigned RegCount = cast<ConstantInt>(V)->getZExtValue();
6293 Check(RegCount % 8 == 0,
6294 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6295 Check((RegCount >= 24 && RegCount <= 256),
6296 "reg_count argument to nvvm.setmaxnreg must be within [24, 256]");
6299 case Intrinsic::experimental_convergence_entry:
6300 case Intrinsic::experimental_convergence_anchor:
6302 case Intrinsic::experimental_convergence_loop:
6304 case Intrinsic::ptrmask: {
6305 Type *Ty0 =
Call.getArgOperand(0)->getType();
6306 Type *Ty1 =
Call.getArgOperand(1)->getType();
6308 "llvm.ptrmask intrinsic first argument must be pointer or vector "
6313 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
6316 Check(cast<VectorType>(Ty0)->getElementCount() ==
6317 cast<VectorType>(Ty1)->getElementCount(),
6318 "llvm.ptrmask intrinsic arguments must have the same number of "
6322 "llvm.ptrmask intrinsic second argument bitwidth must match "
6323 "pointer index type size of first argument",
6327 case Intrinsic::threadlocal_address: {
6328 const Value &Arg0 = *
Call.getArgOperand(0);
6329 Check(isa<GlobalValue>(Arg0),
6330 "llvm.threadlocal.address first argument must be a GlobalValue");
6331 Check(cast<GlobalValue>(Arg0).isThreadLocal(),
6332 "llvm.threadlocal.address operand isThreadLocal() must be true");
6340 if (
F->hasPersonalityFn() &&
6344 if (BlockEHFuncletColors.
empty())
6348 bool InEHFunclet =
false;
6353 if (dyn_cast_or_null<FuncletPadInst>(ColorFirstBB->getFirstNonPHI()))
6357 bool HasToken =
false;
6358 for (
unsigned I = 0, E =
Call.getNumOperandBundles();
I != E; ++
I)
6364 Check(HasToken,
"Missing funclet token on intrinsic call", &Call);
6377 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
6380 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
6384 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
6390 "invalid #dbg_label intrinsic variable", &DLR, DLR.
getRawLabel());
6394 if (!isa<DILocation>(
N))
6403 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DLR, BB,
F);
6407 if (!LabelSP || !LocSP)
6411 "mismatched subprogram between #dbg_label label and !dbg attachment",
6412 &DLR, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6413 Loc->getScope()->getSubprogram());
6423 "invalid #dbg record type", &DVR, DVR.
getType());
6429 CheckDI(MD && (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6430 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands())),
6431 "invalid #dbg record address/value", &DVR, MD);
6432 if (
auto *VAM = dyn_cast<ValueAsMetadata>(MD))
6433 visitValueAsMetadata(*VAM,
F);
6434 else if (
auto *AL = dyn_cast<DIArgList>(MD))
6435 visitDIArgList(*AL,
F);
6449 AreDebugLocsAllowed::No);
6456 isa<ValueAsMetadata>(RawAddr) ||
6457 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6459 if (
auto *VAM = dyn_cast<ValueAsMetadata>(RawAddr))
6460 visitValueAsMetadata(*VAM,
F);
6463 "invalid #dbg_assign address expression", &DVR,
6470 "inst not in same function as #dbg_assign",
I, &DVR);
6479 CheckDI(isa_and_nonnull<DILocation>(DLNode),
"invalid #dbg record DILocation",
6486 if (!VarSP || !LocSP)
6490 "mismatched subprogram between #dbg record variable and DILocation",
6492 Loc->getScope()->getSubprogram());
6497void Verifier::visitVPIntrinsic(
VPIntrinsic &VPI) {
6498 if (
auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
6499 auto *
RetTy = cast<VectorType>(VPCast->getType());
6500 auto *ValTy = cast<VectorType>(VPCast->getOperand(0)->getType());
6501 Check(
RetTy->getElementCount() == ValTy->getElementCount(),
6502 "VP cast intrinsic first argument and result vector lengths must be "
6506 switch (VPCast->getIntrinsicID()) {
6509 case Intrinsic::vp_trunc:
6511 "llvm.vp.trunc intrinsic first argument and result element type "
6515 "llvm.vp.trunc intrinsic the bit size of first argument must be "
6516 "larger than the bit size of the return type",
6519 case Intrinsic::vp_zext:
6520 case Intrinsic::vp_sext:
6522 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
6523 "element type must be integer",
6526 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
6527 "argument must be smaller than the bit size of the return type",
6530 case Intrinsic::vp_fptoui:
6531 case Intrinsic::vp_fptosi:
6532 case Intrinsic::vp_lrint:
6533 case Intrinsic::vp_llrint:
6536 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
6537 "type must be floating-point and result element type must be integer",
6540 case Intrinsic::vp_uitofp:
6541 case Intrinsic::vp_sitofp:
6544 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
6545 "type must be integer and result element type must be floating-point",
6548 case Intrinsic::vp_fptrunc:
6550 "llvm.vp.fptrunc intrinsic first argument and result element type "
6551 "must be floating-point",
6554 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
6555 "larger than the bit size of the return type",
6558 case Intrinsic::vp_fpext:
6560 "llvm.vp.fpext intrinsic first argument and result element type "
6561 "must be floating-point",
6564 "llvm.vp.fpext intrinsic the bit size of first argument must be "
6565 "smaller than the bit size of the return type",
6568 case Intrinsic::vp_ptrtoint:
6570 "llvm.vp.ptrtoint intrinsic first argument element type must be "
6571 "pointer and result element type must be integer",
6574 case Intrinsic::vp_inttoptr:
6576 "llvm.vp.inttoptr intrinsic first argument element type must be "
6577 "integer and result element type must be pointer",
6583 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6585 "invalid predicate for VP FP comparison intrinsic", &VPI);
6588 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6590 "invalid predicate for VP integer comparison intrinsic", &VPI);
6593 auto TestMask = cast<ConstantInt>(VPI.
getOperand(1));
6595 "unsupported bits for llvm.vp.is.fpclass test mask");
6601 bool HasRoundingMD =
6605 NumOperands += (1 + HasRoundingMD);
6608 if (isa<ConstrainedFPCmpIntrinsic>(FPI))
6611 "invalid arguments for constrained FP intrinsic", &FPI);
6614 case Intrinsic::experimental_constrained_lrint:
6615 case Intrinsic::experimental_constrained_llrint: {
6619 "Intrinsic does not support vectors", &FPI);
6623 case Intrinsic::experimental_constrained_lround:
6624 case Intrinsic::experimental_constrained_llround: {
6628 "Intrinsic does not support vectors", &FPI);
6632 case Intrinsic::experimental_constrained_fcmp:
6633 case Intrinsic::experimental_constrained_fcmps: {
6634 auto Pred = cast<ConstrainedFPCmpIntrinsic>(&FPI)->getPredicate();
6636 "invalid predicate for constrained FP comparison intrinsic", &FPI);
6640 case Intrinsic::experimental_constrained_fptosi:
6641 case Intrinsic::experimental_constrained_fptoui: {
6645 "Intrinsic first argument must be floating point", &FPI);
6646 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6647 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6652 "Intrinsic first argument and result disagree on vector use", &FPI);
6654 "Intrinsic result must be an integer", &FPI);
6655 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6656 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6657 "Intrinsic first argument and result vector lengths must be equal",
6663 case Intrinsic::experimental_constrained_sitofp:
6664 case Intrinsic::experimental_constrained_uitofp: {
6668 "Intrinsic first argument must be integer", &FPI);
6669 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6670 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6675 "Intrinsic first argument and result disagree on vector use", &FPI);
6677 "Intrinsic result must be a floating point", &FPI);
6678 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6679 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6680 "Intrinsic first argument and result vector lengths must be equal",
6686 case Intrinsic::experimental_constrained_fptrunc:
6687 case Intrinsic::experimental_constrained_fpext: {
6693 "Intrinsic first argument must be FP or FP vector", &FPI);
6695 "Intrinsic result must be FP or FP vector", &FPI);
6697 "Intrinsic first argument and result disagree on vector use", &FPI);
6699 Check(cast<VectorType>(OperandTy)->getElementCount() ==
6700 cast<VectorType>(ResultTy)->getElementCount(),
6701 "Intrinsic first argument and result vector lengths must be equal",
6704 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
6706 "Intrinsic first argument's type must be larger than result type",
6710 "Intrinsic first argument's type must be smaller than result type",
6726 "invalid exception behavior argument", &FPI);
6727 if (HasRoundingMD) {
6735 CheckDI(isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6736 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
6737 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
6739 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
6742 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
6745 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(&DII)) {
6746 CheckDI(isa<DIAssignID>(DAI->getRawAssignID()),
6747 "invalid llvm.dbg.assign intrinsic DIAssignID", &DII,
6748 DAI->getRawAssignID());
6749 const auto *RawAddr = DAI->getRawAddress();
6751 isa<ValueAsMetadata>(RawAddr) ||
6752 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6753 "invalid llvm.dbg.assign intrinsic address", &DII,
6754 DAI->getRawAddress());
6755 CheckDI(isa<DIExpression>(DAI->getRawAddressExpression()),
6756 "invalid llvm.dbg.assign intrinsic address expression", &DII,
6757 DAI->getRawAddressExpression());
6760 CheckDI(DAI->getFunction() ==
I->getFunction(),
6761 "inst not in same function as dbg.assign",
I, DAI);
6766 if (!isa<DILocation>(
N))
6775 CheckDI(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
6780 if (!VarSP || !LocSP)
6784 "mismatched subprogram between llvm.dbg." + Kind +
6785 " variable and !dbg attachment",
6787 Loc->getScope()->getSubprogram());
6797 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DLI,
6802 if (!isa<DILocation>(
N))
6811 Check(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment", &DLI,
6816 if (!LabelSP || !LocSP)
6820 "mismatched subprogram between llvm.dbg." + Kind +
6821 " label and !dbg attachment",
6822 &DLI, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6823 Loc->getScope()->getSubprogram());
6828 DIExpression *E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6831 if (!V || !E || !E->
isValid())
6845 if (
V->isArtificial())
6848 verifyFragmentExpression(*V, *Fragment, &
I);
6855 if (!V || !E || !E->
isValid())
6869 if (
V->isArtificial())
6872 verifyFragmentExpression(*V, *Fragment, &DVR);
6875template <
typename ValueOrMetadata>
6876void Verifier::verifyFragmentExpression(
const DIVariable &V,
6878 ValueOrMetadata *
Desc) {
6881 auto VarSize =
V.getSizeInBits();
6887 CheckDI(FragSize + FragOffset <= *VarSize,
6888 "fragment is larger than or outside of variable",
Desc, &V);
6889 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
6900 if (
I.getDebugLoc()->getInlinedAt())
6904 CheckDI(Var,
"dbg intrinsic without variable");
6906 unsigned ArgNo = Var->
getArg();
6912 if (DebugFnArgs.
size() < ArgNo)
6913 DebugFnArgs.
resize(ArgNo,
nullptr);
6915 auto *Prev = DebugFnArgs[ArgNo - 1];
6916 DebugFnArgs[ArgNo - 1] = Var;
6917 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &
I,
6932 CheckDI(Var,
"#dbg record without variable");
6934 unsigned ArgNo = Var->
getArg();
6940 if (DebugFnArgs.
size() < ArgNo)
6941 DebugFnArgs.
resize(ArgNo,
nullptr);
6943 auto *Prev = DebugFnArgs[ArgNo - 1];
6944 DebugFnArgs[ArgNo - 1] = Var;
6945 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DVR,
6950 DIExpression *E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6956 if (isa<ValueAsMetadata>(
I.getRawLocation())) {
6957 Value *VarValue =
I.getVariableLocationOp(0);
6958 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6962 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6963 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6968 "Entry values are only allowed in MIR unless they target a "
6969 "swiftasync Argument",
6981 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6985 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6986 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6991 "Entry values are only allowed in MIR unless they target a "
6992 "swiftasync Argument",
6996void Verifier::verifyCompileUnits() {
7000 if (
M.getContext().isODRUniquingDebugTypes())
7002 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
7005 Listed.
insert(CUs->op_begin(), CUs->op_end());
7006 for (
const auto *
CU : CUVisited)
7011void Verifier::verifyDeoptimizeCallingConvs() {
7012 if (DeoptimizeDeclarations.
empty())
7016 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
7017 Check(
First->getCallingConv() ==
F->getCallingConv(),
7018 "All llvm.experimental.deoptimize declarations must have the same "
7019 "calling convention",
7024void Verifier::verifyAttachedCallBundle(
const CallBase &Call,
7028 Check((FTy->getReturnType()->isPointerTy() ||
7029 (
Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())),
7030 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
7031 "function returning a pointer or a non-returning function that has a "
7036 "operand bundle \"clang.arc.attachedcall\" requires one function as "
7040 auto *Fn = cast<Function>(BU.
Inputs.front());
7044 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
7045 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
7046 "invalid function argument", Call);
7049 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
7050 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
7051 "invalid function argument", Call);
7055void Verifier::verifyNoAliasScopeDecl() {
7056 if (NoAliasScopeDecls.
empty())
7060 for (
auto *
II : NoAliasScopeDecls) {
7061 assert(
II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
7062 "Not a llvm.experimental.noalias.scope.decl ?");
7063 const auto *ScopeListMV = dyn_cast<MetadataAsValue>(
7065 Check(ScopeListMV !=
nullptr,
7066 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
7070 const auto *ScopeListMD = dyn_cast<MDNode>(ScopeListMV->getMetadata());
7071 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode",
II);
7072 Check(ScopeListMD->getNumOperands() == 1,
7073 "!id.scope.list must point to a list with a single scope",
II);
7074 visitAliasScopeListMetadata(ScopeListMD);
7085 const auto *ScopeListMV = cast<MetadataAsValue>(
7087 return &cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
7093 return GetScope(Lhs) < GetScope(Rhs);
7100 auto ItCurrent = NoAliasScopeDecls.begin();
7101 while (ItCurrent != NoAliasScopeDecls.end()) {
7102 auto CurScope = GetScope(*ItCurrent);
7103 auto ItNext = ItCurrent;
7106 }
while (ItNext != NoAliasScopeDecls.end() &&
7107 GetScope(*ItNext) == CurScope);
7112 if (ItNext - ItCurrent < 32)
7116 Check(!DT.dominates(
I, J),
7117 "llvm.experimental.noalias.scope.decl dominates another one "
7118 "with the same scope",
7136 return !V.verify(
F);
7140 bool *BrokenDebugInfo) {
7144 bool Broken =
false;
7146 Broken |= !V.verify(
F);
7148 Broken |= !V.verify();
7149 if (BrokenDebugInfo)
7150 *BrokenDebugInfo = V.hasBrokenDebugInfo();
7161 std::unique_ptr<Verifier> V;
7162 bool FatalErrors =
true;
7167 explicit VerifierLegacyPass(
bool FatalErrors)
7169 FatalErrors(FatalErrors) {
7173 bool doInitialization(
Module &M)
override {
7174 V = std::make_unique<Verifier>(
7180 if (!
V->verify(
F) && FatalErrors) {
7181 errs() <<
"in function " <<
F.getName() <<
'\n';
7187 bool doFinalization(
Module &M)
override {
7188 bool HasErrors =
false;
7190 if (
F.isDeclaration())
7191 HasErrors |= !
V->verify(
F);
7193 HasErrors |= !
V->verify();
7194 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
7207template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
7212#define CheckTBAA(C, ...) \
7215 CheckFailed(__VA_ARGS__); \
7223TBAAVerifier::TBAABaseNodeSummary
7227 CheckFailed(
"Base nodes must have at least two operands", &
I, BaseNode);
7231 auto Itr = TBAABaseNodes.find(BaseNode);
7232 if (Itr != TBAABaseNodes.end())
7235 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
7236 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
7238 assert(InsertResult.second &&
"We just checked!");
7242TBAAVerifier::TBAABaseNodeSummary
7245 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
7249 return isValidScalarTBAANode(BaseNode)
7250 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
7256 CheckFailed(
"Access tag nodes must have the number of operands that is a "
7257 "multiple of 3!", BaseNode);
7262 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
7270 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7272 if (!TypeSizeNode) {
7273 CheckFailed(
"Type size nodes must be constants!", &
I, BaseNode);
7279 if (!IsNewFormat && !isa<MDString>(BaseNode->
getOperand(0))) {
7280 CheckFailed(
"Struct tag nodes have a string as their first operand",
7287 std::optional<APInt> PrevOffset;
7292 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7293 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7295 Idx += NumOpsPerField) {
7298 if (!isa<MDNode>(FieldTy)) {
7299 CheckFailed(
"Incorrect field entry in struct type node!", &
I, BaseNode);
7304 auto *OffsetEntryCI =
7305 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
7306 if (!OffsetEntryCI) {
7307 CheckFailed(
"Offset entries must be constants!", &
I, BaseNode);
7313 BitWidth = OffsetEntryCI->getBitWidth();
7315 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
7317 "Bitwidth between the offsets and struct type entries must match", &
I,
7329 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
7332 CheckFailed(
"Offsets must be increasing!", &
I, BaseNode);
7336 PrevOffset = OffsetEntryCI->getValue();
7339 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7341 if (!MemberSizeNode) {
7342 CheckFailed(
"Member size entries must be constants!", &
I, BaseNode);
7349 return Failed ? InvalidNode
7350 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
7371 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
7372 return Parent && Visited.
insert(Parent).second &&
7376bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
7377 auto ResultIt = TBAAScalarNodes.find(MD);
7378 if (ResultIt != TBAAScalarNodes.end())
7379 return ResultIt->second;
7383 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
7385 assert(InsertResult.second &&
"Just checked!");
7404 return cast<MDNode>(BaseNode->
getOperand(1));
7406 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7407 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7409 Idx += NumOpsPerField) {
7410 auto *OffsetEntryCI =
7411 mdconst::extract<ConstantInt>(BaseNode->
getOperand(
Idx + 1));
7412 if (OffsetEntryCI->getValue().ugt(
Offset)) {
7413 if (
Idx == FirstFieldOpNo) {
7414 CheckFailed(
"Could not find TBAA parent in struct type node", &
I,
7419 unsigned PrevIdx =
Idx - NumOpsPerField;
7420 auto *PrevOffsetEntryCI =
7421 mdconst::extract<ConstantInt>(BaseNode->
getOperand(PrevIdx + 1));
7422 Offset -= PrevOffsetEntryCI->getValue();
7423 return cast<MDNode>(BaseNode->
getOperand(PrevIdx));
7428 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
7430 Offset -= LastOffsetEntryCI->getValue();
7431 return cast<MDNode>(BaseNode->
getOperand(LastIdx));
7435 if (!
Type ||
Type->getNumOperands() < 3)
7440 return isa_and_nonnull<MDNode>(
Type->getOperand(0));
7447 CheckTBAA(isa<LoadInst>(
I) || isa<StoreInst>(
I) || isa<CallInst>(
I) ||
7448 isa<VAArgInst>(
I) || isa<AtomicRMWInst>(
I) ||
7449 isa<AtomicCmpXchgInst>(
I),
7450 "This instruction shall not have a TBAA access tag!", &
I);
7452 bool IsStructPathTBAA =
7456 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
7466 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
7469 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
7474 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7476 CheckTBAA(AccessSizeNode,
"Access size field must be a constant", &
I, MD);
7480 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
7482 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
7485 "Immutability tag on struct tag metadata must be a constant", &
I,
7488 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
7489 "Immutability part of the struct tag metadata must be either 0 or 1",
7494 "Malformed struct tag metadata: base and access-type "
7495 "should be non-null and point to Metadata nodes",
7496 &
I, MD, BaseNode, AccessType);
7499 CheckTBAA(isValidScalarTBAANode(AccessType),
7500 "Access type node must be a valid scalar type", &
I, MD,
7504 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
7505 CheckTBAA(OffsetCI,
"Offset must be constant integer", &
I, MD);
7508 bool SeenAccessTypeInPath =
false;
7513 BaseNode = getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset,
7515 if (!StructPath.
insert(BaseNode).second) {
7516 CheckFailed(
"Cycle detected in struct path", &
I, MD);
7521 unsigned BaseNodeBitWidth;
7522 std::tie(
Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(
I, BaseNode,
7530 SeenAccessTypeInPath |= BaseNode == AccessType;
7532 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
7533 CheckTBAA(
Offset == 0,
"Offset not zero at the point of scalar access",
7537 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
7538 (IsNewFormat && BaseNodeBitWidth == ~0u),
7539 "Access bit-width not the same as description bit-width", &
I, MD,
7540 BaseNodeBitWidth,
Offset.getBitWidth());
7542 if (IsNewFormat && SeenAccessTypeInPath)
7546 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!", &
I,
7551char VerifierLegacyPass::ID = 0;
7552INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
7555 return new VerifierLegacyPass(FatalErrors);
7573 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
7581 if (res.IRBroken && FatalErrors)
This file defines the StringMap class.
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...
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).
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
verify safepoint Safepoint IR Verifier
This file defines the SmallPtrSet class.
This file defines the SmallSet 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 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.
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.
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.
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.
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 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.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
std::string getAsString(bool InAttrGrp=false) const
static Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static bool canUseAsRetAttr(AttrKind Kind)
static bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
static 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 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.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Instruction & front() const
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
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 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.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the parameter 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 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 bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This is an important base class in LLVM.
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.
std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
std::optional< RoundingMode > getRoundingMode() const
unsigned getNonMetadataArgCount() const
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
A pair of DIGlobalVariable and DIExpression.
DIGlobalVariable * getVariable() const
DIExpression * getExpression() const
An imported module (C++ using directive or similar).
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.
Base class for scope-like contexts.
String type, Fortran CHARACTER(n)
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.
Metadata * getRawLabel() const
DILabel * getLabel() const
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.
void print(raw_ostream &O, bool IsForDebug=false) const
DebugLoc getDebugLoc() const
const BasicBlock * getParent() const
This is the common base class for debug info intrinsics for variables.
Metadata * getRawLocation() const
DILocalVariable * getVariable() const
Metadata * getRawVariable() const
Metadata * getRawExpression() 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
Value * getVariableLocationOp(unsigned OpIdx) const
MDNode * getRawVariable() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
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)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
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.
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.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
const std::string & getGC() const
Represents calls to the gc.relocate intrinsic.
Value * getBasePtr() const
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 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
const Function * getResolverFunction() const
static FunctionType * getResolverFunctionType(Type *IFuncValTy)
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
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.
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 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)
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
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 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.
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.
StringRef getName() const
void print(raw_ostream &ROS, bool IsForDebug=false) const
iterator_range< op_iterator > operands()
op_range incoming_values()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static 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 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 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 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 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.
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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.
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.
bool containsScalableVectorType(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Returns true if this struct contains a scalable vector.
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Verify that the TBAA Metadatas are valid.
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.
@ CanBeGlobal
This type may be used as the value type of a global variable.
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.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
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.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isTokenTy() const
Return true if this is 'token'.
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
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
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
LLVMContext & getContext() const
All values hold a context through their type.
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.
Result run(Module &M, ModuleAnalysisManager &)
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.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeMask typeIncompatible(Type *Ty, 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.
@ 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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
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
bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics" that take ...
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
static const int NoAliasScopeDeclScopeArg
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ System
Synchronized with respect to all concurrently executing threads.
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)
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.
@ 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.
bool canInstructionHaveMMRAs(const Instruction &I)
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 are tuples (A,...
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()
void initializeVerifierLegacyPassPass(PassRegistry &)
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.
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,...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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.
FunctionPass * createVerifierPass(bool FatalErrors=true)
@ Dynamic
Denotes mode unknown at compile time.
@ MaskAll
A bitmask that includes all valid flags.
constexpr unsigned BitWidth
std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
std::unique_ptr< GCStrategy > getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
static 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.
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).