96#include "llvm/IR/IntrinsicsAArch64.h"
97#include "llvm/IR/IntrinsicsAMDGPU.h"
98#include "llvm/IR/IntrinsicsARM.h"
99#include "llvm/IR/IntrinsicsNVPTX.h"
100#include "llvm/IR/IntrinsicsWebAssembly.h"
134 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
135 "scopes are not dominating"));
163 void Write(
const Value *V) {
168 void Write(
const Value &V) {
169 if (isa<Instruction>(V)) {
173 V.printAsOperand(*
OS,
true,
MST);
223 void Write(
Type *
T) {
235 void Write(
const APInt *AI) {
241 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
247 *
OS <<
A->getAsString() <<
'\n';
267 for (
const T &V : Vs)
271 template <
typename T1,
typename... Ts>
272 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
277 template <
typename... Ts>
void WriteTs() {}
286 *
OS << Message <<
'\n';
294 template <
typename T1,
typename... Ts>
304 *
OS << Message <<
'\n';
310 template <
typename T1,
typename... Ts>
331 static constexpr unsigned ParamMaxAlignment = 1 << 14;
351 Type *LandingPadResultTy;
358 bool HasDebugInfo =
false;
404 SawFrameEscape(
false), TBAAVerifyHelper(this) {
405 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
412 "An instance of this class only works with a specific module!");
424 if (!BB.empty() && BB.back().isTerminator())
428 *
OS <<
"Basic Block in function '" <<
F.getName()
429 <<
"' does not have terminator!\n";
430 BB.printAsOperand(*
OS,
true, MST);
436 auto FailureCB = [
this](
const Twine &Message) {
444 verifySiblingFuncletUnwinds();
447 ConvergenceVerifyHelper.
verify(DT);
449 InstsInThisBlock.
clear();
451 LandingPadResultTy =
nullptr;
452 SawFrameEscape =
false;
453 SiblingFuncletInfo.
clear();
454 verifyNoAliasScopeDecl();
455 NoAliasScopeDecls.
clear();
466 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
471 verifyFrameRecoverIndices();
473 visitGlobalVariable(GV);
476 visitGlobalAlias(GA);
479 visitGlobalIFunc(GI);
482 visitNamedMDNode(NMD);
485 visitComdat(SMEC.getValue());
489 visitModuleCommandLines();
491 verifyCompileUnits();
493 verifyDeoptimizeCallingConvs();
494 DISubprogramAttachments.
clear();
500 enum class AreDebugLocsAllowed {
No,
Yes };
511 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
515 void visitComdat(
const Comdat &
C);
516 void visitModuleIdents();
517 void visitModuleCommandLines();
518 void visitModuleFlags();
519 void visitModuleFlag(
const MDNode *
Op,
522 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
525 void verifyRangeMetadata(
const Value &V,
const MDNode *Range,
Type *Ty,
526 bool IsAbsoluteSymbol);
530 void visitCallStackMetadata(
MDNode *MD);
535 void visitAnnotationMetadata(
MDNode *Annotation);
536 void visitAliasScopeMetadata(
const MDNode *MD);
537 void visitAliasScopeListMetadata(
const MDNode *MD);
538 void visitAccessGroupMetadata(
const MDNode *MD);
540 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
541#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
542#include "llvm/IR/Metadata.def"
543 void visitDIScope(
const DIScope &
N);
570 void visitPHINode(
PHINode &PN);
579 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
617 void verifySwiftErrorCall(
CallBase &Call,
const Value *SwiftErrorVal);
618 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
620 void verifyMustTailCall(
CallInst &CI);
621 bool verifyAttributeCount(
AttributeList Attrs,
unsigned Params);
627 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
628 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
630 void visitConstantExprsRecursively(
const Constant *EntryC);
632 void verifyInlineAsmCall(
const CallBase &Call);
633 void verifyStatepoint(
const CallBase &Call);
634 void verifyFrameRecoverIndices();
635 void verifySiblingFuncletUnwinds();
639 template <
typename ValueOrMetadata>
640 void verifyFragmentExpression(
const DIVariable &V,
642 ValueOrMetadata *
Desc);
649 void verifyCompileUnits();
653 void verifyDeoptimizeCallingConvs();
655 void verifyAttachedCallBundle(
const CallBase &Call,
659 void verifyNoAliasScopeDecl();
665#define Check(C, ...) \
668 CheckFailed(__VA_ARGS__); \
675#define CheckDI(C, ...) \
678 DebugInfoCheckFailed(__VA_ARGS__); \
686 CheckDI(
I.DebugMarker->MarkedInstr == &
I,
687 "Instruction has invalid DebugMarker", &
I);
688 CheckDI(!isa<PHINode>(&
I) || !
I.hasDbgRecords(),
689 "PHI Node must not have any attached DbgRecords", &
I);
692 "DbgRecord had invalid DebugMarker", &
I, &DR);
695 visitMDNode(*Loc, AreDebugLocsAllowed::Yes);
696 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR)) {
700 verifyFragmentExpression(*DVR);
701 verifyNotEntryValue(*DVR);
702 }
else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
710 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
711 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
724 while (!WorkList.
empty()) {
726 if (!Visited.
insert(Cur).second)
733void Verifier::visitGlobalValue(
const GlobalValue &GV) {
735 "Global is external, but doesn't have external or weak linkage!", &GV);
737 if (
const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
741 "huge alignment values are unsupported", GO);
744 if (
const MDNode *Associated =
745 GO->getMetadata(LLVMContext::MD_associated)) {
746 Check(Associated->getNumOperands() == 1,
747 "associated metadata must have one operand", &GV, Associated);
748 const Metadata *
Op = Associated->getOperand(0).get();
749 Check(
Op,
"associated metadata must have a global value", GO, Associated);
751 const auto *VM = dyn_cast_or_null<ValueAsMetadata>(
Op);
752 Check(VM,
"associated metadata must be ValueAsMetadata", GO, Associated);
754 Check(isa<PointerType>(VM->getValue()->getType()),
755 "associated value must be pointer typed", GV, Associated);
758 Check(isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
759 "associated metadata must point to a GlobalObject", GO, Stripped);
760 Check(Stripped != GO,
761 "global values should not associate to themselves", GO,
767 if (
const MDNode *AbsoluteSymbol =
768 GO->getMetadata(LLVMContext::MD_absolute_symbol)) {
769 verifyRangeMetadata(*GO, AbsoluteSymbol,
DL.getIntPtrType(GO->getType()),
775 "Only global variables can have appending linkage!", &GV);
780 "Only global arrays can have appending linkage!", GVar);
784 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
788 "dllexport GlobalValue must have default or protected visibility",
793 "dllimport GlobalValue must have default visibility", &GV);
794 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
800 "Global is marked as dllimport, but not external", &GV);
805 "GlobalValue with local linkage or non-default "
806 "visibility must be dso_local!",
811 if (!
I->getParent() || !
I->getParent()->getParent())
812 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
814 else if (
I->getParent()->getParent()->getParent() != &M)
815 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
816 I->getParent()->getParent(),
817 I->getParent()->getParent()->getParent());
819 }
else if (
const Function *
F = dyn_cast<Function>(V)) {
820 if (
F->getParent() != &M)
821 CheckFailed(
"Global is used by function in a different module", &GV, &M,
832 "Global variable initializer type does not match global "
839 "'common' global must have a zero initializer!", &GV);
842 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
847 GV.
getName() ==
"llvm.global_dtors")) {
849 "invalid linkage for intrinsic global variable", &GV);
851 "invalid uses of intrinsic global variable", &GV);
856 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
862 "wrong type for intrinsic global variable", &GV);
864 "the third field of the element type is mandatory, "
865 "specify ptr null to migrate from the obsoleted 2-field form");
873 GV.
getName() ==
"llvm.compiler.used")) {
875 "invalid linkage for intrinsic global variable", &GV);
877 "invalid uses of intrinsic global variable", &GV);
880 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
881 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
882 Check(PTy,
"wrong type for intrinsic global variable", &GV);
886 Check(InitArray,
"wrong initalizer for intrinsic global variable",
890 Check(isa<GlobalVariable>(V) || isa<Function>(V) ||
894 Twine(
"members of ") + GV.
getName() +
" must be named", V);
903 for (
auto *MD : MDs) {
904 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
905 visitDIGlobalVariableExpression(*GVE);
907 CheckDI(
false,
"!dbg attachment of global variable must be a "
908 "DIGlobalVariableExpression");
914 "Globals cannot contain scalable types", &GV);
918 if (
auto *TTy = dyn_cast<TargetExtType>(GV.
getValueType()))
920 "Global @" + GV.
getName() +
" has illegal target extension type",
924 visitGlobalValue(GV);
931 visitGlobalValue(GV);
937 visitAliaseeSubExpr(Visited, GA,
C);
943 Check(isa<GlobalValue>(
C) &&
944 cast<GlobalValue>(
C).hasAvailableExternallyLinkage(),
945 "available_externally alias must point to available_externally "
949 if (
const auto *GV = dyn_cast<GlobalValue>(&
C)) {
955 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
956 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
958 Check(!GA2->isInterposable(),
959 "Alias cannot point to an interposable alias", &GA);
967 if (
const auto *CE = dyn_cast<ConstantExpr>(&
C))
968 visitConstantExprsRecursively(CE);
970 for (
const Use &U :
C.operands()) {
972 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
973 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
974 else if (
const auto *C2 = dyn_cast<Constant>(V))
975 visitAliaseeSubExpr(Visited, GA, *C2);
979void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
981 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
982 "weak_odr, external, or available_externally linkage!",
985 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
987 "Alias and aliasee types should match!", &GA);
989 Check(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
990 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
992 visitAliaseeSubExpr(GA, *Aliasee);
994 visitGlobalValue(GA);
997void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
999 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
1000 "weak_odr, or external linkage!",
1005 Check(
Resolver,
"IFunc must have a Function resolver", &GI);
1007 "IFunc resolver must be a definition", &GI);
1013 Check(isa<PointerType>(
Resolver->getFunctionType()->getReturnType()),
1014 "IFunc resolver must return a pointer", &GI);
1016 const Type *ResolverFuncTy =
1019 "IFunc resolver has incorrect type", &GI);
1022void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1027 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1029 if (NMD.
getName() ==
"llvm.dbg.cu")
1030 CheckDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
1035 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1039void Verifier::visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
1042 if (!MDNodes.
insert(&MD).second)
1046 "MDNode context does not match Module context!", &MD);
1051 case Metadata::MDTupleKind:
1053#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1054 case Metadata::CLASS##Kind: \
1055 visit##CLASS(cast<CLASS>(MD)); \
1057#include "llvm/IR/Metadata.def"
1063 Check(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
1065 CheckDI(!isa<DILocation>(
Op) || AllowLocs == AreDebugLocsAllowed::Yes,
1066 "DILocation not allowed within this metadata node", &MD,
Op);
1067 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
1068 visitMDNode(*
N, AllowLocs);
1071 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
1072 visitValueAsMetadata(*V,
nullptr);
1085 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1087 auto *
L = dyn_cast<LocalAsMetadata>(&MD);
1091 Check(
F,
"function-local metadata used outside a function", L);
1096 if (
Instruction *
I = dyn_cast<Instruction>(
L->getValue())) {
1097 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1098 ActualF =
I->getParent()->getParent();
1099 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(
L->getValue()))
1101 else if (
Argument *
A = dyn_cast<Argument>(
L->getValue()))
1102 ActualF =
A->getParent();
1103 assert(ActualF &&
"Unimplemented function local metadata case!");
1105 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1110 visitValueAsMetadata(*VAM,
F);
1115 if (
auto *
N = dyn_cast<MDNode>(MD)) {
1116 visitMDNode(*
N, AreDebugLocsAllowed::No);
1122 if (!MDNodes.
insert(MD).second)
1125 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
1126 visitValueAsMetadata(*V,
F);
1128 if (
auto *AL = dyn_cast<DIArgList>(MD))
1129 visitDIArgList(*AL,
F);
1136void Verifier::visitDILocation(
const DILocation &
N) {
1137 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1138 "location requires a valid scope", &
N,
N.getRawScope());
1139 if (
auto *IA =
N.getRawInlinedAt())
1140 CheckDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
1141 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1142 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1149void Verifier::visitDIScope(
const DIScope &
N) {
1150 if (
auto *
F =
N.getRawFile())
1151 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1154void Verifier::visitDISubrange(
const DISubrange &
N) {
1155 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1157 CheckDI(HasAssumedSizedArraySupport ||
N.getRawCountNode() ||
1158 N.getRawUpperBound(),
1159 "Subrange must contain count or upperBound", &
N);
1160 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1161 "Subrange can have any one of count or upperBound", &
N);
1162 auto *CBound =
N.getRawCountNode();
1163 CheckDI(!CBound || isa<ConstantAsMetadata>(CBound) ||
1164 isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1165 "Count must be signed constant or DIVariable or DIExpression", &
N);
1166 auto Count =
N.getCount();
1167 CheckDI(!Count || !isa<ConstantInt *>(Count) ||
1168 cast<ConstantInt *>(Count)->getSExtValue() >= -1,
1169 "invalid subrange count", &
N);
1170 auto *LBound =
N.getRawLowerBound();
1171 CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||
1172 isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1173 "LowerBound must be signed constant or DIVariable or DIExpression",
1175 auto *UBound =
N.getRawUpperBound();
1176 CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) ||
1177 isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1178 "UpperBound must be signed constant or DIVariable or DIExpression",
1180 auto *Stride =
N.getRawStride();
1181 CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) ||
1182 isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1183 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1187 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1188 CheckDI(
N.getRawCountNode() ||
N.getRawUpperBound(),
1189 "GenericSubrange must contain count or upperBound", &
N);
1190 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1191 "GenericSubrange can have any one of count or upperBound", &
N);
1192 auto *CBound =
N.getRawCountNode();
1193 CheckDI(!CBound || isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1194 "Count must be signed constant or DIVariable or DIExpression", &
N);
1195 auto *LBound =
N.getRawLowerBound();
1196 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1197 CheckDI(isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1198 "LowerBound must be signed constant or DIVariable or DIExpression",
1200 auto *UBound =
N.getRawUpperBound();
1201 CheckDI(!UBound || isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1202 "UpperBound must be signed constant or DIVariable or DIExpression",
1204 auto *Stride =
N.getRawStride();
1205 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1206 CheckDI(isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1207 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1211 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1215 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1216 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1217 N.getTag() == dwarf::DW_TAG_string_type,
1222 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1223 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1231 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1232 N.getTag() == dwarf::DW_TAG_pointer_type ||
1233 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1234 N.getTag() == dwarf::DW_TAG_reference_type ||
1235 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1236 N.getTag() == dwarf::DW_TAG_const_type ||
1237 N.getTag() == dwarf::DW_TAG_immutable_type ||
1238 N.getTag() == dwarf::DW_TAG_volatile_type ||
1239 N.getTag() == dwarf::DW_TAG_restrict_type ||
1240 N.getTag() == dwarf::DW_TAG_atomic_type ||
1241 N.getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ||
1242 N.getTag() == dwarf::DW_TAG_member ||
1243 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1244 N.getTag() == dwarf::DW_TAG_inheritance ||
1245 N.getTag() == dwarf::DW_TAG_friend ||
1246 N.getTag() == dwarf::DW_TAG_set_type ||
1247 N.getTag() == dwarf::DW_TAG_template_alias,
1249 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1250 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1251 N.getRawExtraData());
1254 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1255 if (
auto *
T =
N.getRawBaseType()) {
1256 auto *
Enum = dyn_cast_or_null<DICompositeType>(
T);
1257 auto *
Basic = dyn_cast_or_null<DIBasicType>(
T);
1259 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1260 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1261 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1262 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1263 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1264 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1265 "invalid set base type", &
N,
T);
1271 N.getRawBaseType());
1273 if (
N.getDWARFAddressSpace()) {
1274 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1275 N.getTag() == dwarf::DW_TAG_reference_type ||
1276 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1277 "DWARF address space only applies to pointer or reference types",
1284 return ((Flags & DINode::FlagLValueReference) &&
1285 (Flags & DINode::FlagRValueReference)) ||
1286 ((Flags & DINode::FlagTypePassByValue) &&
1287 (Flags & DINode::FlagTypePassByReference));
1290void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1291 auto *Params = dyn_cast<MDTuple>(&RawParams);
1292 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1294 CheckDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
1303 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1304 N.getTag() == dwarf::DW_TAG_structure_type ||
1305 N.getTag() == dwarf::DW_TAG_union_type ||
1306 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1307 N.getTag() == dwarf::DW_TAG_class_type ||
1308 N.getTag() == dwarf::DW_TAG_variant_part ||
1309 N.getTag() == dwarf::DW_TAG_namelist,
1314 N.getRawBaseType());
1316 CheckDI(!
N.getRawElements() || isa<MDTuple>(
N.getRawElements()),
1317 "invalid composite elements", &
N,
N.getRawElements());
1319 N.getRawVTableHolder());
1321 "invalid reference flags", &
N);
1322 unsigned DIBlockByRefStruct = 1 << 4;
1323 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1324 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1327 const DINodeArray
Elements =
N.getElements();
1329 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1330 "invalid vector, expected one element of type subrange", &
N);
1333 if (
auto *Params =
N.getRawTemplateParams())
1334 visitTemplateParams(
N, *Params);
1336 if (
auto *
D =
N.getRawDiscriminator()) {
1337 CheckDI(isa<DIDerivedType>(
D) &&
N.getTag() == dwarf::DW_TAG_variant_part,
1338 "discriminator can only appear on variant part");
1341 if (
N.getRawDataLocation()) {
1342 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1343 "dataLocation can only appear in array type");
1346 if (
N.getRawAssociated()) {
1347 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1348 "associated can only appear in array type");
1351 if (
N.getRawAllocated()) {
1352 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1353 "allocated can only appear in array type");
1356 if (
N.getRawRank()) {
1357 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1358 "rank can only appear in array type");
1361 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1362 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1367 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1368 if (
auto *Types =
N.getRawTypeArray()) {
1369 CheckDI(isa<MDTuple>(Types),
"invalid composite elements", &
N, Types);
1370 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1371 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1375 "invalid reference flags", &
N);
1378void Verifier::visitDIFile(
const DIFile &
N) {
1379 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1380 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1383 "invalid checksum kind", &
N);
1385 switch (Checksum->Kind) {
1396 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1398 "invalid checksum", &
N);
1403 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1404 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1408 CheckDI(
N.getRawFile() && isa<DIFile>(
N.getRawFile()),
"invalid file", &
N,
1410 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1416 "invalid emission kind", &
N);
1418 if (
auto *Array =
N.getRawEnumTypes()) {
1419 CheckDI(isa<MDTuple>(Array),
"invalid enum list", &
N, Array);
1420 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1421 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
1422 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1423 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1426 if (
auto *Array =
N.getRawRetainedTypes()) {
1427 CheckDI(isa<MDTuple>(Array),
"invalid retained type list", &
N, Array);
1428 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1430 Op && (isa<DIType>(
Op) || (isa<DISubprogram>(
Op) &&
1431 !cast<DISubprogram>(
Op)->isDefinition())),
1432 "invalid retained type", &
N,
Op);
1435 if (
auto *Array =
N.getRawGlobalVariables()) {
1436 CheckDI(isa<MDTuple>(Array),
"invalid global variable list", &
N, Array);
1437 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1438 CheckDI(
Op && (isa<DIGlobalVariableExpression>(
Op)),
1439 "invalid global variable ref", &
N,
Op);
1442 if (
auto *Array =
N.getRawImportedEntities()) {
1443 CheckDI(isa<MDTuple>(Array),
"invalid imported entity list", &
N, Array);
1444 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1445 CheckDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1449 if (
auto *Array =
N.getRawMacros()) {
1450 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1452 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1459 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1461 if (
auto *
F =
N.getRawFile())
1462 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1464 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1465 if (
auto *
T =
N.getRawType())
1466 CheckDI(isa<DISubroutineType>(
T),
"invalid subroutine type", &
N,
T);
1467 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1468 N.getRawContainingType());
1469 if (
auto *Params =
N.getRawTemplateParams())
1470 visitTemplateParams(
N, *Params);
1471 if (
auto *S =
N.getRawDeclaration())
1472 CheckDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1473 "invalid subprogram declaration", &
N, S);
1474 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1475 auto *
Node = dyn_cast<MDTuple>(RawNode);
1476 CheckDI(
Node,
"invalid retained nodes list", &
N, RawNode);
1478 CheckDI(
Op && (isa<DILocalVariable>(
Op) || isa<DILabel>(
Op) ||
1479 isa<DIImportedEntity>(
Op)),
1480 "invalid retained nodes, expected DILocalVariable, DILabel or "
1486 "invalid reference flags", &
N);
1488 auto *Unit =
N.getRawUnit();
1489 if (
N.isDefinition()) {
1491 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1492 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1493 CheckDI(isa<DICompileUnit>(Unit),
"invalid unit type", &
N, Unit);
1496 auto *CT = dyn_cast_or_null<DICompositeType>(
N.getRawScope());
1497 if (CT && CT->getRawIdentifier() &&
1498 M.getContext().isODRUniquingDebugTypes())
1500 "definition subprograms cannot be nested within DICompositeType "
1501 "when enabling ODR",
1505 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1507 "subprogram declaration must not have a declaration field");
1510 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1511 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1512 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1514 CheckDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1518 if (
N.areAllCallsDescribed())
1520 "DIFlagAllCallsDescribed must be attached to a definition");
1524 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1525 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1526 "invalid local scope", &
N,
N.getRawScope());
1527 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1528 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1532 visitDILexicalBlockBase(
N);
1535 "cannot have column info without line info", &
N);
1539 visitDILexicalBlockBase(
N);
1543 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1544 if (
auto *S =
N.getRawScope())
1545 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1546 if (
auto *S =
N.getRawDecl())
1547 CheckDI(isa<DIGlobalVariable>(S),
"invalid declaration", &
N, S);
1551 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1552 if (
auto *S =
N.getRawScope())
1553 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1556void Verifier::visitDIMacro(
const DIMacro &
N) {
1559 "invalid macinfo type", &
N);
1560 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1561 if (!
N.getValue().empty()) {
1562 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1568 "invalid macinfo type", &
N);
1569 if (
auto *
F =
N.getRawFile())
1570 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1572 if (
auto *Array =
N.getRawElements()) {
1573 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1574 for (
Metadata *
Op :
N.getElements()->operands()) {
1575 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1580void Verifier::visitDIModule(
const DIModule &
N) {
1581 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1582 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1590 visitDITemplateParameter(
N);
1592 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1596void Verifier::visitDITemplateValueParameter(
1598 visitDITemplateParameter(
N);
1600 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1601 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1602 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1606void Verifier::visitDIVariable(
const DIVariable &
N) {
1607 if (
auto *S =
N.getRawScope())
1608 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1609 if (
auto *
F =
N.getRawFile())
1610 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1617 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1620 if (
N.isDefinition())
1621 CheckDI(
N.getType(),
"missing global variable type", &
N);
1622 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1623 CheckDI(isa<DIDerivedType>(Member),
1624 "invalid static data member declaration", &
N, Member);
1633 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1634 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1635 "local variable requires a valid scope", &
N,
N.getRawScope());
1636 if (
auto Ty =
N.getType())
1637 CheckDI(!isa<DISubroutineType>(Ty),
"invalid type", &
N,
N.getType());
1640void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1641 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1642 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1645void Verifier::visitDILabel(
const DILabel &
N) {
1646 if (
auto *S =
N.getRawScope())
1647 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1648 if (
auto *
F =
N.getRawFile())
1649 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1651 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1652 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1653 "label requires a valid scope", &
N,
N.getRawScope());
1657 CheckDI(
N.isValid(),
"invalid expression", &
N);
1660void Verifier::visitDIGlobalVariableExpression(
1664 visitDIGlobalVariable(*Var);
1666 visitDIExpression(*Expr);
1667 if (
auto Fragment = Expr->getFragmentInfo())
1668 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1673 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1674 if (
auto *
T =
N.getRawType())
1676 if (
auto *
F =
N.getRawFile())
1677 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1681 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1682 N.getTag() == dwarf::DW_TAG_imported_declaration,
1684 if (
auto *S =
N.getRawScope())
1685 CheckDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1690void Verifier::visitComdat(
const Comdat &
C) {
1693 if (
TT.isOSBinFormatCOFF())
1699void Verifier::visitModuleIdents() {
1700 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1707 Check(
N->getNumOperands() == 1,
1708 "incorrect number of operands in llvm.ident metadata",
N);
1709 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1710 (
"invalid value for llvm.ident metadata entry operand"
1711 "(the operand should be a string)"),
1716void Verifier::visitModuleCommandLines() {
1717 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1725 Check(
N->getNumOperands() == 1,
1726 "incorrect number of operands in llvm.commandline metadata",
N);
1727 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1728 (
"invalid value for llvm.commandline metadata entry operand"
1729 "(the operand should be a string)"),
1734void Verifier::visitModuleFlags() {
1744 visitModuleFlag(MDN, SeenIDs, Requirements);
1745 if (MDN->getNumOperands() != 3)
1747 if (
const auto *FlagName = dyn_cast_or_null<MDString>(MDN->getOperand(1))) {
1748 if (FlagName->getString() ==
"aarch64-elf-pauthabi-platform") {
1749 if (
const auto *PAP =
1750 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1751 PAuthABIPlatform = PAP->getZExtValue();
1752 }
else if (FlagName->getString() ==
"aarch64-elf-pauthabi-version") {
1753 if (
const auto *PAV =
1754 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1755 PAuthABIVersion = PAV->getZExtValue();
1760 if ((PAuthABIPlatform ==
uint64_t(-1)) != (PAuthABIVersion ==
uint64_t(-1)))
1761 CheckFailed(
"either both or no 'aarch64-elf-pauthabi-platform' and "
1762 "'aarch64-elf-pauthabi-version' module flags must be present");
1765 for (
const MDNode *Requirement : Requirements) {
1766 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1767 const Metadata *ReqValue = Requirement->getOperand(1);
1771 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1776 if (
Op->getOperand(2) != ReqValue) {
1777 CheckFailed((
"invalid requirement on flag, "
1778 "flag does not have the required value"),
1786Verifier::visitModuleFlag(
const MDNode *
Op,
1792 "incorrect number of operands in module flag",
Op);
1795 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0)),
1796 "invalid behavior operand in module flag (expected constant integer)",
1799 "invalid behavior operand in module flag (unexpected constant)",
1802 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(1));
1803 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
1815 auto *
V = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1816 Check(V &&
V->getValue().isNonNegative(),
1817 "invalid value for 'min' module flag (expected constant non-negative "
1824 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2)),
1825 "invalid value for 'max' module flag (expected constant integer)",
1835 "invalid value for 'require' module flag (expected metadata pair)",
1838 (
"invalid value for 'require' module flag "
1839 "(first value operand should be a string)"),
1840 Value->getOperand(0));
1851 Check(isa<MDNode>(
Op->getOperand(2)),
1852 "invalid value for 'append'-type module flag "
1853 "(expected a metadata node)",
1863 "module flag identifiers must be unique (or of 'require' type)",
ID);
1866 if (
ID->getString() ==
"wchar_size") {
1868 = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1869 Check(
Value,
"wchar_size metadata requires constant integer argument");
1872 if (
ID->getString() ==
"Linker Options") {
1876 Check(
M.getNamedMetadata(
"llvm.linker.options"),
1877 "'Linker Options' named metadata no longer supported");
1880 if (
ID->getString() ==
"SemanticInterposition") {
1882 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1884 "SemanticInterposition metadata requires constant integer argument");
1887 if (
ID->getString() ==
"CG Profile") {
1888 for (
const MDOperand &MDO : cast<MDNode>(
Op->getOperand(2))->operands())
1889 visitModuleFlagCGProfileEntry(MDO);
1893void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1894 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1897 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1898 Check(
F && isa<Function>(
F->getValue()->stripPointerCasts()),
1899 "expected a Function or null", FuncMDO);
1901 auto Node = dyn_cast_or_null<MDNode>(MDO);
1902 Check(
Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1903 CheckFunction(
Node->getOperand(0));
1904 CheckFunction(
Node->getOperand(1));
1905 auto Count = dyn_cast_or_null<ConstantAsMetadata>(
Node->getOperand(2));
1906 Check(Count && Count->getType()->isIntegerTy(),
1907 "expected an integer constant",
Node->getOperand(2));
1913 if (
A.isStringAttribute()) {
1914#define GET_ATTR_NAMES
1915#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
1916#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1917 if (A.getKindAsString() == #DISPLAY_NAME) { \
1918 auto V = A.getValueAsString(); \
1919 if (!(V.empty() || V == "true" || V == "false")) \
1920 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
1924#include "llvm/IR/Attributes.inc"
1929 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
1940 if (!
Attrs.hasAttributes())
1943 verifyAttributeTypes(Attrs, V);
1946 Check(Attr.isStringAttribute() ||
1948 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
1951 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
1953 "Attribute 'immarg' is incompatible with other attributes", V);
1958 unsigned AttrCount = 0;
1959 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
1960 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
1961 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
1962 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
1963 Attrs.hasAttribute(Attribute::InReg);
1964 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
1965 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
1966 Check(AttrCount <= 1,
1967 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
1968 "'byref', and 'sret' are incompatible!",
1971 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
1972 Attrs.hasAttribute(Attribute::ReadOnly)),
1974 "'inalloca and readonly' are incompatible!",
1977 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
1978 Attrs.hasAttribute(Attribute::Returned)),
1980 "'sret and returned' are incompatible!",
1983 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
1984 Attrs.hasAttribute(Attribute::SExt)),
1986 "'zeroext and signext' are incompatible!",
1989 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1990 Attrs.hasAttribute(Attribute::ReadOnly)),
1992 "'readnone and readonly' are incompatible!",
1995 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1996 Attrs.hasAttribute(Attribute::WriteOnly)),
1998 "'readnone and writeonly' are incompatible!",
2001 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
2002 Attrs.hasAttribute(Attribute::WriteOnly)),
2004 "'readonly and writeonly' are incompatible!",
2007 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
2008 Attrs.hasAttribute(Attribute::AlwaysInline)),
2010 "'noinline and alwaysinline' are incompatible!",
2013 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2014 Attrs.hasAttribute(Attribute::ReadNone)),
2015 "Attributes writable and readnone are incompatible!", V);
2017 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2018 Attrs.hasAttribute(Attribute::ReadOnly)),
2019 "Attributes writable and readonly are incompatible!", V);
2023 if (!Attr.isStringAttribute() &&
2024 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2025 CheckFailed(
"Attribute '" + Attr.getAsString() +
2026 "' applied to incompatible type!", V);
2031 if (isa<PointerType>(Ty)) {
2032 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2033 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2034 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2035 Align MaxAlign(ParamMaxAlignment);
2036 Check(AttrAlign <= MaxAlign,
2037 "Attribute 'align' exceed the max size 2^14", V);
2040 Check(
Attrs.getByValType()->isSized(&Visited),
2041 "Attribute 'byval' does not support unsized types!", V);
2043 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2045 Check(
Attrs.getByRefType()->isSized(&Visited),
2046 "Attribute 'byref' does not support unsized types!", V);
2048 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2050 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2051 "Attribute 'inalloca' does not support unsized types!", V);
2053 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2055 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2056 "Attribute 'preallocated' does not support unsized types!", V);
2060 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2061 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2062 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2065 "Invalid value for 'nofpclass' test mask", V);
2067 if (
Attrs.hasAttribute(Attribute::Range)) {
2069 Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2071 "Range bit width must match type bit width!", V);
2077 if (
Attrs.hasFnAttr(Attr)) {
2081 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2088 const Value *V,
bool IsIntrinsic,
2090 if (
Attrs.isEmpty())
2093 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2095 "Attribute list does not match Module context!", &Attrs, V);
2096 for (
const auto &AttrSet : Attrs) {
2097 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
2098 "Attribute set does not match Module context!", &AttrSet, V);
2099 for (
const auto &
A : AttrSet) {
2100 Check(
A.hasParentContext(Context),
2101 "Attribute does not match Module context!", &
A, V);
2106 bool SawNest =
false;
2107 bool SawReturned =
false;
2108 bool SawSRet =
false;
2109 bool SawSwiftSelf =
false;
2110 bool SawSwiftAsync =
false;
2111 bool SawSwiftError =
false;
2118 "Attribute '" +
RetAttr.getAsString() +
2119 "' does not apply to function return values",
2122 unsigned MaxParameterWidth = 0;
2123 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2125 if (
auto *VT = dyn_cast<FixedVectorType>(Ty)) {
2126 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2127 if (
Size > MaxParameterWidth)
2128 MaxParameterWidth =
Size;
2132 GetMaxParameterWidth(FT->getReturnType());
2133 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2136 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2137 Type *Ty = FT->getParamType(i);
2142 "immarg attribute only applies to intrinsics", V);
2145 "Attribute 'elementtype' can only be applied to intrinsics"
2150 verifyParameterAttrs(ArgAttrs, Ty, V);
2151 GetMaxParameterWidth(Ty);
2154 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2159 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2161 "Incompatible argument and return types for 'returned' attribute",
2167 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2168 Check(i == 0 || i == 1,
2169 "Attribute 'sret' is not on first or second parameter!", V);
2174 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2175 SawSwiftSelf =
true;
2179 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2180 SawSwiftAsync =
true;
2184 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2185 SawSwiftError =
true;
2189 Check(i == FT->getNumParams() - 1,
2190 "inalloca isn't on the last parameter!", V);
2194 if (!
Attrs.hasFnAttrs())
2197 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2201 "Attribute '" +
FnAttr.getAsString() +
2202 "' does not apply to functions!",
2205 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2206 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2207 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2209 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2211 "Attribute 'optnone' requires 'noinline'!", V);
2213 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2214 "Attributes 'optsize and optnone' are incompatible!", V);
2217 "Attributes 'minsize and optnone' are incompatible!", V);
2219 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2220 "Attributes 'optdebug and optnone' are incompatible!", V);
2223 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2224 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2225 "Attributes 'optsize and optdebug' are incompatible!", V);
2228 "Attributes 'minsize and optdebug' are incompatible!", V);
2231 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2233 "Attribute writable and memory without argmem: write are incompatible!",
2236 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2237 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2238 "Attributes 'aarch64_pstate_sm_enabled and "
2239 "aarch64_pstate_sm_compatible' are incompatible!",
2243 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2244 Attrs.hasFnAttr(
"aarch64_inout_za") +
2245 Attrs.hasFnAttr(
"aarch64_out_za") +
2246 Attrs.hasFnAttr(
"aarch64_preserves_za")) <= 1,
2247 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2248 "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive",
2252 (
Attrs.hasFnAttr(
"aarch64_new_zt0") +
Attrs.hasFnAttr(
"aarch64_in_zt0") +
2253 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2254 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2255 Attrs.hasFnAttr(
"aarch64_preserves_zt0")) <= 1,
2256 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2257 "'aarch64_inout_zt0' and 'aarch64_preserves_zt0' are mutually exclusive",
2260 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2263 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2266 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2268 if (ParamNo >= FT->getNumParams()) {
2269 CheckFailed(
"'allocsize' " +
Name +
" argument is out of bounds", V);
2273 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2274 CheckFailed(
"'allocsize' " +
Name +
2275 " argument must refer to an integer parameter",
2283 if (!CheckParam(
"element size",
Args->first))
2286 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2290 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2298 "'allockind()' requires exactly one of alloc, realloc, and free");
2302 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2303 "or aligned modifiers.");
2305 if ((K & ZeroedUninit) == ZeroedUninit)
2306 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2309 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2310 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2312 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2314 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2315 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2316 if (VScaleMax && VScaleMin > VScaleMax)
2317 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2319 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2322 if (
Attrs.hasFnAttr(
"frame-pointer")) {
2324 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none")
2325 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2329 if (MaxParameterWidth >= 512 &&
Attrs.hasFnAttr(
"target-features") &&
2331 StringRef TF =
Attrs.getFnAttr(
"target-features").getValueAsString();
2333 "512-bit vector arguments require 'evex512' for AVX512", V);
2336 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2337 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2338 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2340 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2342 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2343 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2346 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2348 if (S !=
"a_key" && S !=
"b_key")
2349 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2353 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2355 if (S !=
"true" && S !=
"false")
2357 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2360 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2364 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2368void Verifier::verifyFunctionMetadata(
2369 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2370 for (
const auto &Pair : MDs) {
2371 if (Pair.first == LLVMContext::MD_prof) {
2372 MDNode *MD = Pair.second;
2374 "!prof annotations should have no less than 2 operands", MD);
2377 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2380 "expected string with name of the !prof annotation", MD);
2383 Check(ProfName ==
"function_entry_count" ||
2384 ProfName ==
"synthetic_function_entry_count",
2385 "first operand should be 'function_entry_count'"
2386 " or 'synthetic_function_entry_count'",
2390 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2393 "expected integer argument to function_entry_count", MD);
2394 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2395 MDNode *MD = Pair.second;
2397 "!kcfi_type must have exactly one operand", MD);
2398 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2401 "expected a constant operand for !kcfi_type", MD);
2403 Check(isa<ConstantInt>(
C) && isa<IntegerType>(
C->getType()),
2404 "expected a constant integer operand for !kcfi_type", MD);
2406 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2411void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2412 if (!ConstantExprVisited.
insert(EntryC).second)
2416 Stack.push_back(EntryC);
2418 while (!
Stack.empty()) {
2422 if (
const auto *CE = dyn_cast<ConstantExpr>(
C))
2423 visitConstantExpr(CE);
2425 if (
const auto *GV = dyn_cast<GlobalValue>(
C)) {
2428 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2434 for (
const Use &U :
C->operands()) {
2435 const auto *OpC = dyn_cast<Constant>(U);
2438 if (!ConstantExprVisited.
insert(OpC).second)
2440 Stack.push_back(OpC);
2445void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2446 if (
CE->getOpcode() == Instruction::BitCast)
2449 "Invalid bitcast", CE);
2452bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
2455 return Attrs.getNumAttrSets() <= Params + 2;
2458void Verifier::verifyInlineAsmCall(
const CallBase &Call) {
2461 unsigned LabelNo = 0;
2472 if (CI.isIndirect) {
2473 const Value *Arg =
Call.getArgOperand(ArgNo);
2475 "Operand for indirect constraint must have pointer type", &Call);
2478 "Operand for indirect constraint must have elementtype attribute",
2481 Check(!
Call.paramHasAttr(ArgNo, Attribute::ElementType),
2482 "Elementtype attribute can only be applied for indirect "
2490 if (
auto *CallBr = dyn_cast<CallBrInst>(&Call)) {
2491 Check(LabelNo == CallBr->getNumIndirectDests(),
2492 "Number of label constraints does not match number of callbr dests",
2495 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
2501void Verifier::verifyStatepoint(
const CallBase &Call) {
2503 Call.getCalledFunction()->getIntrinsicID() ==
2504 Intrinsic::experimental_gc_statepoint);
2506 Check(!
Call.doesNotAccessMemory() && !
Call.onlyReadsMemory() &&
2507 !
Call.onlyAccessesArgMemory(),
2508 "gc.statepoint must read and write all memory to preserve "
2509 "reordering restrictions required by safepoint semantics",
2512 const int64_t NumPatchBytes =
2513 cast<ConstantInt>(
Call.getArgOperand(1))->getSExtValue();
2514 assert(isInt<32>(NumPatchBytes) &&
"NumPatchBytesV is an i32!");
2515 Check(NumPatchBytes >= 0,
2516 "gc.statepoint number of patchable bytes must be "
2520 Type *TargetElemType =
Call.getParamElementType(2);
2521 Check(TargetElemType,
2522 "gc.statepoint callee argument must have elementtype attribute", Call);
2523 FunctionType *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
2524 Check(TargetFuncType,
2525 "gc.statepoint callee elementtype must be function type", Call);
2527 const int NumCallArgs = cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue();
2528 Check(NumCallArgs >= 0,
2529 "gc.statepoint number of arguments to underlying call "
2532 const int NumParams = (int)TargetFuncType->getNumParams();
2533 if (TargetFuncType->isVarArg()) {
2534 Check(NumCallArgs >= NumParams,
2535 "gc.statepoint mismatch in number of vararg call args", Call);
2538 Check(TargetFuncType->getReturnType()->isVoidTy(),
2539 "gc.statepoint doesn't support wrapping non-void "
2540 "vararg functions yet",
2543 Check(NumCallArgs == NumParams,
2544 "gc.statepoint mismatch in number of call args", Call);
2547 = cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue();
2549 "unknown flag used in gc.statepoint flags argument", Call);
2554 for (
int i = 0; i < NumParams; i++) {
2555 Type *ParamType = TargetFuncType->getParamType(i);
2556 Type *ArgType =
Call.getArgOperand(5 + i)->getType();
2557 Check(ArgType == ParamType,
2558 "gc.statepoint call argument does not match wrapped "
2562 if (TargetFuncType->isVarArg()) {
2565 "Attribute 'sret' cannot be used for vararg call arguments!", Call);
2569 const int EndCallArgsInx = 4 + NumCallArgs;
2571 const Value *NumTransitionArgsV =
Call.getArgOperand(EndCallArgsInx + 1);
2572 Check(isa<ConstantInt>(NumTransitionArgsV),
2573 "gc.statepoint number of transition arguments "
2574 "must be constant integer",
2576 const int NumTransitionArgs =
2577 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
2578 Check(NumTransitionArgs == 0,
2579 "gc.statepoint w/inline transition bundle is deprecated", Call);
2580 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2582 const Value *NumDeoptArgsV =
Call.getArgOperand(EndTransitionArgsInx + 1);
2583 Check(isa<ConstantInt>(NumDeoptArgsV),
2584 "gc.statepoint number of deoptimization arguments "
2585 "must be constant integer",
2587 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
2588 Check(NumDeoptArgs == 0,
2589 "gc.statepoint w/inline deopt operands is deprecated", Call);
2591 const int ExpectedNumArgs = 7 + NumCallArgs;
2592 Check(ExpectedNumArgs == (
int)
Call.arg_size(),
2593 "gc.statepoint too many arguments", Call);
2598 for (
const User *U :
Call.users()) {
2599 const CallInst *UserCall = dyn_cast<const CallInst>(U);
2600 Check(UserCall,
"illegal use of statepoint token", Call, U);
2603 Check(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),
2604 "gc.result or gc.relocate are the only value uses "
2605 "of a gc.statepoint",
2607 if (isa<GCResultInst>(UserCall)) {
2609 "gc.result connected to wrong gc.statepoint", Call, UserCall);
2610 }
else if (isa<GCRelocateInst>(Call)) {
2612 "gc.relocate connected to wrong gc.statepoint", Call, UserCall);
2626void Verifier::verifyFrameRecoverIndices() {
2627 for (
auto &Counts : FrameEscapeInfo) {
2629 unsigned EscapedObjectCount = Counts.second.first;
2630 unsigned MaxRecoveredIndex = Counts.second.second;
2631 Check(MaxRecoveredIndex <= EscapedObjectCount,
2632 "all indices passed to llvm.localrecover must be less than the "
2633 "number of arguments passed to llvm.localescape in the parent "
2641 if (
auto *II = dyn_cast<InvokeInst>(Terminator))
2642 UnwindDest = II->getUnwindDest();
2643 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2644 UnwindDest = CSI->getUnwindDest();
2646 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2650void Verifier::verifySiblingFuncletUnwinds() {
2653 for (
const auto &Pair : SiblingFuncletInfo) {
2655 if (Visited.
count(PredPad))
2661 if (Active.
count(SuccPad)) {
2667 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2668 if (CycleTerminator != CyclePad)
2671 }
while (CyclePad != SuccPad);
2672 Check(
false,
"EH pads can't handle each other's exceptions",
2676 if (!Visited.
insert(SuccPad).second)
2680 auto TermI = SiblingFuncletInfo.find(PredPad);
2681 if (TermI == SiblingFuncletInfo.end())
2694void Verifier::visitFunction(
const Function &
F) {
2695 visitGlobalValue(
F);
2699 unsigned NumArgs =
F.arg_size();
2701 Check(&Context == &
F.getContext(),
2702 "Function context does not match Module context!", &
F);
2704 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
2705 Check(FT->getNumParams() == NumArgs,
2706 "# formal arguments must match # of arguments for function type!", &
F,
2708 Check(
F.getReturnType()->isFirstClassType() ||
2709 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
2710 "Functions cannot return aggregate values!", &
F);
2712 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
2713 "Invalid struct return type!", &
F);
2717 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
2718 "Attribute after last parameter!", &
F);
2720 CheckDI(
F.IsNewDbgInfoFormat ==
F.getParent()->IsNewDbgInfoFormat,
2721 "Function debug format should match parent module", &
F,
2722 F.IsNewDbgInfoFormat,
F.getParent(),
2723 F.getParent()->IsNewDbgInfoFormat);
2725 bool IsIntrinsic =
F.isIntrinsic();
2728 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
2734 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2736 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
2737 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
2742 switch (
F.getCallingConv()) {
2747 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
2748 "Calling convention parameter requires byval", &
F);
2755 Check(
F.getReturnType()->isVoidTy(),
2756 "Calling convention requires void return type", &
F);
2763 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
2765 const unsigned StackAS =
DL.getAllocaAddrSpace();
2768 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
2769 "Calling convention disallows byval", &
F);
2770 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
2771 "Calling convention disallows preallocated", &
F);
2772 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
2773 "Calling convention disallows inalloca", &
F);
2775 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
2778 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
2779 "Calling convention disallows stack byref", &
F);
2793 "Calling convention does not support varargs or "
2794 "perfect forwarding!",
2802 Check(Arg.getType() == FT->getParamType(i),
2803 "Argument value does not match function argument type!", &Arg,
2804 FT->getParamType(i));
2805 Check(Arg.getType()->isFirstClassType(),
2806 "Function arguments must have first-class types!", &Arg);
2808 Check(!Arg.getType()->isMetadataTy(),
2809 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
2810 Check(!Arg.getType()->isTokenTy(),
2811 "Function takes token but isn't an intrinsic", &Arg, &
F);
2812 Check(!Arg.getType()->isX86_AMXTy(),
2813 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
2817 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
2818 verifySwiftErrorValue(&Arg);
2824 Check(!
F.getReturnType()->isTokenTy(),
2825 "Function returns a token but isn't an intrinsic", &
F);
2826 Check(!
F.getReturnType()->isX86_AMXTy(),
2827 "Function returns a x86_amx but isn't an intrinsic", &
F);
2832 F.getAllMetadata(MDs);
2833 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
2834 verifyFunctionMetadata(MDs);
2837 if (
F.hasPersonalityFn()) {
2838 auto *Per = dyn_cast<Function>(
F.getPersonalityFn()->stripPointerCasts());
2840 Check(Per->getParent() ==
F.getParent(),
2841 "Referencing personality function in another module!", &
F,
2842 F.getParent(), Per, Per->getParent());
2846 BlockEHFuncletColors.
clear();
2848 if (
F.isMaterializable()) {
2850 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
2852 }
else if (
F.isDeclaration()) {
2853 for (
const auto &
I : MDs) {
2855 CheckDI(
I.first != LLVMContext::MD_dbg ||
2856 !cast<DISubprogram>(
I.second)->isDistinct(),
2857 "function declaration may only have a unique !dbg attachment",
2859 Check(
I.first != LLVMContext::MD_prof,
2860 "function declaration may not have a !prof attachment", &
F);
2863 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
2865 Check(!
F.hasPersonalityFn(),
2866 "Function declaration shouldn't have a personality routine", &
F);
2870 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
2875 "Entry block to function must not have predecessors!", Entry);
2878 if (Entry->hasAddressTaken()) {
2880 "blockaddress may not be used with the entry block!", Entry);
2883 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
2884 NumKCFIAttachments = 0;
2886 for (
const auto &
I : MDs) {
2888 auto AllowLocs = AreDebugLocsAllowed::No;
2892 case LLVMContext::MD_dbg: {
2893 ++NumDebugAttachments;
2894 CheckDI(NumDebugAttachments == 1,
2895 "function must have a single !dbg attachment", &
F,
I.second);
2896 CheckDI(isa<DISubprogram>(
I.second),
2897 "function !dbg attachment must be a subprogram", &
F,
I.second);
2898 CheckDI(cast<DISubprogram>(
I.second)->isDistinct(),
2899 "function definition may only have a distinct !dbg attachment",
2902 auto *SP = cast<DISubprogram>(
I.second);
2903 const Function *&AttachedTo = DISubprogramAttachments[SP];
2904 CheckDI(!AttachedTo || AttachedTo == &
F,
2905 "DISubprogram attached to more than one function", SP, &
F);
2907 AllowLocs = AreDebugLocsAllowed::Yes;
2910 case LLVMContext::MD_prof:
2911 ++NumProfAttachments;
2912 Check(NumProfAttachments == 1,
2913 "function must have a single !prof attachment", &
F,
I.second);
2915 case LLVMContext::MD_kcfi_type:
2916 ++NumKCFIAttachments;
2917 Check(NumKCFIAttachments == 1,
2918 "function must have a single !kcfi_type attachment", &
F,
2924 visitMDNode(*
I.second, AllowLocs);
2932 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
2934 if (
F.hasAddressTaken(&U,
false,
true,
false,
2936 Check(
false,
"Invalid user of intrinsic instruction!", U);
2940 switch (
F.getIntrinsicID()) {
2941 case Intrinsic::experimental_gc_get_pointer_base: {
2943 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2944 Check(isa<PointerType>(
F.getReturnType()),
2945 "gc.get.pointer.base must return a pointer",
F);
2946 Check(FT->getParamType(0) ==
F.getReturnType(),
2947 "gc.get.pointer.base operand and result must be of the same type",
F);
2950 case Intrinsic::experimental_gc_get_pointer_offset: {
2952 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2953 Check(isa<PointerType>(FT->getParamType(0)),
2954 "gc.get.pointer.offset operand must be a pointer",
F);
2955 Check(
F.getReturnType()->isIntegerTy(),
2956 "gc.get.pointer.offset must return integer",
F);
2961 auto *
N =
F.getSubprogram();
2962 HasDebugInfo = (
N !=
nullptr);
2981 CheckDI(Parent && isa<DILocalScope>(Parent),
2982 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
2985 Check(Scope,
"Failed to find DILocalScope",
DL);
2987 if (!Seen.
insert(Scope).second)
2994 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
2998 "!dbg attachment points at wrong subprogram for function",
N, &
F,
3002 for (
auto &
I : BB) {
3003 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
3005 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
3007 VisitDebugLoc(
I, dyn_cast_or_null<MDNode>(MD->
getOperand(i)));
3008 if (BrokenDebugInfo)
3015void Verifier::visitBasicBlock(
BasicBlock &BB) {
3016 InstsInThisBlock.
clear();
3017 ConvergenceVerifyHelper.
visit(BB);
3024 if (isa<PHINode>(BB.
front())) {
3029 Check(PN.getNumIncomingValues() == Preds.size(),
3030 "PHINode should have one entry for each predecessor of its "
3031 "parent basic block!",
3036 Values.
reserve(PN.getNumIncomingValues());
3037 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3039 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3042 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3047 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3048 Values[i].second == Values[i - 1].second,
3049 "PHI node has multiple entries for the same basic block with "
3050 "different incoming values!",
3051 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3055 Check(Values[i].first == Preds[i],
3056 "PHI node entries do not match predecessors!", &PN,
3057 Values[i].first, Preds[i]);
3065 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3068 CheckDI(BB.IsNewDbgInfoFormat == BB.getParent()->IsNewDbgInfoFormat,
3069 "BB debug format should match parent function", &BB,
3070 BB.IsNewDbgInfoFormat, BB.getParent(),
3071 BB.getParent()->IsNewDbgInfoFormat);
3074 if (BB.IsNewDbgInfoFormat)
3075 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3081 Check(&
I ==
I.getParent()->getTerminator(),
3082 "Terminator found in the middle of a basic block!",
I.getParent());
3086void Verifier::visitBranchInst(
BranchInst &BI) {
3089 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3094void Verifier::visitReturnInst(
ReturnInst &RI) {
3097 if (
F->getReturnType()->isVoidTy())
3099 "Found return instr that returns non-void in Function of void "
3101 &RI,
F->getReturnType());
3104 "Function return type does not match operand "
3105 "type of return inst!",
3106 &RI,
F->getReturnType());
3113void Verifier::visitSwitchInst(
SwitchInst &SI) {
3114 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3117 Type *SwitchTy =
SI.getCondition()->getType();
3119 for (
auto &Case :
SI.cases()) {
3120 Check(isa<ConstantInt>(
SI.getOperand(Case.getCaseIndex() * 2 + 2)),
3121 "Case value is not a constant integer.", &SI);
3122 Check(Case.getCaseValue()->getType() == SwitchTy,
3123 "Switch constants must all be same type as switch value!", &SI);
3125 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3133 "Indirectbr operand must have pointer type!", &BI);
3136 "Indirectbr destinations must all have pointer type!", &BI);
3141void Verifier::visitCallBrInst(
CallBrInst &CBI) {
3142 Check(CBI.
isInlineAsm(),
"Callbr is currently only used for asm-goto!", &CBI);
3144 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3146 verifyInlineAsmCall(CBI);
3150void Verifier::visitSelectInst(
SelectInst &SI) {
3153 "Invalid operands for select instruction!", &SI);
3155 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3156 "Select values must have same type as select instruction!", &SI);
3164 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3169 Type *SrcTy =
I.getOperand(0)->getType();
3170 Type *DestTy =
I.getType();
3179 "trunc source and destination must both be a vector or neither", &
I);
3180 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3185void Verifier::visitZExtInst(
ZExtInst &
I) {
3187 Type *SrcTy =
I.getOperand(0)->getType();
3188 Type *DestTy =
I.getType();
3194 "zext source and destination must both be a vector or neither", &
I);
3198 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3203void Verifier::visitSExtInst(
SExtInst &
I) {
3205 Type *SrcTy =
I.getOperand(0)->getType();
3206 Type *DestTy =
I.getType();
3215 "sext source and destination must both be a vector or neither", &
I);
3216 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3223 Type *SrcTy =
I.getOperand(0)->getType();
3224 Type *DestTy =
I.getType();
3232 "fptrunc source and destination must both be a vector or neither", &
I);
3233 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3240 Type *SrcTy =
I.getOperand(0)->getType();
3241 Type *DestTy =
I.getType();
3250 "fpext source and destination must both be a vector or neither", &
I);
3251 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3258 Type *SrcTy =
I.getOperand(0)->getType();
3259 Type *DestTy =
I.getType();
3264 Check(SrcVec == DstVec,
3265 "UIToFP source and dest must both be vector or scalar", &
I);
3267 "UIToFP source must be integer or integer vector", &
I);
3271 if (SrcVec && DstVec)
3272 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3273 cast<VectorType>(DestTy)->getElementCount(),
3274 "UIToFP source and dest vector length mismatch", &
I);
3281 Type *SrcTy =
I.getOperand(0)->getType();
3282 Type *DestTy =
I.getType();
3287 Check(SrcVec == DstVec,
3288 "SIToFP source and dest must both be vector or scalar", &
I);
3290 "SIToFP source must be integer or integer vector", &
I);
3294 if (SrcVec && DstVec)
3295 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3296 cast<VectorType>(DestTy)->getElementCount(),
3297 "SIToFP source and dest vector length mismatch", &
I);
3304 Type *SrcTy =
I.getOperand(0)->getType();
3305 Type *DestTy =
I.getType();
3310 Check(SrcVec == DstVec,
3311 "FPToUI source and dest must both be vector or scalar", &
I);
3314 "FPToUI result must be integer or integer vector", &
I);
3316 if (SrcVec && DstVec)
3317 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3318 cast<VectorType>(DestTy)->getElementCount(),
3319 "FPToUI source and dest vector length mismatch", &
I);
3326 Type *SrcTy =
I.getOperand(0)->getType();
3327 Type *DestTy =
I.getType();
3332 Check(SrcVec == DstVec,
3333 "FPToSI source and dest must both be vector or scalar", &
I);
3336 "FPToSI result must be integer or integer vector", &
I);
3338 if (SrcVec && DstVec)
3339 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3340 cast<VectorType>(DestTy)->getElementCount(),
3341 "FPToSI source and dest vector length mismatch", &
I);
3348 Type *SrcTy =
I.getOperand(0)->getType();
3349 Type *DestTy =
I.getType();
3358 auto *VSrc = cast<VectorType>(SrcTy);
3359 auto *VDest = cast<VectorType>(DestTy);
3360 Check(VSrc->getElementCount() == VDest->getElementCount(),
3361 "PtrToInt Vector width mismatch", &
I);
3369 Type *SrcTy =
I.getOperand(0)->getType();
3370 Type *DestTy =
I.getType();
3378 auto *VSrc = cast<VectorType>(SrcTy);
3379 auto *VDest = cast<VectorType>(DestTy);
3380 Check(VSrc->getElementCount() == VDest->getElementCount(),
3381 "IntToPtr Vector width mismatch", &
I);
3389 "Invalid bitcast", &
I);
3394 Type *SrcTy =
I.getOperand(0)->getType();
3395 Type *DestTy =
I.getType();
3402 "AddrSpaceCast must be between different address spaces", &
I);
3403 if (
auto *SrcVTy = dyn_cast<VectorType>(SrcTy))
3404 Check(SrcVTy->getElementCount() ==
3405 cast<VectorType>(DestTy)->getElementCount(),
3406 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3412void Verifier::visitPHINode(
PHINode &PN) {
3419 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
3428 "PHI node operands are not the same type as the result!", &PN);
3436void Verifier::visitCallBase(
CallBase &Call) {
3437 Check(
Call.getCalledOperand()->getType()->isPointerTy(),
3438 "Called function must be a pointer!", Call);
3442 if (FTy->isVarArg())
3443 Check(
Call.arg_size() >= FTy->getNumParams(),
3444 "Called function requires more parameters than were provided!", Call);
3446 Check(
Call.arg_size() == FTy->getNumParams(),
3447 "Incorrect number of arguments passed to called function!", Call);
3450 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3451 Check(
Call.getArgOperand(i)->getType() == FTy->getParamType(i),
3452 "Call parameter type does not match function signature!",
3453 Call.getArgOperand(i), FTy->getParamType(i), Call);
3457 Check(verifyAttributeCount(Attrs,
Call.arg_size()),
3458 "Attribute after last parameter!", Call);
3461 dyn_cast<Function>(
Call.getCalledOperand()->stripPointerCasts());
3465 "Intrinsic called with incompatible signature", Call);
3469 auto CC =
Call.getCallingConv();
3472 "Direct calls to amdgpu_cs_chain/amdgpu_cs_chain_preserve functions "
3473 "not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.",
3476 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
3479 Align ABIAlign =
DL.getABITypeAlign(Ty);
3480 Align MaxAlign(ParamMaxAlignment);
3481 Check(ABIAlign <= MaxAlign,
3482 "Incorrect alignment of " + Message +
" to called function!", Call);
3486 VerifyTypeAlign(FTy->getReturnType(),
"return type");
3487 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3488 Type *Ty = FTy->getParamType(i);
3489 VerifyTypeAlign(Ty,
"argument passed");
3493 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
3497 "speculatable attribute may not apply to call sites", Call);
3500 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
3501 Check(
Call.getCalledFunction()->getIntrinsicID() ==
3502 Intrinsic::call_preallocated_arg,
3503 "preallocated as a call site attribute can only be on "
3504 "llvm.call.preallocated.arg");
3508 verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic,
Call.isInlineAsm());
3513 if (
Call.hasInAllocaArgument()) {
3514 Value *InAllocaArg =
Call.getArgOperand(FTy->getNumParams() - 1);
3516 Check(AI->isUsedWithInAlloca(),
3517 "inalloca argument for call has mismatched alloca", AI, Call);
3523 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3524 if (
Call.paramHasAttr(i, Attribute::SwiftError)) {
3525 Value *SwiftErrorArg =
Call.getArgOperand(i);
3527 Check(AI->isSwiftError(),
3528 "swifterror argument for call has mismatched alloca", AI, Call);
3531 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
3532 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
3533 SwiftErrorArg, Call);
3534 Check(ArgI->hasSwiftErrorAttr(),
3535 "swifterror argument for call has mismatched parameter", ArgI,
3539 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
3542 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
3543 "immarg may not apply only to call sites",
Call.getArgOperand(i),
3547 if (
Call.paramHasAttr(i, Attribute::ImmArg)) {
3549 Check(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),
3550 "immarg operand has non-immediate parameter", ArgVal, Call);
3553 if (
Call.paramHasAttr(i, Attribute::Preallocated)) {
3557 bool isMustTail =
Call.isMustTailCall();
3558 Check(hasOB != isMustTail,
3559 "preallocated operand either requires a preallocated bundle or "
3560 "the call to be musttail (but not both)",
3565 if (FTy->isVarArg()) {
3567 bool SawNest =
false;
3568 bool SawReturned =
false;
3570 for (
unsigned Idx = 0;
Idx < FTy->getNumParams(); ++
Idx) {
3571 if (
Attrs.hasParamAttr(
Idx, Attribute::Nest))
3573 if (
Attrs.hasParamAttr(
Idx, Attribute::Returned))
3578 for (
unsigned Idx = FTy->getNumParams();
Idx <
Call.arg_size(); ++
Idx) {
3581 verifyParameterAttrs(ArgAttrs, Ty, &Call);
3584 Check(!SawNest,
"More than one parameter has attribute nest!", Call);
3589 Check(!SawReturned,
"More than one parameter has attribute returned!",
3592 "Incompatible argument and return types for 'returned' "
3600 if (!
Call.getCalledFunction() ||
3601 Call.getCalledFunction()->getIntrinsicID() !=
3602 Intrinsic::experimental_gc_statepoint)
3604 "Attribute 'sret' cannot be used for vararg call arguments!",
3609 "inalloca isn't on the last argument!", Call);
3615 for (
Type *ParamTy : FTy->params()) {
3616 Check(!ParamTy->isMetadataTy(),
3617 "Function has metadata parameter but isn't an intrinsic", Call);
3618 Check(!ParamTy->isTokenTy(),
3619 "Function has token parameter but isn't an intrinsic", Call);
3624 if (!
Call.getCalledFunction()) {
3625 Check(!FTy->getReturnType()->isTokenTy(),
3626 "Return type cannot be token for indirect call!");
3627 Check(!FTy->getReturnType()->isX86_AMXTy(),
3628 "Return type cannot be x86_amx for indirect call!");
3633 visitIntrinsicCall(
ID, Call);
3638 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
3639 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
3640 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
3641 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
3642 FoundAttachedCallBundle =
false;
3643 for (
unsigned i = 0, e =
Call.getNumOperandBundles(); i < e; ++i) {
3647 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles", Call);
3648 FoundDeoptBundle =
true;
3650 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
3652 FoundGCTransitionBundle =
true;
3654 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles", Call);
3655 FoundFuncletBundle =
true;
3657 "Expected exactly one funclet bundle operand", Call);
3659 "Funclet bundle operands should correspond to a FuncletPadInst",
3662 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
3664 FoundCFGuardTargetBundle =
true;
3666 "Expected exactly one cfguardtarget bundle operand", Call);
3668 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles", Call);
3669 FoundPtrauthBundle =
true;
3671 "Expected exactly two ptrauth bundle operands", Call);
3673 BU.
Inputs[0]->getType()->isIntegerTy(32),
3674 "Ptrauth bundle key operand must be an i32 constant", Call);
3676 "Ptrauth bundle discriminator operand must be an i64", Call);
3678 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles", Call);
3679 FoundKCFIBundle =
true;
3680 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
3683 BU.
Inputs[0]->getType()->isIntegerTy(32),
3684 "Kcfi bundle operand must be an i32 constant", Call);
3686 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
3688 FoundPreallocatedBundle =
true;
3690 "Expected exactly one preallocated bundle operand", Call);
3691 auto Input = dyn_cast<IntrinsicInst>(BU.
Inputs.front());
3693 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
3694 "\"preallocated\" argument must be a token from "
3695 "llvm.call.preallocated.setup",
3698 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles", Call);
3699 FoundGCLiveBundle =
true;
3701 Check(!FoundAttachedCallBundle,
3702 "Multiple \"clang.arc.attachedcall\" operand bundles", Call);
3703 FoundAttachedCallBundle =
true;
3704 verifyAttachedCallBundle(Call, BU);
3709 Check(!(
Call.getCalledFunction() && FoundPtrauthBundle),
3710 "Direct call cannot have a ptrauth bundle", Call);
3717 if (
Call.getFunction()->getSubprogram() &&
Call.getCalledFunction() &&
3718 !
Call.getCalledFunction()->isInterposable() &&
3719 !
Call.getCalledFunction()->isDeclaration() &&
3720 Call.getCalledFunction()->getSubprogram())
3722 "inlinable function call in a function with "
3723 "debug info must have a !dbg location",
3726 if (
Call.isInlineAsm())
3727 verifyInlineAsmCall(Call);
3729 ConvergenceVerifyHelper.
visit(Call);
3734void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
3737 Twine(
"inalloca attribute not allowed in ") + Context);
3739 Twine(
"inreg attribute not allowed in ") + Context);
3740 Check(!
Attrs.contains(Attribute::SwiftError),
3741 Twine(
"swifterror attribute not allowed in ") + Context);
3742 Check(!
Attrs.contains(Attribute::Preallocated),
3743 Twine(
"preallocated attribute not allowed in ") + Context);
3745 Twine(
"byref attribute not allowed in ") + Context);
3757 return PL->getAddressSpace() == PR->getAddressSpace();
3762 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3763 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
3764 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
3767 for (
auto AK : ABIAttrs) {
3768 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
3770 Copy.addAttribute(Attr);
3774 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
3775 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
3776 Attrs.hasParamAttr(
I, Attribute::ByRef)))
3777 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
3781void Verifier::verifyMustTailCall(
CallInst &CI) {
3787 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
3788 "cannot guarantee tail call due to mismatched varargs", &CI);
3790 "cannot guarantee tail call due to mismatched return types", &CI);
3794 "cannot guarantee tail call due to mismatched calling conv", &CI);
3800 Value *RetVal = &CI;
3804 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
3806 "bitcast following musttail call must use the call", BI);
3813 Check(Ret,
"musttail call must precede a ret with an optional bitcast", &CI);
3814 Check(!
Ret->getReturnValue() ||
Ret->getReturnValue() == RetVal ||
3815 isa<UndefValue>(
Ret->getReturnValue()),
3816 "musttail call result must be returned", Ret);
3827 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3830 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3832 for (
unsigned I = 0, E = CalleeTy->getNumParams();
I != E; ++
I) {
3835 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3838 Check(!CallerTy->isVarArg(),
Twine(
"cannot guarantee ") + CCName +
3839 " tail call for varargs function");
3847 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
3848 "cannot guarantee tail call due to mismatched parameter counts", &CI);
3849 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3852 "cannot guarantee tail call due to mismatched parameter types", &CI);
3858 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3861 Check(CallerABIAttrs == CalleeABIAttrs,
3862 "cannot guarantee tail call due to mismatched ABI impacting "
3863 "function attributes",
3868void Verifier::visitCallInst(
CallInst &CI) {
3872 verifyMustTailCall(CI);
3875void Verifier::visitInvokeInst(
InvokeInst &II) {
3882 "The unwind destination does not have an exception handling instruction!",
3891 Check(
U.getType() ==
U.getOperand(0)->getType(),
3892 "Unary operators must have same type for"
3893 "operands and result!",
3896 switch (
U.getOpcode()) {
3899 case Instruction::FNeg:
3900 Check(
U.getType()->isFPOrFPVectorTy(),
3901 "FNeg operator only works with float types!", &U);
3914 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
3915 "Both operands to a binary operator are not of the same type!", &
B);
3917 switch (
B.getOpcode()) {
3920 case Instruction::Add:
3921 case Instruction::Sub:
3922 case Instruction::Mul:
3923 case Instruction::SDiv:
3924 case Instruction::UDiv:
3925 case Instruction::SRem:
3926 case Instruction::URem:
3927 Check(
B.getType()->isIntOrIntVectorTy(),
3928 "Integer arithmetic operators only work with integral types!", &
B);
3929 Check(
B.getType() ==
B.getOperand(0)->getType(),
3930 "Integer arithmetic operators must have same type "
3931 "for operands and result!",
3936 case Instruction::FAdd:
3937 case Instruction::FSub:
3938 case Instruction::FMul:
3939 case Instruction::FDiv:
3940 case Instruction::FRem:
3941 Check(
B.getType()->isFPOrFPVectorTy(),
3942 "Floating-point arithmetic operators only work with "
3943 "floating-point types!",
3945 Check(
B.getType() ==
B.getOperand(0)->getType(),
3946 "Floating-point arithmetic operators must have same type "
3947 "for operands and result!",
3951 case Instruction::And:
3952 case Instruction::Or:
3953 case Instruction::Xor:
3954 Check(
B.getType()->isIntOrIntVectorTy(),
3955 "Logical operators only work with integral types!", &
B);
3956 Check(
B.getType() ==
B.getOperand(0)->getType(),
3957 "Logical operators must have same type for operands and result!", &
B);
3959 case Instruction::Shl:
3960 case Instruction::LShr:
3961 case Instruction::AShr:
3962 Check(
B.getType()->isIntOrIntVectorTy(),
3963 "Shifts only work with integral types!", &
B);
3964 Check(
B.getType() ==
B.getOperand(0)->getType(),
3965 "Shift return type must be same as operands!", &
B);
3974void Verifier::visitICmpInst(
ICmpInst &IC) {
3978 Check(Op0Ty == Op1Ty,
3979 "Both operands to ICmp instruction are not of the same type!", &IC);
3982 "Invalid operand types for ICmp instruction", &IC);
3989void Verifier::visitFCmpInst(
FCmpInst &FC) {
3991 Type *Op0Ty =
FC.getOperand(0)->getType();
3992 Type *Op1Ty =
FC.getOperand(1)->getType();
3993 Check(Op0Ty == Op1Ty,
3994 "Both operands to FCmp instruction are not of the same type!", &FC);
3999 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
4006 "Invalid extractelement operands!", &EI);
4013 "Invalid insertelement operands!", &IE);
4020 "Invalid shufflevector operands!", &SV);
4025 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4027 Check(isa<PointerType>(TargetTy),
4028 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4029 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4031 if (
auto *STy = dyn_cast<StructType>(
GEP.getSourceElementType())) {
4034 "getelementptr cannot target structure that contains scalable vector"
4041 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4042 "GEP indexes must be integers", &
GEP);
4045 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4047 Check(
GEP.getType()->isPtrOrPtrVectorTy() &&
4048 GEP.getResultElementType() == ElTy,
4049 "GEP is not of right type for indices!", &
GEP, ElTy);
4051 if (
auto *GEPVTy = dyn_cast<VectorType>(
GEP.getType())) {
4054 if (
GEP.getPointerOperandType()->isVectorTy())
4057 cast<VectorType>(
GEP.getPointerOperandType())->getElementCount(),
4058 "Vector GEP result width doesn't match operand's", &
GEP);
4060 Type *IndexTy =
Idx->getType();
4061 if (
auto *IndexVTy = dyn_cast<VectorType>(IndexTy)) {
4063 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4066 "All GEP indices should be of integer type");
4070 if (
auto *PTy = dyn_cast<PointerType>(
GEP.getType())) {
4071 Check(
GEP.getAddressSpace() == PTy->getAddressSpace(),
4072 "GEP address space doesn't match type", &
GEP);
4079 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4084void Verifier::verifyRangeMetadata(
const Value &
I,
const MDNode *Range,
4085 Type *Ty,
bool IsAbsoluteSymbol) {
4086 unsigned NumOperands =
Range->getNumOperands();
4087 Check(NumOperands % 2 == 0,
"Unfinished range!", Range);
4088 unsigned NumRanges = NumOperands / 2;
4089 Check(NumRanges >= 1,
"It should have at least one range!", Range);
4092 for (
unsigned i = 0; i < NumRanges; ++i) {
4094 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i));
4095 Check(
Low,
"The lower limit must be an integer!",
Low);
4097 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i + 1));
4101 "Range types must match instruction type!", &
I);
4109 "The upper and lower limits cannot be the same value", &
I);
4112 Check(!CurRange.isEmptySet() && (IsAbsoluteSymbol || !CurRange.isFullSet()),
4113 "Range must not be empty!", Range);
4115 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4116 "Intervals are overlapping", Range);
4117 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4124 if (NumRanges > 2) {
4126 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(0))->getValue();
4128 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(1))->getValue();
4130 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4131 "Intervals are overlapping", Range);
4138 assert(Range && Range ==
I.getMetadata(LLVMContext::MD_range) &&
4139 "precondition violation");
4140 verifyRangeMetadata(
I, Range, Ty,
false);
4144 unsigned Size =
DL.getTypeSizeInBits(Ty);
4145 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4147 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4150void Verifier::visitLoadInst(
LoadInst &LI) {
4152 Check(PTy,
"Load operand must be a pointer.", &LI);
4156 "huge alignment values are unsupported", &LI);
4158 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4162 "Load cannot have Release ordering", &LI);
4164 "atomic load operand must have integer, pointer, or floating point "
4167 checkAtomicMemAccessSize(ElTy, &LI);
4170 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4176void Verifier::visitStoreInst(
StoreInst &SI) {
4177 PointerType *PTy = dyn_cast<PointerType>(
SI.getOperand(1)->getType());
4178 Check(PTy,
"Store operand must be a pointer.", &SI);
4179 Type *ElTy =
SI.getOperand(0)->getType();
4182 "huge alignment values are unsupported", &SI);
4184 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4185 if (
SI.isAtomic()) {
4188 "Store cannot have Acquire ordering", &SI);
4190 "atomic store operand must have integer, pointer, or floating point "
4193 checkAtomicMemAccessSize(ElTy, &SI);
4196 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4202void Verifier::verifySwiftErrorCall(
CallBase &Call,
4203 const Value *SwiftErrorVal) {
4205 if (
I.value() == SwiftErrorVal) {
4206 Check(
Call.paramHasAttr(
I.index(), Attribute::SwiftError),
4207 "swifterror value when used in a callsite should be marked "
4208 "with swifterror attribute",
4209 SwiftErrorVal, Call);
4214void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4217 for (
const User *U : SwiftErrorVal->
users()) {
4218 Check(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
4220 "swifterror value can only be loaded and stored from, or "
4221 "as a swifterror argument!",
4224 if (
auto StoreI = dyn_cast<StoreInst>(U))
4225 Check(StoreI->getOperand(1) == SwiftErrorVal,
4226 "swifterror value should be the second operand when used "
4229 if (
auto *Call = dyn_cast<CallBase>(U))
4230 verifySwiftErrorCall(*
const_cast<CallBase *
>(Call), SwiftErrorVal);
4234void Verifier::visitAllocaInst(
AllocaInst &AI) {
4237 "Cannot allocate unsized type", &AI);
4239 "Alloca array size must have integer type", &AI);
4242 "huge alignment values are unsupported", &AI);
4247 "swifterror alloca must have pointer type", &AI);
4249 "swifterror alloca must not be array allocation", &AI);
4250 verifySwiftErrorValue(&AI);
4259 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4260 checkAtomicMemAccessSize(ElTy, &CXI);
4266 "atomicrmw instructions cannot be unordered.", &RMWI);
4273 " operand must have integer or floating point type!",
4278 " operand must have floating-point or fixed vector of floating-point "
4284 " operand must have integer type!",
4287 checkAtomicMemAccessSize(ElTy, &RMWI);
4289 "Invalid binary operation!", &RMWI);
4293void Verifier::visitFenceInst(
FenceInst &FI) {
4299 "fence instructions may only have acquire, release, acq_rel, or "
4300 "seq_cst ordering.",
4308 "Invalid ExtractValueInst operands!", &EVI);
4317 "Invalid InsertValueInst operands!", &IVI);
4323 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
4324 return FPI->getParentPad();
4326 return cast<CatchSwitchInst>(EHPad)->getParentPad();
4335 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4337 if (
auto *LPI = dyn_cast<LandingPadInst>(&
I)) {
4342 const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator());
4343 Check(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,
4344 "Block containing LandingPadInst must be jumped to "
4345 "only by the unwind edge of an invoke.",
4350 if (
auto *CPI = dyn_cast<CatchPadInst>(&
I)) {
4353 "Block containg CatchPadInst must be jumped to "
4354 "only by its catchswitch.",
4356 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
4357 "Catchswitch cannot unwind to one of its catchpads",
4358 CPI->getCatchSwitch(), CPI);
4369 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
4370 Check(II->getUnwindDest() == BB && II->getNormalDest() != BB,
4371 "EH pad must be jumped to via an unwind edge", ToPad, II);
4373 dyn_cast<Function>(II->getCalledOperand()->stripPointerCasts());
4374 if (CalledFn && CalledFn->isIntrinsic() && II->doesNotThrow() &&
4378 FromPad = Bundle->Inputs[0];
4381 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
4382 FromPad = CRI->getOperand(0);
4383 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
4384 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
4387 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
4393 Check(FromPad != ToPad,
4394 "EH pad cannot handle exceptions raised within it", FromPad, TI);
4395 if (FromPad == ToPadParent) {
4399 Check(!isa<ConstantTokenNone>(FromPad),
4400 "A single unwind edge may only enter one EH pad", TI);
4401 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
4406 Check(isa<FuncletPadInst>(FromPad) || isa<CatchSwitchInst>(FromPad),
4407 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
4416 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
4418 visitEHPadPredecessors(LPI);
4420 if (!LandingPadResultTy)
4421 LandingPadResultTy = LPI.
getType();
4424 "The landingpad instruction should have a consistent result type "
4425 "inside a function.",
4429 Check(
F->hasPersonalityFn(),
4430 "LandingPadInst needs to be in a function with a personality.", &LPI);
4435 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
4441 "Catch operand does not have pointer type!", &LPI);
4443 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
4445 "Filter operand is not an array of constants!", &LPI);
4452void Verifier::visitResumeInst(
ResumeInst &RI) {
4454 "ResumeInst needs to be in a function with a personality.", &RI);
4456 if (!LandingPadResultTy)
4460 "The resume instruction should have a consistent result type "
4461 "inside a function.",
4471 Check(
F->hasPersonalityFn(),
4472 "CatchPadInst needs to be in a function with a personality.", &CPI);
4475 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
4481 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
4483 visitEHPadPredecessors(CPI);
4489 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
4499 Check(
F->hasPersonalityFn(),
4500 "CleanupPadInst needs to be in a function with a personality.", &CPI);
4505 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
4508 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4509 "CleanupPadInst has an invalid parent.", &CPI);
4511 visitEHPadPredecessors(CPI);
4516 User *FirstUser =
nullptr;
4517 Value *FirstUnwindPad =
nullptr;
4521 while (!Worklist.empty()) {
4524 "FuncletPadInst must not be nested within itself", CurrentPad);
4525 Value *UnresolvedAncestorPad =
nullptr;
4528 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
4529 UnwindDest = CRI->getUnwindDest();
4530 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
4535 if (CSI->unwindsToCaller())
4537 UnwindDest = CSI->getUnwindDest();
4538 }
else if (
auto *II = dyn_cast<InvokeInst>(U)) {
4539 UnwindDest = II->getUnwindDest();
4540 }
else if (isa<CallInst>(U)) {
4545 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
4549 Worklist.push_back(CPI);
4552 Check(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
4560 if (!cast<Instruction>(UnwindPad)->isEHPad())
4564 if (UnwindParent == CurrentPad)
4570 Value *ExitedPad = CurrentPad;
4573 if (ExitedPad == &FPI) {
4578 UnresolvedAncestorPad = &FPI;
4582 if (ExitedParent == UnwindParent) {
4586 UnresolvedAncestorPad = ExitedParent;
4589 ExitedPad = ExitedParent;
4590 }
while (!isa<ConstantTokenNone>(ExitedPad));
4595 UnresolvedAncestorPad = &FPI;
4602 Check(UnwindPad == FirstUnwindPad,
4603 "Unwind edges out of a funclet "
4604 "pad must have the same unwind "
4606 &FPI, U, FirstUser);
4609 FirstUnwindPad = UnwindPad;
4611 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
4613 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
4618 if (CurrentPad != &FPI)
4621 if (UnresolvedAncestorPad) {
4622 if (CurrentPad == UnresolvedAncestorPad) {
4626 assert(CurrentPad == &FPI);
4634 Value *ResolvedPad = CurrentPad;
4635 while (!Worklist.empty()) {
4636 Value *UnclePad = Worklist.back();
4640 while (ResolvedPad != AncestorPad) {
4642 if (ResolvedParent == UnresolvedAncestorPad) {
4645 ResolvedPad = ResolvedParent;
4649 if (ResolvedPad != AncestorPad)
4652 Worklist.pop_back();
4657 if (FirstUnwindPad) {
4658 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
4659 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
4660 Value *SwitchUnwindPad;
4661 if (SwitchUnwindDest)
4665 Check(SwitchUnwindPad == FirstUnwindPad,
4666 "Unwind edges out of a catch must have the same unwind dest as "
4667 "the parent catchswitch",
4668 &FPI, FirstUser, CatchSwitch);
4679 Check(
F->hasPersonalityFn(),
4680 "CatchSwitchInst needs to be in a function with a personality.",
4686 "CatchSwitchInst not the first non-PHI instruction in the block.",
4690 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4691 "CatchSwitchInst has an invalid parent.", ParentPad);
4695 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4696 "CatchSwitchInst must unwind to an EH block which is not a "
4702 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
4706 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
4709 Check(isa<CatchPadInst>(Handler->getFirstNonPHI()),
4710 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
4713 visitEHPadPredecessors(CatchSwitch);
4719 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
4724 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4725 "CleanupReturnInst must unwind to an EH block which is not a "
4733void Verifier::verifyDominatesUse(
Instruction &
I,
unsigned i) {
4739 if (II->getNormalDest() == II->getUnwindDest())
4750 if (!isa<PHINode>(
I) && InstsInThisBlock.
count(
Op))
4753 const Use &
U =
I.getOperandUse(i);
4758 Check(
I.getType()->isPointerTy(),
4759 "dereferenceable, dereferenceable_or_null "
4760 "apply only to pointer types",
4762 Check((isa<LoadInst>(
I) || isa<IntToPtrInst>(
I)),
4763 "dereferenceable, dereferenceable_or_null apply only to load"
4764 " and inttoptr instructions, use attributes for calls or invokes",
4767 "dereferenceable, dereferenceable_or_null "
4768 "take one operand!",
4773 "dereferenceable_or_null metadata value must be an i64!",
4779 "!prof annotations should have no less than 2 operands", MD);
4782 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null", MD);
4784 "expected string with name of the !prof annotation", MD);
4789 if (ProfName ==
"branch_weights") {
4790 if (isa<InvokeInst>(&
I)) {
4792 "Wrong number of InvokeInst branch_weights operands", MD);
4794 unsigned ExpectedNumOperands = 0;
4797 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
4798 ExpectedNumOperands =
SI->getNumSuccessors();
4799 else if (isa<CallInst>(&
I))
4800 ExpectedNumOperands = 1;
4802 ExpectedNumOperands = IBI->getNumDestinations();
4803 else if (isa<SelectInst>(&
I))
4804 ExpectedNumOperands = 2;
4805 else if (
CallBrInst *CI = dyn_cast<CallBrInst>(&
I))
4808 CheckFailed(
"!prof branch_weights are not allowed for this instruction",
4812 "Wrong number of operands", MD);
4816 Check(MDO,
"second operand should not be null", MD);
4817 Check(mdconst::dyn_extract<ConstantInt>(MDO),
4818 "!prof brunch_weights operand is not a const int");
4824 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
4825 bool ExpectedInstTy =
4826 isa<AllocaInst>(
I) || isa<StoreInst>(
I) || isa<MemIntrinsic>(
I);
4827 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
4834 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
4837 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(
User))
4838 CheckDI(DAI->getFunction() ==
I.getFunction(),
4839 "dbg.assign not in same function as inst", DAI, &
I);
4843 cast<DIAssignID>(MD)->getAllDbgVariableRecordUsers()) {
4845 "!DIAssignID should only be used by Assign DVRs.", MD, DVR);
4846 CheckDI(DVR->getFunction() ==
I.getFunction(),
4847 "DVRAssign not in same function as inst", DVR, &
I);
4853 "!mmra metadata attached to unexpected instruction kind",
I, MD);
4863 Check(isa<MDTuple>(MD),
"!mmra expected to be a metadata tuple",
I, MD);
4866 "!mmra metadata tuple operand is not an MMRA tag",
I, MDOp.get());
4869void Verifier::visitCallStackMetadata(
MDNode *MD) {
4873 "call stack metadata should have at least 1 operand", MD);
4876 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op),
4877 "call stack metadata operand should be constant integer",
Op);
4881 Check(isa<CallBase>(
I),
"!memprof metadata should only exist on calls", &
I);
4883 "!memprof annotations should have at least 1 metadata operand "
4888 for (
auto &MIBOp : MD->
operands()) {
4889 MDNode *MIB = dyn_cast<MDNode>(MIBOp);
4894 "Each !memprof MemInfoBlock should have at least 2 operands", MIB);
4898 "!memprof MemInfoBlock first operand should not be null", MIB);
4900 "!memprof MemInfoBlock first operand should be an MDNode", MIB);
4902 visitCallStackMetadata(StackMD);
4906 [](
const MDOperand &
Op) { return isa<MDString>(Op); }),
4907 "Not all !memprof MemInfoBlock operands 1 to N are MDString", MIB);
4912 Check(isa<CallBase>(
I),
"!callsite metadata should only exist on calls", &
I);
4915 visitCallStackMetadata(MD);
4918void Verifier::visitAnnotationMetadata(
MDNode *Annotation) {
4919 Check(isa<MDTuple>(Annotation),
"annotation must be a tuple");
4921 "annotation must have at least one operand");
4923 bool TupleOfStrings =
4924 isa<MDTuple>(
Op.get()) &&
4925 all_of(cast<MDTuple>(
Op)->operands(), [](
auto &Annotation) {
4928 Check(isa<MDString>(
Op.get()) || TupleOfStrings,
4929 "operands must be a string or a tuple of strings");
4933void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
4935 Check(NumOps >= 2 && NumOps <= 3,
"scope must have two or three operands",
4938 "first scope operand must be self-referential or string", MD);
4941 "third scope operand must be string (if used)", MD);
4944 Check(
Domain !=
nullptr,
"second scope operand must be MDNode", MD);
4946 unsigned NumDomainOps =
Domain->getNumOperands();
4947 Check(NumDomainOps >= 1 && NumDomainOps <= 2,
4948 "domain must have one or two operands",
Domain);
4950 isa<MDString>(
Domain->getOperand(0)),
4951 "first domain operand must be self-referential or string",
Domain);
4952 if (NumDomainOps == 2)
4954 "second domain operand must be string (if used)",
Domain);
4957void Verifier::visitAliasScopeListMetadata(
const MDNode *MD) {
4959 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
4960 Check(OpMD !=
nullptr,
"scope list must consist of MDNodes", MD);
4961 visitAliasScopeMetadata(OpMD);
4965void Verifier::visitAccessGroupMetadata(
const MDNode *MD) {
4966 auto IsValidAccessScope = [](
const MDNode *MD) {
4971 if (IsValidAccessScope(MD))
4976 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
4977 Check(OpMD !=
nullptr,
"Access scope list must consist of MDNodes", MD);
4978 Check(IsValidAccessScope(OpMD),
4979 "Access scope list contains invalid access scope", MD);
4987 Check(BB,
"Instruction not embedded in basic block!", &
I);
4989 if (!isa<PHINode>(
I)) {
4990 for (
User *U :
I.users()) {
4992 "Only PHI nodes may reference their own value!", &
I);
4997 Check(!
I.getType()->isVoidTy() || !
I.hasName(),
4998 "Instruction has a name, but provides a void value!", &
I);
5002 Check(
I.getType()->isVoidTy() ||
I.getType()->isFirstClassType(),
5003 "Instruction returns a non-scalar type!", &
I);
5007 Check(!
I.getType()->isMetadataTy() || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5008 "Invalid use of metadata!", &
I);
5013 for (
Use &U :
I.uses()) {
5014 if (
Instruction *Used = dyn_cast<Instruction>(
U.getUser()))
5016 "Instruction referencing"
5017 " instruction not embedded in a basic block!",
5020 CheckFailed(
"Use of instruction is not an instruction!", U);
5027 const CallBase *CBI = dyn_cast<CallBase>(&
I);
5029 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
5030 Check(
I.getOperand(i) !=
nullptr,
"Instruction has null operand!", &
I);
5034 if (!
I.getOperand(i)->getType()->isFirstClassType()) {
5035 Check(
false,
"Instruction operands must be first-class values!", &
I);
5038 if (
Function *
F = dyn_cast<Function>(
I.getOperand(i))) {
5043 return CBI && CBI->isOperandBundleOfType(
5051 Check((!
F->isIntrinsic() ||
5052 (CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i)) ||
5053 IsAttachedCallOperand(
F, CBI, i)),
5054 "Cannot take the address of an intrinsic!", &
I);
5055 Check(!
F->isIntrinsic() || isa<CallInst>(
I) ||
5056 F->getIntrinsicID() == Intrinsic::donothing ||
5057 F->getIntrinsicID() == Intrinsic::seh_try_begin ||
5058 F->getIntrinsicID() == Intrinsic::seh_try_end ||
5059 F->getIntrinsicID() == Intrinsic::seh_scope_begin ||
5060 F->getIntrinsicID() == Intrinsic::seh_scope_end ||
5061 F->getIntrinsicID() == Intrinsic::coro_resume ||
5062 F->getIntrinsicID() == Intrinsic::coro_destroy ||
5063 F->getIntrinsicID() == Intrinsic::coro_await_suspend_void ||
5064 F->getIntrinsicID() == Intrinsic::coro_await_suspend_bool ||
5065 F->getIntrinsicID() == Intrinsic::coro_await_suspend_handle ||
5066 F->getIntrinsicID() ==
5067 Intrinsic::experimental_patchpoint_void ||
5068 F->getIntrinsicID() == Intrinsic::experimental_patchpoint ||
5069 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
5070 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
5071 IsAttachedCallOperand(
F, CBI, i),
5072 "Cannot invoke an intrinsic other than donothing, patchpoint, "
5073 "statepoint, coro_resume, coro_destroy or clang.arc.attachedcall",
5075 Check(
F->getParent() == &M,
"Referencing function in another module!", &
I,
5076 &M,
F,
F->getParent());
5077 }
else if (
BasicBlock *OpBB = dyn_cast<BasicBlock>(
I.getOperand(i))) {
5079 "Referring to a basic block in another function!", &
I);
5080 }
else if (
Argument *OpArg = dyn_cast<Argument>(
I.getOperand(i))) {
5082 "Referring to an argument in another function!", &
I);
5083 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(
I.getOperand(i))) {
5084 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5086 }
else if (
Instruction *OpInst = dyn_cast<Instruction>(
I.getOperand(i))) {
5088 "Referring to an instruction in another function!", &
I);
5089 verifyDominatesUse(
I, i);
5090 }
else if (isa<InlineAsm>(
I.getOperand(i))) {
5091 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5092 "Cannot take the address of an inline asm!", &
I);
5093 }
else if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(
I.getOperand(i))) {
5094 if (
CE->getType()->isPtrOrPtrVectorTy()) {
5097 visitConstantExprsRecursively(CE);
5102 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_fpmath)) {
5103 Check(
I.getType()->isFPOrFPVectorTy(),
5104 "fpmath requires a floating point result!", &
I);
5107 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
5108 const APFloat &Accuracy = CFP0->getValueAPF();
5110 "fpmath accuracy must have float type", &
I);
5112 "fpmath accuracy not a positive number!", &
I);
5114 Check(
false,
"invalid fpmath accuracy!", &
I);
5118 if (
MDNode *Range =
I.getMetadata(LLVMContext::MD_range)) {
5119 Check(isa<LoadInst>(
I) || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5120 "Ranges are only for loads, calls and invokes!", &
I);
5121 visitRangeMetadata(
I, Range,
I.getType());
5124 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
5125 Check(isa<LoadInst>(
I) || isa<StoreInst>(
I),
5126 "invariant.group metadata is only for loads and stores", &
I);
5129 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_nonnull)) {
5130 Check(
I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
5133 "nonnull applies only to load instructions, use attributes"
5134 " for calls or invokes",
5139 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable))
5140 visitDereferenceableMetadata(
I, MD);
5142 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
5143 visitDereferenceableMetadata(
I, MD);
5145 if (
MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
5148 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
5149 visitAliasScopeListMetadata(MD);
5150 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
5151 visitAliasScopeListMetadata(MD);
5153 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
5154 visitAccessGroupMetadata(MD);
5156 if (
MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
5157 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
5160 "align applies only to load instructions, "
5161 "use attributes for calls or invokes",
5163 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
5164 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
5166 "align metadata value must be an i64!", &
I);
5171 "alignment is larger that implementation defined limit", &
I);
5174 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
5175 visitProfMetadata(
I, MD);
5177 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
5178 visitMemProfMetadata(
I, MD);
5180 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
5181 visitCallsiteMetadata(
I, MD);
5183 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
5184 visitDIAssignIDMetadata(
I, MD);
5186 if (
MDNode *MMRA =
I.getMetadata(LLVMContext::MD_mmra))
5187 visitMMRAMetadata(
I, MMRA);
5189 if (
MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
5190 visitAnnotationMetadata(Annotation);
5192 if (
MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
5193 CheckDI(isa<DILocation>(
N),
"invalid !dbg metadata attachment", &
I,
N);
5194 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
5197 if (
auto *DII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
5198 verifyFragmentExpression(*DII);
5199 verifyNotEntryValue(*DII);
5203 I.getAllMetadata(MDs);
5204 for (
auto Attachment : MDs) {
5205 unsigned Kind = Attachment.first;
5207 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
5208 ? AreDebugLocsAllowed::Yes
5209 : AreDebugLocsAllowed::No;
5210 visitMDNode(*Attachment.second, AllowLocs);
5219 Check(
IF->isDeclaration(),
"Intrinsic functions should never be defined!",
5225 bool IsVarArg = IFTy->isVarArg();
5236 "Intrinsic has incorrect return type!", IF);
5238 "Intrinsic has incorrect argument type!", IF);
5243 "Intrinsic was not defined with variable arguments!", IF);
5246 "Callsite was not defined with variable arguments!", IF);
5255 const std::string ExpectedName =
5257 Check(ExpectedName ==
IF->getName(),
5258 "Intrinsic name not mangled correctly for type arguments! "
5266 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
5267 visitMetadataAsValue(*MD,
Call.getCaller());
5268 if (
auto *Const = dyn_cast<Constant>(V))
5270 "const x86_amx is not allowed in argument!");
5276 case Intrinsic::assume: {
5277 for (
auto &Elem :
Call.bundle_op_infos()) {
5278 unsigned ArgCount = Elem.End - Elem.Begin;
5281 if (Elem.Tag->getKey() ==
"separate_storage") {
5282 Check(ArgCount == 2,
5283 "separate_storage assumptions should have 2 arguments", Call);
5284 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy() &&
5285 Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(),
5286 "arguments to separate_storage assumptions should be pointers",
5290 Check(Elem.Tag->getKey() ==
"ignore" ||
5292 "tags must be valid attribute names", Call);
5295 if (Kind == Attribute::Alignment) {
5296 Check(ArgCount <= 3 && ArgCount >= 2,
5297 "alignment assumptions should have 2 or 3 arguments", Call);
5298 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5299 "first argument should be a pointer", Call);
5300 Check(
Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5301 "second argument should be an integer", Call);
5303 Check(
Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(),
5304 "third argument should be an integer if present", Call);
5307 Check(ArgCount <= 2,
"too many arguments", Call);
5311 Check(ArgCount == 2,
"this attribute should have 2 arguments", Call);
5312 Check(isa<ConstantInt>(
Call.getOperand(Elem.Begin + 1)),
5313 "the second argument should be a constant integral value", Call);
5315 Check((ArgCount) == 1,
"this attribute should have one argument", Call);
5317 Check((ArgCount) == 0,
"this attribute has no argument", Call);
5322 case Intrinsic::ucmp:
5323 case Intrinsic::scmp: {
5324 Type *SrcTy =
Call.getOperand(0)->getType();
5328 "result type must be at least 2 bits wide", Call);
5330 bool IsDestTypeVector = DestTy->
isVectorTy();
5332 "ucmp/scmp argument and result types must both be either vector or "
5335 if (IsDestTypeVector) {
5336 auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
5337 auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
5338 Check(SrcVecLen == DestVecLen,
5339 "return type and arguments must have the same number of "
5345 case Intrinsic::coro_id: {
5346 auto *InfoArg =
Call.getArgOperand(3)->stripPointerCasts();
5347 if (isa<ConstantPointerNull>(InfoArg))
5349 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
5351 "info argument of llvm.coro.id must refer to an initialized "
5354 Check(isa<ConstantStruct>(
Init) || isa<ConstantArray>(
Init),
5355 "info argument of llvm.coro.id must refer to either a struct or "
5359 case Intrinsic::is_fpclass: {
5362 "unsupported bits for llvm.is.fpclass test mask");
5365 case Intrinsic::fptrunc_round: {
5368 auto *MAV = dyn_cast<MetadataAsValue>(
Call.getOperand(1));
5370 MD = MAV->getMetadata();
5372 Check(MD !=
nullptr,
"missing rounding mode argument", Call);
5374 Check(isa<MDString>(MD),
5375 (
"invalid value for llvm.fptrunc.round metadata operand"
5376 " (the operand should be a string)"),
5379 std::optional<RoundingMode> RoundMode =
5382 "unsupported rounding mode argument", Call);
5385#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
5386#include "llvm/IR/VPIntrinsics.def"
5387 visitVPIntrinsic(cast<VPIntrinsic>(Call));
5389#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
5390 case Intrinsic::INTRINSIC:
5391#include "llvm/IR/ConstrainedOps.def"
5392 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call));
5394 case Intrinsic::dbg_declare:
5395 Check(isa<MetadataAsValue>(
Call.getArgOperand(0)),
5396 "invalid llvm.dbg.declare intrinsic call 1", Call);
5397 visitDbgIntrinsic(
"declare", cast<DbgVariableIntrinsic>(Call));
5399 case Intrinsic::dbg_value:
5400 visitDbgIntrinsic(
"value", cast<DbgVariableIntrinsic>(Call));
5402 case Intrinsic::dbg_assign:
5403 visitDbgIntrinsic(
"assign", cast<DbgVariableIntrinsic>(Call));
5405 case Intrinsic::dbg_label:
5406 visitDbgLabelIntrinsic(
"label", cast<DbgLabelInst>(Call));
5408 case Intrinsic::memcpy:
5409 case Intrinsic::memcpy_inline:
5410 case Intrinsic::memmove:
5411 case Intrinsic::memset:
5412 case Intrinsic::memset_inline: {
5415 case Intrinsic::memcpy_element_unordered_atomic:
5416 case Intrinsic::memmove_element_unordered_atomic:
5417 case Intrinsic::memset_element_unordered_atomic: {
5418 const auto *AMI = cast<AtomicMemIntrinsic>(&Call);
5421 cast<ConstantInt>(AMI->getRawElementSizeInBytes());
5424 "element size of the element-wise atomic memory intrinsic "
5425 "must be a power of 2",
5428 auto IsValidAlignment = [&](
MaybeAlign Alignment) {
5429 return Alignment && ElementSizeVal.
ule(Alignment->value());
5431 Check(IsValidAlignment(AMI->getDestAlign()),
5432 "incorrect alignment of the destination argument", Call);
5433 if (
const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
5434 Check(IsValidAlignment(AMT->getSourceAlign()),
5435 "incorrect alignment of the source argument", Call);
5439 case Intrinsic::call_preallocated_setup: {
5440 auto *NumArgs = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5441 Check(NumArgs !=
nullptr,
5442 "llvm.call.preallocated.setup argument must be a constant");
5443 bool FoundCall =
false;
5445 auto *UseCall = dyn_cast<CallBase>(U);
5446 Check(UseCall !=
nullptr,
5447 "Uses of llvm.call.preallocated.setup must be calls");
5448 const Function *Fn = UseCall->getCalledFunction();
5449 if (Fn && Fn->
getIntrinsicID() == Intrinsic::call_preallocated_arg) {
5450 auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5451 Check(AllocArgIndex !=
nullptr,
5452 "llvm.call.preallocated.alloc arg index must be a constant");
5453 auto AllocArgIndexInt = AllocArgIndex->getValue();
5454 Check(AllocArgIndexInt.sge(0) &&
5455 AllocArgIndexInt.slt(NumArgs->getValue()),
5456 "llvm.call.preallocated.alloc arg index must be between 0 and "
5458 "llvm.call.preallocated.setup's argument count");
5460 Intrinsic::call_preallocated_teardown) {
5463 Check(!FoundCall,
"Can have at most one call corresponding to a "
5464 "llvm.call.preallocated.setup");
5466 size_t NumPreallocatedArgs = 0;
5467 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
5468 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
5469 ++NumPreallocatedArgs;
5472 Check(NumPreallocatedArgs != 0,
5473 "cannot use preallocated intrinsics on a call without "
5474 "preallocated arguments");
5475 Check(NumArgs->equalsInt(NumPreallocatedArgs),
5476 "llvm.call.preallocated.setup arg size must be equal to number "
5477 "of preallocated arguments "
5487 auto PreallocatedBundle =
5489 Check(PreallocatedBundle,
5490 "Use of llvm.call.preallocated.setup outside intrinsics "
5491 "must be in \"preallocated\" operand bundle");
5492 Check(PreallocatedBundle->Inputs.front().get() == &Call,
5493 "preallocated bundle must have token from corresponding "
5494 "llvm.call.preallocated.setup");
5499 case Intrinsic::call_preallocated_arg: {
5500 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5501 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5502 Intrinsic::call_preallocated_setup,
5503 "llvm.call.preallocated.arg token argument must be a "
5504 "llvm.call.preallocated.setup");
5505 Check(
Call.hasFnAttr(Attribute::Preallocated),
5506 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
5507 "call site attribute");
5510 case Intrinsic::call_preallocated_teardown: {
5511 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5512 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5513 Intrinsic::call_preallocated_setup,
5514 "llvm.call.preallocated.teardown token argument must be a "
5515 "llvm.call.preallocated.setup");
5518 case Intrinsic::gcroot:
5519 case Intrinsic::gcwrite:
5520 case Intrinsic::gcread:
5521 if (
ID == Intrinsic::gcroot) {
5523 dyn_cast<AllocaInst>(
Call.getArgOperand(0)->stripPointerCasts());
5524 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.", Call);
5525 Check(isa<Constant>(
Call.getArgOperand(1)),
5526 "llvm.gcroot parameter #2 must be a constant.", Call);
5528 Check(!isa<ConstantPointerNull>(
Call.getArgOperand(1)),
5529 "llvm.gcroot parameter #1 must either be a pointer alloca, "
5530 "or argument #2 must be a non-null constant.",
5535 Check(
Call.getParent()->getParent()->hasGC(),
5536 "Enclosing function does not use GC.", Call);
5538 case Intrinsic::init_trampoline:
5539 Check(isa<Function>(
Call.getArgOperand(1)->stripPointerCasts()),
5540 "llvm.init_trampoline parameter #2 must resolve to a function.",
5543 case Intrinsic::prefetch:
5544 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
5545 "rw argument to llvm.prefetch must be 0-1", Call);
5546 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
5547 "locality argument to llvm.prefetch must be 0-3", Call);
5548 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
5549 "cache type argument to llvm.prefetch must be 0-1", Call);
5551 case Intrinsic::stackprotector:
5552 Check(isa<AllocaInst>(
Call.getArgOperand(1)->stripPointerCasts()),
5553 "llvm.stackprotector parameter #2 must resolve to an alloca.", Call);
5555 case Intrinsic::localescape: {
5559 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
5562 if (isa<ConstantPointerNull>(Arg))
5564 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
5566 "llvm.localescape only accepts static allocas", Call);
5569 SawFrameEscape =
true;
5572 case Intrinsic::localrecover: {
5573 Value *FnArg =
Call.getArgOperand(0)->stripPointerCasts();
5574 Function *Fn = dyn_cast<Function>(FnArg);
5576 "llvm.localrecover first "
5577 "argument must be function defined in this module",
5579 auto *IdxArg = cast<ConstantInt>(
Call.getArgOperand(2));
5580 auto &Entry = FrameEscapeInfo[Fn];
5582 std::max(
uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
5586 case Intrinsic::experimental_gc_statepoint:
5587 if (
auto *CI = dyn_cast<CallInst>(&Call))
5588 Check(!CI->isInlineAsm(),
5589 "gc.statepoint support for inline assembly unimplemented", CI);
5590 Check(
Call.getParent()->getParent()->hasGC(),
5591 "Enclosing function does not use GC.", Call);
5593 verifyStatepoint(Call);
5595 case Intrinsic::experimental_gc_result: {
5596 Check(
Call.getParent()->getParent()->hasGC(),
5597 "Enclosing function does not use GC.", Call);
5599 auto *Statepoint =
Call.getArgOperand(0);
5600 if (isa<UndefValue>(Statepoint))
5604 const auto *StatepointCall = dyn_cast<CallBase>(Statepoint);
5606 StatepointCall ? StatepointCall->getCalledFunction() :
nullptr;
5609 Intrinsic::experimental_gc_statepoint,
5610 "gc.result operand #1 must be from a statepoint", Call,
5611 Call.getArgOperand(0));
5614 auto *TargetFuncType =
5615 cast<FunctionType>(StatepointCall->getParamElementType(2));
5616 Check(
Call.getType() == TargetFuncType->getReturnType(),
5617 "gc.result result type does not match wrapped callee", Call);
5620 case Intrinsic::experimental_gc_relocate: {
5621 Check(
Call.arg_size() == 3,
"wrong number of arguments", Call);
5623 Check(isa<PointerType>(
Call.getType()->getScalarType()),
5624 "gc.relocate must return a pointer or a vector of pointers", Call);
5630 dyn_cast<LandingPadInst>(
Call.getArgOperand(0))) {
5633 LandingPad->
getParent()->getUniquePredecessor();
5637 Check(InvokeBB,
"safepoints should have unique landingpads",
5638 LandingPad->getParent());
5642 "gc relocate should be linked to a statepoint", InvokeBB);
5647 auto *Token =
Call.getArgOperand(0);
5648 Check(isa<GCStatepointInst>(Token) || isa<UndefValue>(Token),
5649 "gc relocate is incorrectly tied to the statepoint", Call, Token);
5653 const Value &StatepointCall = *cast<GCRelocateInst>(Call).getStatepoint();
5658 "gc.relocate operand #2 must be integer offset", Call);
5661 Check(isa<ConstantInt>(Derived),
5662 "gc.relocate operand #3 must be integer offset", Call);
5664 const uint64_t BaseIndex = cast<ConstantInt>(
Base)->getZExtValue();
5665 const uint64_t DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
5668 if (isa<UndefValue>(StatepointCall))
5670 if (
auto Opt = cast<GCStatepointInst>(StatepointCall)
5672 Check(BaseIndex < Opt->Inputs.size(),
5673 "gc.relocate: statepoint base index out of bounds", Call);
5674 Check(DerivedIndex < Opt->Inputs.size(),
5675 "gc.relocate: statepoint derived index out of bounds", Call);
5683 auto *ResultType =
Call.getType();
5688 "gc.relocate: relocated value must be a pointer", Call);
5689 Check(DerivedType->isPtrOrPtrVectorTy(),
5690 "gc.relocate: relocated value must be a pointer", Call);
5692 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
5693 "gc.relocate: vector relocates to vector and pointer to pointer",
5696 ResultType->getPointerAddressSpace() ==
5697 DerivedType->getPointerAddressSpace(),
5698 "gc.relocate: relocating a pointer shouldn't change its address space",
5702 Check(GC,
"gc.relocate: calling function must have GCStrategy",
5703 Call.getFunction());
5705 auto isGCPtr = [&
GC](
Type *PTy) {
5706 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
5708 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer", Call);
5710 "gc.relocate: relocated value must be a gc pointer", Call);
5711 Check(isGCPtr(DerivedType),
5712 "gc.relocate: relocated value must be a gc pointer", Call);
5716 case Intrinsic::experimental_patchpoint: {
5718 Check(
Call.getType()->isSingleValueType(),
5719 "patchpoint: invalid return type used with anyregcc", Call);
5723 case Intrinsic::eh_exceptioncode:
5724 case Intrinsic::eh_exceptionpointer: {
5725 Check(isa<CatchPadInst>(
Call.getArgOperand(0)),
5726 "eh.exceptionpointer argument must be a catchpad", Call);
5729 case Intrinsic::get_active_lane_mask: {
5731 "get_active_lane_mask: must return a "
5734 auto *ElemTy =
Call.getType()->getScalarType();
5735 Check(ElemTy->isIntegerTy(1),
5736 "get_active_lane_mask: element type is not "
5741 case Intrinsic::experimental_get_vector_length: {
5744 "get_vector_length: VF must be positive", Call);
5747 case Intrinsic::masked_load: {
5748 Check(
Call.getType()->isVectorTy(),
"masked_load: must return a vector",
5753 Value *PassThru =
Call.getArgOperand(3);
5754 Check(
Mask->getType()->isVectorTy(),
"masked_load: mask must be vector",
5757 "masked_load: alignment must be a power of 2", Call);
5759 "masked_load: pass through and return type must match", Call);
5760 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5761 cast<VectorType>(
Call.getType())->getElementCount(),
5762 "masked_load: vector mask must be same length as return", Call);
5765 case Intrinsic::masked_store: {
5769 Check(
Mask->getType()->isVectorTy(),
"masked_store: mask must be vector",
5772 "masked_store: alignment must be a power of 2", Call);
5773 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5774 cast<VectorType>(Val->
getType())->getElementCount(),
5775 "masked_store: vector mask must be same length as value", Call);
5779 case Intrinsic::masked_gather: {
5780 const APInt &Alignment =
5783 "masked_gather: alignment must be 0 or a power of 2", Call);
5786 case Intrinsic::masked_scatter: {
5787 const APInt &Alignment =
5788 cast<ConstantInt>(
Call.getArgOperand(2))->getValue();
5790 "masked_scatter: alignment must be 0 or a power of 2", Call);
5794 case Intrinsic::experimental_guard: {
5795 Check(isa<CallInst>(Call),
"experimental_guard cannot be invoked", Call);
5797 "experimental_guard must have exactly one "
5798 "\"deopt\" operand bundle");
5802 case Intrinsic::experimental_deoptimize: {
5803 Check(isa<CallInst>(Call),
"experimental_deoptimize cannot be invoked",
5806 "experimental_deoptimize must have exactly one "
5807 "\"deopt\" operand bundle");
5808 Check(
Call.getType() ==
Call.getFunction()->getReturnType(),
5809 "experimental_deoptimize return type must match caller return type");
5811 if (isa<CallInst>(Call)) {
5812 auto *RI = dyn_cast<ReturnInst>(
Call.getNextNode());
5814 "calls to experimental_deoptimize must be followed by a return");
5816 if (!
Call.getType()->isVoidTy() && RI)
5817 Check(RI->getReturnValue() == &Call,
5818 "calls to experimental_deoptimize must be followed by a return "
5819 "of the value computed by experimental_deoptimize");
5824 case Intrinsic::vastart: {
5826 "va_start called in a non-varargs function");
5829 case Intrinsic::vector_reduce_and:
5830 case Intrinsic::vector_reduce_or:
5831 case Intrinsic::vector_reduce_xor:
5832 case Intrinsic::vector_reduce_add:
5833 case Intrinsic::vector_reduce_mul:
5834 case Intrinsic::vector_reduce_smax:
5835 case Intrinsic::vector_reduce_smin:
5836 case Intrinsic::vector_reduce_umax:
5837 case Intrinsic::vector_reduce_umin: {
5838 Type *ArgTy =
Call.getArgOperand(0)->getType();
5840 "Intrinsic has incorrect argument type!");
5843 case Intrinsic::vector_reduce_fmax:
5844 case Intrinsic::vector_reduce_fmin: {
5845 Type *ArgTy =
Call.getArgOperand(0)->getType();
5847 "Intrinsic has incorrect argument type!");
5850 case Intrinsic::vector_reduce_fadd:
5851 case Intrinsic::vector_reduce_fmul: {
5854 Type *ArgTy =
Call.getArgOperand(1)->getType();
5856 "Intrinsic has incorrect argument type!");
5859 case Intrinsic::smul_fix:
5860 case Intrinsic::smul_fix_sat:
5861 case Intrinsic::umul_fix:
5862 case Intrinsic::umul_fix_sat:
5863 case Intrinsic::sdiv_fix:
5864 case Intrinsic::sdiv_fix_sat:
5865 case Intrinsic::udiv_fix:
5866 case Intrinsic::udiv_fix_sat: {
5870 "first operand of [us][mul|div]_fix[_sat] must be an int type or "
5873 "second operand of [us][mul|div]_fix[_sat] must be an int type or "
5876 auto *Op3 = cast<ConstantInt>(
Call.getArgOperand(2));
5877 Check(Op3->getType()->isIntegerTy(),
5878 "third operand of [us][mul|div]_fix[_sat] must be an int type");
5879 Check(Op3->getBitWidth() <= 32,
5880 "third operand of [us][mul|div]_fix[_sat] must fit within 32 bits");
5882 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
5883 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
5885 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
5889 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
5890 "to the width of the operands");
5894 case Intrinsic::lrint:
5895 case Intrinsic::llrint: {
5896 Type *ValTy =
Call.getArgOperand(0)->getType();
5900 "llvm.lrint, llvm.llrint: argument must be floating-point or vector "
5901 "of floating-points, and result must be integer or vector of integers",
5904 "llvm.lrint, llvm.llrint: argument and result disagree on vector use",
5907 Check(cast<VectorType>(ValTy)->getElementCount() ==
5908 cast<VectorType>(ResultTy)->getElementCount(),
5909 "llvm.lrint, llvm.llrint: argument must be same length as result",
5914 case Intrinsic::lround:
5915 case Intrinsic::llround: {
5916 Type *ValTy =
Call.getArgOperand(0)->getType();
5919 "Intrinsic does not support vectors", &Call);
5922 case Intrinsic::bswap: {
5925 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &Call);
5928 case Intrinsic::invariant_start: {
5929 ConstantInt *InvariantSize = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5930 Check(InvariantSize &&
5932 "invariant_start parameter must be -1, 0 or a positive number",
5936 case Intrinsic::matrix_multiply:
5937 case Intrinsic::matrix_transpose:
5938 case Intrinsic::matrix_column_major_load:
5939 case Intrinsic::matrix_column_major_store: {
5945 Type *Op0ElemTy =
nullptr;
5946 Type *Op1ElemTy =
nullptr;
5948 case Intrinsic::matrix_multiply: {
5949 NumRows = cast<ConstantInt>(
Call.getArgOperand(2));
5951 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
5952 Check(cast<FixedVectorType>(
Call.getArgOperand(0)->getType())
5953 ->getNumElements() ==
5955 "First argument of a matrix operation does not match specified "
5957 Check(cast<FixedVectorType>(
Call.getArgOperand(1)->getType())
5958 ->getNumElements() ==
5960 "Second argument of a matrix operation does not match specified "
5963 ResultTy = cast<VectorType>(
Call.getType());
5965 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
5967 cast<VectorType>(
Call.getArgOperand(1)->getType())->getElementType();
5970 case Intrinsic::matrix_transpose:
5971 NumRows = cast<ConstantInt>(
Call.getArgOperand(1));
5972 NumColumns = cast<ConstantInt>(
Call.getArgOperand(2));
5973 ResultTy = cast<VectorType>(
Call.getType());
5975 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
5977 case Intrinsic::matrix_column_major_load: {
5978 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(1));
5979 NumRows = cast<ConstantInt>(
Call.getArgOperand(3));
5980 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
5981 ResultTy = cast<VectorType>(
Call.getType());
5984 case Intrinsic::matrix_column_major_store: {
5985 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(2));
5986 NumRows = cast<ConstantInt>(
Call.getArgOperand(4));
5987 NumColumns = cast<ConstantInt>(
Call.getArgOperand(5));
5988 ResultTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
5990 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
5997 Check(ResultTy->getElementType()->isIntegerTy() ||
5998 ResultTy->getElementType()->isFloatingPointTy(),
5999 "Result type must be an integer or floating-point type!", IF);
6002 Check(ResultTy->getElementType() == Op0ElemTy,
6003 "Vector element type mismatch of the result and first operand "
6008 Check(ResultTy->getElementType() == Op1ElemTy,
6009 "Vector element type mismatch of the result and second operand "
6013 Check(cast<FixedVectorType>(ResultTy)->getNumElements() ==
6015 "Result of a matrix operation does not fit in the returned vector!");
6019 "Stride must be greater or equal than the number of rows!", IF);
6023 case Intrinsic::vector_splice: {
6025 int64_t
Idx = cast<ConstantInt>(
Call.getArgOperand(2))->getSExtValue();
6026 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
6027 if (
Call.getParent() &&
Call.getParent()->getParent()) {
6029 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
6030 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
6032 Check((
Idx < 0 && std::abs(
Idx) <= KnownMinNumElements) ||
6033 (
Idx >= 0 &&
Idx < KnownMinNumElements),
6034 "The splice index exceeds the range [-VL, VL-1] where VL is the "
6035 "known minimum number of elements in the vector. For scalable "
6036 "vectors the minimum number of elements is determined from "
6041 case Intrinsic::experimental_stepvector: {
6043 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
6044 VecTy->getScalarSizeInBits() >= 8,
6045 "experimental_stepvector only supported for vectors of integers "
6046 "with a bitwidth of at least 8.",
6050 case Intrinsic::vector_insert: {
6054 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6061 Check(VecTy->getElementType() == SubVecTy->getElementType(),
6062 "vector_insert parameters must have the same element "
6066 "vector_insert index must be a constant multiple of "
6067 "the subvector's known minimum vector length.");
6075 "subvector operand of vector_insert would overrun the "
6076 "vector being inserted into.");
6080 case Intrinsic::vector_extract: {
6083 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6091 Check(ResultTy->getElementType() == VecTy->getElementType(),
6092 "vector_extract result must have the same element "
6093 "type as the input vector.",
6096 "vector_extract index must be a constant multiple of "
6097 "the result type's known minimum vector length.");
6105 "vector_extract would overrun.");
6109 case Intrinsic::experimental_noalias_scope_decl: {
6110 NoAliasScopeDecls.
push_back(cast<IntrinsicInst>(&Call));
6113 case Intrinsic::preserve_array_access_index:
6114 case Intrinsic::preserve_struct_access_index:
6115 case Intrinsic::aarch64_ldaxr:
6116 case Intrinsic::aarch64_ldxr:
6117 case Intrinsic::arm_ldaex:
6118 case Intrinsic::arm_ldrex: {
6119 Type *ElemTy =
Call.getParamElementType(0);
6120 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
6124 case Intrinsic::aarch64_stlxr:
6125 case Intrinsic::aarch64_stxr:
6126 case Intrinsic::arm_stlex:
6127 case Intrinsic::arm_strex: {
6128 Type *ElemTy =
Call.getAttributes().getParamElementType(1);
6130 "Intrinsic requires elementtype attribute on second argument.",
6134 case Intrinsic::aarch64_prefetch: {
6135 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
6136 "write argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6137 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
6138 "target argument to llvm.aarch64.prefetch must be 0-3", Call);
6139 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
6140 "stream argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6141 Check(cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue() < 2,
6142 "isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6145 case Intrinsic::callbr_landingpad: {
6146 const auto *CBR = dyn_cast<CallBrInst>(
Call.getOperand(0));
6147 Check(CBR,
"intrinstic requires callbr operand", &Call);
6154 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &Call);
6158 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
6164 return IndDest == LandingPadBB;
6166 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
6167 "block in indirect destination list",
6170 Check(&
First == &Call,
"No other instructions may proceed intrinsic",
6174 case Intrinsic::amdgcn_cs_chain: {
6175 auto CallerCC =
Call.getCaller()->getCallingConv();
6182 CheckFailed(
"Intrinsic can only be used from functions with the "
6183 "amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6184 "calling conventions",
6189 Check(
Call.paramHasAttr(2, Attribute::InReg),
6190 "SGPR arguments must have the `inreg` attribute", &Call);
6191 Check(!
Call.paramHasAttr(3, Attribute::InReg),
6192 "VGPR arguments must not have the `inreg` attribute", &Call);
6195 case Intrinsic::amdgcn_set_inactive_chain_arg: {
6196 auto CallerCC =
Call.getCaller()->getCallingConv();
6202 CheckFailed(
"Intrinsic can only be used from functions with the "
6203 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6204 "calling conventions",
6209 unsigned InactiveIdx = 1;
6210 Check(!
Call.paramHasAttr(InactiveIdx, Attribute::InReg),
6211 "Value for inactive lanes must not have the `inreg` attribute",
6213 Check(isa<Argument>(
Call.getArgOperand(InactiveIdx)),
6214 "Value for inactive lanes must be a function argument", &Call);
6215 Check(!cast<Argument>(
Call.getArgOperand(InactiveIdx))->hasInRegAttr(),
6216 "Value for inactive lanes must be a VGPR function argument", &Call);
6219 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
6220 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
6222 unsigned RegCount = cast<ConstantInt>(V)->getZExtValue();
6223 Check(RegCount % 8 == 0,
6224 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6225 Check((RegCount >= 24 && RegCount <= 256),
6226 "reg_count argument to nvvm.setmaxnreg must be within [24, 256]");
6229 case Intrinsic::experimental_convergence_entry:
6230 case Intrinsic::experimental_convergence_anchor:
6232 case Intrinsic::experimental_convergence_loop:
6234 case Intrinsic::ptrmask: {
6235 Type *Ty0 =
Call.getArgOperand(0)->getType();
6236 Type *Ty1 =
Call.getArgOperand(1)->getType();
6238 "llvm.ptrmask intrinsic first argument must be pointer or vector "
6243 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
6246 Check(cast<VectorType>(Ty0)->getElementCount() ==
6247 cast<VectorType>(Ty1)->getElementCount(),
6248 "llvm.ptrmask intrinsic arguments must have the same number of "
6252 "llvm.ptrmask intrinsic second argument bitwidth must match "
6253 "pointer index type size of first argument",
6257 case Intrinsic::threadlocal_address: {
6258 const Value &Arg0 = *
Call.getArgOperand(0);
6259 Check(isa<GlobalValue>(Arg0),
6260 "llvm.threadlocal.address first argument must be a GlobalValue");
6261 Check(cast<GlobalValue>(Arg0).isThreadLocal(),
6262 "llvm.threadlocal.address operand isThreadLocal() must be true");
6270 if (
F->hasPersonalityFn() &&
6274 if (BlockEHFuncletColors.
empty())
6278 bool InEHFunclet =
false;
6283 if (dyn_cast_or_null<FuncletPadInst>(ColorFirstBB->getFirstNonPHI()))
6287 bool HasToken =
false;
6288 for (
unsigned I = 0, E =
Call.getNumOperandBundles();
I != E; ++
I)
6294 Check(HasToken,
"Missing funclet token on intrinsic call", &Call);
6307 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
6310 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
6314 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
6320 "invalid #dbg_label intrinsic variable", &DLR, DLR.
getRawLabel());
6324 if (!isa<DILocation>(
N))
6333 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DLR, BB,
F);
6337 if (!LabelSP || !LocSP)
6341 "mismatched subprogram between #dbg_label label and !dbg attachment",
6342 &DLR, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6343 Loc->getScope()->getSubprogram());
6353 "invalid #dbg record type", &DVR, DVR.
getType());
6359 CheckDI(MD && (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6360 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands())),
6361 "invalid #dbg record address/value", &DVR, MD);
6362 if (
auto *VAM = dyn_cast<ValueAsMetadata>(MD))
6363 visitValueAsMetadata(*VAM,
F);
6364 else if (
auto *AL = dyn_cast<DIArgList>(MD))
6365 visitDIArgList(*AL,
F);
6379 AreDebugLocsAllowed::No);
6386 isa<ValueAsMetadata>(RawAddr) ||
6387 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6389 if (
auto *VAM = dyn_cast<ValueAsMetadata>(RawAddr))
6390 visitValueAsMetadata(*VAM,
F);
6393 "invalid #dbg_assign address expression", &DVR,
6400 "inst not in same function as #dbg_assign",
I, &DVR);
6409 CheckDI(isa_and_nonnull<DILocation>(DLNode),
"invalid #dbg record DILocation",
6416 if (!VarSP || !LocSP)
6420 "mismatched subprogram between #dbg record variable and DILocation",
6422 Loc->getScope()->getSubprogram());
6427void Verifier::visitVPIntrinsic(
VPIntrinsic &VPI) {
6428 if (
auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
6429 auto *
RetTy = cast<VectorType>(VPCast->getType());
6430 auto *ValTy = cast<VectorType>(VPCast->getOperand(0)->getType());
6431 Check(
RetTy->getElementCount() == ValTy->getElementCount(),
6432 "VP cast intrinsic first argument and result vector lengths must be "
6436 switch (VPCast->getIntrinsicID()) {
6439 case Intrinsic::vp_trunc:
6441 "llvm.vp.trunc intrinsic first argument and result element type "
6445 "llvm.vp.trunc intrinsic the bit size of first argument must be "
6446 "larger than the bit size of the return type",
6449 case Intrinsic::vp_zext:
6450 case Intrinsic::vp_sext:
6452 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
6453 "element type must be integer",
6456 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
6457 "argument must be smaller than the bit size of the return type",
6460 case Intrinsic::vp_fptoui:
6461 case Intrinsic::vp_fptosi:
6462 case Intrinsic::vp_lrint:
6463 case Intrinsic::vp_llrint:
6466 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
6467 "type must be floating-point and result element type must be integer",
6470 case Intrinsic::vp_uitofp:
6471 case Intrinsic::vp_sitofp:
6474 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
6475 "type must be integer and result element type must be floating-point",
6478 case Intrinsic::vp_fptrunc:
6480 "llvm.vp.fptrunc intrinsic first argument and result element type "
6481 "must be floating-point",
6484 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
6485 "larger than the bit size of the return type",
6488 case Intrinsic::vp_fpext:
6490 "llvm.vp.fpext intrinsic first argument and result element type "
6491 "must be floating-point",
6494 "llvm.vp.fpext intrinsic the bit size of first argument must be "
6495 "smaller than the bit size of the return type",
6498 case Intrinsic::vp_ptrtoint:
6500 "llvm.vp.ptrtoint intrinsic first argument element type must be "
6501 "pointer and result element type must be integer",
6504 case Intrinsic::vp_inttoptr:
6506 "llvm.vp.inttoptr intrinsic first argument element type must be "
6507 "integer and result element type must be pointer",
6513 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6515 "invalid predicate for VP FP comparison intrinsic", &VPI);
6518 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6520 "invalid predicate for VP integer comparison intrinsic", &VPI);
6523 auto TestMask = cast<ConstantInt>(VPI.
getOperand(1));
6525 "unsupported bits for llvm.vp.is.fpclass test mask");
6530 unsigned NumOperands;
6533#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
6534 case Intrinsic::INTRINSIC: \
6535 NumOperands = NARG; \
6536 HasRoundingMD = ROUND_MODE; \
6538#include "llvm/IR/ConstrainedOps.def"
6542 NumOperands += (1 + HasRoundingMD);
6544 if (isa<ConstrainedFPCmpIntrinsic>(FPI))
6547 "invalid arguments for constrained FP intrinsic", &FPI);
6550 case Intrinsic::experimental_constrained_lrint:
6551 case Intrinsic::experimental_constrained_llrint: {
6555 "Intrinsic does not support vectors", &FPI);
6559 case Intrinsic::experimental_constrained_lround:
6560 case Intrinsic::experimental_constrained_llround: {
6564 "Intrinsic does not support vectors", &FPI);
6568 case Intrinsic::experimental_constrained_fcmp:
6569 case Intrinsic::experimental_constrained_fcmps: {
6570 auto Pred = cast<ConstrainedFPCmpIntrinsic>(&FPI)->getPredicate();
6572 "invalid predicate for constrained FP comparison intrinsic", &FPI);
6576 case Intrinsic::experimental_constrained_fptosi:
6577 case Intrinsic::experimental_constrained_fptoui: {
6581 "Intrinsic first argument must be floating point", &FPI);
6582 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6583 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6588 "Intrinsic first argument and result disagree on vector use", &FPI);
6590 "Intrinsic result must be an integer", &FPI);
6591 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6592 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6593 "Intrinsic first argument and result vector lengths must be equal",
6599 case Intrinsic::experimental_constrained_sitofp:
6600 case Intrinsic::experimental_constrained_uitofp: {
6604 "Intrinsic first argument must be integer", &FPI);
6605 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6606 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6611 "Intrinsic first argument and result disagree on vector use", &FPI);
6613 "Intrinsic result must be a floating point", &FPI);
6614 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6615 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6616 "Intrinsic first argument and result vector lengths must be equal",
6621 case Intrinsic::experimental_constrained_fptrunc:
6622 case Intrinsic::experimental_constrained_fpext: {
6628 "Intrinsic first argument must be FP or FP vector", &FPI);
6630 "Intrinsic result must be FP or FP vector", &FPI);
6632 "Intrinsic first argument and result disagree on vector use", &FPI);
6634 Check(cast<VectorType>(OperandTy)->getElementCount() ==
6635 cast<VectorType>(ResultTy)->getElementCount(),
6636 "Intrinsic first argument and result vector lengths must be equal",
6639 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
6641 "Intrinsic first argument's type must be larger than result type",
6645 "Intrinsic first argument's type must be smaller than result type",
6661 "invalid exception behavior argument", &FPI);
6662 if (HasRoundingMD) {
6670 CheckDI(isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6671 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
6672 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
6674 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
6677 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
6680 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(&DII)) {
6681 CheckDI(isa<DIAssignID>(DAI->getRawAssignID()),
6682 "invalid llvm.dbg.assign intrinsic DIAssignID", &DII,
6683 DAI->getRawAssignID());
6684 const auto *RawAddr = DAI->getRawAddress();
6686 isa<ValueAsMetadata>(RawAddr) ||
6687 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6688 "invalid llvm.dbg.assign intrinsic address", &DII,
6689 DAI->getRawAddress());
6690 CheckDI(isa<DIExpression>(DAI->getRawAddressExpression()),
6691 "invalid llvm.dbg.assign intrinsic address expression", &DII,
6692 DAI->getRawAddressExpression());
6695 CheckDI(DAI->getFunction() ==
I->getFunction(),
6696 "inst not in same function as dbg.assign",
I, DAI);
6701 if (!isa<DILocation>(
N))
6710 CheckDI(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
6715 if (!VarSP || !LocSP)
6719 "mismatched subprogram between llvm.dbg." + Kind +
6720 " variable and !dbg attachment",
6722 Loc->getScope()->getSubprogram());
6732 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DLI,
6737 if (!isa<DILocation>(
N))
6746 Check(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment", &DLI,
6751 if (!LabelSP || !LocSP)
6755 "mismatched subprogram between llvm.dbg." + Kind +
6756 " label and !dbg attachment",
6757 &DLI, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6758 Loc->getScope()->getSubprogram());
6763 DIExpression *E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6766 if (!V || !E || !E->
isValid())
6780 if (
V->isArtificial())
6783 verifyFragmentExpression(*V, *Fragment, &
I);
6790 if (!V || !E || !E->
isValid())
6804 if (
V->isArtificial())
6807 verifyFragmentExpression(*V, *Fragment, &DVR);
6810template <
typename ValueOrMetadata>
6811void Verifier::verifyFragmentExpression(
const DIVariable &V,
6813 ValueOrMetadata *
Desc) {
6816 auto VarSize =
V.getSizeInBits();
6822 CheckDI(FragSize + FragOffset <= *VarSize,
6823 "fragment is larger than or outside of variable",
Desc, &V);
6824 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
6835 if (
I.getDebugLoc()->getInlinedAt())
6839 CheckDI(Var,
"dbg intrinsic without variable");
6841 unsigned ArgNo = Var->
getArg();
6847 if (DebugFnArgs.
size() < ArgNo)
6848 DebugFnArgs.
resize(ArgNo,
nullptr);
6850 auto *Prev = DebugFnArgs[ArgNo - 1];
6851 DebugFnArgs[ArgNo - 1] = Var;
6852 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &
I,
6867 CheckDI(Var,
"#dbg record without variable");
6869 unsigned ArgNo = Var->
getArg();
6875 if (DebugFnArgs.
size() < ArgNo)
6876 DebugFnArgs.
resize(ArgNo,
nullptr);
6878 auto *Prev = DebugFnArgs[ArgNo - 1];
6879 DebugFnArgs[ArgNo - 1] = Var;
6880 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DVR,
6885 DIExpression *E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6891 if (isa<ValueAsMetadata>(
I.getRawLocation())) {
6892 Value *VarValue =
I.getVariableLocationOp(0);
6893 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6897 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6898 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6903 "Entry values are only allowed in MIR unless they target a "
6904 "swiftasync Argument",
6916 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6920 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6921 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6926 "Entry values are only allowed in MIR unless they target a "
6927 "swiftasync Argument",
6931void Verifier::verifyCompileUnits() {
6935 if (
M.getContext().isODRUniquingDebugTypes())
6937 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
6940 Listed.
insert(CUs->op_begin(), CUs->op_end());
6941 for (
const auto *
CU : CUVisited)
6946void Verifier::verifyDeoptimizeCallingConvs() {
6947 if (DeoptimizeDeclarations.
empty())
6951 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
6952 Check(
First->getCallingConv() ==
F->getCallingConv(),
6953 "All llvm.experimental.deoptimize declarations must have the same "
6954 "calling convention",
6959void Verifier::verifyAttachedCallBundle(
const CallBase &Call,
6963 Check((FTy->getReturnType()->isPointerTy() ||
6964 (
Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())),
6965 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
6966 "function returning a pointer or a non-returning function that has a "
6971 "operand bundle \"clang.arc.attachedcall\" requires one function as "
6975 auto *Fn = cast<Function>(BU.
Inputs.front());
6979 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
6980 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
6981 "invalid function argument", Call);
6984 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
6985 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
6986 "invalid function argument", Call);
6990void Verifier::verifyNoAliasScopeDecl() {
6991 if (NoAliasScopeDecls.
empty())
6995 for (
auto *II : NoAliasScopeDecls) {
6996 assert(II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
6997 "Not a llvm.experimental.noalias.scope.decl ?");
6998 const auto *ScopeListMV = dyn_cast<MetadataAsValue>(
7000 Check(ScopeListMV !=
nullptr,
7001 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
7005 const auto *ScopeListMD = dyn_cast<MDNode>(ScopeListMV->getMetadata());
7006 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode", II);
7007 Check(ScopeListMD->getNumOperands() == 1,
7008 "!id.scope.list must point to a list with a single scope", II);
7009 visitAliasScopeListMetadata(ScopeListMD);
7020 const auto *ScopeListMV = cast<MetadataAsValue>(
7022 return &cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
7028 return GetScope(Lhs) < GetScope(Rhs);
7035 auto ItCurrent = NoAliasScopeDecls.begin();
7036 while (ItCurrent != NoAliasScopeDecls.end()) {
7037 auto CurScope = GetScope(*ItCurrent);
7038 auto ItNext = ItCurrent;
7041 }
while (ItNext != NoAliasScopeDecls.end() &&
7042 GetScope(*ItNext) == CurScope);
7047 if (ItNext - ItCurrent < 32)
7052 "llvm.experimental.noalias.scope.decl dominates another one "
7053 "with the same scope",
7071 return !V.verify(
F);
7075 bool *BrokenDebugInfo) {
7079 bool Broken =
false;
7081 Broken |= !V.verify(
F);
7083 Broken |= !V.verify();
7084 if (BrokenDebugInfo)
7085 *BrokenDebugInfo = V.hasBrokenDebugInfo();
7096 std::unique_ptr<Verifier> V;
7097 bool FatalErrors =
true;
7102 explicit VerifierLegacyPass(
bool FatalErrors)
7104 FatalErrors(FatalErrors) {
7108 bool doInitialization(
Module &M)
override {
7109 V = std::make_unique<Verifier>(
7115 if (!
V->verify(
F) && FatalErrors) {
7116 errs() <<
"in function " <<
F.getName() <<
'\n';
7122 bool doFinalization(
Module &M)
override {
7123 bool HasErrors =
false;
7125 if (
F.isDeclaration())
7126 HasErrors |= !
V->verify(
F);
7128 HasErrors |= !
V->verify();
7129 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
7142template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
7147#define CheckTBAA(C, ...) \
7150 CheckFailed(__VA_ARGS__); \
7158TBAAVerifier::TBAABaseNodeSummary
7162 CheckFailed(
"Base nodes must have at least two operands", &
I, BaseNode);
7166 auto Itr = TBAABaseNodes.find(BaseNode);
7167 if (Itr != TBAABaseNodes.end())
7170 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
7171 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
7173 assert(InsertResult.second &&
"We just checked!");
7177TBAAVerifier::TBAABaseNodeSummary
7180 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
7184 return isValidScalarTBAANode(BaseNode)
7185 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
7191 CheckFailed(
"Access tag nodes must have the number of operands that is a "
7192 "multiple of 3!", BaseNode);
7197 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
7205 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7207 if (!TypeSizeNode) {
7208 CheckFailed(
"Type size nodes must be constants!", &
I, BaseNode);
7214 if (!IsNewFormat && !isa<MDString>(BaseNode->
getOperand(0))) {
7215 CheckFailed(
"Struct tag nodes have a string as their first operand",
7222 std::optional<APInt> PrevOffset;
7227 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7228 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7230 Idx += NumOpsPerField) {
7233 if (!isa<MDNode>(FieldTy)) {
7234 CheckFailed(
"Incorrect field entry in struct type node!", &
I, BaseNode);
7239 auto *OffsetEntryCI =
7240 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
7241 if (!OffsetEntryCI) {
7242 CheckFailed(
"Offset entries must be constants!", &
I, BaseNode);
7248 BitWidth = OffsetEntryCI->getBitWidth();
7250 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
7252 "Bitwidth between the offsets and struct type entries must match", &
I,
7264 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
7267 CheckFailed(
"Offsets must be increasing!", &
I, BaseNode);
7271 PrevOffset = OffsetEntryCI->getValue();
7274 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7276 if (!MemberSizeNode) {
7277 CheckFailed(
"Member size entries must be constants!", &
I, BaseNode);
7284 return Failed ? InvalidNode
7285 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
7306 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
7307 return Parent && Visited.
insert(Parent).second &&
7311bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
7312 auto ResultIt = TBAAScalarNodes.find(MD);
7313 if (ResultIt != TBAAScalarNodes.end())
7314 return ResultIt->second;
7318 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
7320 assert(InsertResult.second &&
"Just checked!");
7339 return cast<MDNode>(BaseNode->
getOperand(1));
7341 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7342 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7344 Idx += NumOpsPerField) {
7345 auto *OffsetEntryCI =
7346 mdconst::extract<ConstantInt>(BaseNode->
getOperand(
Idx + 1));
7347 if (OffsetEntryCI->getValue().ugt(
Offset)) {
7348 if (
Idx == FirstFieldOpNo) {
7349 CheckFailed(
"Could not find TBAA parent in struct type node", &
I,
7354 unsigned PrevIdx =
Idx - NumOpsPerField;
7355 auto *PrevOffsetEntryCI =
7356 mdconst::extract<ConstantInt>(BaseNode->
getOperand(PrevIdx + 1));
7357 Offset -= PrevOffsetEntryCI->getValue();
7358 return cast<MDNode>(BaseNode->
getOperand(PrevIdx));
7363 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
7365 Offset -= LastOffsetEntryCI->getValue();
7366 return cast<MDNode>(BaseNode->
getOperand(LastIdx));
7370 if (!
Type ||
Type->getNumOperands() < 3)
7375 return isa_and_nonnull<MDNode>(
Type->getOperand(0));
7382 CheckTBAA(isa<LoadInst>(
I) || isa<StoreInst>(
I) || isa<CallInst>(
I) ||
7383 isa<VAArgInst>(
I) || isa<AtomicRMWInst>(
I) ||
7384 isa<AtomicCmpXchgInst>(
I),
7385 "This instruction shall not have a TBAA access tag!", &
I);
7387 bool IsStructPathTBAA =
7391 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
7401 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
7404 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
7409 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7411 CheckTBAA(AccessSizeNode,
"Access size field must be a constant", &
I, MD);
7415 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
7417 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
7420 "Immutability tag on struct tag metadata must be a constant", &
I,
7423 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
7424 "Immutability part of the struct tag metadata must be either 0 or 1",
7429 "Malformed struct tag metadata: base and access-type "
7430 "should be non-null and point to Metadata nodes",
7431 &
I, MD, BaseNode, AccessType);
7434 CheckTBAA(isValidScalarTBAANode(AccessType),
7435 "Access type node must be a valid scalar type", &
I, MD,
7439 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
7440 CheckTBAA(OffsetCI,
"Offset must be constant integer", &
I, MD);
7443 bool SeenAccessTypeInPath =
false;
7448 BaseNode = getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset,
7450 if (!StructPath.
insert(BaseNode).second) {
7451 CheckFailed(
"Cycle detected in struct path", &
I, MD);
7456 unsigned BaseNodeBitWidth;
7457 std::tie(
Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(
I, BaseNode,
7465 SeenAccessTypeInPath |= BaseNode == AccessType;
7467 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
7468 CheckTBAA(
Offset == 0,
"Offset not zero at the point of scalar access",
7472 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
7473 (IsNewFormat && BaseNodeBitWidth == ~0u),
7474 "Access bit-width not the same as description bit-width", &
I, MD,
7475 BaseNodeBitWidth,
Offset.getBitWidth());
7477 if (IsNewFormat && SeenAccessTypeInPath)
7481 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!", &
I,
7486char VerifierLegacyPass::ID = 0;
7487INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
7490 return new VerifierLegacyPass(FatalErrors);
7508 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
7516 if (res.IRBroken && FatalErrors)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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...
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 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.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
verify safepoint Safepoint IR Verifier
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
This file defines the SmallVector class.
This defines the Use 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 LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
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...
bool isEHPad() const
Return true if this basic block is an exception handling block.
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.
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.
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
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)
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This instruction compares its operands according to the predicate given to the constructor.
This class represents an extension of floating point types.
This class represents a cast from floating point to signed integer.
This class represents a cast from floating point to unsigned integer.
This class represents a truncation of floating point types.
An instruction for ordering other memory operations.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
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 BasicBlock * getParent() const
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.
BasicBlock * getUnwindDest() const
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.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ X86_INTR
x86 hardware interrupt context.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ C
The default llvm calling convention, compatible with C.
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
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)
bool isFortran(SourceLanguage S)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool canInstructionHaveMMRAs(const Instruction &I)
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.
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)
@ Invalid
Denotes invalid value.
@ 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.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Holds the characteristics of one fragment of a larger variable.
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).