116 using namespace llvm;
135 : OS(OS), M(M), MST(&M), DL(M.getDataLayout()), Context(M.getContext()) {}
138 void Write(
const Module *M) {
142 void Write(
const Value *V) {
145 if (isa<Instruction>(V)) {
161 MD->
print(*OS, MST, &M);
172 NMD->
print(*OS, MST);
176 void Write(
Type *
T) {
188 void Write(
const APInt *AI) {
194 void Write(
const unsigned i) { *OS << i <<
'\n'; }
197 for (
const T &V : Vs)
201 template <
typename T1,
typename... Ts>
202 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
207 template <
typename... Ts>
void WriteTs() {}
216 *OS << Message <<
'\n';
224 template <
typename T1,
typename... Ts>
234 *OS << Message <<
'\n';
236 BrokenDebugInfo =
true;
240 template <
typename T1,
typename... Ts>
275 Type *LandingPadResultTy;
282 bool HasDebugInfo =
false;
315 SawFrameEscape(
false), TBAAVerifyHelper(
this) {
323 "An instance of this class only works with a specific module!");
332 DT.recalculate(const_cast<Function &>(F));
335 if (!BB.empty() && BB.back().isTerminator())
339 *OS <<
"Basic Block in function '" << F.getName()
340 <<
"' does not have terminator!\n";
341 BB.printAsOperand(*OS,
true,
MST);
349 visit(const_cast<Function &>(F));
350 verifySiblingFuncletUnwinds();
351 InstsInThisBlock.
clear();
353 LandingPadResultTy =
nullptr;
354 SawFrameEscape =
false;
355 SiblingFuncletInfo.
clear();
371 verifyFrameRecoverIndices();
373 visitGlobalVariable(GV);
376 visitGlobalAlias(GA);
379 visitNamedMDNode(NMD);
382 visitComdat(SMEC.getValue());
385 visitModuleIdents(M);
387 verifyCompileUnits();
389 verifyDeoptimizeCallingConvs();
390 DISubprogramAttachments.
clear();
403 void visitMDNode(
const MDNode &MD);
406 void visitComdat(
const Comdat &C);
407 void visitModuleIdents(
const Module &M);
408 void visitModuleFlags(
const Module &M);
409 void visitModuleFlag(
const MDNode *
Op,
412 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
413 void visitFunction(
const Function &F);
418 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
419 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); 420 #include "llvm/IR/Metadata.def" 421 void visitDIScope(
const DIScope &N);
426 void visitTemplateParams(
const MDNode &N,
const Metadata &RawParams);
445 void visitPHINode(
PHINode &PN);
452 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
458 void verifyDominatesUse(
Instruction &I,
unsigned i);
467 void visitUserOp2(
Instruction &I) { visitUserOp1(I); }
489 void verifySwiftErrorCallSite(
CallSite CS,
const Value *SwiftErrorVal);
490 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
491 void verifyMustTailCall(
CallInst &CI);
493 unsigned ArgNo, std::string &Suffix);
500 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
502 void visitConstantExprsRecursively(
const Constant *EntryC);
505 void verifyFrameRecoverIndices();
506 void verifySiblingFuncletUnwinds();
509 template <
typename ValueOrMetadata>
510 void verifyFragmentExpression(
const DIVariable &V,
512 ValueOrMetadata *Desc);
516 void verifyCompileUnits();
520 void verifyDeoptimizeCallingConvs();
526 #define Assert(C, ...) \ 527 do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false) 531 #define AssertDI(C, ...) \ 532 do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false) 546 if (!Visited.
insert(User).second)
549 if (Callback(TheNextUser))
553 void Verifier::visitGlobalValue(
const GlobalValue &GV) {
555 "Global is external, but doesn't have external or weak linkage!", &GV);
558 "huge alignment values are unsupported", &GV);
560 "Only global variables can have appending linkage!", &GV);
565 "Only global arrays can have appending linkage!", GVar);
573 "GlobalValue with DLLImport Storage is dso_local!", &GV);
577 "Global is marked as dllimport, but not external", &GV);
582 "GlobalValue with private or internal linkage must be dso_local!",
587 "GlobalValue with non default visibility must be dso_local!", &GV);
591 if (!
I->getParent() || !
I->getParent()->getParent())
592 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &
M,
594 else if (
I->getParent()->getParent()->getParent() != &
M)
595 CheckFailed(
"Global is referenced in a different module!", &GV, &
M,
I,
596 I->getParent()->getParent(),
597 I->getParent()->getParent()->getParent());
599 }
else if (
const Function *
F = dyn_cast<Function>(V)) {
600 if (
F->getParent() != &
M)
601 CheckFailed(
"Global is used by function in a different module", &GV, &
M,
612 "Global variable initializer type does not match global " 619 "'common' global must have a zero initializer!", &GV);
622 Assert(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
627 GV.
getName() ==
"llvm.global_dtors")) {
629 "invalid linkage for intrinsic global variable", &GV);
641 "wrong type for intrinsic global variable", &GV);
645 cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),
646 "wrong type for intrinsic global variable", &GV);
652 GV.
getName() ==
"llvm.compiler.used")) {
654 "invalid linkage for intrinsic global variable", &GV);
656 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
658 Assert(PTy,
"wrong type for intrinsic global variable", &GV);
662 Assert(InitArray,
"wrong initalizer for intrinsic global variable",
665 Value *V =
Op->stripPointerCastsNoFollowAliases();
666 Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||
668 "invalid llvm.used member", V);
669 Assert(V->
hasName(),
"members of llvm.used must be named", V);
678 for (
auto *MD : MDs) {
679 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
680 visitDIGlobalVariableExpression(*GVE);
682 AssertDI(
false,
"!dbg attachment of global variable must be a " 683 "DIGlobalVariableExpression");
687 visitGlobalValue(GV);
694 visitGlobalValue(GV);
700 visitAliaseeSubExpr(Visited, GA, C);
705 if (
const auto *GV = dyn_cast<GlobalValue>(&C)) {
709 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
710 Assert(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
712 Assert(!GA2->isInterposable(),
"Alias cannot point to an interposable alias",
721 if (
const auto *CE = dyn_cast<ConstantExpr>(&C))
722 visitConstantExprsRecursively(CE);
726 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
727 visitAliaseeSubExpr(Visited, GA, *GA2->
getAliasee());
728 else if (
const auto *C2 = dyn_cast<Constant>(V))
729 visitAliaseeSubExpr(Visited, GA, *C2);
733 void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
735 "Alias should have private, internal, linkonce, weak, linkonce_odr, " 736 "weak_odr, or external linkage!",
739 Assert(Aliasee,
"Aliasee cannot be NULL!", &GA);
741 "Alias and aliasee types should match!", &GA);
743 Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
744 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
746 visitAliaseeSubExpr(GA, *Aliasee);
748 visitGlobalValue(GA);
751 void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
756 "unrecognized named metadata node in the llvm.dbg namespace",
759 if (NMD.
getName() ==
"llvm.dbg.cu")
760 AssertDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
769 void Verifier::visitMDNode(
const MDNode &MD) {
772 if (!MDNodes.insert(&MD).second)
778 case Metadata::MDTupleKind:
780 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 781 case Metadata::CLASS##Kind: \ 782 visit##CLASS(cast<CLASS>(MD)); \ 784 #include "llvm/IR/Metadata.def" 790 Assert(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
792 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
796 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
797 visitValueAsMetadata(*V,
nullptr);
810 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
816 Assert(F,
"function-local metadata used outside a function", L);
821 if (
Instruction *
I = dyn_cast<Instruction>(L->getValue())) {
822 Assert(
I->getParent(),
"function-local metadata not in basic block", L,
I);
823 ActualF =
I->getParent()->getParent();
824 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
826 else if (
Argument *
A = dyn_cast<Argument>(L->getValue()))
827 ActualF =
A->getParent();
828 assert(ActualF &&
"Unimplemented function local metadata case!");
830 Assert(ActualF == F,
"function-local metadata used in wrong function", L);
835 if (
auto *
N = dyn_cast<MDNode>(MD)) {
842 if (!MDNodes.insert(MD).second)
845 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
846 visitValueAsMetadata(*V, F);
853 void Verifier::visitDILocation(
const DILocation &
N) {
855 "location requires a valid scope", &N, N.
getRawScope());
857 AssertDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
859 AssertDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
866 void Verifier::visitDIScope(
const DIScope &N) {
868 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
871 void Verifier::visitDISubrange(
const DISubrange &N) {
872 AssertDI(N.
getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
874 AssertDI(Count,
"Count must either be a signed constant or a DIVariable",
878 "invalid subrange count", &
N);
881 void Verifier::visitDIEnumerator(
const DIEnumerator &N) {
885 void Verifier::visitDIBasicType(
const DIBasicType &N) {
887 N.
getTag() == dwarf::DW_TAG_unspecified_type,
896 N.
getTag() == dwarf::DW_TAG_pointer_type ||
897 N.
getTag() == dwarf::DW_TAG_ptr_to_member_type ||
898 N.
getTag() == dwarf::DW_TAG_reference_type ||
899 N.
getTag() == dwarf::DW_TAG_rvalue_reference_type ||
900 N.
getTag() == dwarf::DW_TAG_const_type ||
901 N.
getTag() == dwarf::DW_TAG_volatile_type ||
902 N.
getTag() == dwarf::DW_TAG_restrict_type ||
903 N.
getTag() == dwarf::DW_TAG_atomic_type ||
904 N.
getTag() == dwarf::DW_TAG_member ||
905 N.
getTag() == dwarf::DW_TAG_inheritance ||
906 N.
getTag() == dwarf::DW_TAG_friend,
908 if (N.
getTag() == dwarf::DW_TAG_ptr_to_member_type) {
909 AssertDI(
isType(N.getRawExtraData()),
"invalid pointer to member type", &N,
910 N.getRawExtraData());
917 if (N.getDWARFAddressSpace()) {
919 N.
getTag() == dwarf::DW_TAG_reference_type,
920 "DWARF address space only applies to pointer or reference types",
927 return ((Flags & DINode::FlagLValueReference) &&
928 (Flags & DINode::FlagRValueReference)) ||
929 ((Flags & DINode::FlagTypePassByValue) &&
930 (Flags & DINode::FlagTypePassByReference));
933 void Verifier::visitTemplateParams(
const MDNode &N,
const Metadata &RawParams) {
935 AssertDI(Params,
"invalid template params", &N, &RawParams);
937 AssertDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
947 N.
getTag() == dwarf::DW_TAG_structure_type ||
948 N.
getTag() == dwarf::DW_TAG_union_type ||
949 N.
getTag() == dwarf::DW_TAG_enumeration_type ||
950 N.
getTag() == dwarf::DW_TAG_class_type ||
951 N.
getTag() == dwarf::DW_TAG_variant_part,
963 "invalid reference flags", &N);
968 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
969 "invalid vector, expected one element of type subrange", &
N);
973 visitTemplateParams(N, *Params);
975 if (N.
getTag() == dwarf::DW_TAG_class_type ||
976 N.
getTag() == dwarf::DW_TAG_union_type) {
978 "class/union requires a filename", &
N, N.
getFile());
982 AssertDI(isa<DIDerivedType>(
D) && N.
getTag() == dwarf::DW_TAG_variant_part,
983 "discriminator can only appear on variant part");
988 AssertDI(N.
getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
990 AssertDI(isa<MDTuple>(Types),
"invalid composite elements", &N, Types);
992 AssertDI(
isType(Ty),
"invalid subroutine type ref", &N, Types, Ty);
996 "invalid reference flags", &N);
999 void Verifier::visitDIFile(
const DIFile &N) {
1003 AssertDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,
1004 "invalid checksum kind", &N);
1006 switch (Checksum->Kind) {
1014 AssertDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1016 "invalid checksum", &
N);
1022 AssertDI(N.
getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1032 "invalid emission kind", &N);
1037 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
1039 "invalid enum type", &
N, N.getEnumTypes(),
Op);
1046 (isa<DISubprogram>(
Op) &&
1047 !cast<DISubprogram>(
Op)->isDefinition())),
1048 "invalid retained type", &N,
Op);
1055 "invalid global variable ref", &N,
Op);
1061 AssertDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1068 AssertDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &N,
Op);
1071 CUVisited.insert(&N);
1074 void Verifier::visitDISubprogram(
const DISubprogram &N) {
1076 AssertDI(
isScope(N.getRawScope()),
"invalid scope", &N, N.getRawScope());
1078 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1080 AssertDI(N.getLine() == 0,
"line specified with no file", &
N, N.getLine());
1081 if (
auto *
T = N.getRawType())
1082 AssertDI(isa<DISubroutineType>(
T),
"invalid subroutine type", &
N,
T);
1083 AssertDI(
isType(N.getRawContainingType()),
"invalid containing type", &N,
1084 N.getRawContainingType());
1085 if (
auto *Params = N.getRawTemplateParams())
1086 visitTemplateParams(N, *Params);
1087 if (
auto *S = N.getRawDeclaration())
1088 AssertDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1089 "invalid subprogram declaration", &
N, S);
1090 if (
auto *RawNode = N.getRawRetainedNodes()) {
1092 AssertDI(Node,
"invalid retained nodes list", &N, RawNode);
1095 "invalid retained nodes, expected DILocalVariable or DILabel",
1100 "invalid reference flags", &N);
1102 auto *Unit = N.getRawUnit();
1103 if (N.isDefinition()) {
1106 AssertDI(Unit,
"subprogram definitions must have a compile unit", &N);
1107 AssertDI(isa<DICompileUnit>(Unit),
"invalid unit type", &N, Unit);
1110 AssertDI(!Unit,
"subprogram declarations must not have a compile unit", &N);
1113 if (
auto *RawThrownTypes = N.getRawThrownTypes()) {
1115 AssertDI(ThrownTypes,
"invalid thrown types list", &N, RawThrownTypes);
1117 AssertDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1123 AssertDI(N.
getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1127 AssertDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1131 visitDILexicalBlockBase(N);
1134 "cannot have column info without line info", &
N);
1138 visitDILexicalBlockBase(N);
1141 void Verifier::visitDINamespace(
const DINamespace &N) {
1144 AssertDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1147 void Verifier::visitDIMacro(
const DIMacro &N) {
1150 "invalid macinfo type", &
N);
1157 void Verifier::visitDIMacroFile(
const DIMacroFile &N) {
1159 "invalid macinfo type", &
N);
1161 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1166 AssertDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &N,
Op);
1171 void Verifier::visitDIModule(
const DIModule &N) {
1181 visitDITemplateParameter(N);
1183 AssertDI(N.
getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1187 void Verifier::visitDITemplateValueParameter(
1189 visitDITemplateParameter(N);
1192 N.
getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1193 N.
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1197 void Verifier::visitDIVariable(
const DIVariable &N) {
1199 AssertDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1201 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1213 AssertDI(isa<DIDerivedType>(Member),
1214 "invalid static data member declaration", &N, Member);
1225 "local variable requires a valid scope", &N, N.
getRawScope());
1228 void Verifier::visitDILabel(
const DILabel &N) {
1230 AssertDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1232 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1236 "label requires a valid scope", &N, N.
getRawScope());
1239 void Verifier::visitDIExpression(
const DIExpression &N) {
1243 void Verifier::visitDIGlobalVariableExpression(
1247 visitDIGlobalVariable(*Var);
1249 visitDIExpression(*Expr);
1250 if (
auto Fragment = Expr->getFragmentInfo())
1251 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1256 AssertDI(N.
getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1260 AssertDI(isa<DIFile>(F),
"invalid file", &
N,
F);
1265 N.
getTag() == dwarf::DW_TAG_imported_declaration,
1268 AssertDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1273 void Verifier::visitComdat(
const Comdat &C) {
1281 void Verifier::visitModuleIdents(
const Module &
M) {
1290 "incorrect number of operands in llvm.ident metadata",
N);
1292 (
"invalid value for llvm.ident metadata entry operand" 1293 "(the operand should be a string)"),
1298 void Verifier::visitModuleFlags(
const Module &M) {
1306 visitModuleFlag(MDN, SeenIDs, Requirements);
1309 for (
const MDNode *Requirement : Requirements) {
1310 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1311 const Metadata *ReqValue = Requirement->getOperand(1);
1315 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1322 "flag does not have the required value"),
1330 Verifier::visitModuleFlag(
const MDNode *
Op,
1336 "incorrect number of operands in module flag",
Op);
1340 mdconst::dyn_extract_or_null<ConstantInt>(Op->
getOperand(0)),
1341 "invalid behavior operand in module flag (expected constant integer)",
1344 "invalid behavior operand in module flag (unexpected constant)",
1348 Assert(ID,
"invalid ID operand in module flag (expected metadata string)",
1361 "invalid value for 'max' module flag (expected constant integer)",
1371 "invalid value for 'require' module flag (expected metadata pair)",
1374 (
"invalid value for 'require' module flag " 1375 "(first value operand should be a string)"),
1388 "invalid value for 'append'-type module flag " 1389 "(expected a metadata node)",
1397 bool Inserted = SeenIDs.
insert(std::make_pair(ID, Op)).second;
1399 "module flag identifiers must be unique (or of 'require' type)", ID);
1402 if (ID->getString() ==
"wchar_size") {
1404 = mdconst::dyn_extract_or_null<ConstantInt>(Op->
getOperand(2));
1405 Assert(Value,
"wchar_size metadata requires constant integer argument");
1408 if (ID->getString() ==
"Linker Options") {
1413 "'Linker Options' named metadata no longer supported");
1416 if (ID->getString() ==
"CG Profile") {
1418 visitModuleFlagCGProfileEntry(MDO);
1422 void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1423 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1427 Assert(F && isa<Function>(F->getValue()),
"expected a Function or null",
1430 auto Node = dyn_cast_or_null<MDNode>(MDO);
1431 Assert(Node && Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1432 CheckFunction(Node->getOperand(0));
1433 CheckFunction(Node->getOperand(1));
1434 auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2));
1435 Assert(Count && Count->getType()->isIntegerTy(),
1436 "expected an integer constant", Node->getOperand(2));
1442 case Attribute::NoReturn:
1443 case Attribute::NoCfCheck:
1444 case Attribute::NoUnwind:
1445 case Attribute::NoInline:
1446 case Attribute::AlwaysInline:
1447 case Attribute::OptimizeForSize:
1448 case Attribute::StackProtect:
1449 case Attribute::StackProtectReq:
1450 case Attribute::StackProtectStrong:
1451 case Attribute::SafeStack:
1452 case Attribute::ShadowCallStack:
1453 case Attribute::NoRedZone:
1454 case Attribute::NoImplicitFloat:
1455 case Attribute::Naked:
1456 case Attribute::InlineHint:
1457 case Attribute::StackAlignment:
1458 case Attribute::UWTable:
1459 case Attribute::NonLazyBind:
1460 case Attribute::ReturnsTwice:
1461 case Attribute::SanitizeAddress:
1462 case Attribute::SanitizeHWAddress:
1463 case Attribute::SanitizeThread:
1464 case Attribute::SanitizeMemory:
1465 case Attribute::MinSize:
1466 case Attribute::NoDuplicate:
1467 case Attribute::Builtin:
1468 case Attribute::NoBuiltin:
1470 case Attribute::OptForFuzzing:
1471 case Attribute::OptimizeNone:
1474 case Attribute::ArgMemOnly:
1475 case Attribute::NoRecurse:
1476 case Attribute::InaccessibleMemOnly:
1477 case Attribute::InaccessibleMemOrArgMemOnly:
1478 case Attribute::AllocSize:
1479 case Attribute::Speculatable:
1480 case Attribute::StrictFP:
1491 return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly ||
1492 Kind == Attribute::ReadNone;
1498 if (
A.isStringAttribute())
1504 "' only applies to functions!",
1510 "' does not apply to functions!",
1524 verifyAttributeTypes(Attrs,
false, V);
1528 unsigned AttrCount = 0;
1531 AttrCount += Attrs.
hasAttribute(Attribute::StructRet) ||
1534 Assert(AttrCount <= 1,
"Attributes 'byval', 'inalloca', 'inreg', 'nest', " 1535 "and 'sret' are incompatible!",
1541 "'inalloca and readonly' are incompatible!",
1547 "'sret and returned' are incompatible!",
1553 "'zeroext and signext' are incompatible!",
1559 "'readnone and readonly' are incompatible!",
1565 "'readnone and writeonly' are incompatible!",
1571 "'readonly and writeonly' are incompatible!",
1577 "'noinline and alwaysinline' are incompatible!",
1582 "Wrong types for attribute: " +
1586 if (
PointerType *PTy = dyn_cast<PointerType>(Ty)) {
1588 if (!PTy->getElementType()->isSized(&Visited)) {
1591 "Attributes 'byval' and 'inalloca' do not support unsized types!",
1594 if (!isa<PointerType>(PTy->getElementType()))
1596 "Attribute 'swifterror' only applies to parameters " 1597 "with pointer to pointer type!",
1601 "Attribute 'byval' only applies to parameters with pointer type!",
1604 "Attribute 'swifterror' only applies to parameters " 1605 "with pointer type!",
1617 bool SawNest =
false;
1618 bool SawReturned =
false;
1619 bool SawSRet =
false;
1620 bool SawSwiftSelf =
false;
1621 bool SawSwiftError =
false;
1633 "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " 1634 "'returned', 'swiftself', and 'swifterror' do not apply to return " 1641 "' does not apply to function returns",
1646 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
1650 verifyParameterAttrs(ArgAttrs, Ty, V);
1653 Assert(!SawNest,
"More than one parameter has attribute nest!", V);
1658 Assert(!SawReturned,
"More than one parameter has attribute returned!",
1661 "Incompatible argument and return types for 'returned' attribute",
1667 Assert(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
1669 "Attribute 'sret' is not on first or second parameter!", V);
1674 Assert(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
1675 SawSwiftSelf =
true;
1679 Assert(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!",
1681 SawSwiftError =
true;
1686 "inalloca isn't on the last parameter!", V);
1697 "Attributes 'readnone and readonly' are incompatible!", V);
1701 "Attributes 'readnone and writeonly' are incompatible!", V);
1705 "Attributes 'readonly and writeonly' are incompatible!", V);
1709 "Attributes 'readnone and inaccessiblemem_or_argmemonly' are " 1715 "Attributes 'readnone and inaccessiblememonly' are incompatible!", V);
1719 "Attributes 'noinline and alwaysinline' are incompatible!", V);
1723 "Attribute 'optnone' requires 'noinline'!", V);
1726 "Attributes 'optsize and optnone' are incompatible!", V);
1729 "Attributes 'minsize and optnone' are incompatible!", V);
1735 "Attribute 'jumptable' requires 'unnamed_addr'", V);
1739 std::pair<unsigned, Optional<unsigned>>
Args =
1744 CheckFailed(
"'allocsize' " + Name +
" argument is out of bounds", V);
1750 " argument must refer to an integer parameter",
1758 if (!CheckParam(
"element size", Args.first))
1761 if (Args.second && !CheckParam(
"number of elements", *Args.second))
1766 void Verifier::verifyFunctionMetadata(
1767 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
1768 for (
const auto &Pair : MDs) {
1770 MDNode *MD = Pair.second;
1772 "!prof annotations should have no less than 2 operands", MD);
1778 "expected string with name of the !prof annotation", MD);
1781 Assert(ProfName.equals(
"function_entry_count") ||
1782 ProfName.equals(
"synthetic_function_entry_count"),
1783 "first operand should be 'function_entry_count'" 1784 " or 'synthetic_function_entry_count'",
1791 "expected integer argument to function_entry_count", MD);
1796 void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
1797 if (!ConstantExprVisited.insert(EntryC).second)
1803 while (!Stack.
empty()) {
1807 if (
const auto *CE = dyn_cast<ConstantExpr>(C))
1808 visitConstantExpr(CE);
1810 if (
const auto *GV = dyn_cast<GlobalValue>(C)) {
1823 if (!ConstantExprVisited.insert(OpC).second)
1830 void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
1831 if (CE->
getOpcode() == Instruction::BitCast)
1834 "Invalid bitcast", CE);
1836 if (CE->
getOpcode() == Instruction::IntToPtr ||
1837 CE->
getOpcode() == Instruction::PtrToInt) {
1838 auto *PtrTy = CE->
getOpcode() == Instruction::IntToPtr
1842 ?
"inttoptr not supported for non-integral pointers" 1843 :
"ptrtoint not supported for non-integral pointers";
1850 bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
1860 Intrinsic::experimental_gc_statepoint);
1866 "gc.statepoint must read and write all memory to preserve " 1867 "reordering restrictions required by safepoint semantics",
1871 Assert(isa<ConstantInt>(IDV),
"gc.statepoint ID must be a constant integer",
1875 Assert(isa<ConstantInt>(NumPatchBytesV),
1876 "gc.statepoint number of patchable bytes must be a constant integer",
1878 const int64_t NumPatchBytes =
1879 cast<ConstantInt>(NumPatchBytesV)->getSExtValue();
1881 Assert(NumPatchBytes >= 0,
"gc.statepoint number of patchable bytes must be " 1887 Assert(PT && PT->getElementType()->isFunctionTy(),
1888 "gc.statepoint callee must be of function pointer type", &CI, Target);
1889 FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType());
1892 Assert(isa<ConstantInt>(NumCallArgsV),
1893 "gc.statepoint number of arguments to underlying call " 1894 "must be constant integer",
1896 const int NumCallArgs = cast<ConstantInt>(NumCallArgsV)->getZExtValue();
1898 "gc.statepoint number of arguments to underlying call " 1901 const int NumParams = (int)TargetFuncType->getNumParams();
1902 if (TargetFuncType->isVarArg()) {
1903 Assert(NumCallArgs >= NumParams,
1904 "gc.statepoint mismatch in number of vararg call args", &CI);
1907 Assert(TargetFuncType->getReturnType()->isVoidTy(),
1908 "gc.statepoint doesn't support wrapping non-void " 1909 "vararg functions yet",
1912 Assert(NumCallArgs == NumParams,
1913 "gc.statepoint mismatch in number of call args", &CI);
1916 Assert(isa<ConstantInt>(FlagsV),
1917 "gc.statepoint flags must be constant integer", &CI);
1918 const uint64_t Flags = cast<ConstantInt>(FlagsV)->getZExtValue();
1920 "unknown flag used in gc.statepoint flags argument", &CI);
1924 for (
int i = 0; i < NumParams; i++) {
1925 Type *ParamType = TargetFuncType->getParamType(i);
1927 Assert(ArgType == ParamType,
1928 "gc.statepoint call argument does not match wrapped " 1933 const int EndCallArgsInx = 4 + NumCallArgs;
1936 Assert(isa<ConstantInt>(NumTransitionArgsV),
1937 "gc.statepoint number of transition arguments " 1938 "must be constant integer",
1940 const int NumTransitionArgs =
1941 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
1942 Assert(NumTransitionArgs >= 0,
1943 "gc.statepoint number of transition arguments must be positive", &CI);
1944 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
1947 Assert(isa<ConstantInt>(NumDeoptArgsV),
1948 "gc.statepoint number of deoptimization arguments " 1949 "must be constant integer",
1951 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
1952 Assert(NumDeoptArgs >= 0,
"gc.statepoint number of deoptimization arguments " 1956 const int ExpectedNumArgs =
1957 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs;
1959 "gc.statepoint too few arguments according to length fields", &CI);
1964 for (
const User *U : CI.
users()) {
1966 Assert(Call,
"illegal use of statepoint token", &CI, U);
1967 if (!Call)
continue;
1968 Assert(isa<GCRelocateInst>(Call) || isa<GCResultInst>(Call),
1969 "gc.result or gc.relocate are the only value uses " 1970 "of a gc.statepoint",
1972 if (isa<GCResultInst>(Call)) {
1974 "gc.result connected to wrong gc.statepoint", &CI,
Call);
1975 }
else if (isa<GCRelocateInst>(Call)) {
1977 "gc.relocate connected to wrong gc.statepoint", &CI,
Call);
1991 void Verifier::verifyFrameRecoverIndices() {
1992 for (
auto &Counts : FrameEscapeInfo) {
1994 unsigned EscapedObjectCount = Counts.second.first;
1995 unsigned MaxRecoveredIndex = Counts.second.second;
1996 Assert(MaxRecoveredIndex <= EscapedObjectCount,
1997 "all indices passed to llvm.localrecover must be less than the " 1998 "number of arguments passed ot llvm.localescape in the parent " 2006 if (
auto *II = dyn_cast<InvokeInst>(Terminator))
2007 UnwindDest = II->getUnwindDest();
2008 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2009 UnwindDest = CSI->getUnwindDest();
2011 UnwindDest = cast<CleanupReturnInst>(
Terminator)->getUnwindDest();
2015 void Verifier::verifySiblingFuncletUnwinds() {
2018 for (
const auto &Pair : SiblingFuncletInfo) {
2020 if (Visited.
count(PredPad))
2026 if (Active.
count(SuccPad)) {
2033 if (CycleTerminator != CyclePad)
2036 }
while (CyclePad != SuccPad);
2037 Assert(
false,
"EH pads can't handle each other's exceptions",
2041 if (!Visited.
insert(SuccPad).second)
2045 auto TermI = SiblingFuncletInfo.find(PredPad);
2046 if (TermI == SiblingFuncletInfo.end())
2048 Terminator = TermI->second;
2059 void Verifier::visitFunction(
const Function &F) {
2060 visitGlobalValue(F);
2067 "Function context does not match Module context!", &
F);
2071 "# formal arguments must match # of arguments for function type!", &
F,
2073 Assert(F.getReturnType()->isFirstClassType() ||
2074 F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(),
2075 "Functions cannot return aggregate values!", &
F);
2077 Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),
2078 "Invalid struct return type!", &
F);
2083 "Attribute after last parameter!", &F);
2086 verifyFunctionAttrs(FT, Attrs, &F);
2091 Assert(!Attrs.hasFnAttribute(Attribute::Builtin),
2092 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2097 switch (F.getCallingConv()) {
2103 Assert(F.getReturnType()->isVoidTy(),
2104 "Calling convention requires void return type", &
F);
2111 Assert(!F.hasStructRetAttr(),
2112 "Calling convention does not allow sret", &
F);
2119 Assert(!F.isVarArg(),
"Calling convention does not support varargs or " 2120 "perfect forwarding!",
2125 bool isLLVMdotName = F.getName().size() >= 5 &&
2126 F.getName().substr(0, 5) ==
"llvm.";
2132 "Argument value does not match function argument type!", &
Arg,
2135 "Function arguments must have first-class types!", &
Arg);
2136 if (!isLLVMdotName) {
2138 "Function takes metadata but isn't an intrinsic", &
Arg, &
F);
2140 "Function takes token but isn't an intrinsic", &
Arg, &
F);
2144 if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) {
2145 verifySwiftErrorValue(&
Arg);
2151 Assert(!F.getReturnType()->isTokenTy(),
2152 "Functions returns a token but isn't an intrinsic", &
F);
2156 F.getAllMetadata(MDs);
2157 assert(F.hasMetadata() != MDs.empty() &&
"Bit out-of-sync");
2158 verifyFunctionMetadata(MDs);
2161 if (F.hasPersonalityFn()) {
2164 Assert(Per->getParent() == F.getParent(),
2165 "Referencing personality function in another module!",
2166 &
F, F.getParent(), Per, Per->getParent());
2169 if (F.isMaterializable()) {
2171 Assert(MDs.empty(),
"unmaterialized function cannot have metadata", &
F,
2172 MDs.empty() ? nullptr : MDs.front().second);
2173 }
else if (F.isDeclaration()) {
2174 for (
const auto &
I : MDs) {
2176 "function declaration may not have a !dbg attachment", &F);
2178 "function declaration may not have a !prof attachment", &F);
2181 visitMDNode(*
I.second);
2183 Assert(!F.hasPersonalityFn(),
2184 "Function declaration shouldn't have a personality routine", &
F);
2188 Assert(!isLLVMdotName,
"llvm intrinsics cannot be defined!", &F);
2191 const BasicBlock *Entry = &F.getEntryBlock();
2193 "Entry block to function must not have predecessors!", Entry);
2198 "blockaddress may not be used with the entry block!", Entry);
2201 unsigned NumDebugAttachments = 0, NumProfAttachments = 0;
2203 for (
const auto &
I : MDs) {
2209 ++NumDebugAttachments;
2211 "function must have a single !dbg attachment", &F,
I.second);
2213 "function !dbg attachment must be a subprogram", &F,
I.second);
2214 auto *
SP = cast<DISubprogram>(
I.second);
2215 const Function *&AttachedTo = DISubprogramAttachments[
SP];
2216 AssertDI(!AttachedTo || AttachedTo == &F,
2217 "DISubprogram attached to more than one function",
SP, &F);
2222 ++NumProfAttachments;
2223 Assert(NumProfAttachments == 1,
2224 "function must have a single !prof attachment", &F,
I.second);
2229 visitMDNode(*
I.second);
2237 if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
2239 if (F.hasAddressTaken(&U))
2240 Assert(
false,
"Invalid user of intrinsic instruction!", U);
2243 auto *N = F.getSubprogram();
2244 HasDebugInfo = (N !=
nullptr);
2255 for (
auto &
I : BB) {
2259 dyn_cast_or_null<DILocation>(
I.getDebugLoc().getAsMDNode());
2262 if (!Seen.
insert(DL).second)
2266 if (Scope && !Seen.
insert(Scope).second)
2273 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
2278 "!dbg attachment points at wrong subprogram for function",
N, &
F,
2285 void Verifier::visitBasicBlock(
BasicBlock &BB) {
2286 InstsInThisBlock.clear();
2293 if (isa<PHINode>(BB.
front())) {
2299 Assert(PN.getNumIncomingValues() != 0,
2300 "PHI nodes must have at least one entry. If the block is dead, " 2301 "the PHI should be removed!",
2303 Assert(PN.getNumIncomingValues() == Preds.
size(),
2304 "PHINode should have one entry for each predecessor of its " 2305 "parent basic block!",
2310 Values.
reserve(PN.getNumIncomingValues());
2311 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
2313 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
2316 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
2323 "PHI node has multiple entries for the same basic block with " 2324 "different incoming values!",
2325 &PN, Values[i].
first, Values[i].
second, Values[i - 1].second);
2329 Assert(Values[i].first == Preds[i],
2330 "PHI node entries do not match predecessors!", &PN,
2331 Values[i].first, Preds[i]);
2339 Assert(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
2346 "Terminator found in the middle of a basic block!", I.
getParent());
2347 visitInstruction(I);
2350 void Verifier::visitBranchInst(
BranchInst &BI) {
2353 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
2355 visitTerminatorInst(BI);
2358 void Verifier::visitReturnInst(
ReturnInst &RI) {
2363 "Found return instr that returns non-void in Function of void " 2368 "Function return type does not match operand " 2369 "type of return inst!",
2374 visitTerminatorInst(RI);
2382 for (
auto &Case : SI.
cases()) {
2383 Assert(Case.getCaseValue()->getType() == SwitchTy,
2384 "Switch constants must all be same type as switch value!", &
SI);
2386 "Duplicate integer as switch case", &SI, Case.getCaseValue());
2389 visitTerminatorInst(SI);
2394 "Indirectbr operand must have pointer type!", &BI);
2397 "Indirectbr destinations must all have pointer type!", &BI);
2399 visitTerminatorInst(BI);
2402 void Verifier::visitSelectInst(
SelectInst &SI) {
2405 "Invalid operands for select instruction!", &SI);
2408 "Select values must have same type as select instruction!", &
SI);
2409 visitInstruction(SI);
2416 Assert(
false,
"User-defined operators should not live outside of a pass!", &I);
2419 void Verifier::visitTruncInst(
TruncInst &I) {
2431 "trunc source and destination must both be a vector or neither", &
I);
2432 Assert(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &I);
2434 visitInstruction(I);
2437 void Verifier::visitZExtInst(
ZExtInst &I) {
2446 "zext source and destination must both be a vector or neither", &
I);
2450 Assert(SrcBitSize < DestBitSize,
"Type too small for ZExt", &I);
2452 visitInstruction(I);
2455 void Verifier::visitSExtInst(
SExtInst &I) {
2467 "sext source and destination must both be a vector or neither", &
I);
2468 Assert(SrcBitSize < DestBitSize,
"Type too small for SExt", &I);
2470 visitInstruction(I);
2484 "fptrunc source and destination must both be a vector or neither", &
I);
2485 Assert(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &I);
2487 visitInstruction(I);
2490 void Verifier::visitFPExtInst(
FPExtInst &I) {
2502 "fpext source and destination must both be a vector or neither", &
I);
2503 Assert(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &I);
2505 visitInstruction(I);
2508 void Verifier::visitUIToFPInst(
UIToFPInst &I) {
2517 "UIToFP source and dest must both be vector or scalar", &I);
2519 "UIToFP source must be integer or integer vector", &
I);
2523 if (SrcVec && DstVec)
2524 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2525 cast<VectorType>(DestTy)->getNumElements(),
2526 "UIToFP source and dest vector length mismatch", &I);
2528 visitInstruction(I);
2531 void Verifier::visitSIToFPInst(
SIToFPInst &I) {
2540 "SIToFP source and dest must both be vector or scalar", &I);
2542 "SIToFP source must be integer or integer vector", &
I);
2546 if (SrcVec && DstVec)
2547 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2548 cast<VectorType>(DestTy)->getNumElements(),
2549 "SIToFP source and dest vector length mismatch", &I);
2551 visitInstruction(I);
2554 void Verifier::visitFPToUIInst(
FPToUIInst &I) {
2563 "FPToUI source and dest must both be vector or scalar", &I);
2567 "FPToUI result must be integer or integer vector", &
I);
2569 if (SrcVec && DstVec)
2570 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2571 cast<VectorType>(DestTy)->getNumElements(),
2572 "FPToUI source and dest vector length mismatch", &I);
2574 visitInstruction(I);
2577 void Verifier::visitFPToSIInst(
FPToSIInst &I) {
2586 "FPToSI source and dest must both be vector or scalar", &I);
2590 "FPToSI result must be integer or integer vector", &
I);
2592 if (SrcVec && DstVec)
2593 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2594 cast<VectorType>(DestTy)->getNumElements(),
2595 "FPToSI source and dest vector length mismatch", &I);
2597 visitInstruction(I);
2607 if (
auto *PTy = dyn_cast<PointerType>(SrcTy->
getScalarType()))
2609 "ptrtoint not supported for non-integral pointers");
2619 "PtrToInt Vector width mismatch", &
I);
2622 visitInstruction(I);
2631 "IntToPtr source must be an integral", &
I);
2634 if (
auto *PTy = dyn_cast<PointerType>(DestTy->
getScalarType()))
2636 "inttoptr not supported for non-integral pointers");
2644 "IntToPtr Vector width mismatch", &
I);
2646 visitInstruction(I);
2652 "Invalid bitcast", &I);
2653 visitInstruction(I);
2665 "AddrSpaceCast must be between different address spaces", &
I);
2668 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
2669 visitInstruction(I);
2674 void Verifier::visitPHINode(
PHINode &PN) {
2681 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
2690 "PHI node operands are not the same type as the result!", &PN);
2695 visitInstruction(PN);
2698 void Verifier::verifyCallSite(
CallSite CS) {
2702 "Called function must be a pointer!",
I);
2705 Assert(FPTy->getElementType()->isFunctionTy(),
2706 "Called function is not pointer to function type!",
I);
2709 "Called function is not the same type as the call!",
I);
2714 if (FTy->isVarArg())
2716 "Called function requires more parameters than were provided!",
I);
2719 "Incorrect number of arguments passed to called function!",
I);
2722 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2724 "Call parameter type does not match function signature!",
2730 "Attribute after last parameter!", I);
2738 "speculatable attribute may not apply to call sites",
I);
2742 verifyFunctionAttrs(FTy, Attrs, I);
2750 Assert(AI->isUsedWithInAlloca(),
2751 "inalloca argument for call has mismatched alloca", AI,
I);
2757 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2761 Assert(AI->isSwiftError(),
2762 "swifterror argument for call has mismatched alloca", AI,
I);
2766 Assert(ArgI,
"swifterror argument should come from an alloca or parameter", SwiftErrorArg, I);
2767 Assert(ArgI->hasSwiftErrorAttr(),
2768 "swifterror argument for call has mismatched parameter", ArgI,
I);
2771 if (FTy->isVarArg()) {
2773 bool SawNest =
false;
2774 bool SawReturned =
false;
2776 for (
unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
2784 for (
unsigned Idx = FTy->getNumParams(); Idx < CS.
arg_size(); ++Idx) {
2787 verifyParameterAttrs(ArgAttrs, Ty, I);
2790 Assert(!SawNest,
"More than one parameter has attribute nest!", I);
2795 Assert(!SawReturned,
"More than one parameter has attribute returned!",
2798 "Incompatible argument and return types for 'returned' " 2805 "Attribute 'sret' cannot be used for vararg call arguments!",
I);
2808 Assert(Idx == CS.
arg_size() - 1,
"inalloca isn't on the last argument!",
2816 for (
Type *ParamTy : FTy->params()) {
2817 Assert(!ParamTy->isMetadataTy(),
2818 "Function has metadata parameter but isn't an intrinsic",
I);
2819 Assert(!ParamTy->isTokenTy(),
2820 "Function has token parameter but isn't an intrinsic",
I);
2826 Assert(!FTy->getReturnType()->isTokenTy(),
2827 "Return type cannot be token for indirect call!");
2831 visitIntrinsicCallSite(
ID, CS);
2835 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
2836 FoundGCTransitionBundle =
false;
2841 Assert(!FoundDeoptBundle,
"Multiple deopt operand bundles", I);
2842 FoundDeoptBundle =
true;
2844 Assert(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
2846 FoundGCTransitionBundle =
true;
2848 Assert(!FoundFuncletBundle,
"Multiple funclet operand bundles", I);
2849 FoundFuncletBundle =
true;
2851 "Expected exactly one funclet bundle operand",
I);
2853 "Funclet bundle operands should correspond to a FuncletPadInst",
2864 "debug info must have a !dbg location",
2867 visitInstruction(*I);
2884 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
2885 Attribute::InReg, Attribute::Returned, Attribute::SwiftSelf,
2886 Attribute::SwiftError};
2888 for (
auto AK : ABIAttrs) {
2897 void Verifier::verifyMustTailCall(
CallInst &CI) {
2908 "cannot guarantee tail call due to mismatched parameter counts",
2913 "cannot guarantee tail call due to mismatched parameter types", &CI);
2917 "cannot guarantee tail call due to mismatched varargs", &CI);
2919 "cannot guarantee tail call due to mismatched return types", &CI);
2923 "cannot guarantee tail call due to mismatched calling conv", &CI);
2932 Assert(CallerABIAttrs == CalleeABIAttrs,
2933 "cannot guarantee tail call due to mismatched ABI impacting " 2934 "function attributes",
2942 Value *RetVal = &CI;
2946 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
2948 "bitcast following musttail call must use the call", BI);
2955 Assert(Ret,
"musttail call must precede a ret with an optional bitcast",
2958 "musttail call result must be returned",
Ret);
2961 void Verifier::visitCallInst(
CallInst &CI) {
2962 verifyCallSite(&CI);
2965 verifyMustTailCall(CI);
2968 void Verifier::visitInvokeInst(
InvokeInst &II) {
2969 verifyCallSite(&II);
2975 "The unwind destination does not have an exception handling instruction!",
2978 visitTerminatorInst(II);
2986 "Both operands to a binary operator are not of the same type!", &
B);
2992 case Instruction::Sub:
2993 case Instruction::Mul:
2994 case Instruction::SDiv:
2995 case Instruction::UDiv:
2996 case Instruction::SRem:
2997 case Instruction::URem:
2999 "Integer arithmetic operators only work with integral types!", &
B);
3001 "Integer arithmetic operators must have same type " 3002 "for operands and result!",
3007 case Instruction::FAdd:
3008 case Instruction::FSub:
3009 case Instruction::FMul:
3010 case Instruction::FDiv:
3011 case Instruction::FRem:
3013 "Floating-point arithmetic operators only work with " 3014 "floating-point types!",
3017 "Floating-point arithmetic operators must have same type " 3018 "for operands and result!",
3022 case Instruction::And:
3023 case Instruction::Or:
3024 case Instruction::Xor:
3026 "Logical operators only work with integral types!", &
B);
3028 "Logical operators must have same type for operands and result!",
3031 case Instruction::Shl:
3032 case Instruction::LShr:
3033 case Instruction::AShr:
3035 "Shifts only work with integral types!", &
B);
3037 "Shift return type must be same as operands!", &
B);
3043 visitInstruction(B);
3046 void Verifier::visitICmpInst(
ICmpInst &IC) {
3051 "Both operands to ICmp instruction are not of the same type!", &IC);
3054 "Invalid operand types for ICmp instruction", &IC);
3057 "Invalid predicate in ICmp instruction!", &IC);
3059 visitInstruction(IC);
3067 "Both operands to FCmp instruction are not of the same type!", &FC);
3070 "Invalid operand types for FCmp instruction", &
FC);
3073 "Invalid predicate in FCmp instruction!", &
FC);
3075 visitInstruction(FC);
3081 "Invalid extractelement operands!", &EI);
3082 visitInstruction(EI);
3088 "Invalid insertelement operands!", &IE);
3089 visitInstruction(IE);
3095 "Invalid shufflevector operands!", &SV);
3096 visitInstruction(SV);
3102 Assert(isa<PointerType>(TargetTy),
3103 "GEP base pointer is not a vector or a vector of pointers", &GEP);
3109 "GEP indexes must be integers", &GEP);
3112 Assert(ElTy,
"Invalid indices for GEP pointer type!", &GEP);
3116 "GEP is not of right type for indices!", &
GEP, ElTy);
3118 if (GEP.getType()->isVectorTy()) {
3120 unsigned GEPWidth = GEP.getType()->getVectorNumElements();
3121 if (GEP.getPointerOperandType()->isVectorTy())
3122 Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),
3123 "Vector GEP result width doesn't match operand's", &
GEP);
3124 for (
Value *Idx : Idxs) {
3125 Type *IndexTy = Idx->getType();
3128 Assert(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &GEP);
3131 "All GEP indices should be of integer type");
3134 visitInstruction(GEP);
3143 "precondition violation");
3146 Assert(NumOperands % 2 == 0,
"Unfinished range!", Range);
3147 unsigned NumRanges = NumOperands / 2;
3148 Assert(NumRanges >= 1,
"It should have at least one range!", Range);
3151 for (
unsigned i = 0; i < NumRanges; ++i) {
3153 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(2 * i));
3154 Assert(Low,
"The lower limit must be an integer!", Low);
3156 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(2 * i + 1));
3157 Assert(High,
"The upper limit must be an integer!", High);
3159 "Range types must match instruction type!", &
I);
3165 "Range must not be empty!", Range);
3168 "Intervals are overlapping", Range);
3176 if (NumRanges > 2) {
3178 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(0))->getValue();
3180 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(1))->getValue();
3183 "Intervals are overlapping", Range);
3189 void Verifier::checkAtomicMemAccessSize(
Type *Ty,
const Instruction *I) {
3191 Assert(Size >= 8,
"atomic memory access' size must be byte-sized", Ty, I);
3192 Assert(!(Size & (Size - 1)),
3193 "atomic memory access' operand must have a power-of-two size", Ty, I);
3196 void Verifier::visitLoadInst(
LoadInst &LI) {
3198 Assert(PTy,
"Load operand must be a pointer.", &LI);
3201 "huge alignment values are unsupported", &LI);
3202 Assert(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
3206 "Load cannot have Release ordering", &LI);
3208 "Atomic load must specify explicit alignment", &LI);
3210 "atomic load operand must have integer, pointer, or floating point " 3213 checkAtomicMemAccessSize(ElTy, &LI);
3216 "Non-atomic load cannot have SynchronizationScope specified", &LI);
3219 visitInstruction(LI);
3222 void Verifier::visitStoreInst(
StoreInst &SI) {
3224 Assert(PTy,
"Store operand must be a pointer.", &SI);
3227 "Stored value type does not match pointer operand type!", &
SI, ElTy);
3229 "huge alignment values are unsupported", &
SI);
3234 "Store cannot have Acquire ordering", &
SI);
3236 "Atomic store must specify explicit alignment", &
SI);
3238 "atomic store operand must have integer, pointer, or floating point " 3241 checkAtomicMemAccessSize(ElTy, &SI);
3244 "Non-atomic store cannot have SynchronizationScope specified", &
SI);
3246 visitInstruction(SI);
3250 void Verifier::verifySwiftErrorCallSite(
CallSite CS,
3251 const Value *SwiftErrorVal) {
3254 I !=
E; ++
I, ++Idx) {
3255 if (*I == SwiftErrorVal) {
3257 "swifterror value when used in a callsite should be marked " 3258 "with swifterror attribute",
3264 void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
3267 for (
const User *U : SwiftErrorVal->
users()) {
3268 Assert(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
3270 "swifterror value can only be loaded and stored from, or " 3271 "as a swifterror argument!",
3274 if (
auto StoreI = dyn_cast<StoreInst>(U))
3275 Assert(StoreI->getOperand(1) == SwiftErrorVal,
3276 "swifterror value should be the second operand when used " 3277 "by stores", SwiftErrorVal, U);
3278 if (
auto CallI = dyn_cast<CallInst>(U))
3279 verifySwiftErrorCallSite(const_cast<CallInst*>(CallI), SwiftErrorVal);
3280 if (
auto II = dyn_cast<InvokeInst>(U))
3281 verifySwiftErrorCallSite(const_cast<InvokeInst*>(II), SwiftErrorVal);
3285 void Verifier::visitAllocaInst(
AllocaInst &AI) {
3290 "Allocation instruction pointer not in the stack address space!",
3293 "Cannot allocate unsized type", &AI);
3295 "Alloca array size must have integer type", &AI);
3297 "huge alignment values are unsupported", &AI);
3300 verifySwiftErrorValue(&AI);
3303 visitInstruction(AI);
3310 "cmpxchg instructions must be atomic.", &CXI);
3312 "cmpxchg instructions must be atomic.", &CXI);
3314 "cmpxchg instructions cannot be unordered.", &CXI);
3316 "cmpxchg instructions cannot be unordered.", &CXI);
3318 "cmpxchg instructions failure argument shall be no stronger than the " 3323 "cmpxchg failure ordering cannot include release semantics", &CXI);
3326 Assert(PTy,
"First cmpxchg operand must be a pointer.", &CXI);
3327 Type *ElTy = PTy->getElementType();
3329 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
3330 checkAtomicMemAccessSize(ElTy, &CXI);
3332 "Expected value type does not match pointer operand type!", &CXI,
3335 "Stored value type does not match pointer operand type!", &CXI, ElTy);
3336 visitInstruction(CXI);
3341 "atomicrmw instructions must be atomic.", &RMWI);
3343 "atomicrmw instructions cannot be unordered.", &RMWI);
3345 Assert(PTy,
"First atomicrmw operand must be a pointer.", &RMWI);
3346 Type *ElTy = PTy->getElementType();
3349 checkAtomicMemAccessSize(ElTy, &RMWI);
3351 "Argument value type does not match pointer operand type!", &RMWI,
3355 "Invalid binary operation!", &RMWI);
3356 visitInstruction(RMWI);
3359 void Verifier::visitFenceInst(
FenceInst &FI) {
3365 "fence instructions may only have acquire, release, acq_rel, or " 3366 "seq_cst ordering.",
3368 visitInstruction(FI);
3374 "Invalid ExtractValueInst operands!", &EVI);
3376 visitInstruction(EVI);
3383 "Invalid InsertValueInst operands!", &IVI);
3385 visitInstruction(IVI);
3389 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
3390 return FPI->getParentPad();
3395 void Verifier::visitEHPadPredecessors(
Instruction &I) {
3403 if (
auto *LPI = dyn_cast<LandingPadInst>(&I)) {
3410 "Block containing LandingPadInst must be jumped to " 3411 "only by the unwind edge of an invoke.",
3416 if (
auto *CPI = dyn_cast<CatchPadInst>(&I)) {
3418 Assert(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(),
3419 "Block containg CatchPadInst must be jumped to " 3420 "only by its catchswitch.",
3422 Assert(BB != CPI->getCatchSwitch()->getUnwindDest(),
3423 "Catchswitch cannot unwind to one of its catchpads",
3424 CPI->getCatchSwitch(), CPI);
3435 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
3437 "EH pad must be jumped to via an unwind edge", ToPad, II);
3439 FromPad = Bundle->Inputs[0];
3442 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
3443 FromPad = CRI->getOperand(0);
3444 Assert(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
3445 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
3448 Assert(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
3455 "EH pad cannot handle exceptions raised within it", FromPad, TI);
3456 if (FromPad == ToPadParent) {
3460 Assert(!isa<ConstantTokenNone>(FromPad),
3461 "A single unwind edge may only enter one EH pad", TI);
3463 "EH pad jumps through a cycle of pads", FromPad);
3472 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
3474 visitEHPadPredecessors(LPI);
3476 if (!LandingPadResultTy)
3477 LandingPadResultTy = LPI.
getType();
3480 "The landingpad instruction should have a consistent result type " 3481 "inside a function.",
3485 Assert(F->hasPersonalityFn(),
3486 "LandingPadInst needs to be in a function with a personality.", &LPI);
3491 "LandingPadInst not the first non-PHI instruction in the block.",
3498 "Catch operand does not have pointer type!", &LPI);
3500 Assert(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
3501 Assert(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),
3502 "Filter operand is not an array of constants!", &LPI);
3506 visitInstruction(LPI);
3509 void Verifier::visitResumeInst(
ResumeInst &RI) {
3511 "ResumeInst needs to be in a function with a personality.", &RI);
3513 if (!LandingPadResultTy)
3517 "The resume instruction should have a consistent result type " 3518 "inside a function.",
3521 visitTerminatorInst(RI);
3529 "CatchPadInst needs to be in a function with a personality.", &CPI);
3532 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
3538 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
3540 visitEHPadPredecessors(CPI);
3541 visitFuncletPadInst(CPI);
3546 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
3549 visitTerminatorInst(CatchReturn);
3557 "CleanupPadInst needs to be in a function with a personality.", &CPI);
3562 "CleanupPadInst not the first non-PHI instruction in the block.",
3566 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
3567 "CleanupPadInst has an invalid parent.", &CPI);
3569 visitEHPadPredecessors(CPI);
3570 visitFuncletPadInst(CPI);
3574 User *FirstUser =
nullptr;
3575 Value *FirstUnwindPad =
nullptr;
3579 while (!Worklist.empty()) {
3582 "FuncletPadInst must not be nested within itself", CurrentPad);
3583 Value *UnresolvedAncestorPad =
nullptr;
3584 for (User *U : CurrentPad->
users()) {
3586 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
3587 UnwindDest = CRI->getUnwindDest();
3588 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
3593 if (CSI->unwindsToCaller())
3595 UnwindDest = CSI->getUnwindDest();
3596 }
else if (
auto *II = dyn_cast<InvokeInst>(U)) {
3598 }
else if (isa<CallInst>(U)) {
3603 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
3607 Worklist.push_back(CPI);
3610 Assert(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
3618 if (!cast<Instruction>(UnwindPad)->isEHPad())
3622 if (UnwindParent == CurrentPad)
3628 Value *ExitedPad = CurrentPad;
3631 if (ExitedPad == &FPI) {
3636 UnresolvedAncestorPad = &FPI;
3640 if (ExitedParent == UnwindParent) {
3644 UnresolvedAncestorPad = ExitedParent;
3647 ExitedPad = ExitedParent;
3648 }
while (!isa<ConstantTokenNone>(ExitedPad));
3653 UnresolvedAncestorPad = &FPI;
3660 Assert(UnwindPad == FirstUnwindPad,
"Unwind edges out of a funclet " 3661 "pad must have the same unwind " 3663 &FPI, U, FirstUser);
3666 FirstUnwindPad = UnwindPad;
3668 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
3670 SiblingFuncletInfo[&FPI] = cast<TerminatorInst>(U);
3675 if (CurrentPad != &FPI)
3678 if (UnresolvedAncestorPad) {
3679 if (CurrentPad == UnresolvedAncestorPad) {
3683 assert(CurrentPad == &FPI);
3691 Value *ResolvedPad = CurrentPad;
3692 while (!Worklist.empty()) {
3693 Value *UnclePad = Worklist.back();
3697 while (ResolvedPad != AncestorPad) {
3699 if (ResolvedParent == UnresolvedAncestorPad) {
3702 ResolvedPad = ResolvedParent;
3706 if (ResolvedPad != AncestorPad)
3709 Worklist.pop_back();
3714 if (FirstUnwindPad) {
3715 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
3716 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
3717 Value *SwitchUnwindPad;
3718 if (SwitchUnwindDest)
3722 Assert(SwitchUnwindPad == FirstUnwindPad,
3723 "Unwind edges out of a catch must have the same unwind dest as " 3724 "the parent catchswitch",
3725 &FPI, FirstUser, CatchSwitch);
3729 visitInstruction(FPI);
3737 "CatchSwitchInst needs to be in a function with a personality.",
3743 "CatchSwitchInst not the first non-PHI instruction in the block.",
3747 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
3748 "CatchSwitchInst has an invalid parent.", ParentPad);
3753 "CatchSwitchInst must unwind to an EH block which is not a " 3759 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
3763 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
3766 Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),
3767 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
3770 visitEHPadPredecessors(CatchSwitch);
3771 visitTerminatorInst(CatchSwitch);
3776 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
3782 "CleanupReturnInst must unwind to an EH block which is not a " 3787 visitTerminatorInst(CRI);
3790 void Verifier::verifyDominatesUse(
Instruction &I,
unsigned i) {
3795 if (
InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
3807 if (!isa<PHINode>(I) && InstsInThisBlock.count(Op))
3811 Assert(DT.dominates(Op, U),
3812 "Instruction does not dominate all uses!",
Op, &
I);
3817 "apply only to pointer types", &
I);
3819 "dereferenceable, dereferenceable_or_null apply only to load" 3820 " instructions, use attributes for calls or invokes", &I);
3822 "take one operand!", &
I);
3824 Assert(CI && CI->getType()->isIntegerTy(64),
"dereferenceable, " 3825 "dereferenceable_or_null metadata value must be an i64!", &
I);
3832 Assert(BB,
"Instruction not embedded in basic block!", &I);
3834 if (!isa<PHINode>(I)) {
3835 for (User *U : I.
users()) {
3836 Assert(U != (User *)&I || !DT.isReachableFromEntry(BB),
3837 "Only PHI nodes may reference their own value!", &
I);
3843 "Instruction has a name, but provides a void value!", &
I);
3848 "Instruction returns a non-scalar type!", &
I);
3853 "Invalid use of metadata!", &
I);
3859 if (
Instruction *Used = dyn_cast<Instruction>(U.getUser()))
3860 Assert(Used->getParent() !=
nullptr,
3861 "Instruction referencing" 3862 " instruction not embedded in a basic block!",
3865 CheckFailed(
"Use of instruction is not an instruction!", U);
3876 Assert(
false,
"Instruction operands must be first-class values!", &I);
3884 i == (isa<CallInst>(
I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0),
3885 "Cannot take the address of an intrinsic!", &I);
3891 F->
getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||
3894 "Cannot invoke an intrinsic other than donothing, patchpoint, " 3895 "statepoint, coro_resume or coro_destroy",
3898 &
I, &
M,
F, F->getParent());
3901 "Referring to a basic block in another function!", &
I);
3904 "Referring to an argument in another function!", &
I);
3908 }
else if (isa<Instruction>(I.
getOperand(i))) {
3909 verifyDominatesUse(I, i);
3910 }
else if (isa<InlineAsm>(I.
getOperand(i))) {
3911 Assert((i + 1 == e && isa<CallInst>(I)) ||
3912 (i + 3 == e && isa<InvokeInst>(I)),
3913 "Cannot take the address of an inline asm!", &I);
3921 visitConstantExprsRecursively(CE);
3928 "fpmath requires a floating point result!", &
I);
3931 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
3932 const APFloat &Accuracy = CFP0->getValueAPF();
3934 "fpmath accuracy must have float type", &
I);
3936 "fpmath accuracy not a positive number!", &
I);
3938 Assert(
false,
"invalid fpmath accuracy!", &I);
3943 Assert(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),
3944 "Ranges are only for loads, calls and invokes!", &I);
3945 visitRangeMetadata(I, Range, I.
getType());
3952 "nonnull applies only to load instructions, use attributes" 3953 " for calls or invokes",
3958 visitDereferenceableMetadata(I, MD);
3961 visitDereferenceableMetadata(I, MD);
3964 TBAAVerifyHelper.visitTBAAMetadata(I, TBAA);
3969 Assert(isa<LoadInst>(I),
"align applies only to load instructions, " 3970 "use attributes for calls or invokes", &I);
3971 Assert(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
3972 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
3973 Assert(CI && CI->getType()->isIntegerTy(64),
3974 "align metadata value must be an i64!", &
I);
3975 uint64_t
Align = CI->getZExtValue();
3977 "align metadata value must be a power of 2!", &I);
3979 "alignment is larger that implementation defined limit", &I);
3983 AssertDI(isa<DILocation>(N),
"invalid !dbg metadata attachment", &I, N);
3987 if (
auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
3988 verifyFragmentExpression(*DII);
3990 InstsInThisBlock.insert(&I);
4011 "Intrinsic has incorrect return type!", IF);
4012 for (
unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i)
4015 "Intrinsic has incorrect argument type!", IF);
4020 "Intrinsic was not defined with variable arguments!", IF);
4023 "Callsite was not defined with variable arguments!", IF);
4026 Assert(TableRef.
empty(),
"Intrinsic has too few arguments!",
IF);
4034 "Intrinsic name not mangled correctly for type arguments! " 4042 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
4043 visitMetadataAsValue(*MD, CS.
getCaller());
4048 case Intrinsic::coro_id: {
4050 if (isa<ConstantPointerNull>(InfoArg))
4054 "info argument of llvm.coro.begin must refer to an initialized " 4057 Assert(isa<ConstantStruct>(Init) || isa<ConstantArray>(Init),
4058 "info argument of llvm.coro.begin must refer to either a struct or " 4062 case Intrinsic::ctlz:
4063 case Intrinsic::cttz:
4065 "is_zero_undef argument of bit counting intrinsics must be a " 4069 case Intrinsic::experimental_constrained_fadd:
4070 case Intrinsic::experimental_constrained_fsub:
4071 case Intrinsic::experimental_constrained_fmul:
4072 case Intrinsic::experimental_constrained_fdiv:
4073 case Intrinsic::experimental_constrained_frem:
4074 case Intrinsic::experimental_constrained_fma:
4075 case Intrinsic::experimental_constrained_sqrt:
4076 case Intrinsic::experimental_constrained_pow:
4077 case Intrinsic::experimental_constrained_powi:
4078 case Intrinsic::experimental_constrained_sin:
4079 case Intrinsic::experimental_constrained_cos:
4080 case Intrinsic::experimental_constrained_exp:
4081 case Intrinsic::experimental_constrained_exp2:
4082 case Intrinsic::experimental_constrained_log:
4083 case Intrinsic::experimental_constrained_log10:
4084 case Intrinsic::experimental_constrained_log2:
4085 case Intrinsic::experimental_constrained_rint:
4086 case Intrinsic::experimental_constrained_nearbyint:
4087 visitConstrainedFPIntrinsic(
4090 case Intrinsic::dbg_declare:
4092 "invalid llvm.dbg.declare intrinsic call 1", CS);
4093 visitDbgIntrinsic(
"declare", cast<DbgInfoIntrinsic>(*CS.
getInstruction()));
4095 case Intrinsic::dbg_addr:
4096 visitDbgIntrinsic(
"addr", cast<DbgInfoIntrinsic>(*CS.
getInstruction()));
4098 case Intrinsic::dbg_value:
4099 visitDbgIntrinsic(
"value", cast<DbgInfoIntrinsic>(*CS.
getInstruction()));
4101 case Intrinsic::dbg_label:
4102 visitDbgLabelIntrinsic(
"label", cast<DbgLabelInst>(*CS.
getInstruction()));
4104 case Intrinsic::memcpy:
4105 case Intrinsic::memmove:
4106 case Intrinsic::memset: {
4108 auto IsValidAlignment = [&](
unsigned Alignment) ->
bool {
4111 Assert(IsValidAlignment(
MI->getDestAlignment()),
4112 "alignment of arg 0 of memory intrinsic must be 0 or a power of 2",
4114 if (
const auto *MTI = dyn_cast<MemTransferInst>(
MI)) {
4115 Assert(IsValidAlignment(MTI->getSourceAlignment()),
4116 "alignment of arg 1 of memory intrinsic must be 0 or a power of 2",
4120 "isvolatile argument of memory intrinsics must be a constant int",
4124 case Intrinsic::memcpy_element_unordered_atomic:
4125 case Intrinsic::memmove_element_unordered_atomic:
4126 case Intrinsic::memset_element_unordered_atomic: {
4132 "element size of the element-wise unordered atomic memory " 4133 "intrinsic must be a constant int",
4135 const APInt &ElementSizeVal = ElementSizeCI->getValue();
4137 "element size of the element-wise atomic memory intrinsic " 4138 "must be a power of 2",
4141 if (
auto *LengthCI = dyn_cast<ConstantInt>(AMI->getLength())) {
4142 uint64_t Length = LengthCI->getZExtValue();
4143 uint64_t ElementSize = AMI->getElementSizeInBytes();
4144 Assert((Length % ElementSize) == 0,
4145 "constant length must be a multiple of the element size in the " 4146 "element-wise atomic memory intrinsic",
4150 auto IsValidAlignment = [&](uint64_t Alignment) {
4153 uint64_t DstAlignment = AMI->getDestAlignment();
4154 Assert(IsValidAlignment(DstAlignment),
4155 "incorrect alignment of the destination argument", CS);
4156 if (
const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
4157 uint64_t SrcAlignment = AMT->getSourceAlignment();
4158 Assert(IsValidAlignment(SrcAlignment),
4159 "incorrect alignment of the source argument", CS);
4163 case Intrinsic::gcroot:
4164 case Intrinsic::gcwrite:
4165 case Intrinsic::gcread:
4166 if (ID == Intrinsic::gcroot) {
4169 Assert(AI,
"llvm.gcroot parameter #1 must be an alloca.", CS);
4171 "llvm.gcroot parameter #2 must be a constant.", CS);
4174 "llvm.gcroot parameter #1 must either be a pointer alloca, " 4175 "or argument #2 must be a non-null constant.",
4181 "Enclosing function does not use GC.", CS);
4183 case Intrinsic::init_trampoline:
4185 "llvm.init_trampoline parameter #2 must resolve to a function.",
4191 cast<ConstantInt>(CS.
getArgOperand(1))->getZExtValue() < 2 &&
4193 "invalid arguments to llvm.prefetch", CS);
4195 case Intrinsic::stackprotector:
4197 "llvm.stackprotector parameter #2 must resolve to an alloca.", CS);
4199 case Intrinsic::lifetime_start:
4200 case Intrinsic::lifetime_end:
4201 case Intrinsic::invariant_start:
4203 "size argument of memory use markers must be a constant integer",
4206 case Intrinsic::invariant_end:
4208 "llvm.invariant.end parameter #2 must be a constant integer", CS);
4211 case Intrinsic::localescape: {
4214 "llvm.localescape used outside of entry block", CS);
4216 "multiple calls to llvm.localescape in one function", CS);
4218 if (isa<ConstantPointerNull>(
Arg))
4222 "llvm.localescape only accepts static allocas", CS);
4225 SawFrameEscape =
true;
4228 case Intrinsic::localrecover: {
4232 "llvm.localrecover first " 4233 "argument must be function defined in this module",
4236 Assert(IdxArg,
"idx argument of llvm.localrecover must be a constant int",
4238 auto &Entry = FrameEscapeInfo[Fn];
4240 std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
4244 case Intrinsic::experimental_gc_statepoint:
4246 "gc.statepoint support for inline assembly unimplemented", CS);
4248 "Enclosing function does not use GC.", CS);
4250 verifyStatepoint(CS);
4252 case Intrinsic::experimental_gc_result: {
4254 "Enclosing function does not use GC.", CS);
4258 StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() :
nullptr;
4259 Assert(StatepointFn && StatepointFn->isDeclaration() &&
4260 StatepointFn->getIntrinsicID() ==
4261 Intrinsic::experimental_gc_statepoint,
4262 "gc.result operand #1 must be from a statepoint", CS,
4266 const Value *
Target = StatepointCS.getArgument(2);
4267 auto *PT = cast<PointerType>(Target->getType());
4268 auto *TargetFuncType = cast<FunctionType>(PT->getElementType());
4269 Assert(CS.getType() == TargetFuncType->getReturnType(),
4270 "gc.result result type does not match wrapped callee", CS);
4273 case Intrinsic::experimental_gc_relocate: {
4277 "gc.relocate must return a pointer or a vector of pointers", CS);
4286 LandingPad->
getParent()->getUniquePredecessor();
4290 Assert(InvokeBB,
"safepoints should have unique landingpads",
4295 "gc relocate should be linked to a statepoint", InvokeBB);
4303 "gc relocate is incorrectly tied to the statepoint", CS, Token);
4313 Assert(isa<ConstantInt>(Base),
4314 "gc.relocate operand #2 must be integer offset", CS);
4317 Assert(isa<ConstantInt>(Derived),
4318 "gc.relocate operand #3 must be integer offset", CS);
4320 const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue();
4321 const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
4323 Assert(0 <= BaseIndex && BaseIndex < (
int)StatepointCS.arg_size(),
4324 "gc.relocate: statepoint base index out of bounds", CS);
4325 Assert(0 <= DerivedIndex && DerivedIndex < (
int)StatepointCS.arg_size(),
4326 "gc.relocate: statepoint derived index out of bounds", CS);
4330 Assert(StatepointCS.arg_size() > 0,
4331 "gc.statepoint: insufficient arguments");
4332 Assert(isa<ConstantInt>(StatepointCS.getArgument(3)),
4333 "gc.statement: number of call arguments must be constant integer");
4334 const unsigned NumCallArgs =
4335 cast<ConstantInt>(StatepointCS.getArgument(3))->getZExtValue();
4336 Assert(StatepointCS.arg_size() > NumCallArgs + 5,
4337 "gc.statepoint: mismatch in number of call arguments");
4338 Assert(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)),
4339 "gc.statepoint: number of transition arguments must be " 4340 "a constant integer");
4341 const int NumTransitionArgs =
4342 cast<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5))
4344 const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1;
4345 Assert(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart)),
4346 "gc.statepoint: number of deoptimization arguments must be " 4347 "a constant integer");
4348 const int NumDeoptArgs =
4349 cast<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart))
4351 const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs;
4352 const int GCParamArgsEnd = StatepointCS.arg_size();
4353 Assert(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd,
4354 "gc.relocate: statepoint base index doesn't fall within the " 4355 "'gc parameters' section of the statepoint call",
4357 Assert(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd,
4358 "gc.relocate: statepoint derived index doesn't fall within the " 4359 "'gc parameters' section of the statepoint call",
4368 "gc.relocate: relocated value must be a gc pointer", CS);
4370 auto ResultType = CS.
getType();
4372 Assert(ResultType->isVectorTy() == DerivedType->isVectorTy(),
4373 "gc.relocate: vector relocates to vector and pointer to pointer",
4376 ResultType->getPointerAddressSpace() ==
4377 DerivedType->getPointerAddressSpace(),
4378 "gc.relocate: relocating a pointer shouldn't change its address space",
4382 case Intrinsic::eh_exceptioncode:
4383 case Intrinsic::eh_exceptionpointer: {
4385 "eh.exceptionpointer argument must be a catchpad", CS);
4388 case Intrinsic::masked_load: {
4396 "masked_load: mask must be vector", CS);
4399 Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType();
4401 "masked_load: return must match pointer type", CS);
4403 "masked_load: pass through and data type must match", CS);
4405 DataTy->getVectorNumElements(),
4406 "masked_load: vector mask must be same length as data", CS);
4409 case Intrinsic::masked_store: {
4415 "masked_store: mask must be vector", CS);
4418 Type *DataTy = cast<PointerType>(Ptr->
getType())->getElementType();
4420 "masked_store: storee must match pointer type", CS);
4422 DataTy->getVectorNumElements(),
4423 "masked_store: vector mask must be same length as data", CS);
4427 case Intrinsic::experimental_guard: {
4428 Assert(CS.
isCall(),
"experimental_guard cannot be invoked", CS);
4430 "experimental_guard must have exactly one " 4431 "\"deopt\" operand bundle");
4435 case Intrinsic::experimental_deoptimize: {
4436 Assert(CS.
isCall(),
"experimental_deoptimize cannot be invoked", CS);
4438 "experimental_deoptimize must have exactly one " 4439 "\"deopt\" operand bundle");
4441 "experimental_deoptimize return type must match caller return type");
4447 "calls to experimental_deoptimize must be followed by a return");
4450 Assert(RI->getReturnValue() == DeoptCI,
4451 "calls to experimental_deoptimize must be followed by a return " 4452 "of the value computed by experimental_deoptimize");
4468 if (
auto *
SP = dyn_cast<DISubprogram>(LocalScope))
4471 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
4475 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
4482 (NumOperands == 3 && FPI.
isUnaryOp()) || (NumOperands == 4)),
4483 "invalid arguments for constrained FP intrinsic", &FPI);
4485 "invalid exception behavior argument", &FPI);
4487 "invalid rounding mode argument", &FPI);
4489 "invalid rounding mode argument", &FPI);
4491 "invalid exception behavior argument", &FPI);
4495 auto *MD = cast<MetadataAsValue>(DII.
getArgOperand(0))->getMetadata();
4496 AssertDI(isa<ValueAsMetadata>(MD) ||
4497 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
4498 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
4500 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
4503 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
4508 if (!isa<DILocation>(N))
4517 AssertDI(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
4522 if (!VarSP || !LocSP)
4525 AssertDI(VarSP == LocSP,
"mismatched subprogram between llvm.dbg." + Kind +
4526 " variable and !dbg attachment",
4528 Loc->getScope()->getSubprogram());
4535 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DLI,
4540 if (!isa<DILocation>(N))
4549 Assert(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
4554 if (!LabelSP || !LocSP)
4557 AssertDI(LabelSP == LocSP,
"mismatched subprogram between llvm.dbg." + Kind +
4558 " label and !dbg attachment",
4560 Loc->getScope()->getSubprogram());
4564 if (dyn_cast<DbgLabelInst>(&I))
4571 if (!V || !E || !E->isValid())
4575 auto Fragment = E->getFragmentInfo();
4588 verifyFragmentExpression(*V, *Fragment, &I);
4591 template <
typename ValueOrMetadata>
4592 void Verifier::verifyFragmentExpression(
const DIVariable &V,
4594 ValueOrMetadata *Desc) {
4603 AssertDI(FragSize + FragOffset <= *VarSize,
4604 "fragment is larger than or outside of variable", Desc, &V);
4605 AssertDI(FragSize != *VarSize,
"fragment covers entire variable", Desc, &V);
4620 AssertDI(Var,
"dbg intrinsic without variable");
4622 unsigned ArgNo = Var->
getArg();
4628 if (DebugFnArgs.size() < ArgNo)
4629 DebugFnArgs.resize(ArgNo,
nullptr);
4631 auto *Prev = DebugFnArgs[ArgNo - 1];
4632 DebugFnArgs[ArgNo - 1] = Var;
4633 AssertDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &I,
4637 void Verifier::verifyCompileUnits() {
4646 Listed.
insert(CUs->op_begin(), CUs->op_end());
4647 for (
auto *
CU : CUVisited)
4652 void Verifier::verifyDeoptimizeCallingConvs() {
4653 if (DeoptimizeDeclarations.empty())
4656 const Function *First = DeoptimizeDeclarations[0];
4657 for (
auto *F :
makeArrayRef(DeoptimizeDeclarations).slice(1)) {
4659 "All llvm.experimental.deoptimize declarations must have the same " 4660 "calling convention",
4677 return !V.verify(F);
4683 Verifier V(OS, !BrokenDebugInfo, M);
4687 Broken |= !V.verify(F);
4689 Broken |= !V.verify();
4690 if (BrokenDebugInfo)
4691 *BrokenDebugInfo = V.hasBrokenDebugInfo();
4702 std::unique_ptr<Verifier> V;
4703 bool FatalErrors =
true;
4708 explicit VerifierLegacyPass(
bool FatalErrors)
4710 FatalErrors(FatalErrors) {
4714 bool doInitialization(
Module &M)
override {
4715 V = llvm::make_unique<Verifier>(
4721 if (!V->verify(F) && FatalErrors)
4727 bool doFinalization(
Module &M)
override {
4728 bool HasErrors =
false;
4731 HasErrors |= !V->verify(F);
4733 HasErrors |= !V->verify();
4734 if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo()))
4747 template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&...
Args) {
4749 return Diagnostic->CheckFailed(
Args...);
4752 #define AssertTBAA(C, ...) \ 4755 CheckFailed(__VA_ARGS__); \ 4763 TBAAVerifier::TBAABaseNodeSummary
4767 CheckFailed(
"Base nodes must have at least two operands", &I, BaseNode);
4771 auto Itr = TBAABaseNodes.find(BaseNode);
4772 if (Itr != TBAABaseNodes.end())
4775 auto Result = verifyTBAABaseNodeImpl(I, BaseNode, IsNewFormat);
4776 auto InsertResult = TBAABaseNodes.insert({BaseNode,
Result});
4778 assert(InsertResult.second &&
"We just checked!");
4782 TBAAVerifier::TBAABaseNodeSummary
4785 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0u};
4789 return isValidScalarTBAANode(BaseNode)
4790 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
4796 CheckFailed(
"Access tag nodes must have the number of operands that is a " 4797 "multiple of 3!", BaseNode);
4802 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
4810 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
4812 if (!TypeSizeNode) {
4813 CheckFailed(
"Type size nodes must be constants!", &I, BaseNode);
4819 if (!IsNewFormat && !isa<MDString>(BaseNode->
getOperand(0))) {
4820 CheckFailed(
"Struct tag nodes have a string as their first operand",
4828 unsigned BitWidth = ~0u;
4832 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
4833 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
4834 for (
unsigned Idx = FirstFieldOpNo; Idx < BaseNode->
getNumOperands();
4835 Idx += NumOpsPerField) {
4838 if (!isa<MDNode>(FieldTy)) {
4839 CheckFailed(
"Incorrect field entry in struct type node!", &I, BaseNode);
4844 auto *OffsetEntryCI =
4845 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
4846 if (!OffsetEntryCI) {
4847 CheckFailed(
"Offset entries must be constants!", &I, BaseNode);
4852 if (BitWidth == ~0u)
4853 BitWidth = OffsetEntryCI->getBitWidth();
4855 if (OffsetEntryCI->getBitWidth() != BitWidth) {
4857 "Bitwidth between the offsets and struct type entries must match", &I,
4869 !PrevOffset || PrevOffset->
ule(OffsetEntryCI->getValue());
4872 CheckFailed(
"Offsets must be increasing!", &I, BaseNode);
4876 PrevOffset = OffsetEntryCI->getValue();
4879 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
4881 if (!MemberSizeNode) {
4882 CheckFailed(
"Member size entries must be constants!", &I, BaseNode);
4889 return Failed ? InvalidNode
4890 : TBAAVerifier::TBAABaseNodeSummary(
false, BitWidth);
4911 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
4912 return Parent && Visited.
insert(Parent).second &&
4916 bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
4917 auto ResultIt = TBAAScalarNodes.find(MD);
4918 if (ResultIt != TBAAScalarNodes.end())
4919 return ResultIt->second;
4923 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
4925 assert(InsertResult.second &&
"Just checked!");
4944 return cast<MDNode>(BaseNode->
getOperand(1));
4946 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
4947 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
4948 for (
unsigned Idx = FirstFieldOpNo; Idx < BaseNode->
getNumOperands();
4949 Idx += NumOpsPerField) {
4950 auto *OffsetEntryCI =
4951 mdconst::extract<ConstantInt>(BaseNode->
getOperand(Idx + 1));
4952 if (OffsetEntryCI->getValue().ugt(Offset)) {
4953 if (Idx == FirstFieldOpNo) {
4954 CheckFailed(
"Could not find TBAA parent in struct type node", &I,
4959 unsigned PrevIdx = Idx - NumOpsPerField;
4960 auto *PrevOffsetEntryCI =
4961 mdconst::extract<ConstantInt>(BaseNode->
getOperand(PrevIdx + 1));
4962 Offset -= PrevOffsetEntryCI->getValue();
4963 return cast<MDNode>(BaseNode->
getOperand(PrevIdx));
4968 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
4970 Offset -= LastOffsetEntryCI->getValue();
4971 return cast<MDNode>(BaseNode->
getOperand(LastIdx));
4988 AssertTBAA(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) ||
4989 isa<VAArgInst>(I) || isa<AtomicRMWInst>(I) ||
4990 isa<AtomicCmpXchgInst>(I),
4991 "This instruction shall not have a TBAA access tag!", &I);
4993 bool IsStructPathTBAA =
4998 "Old-style TBAA is no longer allowed, use struct-path TBAA instead", &I);
5007 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
5010 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
5015 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
5017 AssertTBAA(AccessSizeNode,
"Access size field must be a constant", &I, MD);
5021 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
5023 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
5026 "Immutability tag on struct tag metadata must be a constant",
5029 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
5030 "Immutability part of the struct tag metadata must be either 0 or 1",
5035 "Malformed struct tag metadata: base and access-type " 5036 "should be non-null and point to Metadata nodes",
5037 &I, MD, BaseNode, AccessType);
5040 AssertTBAA(isValidScalarTBAANode(AccessType),
5041 "Access type node must be a valid scalar type", &I, MD,
5045 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
5046 AssertTBAA(OffsetCI,
"Offset must be constant integer", &I, MD);
5048 APInt Offset = OffsetCI->getValue();
5049 bool SeenAccessTypeInPath =
false;
5054 BaseNode = getFieldNodeFromTBAABaseNode(I, BaseNode, Offset,
5056 if (!StructPath.
insert(BaseNode).second) {
5057 CheckFailed(
"Cycle detected in struct path", &I, MD);
5062 unsigned BaseNodeBitWidth;
5063 std::tie(Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(I, BaseNode,
5071 SeenAccessTypeInPath |= BaseNode == AccessType;
5073 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
5074 AssertTBAA(Offset == 0,
"Offset not zero at the point of scalar access",
5078 (BaseNodeBitWidth == 0 && Offset == 0) ||
5079 (IsNewFormat && BaseNodeBitWidth == ~0u),
5080 "Access bit-width not the same as description bit-width", &
I, MD,
5083 if (IsNewFormat && SeenAccessTypeInPath)
5087 AssertTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!",
5093 INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
5096 return new VerifierLegacyPass(FatalErrors);
5114 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
5122 if (res.IRBroken && FatalErrors)
bool isDeclarationForLinker() const
Metadata * getRawRetainedTypes() 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. ...
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
static bool isScope(const Metadata *MD)
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Tracking metadata reference owned by Metadata.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
static Value * getParentPad(Value *EHPad)
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
iterator_range< use_iterator > uses()
bool hasLocalLinkage() const
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
This class represents an incoming formal argument to a Function.
Base class for instruction visitors.
Value * getAggregateOperand()
unsigned arg_size() const
bool isSpeculatable() const
Determine if the call has sideeffects.
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
This represents the llvm.dbg.label instruction.
Atomic ordering constants.
Takes the max of the two values, which are required to be integers.
C - The default llvm calling convention, compatible with C.
StringRef getName() const
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
bool hasPrivateLinkage() const
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
bool isMetadataTy() const
Return true if this is 'metadata'.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
BinaryOps getOpcode() const
const APInt & getUpper() const
Return the upper value for this range.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
Type * getParamType(unsigned i) const
Parameter type accessors.
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.
Metadata * getRawGlobalVariables() const
Metadata * getRawVTableHolder() const
A Module instance is used to store all the information related to an LLVM module. ...
Metadata * getRawVariable() const
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Result run(Module &M, ModuleAnalysisManager &)
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.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
This class represents zero extension of integer types.
unsigned getNumElements() const
Random access to the elements.
Metadata * getRawFile() const
Return the raw underlying file.
This class represents a function call, abstracting a target machine's calling convention.
bool hasAvailableExternallyLinkage() const
Metadata * getRawInlinedAt() const
Value * getCondition() const
iterator_range< IterTy > args() const
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
FunctionPass * createVerifierPass(bool FatalErrors=true)
const Value * getTrueValue() const
An efficient, type-erasing, non-owning reference to a callable.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
This instruction constructs a fixed permutation of two input vectors.
LLVMContext & getContext() const
All values hold a context through their type.
DICompositeTypeArray getEnumTypes() const
bool sgt(const APInt &RHS) const
Signed greather than comparison.
const Use & getOperandUse(unsigned i) const
This class implements a map that also provides access to all stored values in a deterministic order...
bool hasDLLImportStorageClass() const
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Metadata * getRawScope() const
const fltSemantics & getSemantics() const
const MDOperand & getOperand(unsigned I) const
This class represents a sign extension of integer types.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
Manage lifetime of a slot tracker for printing IR.
bool hasExternalWeakLinkage() const
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 * getCondition() const
BasicBlock * getUnwindDest() const
bool isVectorTy() const
True if this is an instance of VectorType.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
This is the common base class for constrained floating point intrinsics.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This defines the Use class.
void reserve(size_type N)
bool isMustTailCall() const
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).
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
unsigned getBitWidth() const
Return the number of bits in the APInt.
DINodeArray getElements() const
Check a module for errors, and report separate error states for IR and debug info errors...
iterator_range< user_iterator > materialized_users()
AtomicOrdering getFailureOrdering() const
Returns the failure ordering constraint of this cmpxchg instruction.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Calling convention used for Mesa/AMDPAL pixel shaders.
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.
unsigned getAllocaAddrSpace() const
Metadata * getRawTypeArray() 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...
StringRef getName() const
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
This class represents the LLVM 'select' instruction.
FunctionType * getFunctionType() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
PointerType * getType() const
Overload to return most specific pointer type.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
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.
bool isResolved() const
Check if node is fully resolved.
DIGlobalVariable * getVariable() const
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
A Use represents the edge between a Value definition and its users.
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
DILabel * getLabel() const
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
BinOp getOperation() const
Value * getDerivedPtr() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
bool isArtificial() const
PTX_Device - Call to a PTX device function.
bool isIntegerTy() const
True if this is an instance of IntegerType.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
This file contains the simple types necessary to represent the attributes associated with functions a...
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
InstrTy * getInstruction() const
unsigned getNumHandlers() const
return the number of 'handlers' in this catchswitch instruction, except the default handler ...
static bool isNewFormatTBAATypeNode(llvm::MDNode *Type)
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
Metadata * getRawType() const
uint64_t getNumElements() const
static const unsigned MaximumAlignment
Type * getSourceElementType() const
StringRef getFilename() const
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
BasicBlock * getDestination(unsigned i)
Return the specified destination.
This file implements a class to represent arbitrary precision integral constant values and operations...
bool hasCommonLinkage() const
This class represents a cast from a pointer to an integer.
AtomicOrdering
Atomic ordering for LLVM's memory model.
static bool IsRootTBAANode(const MDNode *MD)
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.
bool hasValidDeclarationLinkage() const
void visit(Iterator Start, Iterator End)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
bool hasExternalLinkage() const
Metadata * getRawImportedEntities() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
A constant value that is initialized with an expression using other constant values.
Class to represent function types.
Type * getType() const
All values are typed, get the type of this value.
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...
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
Holds the characteristics of one fragment of a larger variable.
op_range operands() const
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
ValTy * getArgOperand(unsigned i) const
#define Assert(C,...)
We know that cond should be true, if not print an error message.
Class to represent array types.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
This instruction compares its operands according to the predicate given to the constructor.
RoundingMode getRoundingMode() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
DIMacroNodeArray getElements() const
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
This class represents a no-op cast from one type to another.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const APInt & getValue() const
Return the constant as an APInt value reference.
An instruction for storing to memory.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Metadata * getRawEntity() const
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
LinkageTypes getLinkage() const
This class represents a cast from floating point to signed integer.
unsigned getAlignment() const
Value * getParentPad() const
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeList getAttributes() const
Return the parameter attributes for this call.
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...
amdgpu Simplify well known AMD library false Value * Callee
This class represents a truncation of integer types.
Value * getOperand(unsigned i) const
Class to represent pointers.
Metadata * getRawFile() const
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
bool isCall() const
Return true if a CallInst is enclosed.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool hasAppendingLinkage() const
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Value * getOperand(unsigned i_nocapture) const
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
StringRef getString() const
Metadata * getRawExpression() const
DIMacroNodeArray getMacros() const
bool isVoidTy() const
Return true if this is 'void'.
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
ExceptionBehavior getExceptionBehavior() const
static bool runOnFunction(Function &F, bool PostInlining)
Type * getReturnType() const
Returns the type of the ret val.
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
Returns the module flags in the provided vector.
This instruction inserts a single (scalar) element into a VectorType value.
StringRef getName() const
unsigned getColumn() const
static bool isIntPredicate(Predicate P)
bool isLabelTy() const
Return true if this is 'label'.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
Metadata * getRawDiscriminator() const
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
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.
DISubprogram * getSubprogram() const
Get the attached subprogram.
Conditional or Unconditional Branch instruction.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Resume the propagation of an exception.
CountType getCount() const
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...
bool isPointerTy() const
True if this is an instance of PointerType.
const Instruction & front() const
Indirect Branch Instruction.
void print(raw_ostream &ROS, bool IsForDebug=false) const
Base class for template parameters.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
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...
DIExpression * getExpression() const
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
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)
DILocalVariable * getVariable() const
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...
DIImportedEntityArray getImportedEntities() const
This instruction compares its operands according to the predicate given to the constructor.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Interval::pred_iterator pred_end(Interval *I)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Base class for variables.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
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)
const Function * getFunction() const
Return the function this instruction belongs to.
This class represents a cast from an integer to a pointer.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
static DISubprogram * getSubprogram(Metadata *LocalScope)
Carefully grab the subprogram from a local scope.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
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.
unsigned getNumArgOperands() const
const Value * getArraySize() const
Get the number of elements allocated.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
Metadata * getRawType() const
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.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
An imported module (C++ using directive or similar).
Base class for scope-like contexts.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Value * getParentPad() const
Convenience accessors.
void sort(IteratorTy Start, IteratorTy End)
Metadata * getRawElements() const
bool isEmptySet() const
Return true if this set contains no members.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
BasicBlock * getNormalDest() const
Metadata * getRawScope() const
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
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.
unsigned getNumOperands() const
std::string getAsString(bool InAttrGrp=false) const
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
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)
VerifierSupport(raw_ostream *OS, const Module &M)
Metadata * getRawTemplateParams() const
ValTy * getArgument(unsigned ArgNo) const
OperandBundleUse getOperandBundleAt(unsigned Index) const
static Optional< DebugEmissionKind > getEmissionKind(StringRef Str)
testing::Matcher< const detail::ErrorHolder & > Failed()
Optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
bool isFiniteNonZero() const
static bool isDINode(const Metadata *MD)
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs(unsigned Index) const
Get the allocsize argument numbers (or pair(0, 0) if unknown).
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...
This class represents a range of values.
This is the common base class for debug info intrinsics.
BasicBlock * getUnwindDest() const
Type * getReturnType() const
MDNode * getAsMDNode() const
Return this as a bar MDNode.
This class represents a cast from floating point to unsigned integer.
LLVM_NODISCARD T pop_back_val()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
bool isConditional() const
pred_range predecessors(BasicBlock *BB)
bool hasGlobalUnnamedAddr() const
Metadata * getRawElements() const
Metadata * getRawFile() const
static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs)
BBTy * getParent() const
Get the basic block containing the call site.
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.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
unsigned getVectorNumElements() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Class to represent vector types.
This file contains constants used for implementing Dwarf debug support.
Target - Wrapper for Target specific information.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
unsigned getNumAttrSets() const
Calling convention used for Mesa/AMDPAL compute shaders.
Metadata * getRawFile() const
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
A (clang) module that has been imported by the compile unit.
StringRef getName() const
static bool isFPPredicate(Predicate P)
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
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.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
Calling convention for AMDGPU code object kernels.
InstListType::iterator iterator
Instruction iterators...
DIGlobalVariableExpressionArray getGlobalVariables() const
Generic tagged DWARF-like metadata node.
iterator insert(iterator I, T &&Elt)
Metadata * getRawFile() const
bool isNonIntegralPointerType(PointerType *PT) const
bool doesNotAccessMemory() const
Determine if the call does not access memory.
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
amdgpu Simplify well known AMD library false Value Value * Arg
Metadata * getRawBaseType() const
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Type array for a subprogram.
unsigned countOperandBundlesOfType(uint32_t ID) const
Calling convention used for Mesa/AMDPAL geometry shaders.
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
FunTy * getCaller() const
Return the caller function for this call site.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
unsigned getNumOperandBundles() const
Metadata * getRawEnumTypes() const
bool isInlineAsm() const
Check if this call is an inline asm statement.
Appends the two values, which are required to be metadata nodes.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
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...
LLVM_NODISCARD bool empty() const
unsigned getNumArgOperands() const
Return the number of call arguments.
bool BrokenDebugInfo
Broken debug info can be "recovered" from by stripping the debug info.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
Metadata * getRawScope() const
bool isTokenTy() const
Return true if this is 'token'.
verify safepoint Safepoint IR Verifier
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'. ...
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
const Function * getParent() const
Return the enclosing method, or null if none.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
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...
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs)
A check failed (with values to print).
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs)
A debug info check failed (with values to print).
const APInt & getLower() const
Return the lower value for this range.
Value * getValue() const
Convenience accessor.
Metadata * getRawVariable() const
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
void initializeVerifierLegacyPassPass(PassRegistry &)
This class represents a cast unsigned integer to floating point.
Type * getResultElementType() const
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
unsigned getMacinfoType() const
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
StringRef getValue() const
PTX_Kernel - Call to a PTX kernel.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
void DebugInfoCheckFailed(const Twine &Message)
A debug info check failed.
Type * getType() const
Return the type of the instruction that generated this call site.
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...
Metadata * getRawStaticDataMemberDeclaration() const
DIScopeArray getRetainedTypes() const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool isStatepoint(ImmutableCallSite CS)
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
static bool IsScalarTBAANodeImpl(const MDNode *MD, SmallPtrSetImpl< const MDNode *> &Visited)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Synchronized with respect to all concurrently executing threads.
DITypeRef getType() const
This class represents a cast from signed integer to floating point.
DILocalScope * getScope() const
Get the local scope for this label.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster. ...
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
bool hasAttributes() const
Return true if attributes exists in this set.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
bool isEHPad() const
Return true if this basic block is an exception handling block.
This class represents a truncation of floating point types.
BasicBlock * getUnwindDest() const
Represents calls to the gc.relocate intrinsic.
ArrayRef< unsigned > getIndices() const
Module * getParent()
Get the module that this global value is contained inside of...
Verify that the TBAA Metadatas are valid.
LLVM Value Representation.
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
bool hasInitializer() const
Definitions have initializers, declarations don't.
Metadata * getRawMacros() const
FunctionType * getFunctionType() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Metadata * getRawScope() const
static bool hasConflictingReferenceFlags(unsigned Flags)
Detect mutually exclusive flags.
bool TreatBrokenDebugInfoAsError
Whether to treat broken debug info as an error.
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
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.
AttributeSet getFnAttributes() const
The function attributes are returned.
DITypeRefArray getTypeArray() const
This class implements an extremely fast bulk output stream that can only output to a stream...
bool hasDefaultVisibility() const
Metadata * getRawScope() const
bool Broken
Track the brokenness of the module while recursively visiting.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
static bool isContiguous(const ConstantRange &A, const ConstantRange &B)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
AttributeList getAttributes() const
Get the parameter attributes of the call.
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
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...
Metadata * getRawType() const
Metadata * getRawScope() const
This header defines various interfaces for pass management in LLVM.
DILocalScope * getScope() const
Get the local scope for this variable.
unsigned getNumOperands() const
Return number of MDNode operands.
op_range incoming_values()
This class represents an extension of floating point types.
bool isEmpty() const
Return true if there are no attributes.
A bitmask that includes all valid flags.
#define AssertTBAA(C,...)
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
A special type used by analysis passes to provide an address that identifies that particular analysis...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
PointerType * getType() const
Global values are always pointers.
Metadata * getRawScope() const
bool empty() const
empty - Check if the array is empty.
bool isArrayTy() const
True if this is an instance of ArrayType.
StringRef getName() const
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
const BasicBlock * getParent() const
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)
Basic type, like 'int' or 'float'.
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...
const Constant * getAliasee() const