116 using namespace llvm;
137 : OS(OS), M(M),
MST(&M),
DL(M.getDataLayout()),
Context(M.getContext()) {}
144 void Write(
const Value *V) {
147 if (isa<Instruction>(V)) {
178 void Write(
Type *
T) {
190 void Write(
const APInt *AI) {
196 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
199 for (
const T &V : Vs)
203 template <
typename T1,
typename... Ts>
204 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
209 template <
typename... Ts>
void WriteTs() {}
218 *
OS << Message <<
'\n';
226 template <
typename T1,
typename... Ts>
236 *
OS << Message <<
'\n';
242 template <
typename T1,
typename... Ts>
277 Type *LandingPadResultTy;
284 bool HasDebugInfo =
false;
317 SawFrameEscape(
false), TBAAVerifyHelper(this) {
318 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
321 bool hasBrokenDebugInfo()
const {
return BrokenDebugInfo; }
325 "An instance of this class only works with a specific module!");
334 DT.recalculate(const_cast<Function &>(F));
337 if (!BB.empty() && BB.back().isTerminator())
341 *OS <<
"Basic Block in function '" << F.getName()
342 <<
"' does not have terminator!\n";
343 BB.printAsOperand(*OS,
true, MST);
351 visit(const_cast<Function &>(F));
352 verifySiblingFuncletUnwinds();
353 InstsInThisBlock.clear();
355 LandingPadResultTy =
nullptr;
356 SawFrameEscape =
false;
357 SiblingFuncletInfo.clear();
368 if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
369 DeoptimizeDeclarations.push_back(&F);
373 verifyFrameRecoverIndices();
375 visitGlobalVariable(GV);
378 visitGlobalAlias(GA);
381 visitNamedMDNode(NMD);
384 visitComdat(SMEC.getValue());
387 visitModuleIdents(M);
389 verifyCompileUnits();
391 verifyDeoptimizeCallingConvs();
392 DISubprogramAttachments.clear();
405 void visitMDNode(
const MDNode &MD);
408 void visitComdat(
const Comdat &C);
409 void visitModuleIdents(
const Module &M);
410 void visitModuleFlags(
const Module &M);
411 void visitModuleFlag(
const MDNode *
Op,
414 void visitFunction(
const Function &F);
419 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
420 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
421 #include "llvm/IR/Metadata.def"
422 void visitDIScope(
const DIScope &
N);
446 void visitPHINode(
PHINode &PN);
453 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
471 template <
class DbgIntrinsicTy>
490 void verifySwiftErrorCallSite(
CallSite CS,
const Value *SwiftErrorVal);
491 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
492 void verifyMustTailCall(
CallInst &CI);
494 unsigned ArgNo, std::string &Suffix);
501 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
503 void visitConstantExprsRecursively(
const Constant *EntryC);
506 void verifyFrameRecoverIndices();
507 void verifySiblingFuncletUnwinds();
513 void verifyCompileUnits();
517 void verifyDeoptimizeCallingConvs();
523 #define Assert(C, ...) \
524 do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false)
528 #define AssertDI(C, ...) \
529 do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false)
543 if (!Visited.
insert(User).second)
546 if (Callback(TheNextUser))
550 void Verifier::visitGlobalValue(
const GlobalValue &GV) {
552 "Global is external, but doesn't have external or weak linkage!", &GV);
555 "huge alignment values are unsupported", &GV);
557 "Only global variables can have appending linkage!", &GV);
562 "Only global arrays can have appending linkage!", GVar);
570 if (!
I->getParent() || !
I->getParent()->getParent())
571 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
573 else if (
I->getParent()->getParent()->getParent() != &M)
574 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
575 I->getParent()->getParent(),
576 I->getParent()->getParent()->getParent());
578 }
else if (
const Function *F = dyn_cast<Function>(V)) {
579 if (F->getParent() != &M)
580 CheckFailed(
"Global is used by function in a different module", &GV, &M,
591 "Global variable initializer type does not match global "
598 "'common' global must have a zero initializer!", &GV);
601 Assert(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
606 GV.
getName() ==
"llvm.global_dtors")) {
608 "invalid linkage for intrinsic global variable", &GV);
620 "wrong type for intrinsic global variable", &GV);
624 cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),
625 "wrong type for intrinsic global variable", &GV);
631 GV.
getName() ==
"llvm.compiler.used")) {
633 "invalid linkage for intrinsic global variable", &GV);
635 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
637 Assert(PTy,
"wrong type for intrinsic global variable", &GV);
641 Assert(InitArray,
"wrong initalizer for intrinsic global variable",
644 Value *V =
Op->stripPointerCastsNoFollowAliases();
645 Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||
647 "invalid llvm.used member", V);
648 Assert(V->
hasName(),
"members of llvm.used must be named", V);
657 "Global is marked as dllimport, but not external", &GV);
662 for (
auto *MD : MDs) {
663 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
664 visitDIGlobalVariableExpression(*GVE);
666 AssertDI(
false,
"!dbg attachment of global variable must be a "
667 "DIGlobalVariableExpression");
671 visitGlobalValue(GV);
678 visitGlobalValue(GV);
684 visitAliaseeSubExpr(Visited, GA, C);
689 if (
const auto *GV = dyn_cast<GlobalValue>(&C)) {
693 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
694 Assert(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
696 Assert(!GA2->isInterposable(),
"Alias cannot point to an interposable alias",
705 if (
const auto *CE = dyn_cast<ConstantExpr>(&C))
706 visitConstantExprsRecursively(CE);
710 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
711 visitAliaseeSubExpr(Visited, GA, *GA2->
getAliasee());
712 else if (
const auto *C2 = dyn_cast<Constant>(V))
713 visitAliaseeSubExpr(Visited, GA, *C2);
717 void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
719 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
720 "weak_odr, or external linkage!",
723 Assert(Aliasee,
"Aliasee cannot be NULL!", &GA);
725 "Alias and aliasee types should match!", &GA);
727 Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
728 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
730 visitAliaseeSubExpr(GA, *Aliasee);
732 visitGlobalValue(GA);
735 void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
740 "unrecognized named metadata node in the llvm.dbg namespace",
743 if (NMD.
getName() ==
"llvm.dbg.cu")
744 AssertDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
753 void Verifier::visitMDNode(
const MDNode &MD) {
756 if (!MDNodes.insert(&MD).second)
762 case Metadata::MDTupleKind:
764 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
765 case Metadata::CLASS##Kind: \
766 visit##CLASS(cast<CLASS>(MD)); \
768 #include "llvm/IR/Metadata.def"
774 Assert(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
776 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
780 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
781 visitValueAsMetadata(*V,
nullptr);
794 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
800 Assert(F,
"function-local metadata used outside a function", L);
805 if (
Instruction *
I = dyn_cast<Instruction>(L->getValue())) {
806 Assert(
I->getParent(),
"function-local metadata not in basic block",
L,
I);
807 ActualF =
I->getParent()->getParent();
808 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
809 ActualF = BB->getParent();
810 else if (
Argument *
A = dyn_cast<Argument>(L->getValue()))
811 ActualF =
A->getParent();
812 assert(ActualF &&
"Unimplemented function local metadata case!");
814 Assert(ActualF == F,
"function-local metadata used in wrong function", L);
819 if (
auto *
N = dyn_cast<MDNode>(MD)) {
826 if (!MDNodes.insert(MD).second)
829 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
830 visitValueAsMetadata(*V, F);
837 void Verifier::visitDILocation(
const DILocation &
N) {
839 "location requires a valid scope", &N, N.
getRawScope());
841 AssertDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
848 void Verifier::visitDIScope(
const DIScope &N) {
850 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
853 void Verifier::visitDISubrange(
const DISubrange &N) {
854 AssertDI(N.
getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
858 void Verifier::visitDIEnumerator(
const DIEnumerator &N) {
862 void Verifier::visitDIBasicType(
const DIBasicType &N) {
864 N.
getTag() == dwarf::DW_TAG_unspecified_type,
873 N.
getTag() == dwarf::DW_TAG_pointer_type ||
874 N.
getTag() == dwarf::DW_TAG_ptr_to_member_type ||
875 N.
getTag() == dwarf::DW_TAG_reference_type ||
876 N.
getTag() == dwarf::DW_TAG_rvalue_reference_type ||
877 N.
getTag() == dwarf::DW_TAG_const_type ||
878 N.
getTag() == dwarf::DW_TAG_volatile_type ||
879 N.
getTag() == dwarf::DW_TAG_restrict_type ||
880 N.
getTag() == dwarf::DW_TAG_atomic_type ||
881 N.
getTag() == dwarf::DW_TAG_member ||
882 N.
getTag() == dwarf::DW_TAG_inheritance ||
883 N.
getTag() == dwarf::DW_TAG_friend,
885 if (N.
getTag() == dwarf::DW_TAG_ptr_to_member_type) {
886 AssertDI(
isType(N.getRawExtraData()),
"invalid pointer to member type", &N,
887 N.getRawExtraData());
894 if (N.getDWARFAddressSpace()) {
896 N.
getTag() == dwarf::DW_TAG_reference_type,
897 "DWARF address space only applies to pointer or reference types",
903 return (Flags & DINode::FlagLValueReference) &&
904 (Flags & DINode::FlagRValueReference);
907 void Verifier::visitTemplateParams(
const MDNode &N,
const Metadata &RawParams) {
909 AssertDI(Params,
"invalid template params", &N, &RawParams);
911 AssertDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
921 N.
getTag() == dwarf::DW_TAG_structure_type ||
922 N.
getTag() == dwarf::DW_TAG_union_type ||
923 N.
getTag() == dwarf::DW_TAG_enumeration_type ||
924 N.
getTag() == dwarf::DW_TAG_class_type,
936 "invalid reference flags", &N);
938 visitTemplateParams(N, *Params);
940 if (N.
getTag() == dwarf::DW_TAG_class_type ||
941 N.
getTag() == dwarf::DW_TAG_union_type) {
943 "class/union requires a filename", &
N, N.
getFile());
948 AssertDI(N.
getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
950 AssertDI(isa<MDTuple>(Types),
"invalid composite elements", &N, Types);
952 AssertDI(
isType(Ty),
"invalid subroutine type ref", &N, Types, Ty);
956 "invalid reference flags", &N);
959 void Verifier::visitDIFile(
const DIFile &N) {
962 N.getChecksum().empty()),
"invalid checksum kind", &N);
977 "invalid emission kind", &N);
980 AssertDI(isa<MDTuple>(Array),
"invalid enum list", &N, Array);
982 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
983 AssertDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
984 "invalid enum type", &
N, N.getEnumTypes(),
Op);
988 AssertDI(isa<MDTuple>(Array),
"invalid retained type list", &N, Array);
991 (isa<DISubprogram>(
Op) &&
992 !cast<DISubprogram>(
Op)->isDefinition())),
993 "invalid retained type", &N,
Op);
997 AssertDI(isa<MDTuple>(Array),
"invalid global variable list", &N, Array);
1000 "invalid global variable ref", &N,
Op);
1004 AssertDI(isa<MDTuple>(Array),
"invalid imported entity list", &N, Array);
1006 AssertDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1011 AssertDI(isa<MDTuple>(Array),
"invalid macro list", &N, Array);
1013 AssertDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &N,
Op);
1016 CUVisited.insert(&N);
1019 void Verifier::visitDISubprogram(
const DISubprogram &N) {
1021 AssertDI(
isScope(N.getRawScope()),
"invalid scope", &N, N.getRawScope());
1023 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1025 AssertDI(N.getLine() == 0,
"line specified with no file", &
N, N.getLine());
1026 if (
auto *T = N.getRawType())
1027 AssertDI(isa<DISubroutineType>(T),
"invalid subroutine type", &
N,
T);
1028 AssertDI(
isType(N.getRawContainingType()),
"invalid containing type", &N,
1029 N.getRawContainingType());
1030 if (
auto *Params = N.getRawTemplateParams())
1031 visitTemplateParams(N, *Params);
1032 if (
auto *S = N.getRawDeclaration())
1033 AssertDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1034 "invalid subprogram declaration", &
N, S);
1035 if (
auto *RawVars = N.getRawVariables()) {
1037 AssertDI(Vars,
"invalid variable list", &N, RawVars);
1039 AssertDI(
Op && isa<DILocalVariable>(
Op),
"invalid local variable", &N,
1044 "invalid reference flags", &N);
1046 auto *
Unit = N.getRawUnit();
1047 if (N.isDefinition()) {
1050 AssertDI(
Unit,
"subprogram definitions must have a compile unit", &N);
1054 AssertDI(!
Unit,
"subprogram declarations must not have a compile unit", &N);
1057 if (
auto *RawThrownTypes = N.getRawThrownTypes()) {
1059 AssertDI(ThrownTypes,
"invalid thrown types list", &N, RawThrownTypes);
1061 AssertDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1067 AssertDI(N.
getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1073 visitDILexicalBlockBase(N);
1076 "cannot have column info without line info", &
N);
1080 visitDILexicalBlockBase(N);
1083 void Verifier::visitDINamespace(
const DINamespace &N) {
1086 AssertDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1089 void Verifier::visitDIMacro(
const DIMacro &N) {
1092 "invalid macinfo type", &
N);
1099 void Verifier::visitDIMacroFile(
const DIMacroFile &N) {
1101 "invalid macinfo type", &
N);
1103 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1106 AssertDI(isa<MDTuple>(Array),
"invalid macro list", &N, Array);
1108 AssertDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &N,
Op);
1113 void Verifier::visitDIModule(
const DIModule &N) {
1123 visitDITemplateParameter(N);
1125 AssertDI(N.
getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1129 void Verifier::visitDITemplateValueParameter(
1131 visitDITemplateParameter(N);
1134 N.
getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1135 N.
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1139 void Verifier::visitDIVariable(
const DIVariable &N) {
1141 AssertDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1144 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1154 AssertDI(isa<DIDerivedType>(Member),
1155 "invalid static data member declaration", &N, Member);
1165 "local variable requires a valid scope", &N, N.
getRawScope());
1168 void Verifier::visitDIExpression(
const DIExpression &N) {
1172 void Verifier::visitDIGlobalVariableExpression(
1176 visitDIGlobalVariable(*Var);
1178 visitDIExpression(*Expr);
1182 AssertDI(N.
getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1186 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1191 N.
getTag() == dwarf::DW_TAG_imported_declaration,
1194 AssertDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1199 void Verifier::visitComdat(
const Comdat &C) {
1207 void Verifier::visitModuleIdents(
const Module &M) {
1216 "incorrect number of operands in llvm.ident metadata",
N);
1218 (
"invalid value for llvm.ident metadata entry operand"
1219 "(the operand should be a string)"),
1224 void Verifier::visitModuleFlags(
const Module &M) {
1232 visitModuleFlag(MDN, SeenIDs, Requirements);
1235 for (
const MDNode *Requirement : Requirements) {
1236 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1237 const Metadata *ReqValue = Requirement->getOperand(1);
1241 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1247 CheckFailed((
"invalid requirement on flag, "
1248 "flag does not have the required value"),
1256 Verifier::visitModuleFlag(
const MDNode *Op,
1262 "incorrect number of operands in module flag",
Op);
1266 mdconst::dyn_extract_or_null<ConstantInt>(Op->
getOperand(0)),
1267 "invalid behavior operand in module flag (expected constant integer)",
1270 "invalid behavior operand in module flag (unexpected constant)",
1274 Assert(ID,
"invalid ID operand in module flag (expected metadata string)",
1287 "invalid value for 'max' module flag (expected constant integer)",
1297 "invalid value for 'require' module flag (expected metadata pair)",
1300 (
"invalid value for 'require' module flag "
1301 "(first value operand should be a string)"),
1314 "invalid value for 'append'-type module flag "
1315 "(expected a metadata node)",
1323 bool Inserted = SeenIDs.
insert(std::make_pair(ID, Op)).second;
1325 "module flag identifiers must be unique (or of 'require' type)", ID);
1330 = mdconst::dyn_extract_or_null<ConstantInt>(Op->
getOperand(2));
1331 Assert(Value,
"wchar_size metadata requires constant integer argument");
1334 if (ID->
getString() ==
"Linker Options") {
1339 "'Linker Options' named metadata no longer supported");
1346 case Attribute::NoReturn:
1347 case Attribute::NoUnwind:
1348 case Attribute::NoInline:
1349 case Attribute::AlwaysInline:
1350 case Attribute::OptimizeForSize:
1351 case Attribute::StackProtect:
1352 case Attribute::StackProtectReq:
1353 case Attribute::StackProtectStrong:
1354 case Attribute::SafeStack:
1355 case Attribute::NoRedZone:
1356 case Attribute::NoImplicitFloat:
1357 case Attribute::Naked:
1358 case Attribute::InlineHint:
1359 case Attribute::StackAlignment:
1360 case Attribute::UWTable:
1361 case Attribute::NonLazyBind:
1362 case Attribute::ReturnsTwice:
1363 case Attribute::SanitizeAddress:
1364 case Attribute::SanitizeThread:
1365 case Attribute::SanitizeMemory:
1366 case Attribute::MinSize:
1367 case Attribute::NoDuplicate:
1368 case Attribute::Builtin:
1369 case Attribute::NoBuiltin:
1371 case Attribute::OptimizeNone:
1374 case Attribute::ArgMemOnly:
1375 case Attribute::NoRecurse:
1376 case Attribute::InaccessibleMemOnly:
1377 case Attribute::InaccessibleMemOrArgMemOnly:
1378 case Attribute::AllocSize:
1379 case Attribute::Speculatable:
1390 return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly ||
1391 Kind == Attribute::ReadNone;
1397 if (
A.isStringAttribute())
1402 CheckFailed(
"Attribute '" +
A.getAsString() +
1403 "' only applies to functions!",
1408 CheckFailed(
"Attribute '" +
A.getAsString() +
1409 "' does not apply to functions!",
1423 verifyAttributeTypes(Attrs,
false, V);
1427 unsigned AttrCount = 0;
1430 AttrCount += Attrs.
hasAttribute(Attribute::StructRet) ||
1433 Assert(AttrCount <= 1,
"Attributes 'byval', 'inalloca', 'inreg', 'nest', "
1434 "and 'sret' are incompatible!",
1440 "'inalloca and readonly' are incompatible!",
1446 "'sret and returned' are incompatible!",
1452 "'zeroext and signext' are incompatible!",
1458 "'readnone and readonly' are incompatible!",
1464 "'readnone and writeonly' are incompatible!",
1470 "'readonly and writeonly' are incompatible!",
1476 "'noinline and alwaysinline' are incompatible!",
1481 "Wrong types for attribute: " +
1485 if (
PointerType *PTy = dyn_cast<PointerType>(Ty)) {
1490 "Attributes 'byval' and 'inalloca' do not support unsized types!",
1495 "Attribute 'swifterror' only applies to parameters "
1496 "with pointer to pointer type!",
1500 "Attribute 'byval' only applies to parameters with pointer type!",
1503 "Attribute 'swifterror' only applies to parameters "
1504 "with pointer type!",
1516 bool SawNest =
false;
1517 bool SawReturned =
false;
1518 bool SawSRet =
false;
1519 bool SawSwiftSelf =
false;
1520 bool SawSwiftError =
false;
1532 "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
1533 "'returned', 'swiftself', and 'swifterror' do not apply to return "
1540 "' does not apply to function returns",
1545 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
1549 verifyParameterAttrs(ArgAttrs, Ty, V);
1552 Assert(!SawNest,
"More than one parameter has attribute nest!", V);
1557 Assert(!SawReturned,
"More than one parameter has attribute returned!",
1560 "Incompatible argument and return types for 'returned' attribute",
1566 Assert(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
1568 "Attribute 'sret' is not on first or second parameter!", V);
1573 Assert(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
1574 SawSwiftSelf =
true;
1578 Assert(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!",
1580 SawSwiftError =
true;
1585 "inalloca isn't on the last parameter!", V);
1596 "Attributes 'readnone and readonly' are incompatible!", V);
1600 "Attributes 'readnone and writeonly' are incompatible!", V);
1604 "Attributes 'readonly and writeonly' are incompatible!", V);
1608 "Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
1614 "Attributes 'readnone and inaccessiblememonly' are incompatible!", V);
1618 "Attributes 'noinline and alwaysinline' are incompatible!", V);
1622 "Attribute 'optnone' requires 'noinline'!", V);
1625 "Attributes 'optsize and optnone' are incompatible!", V);
1628 "Attributes 'minsize and optnone' are incompatible!", V);
1634 "Attribute 'jumptable' requires 'unnamed_addr'", V);
1638 std::pair<unsigned, Optional<unsigned>>
Args =
1643 CheckFailed(
"'allocsize' " + Name +
" argument is out of bounds", V);
1648 CheckFailed(
"'allocsize' " + Name +
1649 " argument must refer to an integer parameter",
1657 if (!CheckParam(
"element size", Args.first))
1660 if (Args.second && !CheckParam(
"number of elements", *Args.second))
1665 void Verifier::verifyFunctionMetadata(
1666 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
1667 for (
const auto &Pair : MDs) {
1669 MDNode *MD = Pair.second;
1671 "!prof annotations should have no less than 2 operands", MD);
1677 "expected string with name of the !prof annotation", MD);
1680 Assert(ProfName.equals(
"function_entry_count"),
1681 "first operand should be 'function_entry_count'", MD);
1687 "expected integer argument to function_entry_count", MD);
1692 void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
1693 if (!ConstantExprVisited.insert(EntryC).second)
1699 while (!Stack.
empty()) {
1703 if (
const auto *CE = dyn_cast<ConstantExpr>(C))
1704 visitConstantExpr(CE);
1706 if (
const auto *GV = dyn_cast<GlobalValue>(C)) {
1709 Assert(GV->
getParent() == &M,
"Referencing global in another module!",
1719 if (!ConstantExprVisited.insert(OpC).second)
1726 void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
1727 if (CE->
getOpcode() == Instruction::BitCast)
1730 "Invalid bitcast", CE);
1732 if (CE->
getOpcode() == Instruction::IntToPtr ||
1733 CE->
getOpcode() == Instruction::PtrToInt) {
1734 auto *PtrTy = CE->
getOpcode() == Instruction::IntToPtr
1738 ?
"inttoptr not supported for non-integral pointers"
1739 :
"ptrtoint not supported for non-integral pointers";
1746 bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
1756 Intrinsic::experimental_gc_statepoint);
1762 "gc.statepoint must read and write all memory to preserve "
1763 "reordering restrictions required by safepoint semantics",
1767 Assert(isa<ConstantInt>(IDV),
"gc.statepoint ID must be a constant integer",
1771 Assert(isa<ConstantInt>(NumPatchBytesV),
1772 "gc.statepoint number of patchable bytes must be a constant integer",
1774 const int64_t NumPatchBytes =
1775 cast<ConstantInt>(NumPatchBytesV)->getSExtValue();
1777 Assert(NumPatchBytes >= 0,
"gc.statepoint number of patchable bytes must be "
1783 Assert(PT && PT->getElementType()->isFunctionTy(),
1784 "gc.statepoint callee must be of function pointer type", &CI,
Target);
1785 FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType());
1788 Assert(isa<ConstantInt>(NumCallArgsV),
1789 "gc.statepoint number of arguments to underlying call "
1790 "must be constant integer",
1792 const int NumCallArgs = cast<ConstantInt>(NumCallArgsV)->getZExtValue();
1794 "gc.statepoint number of arguments to underlying call "
1797 const int NumParams = (int)TargetFuncType->getNumParams();
1798 if (TargetFuncType->isVarArg()) {
1799 Assert(NumCallArgs >= NumParams,
1800 "gc.statepoint mismatch in number of vararg call args", &CI);
1803 Assert(TargetFuncType->getReturnType()->isVoidTy(),
1804 "gc.statepoint doesn't support wrapping non-void "
1805 "vararg functions yet",
1808 Assert(NumCallArgs == NumParams,
1809 "gc.statepoint mismatch in number of call args", &CI);
1812 Assert(isa<ConstantInt>(FlagsV),
1813 "gc.statepoint flags must be constant integer", &CI);
1814 const uint64_t Flags = cast<ConstantInt>(FlagsV)->getZExtValue();
1816 "unknown flag used in gc.statepoint flags argument", &CI);
1820 for (
int i = 0; i < NumParams; i++) {
1821 Type *ParamType = TargetFuncType->getParamType(i);
1823 Assert(ArgType == ParamType,
1824 "gc.statepoint call argument does not match wrapped "
1829 const int EndCallArgsInx = 4 + NumCallArgs;
1831 const Value *NumTransitionArgsV = CS.
getArgument(EndCallArgsInx+1);
1832 Assert(isa<ConstantInt>(NumTransitionArgsV),
1833 "gc.statepoint number of transition arguments "
1834 "must be constant integer",
1836 const int NumTransitionArgs =
1837 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
1838 Assert(NumTransitionArgs >= 0,
1839 "gc.statepoint number of transition arguments must be positive", &CI);
1840 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
1842 const Value *NumDeoptArgsV = CS.
getArgument(EndTransitionArgsInx+1);
1843 Assert(isa<ConstantInt>(NumDeoptArgsV),
1844 "gc.statepoint number of deoptimization arguments "
1845 "must be constant integer",
1847 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
1848 Assert(NumDeoptArgs >= 0,
"gc.statepoint number of deoptimization arguments "
1852 const int ExpectedNumArgs =
1853 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs;
1855 "gc.statepoint too few arguments according to length fields", &CI);
1860 for (
const User *U : CI.
users()) {
1862 Assert(Call,
"illegal use of statepoint token", &CI, U);
1863 if (!Call)
continue;
1864 Assert(isa<GCRelocateInst>(Call) || isa<GCResultInst>(Call),
1865 "gc.result or gc.relocate are the only value uses "
1866 "of a gc.statepoint",
1868 if (isa<GCResultInst>(Call)) {
1870 "gc.result connected to wrong gc.statepoint", &CI,
Call);
1871 }
else if (isa<GCRelocateInst>(Call)) {
1873 "gc.relocate connected to wrong gc.statepoint", &CI,
Call);
1887 void Verifier::verifyFrameRecoverIndices() {
1888 for (
auto &Counts : FrameEscapeInfo) {
1890 unsigned EscapedObjectCount = Counts.second.first;
1891 unsigned MaxRecoveredIndex = Counts.second.second;
1892 Assert(MaxRecoveredIndex <= EscapedObjectCount,
1893 "all indices passed to llvm.localrecover must be less than the "
1894 "number of arguments passed ot llvm.localescape in the parent "
1902 if (
auto *II = dyn_cast<InvokeInst>(Terminator))
1903 UnwindDest = II->getUnwindDest();
1904 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
1905 UnwindDest = CSI->getUnwindDest();
1907 UnwindDest = cast<CleanupReturnInst>(
Terminator)->getUnwindDest();
1911 void Verifier::verifySiblingFuncletUnwinds() {
1914 for (
const auto &Pair : SiblingFuncletInfo) {
1916 if (Visited.
count(PredPad))
1922 if (Active.
count(SuccPad)) {
1929 if (CycleTerminator != CyclePad)
1932 }
while (CyclePad != SuccPad);
1933 Assert(
false,
"EH pads can't handle each other's exceptions",
1937 if (!Visited.
insert(SuccPad).second)
1941 auto TermI = SiblingFuncletInfo.find(PredPad);
1942 if (TermI == SiblingFuncletInfo.end())
1944 Terminator = TermI->second;
1955 void Verifier::visitFunction(
const Function &F) {
1956 visitGlobalValue(F);
1963 "Function context does not match Module context!", &
F);
1967 "# formal arguments must match # of arguments for function type!", &
F,
1969 Assert(F.getReturnType()->isFirstClassType() ||
1970 F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(),
1971 "Functions cannot return aggregate values!", &
F);
1973 Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),
1974 "Invalid struct return type!", &
F);
1979 "Attribute after last parameter!", &F);
1982 verifyFunctionAttrs(FT, Attrs, &F);
1987 Assert(!Attrs.hasFnAttribute(Attribute::Builtin),
1988 "Attribute 'builtin' can only be applied to a callsite.", &
F);
1993 switch (F.getCallingConv()) {
1999 Assert(F.getReturnType()->isVoidTy(),
2000 "Calling convention requires void return type", &
F);
2007 Assert(!F.hasStructRetAttr(),
2008 "Calling convention does not allow sret", &
F);
2015 Assert(!F.isVarArg(),
"Calling convention does not support varargs or "
2016 "perfect forwarding!",
2021 bool isLLVMdotName = F.getName().size() >= 5 &&
2022 F.getName().substr(0, 5) ==
"llvm.";
2026 for (
const Argument &Arg : F.args()) {
2028 "Argument value does not match function argument type!", &Arg,
2030 Assert(Arg.getType()->isFirstClassType(),
2031 "Function arguments must have first-class types!", &Arg);
2032 if (!isLLVMdotName) {
2033 Assert(!Arg.getType()->isMetadataTy(),
2034 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
2035 Assert(!Arg.getType()->isTokenTy(),
2036 "Function takes token but isn't an intrinsic", &Arg, &
F);
2040 if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) {
2041 verifySwiftErrorValue(&Arg);
2047 Assert(!F.getReturnType()->isTokenTy(),
2048 "Functions returns a token but isn't an intrinsic", &
F);
2052 F.getAllMetadata(MDs);
2053 assert(F.hasMetadata() != MDs.empty() &&
"Bit out-of-sync");
2054 verifyFunctionMetadata(MDs);
2057 if (F.hasPersonalityFn()) {
2060 Assert(Per->getParent() == F.getParent(),
2061 "Referencing personality function in another module!",
2062 &
F, F.getParent(), Per, Per->getParent());
2065 if (F.isMaterializable()) {
2067 Assert(MDs.empty(),
"unmaterialized function cannot have metadata", &
F,
2068 MDs.empty() ?
nullptr : MDs.front().second);
2069 }
else if (F.isDeclaration()) {
2070 for (
const auto &
I : MDs) {
2072 "function declaration may not have a !dbg attachment", &F);
2074 "function declaration may not have a !prof attachment", &F);
2077 visitMDNode(*
I.second);
2079 Assert(!F.hasPersonalityFn(),
2080 "Function declaration shouldn't have a personality routine", &
F);
2084 Assert(!isLLVMdotName,
"llvm intrinsics cannot be defined!", &F);
2087 const BasicBlock *Entry = &F.getEntryBlock();
2089 "Entry block to function must not have predecessors!", Entry);
2094 "blockaddress may not be used with the entry block!", Entry);
2097 unsigned NumDebugAttachments = 0, NumProfAttachments = 0;
2099 for (
const auto &
I : MDs) {
2105 ++NumDebugAttachments;
2107 "function must have a single !dbg attachment", &F,
I.second);
2109 "function !dbg attachment must be a subprogram", &F,
I.second);
2110 auto *
SP = cast<DISubprogram>(
I.second);
2111 const Function *&AttachedTo = DISubprogramAttachments[
SP];
2112 AssertDI(!AttachedTo || AttachedTo == &F,
2113 "DISubprogram attached to more than one function", SP, &F);
2118 ++NumProfAttachments;
2119 Assert(NumProfAttachments == 1,
2120 "function must have a single !prof attachment", &F,
I.second);
2125 visitMDNode(*
I.second);
2133 if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
2135 if (F.hasAddressTaken(&U))
2136 Assert(
false,
"Invalid user of intrinsic instruction!", U);
2139 Assert(!F.hasDLLImportStorageClass() ||
2140 (F.isDeclaration() && F.hasExternalLinkage()) ||
2141 F.hasAvailableExternallyLinkage(),
2142 "Function is marked as dllimport, but not external.", &
F);
2144 auto *N = F.getSubprogram();
2145 HasDebugInfo = (N !=
nullptr);
2156 for (
auto &
I : BB) {
2160 dyn_cast_or_null<DILocation>(
I.getDebugLoc().getAsMDNode());
2163 if (!Seen.
insert(DL).second)
2167 if (Scope && !Seen.
insert(Scope).second)
2174 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
2179 "!dbg attachment points at wrong subprogram for function",
N, &
F,
2186 void Verifier::visitBasicBlock(
BasicBlock &BB) {
2187 InstsInThisBlock.clear();
2194 if (isa<PHINode>(BB.
front())) {
2201 Assert(PN->getNumIncomingValues() != 0,
2202 "PHI nodes must have at least one entry. If the block is dead, "
2203 "the PHI should be removed!",
2205 Assert(PN->getNumIncomingValues() == Preds.size(),
2206 "PHINode should have one entry for each predecessor of its "
2207 "parent basic block!",
2212 Values.
reserve(PN->getNumIncomingValues());
2213 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
2214 Values.
push_back(std::make_pair(PN->getIncomingBlock(i),
2215 PN->getIncomingValue(i)));
2218 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
2225 "PHI node has multiple entries for the same basic block with "
2226 "different incoming values!",
2227 PN, Values[i].
first, Values[i].
second, Values[i - 1].second);
2232 "PHI node entries do not match predecessors!", PN,
2233 Values[i].
first, Preds[i]);
2241 Assert(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
2248 "Terminator found in the middle of a basic block!", I.
getParent());
2249 visitInstruction(I);
2252 void Verifier::visitBranchInst(
BranchInst &BI) {
2255 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
2257 visitTerminatorInst(BI);
2260 void Verifier::visitReturnInst(
ReturnInst &RI) {
2265 "Found return instr that returns non-void in Function of void "
2270 "Function return type does not match operand "
2271 "type of return inst!",
2276 visitTerminatorInst(RI);
2284 for (
auto &Case : SI.
cases()) {
2285 Assert(Case.getCaseValue()->getType() == SwitchTy,
2286 "Switch constants must all be same type as switch value!", &
SI);
2288 "Duplicate integer as switch case", &SI, Case.getCaseValue());
2291 visitTerminatorInst(SI);
2296 "Indirectbr operand must have pointer type!", &BI);
2299 "Indirectbr destinations must all have pointer type!", &BI);
2301 visitTerminatorInst(BI);
2304 void Verifier::visitSelectInst(
SelectInst &SI) {
2307 "Invalid operands for select instruction!", &SI);
2310 "Select values must have same type as select instruction!", &
SI);
2311 visitInstruction(SI);
2318 Assert(
false,
"User-defined operators should not live outside of a pass!", &I);
2321 void Verifier::visitTruncInst(
TruncInst &I) {
2333 "trunc source and destination must both be a vector or neither", &
I);
2334 Assert(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &I);
2336 visitInstruction(I);
2339 void Verifier::visitZExtInst(
ZExtInst &I) {
2348 "zext source and destination must both be a vector or neither", &
I);
2352 Assert(SrcBitSize < DestBitSize,
"Type too small for ZExt", &I);
2354 visitInstruction(I);
2357 void Verifier::visitSExtInst(
SExtInst &I) {
2369 "sext source and destination must both be a vector or neither", &
I);
2370 Assert(SrcBitSize < DestBitSize,
"Type too small for SExt", &I);
2372 visitInstruction(I);
2386 "fptrunc source and destination must both be a vector or neither", &
I);
2387 Assert(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &I);
2389 visitInstruction(I);
2392 void Verifier::visitFPExtInst(
FPExtInst &I) {
2404 "fpext source and destination must both be a vector or neither", &
I);
2405 Assert(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &I);
2407 visitInstruction(I);
2410 void Verifier::visitUIToFPInst(
UIToFPInst &I) {
2419 "UIToFP source and dest must both be vector or scalar", &I);
2421 "UIToFP source must be integer or integer vector", &
I);
2425 if (SrcVec && DstVec)
2426 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2427 cast<VectorType>(DestTy)->getNumElements(),
2428 "UIToFP source and dest vector length mismatch", &I);
2430 visitInstruction(I);
2433 void Verifier::visitSIToFPInst(
SIToFPInst &I) {
2442 "SIToFP source and dest must both be vector or scalar", &I);
2444 "SIToFP source must be integer or integer vector", &
I);
2448 if (SrcVec && DstVec)
2449 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2450 cast<VectorType>(DestTy)->getNumElements(),
2451 "SIToFP source and dest vector length mismatch", &I);
2453 visitInstruction(I);
2456 void Verifier::visitFPToUIInst(
FPToUIInst &I) {
2465 "FPToUI source and dest must both be vector or scalar", &I);
2469 "FPToUI result must be integer or integer vector", &
I);
2471 if (SrcVec && DstVec)
2472 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2473 cast<VectorType>(DestTy)->getNumElements(),
2474 "FPToUI source and dest vector length mismatch", &I);
2476 visitInstruction(I);
2479 void Verifier::visitFPToSIInst(
FPToSIInst &I) {
2488 "FPToSI source and dest must both be vector or scalar", &I);
2492 "FPToSI result must be integer or integer vector", &
I);
2494 if (SrcVec && DstVec)
2495 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2496 cast<VectorType>(DestTy)->getNumElements(),
2497 "FPToSI source and dest vector length mismatch", &I);
2499 visitInstruction(I);
2509 if (
auto *PTy = dyn_cast<PointerType>(SrcTy->
getScalarType()))
2510 Assert(!DL.isNonIntegralPointerType(PTy),
2511 "ptrtoint not supported for non-integral pointers");
2521 "PtrToInt Vector width mismatch", &
I);
2524 visitInstruction(I);
2533 "IntToPtr source must be an integral", &
I);
2536 if (
auto *PTy = dyn_cast<PointerType>(DestTy->
getScalarType()))
2537 Assert(!DL.isNonIntegralPointerType(PTy),
2538 "inttoptr not supported for non-integral pointers");
2546 "IntToPtr Vector width mismatch", &
I);
2548 visitInstruction(I);
2554 "Invalid bitcast", &I);
2555 visitInstruction(I);
2567 "AddrSpaceCast must be between different address spaces", &
I);
2570 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
2571 visitInstruction(I);
2576 void Verifier::visitPHINode(
PHINode &PN) {
2583 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
2592 "PHI node operands are not the same type as the result!", &PN);
2597 visitInstruction(PN);
2600 void Verifier::verifyCallSite(
CallSite CS) {
2604 "Called function must be a pointer!",
I);
2607 Assert(FPTy->getElementType()->isFunctionTy(),
2608 "Called function is not pointer to function type!",
I);
2611 "Called function is not the same type as the call!",
I);
2616 if (FTy->isVarArg())
2618 "Called function requires more parameters than were provided!",
I);
2621 "Incorrect number of arguments passed to called function!",
I);
2624 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2626 "Call parameter type does not match function signature!",
2632 "Attribute after last parameter!", I);
2640 "speculatable attribute may not apply to call sites",
I);
2644 verifyFunctionAttrs(FTy, Attrs, I);
2650 Value *InAllocaArg = CS.
getArgument(FTy->getNumParams() - 1);
2652 Assert(AI->isUsedWithInAlloca(),
2653 "inalloca argument for call has mismatched alloca", AI,
I);
2659 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2663 Assert(AI->isSwiftError(),
2664 "swifterror argument for call has mismatched alloca", AI,
I);
2668 Assert(ArgI,
"swifterror argument should come from an alloca or parameter", SwiftErrorArg, I);
2669 Assert(ArgI->hasSwiftErrorAttr(),
2670 "swifterror argument for call has mismatched parameter", ArgI,
I);
2673 if (FTy->isVarArg()) {
2675 bool SawNest =
false;
2676 bool SawReturned =
false;
2678 for (
unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
2686 for (
unsigned Idx = FTy->getNumParams(); Idx < CS.
arg_size(); ++Idx) {
2689 verifyParameterAttrs(ArgAttrs, Ty, I);
2692 Assert(!SawNest,
"More than one parameter has attribute nest!", I);
2697 Assert(!SawReturned,
"More than one parameter has attribute returned!",
2700 "Incompatible argument and return types for 'returned' "
2707 "Attribute 'sret' cannot be used for vararg call arguments!",
I);
2710 Assert(Idx == CS.
arg_size() - 1,
"inalloca isn't on the last argument!",
2718 for (
Type *ParamTy : FTy->params()) {
2719 Assert(!ParamTy->isMetadataTy(),
2720 "Function has metadata parameter but isn't an intrinsic",
I);
2721 Assert(!ParamTy->isTokenTy(),
2722 "Function has token parameter but isn't an intrinsic",
I);
2728 Assert(!FTy->getReturnType()->isTokenTy(),
2729 "Return type cannot be token for indirect call!");
2733 visitIntrinsicCallSite(ID, CS);
2737 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
2738 FoundGCTransitionBundle =
false;
2743 Assert(!FoundDeoptBundle,
"Multiple deopt operand bundles", I);
2744 FoundDeoptBundle =
true;
2746 Assert(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
2748 FoundGCTransitionBundle =
true;
2750 Assert(!FoundFuncletBundle,
"Multiple funclet operand bundles", I);
2751 FoundFuncletBundle =
true;
2753 "Expected exactly one funclet bundle operand",
I);
2755 "Funclet bundle operands should correspond to a FuncletPadInst",
2766 "debug info must have a !dbg location",
2769 visitInstruction(*I);
2786 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
2787 Attribute::InReg, Attribute::Returned, Attribute::SwiftSelf,
2788 Attribute::SwiftError};
2790 for (
auto AK : ABIAttrs) {
2799 void Verifier::verifyMustTailCall(
CallInst &CI) {
2809 "cannot guarantee tail call due to mismatched parameter counts", &CI);
2811 "cannot guarantee tail call due to mismatched varargs", &CI);
2813 "cannot guarantee tail call due to mismatched return types", &CI);
2817 "cannot guarantee tail call due to mismatched parameter types", &CI);
2822 "cannot guarantee tail call due to mismatched calling conv", &CI);
2831 Assert(CallerABIAttrs == CalleeABIAttrs,
2832 "cannot guarantee tail call due to mismatched ABI impacting "
2833 "function attributes",
2841 Value *RetVal = &CI;
2845 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
2847 "bitcast following musttail call must use the call", BI);
2854 Assert(Ret,
"musttail call must be precede a ret with an optional bitcast",
2857 "musttail call result must be returned",
Ret);
2860 void Verifier::visitCallInst(
CallInst &CI) {
2861 verifyCallSite(&CI);
2864 verifyMustTailCall(CI);
2867 void Verifier::visitInvokeInst(
InvokeInst &II) {
2868 verifyCallSite(&II);
2874 "The unwind destination does not have an exception handling instruction!",
2877 visitTerminatorInst(II);
2885 "Both operands to a binary operator are not of the same type!", &
B);
2891 case Instruction::Sub:
2892 case Instruction::Mul:
2893 case Instruction::SDiv:
2894 case Instruction::UDiv:
2895 case Instruction::SRem:
2896 case Instruction::URem:
2898 "Integer arithmetic operators only work with integral types!", &
B);
2900 "Integer arithmetic operators must have same type "
2901 "for operands and result!",
2906 case Instruction::FAdd:
2907 case Instruction::FSub:
2908 case Instruction::FMul:
2909 case Instruction::FDiv:
2910 case Instruction::FRem:
2912 "Floating-point arithmetic operators only work with "
2913 "floating-point types!",
2916 "Floating-point arithmetic operators must have same type "
2917 "for operands and result!",
2921 case Instruction::And:
2922 case Instruction::Or:
2923 case Instruction::Xor:
2925 "Logical operators only work with integral types!", &
B);
2927 "Logical operators must have same type for operands and result!",
2930 case Instruction::Shl:
2931 case Instruction::LShr:
2932 case Instruction::AShr:
2934 "Shifts only work with integral types!", &
B);
2936 "Shift return type must be same as operands!", &
B);
2942 visitInstruction(B);
2945 void Verifier::visitICmpInst(
ICmpInst &IC) {
2950 "Both operands to ICmp instruction are not of the same type!", &IC);
2953 "Invalid operand types for ICmp instruction", &IC);
2956 "Invalid predicate in ICmp instruction!", &IC);
2958 visitInstruction(IC);
2966 "Both operands to FCmp instruction are not of the same type!", &FC);
2969 "Invalid operand types for FCmp instruction", &
FC);
2972 "Invalid predicate in FCmp instruction!", &
FC);
2974 visitInstruction(FC);
2980 "Invalid extractelement operands!", &EI);
2981 visitInstruction(EI);
2987 "Invalid insertelement operands!", &IE);
2988 visitInstruction(IE);
2994 "Invalid shufflevector operands!", &SV);
2995 visitInstruction(SV);
3001 Assert(isa<PointerType>(TargetTy),
3002 "GEP base pointer is not a vector or a vector of pointers", &GEP);
3007 Assert(ElTy,
"Invalid indices for GEP pointer type!", &GEP);
3011 "GEP is not of right type for indices!", &
GEP, ElTy);
3013 if (GEP.getType()->isVectorTy()) {
3015 unsigned GEPWidth = GEP.getType()->getVectorNumElements();
3016 if (GEP.getPointerOperandType()->isVectorTy())
3017 Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),
3018 "Vector GEP result width doesn't match operand's", &
GEP);
3019 for (Value *Idx : Idxs) {
3020 Type *IndexTy = Idx->getType();
3023 Assert(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &GEP);
3026 "All GEP indices should be of integer type");
3029 visitInstruction(GEP);
3038 "precondition violation");
3041 Assert(NumOperands % 2 == 0,
"Unfinished range!", Range);
3042 unsigned NumRanges = NumOperands / 2;
3043 Assert(NumRanges >= 1,
"It should have at least one range!", Range);
3046 for (
unsigned i = 0; i < NumRanges; ++i) {
3048 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(2 * i));
3049 Assert(Low,
"The lower limit must be an integer!", Low);
3051 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(2 * i + 1));
3052 Assert(High,
"The upper limit must be an integer!", High);
3054 "Range types must match instruction type!", &
I);
3059 Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),
3060 "Range must not be empty!", Range);
3062 Assert(CurRange.intersectWith(LastRange).isEmptySet(),
3063 "Intervals are overlapping", Range);
3064 Assert(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
3071 if (NumRanges > 2) {
3073 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(0))->getValue();
3075 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(1))->getValue();
3077 Assert(FirstRange.intersectWith(LastRange).isEmptySet(),
3078 "Intervals are overlapping", Range);
3084 void Verifier::checkAtomicMemAccessSize(
Type *Ty,
const Instruction *I) {
3085 unsigned Size = DL.getTypeSizeInBits(Ty);
3086 Assert(Size >= 8,
"atomic memory access' size must be byte-sized", Ty, I);
3087 Assert(!(Size & (Size - 1)),
3088 "atomic memory access' operand must have a power-of-two size", Ty, I);
3091 void Verifier::visitLoadInst(
LoadInst &LI) {
3093 Assert(PTy,
"Load operand must be a pointer.", &LI);
3096 "huge alignment values are unsupported", &LI);
3097 Assert(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
3101 "Load cannot have Release ordering", &LI);
3103 "Atomic load must specify explicit alignment", &LI);
3106 "atomic load operand must have integer, pointer, or floating point "
3109 checkAtomicMemAccessSize(ElTy, &LI);
3112 "Non-atomic load cannot have SynchronizationScope specified", &LI);
3115 visitInstruction(LI);
3118 void Verifier::visitStoreInst(
StoreInst &SI) {
3120 Assert(PTy,
"Store operand must be a pointer.", &SI);
3123 "Stored value type does not match pointer operand type!", &
SI, ElTy);
3125 "huge alignment values are unsupported", &
SI);
3130 "Store cannot have Acquire ordering", &
SI);
3132 "Atomic store must specify explicit alignment", &
SI);
3135 "atomic store operand must have integer, pointer, or floating point "
3138 checkAtomicMemAccessSize(ElTy, &SI);
3141 "Non-atomic store cannot have SynchronizationScope specified", &
SI);
3143 visitInstruction(SI);
3147 void Verifier::verifySwiftErrorCallSite(
CallSite CS,
3148 const Value *SwiftErrorVal) {
3151 I !=
E; ++
I, ++Idx) {
3152 if (*I == SwiftErrorVal) {
3154 "swifterror value when used in a callsite should be marked "
3155 "with swifterror attribute",
3161 void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
3164 for (
const User *U : SwiftErrorVal->
users()) {
3165 Assert(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
3167 "swifterror value can only be loaded and stored from, or "
3168 "as a swifterror argument!",
3171 if (
auto StoreI = dyn_cast<StoreInst>(U))
3172 Assert(StoreI->getOperand(1) == SwiftErrorVal,
3173 "swifterror value should be the second operand when used "
3174 "by stores", SwiftErrorVal, U);
3175 if (
auto CallI = dyn_cast<CallInst>(U))
3176 verifySwiftErrorCallSite(const_cast<CallInst*>(CallI), SwiftErrorVal);
3177 if (
auto II = dyn_cast<InvokeInst>(U))
3178 verifySwiftErrorCallSite(const_cast<InvokeInst*>(II), SwiftErrorVal);
3182 void Verifier::visitAllocaInst(
AllocaInst &AI) {
3187 "Allocation instruction pointer not in the stack address space!",
3190 "Cannot allocate unsized type", &AI);
3192 "Alloca array size must have integer type", &AI);
3194 "huge alignment values are unsupported", &AI);
3197 verifySwiftErrorValue(&AI);
3200 visitInstruction(AI);
3207 "cmpxchg instructions must be atomic.", &CXI);
3209 "cmpxchg instructions must be atomic.", &CXI);
3211 "cmpxchg instructions cannot be unordered.", &CXI);
3213 "cmpxchg instructions cannot be unordered.", &CXI);
3215 "cmpxchg instructions failure argument shall be no stronger than the "
3220 "cmpxchg failure ordering cannot include release semantics", &CXI);
3223 Assert(PTy,
"First cmpxchg operand must be a pointer.", &CXI);
3224 Type *ElTy = PTy->getElementType();
3226 "cmpxchg operand must have integer or pointer type",
3228 checkAtomicMemAccessSize(ElTy, &CXI);
3230 "Expected value type does not match pointer operand type!", &CXI,
3233 "Stored value type does not match pointer operand type!", &CXI, ElTy);
3234 visitInstruction(CXI);
3239 "atomicrmw instructions must be atomic.", &RMWI);
3241 "atomicrmw instructions cannot be unordered.", &RMWI);
3243 Assert(PTy,
"First atomicrmw operand must be a pointer.", &RMWI);
3244 Type *ElTy = PTy->getElementType();
3247 checkAtomicMemAccessSize(ElTy, &RMWI);
3249 "Argument value type does not match pointer operand type!", &RMWI,
3253 "Invalid binary operation!", &RMWI);
3254 visitInstruction(RMWI);
3257 void Verifier::visitFenceInst(
FenceInst &FI) {
3263 "fence instructions may only have acquire, release, acq_rel, or "
3264 "seq_cst ordering.",
3266 visitInstruction(FI);
3272 "Invalid ExtractValueInst operands!", &EVI);
3274 visitInstruction(EVI);
3281 "Invalid InsertValueInst operands!", &IVI);
3283 visitInstruction(IVI);
3287 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
3288 return FPI->getParentPad();
3293 void Verifier::visitEHPadPredecessors(
Instruction &I) {
3301 if (
auto *LPI = dyn_cast<LandingPadInst>(&I)) {
3308 "Block containing LandingPadInst must be jumped to "
3309 "only by the unwind edge of an invoke.",
3314 if (
auto *CPI = dyn_cast<CatchPadInst>(&I)) {
3316 Assert(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(),
3317 "Block containg CatchPadInst must be jumped to "
3318 "only by its catchswitch.",
3320 Assert(BB != CPI->getCatchSwitch()->getUnwindDest(),
3321 "Catchswitch cannot unwind to one of its catchpads",
3322 CPI->getCatchSwitch(), CPI);
3333 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
3335 "EH pad must be jumped to via an unwind edge", ToPad, II);
3337 FromPad = Bundle->Inputs[0];
3340 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
3341 FromPad = CRI->getOperand(0);
3342 Assert(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
3343 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
3346 Assert(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
3353 "EH pad cannot handle exceptions raised within it", FromPad, TI);
3354 if (FromPad == ToPadParent) {
3358 Assert(!isa<ConstantTokenNone>(FromPad),
3359 "A single unwind edge may only enter one EH pad", TI);
3361 "EH pad jumps through a cycle of pads", FromPad);
3370 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
3372 visitEHPadPredecessors(LPI);
3374 if (!LandingPadResultTy)
3375 LandingPadResultTy = LPI.
getType();
3378 "The landingpad instruction should have a consistent result type "
3379 "inside a function.",
3383 Assert(F->hasPersonalityFn(),
3384 "LandingPadInst needs to be in a function with a personality.", &LPI);
3389 "LandingPadInst not the first non-PHI instruction in the block.",
3396 "Catch operand does not have pointer type!", &LPI);
3398 Assert(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
3399 Assert(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),
3400 "Filter operand is not an array of constants!", &LPI);
3404 visitInstruction(LPI);
3407 void Verifier::visitResumeInst(
ResumeInst &RI) {
3409 "ResumeInst needs to be in a function with a personality.", &RI);
3411 if (!LandingPadResultTy)
3415 "The resume instruction should have a consistent result type "
3416 "inside a function.",
3419 visitTerminatorInst(RI);
3427 "CatchPadInst needs to be in a function with a personality.", &CPI);
3430 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
3436 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
3438 visitEHPadPredecessors(CPI);
3439 visitFuncletPadInst(CPI);
3444 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
3447 visitTerminatorInst(CatchReturn);
3455 "CleanupPadInst needs to be in a function with a personality.", &CPI);
3460 "CleanupPadInst not the first non-PHI instruction in the block.",
3464 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
3465 "CleanupPadInst has an invalid parent.", &CPI);
3467 visitEHPadPredecessors(CPI);
3468 visitFuncletPadInst(CPI);
3472 User *FirstUser =
nullptr;
3473 Value *FirstUnwindPad =
nullptr;
3477 while (!Worklist.empty()) {
3480 "FuncletPadInst must not be nested within itself", CurrentPad);
3481 Value *UnresolvedAncestorPad =
nullptr;
3482 for (User *U : CurrentPad->
users()) {
3484 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
3485 UnwindDest = CRI->getUnwindDest();
3486 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
3491 if (CSI->unwindsToCaller())
3493 UnwindDest = CSI->getUnwindDest();
3494 }
else if (
auto *II = dyn_cast<InvokeInst>(U)) {
3496 }
else if (isa<CallInst>(U)) {
3501 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
3505 Worklist.push_back(CPI);
3508 Assert(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
3516 if (!cast<Instruction>(UnwindPad)->isEHPad())
3520 if (UnwindParent == CurrentPad)
3526 Value *ExitedPad = CurrentPad;
3529 if (ExitedPad == &FPI) {
3534 UnresolvedAncestorPad = &FPI;
3538 if (ExitedParent == UnwindParent) {
3542 UnresolvedAncestorPad = ExitedParent;
3545 ExitedPad = ExitedParent;
3546 }
while (!isa<ConstantTokenNone>(ExitedPad));
3551 UnresolvedAncestorPad = &FPI;
3558 Assert(UnwindPad == FirstUnwindPad,
"Unwind edges out of a funclet "
3559 "pad must have the same unwind "
3561 &FPI, U, FirstUser);
3564 FirstUnwindPad = UnwindPad;
3566 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
3568 SiblingFuncletInfo[&FPI] = cast<TerminatorInst>(U);
3573 if (CurrentPad != &FPI)
3576 if (UnresolvedAncestorPad) {
3577 if (CurrentPad == UnresolvedAncestorPad) {
3581 assert(CurrentPad == &FPI);
3589 Value *ResolvedPad = CurrentPad;
3590 while (!Worklist.empty()) {
3591 Value *UnclePad = Worklist.back();
3595 while (ResolvedPad != AncestorPad) {
3597 if (ResolvedParent == UnresolvedAncestorPad) {
3600 ResolvedPad = ResolvedParent;
3604 if (ResolvedPad != AncestorPad)
3607 Worklist.pop_back();
3612 if (FirstUnwindPad) {
3613 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
3614 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
3615 Value *SwitchUnwindPad;
3616 if (SwitchUnwindDest)
3620 Assert(SwitchUnwindPad == FirstUnwindPad,
3621 "Unwind edges out of a catch must have the same unwind dest as "
3622 "the parent catchswitch",
3623 &FPI, FirstUser, CatchSwitch);
3627 visitInstruction(FPI);
3635 "CatchSwitchInst needs to be in a function with a personality.",
3641 "CatchSwitchInst not the first non-PHI instruction in the block.",
3645 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
3646 "CatchSwitchInst has an invalid parent.", ParentPad);
3651 "CatchSwitchInst must unwind to an EH block which is not a "
3657 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
3661 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
3664 Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),
3665 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
3668 visitEHPadPredecessors(CatchSwitch);
3669 visitTerminatorInst(CatchSwitch);
3674 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
3680 "CleanupReturnInst must unwind to an EH block which is not a "
3685 visitTerminatorInst(CRI);
3688 void Verifier::verifyDominatesUse(
Instruction &I,
unsigned i) {
3693 if (
InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
3705 if (!isa<PHINode>(I) && InstsInThisBlock.count(Op))
3709 Assert(DT.dominates(Op, U),
3710 "Instruction does not dominate all uses!",
Op, &
I);
3715 "apply only to pointer types", &
I);
3717 "dereferenceable, dereferenceable_or_null apply only to load"
3718 " instructions, use attributes for calls or invokes", &I);
3720 "take one operand!", &
I);
3722 Assert(CI && CI->getType()->isIntegerTy(64),
"dereferenceable, "
3723 "dereferenceable_or_null metadata value must be an i64!", &
I);
3730 Assert(BB,
"Instruction not embedded in basic block!", &I);
3732 if (!isa<PHINode>(I)) {
3733 for (User *U : I.
users()) {
3734 Assert(U != (User *)&I || !DT.isReachableFromEntry(BB),
3735 "Only PHI nodes may reference their own value!", &
I);
3741 "Instruction has a name, but provides a void value!", &
I);
3746 "Instruction returns a non-scalar type!", &
I);
3751 "Invalid use of metadata!", &
I);
3758 Assert(Used->getParent() !=
nullptr,
3759 "Instruction referencing"
3760 " instruction not embedded in a basic block!",
3763 CheckFailed(
"Use of instruction is not an instruction!", U);
3774 Assert(
false,
"Instruction operands must be first-class values!", &I);
3782 i == (isa<CallInst>(
I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0),
3783 "Cannot take the address of an intrinsic!", &I);
3789 F->
getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||
3792 "Cannot invoke an intrinsic other than donothing, patchpoint, "
3793 "statepoint, coro_resume or coro_destroy",
3795 Assert(F->
getParent() == &M,
"Referencing function in another module!",
3796 &
I, &M,
F, F->getParent());
3797 }
else if (
BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
3799 "Referring to a basic block in another function!", &
I);
3800 }
else if (
Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
3802 "Referring to an argument in another function!", &
I);
3803 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
3804 Assert(GV->getParent() == &M,
"Referencing global in another module!", &
I,
3805 &M, GV, GV->getParent());
3806 }
else if (isa<Instruction>(I.getOperand(i))) {
3807 verifyDominatesUse(I, i);
3808 }
else if (isa<InlineAsm>(I.getOperand(i))) {
3809 Assert((i + 1 == e && isa<CallInst>(I)) ||
3810 (i + 3 == e && isa<InvokeInst>(I)),
3811 "Cannot take the address of an inline asm!", &I);
3812 }
else if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) {
3814 !DL.getNonIntegralAddressSpaces().empty()) {
3819 visitConstantExprsRecursively(CE);
3825 Assert(I.getType()->isFPOrFPVectorTy(),
3826 "fpmath requires a floating point result!", &
I);
3829 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
3830 const APFloat &Accuracy = CFP0->getValueAPF();
3832 "fpmath accuracy must have float type", &
I);
3834 "fpmath accuracy not a positive number!", &
I);
3836 Assert(
false,
"invalid fpmath accuracy!", &I);
3841 Assert(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),
3842 "Ranges are only for loads, calls and invokes!", &I);
3843 visitRangeMetadata(I, Range, I.getType());
3847 Assert(I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
3850 "nonnull applies only to load instructions, use attributes"
3851 " for calls or invokes",
3856 visitDereferenceableMetadata(I, MD);
3859 visitDereferenceableMetadata(I, MD);
3862 TBAAVerifyHelper.visitTBAAMetadata(I, TBAA);
3865 Assert(I.getType()->isPointerTy(),
"align applies only to pointer types",
3867 Assert(isa<LoadInst>(I),
"align applies only to load instructions, "
3868 "use attributes for calls or invokes", &I);
3869 Assert(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
3870 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
3871 Assert(CI && CI->getType()->isIntegerTy(64),
3872 "align metadata value must be an i64!", &
I);
3873 uint64_t
Align = CI->getZExtValue();
3875 "align metadata value must be a power of 2!", &I);
3877 "alignment is larger that implementation defined limit", &I);
3880 if (
MDNode *N = I.getDebugLoc().getAsMDNode()) {
3881 AssertDI(isa<DILocation>(N),
"invalid !dbg metadata attachment", &I, N);
3885 if (
auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
3886 verifyFragmentExpression(*DII);
3888 InstsInThisBlock.insert(&I);
3909 "Intrinsic has incorrect return type!", IF);
3910 for (
unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i)
3913 "Intrinsic has incorrect argument type!", IF);
3918 "Intrinsic was not defined with variable arguments!", IF);
3921 "Callsite was not defined with variable arguments!", IF);
3924 Assert(TableRef.
empty(),
"Intrinsic has too few arguments!",
IF);
3932 "Intrinsic name not mangled correctly for type arguments! "
3939 for (Value *V : CS.
args())
3940 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
3941 visitMetadataAsValue(*MD, CS.
getCaller());
3946 case Intrinsic::coro_id: {
3948 if (isa<ConstantPointerNull>(InfoArg))
3951 Assert(GV && GV->isConstant() && GV->hasDefinitiveInitializer(),
3952 "info argument of llvm.coro.begin must refer to an initialized "
3954 Constant *Init = GV->getInitializer();
3955 Assert(isa<ConstantStruct>(Init) || isa<ConstantArray>(Init),
3956 "info argument of llvm.coro.begin must refer to either a struct or "
3960 case Intrinsic::ctlz:
3961 case Intrinsic::cttz:
3963 "is_zero_undef argument of bit counting intrinsics must be a "
3967 case Intrinsic::experimental_constrained_fadd:
3968 case Intrinsic::experimental_constrained_fsub:
3969 case Intrinsic::experimental_constrained_fmul:
3970 case Intrinsic::experimental_constrained_fdiv:
3971 case Intrinsic::experimental_constrained_frem:
3972 case Intrinsic::experimental_constrained_sqrt:
3973 case Intrinsic::experimental_constrained_pow:
3974 case Intrinsic::experimental_constrained_powi:
3975 case Intrinsic::experimental_constrained_sin:
3976 case Intrinsic::experimental_constrained_cos:
3977 case Intrinsic::experimental_constrained_exp:
3978 case Intrinsic::experimental_constrained_exp2:
3979 case Intrinsic::experimental_constrained_log:
3980 case Intrinsic::experimental_constrained_log10:
3981 case Intrinsic::experimental_constrained_log2:
3982 case Intrinsic::experimental_constrained_rint:
3983 case Intrinsic::experimental_constrained_nearbyint:
3984 visitConstrainedFPIntrinsic(
3987 case Intrinsic::dbg_declare:
3989 "invalid llvm.dbg.declare intrinsic call 1", CS);
3990 visitDbgIntrinsic(
"declare", cast<DbgDeclareInst>(*CS.
getInstruction()));
3992 case Intrinsic::dbg_value:
3993 visitDbgIntrinsic(
"value", cast<DbgValueInst>(*CS.
getInstruction()));
3995 case Intrinsic::memcpy:
3996 case Intrinsic::memmove:
3997 case Intrinsic::memset: {
4000 "alignment argument of memory intrinsics must be a constant int",
4004 "alignment argument of memory intrinsics must be a power of 2", CS);
4006 "isvolatile argument of memory intrinsics must be a constant int",
4010 case Intrinsic::memcpy_element_unordered_atomic: {
4018 "element size of the element-wise unordered atomic memory "
4019 "intrinsic must be a constant int",
4023 "element size of the element-wise atomic memory intrinsic "
4024 "must be a power of 2",
4027 if (
auto *LengthCI = dyn_cast<ConstantInt>(MI->
getLength())) {
4028 uint64_t Length = LengthCI->getZExtValue();
4030 Assert((Length % ElementSize) == 0,
4031 "constant length must be a multiple of the element size in the "
4032 "element-wise atomic memory intrinsic",
4036 auto IsValidAlignment = [&](uint64_t Alignment) {
4041 Assert(IsValidAlignment(DstAlignment),
4042 "incorrect alignment of the destination argument", CS);
4043 Assert(IsValidAlignment(SrcAlignment),
4044 "incorrect alignment of the source argument", CS);
4047 case Intrinsic::memmove_element_unordered_atomic: {
4048 auto *MI = cast<ElementUnorderedAtomicMemMoveInst>(CS.
getInstruction());
4053 "element size of the element-wise unordered atomic memory "
4054 "intrinsic must be a constant int",
4056 const APInt &ElementSizeVal = ElementSizeCI->getValue();
4058 "element size of the element-wise atomic memory intrinsic "
4059 "must be a power of 2",
4062 if (
auto *LengthCI = dyn_cast<ConstantInt>(MI->
getLength())) {
4063 uint64_t Length = LengthCI->getZExtValue();
4065 Assert((Length % ElementSize) == 0,
4066 "constant length must be a multiple of the element size in the "
4067 "element-wise atomic memory intrinsic",
4071 auto IsValidAlignment = [&](uint64_t Alignment) {
4076 Assert(IsValidAlignment(DstAlignment),
4077 "incorrect alignment of the destination argument", CS);
4078 Assert(IsValidAlignment(SrcAlignment),
4079 "incorrect alignment of the source argument", CS);
4082 case Intrinsic::memset_element_unordered_atomic: {
4083 auto *MI = cast<ElementUnorderedAtomicMemSetInst>(CS.
getInstruction());
4088 "element size of the element-wise unordered atomic memory "
4089 "intrinsic must be a constant int",
4091 const APInt &ElementSizeVal = ElementSizeCI->getValue();
4093 "element size of the element-wise atomic memory intrinsic "
4094 "must be a power of 2",
4097 if (
auto *LengthCI = dyn_cast<ConstantInt>(MI->
getLength())) {
4098 uint64_t Length = LengthCI->getZExtValue();
4100 Assert((Length % ElementSize) == 0,
4101 "constant length must be a multiple of the element size in the "
4102 "element-wise atomic memory intrinsic",
4106 auto IsValidAlignment = [&](uint64_t Alignment) {
4110 Assert(IsValidAlignment(DstAlignment),
4111 "incorrect alignment of the destination argument", CS);
4114 case Intrinsic::gcroot:
4115 case Intrinsic::gcwrite:
4116 case Intrinsic::gcread:
4117 if (ID == Intrinsic::gcroot) {
4120 Assert(AI,
"llvm.gcroot parameter #1 must be an alloca.", CS);
4122 "llvm.gcroot parameter #2 must be a constant.", CS);
4125 "llvm.gcroot parameter #1 must either be a pointer alloca, "
4126 "or argument #2 must be a non-null constant.",
4132 "Enclosing function does not use GC.", CS);
4134 case Intrinsic::init_trampoline:
4136 "llvm.init_trampoline parameter #2 must resolve to a function.",
4142 cast<ConstantInt>(CS.
getArgOperand(1))->getZExtValue() < 2 &&
4144 "invalid arguments to llvm.prefetch", CS);
4146 case Intrinsic::stackprotector:
4148 "llvm.stackprotector parameter #2 must resolve to an alloca.", CS);
4150 case Intrinsic::lifetime_start:
4151 case Intrinsic::lifetime_end:
4152 case Intrinsic::invariant_start:
4154 "size argument of memory use markers must be a constant integer",
4157 case Intrinsic::invariant_end:
4159 "llvm.invariant.end parameter #2 must be a constant integer", CS);
4162 case Intrinsic::localescape: {
4165 "llvm.localescape used outside of entry block", CS);
4167 "multiple calls to llvm.localescape in one function", CS);
4168 for (Value *Arg : CS.
args()) {
4169 if (isa<ConstantPointerNull>(Arg))
4173 "llvm.localescape only accepts static allocas", CS);
4176 SawFrameEscape =
true;
4179 case Intrinsic::localrecover: {
4183 "llvm.localrecover first "
4184 "argument must be function defined in this module",
4187 Assert(IdxArg,
"idx argument of llvm.localrecover must be a constant int",
4189 auto &Entry = FrameEscapeInfo[Fn];
4191 std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
4195 case Intrinsic::experimental_gc_statepoint:
4197 "gc.statepoint support for inline assembly unimplemented", CS);
4199 "Enclosing function does not use GC.", CS);
4201 verifyStatepoint(CS);
4203 case Intrinsic::experimental_gc_result: {
4205 "Enclosing function does not use GC.", CS);
4209 StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() :
nullptr;
4210 Assert(StatepointFn && StatepointFn->isDeclaration() &&
4211 StatepointFn->getIntrinsicID() ==
4212 Intrinsic::experimental_gc_statepoint,
4213 "gc.result operand #1 must be from a statepoint", CS,
4217 const Value *Target = StatepointCS.getArgument(2);
4218 auto *PT = cast<PointerType>(Target->getType());
4219 auto *TargetFuncType = cast<FunctionType>(PT->getElementType());
4220 Assert(CS.getType() == TargetFuncType->getReturnType(),
4221 "gc.result result type does not match wrapped callee", CS);
4224 case Intrinsic::experimental_gc_relocate: {
4225 Assert(CS.getNumArgOperands() == 3,
"wrong number of arguments", CS);
4227 Assert(isa<PointerType>(CS.getType()->getScalarType()),
4228 "gc.relocate must return a pointer or a vector of pointers", CS);
4234 dyn_cast<LandingPadInst>(CS.getArgOperand(0))) {
4237 LandingPad->
getParent()->getUniquePredecessor();
4241 Assert(InvokeBB,
"safepoints should have unique landingpads",
4246 "gc relocate should be linked to a statepoint", InvokeBB);
4252 auto Token = CS.getArgOperand(0);
4254 "gc relocate is incorrectly tied to the statepoint", CS, Token);
4260 cast<GCRelocateInst>(*CS.getInstruction()).getStatepoint());
4263 Value*
Base = CS.getArgOperand(1);
4264 Assert(isa<ConstantInt>(Base),
4265 "gc.relocate operand #2 must be integer offset", CS);
4267 Value* Derived = CS.getArgOperand(2);
4268 Assert(isa<ConstantInt>(Derived),
4269 "gc.relocate operand #3 must be integer offset", CS);
4271 const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue();
4272 const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
4274 Assert(0 <= BaseIndex && BaseIndex < (
int)StatepointCS.arg_size(),
4275 "gc.relocate: statepoint base index out of bounds", CS);
4276 Assert(0 <= DerivedIndex && DerivedIndex < (
int)StatepointCS.arg_size(),
4277 "gc.relocate: statepoint derived index out of bounds", CS);
4281 Assert(StatepointCS.arg_size() > 0,
4282 "gc.statepoint: insufficient arguments");
4283 Assert(isa<ConstantInt>(StatepointCS.getArgument(3)),
4284 "gc.statement: number of call arguments must be constant integer");
4285 const unsigned NumCallArgs =
4286 cast<ConstantInt>(StatepointCS.getArgument(3))->getZExtValue();
4287 Assert(StatepointCS.arg_size() > NumCallArgs + 5,
4288 "gc.statepoint: mismatch in number of call arguments");
4289 Assert(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)),
4290 "gc.statepoint: number of transition arguments must be "
4291 "a constant integer");
4292 const int NumTransitionArgs =
4293 cast<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5))
4295 const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1;
4296 Assert(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart)),
4297 "gc.statepoint: number of deoptimization arguments must be "
4298 "a constant integer");
4299 const int NumDeoptArgs =
4300 cast<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart))
4302 const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs;
4303 const int GCParamArgsEnd = StatepointCS.arg_size();
4304 Assert(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd,
4305 "gc.relocate: statepoint base index doesn't fall within the "
4306 "'gc parameters' section of the statepoint call",
4308 Assert(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd,
4309 "gc.relocate: statepoint derived index doesn't fall within the "
4310 "'gc parameters' section of the statepoint call",
4317 GCRelocateInst &Relocate = cast<GCRelocateInst>(*CS.getInstruction());
4319 "gc.relocate: relocated value must be a gc pointer", CS);
4321 auto ResultType = CS.getType();
4323 Assert(ResultType->isVectorTy() == DerivedType->isVectorTy(),
4324 "gc.relocate: vector relocates to vector and pointer to pointer",
4327 ResultType->getPointerAddressSpace() ==
4328 DerivedType->getPointerAddressSpace(),
4329 "gc.relocate: relocating a pointer shouldn't change its address space",
4333 case Intrinsic::eh_exceptioncode:
4334 case Intrinsic::eh_exceptionpointer: {
4335 Assert(isa<CatchPadInst>(CS.getArgOperand(0)),
4336 "eh.exceptionpointer argument must be a catchpad", CS);
4339 case Intrinsic::masked_load: {
4340 Assert(CS.getType()->isVectorTy(),
"masked_load: must return a vector", CS);
4342 Value *
Ptr = CS.getArgOperand(0);
4344 Value *
Mask = CS.getArgOperand(2);
4345 Value *PassThru = CS.getArgOperand(3);
4347 "masked_load: mask must be vector", CS);
4350 Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType();
4351 Assert(DataTy == CS.getType(),
4352 "masked_load: return must match pointer type", CS);
4354 "masked_load: pass through and data type must match", CS);
4356 DataTy->getVectorNumElements(),
4357 "masked_load: vector mask must be same length as data", CS);
4360 case Intrinsic::masked_store: {
4361 Value *Val = CS.getArgOperand(0);
4362 Value *Ptr = CS.getArgOperand(1);
4364 Value *Mask = CS.getArgOperand(3);
4366 "masked_store: mask must be vector", CS);
4369 Type *DataTy = cast<PointerType>(Ptr->
getType())->getElementType();
4371 "masked_store: storee must match pointer type", CS);
4373 DataTy->getVectorNumElements(),
4374 "masked_store: vector mask must be same length as data", CS);
4378 case Intrinsic::experimental_guard: {
4379 Assert(CS.isCall(),
"experimental_guard cannot be invoked", CS);
4381 "experimental_guard must have exactly one "
4382 "\"deopt\" operand bundle");
4386 case Intrinsic::experimental_deoptimize: {
4387 Assert(CS.isCall(),
"experimental_deoptimize cannot be invoked", CS);
4389 "experimental_deoptimize must have exactly one "
4390 "\"deopt\" operand bundle");
4391 Assert(CS.getType() == CS.getInstruction()->getFunction()->getReturnType(),
4392 "experimental_deoptimize return type must match caller return type");
4395 auto *DeoptCI = CS.getInstruction();
4398 "calls to experimental_deoptimize must be followed by a return");
4400 if (!CS.getType()->isVoidTy() && RI)
4401 Assert(RI->getReturnValue() == DeoptCI,
4402 "calls to experimental_deoptimize must be followed by a return "
4403 "of the value computed by experimental_deoptimize");
4419 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
4422 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
4426 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
4433 "invalid arguments for constrained FP intrinsic", &FPI);
4435 "invalid exception behavior argument", &FPI);
4437 "invalid rounding mode argument", &FPI);
4439 "invalid rounding mode argument", &FPI);
4441 "invalid exception behavior argument", &FPI);
4444 template <
class DbgIntrinsicTy>
4445 void Verifier::visitDbgIntrinsic(
StringRef Kind, DbgIntrinsicTy &DII) {
4446 auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata();
4447 AssertDI(isa<ValueAsMetadata>(MD) ||
4448 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
4449 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
4450 AssertDI(isa<DILocalVariable>(DII.getRawVariable()),
4451 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
4452 DII.getRawVariable());
4453 AssertDI(isa<DIExpression>(DII.getRawExpression()),
4454 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
4455 DII.getRawExpression());
4458 if (
MDNode *N = DII.getDebugLoc().getAsMDNode())
4459 if (!isa<DILocation>(N))
4468 Assert(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
4473 if (!VarSP || !LocSP)
4476 AssertDI(VarSP == LocSP,
"mismatched subprogram between llvm.dbg." + Kind +
4477 " variable and !dbg attachment",
4479 Loc->getScope()->getSubprogram());
4489 if (
auto *T = dyn_cast<DIType>(RawType))
4490 if (uint64_t Size = T->getSizeInBits())
4493 if (
auto *DT = dyn_cast<DIDerivedType>(RawType)) {
4495 RawType = DT->getRawBaseType();
4510 if (
auto *DVI = dyn_cast<DbgValueInst>(&I)) {
4511 V = dyn_cast_or_null<DILocalVariable>(DVI->getRawVariable());
4512 E = dyn_cast_or_null<DIExpression>(DVI->getRawExpression());
4514 auto *DDI = cast<DbgDeclareInst>(&
I);
4515 V = dyn_cast_or_null<DILocalVariable>(DDI->getRawVariable());
4516 E = dyn_cast_or_null<DIExpression>(DDI->getRawExpression());
4520 if (!V || !E || !E->isValid())
4524 auto Fragment = E->getFragmentInfo();
4534 if (V->isArtificial())
4543 unsigned FragSize = Fragment->SizeInBits;
4544 unsigned FragOffset = Fragment->OffsetInBits;
4545 AssertDI(FragSize + FragOffset <= VarSize,
4546 "fragment is larger than or outside of variable", &I, V, E);
4547 AssertDI(FragSize != VarSize,
"fragment covers entire variable", &I, V, E);
4558 if (
auto *DV = dyn_cast<DbgValueInst>(&I)) {
4560 if (DV->getDebugLoc()->getInlinedAt())
4562 Var = DV->getVariable();
4564 auto *DD = cast<DbgDeclareInst>(&
I);
4565 if (DD->getDebugLoc()->getInlinedAt())
4567 Var = DD->getVariable();
4569 AssertDI(Var,
"dbg intrinsic without variable");
4571 unsigned ArgNo = Var->
getArg();
4577 if (DebugFnArgs.size() < ArgNo)
4578 DebugFnArgs.resize(ArgNo,
nullptr);
4580 auto *Prev = DebugFnArgs[ArgNo - 1];
4581 DebugFnArgs[ArgNo - 1] = Var;
4582 AssertDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &I,
4586 void Verifier::verifyCompileUnits() {
4587 auto *CUs = M.getNamedMetadata(
"llvm.dbg.cu");
4590 Listed.
insert(CUs->op_begin(), CUs->op_end());
4591 for (
auto *CU : CUVisited)
4592 AssertDI(Listed.
count(CU),
"DICompileUnit not listed in llvm.dbg.cu", CU);
4596 void Verifier::verifyDeoptimizeCallingConvs() {
4597 if (DeoptimizeDeclarations.empty())
4600 const Function *First = DeoptimizeDeclarations[0];
4601 for (
auto *F :
makeArrayRef(DeoptimizeDeclarations).slice(1)) {
4603 "All llvm.experimental.deoptimize declarations must have the same "
4604 "calling convention",
4621 return !V.verify(F);
4625 bool *BrokenDebugInfo) {
4627 Verifier V(OS, !BrokenDebugInfo, M);
4629 bool Broken =
false;
4631 Broken |= !V.verify(F);
4633 Broken |= !V.verify();
4634 if (BrokenDebugInfo)
4635 *BrokenDebugInfo = V.hasBrokenDebugInfo();
4646 std::unique_ptr<Verifier> V;
4647 bool FatalErrors =
true;
4652 explicit VerifierLegacyPass(
bool FatalErrors)
4654 FatalErrors(FatalErrors) {
4658 bool doInitialization(
Module &M)
override {
4659 V = llvm::make_unique<Verifier>(
4664 bool runOnFunction(
Function &F)
override {
4665 if (!V->verify(F) && FatalErrors)
4671 bool doFinalization(
Module &M)
override {
4672 bool HasErrors =
false;
4675 HasErrors |= !V->verify(F);
4677 HasErrors |= !V->verify();
4681 assert(!V->hasBrokenDebugInfo() &&
"Module contains invalid debug info");
4685 if (V->hasBrokenDebugInfo()) {
4687 M.getContext().diagnose(DiagInvalid);
4702 template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
4707 #define AssertTBAA(C, ...) \
4710 CheckFailed(__VA_ARGS__); \
4718 TBAAVerifier::TBAABaseNodeSummary
4721 CheckFailed(
"Base nodes must have at least two operands", &I, BaseNode);
4725 auto Itr = TBAABaseNodes.find(BaseNode);
4726 if (Itr != TBAABaseNodes.end())
4729 auto Result = verifyTBAABaseNodeImpl(I, BaseNode);
4730 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
4732 assert(InsertResult.second &&
"We just checked!");
4736 TBAAVerifier::TBAABaseNodeSummary
4738 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0u};
4742 return isValidScalarTBAANode(BaseNode)
4743 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
4748 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
4753 if (!isa<MDString>(BaseNode->
getOperand(0))) {
4754 CheckFailed(
"Struct tag nodes have a string as their first operand",
4759 bool Failed =
false;
4762 unsigned BitWidth = ~0u;
4766 for (
unsigned Idx = 1; Idx < BaseNode->
getNumOperands(); Idx += 2) {
4769 if (!isa<MDNode>(FieldTy)) {
4770 CheckFailed(
"Incorrect field entry in struct type node!", &I, BaseNode);
4775 auto *OffsetEntryCI =
4776 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
4777 if (!OffsetEntryCI) {
4778 CheckFailed(
"Offset entries must be constants!", &I, BaseNode);
4783 if (BitWidth == ~0u)
4784 BitWidth = OffsetEntryCI->getBitWidth();
4786 if (OffsetEntryCI->getBitWidth() != BitWidth) {
4788 "Bitwidth between the offsets and struct type entries must match", &I,
4800 !PrevOffset || PrevOffset->
ule(OffsetEntryCI->getValue());
4803 CheckFailed(
"Offsets must be increasing!", &I, BaseNode);
4807 PrevOffset = OffsetEntryCI->getValue();
4810 return Failed ? InvalidNode
4811 : TBAAVerifier::TBAABaseNodeSummary(
false, BitWidth);
4832 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
4833 return Parent && Visited.
insert(Parent).second &&
4837 bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
4838 auto ResultIt = TBAAScalarNodes.find(MD);
4839 if (ResultIt != TBAAScalarNodes.end())
4840 return ResultIt->second;
4844 auto InsertResult = TBAAScalarNodes.insert({MD, Result});
4846 assert(InsertResult.second &&
"Just checked!");
4864 return cast<MDNode>(BaseNode->
getOperand(1));
4866 for (
unsigned Idx = 1; Idx < BaseNode->
getNumOperands(); Idx += 2) {
4867 auto *OffsetEntryCI =
4868 mdconst::extract<ConstantInt>(BaseNode->
getOperand(Idx + 1));
4869 if (OffsetEntryCI->getValue().ugt(Offset)) {
4871 CheckFailed(
"Could not find TBAA parent in struct type node", &I,
4876 auto *PrevOffsetEntryCI =
4877 mdconst::extract<ConstantInt>(BaseNode->
getOperand(Idx - 1));
4878 Offset -= PrevOffsetEntryCI->getValue();
4879 return cast<MDNode>(BaseNode->
getOperand(Idx - 2));
4883 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
4886 Offset -= LastOffsetEntryCI->getValue();
4891 AssertTBAA(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) ||
4892 isa<VAArgInst>(I) || isa<AtomicRMWInst>(I) ||
4893 isa<AtomicCmpXchgInst>(I),
4894 "TBAA is only for loads, stores and calls!", &I);
4896 bool IsStructPathTBAA =
4901 "Old-style TBAA is no longer allowed, use struct-path TBAA instead", &I);
4904 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
4910 auto *IsImmutableCI =
4911 mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(3));
4913 "Immutability tag on struct tag metadata must be a constant", &I,
4916 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
4917 "Immutability part of the struct tag metadata must be either 0 or 1",
4922 "Malformed struct tag metadata: base and access-type "
4923 "should be non-null and point to Metadata nodes",
4924 &I, MD, BaseNode, AccessType);
4926 AssertTBAA(isValidScalarTBAANode(AccessType),
4927 "Access type node must be a valid scalar type", &I, MD,
4930 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
4931 AssertTBAA(OffsetCI,
"Offset must be constant integer", &I, MD);
4933 APInt Offset = OffsetCI->getValue();
4934 bool SeenAccessTypeInPath =
false;
4939 BaseNode = getFieldNodeFromTBAABaseNode(I, BaseNode, Offset)) {
4940 if (!StructPath.
insert(BaseNode).second) {
4941 CheckFailed(
"Cycle detected in struct path", &I, MD);
4946 unsigned BaseNodeBitWidth;
4947 std::tie(Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(I, BaseNode);
4954 SeenAccessTypeInPath |= BaseNode == AccessType;
4956 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
4957 AssertTBAA(Offset == 0,
"Offset not zero at the point of scalar access",
4961 (BaseNodeBitWidth == 0 && Offset == 0),
4962 "Access bit-width not the same as description bit-width", &I, MD,
4966 AssertTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!",
4972 INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
4975 return new VerifierLegacyPass(FatalErrors);
4996 assert(!Res.DebugInfoBroken &&
"Module contains invalid debug info");
5000 if (Res.DebugInfoBroken) {
5011 if (res.IRBroken && FatalErrors)
Metadata * getRawScope() const
Calling convention used for Mesa compute shaders.
bool matchIntrinsicType(Type *Ty, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified type (which comes from an intrinsic argument or return value) with the type const...
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
const Use & getOperandUse(unsigned i) const
Return a value (possibly void), from a function.
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
static bool isScope(const Metadata *MD)
StringRef getName() const
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
AtomicOrdering getFailureOrdering() const
Returns the failure ordering constraint of this cmpxchg instruction.
LinkageTypes getLinkage() const
Tracking metadata reference owned by Metadata.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
unsigned getNumHandlers() const
return the number of 'handlers' in this catchswitch instruction, except the default handler ...
static Value * getParentPad(Value *EHPad)
FunTy * getCaller() const
Return the caller function for this call site.
iterator_range< use_iterator > uses()
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...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Metadata * getRawTemplateParams() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
unsigned getNumOperandBundles() const
This class represents an incoming formal argument to a Function.
Base class for instruction visitors.
Value * getAggregateOperand()
bool isNonIntegralPointerType(PointerType *PT) const
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Atomic ordering constants.
Takes the max of the two values, which are required to be integers.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Type * getSourceElementType() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
ArrayRef< unsigned > getIndices() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
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.
A Module instance is used to store all the information related to an LLVM module. ...
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Result run(Module &M, ModuleAnalysisManager &)
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
An instruction for ordering other memory operations.
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
DILocalScope * getScope() const
Get the local scope for this variable.
This class represents zero extension of integer types.
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
Value * getValue() const
Convenience accessor.
BBTy * getParent() const
Get the basic block containing the call site.
Metadata * getRawFile() const
Return the raw underlying file.
DIMacroNodeArray getElements() const
Type * getValueType() const
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
bool hasAppendingLinkage() const
Metadata * getRawType() const
static uint64_t getVariableSize(const DILocalVariable &V)
FunctionPass * createVerifierPass(bool FatalErrors=true)
An efficient, type-erasing, non-owning reference to a callable.
This instruction constructs a fixed permutation of two input vectors.
bool hasAvailableExternallyLinkage() const
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isTokenTy() const
Return true if this is 'token'.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
This class implements a map that also provides access to all stored values in a deterministic order...
PTX_Kernel - Call to a PTX kernel.
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
Calling convention used for Mesa geometry shaders.
This class represents a sign extension of integer types.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
An instruction for reading from memory.
Manage lifetime of a slot tracker for printing IR.
void CheckFailed(const Twine &Message)
A check failed, so printout out the condition and the message.
Typed, array-like tuple of metadata.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Value * getRawElementSizeInBytes() const
This is the common base class for constrained floating point intrinsics.
This defines the Use class.
Type * getElementType() const
void reserve(size_type N)
static bool isStrongerThan(AtomicOrdering ao, AtomicOrdering other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice, which is based on C++'s definition.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Metadata * getRawScope() const
const Constant * getAliasee() const
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
bool isFiniteNonZero() const
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
unsigned getColumn() const
Check a module for errors, and report separate error states for IR and debug info errors...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
unsigned arg_size() const
Metadata * getRawType() const
iterator_range< user_iterator > materialized_users()
StringRef getName() const
Return a constant reference to the value's name.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
Adds a requirement that another module flag be present and have a specified value after linking is pe...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Appends the two values, which are required to be metadata nodes.
Value * getDerivedPtr() const
This class represents a conversion between pointers from one address space to another.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
bool hasCommonLinkage() const
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
StringRef getName() const
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
This class represents the LLVM 'select' instruction.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
const APInt & getValue() const
Return the constant as an APInt value reference.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &...Vs)
A check failed (with values to print).
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
unsigned getNumArgOperands() const
Return the number of call arguments.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'. ...
Metadata * getRawRetainedTypes() const
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
This file contains the simple types necessary to represent the attributes associated with functions a...
bool isMustTailCall() const
StringRef getFilename() const
unsigned getMacinfoType() const
StringRef getName() const
static const unsigned MaximumAlignment
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
uint32_t getElementSizeInBytes() const
StringRef getName() const
BasicBlock * getDestination(unsigned i)
Return the specified destination.
DITypeRefArray getTypeArray() const
This file implements a class to represent arbitrary precision integral constant values and operations...
Calling convention used for Mesa hull shaders.
bool hasPrivateLinkage() const
This class represents a cast from a pointer to an integer.
LLVM_NODISCARD bool empty() const
bool hasValidDeclarationLinkage() const
AtomicOrdering
Atomic ordering for LLVM's memory model.
static bool IsRootTBAANode(const MDNode *MD)
Metadata * getRawFile() const
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.
void visit(Iterator Start, Iterator End)
Metadata * getRawStaticDataMemberDeclaration() const
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
A constant value that is initialized with an expression using other constant values.
Class to represent function types.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
#define Assert(C,...)
We know that cond should be true, if not print an error message.
Class to represent array types.
This instruction compares its operands according to the predicate given to the constructor.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
This class represents a no-op cast from one type to another.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
This class represents a cast from floating point to signed integer.
bool isArrayTy() const
True if this is an instance of ArrayType.
Metadata * getRawEnumTypes() const
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
handler_range handlers()
iteration adapter for range-for loops.
iterator_range< op_iterator > operands()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
This class represents a truncation of integer types.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
BasicBlock * getNormalDest() const
Class to represent pointers.
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Metadata * getRawScope() const
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static ChecksumKind getChecksumKind(StringRef CSKindStr)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Function Alias Analysis false
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Type * getReturnType() const
Returns the type of the ret val.
Type * getParamType(unsigned i) const
Parameter type accessors.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
initializer< Ty > init(const Ty &Val)
This instruction inserts a single (scalar) element into a VectorType value.
iterator_range< IterTy > args() const
static bool isIntPredicate(Predicate P)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Metadata * getRawFile() const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
FunctionType * getFunctionType() const
Subclasses of this class are all able to terminate a basic block.
A set of analyses that are preserved following a run of a transformation pass.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Metadata * getRawMacros() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Conditional or Unconditional Branch instruction.
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
Returns the module flags in the provided vector.
PointerType * getType() const
Overload to return most specific pointer type.
Metadata * getRawType() const
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, const Ts &...Vs)
A debug info check failed (with values to print).
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Resume the propagation of an exception.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Indirect Branch Instruction.
Base class for template parameters.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool hasPersonalityFn() const
Check whether this function has a personality function.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static bool isValidLinkage(LinkageTypes L)
A pair of DIGlobalVariable and DIExpression.
Represent the analysis usage information of a pass.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static Type * getVoidTy(LLVMContext &C)
static bool isFuncOnlyAttr(Attribute::AttrKind Kind)
Return true if this attribute kind only applies to functions.
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...
Metadata * getRawElements() const
This instruction compares its operands according to the predicate given to the constructor.
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getNumElements() const
DIMacroNodeArray getMacros() const
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
AttributeList getAttributes() const
Get the parameter attributes of the call.
Base class for variables.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
bool pred_empty(const BasicBlock *BB)
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
bool empty() const
empty - Check if the array is empty.
This class represents a cast from an integer to a pointer.
static DISubprogram * getSubprogram(Metadata *LocalScope)
Carefully grab the subprogram from a local scope.
bool isPointerTy() const
True if this is an instance of PointerType.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
LLVMContext & getContext() const
All values hold a context through their type.
Calling convention used for Mesa vertex shaders.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
unsigned getNumAttrSets() const
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
OperandBundleUse getOperandBundleAt(unsigned Index) const
FunctionType * getFunctionType() const
An imported module (C++ using directive or similar).
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster. ...
Base class for scope-like contexts.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
DIScopeArray getRetainedTypes() const
ExceptionBehavior getExceptionBehavior() const
bool doesNotAccessMemory() const
Determine if the call does not access memory.
BasicBlock * getUnwindDest() const
bool isConditional() const
DIExpression * getExpression() const
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
BasicBlock * getUnwindDest() const
DIImportedEntityArray getImportedEntities() const
BinaryOps getOpcode() const
StringRef getString() const
bool hasExternalLinkage() const
bool hasDLLImportStorageClass() const
const MDOperand & getOperand(unsigned I) const
Metadata * getRawBaseType() const
static const fltSemantics & IEEEsingle() LLVM_READNONE
#define AssertDI(C,...)
We know that a debug info condition should be true, if not print an error message.
Synchronized with respect to all concurrently executing threads.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Iterator for intrusive lists based on ilist_node.
bool hasGlobalUnnamedAddr() const
BasicBlock * getUnwindDest() const
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs(unsigned Index) const
Get the allocsize argument numbers (or pair(0, 0) if unknown).
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
This is the shared class of boolean and integer constants.
constexpr bool isInt< 32 >(int64_t x)
InstrTy * getInstruction() const
VerifierSupport(raw_ostream *OS, const Module &M)
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
bool isEmpty() const
Return true if there are no attributes.
static Optional< DebugEmissionKind > getEmissionKind(StringRef Str)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
ValTy * getArgument(unsigned ArgNo) const
Metadata * getRawInlinedAt() const
std::string getAsString(bool InAttrGrp=false) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
bool hasAttributes() const
Return true if attributes exists in this set.
Calling convention used for Mesa pixel shaders.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static bool isDINode(const Metadata *MD)
static bool isFuncOrArgAttr(Attribute::AttrKind Kind)
Return true if this is a function attribute that can also appear on arguments.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
This class represents a range of values.
This is the common base class for debug info intrinsics.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static const char * Target
const APInt & getLower() const
Return the lower value for this range.
StringRef getName() const
This class represents a cast from floating point to unsigned integer.
LLVM_NODISCARD T pop_back_val()
Value * getParentPad() const
Convenience accessors.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
pred_range predecessors(BasicBlock *BB)
const BasicBlock & getEntryBlock() const
static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs)
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Metadata * getRawEntity() const
AttributeSet getFnAttributes() const
The function attributes are returned.
BinOp getOperation() const
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Uses the specified value, regardless of the behavior or value of the other module.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
C - The default llvm calling convention, compatible with C.
This class represents atomic memcpy intrinsic TODO: Integrate this class into MemIntrinsic hierarchy;...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
unsigned getNumArgOperands() const
Class to represent vector types.
Target - Wrapper for Target specific information.
ConstantArray - Constant Array Declarations.
bool hasInitializer() const
Definitions have initializers, declarations don't.
Class for arbitrary precision integers.
DIGlobalVariableExpressionArray getGlobalVariables() const
A (clang) module that has been imported by the compile unit.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
DISubprogram * getSubprogram() const
Get the attached subprogram.
static bool isFPPredicate(Predicate P)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Emits a warning if two values disagree.
static Instruction * getSuccPad(TerminatorInst *Terminator)
void setPreservesAll()
Set by analyses that do not transform their input at all.
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
InstListType::iterator iterator
Instruction iterators...
unsigned getVectorNumElements() const
Generic tagged DWARF-like metadata node.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Value * getCondition() const
iterator insert(iterator I, T &&Elt)
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
bool isInlineAsm() const
Check if this call is an inline asm statement.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
Value * getParentPad() const
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Type array for a subprogram.
Metadata * getRawImportedEntities() const
static std::vector< std::string > Flags
Metadata * getRawScope() const
Metadata * getRawScope() const
PointerType * getType() const
Global values are always pointers.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Value * getCondition() const
Appends the two values, which are required to be metadata nodes.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
bool BrokenDebugInfo
Broken debug info can be "recovered" from by stripping the debug info.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
verify safepoint Safepoint IR Verifier
Establish a view to a call site for examination.
AttributeList getAttributes() const
Return the parameter attributes for this call.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
RoundingMode getRoundingMode() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
DIGlobalVariable * getVariable() const
void initializeVerifierLegacyPassPass(PassRegistry &)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This class represents a cast unsigned integer to floating point.
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
Metadata * getRawElements() const
Fast - This calling convention attempts to make calls as fast as possible (e.g.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
op_range operands() const
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
PTX_Device - Call to a PTX device function.
void DebugInfoCheckFailed(const Twine &Message)
A debug info check failed.
Metadata * getRawFile() const
Metadata * getRawScope() const
bool isStatepoint(ImmutableCallSite CS)
std::vector< uint8_t > Unit
bool isSpeculatable() const
Determine if the call has sideeffects.
This class represents a cast from signed integer to floating point.
const APInt & getUpper() const
Return the upper value for this range.
Type * getReturnType() const
unsigned getAlignment() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void forEachUser(const Value *User, SmallPtrSet< const Value *, 32 > &Visited, llvm::function_ref< bool(const Value *)> Callback)
const BasicBlock & front() const
This class represents a truncation of floating point types.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
DICompositeTypeArray getEnumTypes() const
Represents calls to the gc.relocate intrinsic.
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
bool isLabelTy() const
Return true if this is 'label'.
Module * getParent()
Get the module that this global value is contained inside of...
Verify that the TBAA Metadatas are valid.
LLVM Value Representation.
Value * getLength() const
static bool hasConflictingReferenceFlags(unsigned Flags)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
bool TreatBrokenDebugInfoAsError
Whether to treat broken debug info as an error.
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
const Value * getArraySize() const
Get the number of elements allocated.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ValTy * getArgOperand(unsigned i) const
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void print(raw_ostream &ROS, bool IsForDebug=false) const
bool Broken
Track the brokenness of the module while recursively visiting.
static bool IsScalarTBAANodeImpl(const MDNode *MD, SmallPtrSetImpl< const MDNode * > &Visited)
static bool isContiguous(const ConstantRange &A, const ConstantRange &B)
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
StringRef - Represent a constant reference to a string, i.e.
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
A container for analyses that lazily runs them and caches their results.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This header defines various interfaces for pass management in LLVM.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
unsigned getNumElements() const
Random access to the elements.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
op_range incoming_values()
This class represents an extension of floating point types.
bool isResolved() const
Check if node is fully resolved.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
A bitmask that includes all valid flags.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
#define AssertTBAA(C,...)
Calling convention for AMDGPU code object kernels.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isDeclarationForLinker() const
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
const fltSemantics & getSemantics() const
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock * getParent() const
Type * getResultElementType() const
static cl::opt< bool > VerifyDebugInfo("verify-debug-info", cl::init(true))
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
LLVMContext & getContext() const
Get the global data context.
bool isVoidTy() const
Return true if this is 'void'.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
static bool isType(const Metadata *MD)
StringRef getValue() const
Metadata * getRawGlobalVariables() const
Basic type, like 'int' or 'float'.
bool isMetadataTy() const
Return true if this is 'metadata'.
Metadata * getRawTypeArray() const
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...
Metadata * getRawVTableHolder() const