64 "Allow incomplete IR on a best effort basis (references to unknown "
65 "metadata will be dropped)"));
80 if (Context.shouldDiscardValueNames())
83 "Can't read textual IR with a Context that discards named Values");
86 if (parseTargetDefinitions(DataLayoutCallback))
90 return parseTopLevelEntities() || validateEndOfModule(UpgradeDebugInfo) ||
96 restoreParsingState(Slots);
100 if (parseType(Ty) || parseConstantValue(Ty,
C))
103 return error(Lex.getLoc(),
"expected end of string");
109 restoreParsingState(Slots);
113 SMLoc Start = Lex.getLoc();
117 SMLoc End = Lex.getLoc();
125 restoreParsingState(Slots);
129 SMLoc Start = Lex.getLoc();
131 bool Status = parseDIExpressionBody(Result,
false);
132 SMLoc End = Lex.getLoc();
138void LLParser::restoreParsingState(
const SlotMapping *Slots) {
145 std::make_pair(
I.getKey(), std::make_pair(
I.second,
LocTy())));
146 for (
const auto &
I : Slots->
Types)
147 NumberedTypes.insert(
148 std::make_pair(
I.first, std::make_pair(
I.second,
LocTy())));
154 II->getIntrinsicID() != Intrinsic::experimental_noalias_scope_decl)
161 if (MD->isTemporary())
165 assert(
II->use_empty() &&
"Cannot have uses");
166 II->eraseFromParent();
175void LLParser::dropUnknownMetadataReferences() {
176 auto Pred = [](
unsigned MDKind, MDNode *
Node) {
return Node->isTemporary(); };
177 for (Function &
F : *M) {
178 F.eraseMetadataIf(Pred);
180 I.eraseMetadataIf(Pred);
187 for (GlobalVariable &GV : M->globals())
188 GV.eraseMetadataIf(Pred);
193 if (
Info.first->getNumTemporaryUses() == 1) {
194 NumberedMetadata.erase(
ID);
195 ForwardRefMDNodes.erase(
ID);
208 assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
209 "Mixed debug intrinsics/records seen without a parsing error?");
212 for (
const auto &RAG : ForwardRefAttrGroups) {
214 const std::vector<unsigned> &
Attrs = RAG.second;
215 AttrBuilder
B(Context);
217 for (
const auto &Attr : Attrs) {
218 auto R = NumberedAttrBuilders.find(Attr);
219 if (R != NumberedAttrBuilders.end())
224 AttributeList AS = Fn->getAttributes();
225 AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
226 AS = AS.removeFnAttributes(Context);
232 if (MaybeAlign
A = FnAttrs.getAlignment()) {
233 Fn->setAlignment(*
A);
234 FnAttrs.removeAttribute(Attribute::Alignment);
237 AS = AS.addFnAttributes(Context, FnAttrs);
238 Fn->setAttributes(AS);
240 AttributeList AS = CI->getAttributes();
241 AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
242 AS = AS.removeFnAttributes(Context);
244 AS = AS.addFnAttributes(Context, FnAttrs);
245 CI->setAttributes(AS);
247 AttributeList AS =
II->getAttributes();
248 AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
249 AS = AS.removeFnAttributes(Context);
251 AS = AS.addFnAttributes(Context, FnAttrs);
252 II->setAttributes(AS);
254 AttributeList AS = CBI->getAttributes();
255 AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
256 AS = AS.removeFnAttributes(Context);
258 AS = AS.addFnAttributes(Context, FnAttrs);
259 CBI->setAttributes(AS);
261 AttrBuilder
Attrs(M->getContext(), GV->getAttributes());
271 if (!ForwardRefBlockAddresses.empty())
272 return error(ForwardRefBlockAddresses.begin()->first.Loc,
273 "expected function name in blockaddress");
275 auto ResolveForwardRefDSOLocalEquivalents = [&](
const ValID &GVRef,
276 GlobalValue *FwdRef) {
277 GlobalValue *GV =
nullptr;
279 GV = M->getNamedValue(GVRef.
StrVal);
281 GV = NumberedVals.get(GVRef.
UIntVal);
286 "' referenced by dso_local_equivalent");
290 "expected a function, alias to function, or ifunc "
291 "in dso_local_equivalent");
294 FwdRef->replaceAllUsesWith(Equiv);
295 FwdRef->eraseFromParent();
302 for (
auto &Iter : ForwardRefDSOLocalEquivalentIDs) {
303 if (ResolveForwardRefDSOLocalEquivalents(Iter.first, Iter.second))
306 for (
auto &Iter : ForwardRefDSOLocalEquivalentNames) {
307 if (ResolveForwardRefDSOLocalEquivalents(Iter.first, Iter.second))
310 ForwardRefDSOLocalEquivalentIDs.clear();
311 ForwardRefDSOLocalEquivalentNames.clear();
313 for (
const auto &NT : NumberedTypes)
314 if (
NT.second.second.isValid())
316 "use of undefined type '%" + Twine(
NT.first) +
"'");
318 for (
const auto &[Name, TypeInfo] : NamedTypes)
319 if (TypeInfo.second.isValid())
320 return error(TypeInfo.second,
321 "use of undefined type named '" + Name +
"'");
323 if (!ForwardRefComdats.empty())
324 return error(ForwardRefComdats.begin()->second,
325 "use of undefined comdat '$" +
326 ForwardRefComdats.begin()->first +
"'");
340 if (!CB || !CB->isCallee(&U))
341 return error(
Info.second,
"intrinsic can only be used as callee");
355 return error(
Info.second,
"unknown intrinsic '" + Name +
"'");
356 return error(
Info.second,
"invalid intrinsic signature");
366 Info.first->eraseFromParent();
367 ForwardRefVals.erase(Name);
376 auto GetCommonFunctionType = [](
Value *
V) -> FunctionType * {
377 FunctionType *FTy =
nullptr;
378 for (Use &U :
V->uses()) {
380 if (!CB || !CB->isCallee(&U) || (FTy && FTy != CB->getFunctionType()))
382 FTy = CB->getFunctionType();
390 Type *Ty = GetCommonFunctionType(
Info.first);
398 GV =
new GlobalVariable(*M, Ty,
false,
401 Info.first->replaceAllUsesWith(GV);
402 Info.first->eraseFromParent();
403 ForwardRefVals.erase(Name);
406 if (!ForwardRefVals.empty())
407 return error(ForwardRefVals.begin()->second.second,
408 "use of undefined value '@" + ForwardRefVals.begin()->first +
411 if (!ForwardRefValIDs.empty())
412 return error(ForwardRefValIDs.begin()->second.second,
413 "use of undefined value '@" +
414 Twine(ForwardRefValIDs.begin()->first) +
"'");
417 dropUnknownMetadataReferences();
419 if (!ForwardRefMDNodes.empty())
420 return error(ForwardRefMDNodes.begin()->second.second,
421 "use of undefined metadata '!" +
422 Twine(ForwardRefMDNodes.begin()->first) +
"'");
425 for (
auto &
N : NumberedMetadata) {
426 if (
N.second && !
N.second->isResolved())
427 N.second->resolveCycles();
430 for (
auto *Inst : InstsWithTBAATag) {
431 MDNode *MD = Inst->getMetadata(LLVMContext::MD_tbaa);
434 assert(MD &&
"UpgradeInstWithTBAATag should have a TBAA tag");
437 if (MD != UpgradedMD)
438 Inst->setMetadata(LLVMContext::MD_tbaa, UpgradedMD);
447 if (UpgradeDebugInfo)
460 Slots->GlobalValues = std::move(NumberedVals);
461 Slots->MetadataNodes = std::move(NumberedMetadata);
462 for (
const auto &
I : NamedTypes)
463 Slots->NamedTypes.insert(std::make_pair(
I.getKey(),
I.second.first));
464 for (
const auto &
I : NumberedTypes)
465 Slots->Types.insert(std::make_pair(
I.first,
I.second.first));
471bool LLParser::validateEndOfIndex() {
475 if (!ForwardRefValueInfos.empty())
476 return error(ForwardRefValueInfos.begin()->second.front().second,
477 "use of undefined summary '^" +
478 Twine(ForwardRefValueInfos.begin()->first) +
"'");
480 if (!ForwardRefAliasees.empty())
481 return error(ForwardRefAliasees.begin()->second.front().second,
482 "use of undefined summary '^" +
483 Twine(ForwardRefAliasees.begin()->first) +
"'");
485 if (!ForwardRefTypeIds.empty())
486 return error(ForwardRefTypeIds.begin()->second.front().second,
487 "use of undefined type id summary '^" +
488 Twine(ForwardRefTypeIds.begin()->first) +
"'");
502 std::string TentativeDLStr = M->getDataLayoutStr();
507 switch (Lex.getKind()) {
509 if (parseTargetDefinition(TentativeDLStr, DLStrLoc))
513 if (parseSourceFileName())
522 if (
auto LayoutOverride =
523 DataLayoutCallback(M->getTargetTriple().str(), TentativeDLStr)) {
524 TentativeDLStr = *LayoutOverride;
530 M->setDataLayout(MaybeDL.
get());
534bool LLParser::parseTopLevelEntities() {
538 switch (Lex.getKind()) {
542 if (parseSummaryEntry())
546 if (parseSourceFileName())
556 switch (Lex.getKind()) {
558 return tokError(
"expected top-level entity");
569 if (parseModuleAsm())
573 if (parseUnnamedType())
577 if (parseNamedType())
581 if (parseUnnamedGlobal())
585 if (parseNamedGlobal())
590 if (parseStandaloneMetadata())
594 if (parseSummaryEntry())
598 if (parseNamedMetadata())
602 if (parseUnnamedAttrGrp())
606 if (parseUseListOrder())
610 if (parseUseListOrderBB())
619bool LLParser::parseModuleAsm() {
625 parseStringConstant(AsmStr))
628 M->appendModuleInlineAsm(AsmStr);
635bool LLParser::parseTargetDefinition(std::string &TentativeDLStr,
641 return tokError(
"unknown target property");
644 if (parseToken(
lltok::equal,
"expected '=' after target triple") ||
645 parseStringConstant(Str))
647 M->setTargetTriple(Triple(std::move(Str)));
651 if (parseToken(
lltok::equal,
"expected '=' after target datalayout"))
653 DLStrLoc = Lex.getLoc();
654 if (parseStringConstant(TentativeDLStr))
662bool LLParser::parseSourceFileName() {
665 if (parseToken(
lltok::equal,
"expected '=' after source_filename") ||
666 parseStringConstant(SourceFileName))
669 M->setSourceFileName(SourceFileName);
675bool LLParser::parseUnnamedType() {
676 LocTy TypeLoc = Lex.getLoc();
677 unsigned TypeID = Lex.getUIntVal();
680 if (parseToken(
lltok::equal,
"expected '=' after name") ||
685 if (parseStructDefinition(TypeLoc,
"", NumberedTypes[
TypeID], Result))
689 std::pair<Type*, LocTy> &
Entry = NumberedTypes[
TypeID];
691 return error(TypeLoc,
"non-struct types may not be recursive");
693 Entry.second = SMLoc();
701bool LLParser::parseNamedType() {
702 std::string
Name = Lex.getStrVal();
703 LocTy NameLoc = Lex.getLoc();
706 if (parseToken(
lltok::equal,
"expected '=' after name") ||
711 if (parseStructDefinition(NameLoc, Name, NamedTypes[Name], Result))
715 std::pair<Type*, LocTy> &
Entry = NamedTypes[
Name];
717 return error(NameLoc,
"non-struct types may not be recursive");
719 Entry.second = SMLoc();
727bool LLParser::parseDeclare() {
731 std::vector<std::pair<unsigned, MDNode *>> MDs;
735 if (parseMetadataAttachment(MDK,
N))
737 MDs.push_back({MDK,
N});
741 unsigned FunctionNumber = -1;
742 SmallVector<unsigned> UnnamedArgNums;
743 if (parseFunctionHeader(
F,
false, FunctionNumber, UnnamedArgNums))
746 F->addMetadata(MD.first, *MD.second);
752bool LLParser::parseDefine() {
754 FileLoc FunctionStart(Lex.getTokLineColumnPos());
758 unsigned FunctionNumber = -1;
759 SmallVector<unsigned> UnnamedArgNums;
761 parseFunctionHeader(
F,
true, FunctionNumber, UnnamedArgNums) ||
762 parseOptionalFunctionMetadata(*
F) ||
763 parseFunctionBody(*
F, FunctionNumber, UnnamedArgNums);
765 ParserContext->addFunctionLocation(
766 F, FileLocRange(FunctionStart, Lex.getPrevTokEndLineColumnPos()));
774bool LLParser::parseGlobalType(
bool &IsConstant) {
781 return tokError(
"expected 'global' or 'constant'");
787bool LLParser::parseOptionalUnnamedAddr(
808bool LLParser::parseUnnamedGlobal() {
811 LocTy NameLoc = Lex.getLoc();
815 VarID = Lex.getUIntVal();
816 if (checkValueID(NameLoc,
"global",
"@", NumberedVals.getNext(),
VarID))
820 if (parseToken(
lltok::equal,
"expected '=' after name"))
823 VarID = NumberedVals.getNext();
827 unsigned Linkage, Visibility, DLLStorageClass;
831 if (parseOptionalLinkage(
Linkage, HasLinkage, Visibility, DLLStorageClass,
833 parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
836 switch (Lex.getKind()) {
838 return parseGlobal(Name,
VarID, NameLoc,
Linkage, HasLinkage, Visibility,
839 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
842 return parseAliasOrIFunc(Name,
VarID, NameLoc,
Linkage, Visibility,
843 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
852bool LLParser::parseNamedGlobal() {
854 LocTy NameLoc = Lex.getLoc();
855 std::string
Name = Lex.getStrVal();
859 unsigned Linkage, Visibility, DLLStorageClass;
863 if (parseToken(
lltok::equal,
"expected '=' in global variable") ||
864 parseOptionalLinkage(
Linkage, HasLinkage, Visibility, DLLStorageClass,
866 parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
869 switch (Lex.getKind()) {
871 return parseGlobal(Name, -1, NameLoc,
Linkage, HasLinkage, Visibility,
872 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
875 return parseAliasOrIFunc(Name, -1, NameLoc,
Linkage, Visibility,
876 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
880bool LLParser::parseComdat() {
882 std::string
Name = Lex.getStrVal();
883 LocTy NameLoc = Lex.getLoc();
890 return tokError(
"expected comdat type");
893 switch (Lex.getKind()) {
895 return tokError(
"unknown selection kind");
917 if (
I != ComdatSymTab.
end() && !ForwardRefComdats.erase(Name))
918 return error(NameLoc,
"redefinition of comdat '$" + Name +
"'");
921 if (
I != ComdatSymTab.
end())
924 C = M->getOrInsertComdat(Name);
925 C->setSelectionKind(SK);
932bool LLParser::parseMDString(
MDString *&Result) {
934 if (parseStringConstant(Str))
942bool LLParser::parseMDNodeID(
MDNode *&Result) {
944 LocTy IDLoc = Lex.getLoc();
946 if (parseUInt32(MID))
950 auto [It,
Inserted] = NumberedMetadata.try_emplace(MID);
957 auto &FwdRef = ForwardRefMDNodes[MID];
960 Result = FwdRef.first.get();
961 It->second.reset(Result);
967bool LLParser::parseNamedMetadata() {
969 std::string
Name = Lex.getStrVal();
977 NamedMDNode *NMD = M->getOrInsertNamedMetadata(Name);
985 Lex.getStrVal() ==
"DIExpression") {
986 if (parseDIExpression(
N,
false))
991 Lex.getStrVal() ==
"DIArgList") {
992 return tokError(
"found DIArgList outside of function");
1000 return parseToken(
lltok::rbrace,
"expected end of metadata node");
1005bool LLParser::parseStandaloneMetadata() {
1008 unsigned MetadataID = 0;
1011 if (parseUInt32(MetadataID) || parseToken(
lltok::equal,
"expected '=' here"))
1016 return tokError(
"unexpected type in metadata definition");
1020 if (parseSpecializedMDNode(Init, IsDistinct))
1023 parseMDTuple(Init, IsDistinct))
1027 auto FI = ForwardRefMDNodes.find(MetadataID);
1028 if (FI != ForwardRefMDNodes.end()) {
1029 auto *ToReplace = FI->second.first.get();
1033 for (
auto *Inst : TempDIAssignIDAttachments[ToReplace]) {
1034 assert(!Inst->getMetadata(LLVMContext::MD_DIAssignID) &&
1035 "Inst unexpectedly already has DIAssignID attachment");
1036 Inst->setMetadata(LLVMContext::MD_DIAssignID, Init);
1040 ToReplace->replaceAllUsesWith(Init);
1041 ForwardRefMDNodes.erase(FI);
1043 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
1045 auto [It,
Inserted] = NumberedMetadata.try_emplace(MetadataID);
1047 return tokError(
"Metadata id is already used");
1048 It->second.reset(Init);
1055bool LLParser::skipModuleSummaryEntry() {
1065 "Expected 'gv', 'module', 'typeid', 'flags' or 'blockcount' at the "
1066 "start of summary entry");
1068 return parseSummaryIndexFlags();
1070 return parseBlockCount();
1072 if (parseToken(
lltok::colon,
"expected ':' at start of summary entry") ||
1073 parseToken(
lltok::lparen,
"expected '(' at start of summary entry"))
1077 unsigned NumOpenParen = 1;
1079 switch (Lex.getKind()) {
1087 return tokError(
"found end of file while parsing summary entry");
1093 }
while (NumOpenParen > 0);
1099bool LLParser::parseSummaryEntry() {
1105 Lex.setIgnoreColonInIdentifiers(
true);
1113 return skipModuleSummaryEntry();
1115 bool result =
false;
1116 switch (Lex.getKind()) {
1118 result = parseGVEntry(SummaryID);
1121 result = parseModuleEntry(SummaryID);
1124 result = parseTypeIdEntry(SummaryID);
1127 result = parseTypeIdCompatibleVtableEntry(SummaryID);
1130 result = parseSummaryIndexFlags();
1133 result = parseBlockCount();
1136 result =
error(Lex.getLoc(),
"unexpected summary kind");
1139 Lex.setIgnoreColonInIdentifiers(
false);
1173bool LLParser::parseAliasOrIFunc(
const std::string &Name,
unsigned NameID,
1174 LocTy NameLoc,
unsigned L,
unsigned Visibility,
1175 unsigned DLLStorageClass,
bool DSOLocal,
1190 return error(NameLoc,
"invalid linkage type for alias");
1193 return error(NameLoc,
1194 "symbol with local linkage must have default visibility");
1197 return error(NameLoc,
1198 "symbol with local linkage cannot have a DLL storage class");
1201 LocTy ExplicitTypeLoc = Lex.getLoc();
1202 if (parseType(Ty) ||
1203 parseToken(
lltok::comma,
"expected comma after alias or ifunc's type"))
1207 LocTy AliaseeLoc = Lex.getLoc();
1212 if (parseGlobalTypeAndValue(Aliasee))
1217 if (parseValID(
ID,
nullptr))
1220 return error(AliaseeLoc,
"invalid aliasee");
1221 Aliasee =
ID.ConstantVal;
1227 return error(AliaseeLoc,
"An alias or ifunc must have pointer type");
1228 unsigned AddrSpace = PTy->getAddressSpace();
1230 GlobalValue *GVal =
nullptr;
1234 if (!
Name.empty()) {
1235 auto I = ForwardRefVals.find(Name);
1236 if (
I != ForwardRefVals.end()) {
1237 GVal =
I->second.first;
1238 ForwardRefVals.erase(Name);
1239 }
else if (M->getNamedValue(Name)) {
1240 return error(NameLoc,
"redefinition of global '@" + Name +
"'");
1243 auto I = ForwardRefValIDs.find(NameID);
1244 if (
I != ForwardRefValIDs.end()) {
1245 GVal =
I->second.first;
1246 ForwardRefValIDs.erase(
I);
1251 std::unique_ptr<GlobalAlias> GA;
1252 std::unique_ptr<GlobalIFunc> GI;
1280 if (parseGlobalObjectMetadataAttachment(*GI))
1283 return tokError(
"unknown alias or ifunc property!");
1288 NumberedVals.add(NameID, GV);
1295 "forward reference and definition of alias have different types");
1305 M->insertAlias(GA.release());
1307 M->insertIFunc(GI.release());
1308 assert(GV->
getName() == Name &&
"Should not be a name conflict!");
1317 case lltok::kw_sanitize_memtag:
1331 switch (Lex.getKind()) {
1333 Meta.NoAddress =
true;
1336 Meta.NoHWAddress =
true;
1338 case lltok::kw_sanitize_memtag:
1342 Meta.IsDynInit =
true;
1345 return tokError(
"non-sanitizer token passed to LLParser::parseSanitizer()");
1365bool LLParser::parseGlobal(
const std::string &Name,
unsigned NameID,
1366 LocTy NameLoc,
unsigned Linkage,
bool HasLinkage,
1367 unsigned Visibility,
unsigned DLLStorageClass,
1371 return error(NameLoc,
1372 "symbol with local linkage must have default visibility");
1375 return error(NameLoc,
1376 "symbol with local linkage cannot have a DLL storage class");
1380 LocTy IsExternallyInitializedLoc;
1384 if (parseOptionalAddrSpace(AddrSpace) ||
1386 IsExternallyInitialized,
1387 &IsExternallyInitializedLoc) ||
1388 parseGlobalType(IsConstant) || parseType(Ty, TyLoc))
1397 if (parseGlobalValue(Ty, Init))
1402 return error(TyLoc,
"invalid type for global variable");
1404 GlobalValue *GVal =
nullptr;
1407 if (!
Name.empty()) {
1408 auto I = ForwardRefVals.find(Name);
1409 if (
I != ForwardRefVals.end()) {
1410 GVal =
I->second.first;
1411 ForwardRefVals.erase(
I);
1412 }
else if (M->getNamedValue(Name)) {
1413 return error(NameLoc,
"redefinition of global '@" + Name +
"'");
1418 if (NameID == (
unsigned)-1)
1419 NameID = NumberedVals.getNext();
1421 auto I = ForwardRefValIDs.find(NameID);
1422 if (
I != ForwardRefValIDs.end()) {
1423 GVal =
I->second.first;
1424 ForwardRefValIDs.erase(
I);
1428 GlobalVariable *GV =
new GlobalVariable(
1433 NumberedVals.add(NameID, GV);
1451 "forward reference and definition of global have different types");
1471 }
else if (Lex.getKind() == lltok::kw_align) {
1472 MaybeAlign Alignment;
1473 if (parseOptionalAlignment(Alignment))
1479 if (parseOptionalCodeModel(CodeModel))
1483 if (parseGlobalObjectMetadataAttachment(*GV))
1486 if (parseSanitizer(GV))
1490 if (parseOptionalComdat(Name,
C))
1495 return tokError(
"unknown global variable property!");
1499 AttrBuilder
Attrs(M->getContext());
1501 std::vector<unsigned> FwdRefAttrGrps;
1502 if (parseFnAttributeValuePairs(Attrs, FwdRefAttrGrps,
false, BuiltinLoc))
1504 if (
Attrs.hasAttributes() || !FwdRefAttrGrps.empty()) {
1506 ForwardRefAttrGroups[GV] = FwdRefAttrGrps;
1514bool LLParser::parseUnnamedAttrGrp() {
1516 LocTy AttrGrpLoc = Lex.getLoc();
1520 return tokError(
"expected attribute group id");
1522 unsigned VarID = Lex.getUIntVal();
1523 std::vector<unsigned> unused;
1531 auto R = NumberedAttrBuilders.find(
VarID);
1532 if (R == NumberedAttrBuilders.end())
1533 R = NumberedAttrBuilders.emplace(
VarID, AttrBuilder(M->getContext())).first;
1535 if (parseFnAttributeValuePairs(
R->second, unused,
true, BuiltinLoc) ||
1536 parseToken(
lltok::rbrace,
"expected end of attribute group"))
1539 if (!
R->second.hasAttributes())
1540 return error(AttrGrpLoc,
"attribute group has no attributes");
1547#define GET_ATTR_NAMES
1548#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
1549 case lltok::kw_##DISPLAY_NAME: \
1550 return Attribute::ENUM_NAME;
1551#include "llvm/IR/Attributes.inc"
1560 return parseRequiredTypeAttr(
B, Lex.getKind(), Attr);
1563 case Attribute::Alignment: {
1564 MaybeAlign Alignment;
1572 if (parseOptionalAlignment(Alignment,
true))
1575 B.addAlignmentAttr(Alignment);
1578 case Attribute::StackAlignment: {
1583 parseUInt32(Alignment))
1586 if (parseOptionalStackAlignment(Alignment))
1589 B.addStackAlignmentAttr(Alignment);
1592 case Attribute::AllocSize: {
1593 unsigned ElemSizeArg;
1594 std::optional<unsigned> NumElemsArg;
1595 if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg))
1597 B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1600 case Attribute::VScaleRange: {
1601 unsigned MinValue, MaxValue;
1602 if (parseVScaleRangeArguments(MinValue, MaxValue))
1604 B.addVScaleRangeAttr(MinValue,
1605 MaxValue > 0 ? MaxValue : std::optional<unsigned>());
1608 case Attribute::Dereferenceable: {
1610 if (parseOptionalDerefAttrBytes(lltok::kw_dereferenceable, Bytes))
1612 B.addDereferenceableAttr(Bytes);
1615 case Attribute::DereferenceableOrNull: {
1617 if (parseOptionalDerefAttrBytes(lltok::kw_dereferenceable_or_null, Bytes))
1619 B.addDereferenceableOrNullAttr(Bytes);
1622 case Attribute::UWTable: {
1624 if (parseOptionalUWTableKind(Kind))
1626 B.addUWTableAttr(Kind);
1629 case Attribute::AllocKind: {
1631 if (parseAllocKind(Kind))
1633 B.addAllocKindAttr(Kind);
1636 case Attribute::Memory: {
1637 std::optional<MemoryEffects> ME = parseMemoryAttr();
1640 B.addMemoryAttr(*ME);
1643 case Attribute::NoFPClass: {
1646 B.addNoFPClassAttr(NoFPClass);
1652 case Attribute::Range:
1653 return parseRangeAttr(
B);
1654 case Attribute::Initializes:
1655 return parseInitializesAttr(
B);
1656 case Attribute::Captures:
1657 return parseCapturesAttr(
B);
1659 B.addAttribute(Attr);
1667 case lltok::kw_readnone:
1670 case lltok::kw_readonly:
1673 case lltok::kw_writeonly:
1692bool LLParser::parseFnAttributeValuePairs(AttrBuilder &
B,
1693 std::vector<unsigned> &FwdRefAttrGrps,
1694 bool InAttrGrp, LocTy &BuiltinLoc) {
1695 bool HaveError =
false;
1706 if (parseStringAttribute(
B))
1718 "cannot have an attribute group reference in an attribute group");
1721 FwdRefAttrGrps.push_back(Lex.getUIntVal());
1727 SMLoc Loc = Lex.getLoc();
1728 if (Token == lltok::kw_builtin)
1740 return error(Lex.getLoc(),
"unterminated attribute group");
1743 if (parseEnumAttribute(Attr,
B, InAttrGrp))
1750 HaveError |=
error(Loc,
"this attribute does not apply to functions");
1754 B.addMemoryAttr(ME);
1768 PTy->getAddressSpace());
1777 error(Loc,
"'" + Name +
"' is not a basic block");
1779 error(Loc,
"'" + Name +
"' defined with type '" +
1792 error(Loc,
"global variable reference must have pointer type");
1803 auto I = ForwardRefVals.find(Name);
1804 if (
I != ForwardRefVals.end())
1805 Val =
I->second.first;
1811 checkValidVariableType(Loc,
"@" + Name, Ty, Val));
1815 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1822 error(Loc,
"global variable reference must have pointer type");
1826 GlobalValue *Val = NumberedVals.get(
ID);
1831 auto I = ForwardRefValIDs.find(
ID);
1832 if (
I != ForwardRefValIDs.end())
1833 Val =
I->second.first;
1839 checkValidVariableType(Loc,
"@" + Twine(
ID), Ty, Val));
1843 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1851Comdat *LLParser::getComdat(
const std::string &Name, LocTy
Loc) {
1855 if (
I != ComdatSymTab.
end())
1859 Comdat *
C = M->getOrInsertComdat(Name);
1860 ForwardRefComdats[
Name] = Loc;
1870bool LLParser::parseToken(
lltok::Kind T,
const char *ErrMsg) {
1871 if (Lex.getKind() !=
T)
1872 return tokError(ErrMsg);
1879bool LLParser::parseStringConstant(std::string &Result) {
1881 return tokError(
"expected string constant");
1882 Result = Lex.getStrVal();
1889bool LLParser::parseUInt32(uint32_t &Val) {
1890 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
1891 return tokError(
"expected integer");
1892 uint64_t Val64 = Lex.getAPSIntVal().getLimitedValue(0xFFFFFFFFULL+1);
1893 if (Val64 !=
unsigned(Val64))
1894 return tokError(
"expected 32-bit integer (too large)");
1902bool LLParser::parseUInt64(uint64_t &Val) {
1903 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
1904 return tokError(
"expected integer");
1905 Val = Lex.getAPSIntVal().getLimitedValue();
1915 switch (Lex.getKind()) {
1917 return tokError(
"expected localdynamic, initialexec or localexec");
1945 return parseTLSModel(TLM) ||
1946 parseToken(
lltok::rparen,
"expected ')' after thread local model");
1954bool LLParser::parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS) {
1955 AddrSpace = DefaultAS;
1959 auto ParseAddrspaceValue = [&](
unsigned &AddrSpace) ->
bool {
1961 auto AddrSpaceStr = Lex.getStrVal();
1962 if (AddrSpaceStr ==
"A") {
1963 AddrSpace = M->getDataLayout().getAllocaAddrSpace();
1964 }
else if (AddrSpaceStr ==
"G") {
1965 AddrSpace = M->getDataLayout().getDefaultGlobalsAddressSpace();
1966 }
else if (AddrSpaceStr ==
"P") {
1967 AddrSpace = M->getDataLayout().getProgramAddressSpace();
1969 return tokError(
"invalid symbolic addrspace '" + AddrSpaceStr +
"'");
1975 return tokError(
"expected integer or string constant");
1976 SMLoc Loc = Lex.getLoc();
1977 if (parseUInt32(AddrSpace))
1980 return error(Loc,
"invalid address space, must be a 24-bit integer");
1984 return parseToken(
lltok::lparen,
"expected '(' in address space") ||
1985 ParseAddrspaceValue(AddrSpace) ||
1992bool LLParser::parseStringAttribute(AttrBuilder &
B) {
1993 std::string Attr = Lex.getStrVal();
1996 if (EatIfPresent(
lltok::equal) && parseStringConstant(Val))
1998 B.addAttribute(Attr, Val);
2003bool LLParser::parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam) {
2004 bool HaveError =
false;
2011 if (parseStringAttribute(
B))
2022 SMLoc Loc = Lex.getLoc();
2027 if (parseEnumAttribute(Attr,
B,
false))
2031 HaveError |=
error(Loc,
"this attribute does not apply to parameters");
2033 HaveError |=
error(Loc,
"this attribute does not apply to return values");
2081bool LLParser::parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
2082 unsigned &Visibility,
2083 unsigned &DLLStorageClass,
bool &DSOLocal) {
2087 parseOptionalDSOLocal(DSOLocal);
2088 parseOptionalVisibility(Visibility);
2089 parseOptionalDLLStorageClass(DLLStorageClass);
2092 return error(Lex.getLoc(),
"dso_location and DLL-StorageClass mismatch");
2098void LLParser::parseOptionalDSOLocal(
bool &DSOLocal) {
2099 switch (Lex.getKind()) {
2120void LLParser::parseOptionalVisibility(
unsigned &Res) {
2121 switch (Lex.getKind()) {
2138bool LLParser::parseOptionalImportType(
lltok::Kind Kind,
2142 return tokError(
"unknown import kind. Expect definition or declaration.");
2157void LLParser::parseOptionalDLLStorageClass(
unsigned &Res) {
2158 switch (Lex.getKind()) {
2228bool LLParser::parseOptionalCallingConv(
unsigned &CC) {
2229 switch (Lex.getKind()) {
2316 return tokError(
"unknown RISC-V ABI VLEN");
2317#define CC_VLS_CASE(ABIVlen) \
2319 CC = CallingConv::RISCV_VLSCall_##ABIVlen; \
2347 return parseUInt32(CC);
2357bool LLParser::parseMetadataAttachment(
unsigned &Kind,
MDNode *&MD) {
2360 std::string
Name = Lex.getStrVal();
2361 Kind = M->getMDKindID(Name);
2364 return parseMDNode(MD);
2369bool LLParser::parseInstructionMetadata(
Instruction &Inst) {
2372 return tokError(
"expected metadata after comma");
2376 if (parseMetadataAttachment(MDK,
N))
2379 if (MDK == LLVMContext::MD_DIAssignID)
2380 TempDIAssignIDAttachments[
N].push_back(&Inst);
2384 if (MDK == LLVMContext::MD_tbaa)
2385 InstsWithTBAATag.push_back(&Inst);
2394bool LLParser::parseGlobalObjectMetadataAttachment(
GlobalObject &GO) {
2397 if (parseMetadataAttachment(MDK,
N))
2406bool LLParser::parseOptionalFunctionMetadata(
Function &
F) {
2408 if (parseGlobalObjectMetadataAttachment(
F))
2416bool LLParser::parseOptionalAlignment(
MaybeAlign &Alignment,
bool AllowParens) {
2417 Alignment = std::nullopt;
2418 if (!EatIfPresent(lltok::kw_align))
2420 LocTy AlignLoc = Lex.getLoc();
2423 LocTy ParenLoc = Lex.getLoc();
2424 bool HaveParens =
false;
2430 if (parseUInt64(
Value))
2434 return error(ParenLoc,
"expected ')'");
2437 return error(AlignLoc,
"alignment is not a power of two");
2439 return error(AlignLoc,
"huge alignments are not supported yet");
2449 auto StrVal = Lex.getStrVal();
2450 auto ErrMsg =
"expected global code model string";
2451 if (StrVal ==
"tiny")
2453 else if (StrVal ==
"small")
2455 else if (StrVal ==
"kernel")
2457 else if (StrVal ==
"medium")
2459 else if (StrVal ==
"large")
2462 return tokError(ErrMsg);
2473bool LLParser::parseOptionalDerefAttrBytes(
lltok::Kind AttrKind,
2475 assert((AttrKind == lltok::kw_dereferenceable ||
2476 AttrKind == lltok::kw_dereferenceable_or_null) &&
2480 if (!EatIfPresent(AttrKind))
2482 LocTy ParenLoc = Lex.getLoc();
2484 return error(ParenLoc,
"expected '('");
2485 LocTy DerefLoc = Lex.getLoc();
2486 if (parseUInt64(Bytes))
2488 ParenLoc = Lex.getLoc();
2490 return error(ParenLoc,
"expected ')'");
2492 return error(DerefLoc,
"dereferenceable bytes must be non-zero");
2496bool LLParser::parseOptionalUWTableKind(
UWTableKind &Kind) {
2501 LocTy KindLoc = Lex.getLoc();
2507 return error(KindLoc,
"expected unwind table kind");
2514 LocTy ParenLoc = Lex.getLoc();
2516 return error(ParenLoc,
"expected '('");
2517 LocTy KindLoc = Lex.getLoc();
2519 if (parseStringConstant(Arg))
2520 return error(KindLoc,
"expected allockind value");
2524 }
else if (
A ==
"realloc") {
2526 }
else if (
A ==
"free") {
2528 }
else if (
A ==
"uninitialized") {
2530 }
else if (
A ==
"zeroed") {
2532 }
else if (
A ==
"aligned") {
2535 return error(KindLoc, Twine(
"unknown allockind ") +
A);
2538 ParenLoc = Lex.getLoc();
2540 return error(ParenLoc,
"expected ')'");
2542 return error(KindLoc,
"expected allockind value");
2559 return std::nullopt;
2574 return std::nullopt;
2578std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
2583 Lex.setIgnoreColonInIdentifiers(
true);
2588 tokError(
"expected '('");
2589 return std::nullopt;
2592 bool SeenLoc =
false;
2594 std::optional<IRMemLocation> Loc =
keywordToLoc(Lex.getKind());
2598 tokError(
"expected ':' after location");
2599 return std::nullopt;
2606 tokError(
"expected memory location (argmem, inaccessiblemem, errnomem) "
2607 "or access kind (none, read, write, readwrite)");
2609 tokError(
"expected access kind (none, read, write, readwrite)");
2610 return std::nullopt;
2619 tokError(
"default access kind must be specified first");
2620 return std::nullopt;
2629 tokError(
"unterminated memory attribute");
2630 return std::nullopt;
2672unsigned LLParser::parseNoFPClassAttr() {
2677 tokError(
"expected '('");
2684 if (TestMask != 0) {
2688 !parseUInt64(
Value)) {
2690 error(Lex.getLoc(),
"invalid mask value for 'nofpclass'");
2695 error(Lex.getLoc(),
"expected ')'");
2701 error(Lex.getLoc(),
"expected nofpclass test mask");
2719bool LLParser::parseOptionalCommaAlign(
MaybeAlign &Alignment,
2720 bool &AteExtraComma) {
2721 AteExtraComma =
false;
2725 AteExtraComma =
true;
2729 if (Lex.getKind() != lltok::kw_align)
2730 return error(Lex.getLoc(),
"expected metadata or 'align'");
2732 if (parseOptionalAlignment(Alignment))
2745bool LLParser::parseOptionalCommaAddrSpace(
unsigned &AddrSpace, LocTy &
Loc,
2746 bool &AteExtraComma) {
2747 AteExtraComma =
false;
2751 AteExtraComma =
true;
2757 return error(Lex.getLoc(),
"expected metadata or 'addrspace'");
2759 if (parseOptionalAddrSpace(AddrSpace))
2766bool LLParser::parseAllocSizeArguments(
unsigned &BaseSizeArg,
2767 std::optional<unsigned> &HowManyArg) {
2770 auto StartParen = Lex.getLoc();
2772 return error(StartParen,
"expected '('");
2774 if (parseUInt32(BaseSizeArg))
2778 auto HowManyAt = Lex.getLoc();
2780 if (parseUInt32(HowMany))
2782 if (HowMany == BaseSizeArg)
2783 return error(HowManyAt,
2784 "'allocsize' indices can't refer to the same parameter");
2785 HowManyArg = HowMany;
2787 HowManyArg = std::nullopt;
2789 auto EndParen = Lex.getLoc();
2791 return error(EndParen,
"expected ')'");
2795bool LLParser::parseVScaleRangeArguments(
unsigned &MinValue,
2796 unsigned &MaxValue) {
2799 auto StartParen = Lex.getLoc();
2801 return error(StartParen,
"expected '('");
2803 if (parseUInt32(MinValue))
2807 if (parseUInt32(MaxValue))
2810 MaxValue = MinValue;
2812 auto EndParen = Lex.getLoc();
2814 return error(EndParen,
"expected ')'");
2823bool LLParser::parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
2828 return parseScope(SSID) || parseOrdering(Ordering);
2838 auto StartParenAt = Lex.getLoc();
2840 return error(StartParenAt,
"Expected '(' in syncscope");
2843 auto SSNAt = Lex.getLoc();
2844 if (parseStringConstant(SSN))
2845 return error(SSNAt,
"Expected synchronization scope name");
2847 auto EndParenAt = Lex.getLoc();
2849 return error(EndParenAt,
"Expected ')' in syncscope");
2851 SSID = Context.getOrInsertSyncScopeID(SSN);
2862 switch (Lex.getKind()) {
2864 return tokError(
"Expected ordering on atomic instruction");
2883bool LLParser::parseOptionalStackAlignment(
unsigned &Alignment) {
2885 if (!EatIfPresent(lltok::kw_alignstack))
2887 LocTy ParenLoc = Lex.getLoc();
2889 return error(ParenLoc,
"expected '('");
2890 LocTy AlignLoc = Lex.getLoc();
2891 if (parseUInt32(Alignment))
2893 ParenLoc = Lex.getLoc();
2895 return error(ParenLoc,
"expected ')'");
2897 return error(AlignLoc,
"stack alignment is not a power of two");
2911 bool &AteExtraComma) {
2912 AteExtraComma =
false;
2915 return tokError(
"expected ',' as start of index list");
2919 if (Indices.
empty())
2920 return tokError(
"expected index");
2921 AteExtraComma =
true;
2925 if (parseUInt32(Idx))
2938bool LLParser::parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid) {
2939 SMLoc TypeLoc = Lex.getLoc();
2940 switch (Lex.getKind()) {
2942 return tokError(Msg);
2951 if (
Result->isPointerTy()) {
2953 if (parseOptionalAddrSpace(AddrSpace))
2959 return tokError(
"ptr* is invalid - use ptr instead");
2970 if (parseTargetExtType(Result))
2976 if (parseAnonStructType(Result,
false))
2982 if (parseArrayVectorType(Result,
false))
2989 if (parseAnonStructType(Result,
true) ||
2990 parseToken(
lltok::greater,
"expected '>' at end of packed struct"))
2992 }
else if (parseArrayVectorType(Result,
true))
2997 std::pair<Type*, LocTy> &
Entry = NamedTypes[Lex.getStrVal()];
3003 Entry.second = Lex.getLoc();
3012 std::pair<Type*, LocTy> &
Entry = NumberedTypes[Lex.getUIntVal()];
3018 Entry.second = Lex.getLoc();
3028 switch (Lex.getKind()) {
3031 if (!AllowVoid &&
Result->isVoidTy())
3032 return error(TypeLoc,
"void type only allowed for function results");
3038 return tokError(
"basic block pointers are invalid");
3040 return tokError(
"pointers to void are invalid - use i8* instead");
3042 return tokError(
"pointer to this type is invalid");
3050 return tokError(
"basic block pointers are invalid");
3052 return tokError(
"pointers to void are invalid; use i8* instead");
3054 return tokError(
"pointer to this type is invalid");
3056 if (parseOptionalAddrSpace(AddrSpace) ||
3057 parseToken(
lltok::star,
"expected '*' in address space"))
3066 if (parseFunctionType(Result))
3079 PerFunctionState &PFS,
bool IsMustTailCall,
3080 bool InVarArgsFunc) {
3086 if (!ArgList.
empty() &&
3087 parseToken(
lltok::comma,
"expected ',' in argument list"))
3092 const char *Msg =
"unexpected ellipsis in argument list for ";
3093 if (!IsMustTailCall)
3094 return tokError(Twine(Msg) +
"non-musttail call");
3096 return tokError(Twine(Msg) +
"musttail call in non-varargs function");
3098 return parseToken(
lltok::rparen,
"expected ')' at end of argument list");
3103 Type *ArgTy =
nullptr;
3105 if (parseType(ArgTy, ArgLoc))
3108 return error(ArgLoc,
"invalid type for function argument");
3110 AttrBuilder ArgAttrs(M->getContext());
3113 if (parseMetadataAsValue(V, PFS))
3117 if (parseOptionalParamAttrs(ArgAttrs) || parseValue(ArgTy, V, PFS))
3124 if (IsMustTailCall && InVarArgsFunc)
3125 return tokError(
"expected '...' at end of argument list for musttail call "
3126 "in varargs function");
3134bool LLParser::parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
3137 if (!EatIfPresent(AttrToken))
3140 return error(Lex.getLoc(),
"expected '('");
3144 return error(Lex.getLoc(),
"expected ')'");
3146 B.addTypeAttr(AttrKind, Ty);
3152bool LLParser::parseRangeAttr(AttrBuilder &
B) {
3160 auto ParseAPSInt = [&](
unsigned BitWidth, APInt &Val) {
3162 return tokError(
"expected integer");
3163 if (Lex.getAPSIntVal().getBitWidth() >
BitWidth)
3165 "integer is too large for the bit width of specified type");
3166 Val = Lex.getAPSIntVal().extend(
BitWidth);
3171 if (parseToken(
lltok::lparen,
"expected '('") || parseType(Ty, TyLoc))
3174 return error(TyLoc,
"the range must have integer type!");
3182 return tokError(
"the range represent the empty set but limits aren't 0!");
3193bool LLParser::parseInitializesAttr(AttrBuilder &
B) {
3196 auto ParseAPSInt = [&](APInt &Val) {
3198 return tokError(
"expected integer");
3199 Val = Lex.getAPSIntVal().extend(64);
3219 return tokError(
"the range should not represent the full or empty set!");
3231 if (!CRLOrNull.has_value())
3232 return tokError(
"Invalid (unordered or overlapping) range list");
3233 B.addInitializesAttr(*CRLOrNull);
3237bool LLParser::parseCapturesAttr(AttrBuilder &
B) {
3239 std::optional<CaptureComponents>
Ret;
3243 Lex.setIgnoreColonInIdentifiers(
true);
3251 bool SeenComponent =
false;
3257 return tokError(
"duplicate 'ret' location");
3260 SeenComponent =
false;
3265 return tokError(
"cannot use 'none' with other component");
3269 return tokError(
"cannot use 'none' with other component");
3280 return tokError(
"expected one of 'none', 'address', 'address_is_null', "
3281 "'provenance' or 'read_provenance'");
3284 SeenComponent =
true;
3305bool LLParser::parseOptionalOperandBundles(
3307 LocTy BeginLoc = Lex.getLoc();
3313 if (!BundleList.
empty() &&
3314 parseToken(
lltok::comma,
"expected ',' in input list"))
3318 if (parseStringConstant(
Tag))
3321 if (parseToken(
lltok::lparen,
"expected '(' in operand bundle"))
3324 std::vector<Value *> Inputs;
3327 if (!Inputs.empty() &&
3328 parseToken(
lltok::comma,
"expected ',' in input list"))
3332 Value *Input =
nullptr;
3336 if (parseMetadataAsValue(Input, PFS))
3338 }
else if (parseValue(Ty, Input, PFS)) {
3341 Inputs.push_back(Input);
3349 if (BundleList.
empty())
3350 return error(BeginLoc,
"operand bundle set must not be empty");
3357 unsigned NextID,
unsigned ID) {
3359 return error(Loc, Kind +
" expected to be numbered '" + Prefix +
3360 Twine(NextID) +
"' or greater");
3377 unsigned CurValID = 0;
3391 LocTy TypeLoc = Lex.getLoc();
3392 Type *ArgTy =
nullptr;
3393 AttrBuilder
Attrs(M->getContext());
3394 if (parseType(ArgTy) || parseOptionalParamAttrs(Attrs))
3398 return error(TypeLoc,
"argument can not have void type");
3402 Name = Lex.getStrVal();
3407 ArgID = Lex.getUIntVal();
3408 if (checkValueID(TypeLoc,
"argument",
"%", CurValID, ArgID))
3415 CurValID = ArgID + 1;
3419 return error(TypeLoc,
"invalid type for function argument");
3427 return parseToken(
lltok::rparen,
"expected ')' at end of argument list");
3432bool LLParser::parseFunctionType(
Type *&Result) {
3436 return tokError(
"invalid function return type");
3440 SmallVector<unsigned> UnnamedArgNums;
3441 if (parseArgumentList(ArgList, UnnamedArgNums, IsVarArg))
3445 for (
const ArgInfo &Arg : ArgList) {
3446 if (!Arg.Name.empty())
3447 return error(Arg.Loc,
"argument name invalid in function type");
3448 if (Arg.Attrs.hasAttributes())
3449 return error(Arg.Loc,
"argument attributes invalid in function type");
3453 for (
const ArgInfo &Arg : ArgList)
3462bool LLParser::parseAnonStructType(
Type *&Result,
bool Packed) {
3464 if (parseStructBody(Elts))
3472bool LLParser::parseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
3473 std::pair<Type *, LocTy> &Entry,
3477 return error(TypeLoc,
"redefinition of type");
3483 Entry.second = SMLoc();
3488 ResultTy =
Entry.first;
3500 return error(TypeLoc,
"forward references to non-struct type");
3504 return parseArrayVectorType(ResultTy,
true);
3505 return parseType(ResultTy);
3509 Entry.second = SMLoc();
3518 if (parseStructBody(Body) ||
3519 (isPacked && parseToken(
lltok::greater,
"expected '>' in packed struct")))
3523 return tokError(
toString(std::move(
E)));
3543 LocTy EltTyLoc = Lex.getLoc();
3550 return error(EltTyLoc,
"invalid element type for struct");
3553 EltTyLoc = Lex.getLoc();
3558 return error(EltTyLoc,
"invalid element type for struct");
3563 return parseToken(
lltok::rbrace,
"expected '}' at end of struct");
3572bool LLParser::parseArrayVectorType(
Type *&Result,
bool IsVector) {
3573 bool Scalable =
false;
3577 if (parseToken(
lltok::kw_x,
"expected 'x' after vscale"))
3583 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned() ||
3584 Lex.getAPSIntVal().getBitWidth() > 64)
3585 return tokError(
"expected number in address space");
3587 LocTy SizeLoc = Lex.getLoc();
3588 uint64_t
Size = Lex.getAPSIntVal().getZExtValue();
3591 if (parseToken(
lltok::kw_x,
"expected 'x' after element count"))
3594 LocTy TypeLoc = Lex.getLoc();
3595 Type *EltTy =
nullptr;
3596 if (parseType(EltTy))
3600 "expected end of sequential type"))
3605 return error(SizeLoc,
"zero element vector is illegal");
3607 return error(SizeLoc,
"size too large for vector");
3609 return error(TypeLoc,
"invalid vector element type");
3613 return error(TypeLoc,
"invalid array element type");
3630bool LLParser::parseTargetExtType(
Type *&Result) {
3635 if (parseToken(
lltok::lparen,
"expected '(' in target extension type") ||
3636 parseStringConstant(TypeName))
3643 SmallVector<unsigned> IntParams;
3644 bool SeenInt =
false;
3651 if (parseUInt32(IntVal))
3654 }
else if (SeenInt) {
3657 return tokError(
"expected uint32 param");
3660 if (parseType(TypeParam,
true))
3666 if (parseToken(
lltok::rparen,
"expected ')' in target extension type"))
3671 if (
auto E = TTy.takeError())
3672 return tokError(
toString(std::move(
E)));
3685 :
P(
p),
F(
f), FunctionNumber(functionNumber) {
3688 auto It = UnnamedArgNums.
begin();
3691 unsigned ArgNum = *It++;
3692 NumberedVals.add(ArgNum, &A);
3697LLParser::PerFunctionState::~PerFunctionState() {
3700 for (
const auto &P : ForwardRefVals) {
3703 P.second.first->replaceAllUsesWith(
3705 P.second.first->deleteValue();
3708 for (
const auto &P : ForwardRefValIDs) {
3711 P.second.first->replaceAllUsesWith(
3713 P.second.first->deleteValue();
3717bool LLParser::PerFunctionState::finishFunction() {
3718 if (!ForwardRefVals.empty())
3719 return P.error(ForwardRefVals.begin()->second.second,
3720 "use of undefined value '%" + ForwardRefVals.begin()->first +
3722 if (!ForwardRefValIDs.empty())
3723 return P.error(ForwardRefValIDs.begin()->second.second,
3724 "use of undefined value '%" +
3725 Twine(ForwardRefValIDs.begin()->first) +
"'");
3732Value *LLParser::PerFunctionState::getVal(
const std::string &Name,
Type *Ty,
3735 Value *Val =
F.getValueSymbolTable()->lookup(Name);
3740 auto I = ForwardRefVals.find(Name);
3741 if (
I != ForwardRefVals.end())
3742 Val =
I->second.first;
3747 return P.checkValidVariableType(Loc,
"%" + Name, Ty, Val);
3751 P.error(Loc,
"invalid use of a non-first-class type");
3762 if (FwdVal->
getName() != Name) {
3763 P.error(Loc,
"name is too long which can result in name collisions, "
3764 "consider making the name shorter or "
3765 "increasing -non-global-value-max-name-size");
3769 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
3773Value *LLParser::PerFunctionState::getVal(
unsigned ID,
Type *Ty,
LocTy Loc) {
3775 Value *Val = NumberedVals.get(
ID);
3780 auto I = ForwardRefValIDs.find(
ID);
3781 if (
I != ForwardRefValIDs.end())
3782 Val =
I->second.first;
3787 return P.checkValidVariableType(Loc,
"%" + Twine(
ID), Ty, Val);
3790 P.error(Loc,
"invalid use of a non-first-class type");
3802 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
3808bool LLParser::PerFunctionState::setInstName(
int NameID,
3809 const std::string &NameStr,
3810 LocTy NameLoc, Instruction *Inst) {
3813 if (NameID != -1 || !NameStr.empty())
3814 return P.error(NameLoc,
"instructions returning void cannot have a name");
3820 if (NameStr.empty()) {
3823 NameID = NumberedVals.getNext();
3825 if (
P.checkValueID(NameLoc,
"instruction",
"%", NumberedVals.getNext(),
3829 auto FI = ForwardRefValIDs.find(NameID);
3830 if (FI != ForwardRefValIDs.end()) {
3833 return P.error(NameLoc,
"instruction forward referenced with type '" +
3837 Sentinel->replaceAllUsesWith(Inst);
3839 ForwardRefValIDs.erase(FI);
3842 NumberedVals.add(NameID, Inst);
3847 auto FI = ForwardRefVals.find(NameStr);
3848 if (FI != ForwardRefVals.end()) {
3851 return P.error(NameLoc,
"instruction forward referenced with type '" +
3855 Sentinel->replaceAllUsesWith(Inst);
3857 ForwardRefVals.erase(FI);
3863 if (Inst->
getName() != NameStr)
3864 return P.error(NameLoc,
"multiple definition of local value named '" +
3871BasicBlock *LLParser::PerFunctionState::getBB(
const std::string &Name,
3885BasicBlock *LLParser::PerFunctionState::defineBB(
const std::string &Name,
3886 int NameID,
LocTy Loc) {
3890 if (
P.checkValueID(Loc,
"label",
"", NumberedVals.getNext(), NameID))
3893 NameID = NumberedVals.getNext();
3895 BB = getBB(NameID, Loc);
3897 P.error(Loc,
"unable to create block numbered '" + Twine(NameID) +
"'");
3901 BB = getBB(Name, Loc);
3903 P.error(Loc,
"unable to create block named '" + Name +
"'");
3914 ForwardRefValIDs.erase(NameID);
3915 NumberedVals.add(NameID, BB);
3918 ForwardRefVals.erase(Name);
3935bool LLParser::parseValID(ValID &
ID, PerFunctionState *PFS,
Type *ExpectedTy) {
3936 ID.Loc = Lex.getLoc();
3937 switch (Lex.getKind()) {
3939 return tokError(
"expected value token");
3941 ID.UIntVal = Lex.getUIntVal();
3945 ID.StrVal = Lex.getStrVal();
3949 ID.UIntVal = Lex.getUIntVal();
3953 ID.StrVal = Lex.getStrVal();
3957 ID.APSIntVal = Lex.getAPSIntVal();
3961 ID.APFloatVal = Lex.getAPFloatVal();
3982 if (parseGlobalValueVector(Elts) ||
3983 parseToken(
lltok::rbrace,
"expected end of struct constant"))
3986 ID.ConstantStructElts = std::make_unique<Constant *[]>(Elts.
size());
3987 ID.UIntVal = Elts.
size();
3988 memcpy(
ID.ConstantStructElts.get(), Elts.
data(),
3989 Elts.
size() *
sizeof(Elts[0]));
4000 LocTy FirstEltLoc = Lex.getLoc();
4001 if (parseGlobalValueVector(Elts) ||
4003 parseToken(
lltok::rbrace,
"expected end of packed struct")) ||
4007 if (isPackedStruct) {
4008 ID.ConstantStructElts = std::make_unique<Constant *[]>(Elts.
size());
4009 memcpy(
ID.ConstantStructElts.get(), Elts.
data(),
4010 Elts.
size() *
sizeof(Elts[0]));
4011 ID.UIntVal = Elts.
size();
4017 return error(
ID.Loc,
"constant vector must not be empty");
4019 if (!Elts[0]->
getType()->isIntegerTy() &&
4020 !Elts[0]->
getType()->isFloatingPointTy() &&
4024 "vector elements must have integer, pointer or floating point type");
4027 for (
unsigned i = 1, e = Elts.
size(); i != e; ++i)
4029 return error(FirstEltLoc,
"vector element #" + Twine(i) +
4030 " is not of type '" +
4040 LocTy FirstEltLoc = Lex.getLoc();
4041 if (parseGlobalValueVector(Elts) ||
4053 if (!Elts[0]->
getType()->isFirstClassType())
4054 return error(FirstEltLoc,
"invalid array element type: " +
4060 for (
unsigned i = 0, e = Elts.
size(); i != e; ++i) {
4062 return error(FirstEltLoc,
"array element #" + Twine(i) +
4063 " is not of type '" +
4083 bool HasSideEffect, AlignStack, AsmDialect, CanThrow;
4086 parseOptionalToken(lltok::kw_alignstack, AlignStack) ||
4089 parseStringConstant(
ID.StrVal) ||
4090 parseToken(
lltok::comma,
"expected comma in inline asm expression") ||
4093 ID.StrVal2 = Lex.getStrVal();
4094 ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack) << 1) |
4095 (
unsigned(AsmDialect) << 2) | (unsigned(CanThrow) << 3);
4106 if (parseToken(
lltok::lparen,
"expected '(' in block address expression") ||
4107 parseValID(Fn, PFS) ||
4109 "expected comma in block address expression") ||
4110 parseValID(Label, PFS) ||
4111 parseToken(
lltok::rparen,
"expected ')' in block address expression"))
4115 return error(Fn.
Loc,
"expected function name in blockaddress");
4117 return error(
Label.Loc,
"expected basic block name in blockaddress");
4120 GlobalValue *GV =
nullptr;
4122 GV = NumberedVals.get(Fn.
UIntVal);
4123 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
4124 GV = M->getNamedValue(Fn.
StrVal);
4130 return error(Fn.
Loc,
"expected function name in blockaddress");
4132 if (
F->isDeclaration())
4133 return error(Fn.
Loc,
"cannot take blockaddress inside a declaration");
4138 GlobalValue *&FwdRef =
4139 ForwardRefBlockAddresses[std::move(Fn)][std::move(Label)];
4147 "type of blockaddress must be a pointer and not '" +
4152 FwdDeclAS = PFS->getFunction().getAddressSpace();
4156 FwdRef =
new GlobalVariable(
4161 ID.ConstantVal = FwdRef;
4169 if (BlockAddressPFS &&
F == &BlockAddressPFS->getFunction()) {
4171 BB = BlockAddressPFS->getBB(
Label.UIntVal,
Label.Loc);
4173 BB = BlockAddressPFS->getBB(
Label.StrVal,
Label.Loc);
4175 return error(
Label.Loc,
"referenced value is not a basic block");
4178 return error(
Label.Loc,
"cannot take address of numeric label after "
4179 "the function is defined");
4181 F->getValueSymbolTable()->lookup(
Label.StrVal));
4183 return error(
Label.Loc,
"referenced value is not a basic block");
4197 if (parseValID(Fn, PFS))
4202 "expected global value name in dso_local_equivalent");
4205 GlobalValue *GV =
nullptr;
4207 GV = NumberedVals.get(Fn.
UIntVal);
4208 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
4209 GV = M->getNamedValue(Fn.
StrVal);
4215 ? ForwardRefDSOLocalEquivalentIDs
4216 : ForwardRefDSOLocalEquivalentNames;
4217 GlobalValue *&FwdRef = FwdRefMap[Fn];
4224 ID.ConstantVal = FwdRef;
4230 return error(Fn.
Loc,
"expected a function, alias to function, or ifunc "
4231 "in dso_local_equivalent");
4242 if (parseValID(
ID, PFS))
4246 return error(
ID.Loc,
"expected global value name in no_cfi");
4257 Constant *Disc =
nullptr, *AddrDisc =
nullptr;
4260 "expected '(' in constant ptrauth expression") ||
4261 parseGlobalTypeAndValue(Ptr) ||
4263 "expected comma in constant ptrauth expression") ||
4264 parseGlobalTypeAndValue(
Key))
4268 if (parseGlobalTypeAndValue(Disc) ||
4269 (EatIfPresent(
lltok::comma) && parseGlobalTypeAndValue(AddrDisc)))
4272 "expected ')' in constant ptrauth expression"))
4276 return error(
ID.Loc,
"constant ptrauth base pointer must be a pointer");
4279 if (!KeyC || KeyC->getBitWidth() != 32)
4280 return error(
ID.Loc,
"constant ptrauth key must be i32 constant");
4282 ConstantInt *DiscC =
nullptr;
4288 "constant ptrauth integer discriminator must be i64 constant");
4294 if (!AddrDisc->getType()->isPointerTy())
4296 ID.Loc,
"constant ptrauth address discriminator must be a pointer");
4312 unsigned Opc = Lex.getUIntVal();
4313 Type *DestTy =
nullptr;
4316 if (parseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
4317 parseGlobalTypeAndValue(SrcVal) ||
4318 parseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
4319 parseType(DestTy) ||
4320 parseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
4323 return error(
ID.Loc,
"invalid cast opcode for cast from '" +
4332 return error(
ID.Loc,
"extractvalue constexprs are no longer supported");
4334 return error(
ID.Loc,
"insertvalue constexprs are no longer supported");
4336 return error(
ID.Loc,
"udiv constexprs are no longer supported");
4338 return error(
ID.Loc,
"sdiv constexprs are no longer supported");
4340 return error(
ID.Loc,
"urem constexprs are no longer supported");
4342 return error(
ID.Loc,
"srem constexprs are no longer supported");
4344 return error(
ID.Loc,
"fadd constexprs are no longer supported");
4346 return error(
ID.Loc,
"fsub constexprs are no longer supported");
4348 return error(
ID.Loc,
"fmul constexprs are no longer supported");
4350 return error(
ID.Loc,
"fdiv constexprs are no longer supported");
4352 return error(
ID.Loc,
"frem constexprs are no longer supported");
4354 return error(
ID.Loc,
"and constexprs are no longer supported");
4356 return error(
ID.Loc,
"or constexprs are no longer supported");
4358 return error(
ID.Loc,
"lshr constexprs are no longer supported");
4360 return error(
ID.Loc,
"ashr constexprs are no longer supported");
4362 return error(
ID.Loc,
"shl constexprs are no longer supported");
4364 return error(
ID.Loc,
"mul constexprs are no longer supported");
4366 return error(
ID.Loc,
"fneg constexprs are no longer supported");
4368 return error(
ID.Loc,
"select constexprs are no longer supported");
4370 return error(
ID.Loc,
"zext constexprs are no longer supported");
4372 return error(
ID.Loc,
"sext constexprs are no longer supported");
4374 return error(
ID.Loc,
"fptrunc constexprs are no longer supported");
4376 return error(
ID.Loc,
"fpext constexprs are no longer supported");
4378 return error(
ID.Loc,
"uitofp constexprs are no longer supported");
4380 return error(
ID.Loc,
"sitofp constexprs are no longer supported");
4382 return error(
ID.Loc,
"fptoui constexprs are no longer supported");
4384 return error(
ID.Loc,
"fptosi constexprs are no longer supported");
4386 return error(
ID.Loc,
"icmp constexprs are no longer supported");
4388 return error(
ID.Loc,
"fcmp constexprs are no longer supported");
4396 unsigned Opc = Lex.getUIntVal();
4399 if (
Opc == Instruction::Add ||
Opc == Instruction::Sub ||
4400 Opc == Instruction::Mul) {
4409 if (parseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
4410 parseGlobalTypeAndValue(Val0) ||
4411 parseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
4412 parseGlobalTypeAndValue(Val1) ||
4413 parseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
4416 return error(
ID.Loc,
"operands of constexpr must have same type");
4420 "constexpr requires integer or integer vector operands");
4431 if (parseToken(
lltok::lparen,
"expected '(' after vector splat"))
4434 if (parseGlobalTypeAndValue(
C))
4436 if (parseToken(
lltok::rparen,
"expected ')' at end of vector splat"))
4448 unsigned Opc = Lex.getUIntVal();
4451 bool HasInRange =
false;
4457 if (
Opc == Instruction::GetElementPtr) {
4473 return tokError(
"expected integer");
4474 InRangeStart = Lex.getAPSIntVal();
4479 return tokError(
"expected integer");
4480 InRangeEnd = Lex.getAPSIntVal();
4488 if (parseToken(
lltok::lparen,
"expected '(' in constantexpr"))
4491 if (
Opc == Instruction::GetElementPtr) {
4492 if (parseType(Ty) ||
4493 parseToken(
lltok::comma,
"expected comma after getelementptr's type"))
4497 if (parseGlobalValueVector(Elts) ||
4501 if (
Opc == Instruction::GetElementPtr) {
4502 if (Elts.
size() == 0 ||
4503 !Elts[0]->getType()->isPtrOrPtrVectorTy())
4504 return error(
ID.Loc,
"base of getelementptr must be a pointer");
4507 std::optional<ConstantRange>
InRange;
4509 unsigned IndexWidth =
4510 M->getDataLayout().getIndexTypeSizeInBits(
BaseType);
4511 InRangeStart = InRangeStart.
extOrTrunc(IndexWidth);
4512 InRangeEnd = InRangeEnd.
extOrTrunc(IndexWidth);
4513 if (InRangeStart.
sge(InRangeEnd))
4514 return error(
ID.Loc,
"expected end to be larger than start");
4524 for (Constant *Val : Indices) {
4527 return error(
ID.Loc,
"getelementptr index must be an integer");
4530 if (GEPWidth && (ValNumEl != GEPWidth))
4533 "getelementptr vector index has a wrong number of elements");
4536 GEPWidth = ValNumEl;
4540 SmallPtrSet<Type*, 4> Visited;
4541 if (!Indices.empty() && !Ty->
isSized(&Visited))
4542 return error(
ID.Loc,
"base element of getelementptr must be sized");
4545 return error(
ID.Loc,
"invalid base element for constant getelementptr");
4548 return error(
ID.Loc,
"invalid getelementptr indices");
4552 }
else if (
Opc == Instruction::ShuffleVector) {
4553 if (Elts.
size() != 3)
4554 return error(
ID.Loc,
"expected three operands to shufflevector");
4556 return error(
ID.Loc,
"invalid operands to shufflevector");
4557 SmallVector<int, 16>
Mask;
4560 }
else if (
Opc == Instruction::ExtractElement) {
4561 if (Elts.
size() != 2)
4562 return error(
ID.Loc,
"expected two operands to extractelement");
4564 return error(
ID.Loc,
"invalid extractelement operands");
4567 assert(
Opc == Instruction::InsertElement &&
"Unknown opcode");
4568 if (Elts.
size() != 3)
4569 return error(
ID.Loc,
"expected three operands to insertelement");
4571 return error(
ID.Loc,
"invalid insertelement operands");
4586bool LLParser::parseGlobalValue(
Type *Ty, Constant *&
C) {
4590 bool Parsed = parseValID(
ID,
nullptr, Ty) ||
4591 convertValIDToValue(Ty,
ID, V,
nullptr);
4593 return error(
ID.Loc,
"global values must be constants");
4597bool LLParser::parseGlobalTypeAndValue(Constant *&V) {
4599 return parseType(Ty) || parseGlobalValue(Ty, V);
4602bool LLParser::parseOptionalComdat(StringRef GlobalName, Comdat *&
C) {
4605 LocTy KwLoc = Lex.getLoc();
4611 return tokError(
"expected comdat variable");
4612 C = getComdat(Lex.getStrVal(), Lex.getLoc());
4614 if (parseToken(
lltok::rparen,
"expected ')' after comdat var"))
4617 if (GlobalName.
empty())
4618 return tokError(
"comdat cannot be unnamed");
4619 C = getComdat(std::string(GlobalName), KwLoc);
4628bool LLParser::parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts) {
4642 if (parseGlobalTypeAndValue(
C))
4650bool LLParser::parseMDTuple(MDNode *&MD,
bool IsDistinct) {
4652 if (parseMDNodeVector(Elts))
4663bool LLParser::parseMDNode(MDNode *&
N) {
4665 return parseSpecializedMDNode(
N);
4667 return parseToken(
lltok::exclaim,
"expected '!' here") || parseMDNodeTail(
N);
4670bool LLParser::parseMDNodeTail(MDNode *&
N) {
4673 return parseMDTuple(
N);
4676 return parseMDNodeID(
N);
4682template <
class FieldTy>
struct MDFieldImpl {
4683 typedef MDFieldImpl ImplTy;
4687 void assign(FieldTy Val) {
4689 this->Val = std::move(Val);
4692 explicit MDFieldImpl(FieldTy
Default)
4700template <
class FieldTypeA,
class FieldTypeB>
struct MDEitherFieldImpl {
4701 typedef MDEitherFieldImpl<FieldTypeA, FieldTypeB> ImplTy;
4712 void assign(FieldTypeA
A) {
4714 this->
A = std::move(
A);
4718 void assign(FieldTypeB
B) {
4720 this->
B = std::move(
B);
4724 explicit MDEitherFieldImpl(FieldTypeA DefaultA, FieldTypeB DefaultB)
4726 WhatIs(IsInvalid) {}
4729struct MDUnsignedField :
public MDFieldImpl<uint64_t> {
4736struct LineField :
public MDUnsignedField {
4737 LineField() : MDUnsignedField(0, UINT32_MAX) {}
4740struct ColumnField :
public MDUnsignedField {
4741 ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
4744struct DwarfTagField :
public MDUnsignedField {
4750struct DwarfMacinfoTypeField :
public MDUnsignedField {
4756struct DwarfAttEncodingField :
public MDUnsignedField {
4757 DwarfAttEncodingField() : MDUnsignedField(0, dwarf::
DW_ATE_hi_user) {}
4760struct DwarfVirtualityField :
public MDUnsignedField {
4764struct DwarfLangField :
public MDUnsignedField {
4768struct DwarfSourceLangNameField :
public MDUnsignedField {
4769 DwarfSourceLangNameField() : MDUnsignedField(0, UINT32_MAX) {}
4772struct DwarfCCField :
public MDUnsignedField {
4773 DwarfCCField() : MDUnsignedField(0, dwarf::
DW_CC_hi_user) {}
4776struct DwarfEnumKindField :
public MDUnsignedField {
4777 DwarfEnumKindField()
4782struct EmissionKindField :
public MDUnsignedField {
4783 EmissionKindField() : MDUnsignedField(0, DICompileUnit::LastEmissionKind) {}
4786struct FixedPointKindField :
public MDUnsignedField {
4787 FixedPointKindField()
4788 : MDUnsignedField(0, DIFixedPointType::LastFixedPointKind) {}
4791struct NameTableKindField :
public MDUnsignedField {
4792 NameTableKindField()
4795 DICompileUnit::DebugNameTableKind::LastDebugNameTableKind) {}
4798struct DIFlagField :
public MDFieldImpl<DINode::DIFlags> {
4799 DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
4802struct DISPFlagField :
public MDFieldImpl<DISubprogram::DISPFlags> {
4803 DISPFlagField() : MDFieldImpl(DISubprogram::SPFlagZero) {}
4806struct MDAPSIntField :
public MDFieldImpl<APSInt> {
4807 MDAPSIntField() : ImplTy(
APSInt()) {}
4810struct MDSignedField :
public MDFieldImpl<int64_t> {
4814 MDSignedField(int64_t
Default = 0)
4816 MDSignedField(int64_t
Default, int64_t Min, int64_t Max)
4820struct MDBoolField :
public MDFieldImpl<bool> {
4824struct MDField :
public MDFieldImpl<Metadata *> {
4827 MDField(
bool AllowNull =
true) : ImplTy(nullptr), AllowNull(AllowNull) {}
4830struct MDStringField :
public MDFieldImpl<MDString *> {
4831 enum class EmptyIs {
4836 MDStringField(
enum EmptyIs EmptyIs = EmptyIs::Null)
4837 : ImplTy(nullptr), EmptyIs(EmptyIs) {}
4840struct MDFieldList :
public MDFieldImpl<SmallVector<Metadata *, 4>> {
4844struct ChecksumKindField :
public MDFieldImpl<DIFile::ChecksumKind> {
4848struct MDSignedOrMDField : MDEitherFieldImpl<MDSignedField, MDField> {
4849 MDSignedOrMDField(int64_t
Default = 0,
bool AllowNull =
true)
4850 : ImplTy(MDSignedField(
Default), MDField(AllowNull)) {}
4852 MDSignedOrMDField(int64_t
Default, int64_t Min, int64_t Max,
4853 bool AllowNull =
true)
4854 : ImplTy(MDSignedField(
Default, Min,
Max), MDField(AllowNull)) {}
4856 bool isMDSignedField()
const {
return WhatIs == IsTypeA; }
4857 bool isMDField()
const {
return WhatIs == IsTypeB; }
4858 int64_t getMDSignedValue()
const {
4859 assert(isMDSignedField() &&
"Wrong field type");
4862 Metadata *getMDFieldValue()
const {
4863 assert(isMDField() &&
"Wrong field type");
4868struct MDUnsignedOrMDField : MDEitherFieldImpl<MDUnsignedField, MDField> {
4869 MDUnsignedOrMDField(uint64_t
Default = 0,
bool AllowNull =
true)
4870 : ImplTy(MDUnsignedField(
Default), MDField(AllowNull)) {}
4872 MDUnsignedOrMDField(uint64_t
Default, uint64_t Max,
bool AllowNull =
true)
4873 : ImplTy(MDUnsignedField(
Default,
Max), MDField(AllowNull)) {}
4875 bool isMDUnsignedField()
const {
return WhatIs == IsTypeA; }
4876 bool isMDField()
const {
return WhatIs == IsTypeB; }
4877 uint64_t getMDUnsignedValue()
const {
4878 assert(isMDUnsignedField() &&
"Wrong field type");
4881 Metadata *getMDFieldValue()
const {
4882 assert(isMDField() &&
"Wrong field type");
4887 if (isMDUnsignedField())
4889 ConstantInt::get(Type::getInt64Ty(
Context), getMDUnsignedValue()));
4891 return getMDFieldValue();
4903 return tokError(
"expected integer");
4905 Result.assign(Lex.getAPSIntVal());
4912 MDUnsignedField &Result) {
4913 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
4914 return tokError(
"expected unsigned integer");
4916 auto &U = Lex.getAPSIntVal();
4917 if (U.ugt(Result.Max))
4918 return tokError(
"value for '" + Name +
"' too large, limit is " +
4920 Result.assign(U.getZExtValue());
4921 assert(Result.Val <= Result.Max &&
"Expected value in range");
4928 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4932 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4938 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4941 return tokError(
"expected DWARF tag");
4945 return tokError(
"invalid DWARF tag" +
Twine(
" '") + Lex.getStrVal() +
"'");
4946 assert(
Tag <= Result.Max &&
"Expected valid DWARF tag");
4955 DwarfMacinfoTypeField &Result) {
4957 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4960 return tokError(
"expected DWARF macinfo type");
4964 return tokError(
"invalid DWARF macinfo type" +
Twine(
" '") +
4965 Lex.getStrVal() +
"'");
4966 assert(Macinfo <= Result.Max &&
"Expected valid DWARF macinfo type");
4968 Result.assign(Macinfo);
4975 DwarfVirtualityField &Result) {
4977 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4980 return tokError(
"expected DWARF virtuality code");
4984 return tokError(
"invalid DWARF virtuality code" +
Twine(
" '") +
4985 Lex.getStrVal() +
"'");
4986 assert(Virtuality <= Result.Max &&
"Expected valid DWARF virtuality code");
4987 Result.assign(Virtuality);
4994 DwarfEnumKindField &Result) {
4996 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4999 return tokError(
"expected DWARF enum kind code");
5003 return tokError(
"invalid DWARF enum kind code" +
Twine(
" '") +
5004 Lex.getStrVal() +
"'");
5005 assert(EnumKind <= Result.Max &&
"Expected valid DWARF enum kind code");
5006 Result.assign(EnumKind);
5014 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5017 return tokError(
"expected DWARF language");
5021 return tokError(
"invalid DWARF language" +
Twine(
" '") + Lex.getStrVal() +
5023 assert(Lang <= Result.Max &&
"Expected valid DWARF language");
5024 Result.assign(Lang);
5031 DwarfSourceLangNameField &Result) {
5033 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5036 return tokError(
"expected DWARF source language name");
5040 return tokError(
"invalid DWARF source language name" +
Twine(
" '") +
5041 Lex.getStrVal() +
"'");
5042 assert(Lang <= Result.Max &&
"Expected valid DWARF source language name");
5043 Result.assign(Lang);
5051 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5054 return tokError(
"expected DWARF calling convention");
5058 return tokError(
"invalid DWARF calling convention" +
Twine(
" '") +
5059 Lex.getStrVal() +
"'");
5060 assert(CC <= Result.Max &&
"Expected valid DWARF calling convention");
5068 EmissionKindField &Result) {
5070 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5073 return tokError(
"expected emission kind");
5077 return tokError(
"invalid emission kind" +
Twine(
" '") + Lex.getStrVal() +
5079 assert(*Kind <= Result.Max &&
"Expected valid emission kind");
5080 Result.assign(*Kind);
5087 FixedPointKindField &Result) {
5089 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5092 return tokError(
"expected fixed-point kind");
5096 return tokError(
"invalid fixed-point kind" +
Twine(
" '") + Lex.getStrVal() +
5098 assert(*Kind <= Result.Max &&
"Expected valid fixed-point kind");
5099 Result.assign(*Kind);
5106 NameTableKindField &Result) {
5108 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5111 return tokError(
"expected nameTable kind");
5115 return tokError(
"invalid nameTable kind" +
Twine(
" '") + Lex.getStrVal() +
5117 assert(((
unsigned)*Kind) <= Result.Max &&
"Expected valid nameTable kind");
5118 Result.assign((
unsigned)*Kind);
5125 DwarfAttEncodingField &Result) {
5127 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5130 return tokError(
"expected DWARF type attribute encoding");
5134 return tokError(
"invalid DWARF type attribute encoding" +
Twine(
" '") +
5135 Lex.getStrVal() +
"'");
5136 assert(Encoding <= Result.Max &&
"Expected valid DWARF language");
5137 Result.assign(Encoding);
5151 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
5153 bool Res = parseUInt32(TempVal);
5159 return tokError(
"expected debug info flag");
5163 return tokError(
Twine(
"invalid debug info flag '") + Lex.getStrVal() +
5178 Result.assign(Combined);
5191 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
5193 bool Res = parseUInt32(TempVal);
5199 return tokError(
"expected debug info flag");
5203 return tokError(
Twine(
"invalid subprogram debug info flag '") +
5204 Lex.getStrVal() +
"'");
5218 Result.assign(Combined);
5225 return tokError(
"expected signed integer");
5227 auto &S = Lex.getAPSIntVal();
5229 return tokError(
"value for '" + Name +
"' too small, limit is " +
5232 return tokError(
"value for '" + Name +
"' too large, limit is " +
5234 Result.assign(S.getExtValue());
5235 assert(Result.Val >= Result.Min &&
"Expected value in range");
5236 assert(Result.Val <= Result.Max &&
"Expected value in range");
5243 switch (Lex.getKind()) {
5245 return tokError(
"expected 'true' or 'false'");
5247 Result.assign(
true);
5250 Result.assign(
false);
5260 if (!Result.AllowNull)
5261 return tokError(
"'" + Name +
"' cannot be null");
5263 Result.assign(
nullptr);
5268 if (parseMetadata(MD,
nullptr))
5277 MDSignedOrMDField &Result) {
5280 MDSignedField Res = Result.A;
5281 if (!parseMDField(
Loc, Name, Res)) {
5289 MDField Res = Result.B;
5290 if (!parseMDField(
Loc, Name, Res)) {
5300 MDUnsignedOrMDField &Result) {
5303 MDUnsignedField Res = Result.A;
5304 if (!parseMDField(
Loc, Name, Res)) {
5312 MDField Res = Result.B;
5313 if (!parseMDField(
Loc, Name, Res)) {
5323 LocTy ValueLoc = Lex.getLoc();
5325 if (parseStringConstant(S))
5329 switch (Result.EmptyIs) {
5330 case MDStringField::EmptyIs::Null:
5331 Result.assign(
nullptr);
5333 case MDStringField::EmptyIs::Empty:
5335 case MDStringField::EmptyIs::Error:
5336 return error(ValueLoc,
"'" + Name +
"' cannot be empty");
5347 if (parseMDNodeVector(MDs))
5350 Result.assign(std::move(MDs));
5356 ChecksumKindField &Result) {
5357 std::optional<DIFile::ChecksumKind> CSKind =
5361 return tokError(
"invalid checksum kind" +
Twine(
" '") + Lex.getStrVal() +
5364 Result.assign(*CSKind);
5371template <
class ParserTy>
5372bool LLParser::parseMDFieldsImplBody(ParserTy ParseField) {
5375 return tokError(
"expected field label here");
5384template <
class ParserTy>
5385bool LLParser::parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc) {
5392 if (parseMDFieldsImplBody(ParseField))
5395 ClosingLoc = Lex.getLoc();
5399template <
class FieldTy>
5400bool LLParser::parseMDField(
StringRef Name, FieldTy &Result) {
5402 return tokError(
"field '" + Name +
"' cannot be specified more than once");
5404 LocTy Loc = Lex.getLoc();
5406 return parseMDField(Loc, Name, Result);
5409bool LLParser::parseSpecializedMDNode(
MDNode *&
N,
bool IsDistinct) {
5412#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
5413 if (Lex.getStrVal() == #CLASS) \
5414 return parse##CLASS(N, IsDistinct);
5415#include "llvm/IR/Metadata.def"
5417 return tokError(
"expected metadata type");
5420#define DECLARE_FIELD(NAME, TYPE, INIT) TYPE NAME INIT
5421#define NOP_FIELD(NAME, TYPE, INIT)
5422#define REQUIRE_FIELD(NAME, TYPE, INIT) \
5424 return error(ClosingLoc, "missing required field '" #NAME "'");
5425#define PARSE_MD_FIELD(NAME, TYPE, DEFAULT) \
5426 if (Lex.getStrVal() == #NAME) \
5427 return parseMDField(#NAME, NAME);
5428#define PARSE_MD_FIELDS() \
5429 VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD) \
5432 if (parseMDFieldsImpl( \
5434 VISIT_MD_FIELDS(PARSE_MD_FIELD, PARSE_MD_FIELD) \
5435 return tokError(Twine("invalid field '") + Lex.getStrVal() + \
5440 VISIT_MD_FIELDS(NOP_FIELD, REQUIRE_FIELD) \
5442#define GET_OR_DISTINCT(CLASS, ARGS) \
5443 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
5448bool LLParser::parseDILocation(
MDNode *&Result,
bool IsDistinct) {
5449#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5450 OPTIONAL(line, LineField, ); \
5451 OPTIONAL(column, ColumnField, ); \
5452 REQUIRED(scope, MDField, ( false)); \
5453 OPTIONAL(inlinedAt, MDField, ); \
5454 OPTIONAL(isImplicitCode, MDBoolField, (false)); \
5455 OPTIONAL(atomGroup, MDUnsignedField, (0, UINT64_MAX)); \
5456 OPTIONAL(atomRank, MDUnsignedField, (0, UINT8_MAX));
5458#undef VISIT_MD_FIELDS
5461 DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val,
5462 isImplicitCode.Val, atomGroup.Val, atomRank.Val));
5468bool LLParser::parseDIAssignID(
MDNode *&Result,
bool IsDistinct) {
5470 return tokError(
"missing 'distinct', required for !DIAssignID()");
5486bool LLParser::parseGenericDINode(
MDNode *&Result,
bool IsDistinct) {
5487#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5488 REQUIRED(tag, DwarfTagField, ); \
5489 OPTIONAL(header, MDStringField, ); \
5490 OPTIONAL(operands, MDFieldList, );
5492#undef VISIT_MD_FIELDS
5495 (Context, tag.Val, header.Val, operands.Val));
5504bool LLParser::parseDISubrangeType(
MDNode *&Result,
bool IsDistinct) {
5505#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5506 OPTIONAL(name, MDStringField, ); \
5507 OPTIONAL(file, MDField, ); \
5508 OPTIONAL(line, LineField, ); \
5509 OPTIONAL(scope, MDField, ); \
5510 OPTIONAL(baseType, MDField, ); \
5511 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5512 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5513 OPTIONAL(flags, DIFlagField, ); \
5514 OPTIONAL(lowerBound, MDSignedOrMDField, ); \
5515 OPTIONAL(upperBound, MDSignedOrMDField, ); \
5516 OPTIONAL(stride, MDSignedOrMDField, ); \
5517 OPTIONAL(bias, MDSignedOrMDField, );
5519#undef VISIT_MD_FIELDS
5521 auto convToMetadata = [&](MDSignedOrMDField Bound) ->
Metadata * {
5522 if (Bound.isMDSignedField())
5525 if (Bound.isMDField())
5526 return Bound.getMDFieldValue();
5530 Metadata *LowerBound = convToMetadata(lowerBound);
5532 Metadata *Stride = convToMetadata(stride);
5533 Metadata *Bias = convToMetadata(bias);
5536 DISubrangeType, (Context,
name.Val,
file.Val, line.Val, scope.Val,
5537 size.getValueAsMetadata(Context), align.Val, flags.Val,
5538 baseType.Val, LowerBound, UpperBound, Stride, Bias));
5547bool LLParser::parseDISubrange(
MDNode *&Result,
bool IsDistinct) {
5548#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5549 OPTIONAL(count, MDSignedOrMDField, (-1, -1, INT64_MAX, false)); \
5550 OPTIONAL(lowerBound, MDSignedOrMDField, ); \
5551 OPTIONAL(upperBound, MDSignedOrMDField, ); \
5552 OPTIONAL(stride, MDSignedOrMDField, );
5554#undef VISIT_MD_FIELDS
5561 auto convToMetadata = [&](
const MDSignedOrMDField &Bound) ->
Metadata * {
5562 if (Bound.isMDSignedField())
5565 if (Bound.isMDField())
5566 return Bound.getMDFieldValue();
5571 LowerBound = convToMetadata(lowerBound);
5573 Stride = convToMetadata(stride);
5576 (Context,
Count, LowerBound, UpperBound, Stride));
5584bool LLParser::parseDIGenericSubrange(
MDNode *&Result,
bool IsDistinct) {
5585#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5586 OPTIONAL(count, MDSignedOrMDField, ); \
5587 OPTIONAL(lowerBound, MDSignedOrMDField, ); \
5588 OPTIONAL(upperBound, MDSignedOrMDField, ); \
5589 OPTIONAL(stride, MDSignedOrMDField, );
5591#undef VISIT_MD_FIELDS
5593 auto ConvToMetadata = [&](
const MDSignedOrMDField &Bound) ->
Metadata * {
5594 if (Bound.isMDSignedField())
5596 Context, {dwarf::DW_OP_consts,
5597 static_cast<uint64_t
>(Bound.getMDSignedValue())});
5598 if (Bound.isMDField())
5599 return Bound.getMDFieldValue();
5604 Metadata *LowerBound = ConvToMetadata(lowerBound);
5606 Metadata *Stride = ConvToMetadata(stride);
5609 (Context,
Count, LowerBound, UpperBound, Stride));
5616bool LLParser::parseDIEnumerator(
MDNode *&Result,
bool IsDistinct) {
5617#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5618 REQUIRED(name, MDStringField, ); \
5619 REQUIRED(value, MDAPSIntField, ); \
5620 OPTIONAL(isUnsigned, MDBoolField, (false));
5622#undef VISIT_MD_FIELDS
5624 if (isUnsigned.Val && value.Val.isNegative())
5625 return tokError(
"unsigned enumerator with negative value");
5630 if (!isUnsigned.Val && value.Val.isUnsigned() && value.Val.isSignBitSet())
5642bool LLParser::parseDIBasicType(
MDNode *&Result,
bool IsDistinct) {
5643#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5644 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
5645 OPTIONAL(name, MDStringField, ); \
5646 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5647 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5648 OPTIONAL(dataSize, MDUnsignedField, (0, UINT32_MAX)); \
5649 OPTIONAL(encoding, DwarfAttEncodingField, ); \
5650 OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
5651 OPTIONAL(flags, DIFlagField, );
5653#undef VISIT_MD_FIELDS
5657 (Context, tag.Val,
name.Val,
size.getValueAsMetadata(Context), align.Val,
5658 encoding.Val, num_extra_inhabitants.Val, dataSize.Val, flags.Val));
5667bool LLParser::parseDIFixedPointType(
MDNode *&Result,
bool IsDistinct) {
5668#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5669 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
5670 OPTIONAL(name, MDStringField, ); \
5671 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5672 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5673 OPTIONAL(encoding, DwarfAttEncodingField, ); \
5674 OPTIONAL(flags, DIFlagField, ); \
5675 OPTIONAL(kind, FixedPointKindField, ); \
5676 OPTIONAL(factor, MDSignedField, ); \
5677 OPTIONAL(numerator, MDAPSIntField, ); \
5678 OPTIONAL(denominator, MDAPSIntField, );
5680#undef VISIT_MD_FIELDS
5683 (Context, tag.Val,
name.Val,
5684 size.getValueAsMetadata(Context), align.Val,
5685 encoding.Val, flags.Val, kind.Val, factor.Val,
5686 numerator.Val, denominator.Val));
5692bool LLParser::parseDIStringType(
MDNode *&Result,
bool IsDistinct) {
5693#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5694 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_string_type)); \
5695 OPTIONAL(name, MDStringField, ); \
5696 OPTIONAL(stringLength, MDField, ); \
5697 OPTIONAL(stringLengthExpression, MDField, ); \
5698 OPTIONAL(stringLocationExpression, MDField, ); \
5699 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5700 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5701 OPTIONAL(encoding, DwarfAttEncodingField, );
5703#undef VISIT_MD_FIELDS
5707 (Context, tag.Val,
name.Val, stringLength.Val, stringLengthExpression.Val,
5708 stringLocationExpression.Val,
size.getValueAsMetadata(Context),
5709 align.Val, encoding.Val));
5722bool LLParser::parseDIDerivedType(
MDNode *&Result,
bool IsDistinct) {
5723#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5724 REQUIRED(tag, DwarfTagField, ); \
5725 OPTIONAL(name, MDStringField, ); \
5726 OPTIONAL(file, MDField, ); \
5727 OPTIONAL(line, LineField, ); \
5728 OPTIONAL(scope, MDField, ); \
5729 REQUIRED(baseType, MDField, ); \
5730 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5731 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5732 OPTIONAL(offset, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5733 OPTIONAL(flags, DIFlagField, ); \
5734 OPTIONAL(extraData, MDField, ); \
5735 OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); \
5736 OPTIONAL(annotations, MDField, ); \
5737 OPTIONAL(ptrAuthKey, MDUnsignedField, (0, 7)); \
5738 OPTIONAL(ptrAuthIsAddressDiscriminated, MDBoolField, ); \
5739 OPTIONAL(ptrAuthExtraDiscriminator, MDUnsignedField, (0, 0xffff)); \
5740 OPTIONAL(ptrAuthIsaPointer, MDBoolField, ); \
5741 OPTIONAL(ptrAuthAuthenticatesNullValues, MDBoolField, );
5743#undef VISIT_MD_FIELDS
5745 std::optional<unsigned> DWARFAddressSpace;
5746 if (dwarfAddressSpace.Val != UINT32_MAX)
5747 DWARFAddressSpace = dwarfAddressSpace.Val;
5748 std::optional<DIDerivedType::PtrAuthData> PtrAuthData;
5750 PtrAuthData.emplace(
5751 (
unsigned)ptrAuthKey.Val, ptrAuthIsAddressDiscriminated.Val,
5752 (
unsigned)ptrAuthExtraDiscriminator.Val, ptrAuthIsaPointer.Val,
5753 ptrAuthAuthenticatesNullValues.Val);
5756 DIDerivedType, (Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val,
5757 baseType.Val,
size.getValueAsMetadata(Context), align.Val,
5758 offset.getValueAsMetadata(Context), DWARFAddressSpace,
5759 PtrAuthData, flags.Val, extraData.Val, annotations.Val));
5763bool LLParser::parseDICompositeType(
MDNode *&Result,
bool IsDistinct) {
5764#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5765 REQUIRED(tag, DwarfTagField, ); \
5766 OPTIONAL(name, MDStringField, ); \
5767 OPTIONAL(file, MDField, ); \
5768 OPTIONAL(line, LineField, ); \
5769 OPTIONAL(scope, MDField, ); \
5770 OPTIONAL(baseType, MDField, ); \
5771 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5772 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5773 OPTIONAL(offset, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5774 OPTIONAL(flags, DIFlagField, ); \
5775 OPTIONAL(elements, MDField, ); \
5776 OPTIONAL(runtimeLang, DwarfLangField, ); \
5777 OPTIONAL(enumKind, DwarfEnumKindField, ); \
5778 OPTIONAL(vtableHolder, MDField, ); \
5779 OPTIONAL(templateParams, MDField, ); \
5780 OPTIONAL(identifier, MDStringField, ); \
5781 OPTIONAL(discriminator, MDField, ); \
5782 OPTIONAL(dataLocation, MDField, ); \
5783 OPTIONAL(associated, MDField, ); \
5784 OPTIONAL(allocated, MDField, ); \
5785 OPTIONAL(rank, MDSignedOrMDField, ); \
5786 OPTIONAL(annotations, MDField, ); \
5787 OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
5788 OPTIONAL(specification, MDField, ); \
5789 OPTIONAL(bitStride, MDField, );
5791#undef VISIT_MD_FIELDS
5794 if (rank.isMDSignedField())
5797 else if (rank.isMDField())
5798 Rank = rank.getMDFieldValue();
5800 std::optional<unsigned> EnumKind;
5802 EnumKind = enumKind.Val;
5807 Context, *identifier.Val, tag.Val,
name.Val,
file.Val, line.Val,
5808 scope.Val, baseType.Val,
size.getValueAsMetadata(Context),
5809 align.Val, offset.getValueAsMetadata(Context), specification.Val,
5810 num_extra_inhabitants.Val, flags.Val, elements.Val, runtimeLang.Val,
5811 EnumKind, vtableHolder.Val, templateParams.Val, discriminator.Val,
5812 dataLocation.Val, associated.Val, allocated.Val, Rank,
5813 annotations.Val, bitStride.Val)) {
5822 (Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val, baseType.Val,
5823 size.getValueAsMetadata(Context), align.Val,
5824 offset.getValueAsMetadata(Context), flags.Val, elements.Val,
5825 runtimeLang.Val, EnumKind, vtableHolder.Val, templateParams.Val,
5826 identifier.Val, discriminator.Val, dataLocation.Val, associated.Val,
5827 allocated.Val, Rank, annotations.Val, specification.Val,
5828 num_extra_inhabitants.Val, bitStride.Val));
5832bool LLParser::parseDISubroutineType(
MDNode *&Result,
bool IsDistinct) {
5833#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5834 OPTIONAL(flags, DIFlagField, ); \
5835 OPTIONAL(cc, DwarfCCField, ); \
5836 REQUIRED(types, MDField, );
5838#undef VISIT_MD_FIELDS
5841 (Context, flags.Val, cc.Val, types.Val));
5850bool LLParser::parseDIFile(
MDNode *&Result,
bool IsDistinct) {
5854#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5855 REQUIRED(filename, MDStringField, ); \
5856 REQUIRED(directory, MDStringField, ); \
5857 OPTIONAL(checksumkind, ChecksumKindField, (DIFile::CSK_MD5)); \
5858 OPTIONAL(checksum, MDStringField, ); \
5859 OPTIONAL(source, MDStringField, (MDStringField::EmptyIs::Empty));
5861#undef VISIT_MD_FIELDS
5863 std::optional<DIFile::ChecksumInfo<MDString *>> OptChecksum;
5864 if (checksumkind.Seen && checksum.Seen)
5865 OptChecksum.emplace(checksumkind.Val, checksum.Val);
5866 else if (checksumkind.Seen || checksum.Seen)
5867 return tokError(
"'checksumkind' and 'checksum' must be provided together");
5869 MDString *
Source =
nullptr;
5873 DIFile, (Context,
filename.Val, directory.Val, OptChecksum, Source));
5884bool LLParser::parseDICompileUnit(
MDNode *&Result,
bool IsDistinct) {
5886 return tokError(
"missing 'distinct', required for !DICompileUnit");
5888 LocTy Loc = Lex.getLoc();
5890#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5891 REQUIRED(file, MDField, ( false)); \
5892 OPTIONAL(language, DwarfLangField, ); \
5893 OPTIONAL(sourceLanguageName, DwarfSourceLangNameField, ); \
5894 OPTIONAL(sourceLanguageVersion, MDUnsignedField, (0, UINT32_MAX)); \
5895 OPTIONAL(producer, MDStringField, ); \
5896 OPTIONAL(isOptimized, MDBoolField, ); \
5897 OPTIONAL(flags, MDStringField, ); \
5898 OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \
5899 OPTIONAL(splitDebugFilename, MDStringField, ); \
5900 OPTIONAL(emissionKind, EmissionKindField, ); \
5901 OPTIONAL(enums, MDField, ); \
5902 OPTIONAL(retainedTypes, MDField, ); \
5903 OPTIONAL(globals, MDField, ); \
5904 OPTIONAL(imports, MDField, ); \
5905 OPTIONAL(macros, MDField, ); \
5906 OPTIONAL(dwoId, MDUnsignedField, ); \
5907 OPTIONAL(splitDebugInlining, MDBoolField, = true); \
5908 OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
5909 OPTIONAL(nameTableKind, NameTableKindField, ); \
5910 OPTIONAL(rangesBaseAddress, MDBoolField, = false); \
5911 OPTIONAL(sysroot, MDStringField, ); \
5912 OPTIONAL(sdk, MDStringField, );
5914#undef VISIT_MD_FIELDS
5916 if (!language.Seen && !sourceLanguageName.Seen)
5917 return error(Loc,
"missing one of 'language' or 'sourceLanguageName', "
5918 "required for !DICompileUnit");
5920 if (language.Seen && sourceLanguageName.Seen)
5921 return error(Loc,
"can only specify one of 'language' and "
5922 "'sourceLanguageName' on !DICompileUnit");
5924 if (sourceLanguageVersion.Seen && !sourceLanguageName.Seen)
5925 return error(Loc,
"'sourceLanguageVersion' requires an associated "
5926 "'sourceLanguageName' on !DICompileUnit");
5930 language.Seen ? DISourceLanguageName(language.Val)
5931 : DISourceLanguageName(sourceLanguageName.Val,
5932 sourceLanguageVersion.Val),
5933 file.Val, producer.Val, isOptimized.Val, flags.Val, runtimeVersion.Val,
5934 splitDebugFilename.Val, emissionKind.Val, enums.Val, retainedTypes.Val,
5935 globals.Val, imports.Val, macros.Val, dwoId.Val, splitDebugInlining.Val,
5936 debugInfoForProfiling.Val, nameTableKind.Val, rangesBaseAddress.Val,
5937 sysroot.Val, sdk.Val);
5950bool LLParser::parseDISubprogram(
MDNode *&Result,
bool IsDistinct) {
5951 auto Loc = Lex.getLoc();
5952#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5953 OPTIONAL(scope, MDField, ); \
5954 OPTIONAL(name, MDStringField, ); \
5955 OPTIONAL(linkageName, MDStringField, ); \
5956 OPTIONAL(file, MDField, ); \
5957 OPTIONAL(line, LineField, ); \
5958 OPTIONAL(type, MDField, ); \
5959 OPTIONAL(isLocal, MDBoolField, ); \
5960 OPTIONAL(isDefinition, MDBoolField, (true)); \
5961 OPTIONAL(scopeLine, LineField, ); \
5962 OPTIONAL(containingType, MDField, ); \
5963 OPTIONAL(virtuality, DwarfVirtualityField, ); \
5964 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \
5965 OPTIONAL(thisAdjustment, MDSignedField, (0, INT32_MIN, INT32_MAX)); \
5966 OPTIONAL(flags, DIFlagField, ); \
5967 OPTIONAL(spFlags, DISPFlagField, ); \
5968 OPTIONAL(isOptimized, MDBoolField, ); \
5969 OPTIONAL(unit, MDField, ); \
5970 OPTIONAL(templateParams, MDField, ); \
5971 OPTIONAL(declaration, MDField, ); \
5972 OPTIONAL(retainedNodes, MDField, ); \
5973 OPTIONAL(thrownTypes, MDField, ); \
5974 OPTIONAL(annotations, MDField, ); \
5975 OPTIONAL(targetFuncName, MDStringField, ); \
5976 OPTIONAL(keyInstructions, MDBoolField, );
5978#undef VISIT_MD_FIELDS
5983 spFlags.Seen ? spFlags.Val
5985 isOptimized.Val, virtuality.Val);
5986 if ((SPFlags & DISubprogram::SPFlagDefinition) && !IsDistinct)
5989 "missing 'distinct', required for !DISubprogram that is a Definition");
5992 (Context, scope.Val,
name.Val, linkageName.Val,
file.Val, line.Val,
5993 type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val,
5994 thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val,
5995 declaration.Val, retainedNodes.Val, thrownTypes.Val, annotations.Val,
5996 targetFuncName.Val, keyInstructions.Val));
6002bool LLParser::parseDILexicalBlock(
MDNode *&Result,
bool IsDistinct) {
6003#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6004 REQUIRED(scope, MDField, ( false)); \
6005 OPTIONAL(file, MDField, ); \
6006 OPTIONAL(line, LineField, ); \
6007 OPTIONAL(column, ColumnField, );
6009#undef VISIT_MD_FIELDS
6012 DILexicalBlock, (Context, scope.Val,
file.Val, line.Val, column.Val));
6018bool LLParser::parseDILexicalBlockFile(
MDNode *&Result,
bool IsDistinct) {
6019#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6020 REQUIRED(scope, MDField, ( false)); \
6021 OPTIONAL(file, MDField, ); \
6022 REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX));
6024#undef VISIT_MD_FIELDS
6027 (Context, scope.Val,
file.Val, discriminator.Val));
6033bool LLParser::parseDICommonBlock(
MDNode *&Result,
bool IsDistinct) {
6034#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6035 REQUIRED(scope, MDField, ); \
6036 OPTIONAL(declaration, MDField, ); \
6037 OPTIONAL(name, MDStringField, ); \
6038 OPTIONAL(file, MDField, ); \
6039 OPTIONAL(line, LineField, );
6041#undef VISIT_MD_FIELDS
6044 (Context, scope.Val, declaration.Val,
name.Val,
6045 file.Val, line.Val));
6051bool LLParser::parseDINamespace(
MDNode *&Result,
bool IsDistinct) {
6052#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6053 REQUIRED(scope, MDField, ); \
6054 OPTIONAL(name, MDStringField, ); \
6055 OPTIONAL(exportSymbols, MDBoolField, );
6057#undef VISIT_MD_FIELDS
6060 (Context, scope.Val,
name.Val, exportSymbols.Val));
6067bool LLParser::parseDIMacro(
MDNode *&Result,
bool IsDistinct) {
6068#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6069 REQUIRED(type, DwarfMacinfoTypeField, ); \
6070 OPTIONAL(line, LineField, ); \
6071 REQUIRED(name, MDStringField, ); \
6072 OPTIONAL(value, MDStringField, );
6074#undef VISIT_MD_FIELDS
6077 (Context, type.Val, line.Val,
name.Val, value.Val));
6083bool LLParser::parseDIMacroFile(
MDNode *&Result,
bool IsDistinct) {
6084#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6085 OPTIONAL(type, DwarfMacinfoTypeField, (dwarf::DW_MACINFO_start_file)); \
6086 OPTIONAL(line, LineField, ); \
6087 REQUIRED(file, MDField, ); \
6088 OPTIONAL(nodes, MDField, );
6090#undef VISIT_MD_FIELDS
6093 (Context, type.Val, line.Val,
file.Val,
nodes.Val));
6101bool LLParser::parseDIModule(
MDNode *&Result,
bool IsDistinct) {
6102#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6103 REQUIRED(scope, MDField, ); \
6104 REQUIRED(name, MDStringField, ); \
6105 OPTIONAL(configMacros, MDStringField, ); \
6106 OPTIONAL(includePath, MDStringField, ); \
6107 OPTIONAL(apinotes, MDStringField, ); \
6108 OPTIONAL(file, MDField, ); \
6109 OPTIONAL(line, LineField, ); \
6110 OPTIONAL(isDecl, MDBoolField, );
6112#undef VISIT_MD_FIELDS
6115 configMacros.Val, includePath.Val,
6116 apinotes.Val, line.Val, isDecl.Val));
6122bool LLParser::parseDITemplateTypeParameter(
MDNode *&Result,
bool IsDistinct) {
6123#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6124 OPTIONAL(name, MDStringField, ); \
6125 REQUIRED(type, MDField, ); \
6126 OPTIONAL(defaulted, MDBoolField, );
6128#undef VISIT_MD_FIELDS
6131 (Context,
name.Val, type.Val, defaulted.Val));
6139bool LLParser::parseDITemplateValueParameter(
MDNode *&Result,
bool IsDistinct) {
6140#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6141 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_template_value_parameter)); \
6142 OPTIONAL(name, MDStringField, ); \
6143 OPTIONAL(type, MDField, ); \
6144 OPTIONAL(defaulted, MDBoolField, ); \
6145 REQUIRED(value, MDField, );
6148#undef VISIT_MD_FIELDS
6151 DITemplateValueParameter,
6152 (Context, tag.Val,
name.Val, type.Val, defaulted.Val, value.Val));
6161bool LLParser::parseDIGlobalVariable(
MDNode *&Result,
bool IsDistinct) {
6162#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6163 OPTIONAL(name, MDStringField, (MDStringField::EmptyIs::Error)); \
6164 OPTIONAL(scope, MDField, ); \
6165 OPTIONAL(linkageName, MDStringField, ); \
6166 OPTIONAL(file, MDField, ); \
6167 OPTIONAL(line, LineField, ); \
6168 OPTIONAL(type, MDField, ); \
6169 OPTIONAL(isLocal, MDBoolField, ); \
6170 OPTIONAL(isDefinition, MDBoolField, (true)); \
6171 OPTIONAL(templateParams, MDField, ); \
6172 OPTIONAL(declaration, MDField, ); \
6173 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
6174 OPTIONAL(annotations, MDField, );
6176#undef VISIT_MD_FIELDS
6180 (Context, scope.Val,
name.Val, linkageName.Val,
file.Val,
6181 line.Val, type.Val, isLocal.Val, isDefinition.Val,
6182 declaration.Val, templateParams.Val, align.Val,
6194bool LLParser::parseDILocalVariable(
MDNode *&Result,
bool IsDistinct) {
6195#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6196 REQUIRED(scope, MDField, ( false)); \
6197 OPTIONAL(name, MDStringField, ); \
6198 OPTIONAL(arg, MDUnsignedField, (0, UINT16_MAX)); \
6199 OPTIONAL(file, MDField, ); \
6200 OPTIONAL(line, LineField, ); \
6201 OPTIONAL(type, MDField, ); \
6202 OPTIONAL(flags, DIFlagField, ); \
6203 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
6204 OPTIONAL(annotations, MDField, );
6206#undef VISIT_MD_FIELDS
6209 (Context, scope.Val,
name.Val,
file.Val, line.Val,
6210 type.Val, arg.Val, flags.Val, align.Val,
6217bool LLParser::parseDILabel(
MDNode *&Result,
bool IsDistinct) {
6218#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6219 REQUIRED(scope, MDField, ( false)); \
6220 REQUIRED(name, MDStringField, ); \
6221 REQUIRED(file, MDField, ); \
6222 REQUIRED(line, LineField, ); \
6223 OPTIONAL(column, ColumnField, ); \
6224 OPTIONAL(isArtificial, MDBoolField, ); \
6225 OPTIONAL(coroSuspendIdx, MDUnsignedField, );
6227#undef VISIT_MD_FIELDS
6229 std::optional<unsigned> CoroSuspendIdx =
6230 coroSuspendIdx.Seen ? std::optional<unsigned>(coroSuspendIdx.Val)
6234 (Context, scope.Val,
name.Val,
file.Val, line.Val,
6235 column.Val, isArtificial.Val, CoroSuspendIdx));
6241bool LLParser::parseDIExpressionBody(
MDNode *&Result,
bool IsDistinct) {
6254 return tokError(Twine(
"invalid DWARF op '") + Lex.getStrVal() +
"'");
6263 return tokError(Twine(
"invalid DWARF attribute encoding '") +
6264 Lex.getStrVal() +
"'");
6267 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
6268 return tokError(
"expected unsigned integer");
6270 auto &
U = Lex.getAPSIntVal();
6272 return tokError(
"element too large, limit is " + Twine(
UINT64_MAX));
6286bool LLParser::parseDIExpression(
MDNode *&Result,
bool IsDistinct) {
6288 assert(Lex.getStrVal() ==
"DIExpression" &&
"Expected '!DIExpression'");
6291 return parseDIExpressionBody(Result, IsDistinct);
6296bool LLParser::parseDIArgList(
Metadata *&MD, PerFunctionState *PFS) {
6297 assert(PFS &&
"Expected valid function state");
6308 if (parseValueAsMetadata(MD,
"expected value-as-metadata operand", PFS))
6322bool LLParser::parseDIGlobalVariableExpression(
MDNode *&Result,
6324#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6325 REQUIRED(var, MDField, ); \
6326 REQUIRED(expr, MDField, );
6328#undef VISIT_MD_FIELDS
6331 GET_OR_DISTINCT(DIGlobalVariableExpression, (Context, var.Val, expr.Val));
6338bool LLParser::parseDIObjCProperty(
MDNode *&Result,
bool IsDistinct) {
6339#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6340 OPTIONAL(name, MDStringField, ); \
6341 OPTIONAL(file, MDField, ); \
6342 OPTIONAL(line, LineField, ); \
6343 OPTIONAL(setter, MDStringField, ); \
6344 OPTIONAL(getter, MDStringField, ); \
6345 OPTIONAL(attributes, MDUnsignedField, (0, UINT32_MAX)); \
6346 OPTIONAL(type, MDField, );
6348#undef VISIT_MD_FIELDS
6351 (Context,
name.Val,
file.Val, line.Val, getter.Val,
6352 setter.Val, attributes.Val, type.Val));
6359bool LLParser::parseDIImportedEntity(
MDNode *&Result,
bool IsDistinct) {
6360#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6361 REQUIRED(tag, DwarfTagField, ); \
6362 REQUIRED(scope, MDField, ); \
6363 OPTIONAL(entity, MDField, ); \
6364 OPTIONAL(file, MDField, ); \
6365 OPTIONAL(line, LineField, ); \
6366 OPTIONAL(name, MDStringField, ); \
6367 OPTIONAL(elements, MDField, );
6369#undef VISIT_MD_FIELDS
6372 (Context, tag.Val, scope.Val, entity.Val,
file.Val,
6373 line.Val,
name.Val, elements.Val));
6377#undef PARSE_MD_FIELD
6389bool LLParser::parseMetadataAsValue(
Value *&V, PerFunctionState &PFS) {
6392 if (parseMetadata(MD, &PFS))
6403bool LLParser::parseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
6404 PerFunctionState *PFS) {
6407 if (parseType(Ty, TypeMsg, Loc))
6410 return error(Loc,
"invalid metadata-value-metadata roundtrip");
6413 if (parseValue(Ty, V, PFS))
6428bool LLParser::parseMetadata(
Metadata *&MD, PerFunctionState *PFS) {
6432 if (Lex.getStrVal() ==
"DIArgList") {
6434 if (parseDIArgList(AL, PFS))
6440 if (parseSpecializedMDNode(
N)) {
6450 return parseValueAsMetadata(MD,
"expected metadata operand", PFS);
6460 if (parseMDString(S))
6470 if (parseMDNodeTail(
N))
6481 PerFunctionState *PFS) {
6483 return error(
ID.Loc,
"functions are not values, refer to them as pointers");
6488 return error(
ID.Loc,
"invalid use of function-local name");
6489 V = PFS->getVal(
ID.UIntVal, Ty,
ID.Loc);
6490 return V ==
nullptr;
6493 return error(
ID.Loc,
"invalid use of function-local name");
6494 V = PFS->getVal(
ID.StrVal, Ty,
ID.Loc);
6495 return V ==
nullptr;
6498 return error(
ID.Loc,
"invalid type for inline asm constraint string");
6502 ID.FTy,
ID.StrVal,
ID.StrVal2,
ID.UIntVal & 1, (
ID.UIntVal >> 1) & 1,
6507 V = getGlobalVal(
ID.StrVal, Ty,
ID.Loc);
6510 return V ==
nullptr;
6512 V = getGlobalVal(
ID.UIntVal, Ty,
ID.Loc);
6515 return V ==
nullptr;
6518 return error(
ID.Loc,
"integer constant must have integer type");
6520 V = ConstantInt::get(Context,
ID.APSIntVal);
6525 return error(
ID.Loc,
"floating point constant invalid for type");
6531 bool IsSNAN =
ID.APFloatVal.isSignaling();
6546 APInt Payload =
ID.APFloatVal.bitcastToAPInt();
6548 ID.APFloatVal.isNegative(), &Payload);
6551 V = ConstantFP::get(Context,
ID.APFloatVal);
6553 if (
V->getType() != Ty)
6554 return error(
ID.Loc,
"floating point constant does not have type '" +
6560 return error(
ID.Loc,
"null must be a pointer type");
6566 return error(
ID.Loc,
"invalid type for undef constant");
6571 return error(
ID.Loc,
"invalid empty array initializer");
6577 return error(
ID.Loc,
"invalid type for null constant");
6580 return error(
ID.Loc,
"invalid type for null constant");
6585 return error(
ID.Loc,
"invalid type for none constant");
6591 return error(
ID.Loc,
"invalid type for poison constant");
6595 if (
ID.ConstantVal->getType() != Ty)
6596 return error(
ID.Loc,
"constant expression type mismatch: got type '" +
6603 return error(
ID.Loc,
"vector constant must have vector type");
6605 return error(
ID.Loc,
"constant expression type mismatch: got type '" +
6607 "' but expected '" +
6615 if (
ST->getNumElements() !=
ID.UIntVal)
6617 "initializer with struct type has wrong # elements");
6619 return error(
ID.Loc,
"packed'ness of initializer and type don't match");
6622 for (
unsigned i = 0, e =
ID.UIntVal; i != e; ++i)
6623 if (
ID.ConstantStructElts[i]->getType() !=
ST->getElementType(i))
6626 "element " + Twine(i) +
6627 " of struct initializer doesn't match struct element type");
6630 ST,
ArrayRef(
ID.ConstantStructElts.get(),
ID.UIntVal));
6632 return error(
ID.Loc,
"constant expression type mismatch");
6641 auto Loc = Lex.getLoc();
6642 if (parseValID(
ID,
nullptr))
6655 if (convertValIDToValue(Ty,
ID, V,
nullptr))
6665 return error(Loc,
"expected a constant value");
6669bool LLParser::parseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
6672 return parseValID(
ID, PFS, Ty) ||
6673 convertValIDToValue(Ty,
ID, V, PFS);
6676bool LLParser::parseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
6678 return parseType(Ty) || parseValue(Ty, V, PFS);
6681bool LLParser::parseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &
Loc,
6682 PerFunctionState &PFS) {
6685 if (parseTypeAndValue(V, PFS))
6688 return error(Loc,
"expected a basic block");
6697 if (!Name.starts_with(
"llvm.dbg."))
6700 return FnID == Intrinsic::dbg_declare || FnID == Intrinsic::dbg_value ||
6701 FnID == Intrinsic::dbg_assign;
6709bool LLParser::parseFunctionHeader(
Function *&Fn,
bool IsDefine,
6710 unsigned &FunctionNumber,
6713 LocTy LinkageLoc = Lex.getLoc();
6715 unsigned Visibility;
6716 unsigned DLLStorageClass;
6718 AttrBuilder RetAttrs(M->getContext());
6721 Type *RetType =
nullptr;
6722 LocTy RetTypeLoc = Lex.getLoc();
6723 if (parseOptionalLinkage(
Linkage, HasLinkage, Visibility, DLLStorageClass,
6725 parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
6726 parseType(RetType, RetTypeLoc,
true ))
6735 return error(LinkageLoc,
"invalid linkage for function definition");
6745 return error(LinkageLoc,
"invalid linkage for function declaration");
6749 return error(LinkageLoc,
"invalid function linkage type");
6753 return error(LinkageLoc,
6754 "symbol with local linkage must have default visibility");
6757 return error(LinkageLoc,
6758 "symbol with local linkage cannot have a DLL storage class");
6761 return error(RetTypeLoc,
"invalid function return type");
6763 LocTy NameLoc = Lex.getLoc();
6765 std::string FunctionName;
6767 FunctionName = Lex.getStrVal();
6769 FunctionNumber = Lex.getUIntVal();
6770 if (checkValueID(NameLoc,
"function",
"@", NumberedVals.getNext(),
6774 return tokError(
"expected function name");
6780 return tokError(
"expected '(' in function argument list");
6784 AttrBuilder FuncAttrs(M->getContext());
6785 std::vector<unsigned> FwdRefAttrGrps;
6788 std::string Partition;
6789 MaybeAlign Alignment;
6792 unsigned AddrSpace = 0;
6798 if (parseArgumentList(ArgList, UnnamedArgNums, IsVarArg) ||
6799 parseOptionalUnnamedAddr(UnnamedAddr) ||
6800 parseOptionalProgramAddrSpace(AddrSpace) ||
6801 parseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
6805 parseOptionalComdat(FunctionName,
C) ||
6806 parseOptionalAlignment(Alignment) ||
6807 (EatIfPresent(
lltok::kw_gc) && parseStringConstant(GC)) ||
6811 parseGlobalTypeAndValue(PersonalityFn)))
6814 if (FuncAttrs.contains(Attribute::Builtin))
6815 return error(BuiltinLoc,
"'builtin' attribute not valid on function");
6818 if (MaybeAlign
A = FuncAttrs.getAlignment()) {
6820 FuncAttrs.removeAttribute(Attribute::Alignment);
6825 std::vector<Type*> ParamTypeList;
6828 for (
const ArgInfo &Arg : ArgList) {
6829 ParamTypeList.push_back(Arg.Ty);
6830 Attrs.push_back(Arg.Attrs);
6837 if (PAL.hasParamAttr(0, Attribute::StructRet) && !RetType->
isVoidTy())
6838 return error(RetTypeLoc,
"functions with 'sret' argument must return void");
6844 GlobalValue *FwdFn =
nullptr;
6845 if (!FunctionName.empty()) {
6848 auto FRVI = ForwardRefVals.find(FunctionName);
6849 if (FRVI != ForwardRefVals.end()) {
6850 FwdFn = FRVI->second.first;
6852 return error(FRVI->second.second,
6853 "invalid forward reference to "
6856 "' with wrong type: "
6860 ForwardRefVals.erase(FRVI);
6861 }
else if ((Fn = M->getFunction(FunctionName))) {
6863 return error(NameLoc,
6864 "invalid redefinition of function '" + FunctionName +
"'");
6865 }
else if (M->getNamedValue(FunctionName)) {
6866 return error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
6872 if (FunctionNumber == (
unsigned)-1)
6873 FunctionNumber = NumberedVals.getNext();
6877 auto I = ForwardRefValIDs.find(FunctionNumber);
6878 if (
I != ForwardRefValIDs.end()) {
6879 FwdFn =
I->second.first;
6881 return error(NameLoc,
"type of definition and forward reference of '@" +
6882 Twine(FunctionNumber) +
6887 ForwardRefValIDs.erase(
I);
6896 if (FunctionName.empty())
6897 NumberedVals.add(FunctionNumber, Fn);
6912 if (!
GC.empty()) Fn->
setGC(GC);
6915 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
6919 for (
unsigned i = 0, e = ArgList.size(); i != e; ++i, ++ArgIt) {
6921 if (ArgList[i].
Name.empty())
continue;
6924 ArgIt->
setName(ArgList[i].Name);
6926 if (ArgIt->
getName() != ArgList[i].Name)
6927 return error(ArgList[i].Loc,
6928 "redefinition of argument '%" + ArgList[i].Name +
"'");
6941 if (FunctionName.empty()) {
6943 ID.UIntVal = FunctionNumber;
6946 ID.StrVal = FunctionName;
6948 auto Blocks = ForwardRefBlockAddresses.find(
ID);
6949 if (Blocks != ForwardRefBlockAddresses.end())
6950 return error(Blocks->first.Loc,
6951 "cannot take blockaddress inside a declaration");
6955bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
6957 if (FunctionNumber == -1) {
6959 ID.StrVal = std::string(F.getName());
6962 ID.UIntVal = FunctionNumber;
6965 auto Blocks = P.ForwardRefBlockAddresses.find(
ID);
6966 if (Blocks == P.ForwardRefBlockAddresses.end())
6969 for (
const auto &
I : Blocks->second) {
6970 const ValID &BBID =
I.first;
6971 GlobalValue *GV =
I.second;
6974 "Expected local id or name");
6981 return P.error(BBID.
Loc,
"referenced value is not a basic block");
6984 ResolvedVal = P.checkValidVariableType(BBID.
Loc, BBID.
StrVal, GV->
getType(),
6992 P.ForwardRefBlockAddresses.erase(Blocks);
6998bool LLParser::parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
6999 ArrayRef<unsigned> UnnamedArgNums) {
7001 return tokError(
"expected '{' in function body");
7004 PerFunctionState PFS(*
this, Fn, FunctionNumber, UnnamedArgNums);
7008 if (PFS.resolveForwardRefBlockAddresses())
7014 return tokError(
"function body requires at least one basic block");
7018 if (parseBasicBlock(PFS))
7022 if (parseUseListOrder(&PFS))
7029 return PFS.finishFunction();
7034bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
7035 FileLoc BBStart(Lex.getTokLineColumnPos());
7040 LocTy NameLoc = Lex.getLoc();
7042 Name = Lex.getStrVal();
7045 NameID = Lex.getUIntVal();
7049 BasicBlock *BB = PFS.defineBB(Name, NameID, NameLoc);
7053 std::string NameStr;
7058 auto DeleteDbgRecord = [](DbgRecord *DR) { DR->deleteRecord(); };
7059 using DbgRecordPtr = std::unique_ptr<DbgRecord,
decltype(DeleteDbgRecord)>;
7066 if (SeenOldDbgInfoFormat)
7067 return error(Lex.getLoc(),
"debug record should not appear in a module "
7068 "containing debug info intrinsics");
7069 SeenNewDbgInfoFormat =
true;
7073 if (parseDebugRecord(DR, PFS))
7075 TrailingDbgRecord.emplace_back(DR, DeleteDbgRecord);
7078 FileLoc InstStart(Lex.getTokLineColumnPos());
7081 LocTy NameLoc = Lex.getLoc();
7086 NameID = Lex.getUIntVal();
7088 if (parseToken(
lltok::equal,
"expected '=' after instruction id"))
7091 NameStr = Lex.getStrVal();
7093 if (parseToken(
lltok::equal,
"expected '=' after instruction name"))
7097 switch (parseInstruction(Inst, BB, PFS)) {
7100 case InstError:
return true;
7107 if (parseInstructionMetadata(*Inst))
7110 case InstExtraComma:
7115 if (parseInstructionMetadata(*Inst))
7121 if (PFS.setInstName(NameID, NameStr, NameLoc, Inst))
7125 for (DbgRecordPtr &DR : TrailingDbgRecord)
7127 TrailingDbgRecord.clear();
7128 if (ParserContext) {
7129 ParserContext->addInstructionLocation(
7130 Inst, FileLocRange(InstStart, Lex.getPrevTokEndLineColumnPos()));
7135 ParserContext->addBlockLocation(
7136 BB, FileLocRange(BBStart, Lex.getPrevTokEndLineColumnPos()));
7138 assert(TrailingDbgRecord.empty() &&
7139 "All debug values should have been attached to an instruction.");
7148bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
7151 LocTy DVRLoc = Lex.getLoc();
7153 return error(DVRLoc,
"expected debug record type here");
7154 RecordKind
RecordType = StringSwitch<RecordKind>(Lex.getStrVal())
7155 .Case(
"declare", RecordKind::ValueKind)
7156 .Case(
"value", RecordKind::ValueKind)
7157 .Case(
"assign", RecordKind::ValueKind)
7158 .Case(
"label", RecordKind::LabelKind)
7159 .Case(
"declare_value", RecordKind::ValueKind);
7168 if (parseMDNode(Label))
7173 if (parseMDNode(DbgLoc))
7181 LocType
ValueType = StringSwitch<LocType>(Lex.getStrVal())
7182 .Case(
"declare", LocType::Declare)
7183 .Case(
"value", LocType::Value)
7184 .Case(
"assign", LocType::Assign)
7185 .Case(
"declare_value", LocType::DeclareValue);
7193 if (parseMetadata(ValLocMD, &PFS))
7200 if (parseMDNode(Variable))
7207 if (parseMDNode(Expression))
7213 MDNode *AssignID =
nullptr;
7214 Metadata *AddressLocation =
nullptr;
7215 MDNode *AddressExpression =
nullptr;
7218 if (parseMDNode(AssignID))
7224 if (parseMetadata(AddressLocation, &PFS))
7230 if (parseMDNode(AddressExpression))
7244 ValueType, ValLocMD, Variable, Expression, AssignID, AddressLocation,
7254int LLParser::parseInstruction(Instruction *&Inst, BasicBlock *BB,
7255 PerFunctionState &PFS) {
7258 return tokError(
"found end of file when expecting more instructions");
7259 LocTy Loc = Lex.getLoc();
7260 unsigned KeywordVal = Lex.getUIntVal();
7265 return error(Loc,
"expected instruction opcode");
7269 return parseRet(Inst, BB, PFS);
7271 return parseBr(Inst, PFS);
7273 return parseSwitch(Inst, PFS);
7275 return parseIndirectBr(Inst, PFS);
7277 return parseInvoke(Inst, PFS);
7279 return parseResume(Inst, PFS);
7281 return parseCleanupRet(Inst, PFS);
7283 return parseCatchRet(Inst, PFS);
7285 return parseCatchSwitch(Inst, PFS);
7287 return parseCatchPad(Inst, PFS);
7289 return parseCleanupPad(Inst, PFS);
7291 return parseCallBr(Inst, PFS);
7294 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7295 int Res = parseUnaryOp(Inst, PFS, KeywordVal,
true);
7311 if (parseArithmetic(Inst, PFS, KeywordVal,
false))
7323 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7324 int Res = parseArithmetic(Inst, PFS, KeywordVal,
true);
7338 if (parseArithmetic(Inst, PFS, KeywordVal,
false))
7346 return parseArithmetic(Inst, PFS, KeywordVal,
7350 if (parseLogical(Inst, PFS, KeywordVal))
7358 return parseLogical(Inst, PFS, KeywordVal);
7361 if (parseCompare(Inst, PFS, KeywordVal))
7368 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7369 int Res = parseCompare(Inst, PFS, KeywordVal);
7381 bool Res = parseCast(Inst, PFS, KeywordVal);
7393 if (parseCast(Inst, PFS, KeywordVal))
7410 return parseCast(Inst, PFS, KeywordVal);
7413 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7414 if (parseCast(Inst, PFS, KeywordVal))
7423 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7424 int Res = parseSelect(Inst, PFS);
7429 return error(Loc,
"fast-math-flags specified for select without "
7430 "floating-point scalar or vector return type");
7436 return parseVAArg(Inst, PFS);
7438 return parseExtractElement(Inst, PFS);
7440 return parseInsertElement(Inst, PFS);
7442 return parseShuffleVector(Inst, PFS);
7444 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7445 int Res = parsePHI(Inst, PFS);
7450 return error(Loc,
"fast-math-flags specified for phi without "
7451 "floating-point scalar or vector return type");
7457 return parseLandingPad(Inst, PFS);
7459 return parseFreeze(Inst, PFS);
7471 return parseAlloc(Inst, PFS);
7473 return parseLoad(Inst, PFS);
7475 return parseStore(Inst, PFS);
7477 return parseCmpXchg(Inst, PFS);
7479 return parseAtomicRMW(Inst, PFS);
7481 return parseFence(Inst, PFS);
7483 return parseGetElementPtr(Inst, PFS);
7485 return parseExtractValue(Inst, PFS);
7487 return parseInsertValue(Inst, PFS);
7492bool LLParser::parseCmpPredicate(
unsigned &
P,
unsigned Opc) {
7493 if (
Opc == Instruction::FCmp) {
7494 switch (Lex.getKind()) {
7496 return tokError(
"expected fcmp predicate (e.g. 'oeq')");
7515 switch (Lex.getKind()) {
7517 return tokError(
"expected icmp predicate (e.g. 'eq')");
7541bool LLParser::parseRet(Instruction *&Inst, BasicBlock *BB,
7542 PerFunctionState &PFS) {
7543 SMLoc TypeLoc = Lex.getLoc();
7545 if (parseType(Ty,
true ))
7548 Type *ResType = PFS.getFunction().getReturnType();
7552 return error(TypeLoc,
"value doesn't match function result type '" +
7560 if (parseValue(Ty, RV, PFS))
7564 return error(TypeLoc,
"value doesn't match function result type '" +
7574bool LLParser::parseBr(Instruction *&Inst, PerFunctionState &PFS) {
7578 if (parseTypeAndValue(Op0, Loc, PFS))
7587 return error(Loc,
"branch condition must have 'i1' type");
7589 if (parseToken(
lltok::comma,
"expected ',' after branch condition") ||
7590 parseTypeAndBasicBlock(Op1, Loc, PFS) ||
7591 parseToken(
lltok::comma,
"expected ',' after true destination") ||
7592 parseTypeAndBasicBlock(Op2, Loc2, PFS))
7604bool LLParser::parseSwitch(Instruction *&Inst, PerFunctionState &PFS) {
7605 LocTy CondLoc, BBLoc;
7608 if (parseTypeAndValue(
Cond, CondLoc, PFS) ||
7609 parseToken(
lltok::comma,
"expected ',' after switch condition") ||
7610 parseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
7614 if (!
Cond->getType()->isIntegerTy())
7615 return error(CondLoc,
"switch condition must have integer type");
7618 SmallPtrSet<Value*, 32> SeenCases;
7624 if (parseTypeAndValue(Constant, CondLoc, PFS) ||
7625 parseToken(
lltok::comma,
"expected ',' after case value") ||
7626 parseTypeAndBasicBlock(DestBB, PFS))
7629 if (!SeenCases.
insert(Constant).second)
7630 return error(CondLoc,
"duplicate case value in switch");
7632 return error(CondLoc,
"case value is not a constant integer");
7640 for (
const auto &[OnVal, Dest] : Table)
7641 SI->addCase(OnVal, Dest);
7649bool LLParser::parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) {
7652 if (parseTypeAndValue(
Address, AddrLoc, PFS) ||
7653 parseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
7657 if (!
Address->getType()->isPointerTy())
7658 return error(AddrLoc,
"indirectbr address must have pointer type");
7661 SmallVector<BasicBlock*, 16> DestList;
7665 if (parseTypeAndBasicBlock(DestBB, PFS))
7670 if (parseTypeAndBasicBlock(DestBB, PFS))
7676 if (parseToken(
lltok::rsquare,
"expected ']' at end of block list"))
7680 for (BasicBlock *Dest : DestList)
7690 FunctionType *&FuncTy) {
7696 for (
const ParamInfo &Arg : ArgList)
7710bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
7711 LocTy CallLoc = Lex.getLoc();
7712 AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
7713 std::vector<unsigned> FwdRefAttrGrps;
7716 unsigned InvokeAddrSpace;
7717 Type *RetType =
nullptr;
7724 if (parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
7725 parseOptionalProgramAddrSpace(InvokeAddrSpace) ||
7726 parseType(RetType, RetTypeLoc,
true ) ||
7727 parseValID(CalleeID, &PFS) || parseParameterList(ArgList, PFS) ||
7728 parseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
7730 parseOptionalOperandBundles(BundleList, PFS) ||
7732 parseTypeAndBasicBlock(NormalBB, PFS) ||
7734 parseTypeAndBasicBlock(UnwindBB, PFS))
7741 if (resolveFunctionType(RetType, ArgList, Ty))
7742 return error(RetTypeLoc,
"Invalid result type for LLVM function");
7748 if (convertValIDToValue(
PointerType::get(Context, InvokeAddrSpace), CalleeID,
7753 SmallVector<Value *, 8>
Args;
7760 for (
const ParamInfo &Arg : ArgList) {
7761 Type *ExpectedTy =
nullptr;
7764 }
else if (!Ty->isVarArg()) {
7765 return error(Arg.Loc,
"too many arguments specified");
7768 if (ExpectedTy && ExpectedTy != Arg.V->getType())
7769 return error(Arg.Loc,
"argument is not of expected type '" +
7771 Args.push_back(Arg.V);
7776 return error(CallLoc,
"not enough parameters specified for call");
7785 II->setCallingConv(CC);
7786 II->setAttributes(PAL);
7787 ForwardRefAttrGroups[
II] = FwdRefAttrGrps;
7794bool LLParser::parseResume(Instruction *&Inst, PerFunctionState &PFS) {
7796 if (parseTypeAndValue(Exn, ExnLoc, PFS))
7804bool LLParser::parseExceptionArgs(SmallVectorImpl<Value *> &Args,
7805 PerFunctionState &PFS) {
7806 if (parseToken(
lltok::lsquare,
"expected '[' in catchpad/cleanuppad"))
7811 if (!
Args.empty() &&
7812 parseToken(
lltok::comma,
"expected ',' in argument list"))
7817 Type *ArgTy =
nullptr;
7818 if (parseType(ArgTy, ArgLoc))
7823 if (parseMetadataAsValue(V, PFS))
7826 if (parseValue(ArgTy, V, PFS))
7838bool LLParser::parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS) {
7839 Value *CleanupPad =
nullptr;
7841 if (parseToken(
lltok::kw_from,
"expected 'from' after cleanupret"))
7856 if (parseTypeAndBasicBlock(UnwindBB, PFS)) {
7867bool LLParser::parseCatchRet(Instruction *&Inst, PerFunctionState &PFS) {
7868 Value *CatchPad =
nullptr;
7870 if (parseToken(
lltok::kw_from,
"expected 'from' after catchret"))
7877 if (parseToken(
lltok::kw_to,
"expected 'to' in catchret") ||
7878 parseTypeAndBasicBlock(BB, PFS))
7887bool LLParser::parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS) {
7895 return tokError(
"expected scope value for catchswitch");
7900 if (parseToken(
lltok::lsquare,
"expected '[' with catchswitch labels"))
7906 if (parseTypeAndBasicBlock(DestBB, PFS))
7911 if (parseToken(
lltok::rsquare,
"expected ']' after catchswitch labels"))
7914 if (parseToken(
lltok::kw_unwind,
"expected 'unwind' after catchswitch scope"))
7922 if (parseTypeAndBasicBlock(UnwindBB, PFS))
7928 for (BasicBlock *DestBB : Table)
7929 CatchSwitch->addHandler(DestBB);
7936bool LLParser::parseCatchPad(Instruction *&Inst, PerFunctionState &PFS) {
7937 Value *CatchSwitch =
nullptr;
7943 return tokError(
"expected scope value for catchpad");
7948 SmallVector<Value *, 8>
Args;
7949 if (parseExceptionArgs(Args, PFS))
7958bool LLParser::parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS) {
7959 Value *ParentPad =
nullptr;
7966 return tokError(
"expected scope value for cleanuppad");
7971 SmallVector<Value *, 8>
Args;
7972 if (parseExceptionArgs(Args, PFS))
7988bool LLParser::parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
7989 unsigned Opc,
bool IsFP) {
7991 if (parseTypeAndValue(
LHS, Loc, PFS))
7998 return error(Loc,
"invalid operand type for instruction");
8008bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) {
8009 LocTy CallLoc = Lex.getLoc();
8010 AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
8011 std::vector<unsigned> FwdRefAttrGrps;
8014 Type *RetType =
nullptr;
8021 if (parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
8022 parseType(RetType, RetTypeLoc,
true ) ||
8023 parseValID(CalleeID, &PFS) || parseParameterList(ArgList, PFS) ||
8024 parseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
8026 parseOptionalOperandBundles(BundleList, PFS) ||
8028 parseTypeAndBasicBlock(DefaultDest, PFS) ||
8033 SmallVector<BasicBlock *, 16> IndirectDests;
8037 if (parseTypeAndBasicBlock(DestBB, PFS))
8042 if (parseTypeAndBasicBlock(DestBB, PFS))
8048 if (parseToken(
lltok::rsquare,
"expected ']' at end of block list"))
8055 if (resolveFunctionType(RetType, ArgList, Ty))
8056 return error(RetTypeLoc,
"Invalid result type for LLVM function");
8067 SmallVector<Value *, 8>
Args;
8074 for (
const ParamInfo &Arg : ArgList) {
8075 Type *ExpectedTy =
nullptr;
8078 }
else if (!Ty->isVarArg()) {
8079 return error(Arg.Loc,
"too many arguments specified");
8082 if (ExpectedTy && ExpectedTy != Arg.V->getType())
8083 return error(Arg.Loc,
"argument is not of expected type '" +
8085 Args.push_back(Arg.V);
8090 return error(CallLoc,
"not enough parameters specified for call");
8102 ForwardRefAttrGroups[CBI] = FwdRefAttrGrps;
8116bool LLParser::parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
8117 unsigned Opc,
bool IsFP) {
8119 if (parseTypeAndValue(
LHS, Loc, PFS) ||
8120 parseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
8128 return error(Loc,
"invalid operand type for instruction");
8136bool LLParser::parseLogical(Instruction *&Inst, PerFunctionState &PFS,
8139 if (parseTypeAndValue(
LHS, Loc, PFS) ||
8140 parseToken(
lltok::comma,
"expected ',' in logical operation") ||
8146 "instruction requires integer or integer vector operands");
8155bool LLParser::parseCompare(Instruction *&Inst, PerFunctionState &PFS,
8161 if (parseCmpPredicate(Pred,
Opc) || parseTypeAndValue(
LHS, Loc, PFS) ||
8162 parseToken(
lltok::comma,
"expected ',' after compare value") ||
8166 if (
Opc == Instruction::FCmp) {
8168 return error(Loc,
"fcmp requires floating point operands");
8171 assert(
Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
8174 return error(Loc,
"icmp requires integer operands");
8186bool LLParser::parseCast(Instruction *&Inst, PerFunctionState &PFS,
8190 Type *DestTy =
nullptr;
8191 if (parseTypeAndValue(
Op, Loc, PFS) ||
8192 parseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
8197 return error(Loc,
"invalid cast opcode for cast from '" +
8206bool LLParser::parseSelect(Instruction *&Inst, PerFunctionState &PFS) {
8208 Value *Op0, *Op1, *Op2;
8209 if (parseTypeAndValue(Op0, Loc, PFS) ||
8210 parseToken(
lltok::comma,
"expected ',' after select condition") ||
8211 parseTypeAndValue(Op1, PFS) ||
8212 parseToken(
lltok::comma,
"expected ',' after select value") ||
8213 parseTypeAndValue(Op2, PFS))
8217 return error(Loc, Reason);
8225bool LLParser::parseVAArg(Instruction *&Inst, PerFunctionState &PFS) {
8227 Type *EltTy =
nullptr;
8229 if (parseTypeAndValue(
Op, PFS) ||
8230 parseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
8231 parseType(EltTy, TypeLoc))
8235 return error(TypeLoc,
"va_arg requires operand with first class type");
8237 Inst =
new VAArgInst(
Op, EltTy);
8243bool LLParser::parseExtractElement(Instruction *&Inst, PerFunctionState &PFS) {
8246 if (parseTypeAndValue(Op0, Loc, PFS) ||
8247 parseToken(
lltok::comma,
"expected ',' after extract value") ||
8248 parseTypeAndValue(Op1, PFS))
8252 return error(Loc,
"invalid extractelement operands");
8260bool LLParser::parseInsertElement(Instruction *&Inst, PerFunctionState &PFS) {
8262 Value *Op0, *Op1, *Op2;
8263 if (parseTypeAndValue(Op0, Loc, PFS) ||
8264 parseToken(
lltok::comma,
"expected ',' after insertelement value") ||
8265 parseTypeAndValue(Op1, PFS) ||
8266 parseToken(
lltok::comma,
"expected ',' after insertelement value") ||
8267 parseTypeAndValue(Op2, PFS))
8271 return error(Loc,
"invalid insertelement operands");
8279bool LLParser::parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS) {
8281 Value *Op0, *Op1, *Op2;
8282 if (parseTypeAndValue(Op0, Loc, PFS) ||
8283 parseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
8284 parseTypeAndValue(Op1, PFS) ||
8285 parseToken(
lltok::comma,
"expected ',' after shuffle value") ||
8286 parseTypeAndValue(Op2, PFS))
8290 return error(Loc,
"invalid shufflevector operands");
8292 Inst =
new ShuffleVectorInst(Op0, Op1, Op2);
8298int LLParser::parsePHI(Instruction *&Inst, PerFunctionState &PFS) {
8302 if (parseType(Ty, TypeLoc))
8306 return error(TypeLoc,
"phi node must have first class type");
8309 bool AteExtraComma =
false;
8321 AteExtraComma =
true;
8325 if (parseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
8326 parseValue(Ty, Op0, PFS) ||
8327 parseToken(
lltok::comma,
"expected ',' after insertelement value") ||
8336 for (
const auto &[Val, BB] : PHIVals)
8339 return AteExtraComma ? InstExtraComma : InstNormal;
8348bool LLParser::parseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
8351 if (parseType(Ty, TyLoc))
8364 return tokError(
"expected 'catch' or 'filter' clause type");
8368 if (parseTypeAndValue(V, VLoc, PFS))
8375 return error(VLoc,
"'catch' clause has an invalid type");
8378 return error(VLoc,
"'filter' clause has an invalid type");
8383 return error(VLoc,
"clause argument must be a constant");
8387 Inst = LP.release();
8393bool LLParser::parseFreeze(Instruction *&Inst, PerFunctionState &PFS) {
8396 if (parseTypeAndValue(
Op, Loc, PFS))
8399 Inst =
new FreezeInst(
Op);
8412bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS,
8414 AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
8415 std::vector<unsigned> FwdRefAttrGrps;
8417 unsigned CallAddrSpace;
8419 Type *RetType =
nullptr;
8424 LocTy CallLoc = Lex.getLoc();
8428 "expected 'tail call', 'musttail call', or 'notail call'"))
8431 FastMathFlags FMF = EatFastMathFlagsIfPresent();
8433 if (parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
8434 parseOptionalProgramAddrSpace(CallAddrSpace) ||
8435 parseType(RetType, RetTypeLoc,
true ) ||
8436 parseValID(CalleeID, &PFS) ||
8438 PFS.getFunction().isVarArg()) ||
8439 parseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false, BuiltinLoc) ||
8440 parseOptionalOperandBundles(BundleList, PFS))
8447 if (resolveFunctionType(RetType, ArgList, Ty))
8448 return error(RetTypeLoc,
"Invalid result type for LLVM function");
8454 if (convertValIDToValue(
PointerType::get(Context, CallAddrSpace), CalleeID,
8461 SmallVector<Value*, 8>
Args;
8467 for (
const ParamInfo &Arg : ArgList) {
8468 Type *ExpectedTy =
nullptr;
8471 }
else if (!Ty->isVarArg()) {
8472 return error(Arg.Loc,
"too many arguments specified");
8475 if (ExpectedTy && ExpectedTy != Arg.V->getType())
8476 return error(Arg.Loc,
"argument is not of expected type '" +
8478 Args.push_back(Arg.V);
8479 Attrs.push_back(Arg.Attrs);
8483 return error(CallLoc,
"not enough parameters specified for call");
8496 return error(CallLoc,
"fast-math-flags specified for call without "
8497 "floating-point scalar or vector return type");
8504 if (SeenNewDbgInfoFormat) {
8506 return error(CallLoc,
"llvm.dbg intrinsic should not appear in a module "
8507 "using non-intrinsic debug info");
8509 SeenOldDbgInfoFormat =
true;
8512 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
8524int LLParser::parseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
8526 LocTy SizeLoc, TyLoc, ASLoc;
8527 MaybeAlign Alignment;
8528 unsigned AddrSpace = 0;
8531 bool IsInAlloca = EatIfPresent(lltok::kw_inalloca);
8532 bool IsSwiftError = EatIfPresent(lltok::kw_swifterror);
8534 if (parseType(Ty, TyLoc))
8538 return error(TyLoc,
"invalid type for alloca");
8540 bool AteExtraComma =
false;
8542 if (Lex.getKind() == lltok::kw_align) {
8543 if (parseOptionalAlignment(Alignment))
8545 if (parseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
8548 ASLoc = Lex.getLoc();
8549 if (parseOptionalAddrSpace(AddrSpace))
8552 AteExtraComma =
true;
8554 if (parseTypeAndValue(
Size, SizeLoc, PFS))
8557 if (Lex.getKind() == lltok::kw_align) {
8558 if (parseOptionalAlignment(Alignment))
8560 if (parseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
8563 ASLoc = Lex.getLoc();
8564 if (parseOptionalAddrSpace(AddrSpace))
8567 AteExtraComma =
true;
8573 if (
Size && !
Size->getType()->isIntegerTy())
8574 return error(SizeLoc,
"element count must have integer type");
8576 SmallPtrSet<Type *, 4> Visited;
8577 if (!Alignment && !Ty->
isSized(&Visited))
8578 return error(TyLoc,
"Cannot allocate unsized type");
8580 Alignment = M->getDataLayout().getPrefTypeAlign(Ty);
8581 AllocaInst *AI =
new AllocaInst(Ty, AddrSpace,
Size, *Alignment);
8585 return AteExtraComma ? InstExtraComma : InstNormal;
8592int LLParser::parseLoad(Instruction *&Inst, PerFunctionState &PFS) {
8594 MaybeAlign Alignment;
8595 bool AteExtraComma =
false;
8596 bool isAtomic =
false;
8605 bool isVolatile =
false;
8612 LocTy ExplicitTypeLoc = Lex.getLoc();
8613 if (parseType(Ty) ||
8614 parseToken(
lltok::comma,
"expected comma after load's type") ||
8615 parseTypeAndValue(Val, Loc, PFS) ||
8616 parseScopeAndOrdering(isAtomic, SSID, Ordering) ||
8617 parseOptionalCommaAlign(Alignment, AteExtraComma))
8621 return error(Loc,
"load operand must be a pointer to a first class type");
8622 if (isAtomic && !Alignment)
8623 return error(Loc,
"atomic load must have explicit non-zero alignment");
8626 return error(Loc,
"atomic load cannot use Release ordering");
8628 SmallPtrSet<Type *, 4> Visited;
8629 if (!Alignment && !Ty->
isSized(&Visited))
8630 return error(ExplicitTypeLoc,
"loading unsized types is not allowed");
8632 Alignment = M->getDataLayout().getABITypeAlign(Ty);
8633 Inst =
new LoadInst(Ty, Val,
"", isVolatile, *Alignment, Ordering, SSID);
8634 return AteExtraComma ? InstExtraComma : InstNormal;
8642int LLParser::parseStore(Instruction *&Inst, PerFunctionState &PFS) {
8644 MaybeAlign Alignment;
8645 bool AteExtraComma =
false;
8646 bool isAtomic =
false;
8655 bool isVolatile =
false;
8661 if (parseTypeAndValue(Val, Loc, PFS) ||
8662 parseToken(
lltok::comma,
"expected ',' after store operand") ||
8663 parseTypeAndValue(Ptr, PtrLoc, PFS) ||
8664 parseScopeAndOrdering(isAtomic, SSID, Ordering) ||
8665 parseOptionalCommaAlign(Alignment, AteExtraComma))
8669 return error(PtrLoc,
"store operand must be a pointer");
8671 return error(Loc,
"store operand must be a first class value");
8672 if (isAtomic && !Alignment)
8673 return error(Loc,
"atomic store must have explicit non-zero alignment");
8676 return error(Loc,
"atomic store cannot use Acquire ordering");
8677 SmallPtrSet<Type *, 4> Visited;
8679 return error(Loc,
"storing unsized types is not allowed");
8681 Alignment = M->getDataLayout().getABITypeAlign(Val->
getType());
8683 Inst =
new StoreInst(Val, Ptr, isVolatile, *Alignment, Ordering, SSID);
8684 return AteExtraComma ? InstExtraComma : InstNormal;
8691int LLParser::parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) {
8693 bool AteExtraComma =
false;
8697 bool isVolatile =
false;
8698 bool isWeak =
false;
8699 MaybeAlign Alignment;
8707 if (parseTypeAndValue(Ptr, PtrLoc, PFS) ||
8708 parseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
8709 parseTypeAndValue(Cmp, CmpLoc, PFS) ||
8710 parseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
8711 parseTypeAndValue(New, NewLoc, PFS) ||
8712 parseScopeAndOrdering(
true , SSID, SuccessOrdering) ||
8713 parseOrdering(FailureOrdering) ||
8714 parseOptionalCommaAlign(Alignment, AteExtraComma))
8718 return tokError(
"invalid cmpxchg success ordering");
8720 return tokError(
"invalid cmpxchg failure ordering");
8722 return error(PtrLoc,
"cmpxchg operand must be a pointer");
8723 if (
Cmp->getType() !=
New->getType())
8724 return error(NewLoc,
"compare value and new value type do not match");
8725 if (!
New->getType()->isFirstClassType())
8726 return error(NewLoc,
"cmpxchg operand must be a first class value");
8728 const Align DefaultAlignment(
8729 PFS.getFunction().getDataLayout().getTypeStoreSize(
8732 AtomicCmpXchgInst *CXI =
8733 new AtomicCmpXchgInst(Ptr, Cmp, New, Alignment.value_or(DefaultAlignment),
8734 SuccessOrdering, FailureOrdering, SSID);
8739 return AteExtraComma ? InstExtraComma : InstNormal;
8745int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
8747 bool AteExtraComma =
false;
8750 bool isVolatile =
false;
8753 MaybeAlign Alignment;
8758 switch (Lex.getKind()) {
8760 return tokError(
"expected binary operation in atomicrmw");
8811 if (parseTypeAndValue(Ptr, PtrLoc, PFS) ||
8812 parseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
8813 parseTypeAndValue(Val, ValLoc, PFS) ||
8814 parseScopeAndOrdering(
true , SSID, Ordering) ||
8815 parseOptionalCommaAlign(Alignment, AteExtraComma))
8819 return tokError(
"atomicrmw cannot be unordered");
8821 return error(PtrLoc,
"atomicrmw operand must be a pointer");
8823 return error(ValLoc,
"atomicrmw operand may not be scalable");
8832 " operand must be an integer, floating point, or pointer type");
8836 return error(ValLoc,
"atomicrmw " +
8838 " operand must be a floating point type");
8842 return error(ValLoc,
"atomicrmw " +
8844 " operand must be an integer");
8849 PFS.getFunction().getDataLayout().getTypeStoreSizeInBits(
8852 return error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized"
8854 const Align DefaultAlignment(
8855 PFS.getFunction().getDataLayout().getTypeStoreSize(
8857 AtomicRMWInst *RMWI =
8859 Alignment.value_or(DefaultAlignment), Ordering, SSID);
8862 return AteExtraComma ? InstExtraComma : InstNormal;
8867int LLParser::parseFence(Instruction *&Inst, PerFunctionState &PFS) {
8870 if (parseScopeAndOrdering(
true , SSID, Ordering))
8874 return tokError(
"fence cannot be unordered");
8876 return tokError(
"fence cannot be monotonic");
8878 Inst =
new FenceInst(Context, Ordering, SSID);
8884int LLParser::parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
8885 Value *Ptr =
nullptr;
8886 Value *Val =
nullptr;
8902 if (parseType(Ty) ||
8903 parseToken(
lltok::comma,
"expected comma after getelementptr's type") ||
8904 parseTypeAndValue(Ptr, Loc, PFS))
8909 if (!BasePointerType)
8910 return error(Loc,
"base of getelementptr must be a pointer");
8912 SmallVector<Value*, 16> Indices;
8913 bool AteExtraComma =
false;
8916 ElementCount GEPWidth =
BaseType->isVectorTy()
8922 AteExtraComma =
true;
8925 if (parseTypeAndValue(Val, EltLoc, PFS))
8928 return error(EltLoc,
"getelementptr index must be an integer");
8931 ElementCount ValNumEl = ValVTy->getElementCount();
8935 "getelementptr vector index has a wrong number of elements");
8936 GEPWidth = ValNumEl;
8941 SmallPtrSet<Type*, 4> Visited;
8943 return error(Loc,
"base element of getelementptr must be sized");
8947 return error(Loc,
"getelementptr cannot target structure that contains "
8948 "scalable vector type");
8951 return error(Loc,
"invalid getelementptr indices");
8954 GEP->setNoWrapFlags(NW);
8955 return AteExtraComma ? InstExtraComma : InstNormal;
8960int LLParser::parseExtractValue(Instruction *&Inst, PerFunctionState &PFS) {
8962 SmallVector<unsigned, 4> Indices;
8964 if (parseTypeAndValue(Val, Loc, PFS) ||
8965 parseIndexList(Indices, AteExtraComma))
8969 return error(Loc,
"extractvalue operand must be aggregate type");
8972 return error(Loc,
"invalid indices for extractvalue");
8974 return AteExtraComma ? InstExtraComma : InstNormal;
8979int LLParser::parseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
8981 SmallVector<unsigned, 4> Indices;
8983 if (parseTypeAndValue(Val0, Loc0, PFS) ||
8984 parseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
8985 parseTypeAndValue(Val1, Loc1, PFS) ||
8986 parseIndexList(Indices, AteExtraComma))
8990 return error(Loc0,
"insertvalue operand must be aggregate type");
8994 return error(Loc0,
"invalid indices for insertvalue");
8995 if (IndexedType != Val1->
getType())
8996 return error(Loc1,
"insertvalue operand and field disagree in type: '" +
9000 return AteExtraComma ? InstExtraComma : InstNormal;
9011bool LLParser::parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts) {
9026 if (parseMetadata(MD,
nullptr))
9031 return parseToken(
lltok::rbrace,
"expected end of metadata node");
9037bool LLParser::sortUseListOrder(
Value *V, ArrayRef<unsigned> Indexes,
9039 if (!
V->hasUseList())
9042 return error(Loc,
"value has no uses");
9044 unsigned NumUses = 0;
9045 SmallDenseMap<const Use *, unsigned, 16> Order;
9046 for (
const Use &U :
V->uses()) {
9047 if (++NumUses > Indexes.
size())
9049 Order[&
U] = Indexes[NumUses - 1];
9052 return error(Loc,
"value only has one use");
9053 if (Order.
size() != Indexes.
size() || NumUses > Indexes.
size())
9055 "wrong number of indexes, expected " + Twine(
V->getNumUses()));
9057 V->sortUseList([&](
const Use &L,
const Use &R) {
9065bool LLParser::parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes) {
9066 SMLoc Loc = Lex.getLoc();
9070 return tokError(
"expected non-empty list of uselistorder indexes");
9077 bool IsOrdered =
true;
9078 assert(Indexes.
empty() &&
"Expected empty order vector");
9081 if (parseUInt32(Index))
9086 Max = std::max(Max, Index);
9087 IsOrdered &= Index == Indexes.
size();
9095 if (Indexes.
size() < 2)
9096 return error(Loc,
"expected >= 2 uselistorder indexes");
9099 "expected distinct uselistorder indexes in range [0, size)");
9101 return error(Loc,
"expected uselistorder indexes to change the order");
9108bool LLParser::parseUseListOrder(PerFunctionState *PFS) {
9109 SMLoc Loc = Lex.getLoc();
9114 SmallVector<unsigned, 16> Indexes;
9115 if (parseTypeAndValue(V, PFS) ||
9116 parseToken(
lltok::comma,
"expected comma in uselistorder directive") ||
9117 parseUseListOrderIndexes(Indexes))
9120 return sortUseListOrder(V, Indexes, Loc);
9125bool LLParser::parseUseListOrderBB() {
9127 SMLoc Loc = Lex.getLoc();
9131 SmallVector<unsigned, 16> Indexes;
9132 if (parseValID(Fn,
nullptr) ||
9133 parseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
9134 parseValID(Label,
nullptr) ||
9135 parseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
9136 parseUseListOrderIndexes(Indexes))
9142 GV = M->getNamedValue(Fn.
StrVal);
9144 GV = NumberedVals.get(Fn.
UIntVal);
9146 return error(Fn.
Loc,
"expected function name in uselistorder_bb");
9149 "invalid function forward reference in uselistorder_bb");
9152 return error(Fn.
Loc,
"expected function name in uselistorder_bb");
9153 if (
F->isDeclaration())
9154 return error(Fn.
Loc,
"invalid declaration in uselistorder_bb");
9158 return error(
Label.Loc,
"invalid numeric label in uselistorder_bb");
9160 return error(
Label.Loc,
"expected basic block name in uselistorder_bb");
9161 Value *
V =
F->getValueSymbolTable()->lookup(
Label.StrVal);
9163 return error(
Label.Loc,
"invalid basic block in uselistorder_bb");
9165 return error(
Label.Loc,
"expected basic block in uselistorder_bb");
9167 return sortUseListOrder(V, Indexes, Loc);
9173bool LLParser::parseModuleEntry(
unsigned ID) {
9182 parseStringConstant(Path) ||
9190 if (parseUInt32(Hash[0]) || parseToken(
lltok::comma,
"expected ',' here") ||
9191 parseUInt32(Hash[1]) || parseToken(
lltok::comma,
"expected ',' here") ||
9192 parseUInt32(Hash[2]) || parseToken(
lltok::comma,
"expected ',' here") ||
9193 parseUInt32(Hash[3]) || parseToken(
lltok::comma,
"expected ',' here") ||
9194 parseUInt32(Hash[4]))
9201 auto ModuleEntry = Index->addModule(Path, Hash);
9202 ModuleIdMap[
ID] = ModuleEntry->first();
9209bool LLParser::parseTypeIdEntry(
unsigned ID) {
9218 parseStringConstant(Name))
9221 TypeIdSummary &TIS = Index->getOrInsertTypeIdSummary(Name);
9223 parseTypeIdSummary(TIS) || parseToken(
lltok::rparen,
"expected ')' here"))
9228 auto FwdRefTIDs = ForwardRefTypeIds.find(
ID);
9229 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
9230 for (
auto TIDRef : FwdRefTIDs->second) {
9232 "Forward referenced type id GUID expected to be 0");
9235 ForwardRefTypeIds.erase(FwdRefTIDs);
9243bool LLParser::parseTypeIdSummary(TypeIdSummary &TIS) {
9247 parseTypeTestResolution(TIS.
TTRes))
9252 if (parseOptionalWpdResolutions(TIS.
WPDRes))
9263 ValueInfo(
false, (GlobalValueSummaryMapTy::value_type *)-8);
9269bool LLParser::parseTypeIdCompatibleVtableEntry(
unsigned ID) {
9278 parseStringConstant(Name))
9282 Index->getOrInsertTypeIdCompatibleVtableSummary(Name);
9289 IdToIndexMapType IdToIndexMap;
9302 if (parseGVReference(VI, GVId))
9309 IdToIndexMap[GVId].push_back(std::make_pair(TI.size(),
Loc));
9310 TI.push_back({
Offset, VI});
9318 for (
auto I : IdToIndexMap) {
9319 auto &Infos = ForwardRefValueInfos[
I.first];
9320 for (
auto P :
I.second) {
9322 "Forward referenced ValueInfo expected to be empty");
9323 Infos.emplace_back(&TI[
P.first].VTableVI,
P.second);
9333 auto FwdRefTIDs = ForwardRefTypeIds.find(
ID);
9334 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
9335 for (
auto TIDRef : FwdRefTIDs->second) {
9337 "Forward referenced type id GUID expected to be 0");
9340 ForwardRefTypeIds.erase(FwdRefTIDs);
9352bool LLParser::parseTypeTestResolution(TypeTestResolution &TTRes) {
9360 switch (Lex.getKind()) {
9380 return error(Lex.getLoc(),
"unexpected TypeTestResolution kind");
9392 switch (Lex.getKind()) {
9407 if (parseToken(
lltok::colon,
"expected ':'") || parseUInt32(Val))
9420 return error(Lex.getLoc(),
"expected optional TypeTestResolution field");
9433bool LLParser::parseOptionalWpdResolutions(
9434 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap) {
9442 WholeProgramDevirtResolution WPDRes;
9446 parseToken(
lltok::comma,
"expected ',' here") || parseWpdRes(WPDRes) ||
9449 WPDResMap[
Offset] = WPDRes;
9466bool LLParser::parseWpdRes(WholeProgramDevirtResolution &WPDRes) {
9474 switch (Lex.getKind()) {
9485 return error(Lex.getLoc(),
"unexpected WholeProgramDevirtResolution kind");
9491 switch (Lex.getKind()) {
9499 if (parseOptionalResByArg(WPDRes.
ResByArg))
9503 return error(Lex.getLoc(),
9504 "expected optional WholeProgramDevirtResolution field");
9521bool LLParser::parseOptionalResByArg(
9522 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
9530 std::vector<uint64_t>
Args;
9531 if (parseArgs(Args) || parseToken(
lltok::comma,
"expected ',' here") ||
9539 WholeProgramDevirtResolution::ByArg ByArg;
9540 switch (Lex.getKind()) {
9554 return error(Lex.getLoc(),
9555 "unexpected WholeProgramDevirtResolution::ByArg kind");
9561 switch (Lex.getKind()) {
9565 parseUInt64(ByArg.
Info))
9571 parseUInt32(ByArg.
Byte))
9577 parseUInt32(ByArg.
Bit))
9581 return error(Lex.getLoc(),
9582 "expected optional whole program devirt field");
9589 ResByArg[
Args] = ByArg;
9600bool LLParser::parseArgs(std::vector<uint64_t> &Args) {
9608 if (parseUInt64(Val))
9610 Args.push_back(Val);
9619static const auto FwdVIRef = (GlobalValueSummaryMapTy::value_type *)-8;
9624 assert(!(ReadOnly && WriteOnly));
9634bool LLParser::addGlobalValueToIndex(
9636 unsigned ID, std::unique_ptr<GlobalValueSummary> Summary,
LocTy Loc) {
9641 VI = Index->getOrInsertValueInfo(GUID);
9645 auto *GV = M->getNamedValue(Name);
9647 return error(Loc,
"Reference to undefined global \"" + Name +
"\"");
9649 VI = Index->getOrInsertValueInfo(GV);
9653 "Need a source_filename to compute GUID for local");
9656 VI = Index->getOrInsertValueInfo(GUID, Index->saveString(Name));
9661 auto FwdRefVIs = ForwardRefValueInfos.find(
ID);
9662 if (FwdRefVIs != ForwardRefValueInfos.end()) {
9663 for (
auto VIRef : FwdRefVIs->second) {
9665 "Forward referenced ValueInfo expected to be empty");
9668 ForwardRefValueInfos.erase(FwdRefVIs);
9672 auto FwdRefAliasees = ForwardRefAliasees.find(
ID);
9673 if (FwdRefAliasees != ForwardRefAliasees.end()) {
9674 for (
auto AliaseeRef : FwdRefAliasees->second) {
9675 assert(!AliaseeRef.first->hasAliasee() &&
9676 "Forward referencing alias already has aliasee");
9677 assert(Summary &&
"Aliasee must be a definition");
9678 AliaseeRef.first->setAliasee(VI,
Summary.get());
9680 ForwardRefAliasees.erase(FwdRefAliasees);
9685 Index->addGlobalValueSummary(VI, std::move(Summary));
9688 if (
ID == NumberedValueInfos.size())
9689 NumberedValueInfos.push_back(VI);
9692 if (
ID > NumberedValueInfos.size())
9693 NumberedValueInfos.resize(
ID + 1);
9694 NumberedValueInfos[
ID] =
VI;
9702bool LLParser::parseSummaryIndexFlags() {
9709 if (parseUInt64(Flags))
9712 Index->setFlags(Flags);
9718bool LLParser::parseBlockCount() {
9724 uint64_t BlockCount;
9725 if (parseUInt64(BlockCount))
9728 Index->setBlockCount(BlockCount);
9736bool LLParser::parseGVEntry(
unsigned ID) {
9744 LocTy Loc = Lex.getLoc();
9747 switch (Lex.getKind()) {
9751 parseStringConstant(Name))
9757 if (parseToken(
lltok::colon,
"expected ':' here") || parseUInt64(GUID))
9761 return error(Lex.getLoc(),
"expected name or guid tag");
9784 switch (Lex.getKind()) {
9786 if (parseFunctionSummary(Name, GUID,
ID))
9790 if (parseVariableSummary(Name, GUID,
ID))
9794 if (parseAliasSummary(Name, GUID,
ID))
9798 return error(Lex.getLoc(),
"expected summary type");
9816 LocTy Loc = Lex.getLoc();
9820 StringRef ModulePath;
9821 GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
9824 false,
false,
false,
9828 FunctionSummary::TypeIdInfo TypeIdInfo;
9829 std::vector<FunctionSummary::ParamAccess> ParamAccesses;
9831 std::vector<CallsiteInfo> Callsites;
9832 std::vector<AllocInfo> Allocs;
9834 FunctionSummary::FFlags FFlags = {};
9837 parseModuleReference(ModulePath) ||
9838 parseToken(
lltok::comma,
"expected ',' here") || parseGVFlags(GVFlags) ||
9841 parseToken(
lltok::colon,
"expected ':' here") || parseUInt32(InstCount))
9846 switch (Lex.getKind()) {
9848 if (parseOptionalFFlags(FFlags))
9852 if (parseOptionalCalls(Calls))
9856 if (parseOptionalTypeIdInfo(TypeIdInfo))
9860 if (parseOptionalRefs(Refs))
9864 if (parseOptionalParamAccesses(ParamAccesses))
9868 if (parseOptionalAllocs(Allocs))
9872 if (parseOptionalCallsites(Callsites))
9876 return error(Lex.getLoc(),
"expected optional function summary field");
9883 auto FS = std::make_unique<FunctionSummary>(
9884 GVFlags, InstCount, FFlags, std::move(Refs), std::move(Calls),
9890 std::move(ParamAccesses), std::move(Callsites), std::move(Allocs));
9892 FS->setModulePath(ModulePath);
9894 return addGlobalValueToIndex(Name, GUID,
9896 std::move(FS), Loc);
9904 LocTy Loc = Lex.getLoc();
9908 StringRef ModulePath;
9909 GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
9912 false,
false,
false,
9914 GlobalVarSummary::GVarFlags GVarFlags(
false,
9922 parseModuleReference(ModulePath) ||
9923 parseToken(
lltok::comma,
"expected ',' here") || parseGVFlags(GVFlags) ||
9925 parseGVarFlags(GVarFlags))
9930 switch (Lex.getKind()) {
9932 if (parseOptionalVTableFuncs(VTableFuncs))
9936 if (parseOptionalRefs(Refs))
9940 return error(Lex.getLoc(),
"expected optional variable summary field");
9948 std::make_unique<GlobalVarSummary>(GVFlags, GVarFlags, std::move(Refs));
9950 GS->setModulePath(ModulePath);
9951 GS->setVTableFuncs(std::move(VTableFuncs));
9953 return addGlobalValueToIndex(Name, GUID,
9955 std::move(GS), Loc);
9964 LocTy Loc = Lex.getLoc();
9967 StringRef ModulePath;
9968 GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
9971 false,
false,
false,
9975 parseModuleReference(ModulePath) ||
9976 parseToken(
lltok::comma,
"expected ',' here") || parseGVFlags(GVFlags) ||
9982 ValueInfo AliaseeVI;
9984 if (parseGVReference(AliaseeVI, GVId))
9990 auto AS = std::make_unique<AliasSummary>(GVFlags);
9992 AS->setModulePath(ModulePath);
9996 ForwardRefAliasees[GVId].emplace_back(AS.get(), Loc);
9998 auto Summary = Index->findSummaryInModule(AliaseeVI, ModulePath);
9999 assert(Summary &&
"Aliasee must be a definition");
10000 AS->setAliasee(AliaseeVI, Summary);
10003 return addGlobalValueToIndex(Name, GUID,
10005 std::move(AS), Loc);
10010bool LLParser::parseFlag(
unsigned &Val) {
10011 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
10012 return tokError(
"expected integer");
10013 Val = (unsigned)Lex.getAPSIntVal().getBoolValue();
10029bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) {
10033 if (parseToken(
lltok::colon,
"expected ':' in funcFlags") ||
10039 switch (Lex.getKind()) {
10042 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10048 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10054 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10060 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10066 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10072 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10078 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10084 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10090 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10096 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10101 return error(Lex.getLoc(),
"expected function flag type");
10105 if (parseToken(
lltok::rparen,
"expected ')' in funcFlags"))
10116bool LLParser::parseOptionalCalls(
10117 SmallVectorImpl<FunctionSummary::EdgeTy> &Calls) {
10121 if (parseToken(
lltok::colon,
"expected ':' in calls") ||
10125 IdToIndexMapType IdToIndexMap;
10134 LocTy Loc = Lex.getLoc();
10136 if (parseGVReference(VI, GVId))
10140 unsigned RelBF = 0;
10141 unsigned HasTailCall =
false;
10145 switch (Lex.getKind()) {
10148 if (parseToken(
lltok::colon,
"expected ':'") || parseHotness(Hotness))
10153 if (parseToken(
lltok::colon,
"expected ':'") || parseUInt32(RelBF))
10158 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(HasTailCall))
10162 return error(Lex.getLoc(),
"expected hotness, relbf, or tail");
10166 return tokError(
"Expected only one of hotness or relbf");
10171 IdToIndexMap[GVId].push_back(std::make_pair(Calls.
size(), Loc));
10181 for (
auto I : IdToIndexMap) {
10182 auto &Infos = ForwardRefValueInfos[
I.first];
10183 for (
auto P :
I.second) {
10185 "Forward referenced ValueInfo expected to be empty");
10186 Infos.emplace_back(&Calls[
P.first].first,
P.second);
10199 switch (Lex.getKind()) {
10203 case lltok::kw_cold:
10209 case lltok::kw_hot:
10216 return error(Lex.getLoc(),
"invalid call edge hotness");
10225bool LLParser::parseOptionalVTableFuncs(
VTableFuncList &VTableFuncs) {
10229 if (parseToken(
lltok::colon,
"expected ':' in vTableFuncs") ||
10233 IdToIndexMapType IdToIndexMap;
10237 if (parseToken(
lltok::lparen,
"expected '(' in vTableFunc") ||
10242 LocTy Loc = Lex.getLoc();
10244 if (parseGVReference(VI, GVId))
10257 IdToIndexMap[GVId].push_back(std::make_pair(VTableFuncs.size(), Loc));
10258 VTableFuncs.push_back({
VI,
Offset});
10260 if (parseToken(
lltok::rparen,
"expected ')' in vTableFunc"))
10266 for (
auto I : IdToIndexMap) {
10267 auto &Infos = ForwardRefValueInfos[
I.first];
10268 for (
auto P :
I.second) {
10270 "Forward referenced ValueInfo expected to be empty");
10271 Infos.emplace_back(&VTableFuncs[
P.first].FuncVI,
P.second);
10275 if (parseToken(
lltok::rparen,
"expected ')' in vTableFuncs"))
10282bool LLParser::parseParamNo(uint64_t &ParamNo) {
10284 parseToken(
lltok::colon,
"expected ':' here") || parseUInt64(ParamNo))
10290bool LLParser::parseParamAccessOffset(ConstantRange &
Range) {
10293 auto ParseAPSInt = [&](
APSInt &Val) {
10295 return tokError(
"expected integer");
10296 Val = Lex.getAPSIntVal();
10298 Val.setIsSigned(
true);
10320bool LLParser::parseParamAccessCall(FunctionSummary::ParamAccess::Call &
Call,
10321 IdLocListType &IdLocList) {
10329 LocTy Loc = Lex.getLoc();
10330 if (parseGVReference(VI, GVId))
10334 IdLocList.emplace_back(GVId, Loc);
10337 parseParamNo(
Call.ParamNo) ||
10339 parseParamAccessOffset(
Call.Offsets))
10351bool LLParser::parseParamAccess(FunctionSummary::ParamAccess &Param,
10352 IdLocListType &IdLocList) {
10354 parseParamNo(
Param.ParamNo) ||
10356 parseParamAccessOffset(
Param.Use))
10365 FunctionSummary::ParamAccess::Call
Call;
10366 if (parseParamAccessCall(
Call, IdLocList))
10383bool LLParser::parseOptionalParamAccesses(
10384 std::vector<FunctionSummary::ParamAccess> &Params) {
10392 IdLocListType VContexts;
10393 size_t CallsNum = 0;
10395 FunctionSummary::ParamAccess ParamAccess;
10396 if (parseParamAccess(ParamAccess, VContexts))
10398 CallsNum += ParamAccess.
Calls.size();
10399 assert(VContexts.size() == CallsNum);
10401 Params.emplace_back(std::move(ParamAccess));
10409 IdLocListType::const_iterator ItContext = VContexts.begin();
10410 for (
auto &PA : Params) {
10411 for (
auto &
C : PA.Calls) {
10413 ForwardRefValueInfos[ItContext->first].emplace_back(&
C.Callee,
10414 ItContext->second);
10418 assert(ItContext == VContexts.end());
10425bool LLParser::parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs) {
10429 if (parseToken(
lltok::colon,
"expected ':' in refs") ||
10433 struct ValueContext {
10438 std::vector<ValueContext> VContexts;
10442 VC.Loc = Lex.getLoc();
10443 if (parseGVReference(
VC.VI,
VC.GVId))
10445 VContexts.push_back(VC);
10451 llvm::sort(VContexts, [](
const ValueContext &VC1,
const ValueContext &VC2) {
10452 return VC1.VI.getAccessSpecifier() < VC2.VI.getAccessSpecifier();
10455 IdToIndexMapType IdToIndexMap;
10456 for (
auto &VC : VContexts) {
10461 IdToIndexMap[
VC.GVId].push_back(std::make_pair(Refs.
size(),
VC.Loc));
10467 for (
auto I : IdToIndexMap) {
10468 auto &Infos = ForwardRefValueInfos[
I.first];
10469 for (
auto P :
I.second) {
10471 "Forward referenced ValueInfo expected to be empty");
10472 Infos.emplace_back(&Refs[
P.first],
P.second);
10486bool LLParser::parseOptionalTypeIdInfo(
10487 FunctionSummary::TypeIdInfo &TypeIdInfo) {
10496 switch (Lex.getKind()) {
10498 if (parseTypeTests(TypeIdInfo.
TypeTests))
10522 return error(Lex.getLoc(),
"invalid typeIdInfo list type");
10526 if (parseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
10535bool LLParser::parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests) {
10543 IdToIndexMapType IdToIndexMap;
10547 unsigned ID = Lex.getUIntVal();
10548 LocTy Loc = Lex.getLoc();
10552 IdToIndexMap[
ID].push_back(std::make_pair(TypeTests.size(), Loc));
10554 }
else if (parseUInt64(GUID))
10556 TypeTests.push_back(GUID);
10561 for (
auto I : IdToIndexMap) {
10562 auto &Ids = ForwardRefTypeIds[
I.first];
10563 for (
auto P :
I.second) {
10564 assert(TypeTests[
P.first] == 0 &&
10565 "Forward referenced type id GUID expected to be 0");
10566 Ids.emplace_back(&TypeTests[
P.first],
P.second);
10570 if (parseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
10578bool LLParser::parseVFuncIdList(
10579 lltok::Kind Kind, std::vector<FunctionSummary::VFuncId> &VFuncIdList) {
10580 assert(Lex.getKind() == Kind);
10587 IdToIndexMapType IdToIndexMap;
10589 FunctionSummary::VFuncId VFuncId;
10590 if (parseVFuncId(VFuncId, IdToIndexMap, VFuncIdList.size()))
10592 VFuncIdList.push_back(VFuncId);
10600 for (
auto I : IdToIndexMap) {
10601 auto &Ids = ForwardRefTypeIds[
I.first];
10602 for (
auto P :
I.second) {
10603 assert(VFuncIdList[
P.first].GUID == 0 &&
10604 "Forward referenced type id GUID expected to be 0");
10605 Ids.emplace_back(&VFuncIdList[
P.first].GUID,
P.second);
10614bool LLParser::parseConstVCallList(
10616 std::vector<FunctionSummary::ConstVCall> &ConstVCallList) {
10617 assert(Lex.getKind() == Kind);
10624 IdToIndexMapType IdToIndexMap;
10626 FunctionSummary::ConstVCall ConstVCall;
10627 if (parseConstVCall(ConstVCall, IdToIndexMap, ConstVCallList.size()))
10629 ConstVCallList.push_back(ConstVCall);
10637 for (
auto I : IdToIndexMap) {
10638 auto &Ids = ForwardRefTypeIds[
I.first];
10639 for (
auto P :
I.second) {
10640 assert(ConstVCallList[
P.first].VFunc.GUID == 0 &&
10641 "Forward referenced type id GUID expected to be 0");
10642 Ids.emplace_back(&ConstVCallList[
P.first].VFunc.GUID,
P.second);
10651bool LLParser::parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
10652 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
10654 parseVFuncId(ConstVCall.
VFunc, IdToIndexMap, Index))
10658 if (parseArgs(ConstVCall.
Args))
10670bool LLParser::parseVFuncId(FunctionSummary::VFuncId &VFuncId,
10671 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
10681 unsigned ID = Lex.getUIntVal();
10682 LocTy Loc = Lex.getLoc();
10686 IdToIndexMap[
ID].push_back(std::make_pair(Index, Loc));
10688 }
else if (parseToken(
lltok::kw_guid,
"expected 'guid' here") ||
10690 parseUInt64(VFuncId.
GUID))
10696 parseUInt64(VFuncId.
Offset) ||
10708bool LLParser::parseGVFlags(GlobalValueSummary::GVFlags &GVFlags) {
10718 switch (Lex.getKind()) {
10725 assert(HasLinkage &&
"Linkage not optional in summary entry");
10732 parseOptionalVisibility(Flag);
10737 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10743 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10749 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10755 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10764 if (parseOptionalImportType(Lex.getKind(), IK))
10766 GVFlags.
ImportType =
static_cast<unsigned>(IK);
10770 return error(Lex.getLoc(),
"expected gv flag type");
10784bool LLParser::parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags) {
10792 auto ParseRest = [
this](
unsigned int &Val) {
10796 return parseFlag(Val);
10801 switch (Lex.getKind()) {
10802 case lltok::kw_readonly:
10803 if (ParseRest(Flag))
10807 case lltok::kw_writeonly:
10808 if (ParseRest(Flag))
10813 if (ParseRest(Flag))
10818 if (ParseRest(Flag))
10823 return error(Lex.getLoc(),
"expected gvar flag type");
10831bool LLParser::parseModuleReference(StringRef &ModulePath) {
10838 unsigned ModuleID = Lex.getUIntVal();
10839 auto I = ModuleIdMap.find(ModuleID);
10841 assert(
I != ModuleIdMap.end());
10842 ModulePath =
I->second;
10848bool LLParser::parseGVReference(ValueInfo &VI,
unsigned &GVId) {
10851 WriteOnly = EatIfPresent(lltok::kw_writeonly);
10855 GVId = Lex.getUIntVal();
10857 if (GVId < NumberedValueInfos.size() && NumberedValueInfos[GVId]) {
10859 VI = NumberedValueInfos[GVId];
10876bool LLParser::parseOptionalAllocs(std::vector<AllocInfo> &Allocs) {
10880 if (parseToken(
lltok::colon,
"expected ':' in allocs") ||
10892 SmallVector<uint8_t> Versions;
10895 if (parseAllocType(V))
10900 if (parseToken(
lltok::rparen,
"expected ')' in versions") ||
10904 std::vector<MIBInfo> MIBs;
10905 if (parseMemProfs(MIBs))
10908 Allocs.push_back({Versions, MIBs});
10925bool LLParser::parseMemProfs(std::vector<MIBInfo> &MIBs) {
10929 if (parseToken(
lltok::colon,
"expected ':' in memprof") ||
10935 if (parseToken(
lltok::lparen,
"expected '(' in memprof") ||
10944 if (parseToken(
lltok::comma,
"expected ',' in memprof") ||
10950 SmallVector<unsigned> StackIdIndices;
10954 uint64_t StackId = 0;
10955 if (parseUInt64(StackId))
10957 StackIdIndices.
push_back(Index->addOrGetStackIdIndex(StackId));
10978bool LLParser::parseAllocType(uint8_t &
AllocType) {
10979 switch (Lex.getKind()) {
10986 case lltok::kw_cold:
10989 case lltok::kw_hot:
10993 return error(Lex.getLoc(),
"invalid alloc type");
11006bool LLParser::parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites) {
11010 if (parseToken(
lltok::colon,
"expected ':' in callsites") ||
11014 IdToIndexMapType IdToIndexMap;
11017 if (parseToken(
lltok::lparen,
"expected '(' in callsite") ||
11024 LocTy Loc = Lex.getLoc();
11026 if (parseGVReference(VI, GVId))
11030 if (parseToken(
lltok::comma,
"expected ',' in callsite") ||
11036 SmallVector<unsigned> Clones;
11039 if (parseUInt32(V))
11045 parseToken(
lltok::comma,
"expected ',' in callsite") ||
11051 SmallVector<unsigned> StackIdIndices;
11055 uint64_t StackId = 0;
11056 if (parseUInt64(StackId))
11058 StackIdIndices.
push_back(Index->addOrGetStackIdIndex(StackId));
11069 IdToIndexMap[GVId].
push_back(std::make_pair(Callsites.size(), Loc));
11070 Callsites.push_back({
VI, Clones, StackIdIndices});
11078 for (
auto I : IdToIndexMap) {
11079 auto &Infos = ForwardRefValueInfos[
I.first];
11080 for (
auto P :
I.second) {
11082 "Forward referenced ValueInfo expected to be empty");
11083 Infos.emplace_back(&Callsites[
P.first].Callee,
P.second);
11087 if (parseToken(
lltok::rparen,
"expected ')' in callsites"))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Unify divergent function exit nodes
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
Function Alias Analysis false
Expand Atomic instructions
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
GlobalValue::SanitizerMetadata SanitizerMetadata
Module.h This file contains the declarations for the Module class.
static GlobalValue * createGlobalFwdRef(Module *M, PointerType *PTy)
static cl::opt< bool > AllowIncompleteIR("allow-incomplete-ir", cl::init(false), cl::Hidden, cl::desc("Allow incomplete IR on a best effort basis (references to unknown " "metadata will be dropped)"))
static void maybeSetDSOLocal(bool DSOLocal, GlobalValue &GV)
static bool upgradeMemoryAttr(MemoryEffects &ME, lltok::Kind Kind)
static std::optional< MemoryEffects::Location > keywordToLoc(lltok::Kind Tok)
static void resolveFwdRef(ValueInfo *Fwd, ValueInfo &Resolved)
static unsigned parseOptionalLinkageAux(lltok::Kind Kind, bool &HasLinkage)
static unsigned keywordToFPClassTest(lltok::Kind Tok)
#define CC_VLS_CASE(ABIVlen)
static std::optional< ModRefInfo > keywordToModRef(lltok::Kind Tok)
static bool isSanitizer(lltok::Kind Kind)
static void dropIntrinsicWithUnknownMetadataArgument(IntrinsicInst *II)
#define PARSE_MD_FIELDS()
static Attribute::AttrKind tokenToAttribute(lltok::Kind Kind)
#define GET_OR_DISTINCT(CLASS, ARGS)
bool isOldDbgFormatIntrinsic(StringRef Name)
static bool isValidVisibilityForLinkage(unsigned V, unsigned L)
static std::string getTypeString(Type *T)
static bool isValidDLLStorageClassForLinkage(unsigned S, unsigned L)
static const auto FwdVIRef
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
PowerPC Reduce CR logical Operation
static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)
const SmallVectorImpl< MachineOperand > & Cond
dot regions Print regions of function to dot file(with no function bodies)"
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file provides utility classes that use RAII to save and restore values.
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file defines the SmallPtrSet class.
FunctionLoweringInfo::StatepointRelocationRecord RecordType
static SymbolRef::Type getType(const Symbol *Sym)
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
static const fltSemantics & IEEEsingle()
static const fltSemantics & BFloat()
static const fltSemantics & IEEEdouble()
static constexpr roundingMode rmNearestTiesToEven
static const fltSemantics & IEEEhalf()
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
APSInt extOrTrunc(uint32_t width) const
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
void setWeak(bool IsWeak)
static bool isValidFailureOrdering(AtomicOrdering Ordering)
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
void setVolatile(bool V)
Specify whether this is a volatile RMW or not.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
static LLVM_ABI StringRef getOperationName(BinOp Op)
static LLVM_ABI AttributeSet get(LLVMContext &C, const AttrBuilder &B)
static LLVM_ABI bool canUseAsRetAttr(AttrKind Kind)
static bool isTypeAttrKind(AttrKind Kind)
static LLVM_ABI bool canUseAsFnAttr(AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
static LLVM_ABI bool canUseAsParamAttr(AttrKind Kind)
LLVM Basic Block Representation.
LLVM_ABI void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
void setCallingConv(CallingConv::ID CC)
void setAttributes(AttributeList A)
Set the attributes for this call.
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
void setTailCallKind(TailCallKind TCK)
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, InsertPosition InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static LLVM_ABI Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static LLVM_ABI Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static LLVM_ABI Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static LLVM_ABI bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
static LLVM_ABI std::optional< ConstantRangeList > getConstantRangeList(ArrayRef< ConstantRange > RangesRef)
static ConstantRange getNonEmpty(APInt Lower, APInt Upper)
Create non-empty constant range with the given bounds.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
static DIAssignID * getDistinct(LLVMContext &Context)
DebugEmissionKind getEmissionKind() const
DebugNameTableKind getNameTableKind() const
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
static LLVM_ABI std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
ChecksumKind
Which algorithm (e.g.
static LLVM_ABI std::optional< FixedPointKind > getFixedPointKind(StringRef Str)
static LLVM_ABI DIFlags getFlag(StringRef Flag)
static LLVM_ABI DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
static LLVM_ABI DISPFlags getFlag(StringRef Flag)
DISPFlags
Debug info subprogram flags.
static LLVM_ABI DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
static LLVM_ABI Expected< DataLayout > parse(StringRef LayoutString)
Parse a data layout string and return the layout.
static LLVM_ABI DbgLabelRecord * createUnresolvedDbgLabelRecord(MDNode *Label, MDNode *DL)
For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved MDNodes.
Kind
Subclass discriminator.
static LLVM_ABI DbgVariableRecord * createUnresolvedDbgVariableRecord(LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, MDNode *AssignID, Metadata *Address, MDNode *AddressExpression, MDNode *DI)
Used to create DbgVariableRecords during parsing, where some metadata references may still be unresol...
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
static constexpr ElementCount getFixed(ScalarTy MinVal)
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
static LLVM_ABI bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
Type::subtype_iterator param_iterator
static LLVM_ABI bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void setPrefixData(Constant *PrefixData)
void setGC(std::string Str)
void setPersonalityFn(Constant *Fn)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
void setAlignment(Align Align)
Sets the alignment attribute of the Function.
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
void setPrologueData(Constant *PrologueData)
void setCallingConv(CallingConv::ID CC)
static GEPNoWrapFlags inBounds()
static GEPNoWrapFlags noUnsignedWrap()
static GEPNoWrapFlags noUnsignedSignedWrap()
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
static bool isValidLinkage(LinkageTypes L)
static LLVM_ABI GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static LLVM_ABI GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
LLVM_ABI void setComdat(Comdat *C)
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
LLVM_ABI const SanitizerMetadata & getSanitizerMetadata() const
static bool isLocalLinkage(LinkageTypes Linkage)
void setUnnamedAddr(UnnamedAddr Val)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
void setDLLStorageClass(DLLStorageClassTypes C)
void setThreadLocalMode(ThreadLocalMode Val)
void setLinkage(LinkageTypes LT)
DLLStorageClassTypes
Storage classes of global values for PE targets.
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
bool hasSanitizerMetadata() const
unsigned getAddressSpace() const
void setDSOLocal(bool Local)
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
static bool isValidDeclarationLinkage(LinkageTypes Linkage)
static LLVM_ABI std::string getGlobalIdentifier(StringRef Name, GlobalValue::LinkageTypes Linkage, StringRef FileName)
Return the modified name for a global value suitable to be used as the key for a global lookup (e....
void setVisibility(VisibilityTypes V)
LLVM_ABI void setSanitizerMetadata(SanitizerMetadata Meta)
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Type * getValueType() const
LLVM_ABI void setPartition(StringRef Part)
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
void setAttributes(AttributeSet A)
Set attribute list for this global.
void setConstant(bool Val)
LLVM_ABI void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
void setExternallyInitialized(bool Val)
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
LLVM_ABI void addDestination(BasicBlock *Dest)
Add a destination.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
static LLVM_ABI InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT, bool canThrow=false)
InlineAsm::get - Return the specified uniqued inline asm string.
static LLVM_ABI Error verify(FunctionType *Ty, StringRef Constraints)
This static method can be used by the parser to check to see if the specified constraint string is le...
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
LLVM_ABI void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
bool isTerminator() const
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_ABI InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
A wrapper class for inspecting calls to intrinsic functions.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
lltok::Kind getKind() const
bool parseDIExpressionBodyAtBeginning(MDNode *&Result, unsigned &Read, const SlotMapping *Slots)
LLVMContext & getContext()
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
bool Run(bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Run: module ::= toplevelentity*.
static LLVM_ABI LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
static MemoryEffectsBase readOnly()
MemoryEffectsBase getWithModRef(Location Loc, ModRefInfo MR) const
Get new MemoryEffectsBase with modified ModRefInfo for Loc.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase writeOnly()
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase none()
static MemoryEffectsBase unknown()
A Module instance is used to store all the information related to an LLVM module.
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
LLVM_ABI void addOperand(MDNode *M)
static LLVM_ABI NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static ResumeInst * Create(Value *Exn, InsertPosition InsertBefore=nullptr)
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
Represents a location in source code.
constexpr const char * getPointer() const
static LLVM_ABI const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
ArrayRef< int > getShuffleMask() const
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator find(StringRef Key)
StringMapIterBase< Comdat, false > iterator
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
LLVM_ABI Error setBodyOrError(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type or return an error if it would make the type recursive.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Returns true if this struct contains a scalable vector.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, InsertPosition InsertBefore=nullptr)
@ HasZeroInit
zeroinitializer is valid for this target extension type.
static LLVM_ABI Expected< TargetExtType * > getOrError(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters,...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
bool isLabelTy() const
Return true if this is 'label'.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
static LLVM_ABI Type * getLabelTy(LLVMContext &C)
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isAggregateType() const
Return true if the type is an aggregate type.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isFunctionTy() const
True if this is an instance of FunctionType.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isTokenTy() const
Return true if this is 'token'.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
bool isVoidTy() const
Return true if this is 'void'.
bool isMetadataTy() const
Return true if this is 'metadata'.
static LLVM_ABI UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
static constexpr uint64_t MaximumAlignment
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI void deleteValue()
Delete a pointer to a generic Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
self_iterator getIterator()
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
LLVM_ABI unsigned getSourceLanguageName(StringRef SourceLanguageNameString)
LLVM_ABI unsigned getOperationEncoding(StringRef OperationEncodingString)
LLVM_ABI unsigned getAttributeEncoding(StringRef EncodingString)
LLVM_ABI unsigned getTag(StringRef TagString)
LLVM_ABI unsigned getCallingConvention(StringRef LanguageString)
LLVM_ABI unsigned getLanguage(StringRef LanguageString)
LLVM_ABI unsigned getVirtuality(StringRef VirtualityString)
LLVM_ABI unsigned getEnumKind(StringRef EnumKindString)
LLVM_ABI unsigned getMacinfo(StringRef MacinfoString)
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AArch64_VectorCall
Used between AArch64 Advanced SIMD functions.
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ RISCV_VectorCall
Calling convention used for RISC-V V-extension.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AVR_SIGNAL
Used for AVR signal routines.
@ Swift
Calling convention for Swift.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AArch64_SVE_VectorCall
Used between AArch64 SVE functions.
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
@ CHERIoT_CompartmentCall
Calling convention used for CHERIoT when crossing a protection boundary.
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
@ AVR_INTR
Used for AVR interrupt routines.
@ PreserveMost
Used for runtime calls that preserves most registers.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ AMDGPU_Gfx
Used for AMD graphics targets.
@ DUMMY_HHVM
Placeholders for HHVM calling conventions (deprecated, removed).
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
@ CHERIoT_CompartmentCallee
Calling convention used for the callee of CHERIoT_CompartmentCall.
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2
Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ CHERIoT_LibraryCall
Calling convention used for CHERIoT for cross-library calls to a stateless compartment.
@ CXX_FAST_TLS
Used for access functions.
@ X86_INTR
x86 hardware interrupt context.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0
Preserve X0-X13, X19-X29, SP, Z0-Z31, P0-P15.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1
Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ X86_ThisCall
Similar to X86_StdCall.
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
@ X86_StdCall
stdcall is mostly used by the Win32 API.
@ SPIR_FUNC
Used for SPIR non-kernel device functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ MSP430_INTR
Used for MSP430 interrupt routines.
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ PreserveNone
Used for runtime calls that preserves none general registers.
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
@ M68k_RTD
Used for M68k rtd-based CC (similar to X86's stdcall).
@ C
The default llvm calling convention, compatible with C.
@ X86_FastCall
'fast' analog of X86_StdCall.
@ BasicBlock
Various leaf nodes.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
LLVM_ABI bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT, SmallVectorImpl< Type * > &ArgTys)
Gets the type arguments of an intrinsic call by matching type contraints specified by the ....
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ System
Synchronized with respect to all concurrently executing threads.
@ Valid
The data is already valid.
initializer< Ty > init(const Ty &Val)
@ DW_TAG_invalid
LLVM mock tags (see also llvm/BinaryFormat/Dwarf.def).
@ DW_MACINFO_invalid
Macinfo type for invalid results.
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
@ DW_VIRTUALITY_invalid
Virtuality for invalid results.
@ kw_aarch64_sme_preservemost_from_x1
@ kw_no_sanitize_hwaddress
@ kw_cheriot_librarycallcc
@ kw_cheriot_compartmentcalleecc
@ kw_typeCheckedLoadConstVCalls
@ kw_aarch64_sve_vector_pcs
@ kw_cheriot_compartmentcallcc
@ kw_amdgpu_gfx_whole_wave
@ kw_typeTestAssumeConstVCalls
@ kw_typeidCompatibleVTable
@ kw_typeCheckedLoadVCalls
@ kw_inaccessiblemem_or_argmemonly
@ kw_externally_initialized
@ kw_sanitize_address_dyninit
@ kw_amdgpu_cs_chain_preserve
@ kw_available_externally
@ kw_typeTestAssumeVCalls
@ kw_aarch64_sme_preservemost_from_x0
@ kw_dso_local_equivalent
@ kw_aarch64_sme_preservemost_from_x2
NodeAddr< NodeBase * > Node
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
LLVM_ABI void UpgradeIntrinsicCall(CallBase *CB, Function *NewFn)
This is the complement to the above, replacing a specific call to an intrinsic function with a call t...
LLVM_ABI void UpgradeSectionAttributes(Module &M)
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
SaveAndRestore(T &) -> SaveAndRestore< T >
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn, bool CanUpgradeDebugIntrinsicsToRecords=true)
This is a more granular function that simply checks an intrinsic function for upgrading,...
LLVM_ABI void UpgradeCallsToIntrinsic(Function *F)
This is an auto-upgrade hook for any old intrinsic function syntaxes which need to have both the func...
LLVM_ABI void UpgradeNVVMAnnotations(Module &M)
Convert legacy nvvm.annotations metadata to appropriate function attributes.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
auto cast_or_null(const Y &Val)
LLVM_ABI bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
void copyModuleAttrToFunctions(Module &M)
Copies module attributes to the functions in the module.
auto dyn_cast_or_null(const Y &Val)
@ Async
"Asynchronous" unwind tables (instr precise)
@ Sync
"Synchronous" unwind tables
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
void sort(IteratorTy Start, IteratorTy End)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
bool isPointerTy(const Type *T)
FunctionAddr VTableAddr Count
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
CaptureComponents
Components of the pointer that may be captured.
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Ref
The access may reference the value stored in memory.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
@ ArgMem
Access to memory via argument pointers.
@ TargetMem0
Represents target specific state.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ InaccessibleMem
Memory that is inaccessible via LLVM IR.
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
LLVM_ABI bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
static int64_t upperBound(StackOffset Size)
bool capturesNothing(CaptureComponents CC)
LLVM_ABI MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
std::vector< uint64_t > Args
unsigned ReturnDoesNotAlias
unsigned MustBeUnreachable
static constexpr uint32_t RangeWidth
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
std::vector< ConstVCall > TypeCheckedLoadConstVCalls
std::vector< VFuncId > TypeCheckedLoadVCalls
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
unsigned ImportType
This field is written by the ThinLTO indexing step to postlink combined summary.
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
unsigned Linkage
The linkage type of the associated global value.
unsigned Visibility
Indicates the visibility.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
std::map< unsigned, Type * > Types
StringMap< Type * > NamedTypes
std::map< unsigned, TrackingMDNodeRef > MetadataNodes
NumberedValues< GlobalValue * > GlobalValues
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.
@ Unknown
Unknown (analysis not performed, don't lower)
@ Single
Single element (last example in "Short Inline Bit Vectors")
@ Inline
Inlined bit vector ("Short Inline Bit Vectors")
@ Unsat
Unsatisfiable type (i.e. no global has this type metadata)
@ AllOnes
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors")
@ ByteArray
Test a byte array (first example)
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
enum llvm::TypeTestResolution::Kind TheKind
ValID - Represents a reference of a definition of some sort with no type.
enum llvm::ValID::@273232264270353276247031231016211363171152164072 Kind
Struct that holds a reference to a particular GUID in a global value summary.
const GlobalValueSummaryMapTy::value_type * getRef() const
@ UniformRetVal
Uniform return value optimization.
@ VirtualConstProp
Virtual constant propagation.
@ UniqueRetVal
Unique return value optimization.
@ Indir
Just do a regular virtual call.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName
@ SingleImpl
Single implementation devirtualization.
@ Indir
Just do a regular virtual call.
@ BranchFunnel
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module.