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 (StringMap<std::pair<Type*, LocTy> >::iterator
I =
319 NamedTypes.begin(),
E = NamedTypes.end();
I !=
E; ++
I)
320 if (
I->second.second.isValid())
321 return error(
I->second.second,
322 "use of undefined type named '" +
I->getKey() +
"'");
324 if (!ForwardRefComdats.empty())
325 return error(ForwardRefComdats.begin()->second,
326 "use of undefined comdat '$" +
327 ForwardRefComdats.begin()->first +
"'");
341 if (!CB || !CB->isCallee(&U))
342 return error(
Info.second,
"intrinsic can only be used as callee");
356 return error(
Info.second,
"unknown intrinsic '" + Name +
"'");
357 return error(
Info.second,
"invalid intrinsic signature");
367 Info.first->eraseFromParent();
368 ForwardRefVals.erase(Name);
377 auto GetCommonFunctionType = [](
Value *
V) -> FunctionType * {
378 FunctionType *FTy =
nullptr;
379 for (Use &U :
V->uses()) {
381 if (!CB || !CB->isCallee(&U) || (FTy && FTy != CB->getFunctionType()))
383 FTy = CB->getFunctionType();
391 Type *Ty = GetCommonFunctionType(
Info.first);
399 GV =
new GlobalVariable(*M, Ty,
false,
402 Info.first->replaceAllUsesWith(GV);
403 Info.first->eraseFromParent();
404 ForwardRefVals.erase(Name);
407 if (!ForwardRefVals.empty())
408 return error(ForwardRefVals.begin()->second.second,
409 "use of undefined value '@" + ForwardRefVals.begin()->first +
412 if (!ForwardRefValIDs.empty())
413 return error(ForwardRefValIDs.begin()->second.second,
414 "use of undefined value '@" +
415 Twine(ForwardRefValIDs.begin()->first) +
"'");
418 dropUnknownMetadataReferences();
420 if (!ForwardRefMDNodes.empty())
421 return error(ForwardRefMDNodes.begin()->second.second,
422 "use of undefined metadata '!" +
423 Twine(ForwardRefMDNodes.begin()->first) +
"'");
426 for (
auto &
N : NumberedMetadata) {
427 if (
N.second && !
N.second->isResolved())
428 N.second->resolveCycles();
431 for (
auto *Inst : InstsWithTBAATag) {
432 MDNode *MD = Inst->getMetadata(LLVMContext::MD_tbaa);
435 assert(MD &&
"UpgradeInstWithTBAATag should have a TBAA tag");
438 if (MD != UpgradedMD)
439 Inst->setMetadata(LLVMContext::MD_tbaa, UpgradedMD);
448 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() {
757 unsigned FunctionNumber = -1;
758 SmallVector<unsigned> UnnamedArgNums;
759 return parseFunctionHeader(
F,
true, FunctionNumber, UnnamedArgNums) ||
760 parseOptionalFunctionMetadata(*
F) ||
761 parseFunctionBody(*
F, FunctionNumber, UnnamedArgNums);
767bool LLParser::parseGlobalType(
bool &IsConstant) {
774 return tokError(
"expected 'global' or 'constant'");
780bool LLParser::parseOptionalUnnamedAddr(
801bool LLParser::parseUnnamedGlobal() {
804 LocTy NameLoc = Lex.getLoc();
808 VarID = Lex.getUIntVal();
809 if (checkValueID(NameLoc,
"global",
"@", NumberedVals.getNext(),
VarID))
813 if (parseToken(
lltok::equal,
"expected '=' after name"))
816 VarID = NumberedVals.getNext();
820 unsigned Linkage, Visibility, DLLStorageClass;
824 if (parseOptionalLinkage(
Linkage, HasLinkage, Visibility, DLLStorageClass,
826 parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
829 switch (Lex.getKind()) {
831 return parseGlobal(Name,
VarID, NameLoc,
Linkage, HasLinkage, Visibility,
832 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
835 return parseAliasOrIFunc(Name,
VarID, NameLoc,
Linkage, Visibility,
836 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
845bool LLParser::parseNamedGlobal() {
847 LocTy NameLoc = Lex.getLoc();
848 std::string
Name = Lex.getStrVal();
852 unsigned Linkage, Visibility, DLLStorageClass;
856 if (parseToken(
lltok::equal,
"expected '=' in global variable") ||
857 parseOptionalLinkage(
Linkage, HasLinkage, Visibility, DLLStorageClass,
859 parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
862 switch (Lex.getKind()) {
864 return parseGlobal(Name, -1, NameLoc,
Linkage, HasLinkage, Visibility,
865 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
868 return parseAliasOrIFunc(Name, -1, NameLoc,
Linkage, Visibility,
869 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
873bool LLParser::parseComdat() {
875 std::string
Name = Lex.getStrVal();
876 LocTy NameLoc = Lex.getLoc();
883 return tokError(
"expected comdat type");
886 switch (Lex.getKind()) {
888 return tokError(
"unknown selection kind");
910 if (
I != ComdatSymTab.
end() && !ForwardRefComdats.erase(Name))
911 return error(NameLoc,
"redefinition of comdat '$" + Name +
"'");
914 if (
I != ComdatSymTab.
end())
917 C = M->getOrInsertComdat(Name);
918 C->setSelectionKind(SK);
925bool LLParser::parseMDString(
MDString *&Result) {
927 if (parseStringConstant(Str))
935bool LLParser::parseMDNodeID(
MDNode *&Result) {
937 LocTy IDLoc = Lex.getLoc();
939 if (parseUInt32(MID))
943 auto [It,
Inserted] = NumberedMetadata.try_emplace(MID);
950 auto &FwdRef = ForwardRefMDNodes[MID];
953 Result = FwdRef.first.get();
954 It->second.reset(Result);
960bool LLParser::parseNamedMetadata() {
962 std::string
Name = Lex.getStrVal();
970 NamedMDNode *NMD = M->getOrInsertNamedMetadata(Name);
978 Lex.getStrVal() ==
"DIExpression") {
979 if (parseDIExpression(
N,
false))
984 Lex.getStrVal() ==
"DIArgList") {
985 return tokError(
"found DIArgList outside of function");
993 return parseToken(
lltok::rbrace,
"expected end of metadata node");
998bool LLParser::parseStandaloneMetadata() {
1001 unsigned MetadataID = 0;
1004 if (parseUInt32(MetadataID) || parseToken(
lltok::equal,
"expected '=' here"))
1009 return tokError(
"unexpected type in metadata definition");
1013 if (parseSpecializedMDNode(Init, IsDistinct))
1016 parseMDTuple(Init, IsDistinct))
1020 auto FI = ForwardRefMDNodes.find(MetadataID);
1021 if (FI != ForwardRefMDNodes.end()) {
1022 auto *ToReplace = FI->second.first.get();
1026 for (
auto *Inst : TempDIAssignIDAttachments[ToReplace]) {
1027 assert(!Inst->getMetadata(LLVMContext::MD_DIAssignID) &&
1028 "Inst unexpectedly already has DIAssignID attachment");
1029 Inst->setMetadata(LLVMContext::MD_DIAssignID, Init);
1033 ToReplace->replaceAllUsesWith(Init);
1034 ForwardRefMDNodes.erase(FI);
1036 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
1038 auto [It,
Inserted] = NumberedMetadata.try_emplace(MetadataID);
1040 return tokError(
"Metadata id is already used");
1041 It->second.reset(Init);
1048bool LLParser::skipModuleSummaryEntry() {
1058 "Expected 'gv', 'module', 'typeid', 'flags' or 'blockcount' at the "
1059 "start of summary entry");
1061 return parseSummaryIndexFlags();
1063 return parseBlockCount();
1065 if (parseToken(
lltok::colon,
"expected ':' at start of summary entry") ||
1066 parseToken(
lltok::lparen,
"expected '(' at start of summary entry"))
1070 unsigned NumOpenParen = 1;
1072 switch (Lex.getKind()) {
1080 return tokError(
"found end of file while parsing summary entry");
1086 }
while (NumOpenParen > 0);
1092bool LLParser::parseSummaryEntry() {
1098 Lex.setIgnoreColonInIdentifiers(
true);
1106 return skipModuleSummaryEntry();
1108 bool result =
false;
1109 switch (Lex.getKind()) {
1111 result = parseGVEntry(SummaryID);
1114 result = parseModuleEntry(SummaryID);
1117 result = parseTypeIdEntry(SummaryID);
1120 result = parseTypeIdCompatibleVtableEntry(SummaryID);
1123 result = parseSummaryIndexFlags();
1126 result = parseBlockCount();
1129 result =
error(Lex.getLoc(),
"unexpected summary kind");
1132 Lex.setIgnoreColonInIdentifiers(
false);
1166bool LLParser::parseAliasOrIFunc(
const std::string &Name,
unsigned NameID,
1167 LocTy NameLoc,
unsigned L,
unsigned Visibility,
1168 unsigned DLLStorageClass,
bool DSOLocal,
1183 return error(NameLoc,
"invalid linkage type for alias");
1186 return error(NameLoc,
1187 "symbol with local linkage must have default visibility");
1190 return error(NameLoc,
1191 "symbol with local linkage cannot have a DLL storage class");
1194 LocTy ExplicitTypeLoc = Lex.getLoc();
1195 if (parseType(Ty) ||
1196 parseToken(
lltok::comma,
"expected comma after alias or ifunc's type"))
1200 LocTy AliaseeLoc = Lex.getLoc();
1205 if (parseGlobalTypeAndValue(Aliasee))
1210 if (parseValID(
ID,
nullptr))
1213 return error(AliaseeLoc,
"invalid aliasee");
1214 Aliasee =
ID.ConstantVal;
1220 return error(AliaseeLoc,
"An alias or ifunc must have pointer type");
1221 unsigned AddrSpace = PTy->getAddressSpace();
1223 GlobalValue *GVal =
nullptr;
1227 if (!
Name.empty()) {
1228 auto I = ForwardRefVals.find(Name);
1229 if (
I != ForwardRefVals.end()) {
1230 GVal =
I->second.first;
1231 ForwardRefVals.erase(Name);
1232 }
else if (M->getNamedValue(Name)) {
1233 return error(NameLoc,
"redefinition of global '@" + Name +
"'");
1236 auto I = ForwardRefValIDs.find(NameID);
1237 if (
I != ForwardRefValIDs.end()) {
1238 GVal =
I->second.first;
1239 ForwardRefValIDs.erase(
I);
1244 std::unique_ptr<GlobalAlias> GA;
1245 std::unique_ptr<GlobalIFunc> GI;
1273 if (parseGlobalObjectMetadataAttachment(*GI.get()))
1276 return tokError(
"unknown alias or ifunc property!");
1281 NumberedVals.add(NameID, GV);
1288 "forward reference and definition of alias have different types");
1298 M->insertAlias(GA.release());
1300 M->insertIFunc(GI.release());
1301 assert(GV->
getName() == Name &&
"Should not be a name conflict!");
1310 case lltok::kw_sanitize_memtag:
1324 switch (Lex.getKind()) {
1326 Meta.NoAddress =
true;
1329 Meta.NoHWAddress =
true;
1331 case lltok::kw_sanitize_memtag:
1335 Meta.IsDynInit =
true;
1338 return tokError(
"non-sanitizer token passed to LLParser::parseSanitizer()");
1358bool LLParser::parseGlobal(
const std::string &Name,
unsigned NameID,
1359 LocTy NameLoc,
unsigned Linkage,
bool HasLinkage,
1360 unsigned Visibility,
unsigned DLLStorageClass,
1364 return error(NameLoc,
1365 "symbol with local linkage must have default visibility");
1368 return error(NameLoc,
1369 "symbol with local linkage cannot have a DLL storage class");
1373 LocTy IsExternallyInitializedLoc;
1377 if (parseOptionalAddrSpace(AddrSpace) ||
1379 IsExternallyInitialized,
1380 &IsExternallyInitializedLoc) ||
1381 parseGlobalType(IsConstant) || parseType(Ty, TyLoc))
1390 if (parseGlobalValue(Ty, Init))
1395 return error(TyLoc,
"invalid type for global variable");
1397 GlobalValue *GVal =
nullptr;
1400 if (!
Name.empty()) {
1401 auto I = ForwardRefVals.find(Name);
1402 if (
I != ForwardRefVals.end()) {
1403 GVal =
I->second.first;
1404 ForwardRefVals.erase(
I);
1405 }
else if (M->getNamedValue(Name)) {
1406 return error(NameLoc,
"redefinition of global '@" + Name +
"'");
1411 if (NameID == (
unsigned)-1)
1412 NameID = NumberedVals.getNext();
1414 auto I = ForwardRefValIDs.find(NameID);
1415 if (
I != ForwardRefValIDs.end()) {
1416 GVal =
I->second.first;
1417 ForwardRefValIDs.erase(
I);
1421 GlobalVariable *GV =
new GlobalVariable(
1426 NumberedVals.add(NameID, GV);
1444 "forward reference and definition of global have different types");
1464 }
else if (Lex.getKind() == lltok::kw_align) {
1465 MaybeAlign Alignment;
1466 if (parseOptionalAlignment(Alignment))
1472 if (parseOptionalCodeModel(CodeModel))
1476 if (parseGlobalObjectMetadataAttachment(*GV))
1479 if (parseSanitizer(GV))
1483 if (parseOptionalComdat(Name,
C))
1488 return tokError(
"unknown global variable property!");
1492 AttrBuilder
Attrs(M->getContext());
1494 std::vector<unsigned> FwdRefAttrGrps;
1495 if (parseFnAttributeValuePairs(Attrs, FwdRefAttrGrps,
false, BuiltinLoc))
1497 if (
Attrs.hasAttributes() || !FwdRefAttrGrps.empty()) {
1499 ForwardRefAttrGroups[GV] = FwdRefAttrGrps;
1507bool LLParser::parseUnnamedAttrGrp() {
1509 LocTy AttrGrpLoc = Lex.getLoc();
1513 return tokError(
"expected attribute group id");
1515 unsigned VarID = Lex.getUIntVal();
1516 std::vector<unsigned> unused;
1524 auto R = NumberedAttrBuilders.find(
VarID);
1525 if (R == NumberedAttrBuilders.end())
1526 R = NumberedAttrBuilders.emplace(
VarID, AttrBuilder(M->getContext())).first;
1528 if (parseFnAttributeValuePairs(
R->second, unused,
true, BuiltinLoc) ||
1529 parseToken(
lltok::rbrace,
"expected end of attribute group"))
1532 if (!
R->second.hasAttributes())
1533 return error(AttrGrpLoc,
"attribute group has no attributes");
1540#define GET_ATTR_NAMES
1541#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
1542 case lltok::kw_##DISPLAY_NAME: \
1543 return Attribute::ENUM_NAME;
1544#include "llvm/IR/Attributes.inc"
1553 return parseRequiredTypeAttr(
B, Lex.getKind(), Attr);
1556 case Attribute::Alignment: {
1557 MaybeAlign Alignment;
1565 if (parseOptionalAlignment(Alignment,
true))
1568 B.addAlignmentAttr(Alignment);
1571 case Attribute::StackAlignment: {
1576 parseUInt32(Alignment))
1579 if (parseOptionalStackAlignment(Alignment))
1582 B.addStackAlignmentAttr(Alignment);
1585 case Attribute::AllocSize: {
1586 unsigned ElemSizeArg;
1587 std::optional<unsigned> NumElemsArg;
1588 if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg))
1590 B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1593 case Attribute::VScaleRange: {
1594 unsigned MinValue, MaxValue;
1595 if (parseVScaleRangeArguments(MinValue, MaxValue))
1597 B.addVScaleRangeAttr(MinValue,
1598 MaxValue > 0 ? MaxValue : std::optional<unsigned>());
1601 case Attribute::Dereferenceable: {
1603 if (parseOptionalDerefAttrBytes(lltok::kw_dereferenceable, Bytes))
1605 B.addDereferenceableAttr(Bytes);
1608 case Attribute::DereferenceableOrNull: {
1610 if (parseOptionalDerefAttrBytes(lltok::kw_dereferenceable_or_null, Bytes))
1612 B.addDereferenceableOrNullAttr(Bytes);
1615 case Attribute::UWTable: {
1617 if (parseOptionalUWTableKind(Kind))
1619 B.addUWTableAttr(Kind);
1622 case Attribute::AllocKind: {
1624 if (parseAllocKind(Kind))
1626 B.addAllocKindAttr(Kind);
1629 case Attribute::Memory: {
1630 std::optional<MemoryEffects> ME = parseMemoryAttr();
1633 B.addMemoryAttr(*ME);
1636 case Attribute::NoFPClass: {
1639 B.addNoFPClassAttr(NoFPClass);
1645 case Attribute::Range:
1646 return parseRangeAttr(
B);
1647 case Attribute::Initializes:
1648 return parseInitializesAttr(
B);
1649 case Attribute::Captures:
1650 return parseCapturesAttr(
B);
1652 B.addAttribute(Attr);
1660 case lltok::kw_readnone:
1663 case lltok::kw_readonly:
1666 case lltok::kw_writeonly:
1685bool LLParser::parseFnAttributeValuePairs(AttrBuilder &
B,
1686 std::vector<unsigned> &FwdRefAttrGrps,
1687 bool InAttrGrp, LocTy &BuiltinLoc) {
1688 bool HaveError =
false;
1699 if (parseStringAttribute(
B))
1711 "cannot have an attribute group reference in an attribute group");
1714 FwdRefAttrGrps.push_back(Lex.getUIntVal());
1720 SMLoc Loc = Lex.getLoc();
1721 if (Token == lltok::kw_builtin)
1733 return error(Lex.getLoc(),
"unterminated attribute group");
1736 if (parseEnumAttribute(Attr,
B, InAttrGrp))
1743 HaveError |=
error(Loc,
"this attribute does not apply to functions");
1747 B.addMemoryAttr(ME);
1761 PTy->getAddressSpace());
1770 error(Loc,
"'" + Name +
"' is not a basic block");
1772 error(Loc,
"'" + Name +
"' defined with type '" +
1785 error(Loc,
"global variable reference must have pointer type");
1796 auto I = ForwardRefVals.find(Name);
1797 if (
I != ForwardRefVals.end())
1798 Val =
I->second.first;
1804 checkValidVariableType(Loc,
"@" + Name, Ty, Val));
1808 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1815 error(Loc,
"global variable reference must have pointer type");
1819 GlobalValue *Val = NumberedVals.get(
ID);
1824 auto I = ForwardRefValIDs.find(
ID);
1825 if (
I != ForwardRefValIDs.end())
1826 Val =
I->second.first;
1832 checkValidVariableType(Loc,
"@" + Twine(
ID), Ty, Val));
1836 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1844Comdat *LLParser::getComdat(
const std::string &Name, LocTy
Loc) {
1848 if (
I != ComdatSymTab.
end())
1852 Comdat *
C = M->getOrInsertComdat(Name);
1853 ForwardRefComdats[
Name] = Loc;
1863bool LLParser::parseToken(
lltok::Kind T,
const char *ErrMsg) {
1864 if (Lex.getKind() !=
T)
1865 return tokError(ErrMsg);
1872bool LLParser::parseStringConstant(std::string &Result) {
1874 return tokError(
"expected string constant");
1875 Result = Lex.getStrVal();
1882bool LLParser::parseUInt32(uint32_t &Val) {
1883 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
1884 return tokError(
"expected integer");
1885 uint64_t Val64 = Lex.getAPSIntVal().getLimitedValue(0xFFFFFFFFULL+1);
1886 if (Val64 !=
unsigned(Val64))
1887 return tokError(
"expected 32-bit integer (too large)");
1895bool LLParser::parseUInt64(uint64_t &Val) {
1896 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
1897 return tokError(
"expected integer");
1898 Val = Lex.getAPSIntVal().getLimitedValue();
1908 switch (Lex.getKind()) {
1910 return tokError(
"expected localdynamic, initialexec or localexec");
1938 return parseTLSModel(TLM) ||
1939 parseToken(
lltok::rparen,
"expected ')' after thread local model");
1947bool LLParser::parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS) {
1948 AddrSpace = DefaultAS;
1952 auto ParseAddrspaceValue = [&](
unsigned &AddrSpace) ->
bool {
1954 auto AddrSpaceStr = Lex.getStrVal();
1955 if (AddrSpaceStr ==
"A") {
1956 AddrSpace = M->getDataLayout().getAllocaAddrSpace();
1957 }
else if (AddrSpaceStr ==
"G") {
1958 AddrSpace = M->getDataLayout().getDefaultGlobalsAddressSpace();
1959 }
else if (AddrSpaceStr ==
"P") {
1960 AddrSpace = M->getDataLayout().getProgramAddressSpace();
1962 return tokError(
"invalid symbolic addrspace '" + AddrSpaceStr +
"'");
1968 return tokError(
"expected integer or string constant");
1969 SMLoc Loc = Lex.getLoc();
1970 if (parseUInt32(AddrSpace))
1973 return error(Loc,
"invalid address space, must be a 24-bit integer");
1977 return parseToken(
lltok::lparen,
"expected '(' in address space") ||
1978 ParseAddrspaceValue(AddrSpace) ||
1985bool LLParser::parseStringAttribute(AttrBuilder &
B) {
1986 std::string Attr = Lex.getStrVal();
1989 if (EatIfPresent(
lltok::equal) && parseStringConstant(Val))
1991 B.addAttribute(Attr, Val);
1996bool LLParser::parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam) {
1997 bool HaveError =
false;
2004 if (parseStringAttribute(
B))
2015 SMLoc Loc = Lex.getLoc();
2020 if (parseEnumAttribute(Attr,
B,
false))
2024 HaveError |=
error(Loc,
"this attribute does not apply to parameters");
2026 HaveError |=
error(Loc,
"this attribute does not apply to return values");
2074bool LLParser::parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
2075 unsigned &Visibility,
2076 unsigned &DLLStorageClass,
bool &DSOLocal) {
2080 parseOptionalDSOLocal(DSOLocal);
2081 parseOptionalVisibility(Visibility);
2082 parseOptionalDLLStorageClass(DLLStorageClass);
2085 return error(Lex.getLoc(),
"dso_location and DLL-StorageClass mismatch");
2091void LLParser::parseOptionalDSOLocal(
bool &DSOLocal) {
2092 switch (Lex.getKind()) {
2113void LLParser::parseOptionalVisibility(
unsigned &Res) {
2114 switch (Lex.getKind()) {
2131bool LLParser::parseOptionalImportType(
lltok::Kind Kind,
2135 return tokError(
"unknown import kind. Expect definition or declaration.");
2150void LLParser::parseOptionalDLLStorageClass(
unsigned &Res) {
2151 switch (Lex.getKind()) {
2221bool LLParser::parseOptionalCallingConv(
unsigned &CC) {
2222 switch (Lex.getKind()) {
2309 return tokError(
"unknown RISC-V ABI VLEN");
2310#define CC_VLS_CASE(ABIVlen) \
2312 CC = CallingConv::RISCV_VLSCall_##ABIVlen; \
2340 return parseUInt32(CC);
2350bool LLParser::parseMetadataAttachment(
unsigned &Kind,
MDNode *&MD) {
2353 std::string
Name = Lex.getStrVal();
2354 Kind = M->getMDKindID(Name);
2357 return parseMDNode(MD);
2362bool LLParser::parseInstructionMetadata(
Instruction &Inst) {
2365 return tokError(
"expected metadata after comma");
2369 if (parseMetadataAttachment(MDK,
N))
2372 if (MDK == LLVMContext::MD_DIAssignID)
2373 TempDIAssignIDAttachments[
N].push_back(&Inst);
2377 if (MDK == LLVMContext::MD_tbaa)
2378 InstsWithTBAATag.push_back(&Inst);
2387bool LLParser::parseGlobalObjectMetadataAttachment(
GlobalObject &GO) {
2390 if (parseMetadataAttachment(MDK,
N))
2399bool LLParser::parseOptionalFunctionMetadata(
Function &
F) {
2401 if (parseGlobalObjectMetadataAttachment(
F))
2409bool LLParser::parseOptionalAlignment(
MaybeAlign &Alignment,
bool AllowParens) {
2410 Alignment = std::nullopt;
2411 if (!EatIfPresent(lltok::kw_align))
2413 LocTy AlignLoc = Lex.getLoc();
2416 LocTy ParenLoc = Lex.getLoc();
2417 bool HaveParens =
false;
2423 if (parseUInt64(
Value))
2427 return error(ParenLoc,
"expected ')'");
2430 return error(AlignLoc,
"alignment is not a power of two");
2432 return error(AlignLoc,
"huge alignments are not supported yet");
2442 auto StrVal = Lex.getStrVal();
2443 auto ErrMsg =
"expected global code model string";
2444 if (StrVal ==
"tiny")
2446 else if (StrVal ==
"small")
2448 else if (StrVal ==
"kernel")
2450 else if (StrVal ==
"medium")
2452 else if (StrVal ==
"large")
2455 return tokError(ErrMsg);
2466bool LLParser::parseOptionalDerefAttrBytes(
lltok::Kind AttrKind,
2468 assert((AttrKind == lltok::kw_dereferenceable ||
2469 AttrKind == lltok::kw_dereferenceable_or_null) &&
2473 if (!EatIfPresent(AttrKind))
2475 LocTy ParenLoc = Lex.getLoc();
2477 return error(ParenLoc,
"expected '('");
2478 LocTy DerefLoc = Lex.getLoc();
2479 if (parseUInt64(Bytes))
2481 ParenLoc = Lex.getLoc();
2483 return error(ParenLoc,
"expected ')'");
2485 return error(DerefLoc,
"dereferenceable bytes must be non-zero");
2489bool LLParser::parseOptionalUWTableKind(
UWTableKind &Kind) {
2494 LocTy KindLoc = Lex.getLoc();
2500 return error(KindLoc,
"expected unwind table kind");
2507 LocTy ParenLoc = Lex.getLoc();
2509 return error(ParenLoc,
"expected '('");
2510 LocTy KindLoc = Lex.getLoc();
2512 if (parseStringConstant(Arg))
2513 return error(KindLoc,
"expected allockind value");
2517 }
else if (
A ==
"realloc") {
2519 }
else if (
A ==
"free") {
2521 }
else if (
A ==
"uninitialized") {
2523 }
else if (
A ==
"zeroed") {
2525 }
else if (
A ==
"aligned") {
2528 return error(KindLoc, Twine(
"unknown allockind ") +
A);
2531 ParenLoc = Lex.getLoc();
2533 return error(ParenLoc,
"expected ')'");
2535 return error(KindLoc,
"expected allockind value");
2548 return std::nullopt;
2563 return std::nullopt;
2567std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
2572 Lex.setIgnoreColonInIdentifiers(
true);
2577 tokError(
"expected '('");
2578 return std::nullopt;
2581 bool SeenLoc =
false;
2583 std::optional<IRMemLocation> Loc =
keywordToLoc(Lex.getKind());
2587 tokError(
"expected ':' after location");
2588 return std::nullopt;
2595 tokError(
"expected memory location (argmem, inaccessiblemem, errnomem) "
2596 "or access kind (none, read, write, readwrite)");
2598 tokError(
"expected access kind (none, read, write, readwrite)");
2599 return std::nullopt;
2608 tokError(
"default access kind must be specified first");
2609 return std::nullopt;
2618 tokError(
"unterminated memory attribute");
2619 return std::nullopt;
2661unsigned LLParser::parseNoFPClassAttr() {
2666 tokError(
"expected '('");
2673 if (TestMask != 0) {
2677 !parseUInt64(
Value)) {
2679 error(Lex.getLoc(),
"invalid mask value for 'nofpclass'");
2684 error(Lex.getLoc(),
"expected ')'");
2690 error(Lex.getLoc(),
"expected nofpclass test mask");
2708bool LLParser::parseOptionalCommaAlign(
MaybeAlign &Alignment,
2709 bool &AteExtraComma) {
2710 AteExtraComma =
false;
2714 AteExtraComma =
true;
2718 if (Lex.getKind() != lltok::kw_align)
2719 return error(Lex.getLoc(),
"expected metadata or 'align'");
2721 if (parseOptionalAlignment(Alignment))
2734bool LLParser::parseOptionalCommaAddrSpace(
unsigned &AddrSpace, LocTy &
Loc,
2735 bool &AteExtraComma) {
2736 AteExtraComma =
false;
2740 AteExtraComma =
true;
2746 return error(Lex.getLoc(),
"expected metadata or 'addrspace'");
2748 if (parseOptionalAddrSpace(AddrSpace))
2755bool LLParser::parseAllocSizeArguments(
unsigned &BaseSizeArg,
2756 std::optional<unsigned> &HowManyArg) {
2759 auto StartParen = Lex.getLoc();
2761 return error(StartParen,
"expected '('");
2763 if (parseUInt32(BaseSizeArg))
2767 auto HowManyAt = Lex.getLoc();
2769 if (parseUInt32(HowMany))
2771 if (HowMany == BaseSizeArg)
2772 return error(HowManyAt,
2773 "'allocsize' indices can't refer to the same parameter");
2774 HowManyArg = HowMany;
2776 HowManyArg = std::nullopt;
2778 auto EndParen = Lex.getLoc();
2780 return error(EndParen,
"expected ')'");
2784bool LLParser::parseVScaleRangeArguments(
unsigned &MinValue,
2785 unsigned &MaxValue) {
2788 auto StartParen = Lex.getLoc();
2790 return error(StartParen,
"expected '('");
2792 if (parseUInt32(MinValue))
2796 if (parseUInt32(MaxValue))
2799 MaxValue = MinValue;
2801 auto EndParen = Lex.getLoc();
2803 return error(EndParen,
"expected ')'");
2812bool LLParser::parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
2817 return parseScope(SSID) || parseOrdering(Ordering);
2827 auto StartParenAt = Lex.getLoc();
2829 return error(StartParenAt,
"Expected '(' in syncscope");
2832 auto SSNAt = Lex.getLoc();
2833 if (parseStringConstant(SSN))
2834 return error(SSNAt,
"Expected synchronization scope name");
2836 auto EndParenAt = Lex.getLoc();
2838 return error(EndParenAt,
"Expected ')' in syncscope");
2840 SSID = Context.getOrInsertSyncScopeID(SSN);
2851 switch (Lex.getKind()) {
2853 return tokError(
"Expected ordering on atomic instruction");
2872bool LLParser::parseOptionalStackAlignment(
unsigned &Alignment) {
2874 if (!EatIfPresent(lltok::kw_alignstack))
2876 LocTy ParenLoc = Lex.getLoc();
2878 return error(ParenLoc,
"expected '('");
2879 LocTy AlignLoc = Lex.getLoc();
2880 if (parseUInt32(Alignment))
2882 ParenLoc = Lex.getLoc();
2884 return error(ParenLoc,
"expected ')'");
2886 return error(AlignLoc,
"stack alignment is not a power of two");
2900 bool &AteExtraComma) {
2901 AteExtraComma =
false;
2904 return tokError(
"expected ',' as start of index list");
2908 if (Indices.
empty())
2909 return tokError(
"expected index");
2910 AteExtraComma =
true;
2914 if (parseUInt32(Idx))
2927bool LLParser::parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid) {
2928 SMLoc TypeLoc = Lex.getLoc();
2929 switch (Lex.getKind()) {
2931 return tokError(Msg);
2940 if (
Result->isPointerTy()) {
2942 if (parseOptionalAddrSpace(AddrSpace))
2948 return tokError(
"ptr* is invalid - use ptr instead");
2959 if (parseTargetExtType(Result))
2965 if (parseAnonStructType(Result,
false))
2971 if (parseArrayVectorType(Result,
false))
2978 if (parseAnonStructType(Result,
true) ||
2979 parseToken(
lltok::greater,
"expected '>' at end of packed struct"))
2981 }
else if (parseArrayVectorType(Result,
true))
2986 std::pair<Type*, LocTy> &
Entry = NamedTypes[Lex.getStrVal()];
2992 Entry.second = Lex.getLoc();
3001 std::pair<Type*, LocTy> &
Entry = NumberedTypes[Lex.getUIntVal()];
3007 Entry.second = Lex.getLoc();
3017 switch (Lex.getKind()) {
3020 if (!AllowVoid &&
Result->isVoidTy())
3021 return error(TypeLoc,
"void type only allowed for function results");
3027 return tokError(
"basic block pointers are invalid");
3029 return tokError(
"pointers to void are invalid - use i8* instead");
3031 return tokError(
"pointer to this type is invalid");
3039 return tokError(
"basic block pointers are invalid");
3041 return tokError(
"pointers to void are invalid; use i8* instead");
3043 return tokError(
"pointer to this type is invalid");
3045 if (parseOptionalAddrSpace(AddrSpace) ||
3046 parseToken(
lltok::star,
"expected '*' in address space"))
3055 if (parseFunctionType(Result))
3068 PerFunctionState &PFS,
bool IsMustTailCall,
3069 bool InVarArgsFunc) {
3075 if (!ArgList.
empty() &&
3076 parseToken(
lltok::comma,
"expected ',' in argument list"))
3081 const char *Msg =
"unexpected ellipsis in argument list for ";
3082 if (!IsMustTailCall)
3083 return tokError(Twine(Msg) +
"non-musttail call");
3085 return tokError(Twine(Msg) +
"musttail call in non-varargs function");
3087 return parseToken(
lltok::rparen,
"expected ')' at end of argument list");
3092 Type *ArgTy =
nullptr;
3094 if (parseType(ArgTy, ArgLoc))
3097 return error(ArgLoc,
"invalid type for function argument");
3099 AttrBuilder ArgAttrs(M->getContext());
3102 if (parseMetadataAsValue(V, PFS))
3106 if (parseOptionalParamAttrs(ArgAttrs) || parseValue(ArgTy, V, PFS))
3113 if (IsMustTailCall && InVarArgsFunc)
3114 return tokError(
"expected '...' at end of argument list for musttail call "
3115 "in varargs function");
3123bool LLParser::parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
3126 if (!EatIfPresent(AttrToken))
3129 return error(Lex.getLoc(),
"expected '('");
3133 return error(Lex.getLoc(),
"expected ')'");
3135 B.addTypeAttr(AttrKind, Ty);
3141bool LLParser::parseRangeAttr(AttrBuilder &
B) {
3149 auto ParseAPSInt = [&](
unsigned BitWidth, APInt &Val) {
3151 return tokError(
"expected integer");
3152 if (Lex.getAPSIntVal().getBitWidth() >
BitWidth)
3154 "integer is too large for the bit width of specified type");
3155 Val = Lex.getAPSIntVal().extend(
BitWidth);
3160 if (parseToken(
lltok::lparen,
"expected '('") || parseType(Ty, TyLoc))
3163 return error(TyLoc,
"the range must have integer type!");
3171 return tokError(
"the range represent the empty set but limits aren't 0!");
3182bool LLParser::parseInitializesAttr(AttrBuilder &
B) {
3185 auto ParseAPSInt = [&](APInt &Val) {
3187 return tokError(
"expected integer");
3188 Val = Lex.getAPSIntVal().extend(64);
3208 return tokError(
"the range should not represent the full or empty set!");
3220 if (!CRLOrNull.has_value())
3221 return tokError(
"Invalid (unordered or overlapping) range list");
3222 B.addInitializesAttr(*CRLOrNull);
3226bool LLParser::parseCapturesAttr(AttrBuilder &
B) {
3228 std::optional<CaptureComponents>
Ret;
3232 Lex.setIgnoreColonInIdentifiers(
true);
3240 bool SeenComponent =
false;
3246 return tokError(
"duplicate 'ret' location");
3249 SeenComponent =
false;
3254 return tokError(
"cannot use 'none' with other component");
3258 return tokError(
"cannot use 'none' with other component");
3269 return tokError(
"expected one of 'none', 'address', 'address_is_null', "
3270 "'provenance' or 'read_provenance'");
3273 SeenComponent =
true;
3294bool LLParser::parseOptionalOperandBundles(
3296 LocTy BeginLoc = Lex.getLoc();
3302 if (!BundleList.
empty() &&
3303 parseToken(
lltok::comma,
"expected ',' in input list"))
3307 if (parseStringConstant(
Tag))
3310 if (parseToken(
lltok::lparen,
"expected '(' in operand bundle"))
3313 std::vector<Value *> Inputs;
3316 if (!Inputs.empty() &&
3317 parseToken(
lltok::comma,
"expected ',' in input list"))
3321 Value *Input =
nullptr;
3325 if (parseMetadataAsValue(Input, PFS))
3327 }
else if (parseValue(Ty, Input, PFS)) {
3330 Inputs.push_back(Input);
3338 if (BundleList.
empty())
3339 return error(BeginLoc,
"operand bundle set must not be empty");
3346 unsigned NextID,
unsigned ID) {
3348 return error(Loc, Kind +
" expected to be numbered '" + Prefix +
3349 Twine(NextID) +
"' or greater");
3366 unsigned CurValID = 0;
3380 LocTy TypeLoc = Lex.getLoc();
3381 Type *ArgTy =
nullptr;
3382 AttrBuilder
Attrs(M->getContext());
3383 if (parseType(ArgTy) || parseOptionalParamAttrs(Attrs))
3387 return error(TypeLoc,
"argument can not have void type");
3391 Name = Lex.getStrVal();
3396 ArgID = Lex.getUIntVal();
3397 if (checkValueID(TypeLoc,
"argument",
"%", CurValID, ArgID))
3404 CurValID = ArgID + 1;
3408 return error(TypeLoc,
"invalid type for function argument");
3416 return parseToken(
lltok::rparen,
"expected ')' at end of argument list");
3421bool LLParser::parseFunctionType(
Type *&Result) {
3425 return tokError(
"invalid function return type");
3429 SmallVector<unsigned> UnnamedArgNums;
3430 if (parseArgumentList(ArgList, UnnamedArgNums, IsVarArg))
3434 for (
const ArgInfo &Arg : ArgList) {
3435 if (!Arg.Name.empty())
3436 return error(Arg.Loc,
"argument name invalid in function type");
3437 if (Arg.Attrs.hasAttributes())
3438 return error(Arg.Loc,
"argument attributes invalid in function type");
3442 for (
const ArgInfo &Arg : ArgList)
3451bool LLParser::parseAnonStructType(
Type *&Result,
bool Packed) {
3453 if (parseStructBody(Elts))
3461bool LLParser::parseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
3462 std::pair<Type *, LocTy> &Entry,
3466 return error(TypeLoc,
"redefinition of type");
3472 Entry.second = SMLoc();
3477 ResultTy =
Entry.first;
3489 return error(TypeLoc,
"forward references to non-struct type");
3493 return parseArrayVectorType(ResultTy,
true);
3494 return parseType(ResultTy);
3498 Entry.second = SMLoc();
3507 if (parseStructBody(Body) ||
3508 (isPacked && parseToken(
lltok::greater,
"expected '>' in packed struct")))
3512 return tokError(
toString(std::move(
E)));
3532 LocTy EltTyLoc = Lex.getLoc();
3539 return error(EltTyLoc,
"invalid element type for struct");
3542 EltTyLoc = Lex.getLoc();
3547 return error(EltTyLoc,
"invalid element type for struct");
3552 return parseToken(
lltok::rbrace,
"expected '}' at end of struct");
3561bool LLParser::parseArrayVectorType(
Type *&Result,
bool IsVector) {
3562 bool Scalable =
false;
3566 if (parseToken(
lltok::kw_x,
"expected 'x' after vscale"))
3572 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned() ||
3573 Lex.getAPSIntVal().getBitWidth() > 64)
3574 return tokError(
"expected number in address space");
3576 LocTy SizeLoc = Lex.getLoc();
3577 uint64_t
Size = Lex.getAPSIntVal().getZExtValue();
3580 if (parseToken(
lltok::kw_x,
"expected 'x' after element count"))
3583 LocTy TypeLoc = Lex.getLoc();
3584 Type *EltTy =
nullptr;
3585 if (parseType(EltTy))
3589 "expected end of sequential type"))
3594 return error(SizeLoc,
"zero element vector is illegal");
3596 return error(SizeLoc,
"size too large for vector");
3598 return error(TypeLoc,
"invalid vector element type");
3602 return error(TypeLoc,
"invalid array element type");
3619bool LLParser::parseTargetExtType(
Type *&Result) {
3624 if (parseToken(
lltok::lparen,
"expected '(' in target extension type") ||
3625 parseStringConstant(TypeName))
3632 SmallVector<unsigned> IntParams;
3633 bool SeenInt =
false;
3640 if (parseUInt32(IntVal))
3643 }
else if (SeenInt) {
3646 return tokError(
"expected uint32 param");
3649 if (parseType(TypeParam,
true))
3655 if (parseToken(
lltok::rparen,
"expected ')' in target extension type"))
3660 if (
auto E = TTy.takeError())
3661 return tokError(
toString(std::move(
E)));
3674 :
P(
p),
F(
f), FunctionNumber(functionNumber) {
3677 auto It = UnnamedArgNums.
begin();
3680 unsigned ArgNum = *It++;
3681 NumberedVals.add(ArgNum, &A);
3686LLParser::PerFunctionState::~PerFunctionState() {
3689 for (
const auto &P : ForwardRefVals) {
3692 P.second.first->replaceAllUsesWith(
3694 P.second.first->deleteValue();
3697 for (
const auto &P : ForwardRefValIDs) {
3700 P.second.first->replaceAllUsesWith(
3702 P.second.first->deleteValue();
3706bool LLParser::PerFunctionState::finishFunction() {
3707 if (!ForwardRefVals.empty())
3708 return P.error(ForwardRefVals.begin()->second.second,
3709 "use of undefined value '%" + ForwardRefVals.begin()->first +
3711 if (!ForwardRefValIDs.empty())
3712 return P.error(ForwardRefValIDs.begin()->second.second,
3713 "use of undefined value '%" +
3714 Twine(ForwardRefValIDs.begin()->first) +
"'");
3721Value *LLParser::PerFunctionState::getVal(
const std::string &Name,
Type *Ty,
3724 Value *Val =
F.getValueSymbolTable()->lookup(Name);
3729 auto I = ForwardRefVals.find(Name);
3730 if (
I != ForwardRefVals.end())
3731 Val =
I->second.first;
3736 return P.checkValidVariableType(Loc,
"%" + Name, Ty, Val);
3740 P.error(Loc,
"invalid use of a non-first-class type");
3751 if (FwdVal->
getName() != Name) {
3752 P.error(Loc,
"name is too long which can result in name collisions, "
3753 "consider making the name shorter or "
3754 "increasing -non-global-value-max-name-size");
3758 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
3762Value *LLParser::PerFunctionState::getVal(
unsigned ID,
Type *Ty,
LocTy Loc) {
3764 Value *Val = NumberedVals.get(
ID);
3769 auto I = ForwardRefValIDs.find(
ID);
3770 if (
I != ForwardRefValIDs.end())
3771 Val =
I->second.first;
3776 return P.checkValidVariableType(Loc,
"%" + Twine(
ID), Ty, Val);
3779 P.error(Loc,
"invalid use of a non-first-class type");
3791 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
3797bool LLParser::PerFunctionState::setInstName(
int NameID,
3798 const std::string &NameStr,
3799 LocTy NameLoc, Instruction *Inst) {
3802 if (NameID != -1 || !NameStr.empty())
3803 return P.error(NameLoc,
"instructions returning void cannot have a name");
3809 if (NameStr.empty()) {
3812 NameID = NumberedVals.getNext();
3814 if (
P.checkValueID(NameLoc,
"instruction",
"%", NumberedVals.getNext(),
3818 auto FI = ForwardRefValIDs.find(NameID);
3819 if (FI != ForwardRefValIDs.end()) {
3822 return P.error(NameLoc,
"instruction forward referenced with type '" +
3826 Sentinel->replaceAllUsesWith(Inst);
3828 ForwardRefValIDs.erase(FI);
3831 NumberedVals.add(NameID, Inst);
3836 auto FI = ForwardRefVals.find(NameStr);
3837 if (FI != ForwardRefVals.end()) {
3840 return P.error(NameLoc,
"instruction forward referenced with type '" +
3844 Sentinel->replaceAllUsesWith(Inst);
3846 ForwardRefVals.erase(FI);
3852 if (Inst->
getName() != NameStr)
3853 return P.error(NameLoc,
"multiple definition of local value named '" +
3860BasicBlock *LLParser::PerFunctionState::getBB(
const std::string &Name,
3874BasicBlock *LLParser::PerFunctionState::defineBB(
const std::string &Name,
3875 int NameID,
LocTy Loc) {
3879 if (
P.checkValueID(Loc,
"label",
"", NumberedVals.getNext(), NameID))
3882 NameID = NumberedVals.getNext();
3884 BB = getBB(NameID, Loc);
3886 P.error(Loc,
"unable to create block numbered '" + Twine(NameID) +
"'");
3890 BB = getBB(Name, Loc);
3892 P.error(Loc,
"unable to create block named '" + Name +
"'");
3903 ForwardRefValIDs.erase(NameID);
3904 NumberedVals.add(NameID, BB);
3907 ForwardRefVals.erase(Name);
3924bool LLParser::parseValID(ValID &
ID, PerFunctionState *PFS,
Type *ExpectedTy) {
3925 ID.Loc = Lex.getLoc();
3926 switch (Lex.getKind()) {
3928 return tokError(
"expected value token");
3930 ID.UIntVal = Lex.getUIntVal();
3934 ID.StrVal = Lex.getStrVal();
3938 ID.UIntVal = Lex.getUIntVal();
3942 ID.StrVal = Lex.getStrVal();
3946 ID.APSIntVal = Lex.getAPSIntVal();
3950 ID.APFloatVal = Lex.getAPFloatVal();
3971 if (parseGlobalValueVector(Elts) ||
3972 parseToken(
lltok::rbrace,
"expected end of struct constant"))
3975 ID.ConstantStructElts = std::make_unique<Constant *[]>(Elts.
size());
3976 ID.UIntVal = Elts.
size();
3977 memcpy(
ID.ConstantStructElts.get(), Elts.
data(),
3978 Elts.
size() *
sizeof(Elts[0]));
3989 LocTy FirstEltLoc = Lex.getLoc();
3990 if (parseGlobalValueVector(Elts) ||
3992 parseToken(
lltok::rbrace,
"expected end of packed struct")) ||
3996 if (isPackedStruct) {
3997 ID.ConstantStructElts = std::make_unique<Constant *[]>(Elts.
size());
3998 memcpy(
ID.ConstantStructElts.get(), Elts.
data(),
3999 Elts.
size() *
sizeof(Elts[0]));
4000 ID.UIntVal = Elts.
size();
4006 return error(
ID.Loc,
"constant vector must not be empty");
4008 if (!Elts[0]->
getType()->isIntegerTy() &&
4009 !Elts[0]->
getType()->isFloatingPointTy() &&
4013 "vector elements must have integer, pointer or floating point type");
4016 for (
unsigned i = 1, e = Elts.
size(); i != e; ++i)
4018 return error(FirstEltLoc,
"vector element #" + Twine(i) +
4019 " is not of type '" +
4029 LocTy FirstEltLoc = Lex.getLoc();
4030 if (parseGlobalValueVector(Elts) ||
4042 if (!Elts[0]->
getType()->isFirstClassType())
4043 return error(FirstEltLoc,
"invalid array element type: " +
4049 for (
unsigned i = 0, e = Elts.
size(); i != e; ++i) {
4051 return error(FirstEltLoc,
"array element #" + Twine(i) +
4052 " is not of type '" +
4072 bool HasSideEffect, AlignStack, AsmDialect, CanThrow;
4075 parseOptionalToken(lltok::kw_alignstack, AlignStack) ||
4078 parseStringConstant(
ID.StrVal) ||
4079 parseToken(
lltok::comma,
"expected comma in inline asm expression") ||
4082 ID.StrVal2 = Lex.getStrVal();
4083 ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack) << 1) |
4084 (
unsigned(AsmDialect) << 2) | (unsigned(CanThrow) << 3);
4095 if (parseToken(
lltok::lparen,
"expected '(' in block address expression") ||
4096 parseValID(Fn, PFS) ||
4098 "expected comma in block address expression") ||
4099 parseValID(Label, PFS) ||
4100 parseToken(
lltok::rparen,
"expected ')' in block address expression"))
4104 return error(Fn.
Loc,
"expected function name in blockaddress");
4106 return error(
Label.Loc,
"expected basic block name in blockaddress");
4109 GlobalValue *GV =
nullptr;
4111 GV = NumberedVals.get(Fn.
UIntVal);
4112 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
4113 GV = M->getNamedValue(Fn.
StrVal);
4119 return error(Fn.
Loc,
"expected function name in blockaddress");
4121 if (
F->isDeclaration())
4122 return error(Fn.
Loc,
"cannot take blockaddress inside a declaration");
4127 GlobalValue *&FwdRef =
4128 ForwardRefBlockAddresses[std::move(Fn)][std::move(Label)];
4136 "type of blockaddress must be a pointer and not '" +
4141 FwdDeclAS = PFS->getFunction().getAddressSpace();
4145 FwdRef =
new GlobalVariable(
4150 ID.ConstantVal = FwdRef;
4158 if (BlockAddressPFS &&
F == &BlockAddressPFS->getFunction()) {
4160 BB = BlockAddressPFS->getBB(
Label.UIntVal,
Label.Loc);
4162 BB = BlockAddressPFS->getBB(
Label.StrVal,
Label.Loc);
4164 return error(
Label.Loc,
"referenced value is not a basic block");
4167 return error(
Label.Loc,
"cannot take address of numeric label after "
4168 "the function is defined");
4170 F->getValueSymbolTable()->lookup(
Label.StrVal));
4172 return error(
Label.Loc,
"referenced value is not a basic block");
4186 if (parseValID(Fn, PFS))
4191 "expected global value name in dso_local_equivalent");
4194 GlobalValue *GV =
nullptr;
4196 GV = NumberedVals.get(Fn.
UIntVal);
4197 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
4198 GV = M->getNamedValue(Fn.
StrVal);
4204 ? ForwardRefDSOLocalEquivalentIDs
4205 : ForwardRefDSOLocalEquivalentNames;
4206 GlobalValue *&FwdRef = FwdRefMap[Fn];
4213 ID.ConstantVal = FwdRef;
4219 return error(Fn.
Loc,
"expected a function, alias to function, or ifunc "
4220 "in dso_local_equivalent");
4231 if (parseValID(
ID, PFS))
4235 return error(
ID.Loc,
"expected global value name in no_cfi");
4246 Constant *Disc =
nullptr, *AddrDisc =
nullptr;
4249 "expected '(' in constant ptrauth expression") ||
4250 parseGlobalTypeAndValue(
Ptr) ||
4252 "expected comma in constant ptrauth expression") ||
4253 parseGlobalTypeAndValue(
Key))
4257 if (parseGlobalTypeAndValue(Disc) ||
4258 (EatIfPresent(
lltok::comma) && parseGlobalTypeAndValue(AddrDisc)))
4261 "expected ')' in constant ptrauth expression"))
4264 if (!
Ptr->getType()->isPointerTy())
4265 return error(
ID.Loc,
"constant ptrauth base pointer must be a pointer");
4268 if (!KeyC || KeyC->getBitWidth() != 32)
4269 return error(
ID.Loc,
"constant ptrauth key must be i32 constant");
4271 ConstantInt *DiscC =
nullptr;
4277 "constant ptrauth integer discriminator must be i64 constant");
4283 if (!AddrDisc->getType()->isPointerTy())
4285 ID.Loc,
"constant ptrauth address discriminator must be a pointer");
4301 unsigned Opc = Lex.getUIntVal();
4302 Type *DestTy =
nullptr;
4305 if (parseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
4306 parseGlobalTypeAndValue(SrcVal) ||
4307 parseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
4308 parseType(DestTy) ||
4309 parseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
4312 return error(
ID.Loc,
"invalid cast opcode for cast from '" +
4321 return error(
ID.Loc,
"extractvalue constexprs are no longer supported");
4323 return error(
ID.Loc,
"insertvalue constexprs are no longer supported");
4325 return error(
ID.Loc,
"udiv constexprs are no longer supported");
4327 return error(
ID.Loc,
"sdiv constexprs are no longer supported");
4329 return error(
ID.Loc,
"urem constexprs are no longer supported");
4331 return error(
ID.Loc,
"srem constexprs are no longer supported");
4333 return error(
ID.Loc,
"fadd constexprs are no longer supported");
4335 return error(
ID.Loc,
"fsub constexprs are no longer supported");
4337 return error(
ID.Loc,
"fmul constexprs are no longer supported");
4339 return error(
ID.Loc,
"fdiv constexprs are no longer supported");
4341 return error(
ID.Loc,
"frem constexprs are no longer supported");
4343 return error(
ID.Loc,
"and constexprs are no longer supported");
4345 return error(
ID.Loc,
"or constexprs are no longer supported");
4347 return error(
ID.Loc,
"lshr constexprs are no longer supported");
4349 return error(
ID.Loc,
"ashr constexprs are no longer supported");
4351 return error(
ID.Loc,
"shl constexprs are no longer supported");
4353 return error(
ID.Loc,
"mul constexprs are no longer supported");
4355 return error(
ID.Loc,
"fneg constexprs are no longer supported");
4357 return error(
ID.Loc,
"select constexprs are no longer supported");
4359 return error(
ID.Loc,
"zext constexprs are no longer supported");
4361 return error(
ID.Loc,
"sext constexprs are no longer supported");
4363 return error(
ID.Loc,
"fptrunc constexprs are no longer supported");
4365 return error(
ID.Loc,
"fpext constexprs are no longer supported");
4367 return error(
ID.Loc,
"uitofp constexprs are no longer supported");
4369 return error(
ID.Loc,
"sitofp constexprs are no longer supported");
4371 return error(
ID.Loc,
"fptoui constexprs are no longer supported");
4373 return error(
ID.Loc,
"fptosi constexprs are no longer supported");
4375 return error(
ID.Loc,
"icmp constexprs are no longer supported");
4377 return error(
ID.Loc,
"fcmp constexprs are no longer supported");
4385 unsigned Opc = Lex.getUIntVal();
4388 if (
Opc == Instruction::Add ||
Opc == Instruction::Sub ||
4389 Opc == Instruction::Mul) {
4398 if (parseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
4399 parseGlobalTypeAndValue(Val0) ||
4400 parseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
4401 parseGlobalTypeAndValue(Val1) ||
4402 parseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
4405 return error(
ID.Loc,
"operands of constexpr must have same type");
4409 "constexpr requires integer or integer vector operands");
4420 if (parseToken(
lltok::lparen,
"expected '(' after vector splat"))
4423 if (parseGlobalTypeAndValue(
C))
4425 if (parseToken(
lltok::rparen,
"expected ')' at end of vector splat"))
4437 unsigned Opc = Lex.getUIntVal();
4440 bool HasInRange =
false;
4446 if (
Opc == Instruction::GetElementPtr) {
4462 return tokError(
"expected integer");
4463 InRangeStart = Lex.getAPSIntVal();
4468 return tokError(
"expected integer");
4469 InRangeEnd = Lex.getAPSIntVal();
4477 if (parseToken(
lltok::lparen,
"expected '(' in constantexpr"))
4480 if (
Opc == Instruction::GetElementPtr) {
4481 if (parseType(Ty) ||
4482 parseToken(
lltok::comma,
"expected comma after getelementptr's type"))
4486 if (parseGlobalValueVector(Elts) ||
4490 if (
Opc == Instruction::GetElementPtr) {
4491 if (Elts.
size() == 0 ||
4492 !Elts[0]->getType()->isPtrOrPtrVectorTy())
4493 return error(
ID.Loc,
"base of getelementptr must be a pointer");
4496 std::optional<ConstantRange>
InRange;
4498 unsigned IndexWidth =
4499 M->getDataLayout().getIndexTypeSizeInBits(
BaseType);
4500 InRangeStart = InRangeStart.
extOrTrunc(IndexWidth);
4501 InRangeEnd = InRangeEnd.
extOrTrunc(IndexWidth);
4502 if (InRangeStart.
sge(InRangeEnd))
4503 return error(
ID.Loc,
"expected end to be larger than start");
4513 for (Constant *Val : Indices) {
4516 return error(
ID.Loc,
"getelementptr index must be an integer");
4519 if (GEPWidth && (ValNumEl != GEPWidth))
4522 "getelementptr vector index has a wrong number of elements");
4525 GEPWidth = ValNumEl;
4529 SmallPtrSet<Type*, 4> Visited;
4530 if (!Indices.empty() && !Ty->
isSized(&Visited))
4531 return error(
ID.Loc,
"base element of getelementptr must be sized");
4534 return error(
ID.Loc,
"invalid getelementptr indices");
4538 }
else if (
Opc == Instruction::ShuffleVector) {
4539 if (Elts.
size() != 3)
4540 return error(
ID.Loc,
"expected three operands to shufflevector");
4542 return error(
ID.Loc,
"invalid operands to shufflevector");
4543 SmallVector<int, 16>
Mask;
4546 }
else if (
Opc == Instruction::ExtractElement) {
4547 if (Elts.
size() != 2)
4548 return error(
ID.Loc,
"expected two operands to extractelement");
4550 return error(
ID.Loc,
"invalid extractelement operands");
4553 assert(
Opc == Instruction::InsertElement &&
"Unknown opcode");
4554 if (Elts.
size() != 3)
4555 return error(
ID.Loc,
"expected three operands to insertelement");
4557 return error(
ID.Loc,
"invalid insertelement operands");
4572bool LLParser::parseGlobalValue(
Type *Ty, Constant *&
C) {
4576 bool Parsed = parseValID(
ID,
nullptr, Ty) ||
4577 convertValIDToValue(Ty,
ID, V,
nullptr);
4579 return error(
ID.Loc,
"global values must be constants");
4583bool LLParser::parseGlobalTypeAndValue(Constant *&V) {
4585 return parseType(Ty) || parseGlobalValue(Ty, V);
4588bool LLParser::parseOptionalComdat(StringRef GlobalName, Comdat *&
C) {
4591 LocTy KwLoc = Lex.getLoc();
4597 return tokError(
"expected comdat variable");
4598 C = getComdat(Lex.getStrVal(), Lex.getLoc());
4600 if (parseToken(
lltok::rparen,
"expected ')' after comdat var"))
4603 if (GlobalName.
empty())
4604 return tokError(
"comdat cannot be unnamed");
4605 C = getComdat(std::string(GlobalName), KwLoc);
4614bool LLParser::parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts) {
4628 if (parseGlobalTypeAndValue(
C))
4636bool LLParser::parseMDTuple(MDNode *&MD,
bool IsDistinct) {
4638 if (parseMDNodeVector(Elts))
4649bool LLParser::parseMDNode(MDNode *&
N) {
4651 return parseSpecializedMDNode(
N);
4653 return parseToken(
lltok::exclaim,
"expected '!' here") || parseMDNodeTail(
N);
4656bool LLParser::parseMDNodeTail(MDNode *&
N) {
4659 return parseMDTuple(
N);
4662 return parseMDNodeID(
N);
4668template <
class FieldTy>
struct MDFieldImpl {
4669 typedef MDFieldImpl ImplTy;
4673 void assign(FieldTy Val) {
4675 this->Val = std::move(Val);
4678 explicit MDFieldImpl(FieldTy
Default)
4686template <
class FieldTypeA,
class FieldTypeB>
struct MDEitherFieldImpl {
4687 typedef MDEitherFieldImpl<FieldTypeA, FieldTypeB> ImplTy;
4698 void assign(FieldTypeA
A) {
4700 this->
A = std::move(
A);
4704 void assign(FieldTypeB
B) {
4706 this->
B = std::move(
B);
4710 explicit MDEitherFieldImpl(FieldTypeA DefaultA, FieldTypeB DefaultB)
4712 WhatIs(IsInvalid) {}
4715struct MDUnsignedField :
public MDFieldImpl<uint64_t> {
4722struct LineField :
public MDUnsignedField {
4723 LineField() : MDUnsignedField(0, UINT32_MAX) {}
4726struct ColumnField :
public MDUnsignedField {
4727 ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
4730struct DwarfTagField :
public MDUnsignedField {
4736struct DwarfMacinfoTypeField :
public MDUnsignedField {
4742struct DwarfAttEncodingField :
public MDUnsignedField {
4743 DwarfAttEncodingField() : MDUnsignedField(0, dwarf::
DW_ATE_hi_user) {}
4746struct DwarfVirtualityField :
public MDUnsignedField {
4750struct DwarfLangField :
public MDUnsignedField {
4754struct DwarfSourceLangNameField :
public MDUnsignedField {
4755 DwarfSourceLangNameField() : MDUnsignedField(0, UINT32_MAX) {}
4758struct DwarfCCField :
public MDUnsignedField {
4759 DwarfCCField() : MDUnsignedField(0, dwarf::
DW_CC_hi_user) {}
4762struct DwarfEnumKindField :
public MDUnsignedField {
4763 DwarfEnumKindField()
4768struct EmissionKindField :
public MDUnsignedField {
4769 EmissionKindField() : MDUnsignedField(0, DICompileUnit::LastEmissionKind) {}
4772struct FixedPointKindField :
public MDUnsignedField {
4773 FixedPointKindField()
4774 : MDUnsignedField(0, DIFixedPointType::LastFixedPointKind) {}
4777struct NameTableKindField :
public MDUnsignedField {
4778 NameTableKindField()
4781 DICompileUnit::DebugNameTableKind::LastDebugNameTableKind) {}
4784struct DIFlagField :
public MDFieldImpl<DINode::DIFlags> {
4785 DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
4788struct DISPFlagField :
public MDFieldImpl<DISubprogram::DISPFlags> {
4789 DISPFlagField() : MDFieldImpl(DISubprogram::SPFlagZero) {}
4792struct MDAPSIntField :
public MDFieldImpl<APSInt> {
4793 MDAPSIntField() : ImplTy(
APSInt()) {}
4796struct MDSignedField :
public MDFieldImpl<int64_t> {
4800 MDSignedField(int64_t
Default = 0)
4802 MDSignedField(int64_t
Default, int64_t Min, int64_t Max)
4806struct MDBoolField :
public MDFieldImpl<bool> {
4810struct MDField :
public MDFieldImpl<Metadata *> {
4813 MDField(
bool AllowNull =
true) : ImplTy(nullptr), AllowNull(AllowNull) {}
4816struct MDStringField :
public MDFieldImpl<MDString *> {
4817 enum class EmptyIs {
4822 MDStringField(
enum EmptyIs EmptyIs = EmptyIs::Null)
4823 : ImplTy(nullptr), EmptyIs(EmptyIs) {}
4826struct MDFieldList :
public MDFieldImpl<SmallVector<Metadata *, 4>> {
4830struct ChecksumKindField :
public MDFieldImpl<DIFile::ChecksumKind> {
4834struct MDSignedOrMDField : MDEitherFieldImpl<MDSignedField, MDField> {
4835 MDSignedOrMDField(int64_t
Default = 0,
bool AllowNull =
true)
4836 : ImplTy(MDSignedField(
Default), MDField(AllowNull)) {}
4838 MDSignedOrMDField(int64_t
Default, int64_t Min, int64_t Max,
4839 bool AllowNull =
true)
4840 : ImplTy(MDSignedField(
Default, Min,
Max), MDField(AllowNull)) {}
4842 bool isMDSignedField()
const {
return WhatIs == IsTypeA; }
4843 bool isMDField()
const {
return WhatIs == IsTypeB; }
4844 int64_t getMDSignedValue()
const {
4845 assert(isMDSignedField() &&
"Wrong field type");
4848 Metadata *getMDFieldValue()
const {
4849 assert(isMDField() &&
"Wrong field type");
4854struct MDUnsignedOrMDField : MDEitherFieldImpl<MDUnsignedField, MDField> {
4855 MDUnsignedOrMDField(uint64_t
Default = 0,
bool AllowNull =
true)
4856 : ImplTy(MDUnsignedField(
Default), MDField(AllowNull)) {}
4858 MDUnsignedOrMDField(uint64_t
Default, uint64_t Max,
bool AllowNull =
true)
4859 : ImplTy(MDUnsignedField(
Default,
Max), MDField(AllowNull)) {}
4861 bool isMDUnsignedField()
const {
return WhatIs == IsTypeA; }
4862 bool isMDField()
const {
return WhatIs == IsTypeB; }
4863 uint64_t getMDUnsignedValue()
const {
4864 assert(isMDUnsignedField() &&
"Wrong field type");
4867 Metadata *getMDFieldValue()
const {
4868 assert(isMDField() &&
"Wrong field type");
4873 if (isMDUnsignedField())
4875 ConstantInt::get(Type::getInt64Ty(
Context), getMDUnsignedValue()));
4877 return getMDFieldValue();
4889 return tokError(
"expected integer");
4891 Result.assign(Lex.getAPSIntVal());
4898 MDUnsignedField &Result) {
4899 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
4900 return tokError(
"expected unsigned integer");
4902 auto &U = Lex.getAPSIntVal();
4903 if (U.ugt(Result.Max))
4904 return tokError(
"value for '" + Name +
"' too large, limit is " +
4906 Result.assign(U.getZExtValue());
4907 assert(Result.Val <= Result.Max &&
"Expected value in range");
4914 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4918 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4924 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4927 return tokError(
"expected DWARF tag");
4931 return tokError(
"invalid DWARF tag" +
Twine(
" '") + Lex.getStrVal() +
"'");
4932 assert(
Tag <= Result.Max &&
"Expected valid DWARF tag");
4941 DwarfMacinfoTypeField &Result) {
4943 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4946 return tokError(
"expected DWARF macinfo type");
4950 return tokError(
"invalid DWARF macinfo type" +
Twine(
" '") +
4951 Lex.getStrVal() +
"'");
4952 assert(Macinfo <= Result.Max &&
"Expected valid DWARF macinfo type");
4954 Result.assign(Macinfo);
4961 DwarfVirtualityField &Result) {
4963 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4966 return tokError(
"expected DWARF virtuality code");
4970 return tokError(
"invalid DWARF virtuality code" +
Twine(
" '") +
4971 Lex.getStrVal() +
"'");
4972 assert(Virtuality <= Result.Max &&
"Expected valid DWARF virtuality code");
4973 Result.assign(Virtuality);
4980 DwarfEnumKindField &Result) {
4982 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
4985 return tokError(
"expected DWARF enum kind code");
4989 return tokError(
"invalid DWARF enum kind code" +
Twine(
" '") +
4990 Lex.getStrVal() +
"'");
4991 assert(EnumKind <= Result.Max &&
"Expected valid DWARF enum kind code");
4992 Result.assign(EnumKind);
5000 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5003 return tokError(
"expected DWARF language");
5007 return tokError(
"invalid DWARF language" +
Twine(
" '") + Lex.getStrVal() +
5009 assert(Lang <= Result.Max &&
"Expected valid DWARF language");
5010 Result.assign(Lang);
5017 DwarfSourceLangNameField &Result) {
5019 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5022 return tokError(
"expected DWARF source language name");
5026 return tokError(
"invalid DWARF source language name" +
Twine(
" '") +
5027 Lex.getStrVal() +
"'");
5028 assert(Lang <= Result.Max &&
"Expected valid DWARF source language name");
5029 Result.assign(Lang);
5037 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5040 return tokError(
"expected DWARF calling convention");
5044 return tokError(
"invalid DWARF calling convention" +
Twine(
" '") +
5045 Lex.getStrVal() +
"'");
5046 assert(CC <= Result.Max &&
"Expected valid DWARF calling convention");
5054 EmissionKindField &Result) {
5056 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5059 return tokError(
"expected emission kind");
5063 return tokError(
"invalid emission kind" +
Twine(
" '") + Lex.getStrVal() +
5065 assert(*Kind <= Result.Max &&
"Expected valid emission kind");
5066 Result.assign(*Kind);
5073 FixedPointKindField &Result) {
5075 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5078 return tokError(
"expected fixed-point kind");
5082 return tokError(
"invalid fixed-point kind" +
Twine(
" '") + Lex.getStrVal() +
5084 assert(*Kind <= Result.Max &&
"Expected valid fixed-point kind");
5085 Result.assign(*Kind);
5092 NameTableKindField &Result) {
5094 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5097 return tokError(
"expected nameTable kind");
5101 return tokError(
"invalid nameTable kind" +
Twine(
" '") + Lex.getStrVal() +
5103 assert(((
unsigned)*Kind) <= Result.Max &&
"Expected valid nameTable kind");
5104 Result.assign((
unsigned)*Kind);
5111 DwarfAttEncodingField &Result) {
5113 return parseMDField(
Loc, Name,
static_cast<MDUnsignedField &
>(Result));
5116 return tokError(
"expected DWARF type attribute encoding");
5120 return tokError(
"invalid DWARF type attribute encoding" +
Twine(
" '") +
5121 Lex.getStrVal() +
"'");
5122 assert(Encoding <= Result.Max &&
"Expected valid DWARF language");
5123 Result.assign(Encoding);
5137 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
5139 bool Res = parseUInt32(TempVal);
5145 return tokError(
"expected debug info flag");
5149 return tokError(
Twine(
"invalid debug info flag '") + Lex.getStrVal() +
5164 Result.assign(Combined);
5177 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
5179 bool Res = parseUInt32(TempVal);
5185 return tokError(
"expected debug info flag");
5189 return tokError(
Twine(
"invalid subprogram debug info flag '") +
5190 Lex.getStrVal() +
"'");
5204 Result.assign(Combined);
5211 return tokError(
"expected signed integer");
5213 auto &S = Lex.getAPSIntVal();
5215 return tokError(
"value for '" + Name +
"' too small, limit is " +
5218 return tokError(
"value for '" + Name +
"' too large, limit is " +
5220 Result.assign(S.getExtValue());
5221 assert(Result.Val >= Result.Min &&
"Expected value in range");
5222 assert(Result.Val <= Result.Max &&
"Expected value in range");
5229 switch (Lex.getKind()) {
5231 return tokError(
"expected 'true' or 'false'");
5233 Result.assign(
true);
5236 Result.assign(
false);
5246 if (!Result.AllowNull)
5247 return tokError(
"'" + Name +
"' cannot be null");
5249 Result.assign(
nullptr);
5254 if (parseMetadata(MD,
nullptr))
5263 MDSignedOrMDField &Result) {
5266 MDSignedField Res = Result.A;
5267 if (!parseMDField(
Loc, Name, Res)) {
5275 MDField Res = Result.B;
5276 if (!parseMDField(
Loc, Name, Res)) {
5286 MDUnsignedOrMDField &Result) {
5289 MDUnsignedField Res = Result.A;
5290 if (!parseMDField(
Loc, Name, Res)) {
5298 MDField Res = Result.B;
5299 if (!parseMDField(
Loc, Name, Res)) {
5309 LocTy ValueLoc = Lex.getLoc();
5311 if (parseStringConstant(S))
5315 switch (Result.EmptyIs) {
5316 case MDStringField::EmptyIs::Null:
5317 Result.assign(
nullptr);
5319 case MDStringField::EmptyIs::Empty:
5321 case MDStringField::EmptyIs::Error:
5322 return error(ValueLoc,
"'" + Name +
"' cannot be empty");
5333 if (parseMDNodeVector(MDs))
5336 Result.assign(std::move(MDs));
5342 ChecksumKindField &Result) {
5343 std::optional<DIFile::ChecksumKind> CSKind =
5347 return tokError(
"invalid checksum kind" +
Twine(
" '") + Lex.getStrVal() +
5350 Result.assign(*CSKind);
5357template <
class ParserTy>
5358bool LLParser::parseMDFieldsImplBody(ParserTy ParseField) {
5361 return tokError(
"expected field label here");
5370template <
class ParserTy>
5371bool LLParser::parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc) {
5378 if (parseMDFieldsImplBody(ParseField))
5381 ClosingLoc = Lex.getLoc();
5385template <
class FieldTy>
5386bool LLParser::parseMDField(
StringRef Name, FieldTy &Result) {
5388 return tokError(
"field '" + Name +
"' cannot be specified more than once");
5390 LocTy Loc = Lex.getLoc();
5392 return parseMDField(Loc, Name, Result);
5395bool LLParser::parseSpecializedMDNode(
MDNode *&
N,
bool IsDistinct) {
5398#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
5399 if (Lex.getStrVal() == #CLASS) \
5400 return parse##CLASS(N, IsDistinct);
5401#include "llvm/IR/Metadata.def"
5403 return tokError(
"expected metadata type");
5406#define DECLARE_FIELD(NAME, TYPE, INIT) TYPE NAME INIT
5407#define NOP_FIELD(NAME, TYPE, INIT)
5408#define REQUIRE_FIELD(NAME, TYPE, INIT) \
5410 return error(ClosingLoc, "missing required field '" #NAME "'");
5411#define PARSE_MD_FIELD(NAME, TYPE, DEFAULT) \
5412 if (Lex.getStrVal() == #NAME) \
5413 return parseMDField(#NAME, NAME);
5414#define PARSE_MD_FIELDS() \
5415 VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD) \
5418 if (parseMDFieldsImpl( \
5420 VISIT_MD_FIELDS(PARSE_MD_FIELD, PARSE_MD_FIELD) \
5421 return tokError(Twine("invalid field '") + Lex.getStrVal() + \
5426 VISIT_MD_FIELDS(NOP_FIELD, REQUIRE_FIELD) \
5428#define GET_OR_DISTINCT(CLASS, ARGS) \
5429 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
5434bool LLParser::parseDILocation(
MDNode *&Result,
bool IsDistinct) {
5435#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5436 OPTIONAL(line, LineField, ); \
5437 OPTIONAL(column, ColumnField, ); \
5438 REQUIRED(scope, MDField, ( false)); \
5439 OPTIONAL(inlinedAt, MDField, ); \
5440 OPTIONAL(isImplicitCode, MDBoolField, (false)); \
5441 OPTIONAL(atomGroup, MDUnsignedField, (0, UINT64_MAX)); \
5442 OPTIONAL(atomRank, MDUnsignedField, (0, UINT8_MAX));
5444#undef VISIT_MD_FIELDS
5447 DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val,
5448 isImplicitCode.Val, atomGroup.Val, atomRank.Val));
5454bool LLParser::parseDIAssignID(
MDNode *&Result,
bool IsDistinct) {
5456 return tokError(
"missing 'distinct', required for !DIAssignID()");
5472bool LLParser::parseGenericDINode(
MDNode *&Result,
bool IsDistinct) {
5473#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5474 REQUIRED(tag, DwarfTagField, ); \
5475 OPTIONAL(header, MDStringField, ); \
5476 OPTIONAL(operands, MDFieldList, );
5478#undef VISIT_MD_FIELDS
5481 (Context, tag.Val, header.Val, operands.Val));
5490bool LLParser::parseDISubrangeType(
MDNode *&Result,
bool IsDistinct) {
5491#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5492 OPTIONAL(name, MDStringField, ); \
5493 OPTIONAL(file, MDField, ); \
5494 OPTIONAL(line, LineField, ); \
5495 OPTIONAL(scope, MDField, ); \
5496 OPTIONAL(baseType, MDField, ); \
5497 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5498 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5499 OPTIONAL(flags, DIFlagField, ); \
5500 OPTIONAL(lowerBound, MDSignedOrMDField, ); \
5501 OPTIONAL(upperBound, MDSignedOrMDField, ); \
5502 OPTIONAL(stride, MDSignedOrMDField, ); \
5503 OPTIONAL(bias, MDSignedOrMDField, );
5505#undef VISIT_MD_FIELDS
5507 auto convToMetadata = [&](MDSignedOrMDField Bound) ->
Metadata * {
5508 if (Bound.isMDSignedField())
5511 if (Bound.isMDField())
5512 return Bound.getMDFieldValue();
5516 Metadata *LowerBound = convToMetadata(lowerBound);
5518 Metadata *Stride = convToMetadata(stride);
5519 Metadata *Bias = convToMetadata(bias);
5522 DISubrangeType, (Context,
name.Val,
file.Val, line.Val, scope.Val,
5523 size.getValueAsMetadata(Context), align.Val, flags.Val,
5524 baseType.Val, LowerBound, UpperBound, Stride, Bias));
5533bool LLParser::parseDISubrange(
MDNode *&Result,
bool IsDistinct) {
5534#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5535 OPTIONAL(count, MDSignedOrMDField, (-1, -1, INT64_MAX, false)); \
5536 OPTIONAL(lowerBound, MDSignedOrMDField, ); \
5537 OPTIONAL(upperBound, MDSignedOrMDField, ); \
5538 OPTIONAL(stride, MDSignedOrMDField, );
5540#undef VISIT_MD_FIELDS
5547 auto convToMetadata = [&](
const MDSignedOrMDField &Bound) ->
Metadata * {
5548 if (Bound.isMDSignedField())
5551 if (Bound.isMDField())
5552 return Bound.getMDFieldValue();
5557 LowerBound = convToMetadata(lowerBound);
5559 Stride = convToMetadata(stride);
5562 (Context,
Count, LowerBound, UpperBound, Stride));
5570bool LLParser::parseDIGenericSubrange(
MDNode *&Result,
bool IsDistinct) {
5571#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5572 OPTIONAL(count, MDSignedOrMDField, ); \
5573 OPTIONAL(lowerBound, MDSignedOrMDField, ); \
5574 OPTIONAL(upperBound, MDSignedOrMDField, ); \
5575 OPTIONAL(stride, MDSignedOrMDField, );
5577#undef VISIT_MD_FIELDS
5579 auto ConvToMetadata = [&](
const MDSignedOrMDField &Bound) ->
Metadata * {
5580 if (Bound.isMDSignedField())
5582 Context, {dwarf::DW_OP_consts,
5583 static_cast<uint64_t
>(Bound.getMDSignedValue())});
5584 if (Bound.isMDField())
5585 return Bound.getMDFieldValue();
5590 Metadata *LowerBound = ConvToMetadata(lowerBound);
5592 Metadata *Stride = ConvToMetadata(stride);
5595 (Context,
Count, LowerBound, UpperBound, Stride));
5602bool LLParser::parseDIEnumerator(
MDNode *&Result,
bool IsDistinct) {
5603#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5604 REQUIRED(name, MDStringField, ); \
5605 REQUIRED(value, MDAPSIntField, ); \
5606 OPTIONAL(isUnsigned, MDBoolField, (false));
5608#undef VISIT_MD_FIELDS
5610 if (isUnsigned.Val && value.Val.isNegative())
5611 return tokError(
"unsigned enumerator with negative value");
5616 if (!isUnsigned.Val && value.Val.isUnsigned() && value.Val.isSignBitSet())
5628bool LLParser::parseDIBasicType(
MDNode *&Result,
bool IsDistinct) {
5629#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5630 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
5631 OPTIONAL(name, MDStringField, ); \
5632 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5633 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5634 OPTIONAL(encoding, DwarfAttEncodingField, ); \
5635 OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
5636 OPTIONAL(flags, DIFlagField, );
5638#undef VISIT_MD_FIELDS
5641 size.getValueAsMetadata(Context),
5642 align.Val, encoding.Val,
5643 num_extra_inhabitants.Val, flags.Val));
5652bool LLParser::parseDIFixedPointType(
MDNode *&Result,
bool IsDistinct) {
5653#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5654 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
5655 OPTIONAL(name, MDStringField, ); \
5656 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5657 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5658 OPTIONAL(encoding, DwarfAttEncodingField, ); \
5659 OPTIONAL(flags, DIFlagField, ); \
5660 OPTIONAL(kind, FixedPointKindField, ); \
5661 OPTIONAL(factor, MDSignedField, ); \
5662 OPTIONAL(numerator, MDAPSIntField, ); \
5663 OPTIONAL(denominator, MDAPSIntField, );
5665#undef VISIT_MD_FIELDS
5668 (Context, tag.Val,
name.Val,
5669 size.getValueAsMetadata(Context), align.Val,
5670 encoding.Val, flags.Val, kind.Val, factor.Val,
5671 numerator.Val, denominator.Val));
5677bool LLParser::parseDIStringType(
MDNode *&Result,
bool IsDistinct) {
5678#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5679 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_string_type)); \
5680 OPTIONAL(name, MDStringField, ); \
5681 OPTIONAL(stringLength, MDField, ); \
5682 OPTIONAL(stringLengthExpression, MDField, ); \
5683 OPTIONAL(stringLocationExpression, MDField, ); \
5684 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5685 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5686 OPTIONAL(encoding, DwarfAttEncodingField, );
5688#undef VISIT_MD_FIELDS
5692 (Context, tag.Val,
name.Val, stringLength.Val, stringLengthExpression.Val,
5693 stringLocationExpression.Val,
size.getValueAsMetadata(Context),
5694 align.Val, encoding.Val));
5707bool LLParser::parseDIDerivedType(
MDNode *&Result,
bool IsDistinct) {
5708#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5709 REQUIRED(tag, DwarfTagField, ); \
5710 OPTIONAL(name, MDStringField, ); \
5711 OPTIONAL(file, MDField, ); \
5712 OPTIONAL(line, LineField, ); \
5713 OPTIONAL(scope, MDField, ); \
5714 REQUIRED(baseType, MDField, ); \
5715 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5716 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5717 OPTIONAL(offset, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5718 OPTIONAL(flags, DIFlagField, ); \
5719 OPTIONAL(extraData, MDField, ); \
5720 OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); \
5721 OPTIONAL(annotations, MDField, ); \
5722 OPTIONAL(ptrAuthKey, MDUnsignedField, (0, 7)); \
5723 OPTIONAL(ptrAuthIsAddressDiscriminated, MDBoolField, ); \
5724 OPTIONAL(ptrAuthExtraDiscriminator, MDUnsignedField, (0, 0xffff)); \
5725 OPTIONAL(ptrAuthIsaPointer, MDBoolField, ); \
5726 OPTIONAL(ptrAuthAuthenticatesNullValues, MDBoolField, );
5728#undef VISIT_MD_FIELDS
5730 std::optional<unsigned> DWARFAddressSpace;
5731 if (dwarfAddressSpace.Val != UINT32_MAX)
5732 DWARFAddressSpace = dwarfAddressSpace.Val;
5733 std::optional<DIDerivedType::PtrAuthData> PtrAuthData;
5735 PtrAuthData.emplace(
5736 (
unsigned)ptrAuthKey.Val, ptrAuthIsAddressDiscriminated.Val,
5737 (
unsigned)ptrAuthExtraDiscriminator.Val, ptrAuthIsaPointer.Val,
5738 ptrAuthAuthenticatesNullValues.Val);
5741 DIDerivedType, (Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val,
5742 baseType.Val,
size.getValueAsMetadata(Context), align.Val,
5743 offset.getValueAsMetadata(Context), DWARFAddressSpace,
5744 PtrAuthData, flags.Val, extraData.Val, annotations.Val));
5748bool LLParser::parseDICompositeType(
MDNode *&Result,
bool IsDistinct) {
5749#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5750 REQUIRED(tag, DwarfTagField, ); \
5751 OPTIONAL(name, MDStringField, ); \
5752 OPTIONAL(file, MDField, ); \
5753 OPTIONAL(line, LineField, ); \
5754 OPTIONAL(scope, MDField, ); \
5755 OPTIONAL(baseType, MDField, ); \
5756 OPTIONAL(size, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5757 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
5758 OPTIONAL(offset, MDUnsignedOrMDField, (0, UINT64_MAX)); \
5759 OPTIONAL(flags, DIFlagField, ); \
5760 OPTIONAL(elements, MDField, ); \
5761 OPTIONAL(runtimeLang, DwarfLangField, ); \
5762 OPTIONAL(enumKind, DwarfEnumKindField, ); \
5763 OPTIONAL(vtableHolder, MDField, ); \
5764 OPTIONAL(templateParams, MDField, ); \
5765 OPTIONAL(identifier, MDStringField, ); \
5766 OPTIONAL(discriminator, MDField, ); \
5767 OPTIONAL(dataLocation, MDField, ); \
5768 OPTIONAL(associated, MDField, ); \
5769 OPTIONAL(allocated, MDField, ); \
5770 OPTIONAL(rank, MDSignedOrMDField, ); \
5771 OPTIONAL(annotations, MDField, ); \
5772 OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
5773 OPTIONAL(specification, MDField, ); \
5774 OPTIONAL(bitStride, MDField, );
5776#undef VISIT_MD_FIELDS
5779 if (rank.isMDSignedField())
5782 else if (rank.isMDField())
5783 Rank = rank.getMDFieldValue();
5785 std::optional<unsigned> EnumKind;
5787 EnumKind = enumKind.Val;
5792 Context, *identifier.Val, tag.Val,
name.Val,
file.Val, line.Val,
5793 scope.Val, baseType.Val,
size.getValueAsMetadata(Context),
5794 align.Val, offset.getValueAsMetadata(Context), specification.Val,
5795 num_extra_inhabitants.Val, flags.Val, elements.Val, runtimeLang.Val,
5796 EnumKind, vtableHolder.Val, templateParams.Val, discriminator.Val,
5797 dataLocation.Val, associated.Val, allocated.Val, Rank,
5798 annotations.Val, bitStride.Val)) {
5807 (Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val, baseType.Val,
5808 size.getValueAsMetadata(Context), align.Val,
5809 offset.getValueAsMetadata(Context), flags.Val, elements.Val,
5810 runtimeLang.Val, EnumKind, vtableHolder.Val, templateParams.Val,
5811 identifier.Val, discriminator.Val, dataLocation.Val, associated.Val,
5812 allocated.Val, Rank, annotations.Val, specification.Val,
5813 num_extra_inhabitants.Val, bitStride.Val));
5817bool LLParser::parseDISubroutineType(
MDNode *&Result,
bool IsDistinct) {
5818#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5819 OPTIONAL(flags, DIFlagField, ); \
5820 OPTIONAL(cc, DwarfCCField, ); \
5821 REQUIRED(types, MDField, );
5823#undef VISIT_MD_FIELDS
5826 (Context, flags.Val, cc.Val, types.Val));
5835bool LLParser::parseDIFile(
MDNode *&Result,
bool IsDistinct) {
5839#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5840 REQUIRED(filename, MDStringField, ); \
5841 REQUIRED(directory, MDStringField, ); \
5842 OPTIONAL(checksumkind, ChecksumKindField, (DIFile::CSK_MD5)); \
5843 OPTIONAL(checksum, MDStringField, ); \
5844 OPTIONAL(source, MDStringField, (MDStringField::EmptyIs::Empty));
5846#undef VISIT_MD_FIELDS
5848 std::optional<DIFile::ChecksumInfo<MDString *>> OptChecksum;
5849 if (checksumkind.Seen && checksum.Seen)
5850 OptChecksum.emplace(checksumkind.Val, checksum.Val);
5851 else if (checksumkind.Seen || checksum.Seen)
5852 return tokError(
"'checksumkind' and 'checksum' must be provided together");
5854 MDString *
Source =
nullptr;
5858 DIFile, (Context,
filename.Val, directory.Val, OptChecksum, Source));
5869bool LLParser::parseDICompileUnit(
MDNode *&Result,
bool IsDistinct) {
5871 return tokError(
"missing 'distinct', required for !DICompileUnit");
5873 LocTy Loc = Lex.getLoc();
5875#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5876 REQUIRED(file, MDField, ( false)); \
5877 OPTIONAL(language, DwarfLangField, ); \
5878 OPTIONAL(sourceLanguageName, DwarfSourceLangNameField, ); \
5879 OPTIONAL(producer, MDStringField, ); \
5880 OPTIONAL(isOptimized, MDBoolField, ); \
5881 OPTIONAL(flags, MDStringField, ); \
5882 OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \
5883 OPTIONAL(splitDebugFilename, MDStringField, ); \
5884 OPTIONAL(emissionKind, EmissionKindField, ); \
5885 OPTIONAL(enums, MDField, ); \
5886 OPTIONAL(retainedTypes, MDField, ); \
5887 OPTIONAL(globals, MDField, ); \
5888 OPTIONAL(imports, MDField, ); \
5889 OPTIONAL(macros, MDField, ); \
5890 OPTIONAL(dwoId, MDUnsignedField, ); \
5891 OPTIONAL(splitDebugInlining, MDBoolField, = true); \
5892 OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
5893 OPTIONAL(nameTableKind, NameTableKindField, ); \
5894 OPTIONAL(rangesBaseAddress, MDBoolField, = false); \
5895 OPTIONAL(sysroot, MDStringField, ); \
5896 OPTIONAL(sdk, MDStringField, );
5898#undef VISIT_MD_FIELDS
5900 if (!language.Seen && !sourceLanguageName.Seen)
5901 return error(Loc,
"missing one of 'language' or 'sourceLanguageName', "
5902 "required for !DICompileUnit");
5904 if (language.Seen && sourceLanguageName.Seen)
5905 return error(Loc,
"can only specify one of 'language' and "
5906 "'sourceLanguageName' on !DICompileUnit");
5910 language.Seen ? DISourceLanguageName(language.Val)
5911 : DISourceLanguageName(sourceLanguageName.Val, 0),
5912 file.Val, producer.Val, isOptimized.Val, flags.Val, runtimeVersion.Val,
5913 splitDebugFilename.Val, emissionKind.Val, enums.Val, retainedTypes.Val,
5914 globals.Val, imports.Val, macros.Val, dwoId.Val, splitDebugInlining.Val,
5915 debugInfoForProfiling.Val, nameTableKind.Val, rangesBaseAddress.Val,
5916 sysroot.Val, sdk.Val);
5929bool LLParser::parseDISubprogram(
MDNode *&Result,
bool IsDistinct) {
5930 auto Loc = Lex.getLoc();
5931#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5932 OPTIONAL(scope, MDField, ); \
5933 OPTIONAL(name, MDStringField, ); \
5934 OPTIONAL(linkageName, MDStringField, ); \
5935 OPTIONAL(file, MDField, ); \
5936 OPTIONAL(line, LineField, ); \
5937 OPTIONAL(type, MDField, ); \
5938 OPTIONAL(isLocal, MDBoolField, ); \
5939 OPTIONAL(isDefinition, MDBoolField, (true)); \
5940 OPTIONAL(scopeLine, LineField, ); \
5941 OPTIONAL(containingType, MDField, ); \
5942 OPTIONAL(virtuality, DwarfVirtualityField, ); \
5943 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \
5944 OPTIONAL(thisAdjustment, MDSignedField, (0, INT32_MIN, INT32_MAX)); \
5945 OPTIONAL(flags, DIFlagField, ); \
5946 OPTIONAL(spFlags, DISPFlagField, ); \
5947 OPTIONAL(isOptimized, MDBoolField, ); \
5948 OPTIONAL(unit, MDField, ); \
5949 OPTIONAL(templateParams, MDField, ); \
5950 OPTIONAL(declaration, MDField, ); \
5951 OPTIONAL(retainedNodes, MDField, ); \
5952 OPTIONAL(thrownTypes, MDField, ); \
5953 OPTIONAL(annotations, MDField, ); \
5954 OPTIONAL(targetFuncName, MDStringField, ); \
5955 OPTIONAL(keyInstructions, MDBoolField, );
5957#undef VISIT_MD_FIELDS
5962 spFlags.Seen ? spFlags.Val
5964 isOptimized.Val, virtuality.Val);
5965 if ((SPFlags & DISubprogram::SPFlagDefinition) && !IsDistinct)
5968 "missing 'distinct', required for !DISubprogram that is a Definition");
5971 (Context, scope.Val,
name.Val, linkageName.Val,
file.Val, line.Val,
5972 type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val,
5973 thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val,
5974 declaration.Val, retainedNodes.Val, thrownTypes.Val, annotations.Val,
5975 targetFuncName.Val, keyInstructions.Val));
5981bool LLParser::parseDILexicalBlock(
MDNode *&Result,
bool IsDistinct) {
5982#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5983 REQUIRED(scope, MDField, ( false)); \
5984 OPTIONAL(file, MDField, ); \
5985 OPTIONAL(line, LineField, ); \
5986 OPTIONAL(column, ColumnField, );
5988#undef VISIT_MD_FIELDS
5991 DILexicalBlock, (Context, scope.Val,
file.Val, line.Val, column.Val));
5997bool LLParser::parseDILexicalBlockFile(
MDNode *&Result,
bool IsDistinct) {
5998#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5999 REQUIRED(scope, MDField, ( false)); \
6000 OPTIONAL(file, MDField, ); \
6001 REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX));
6003#undef VISIT_MD_FIELDS
6006 (Context, scope.Val,
file.Val, discriminator.Val));
6012bool LLParser::parseDICommonBlock(
MDNode *&Result,
bool IsDistinct) {
6013#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6014 REQUIRED(scope, MDField, ); \
6015 OPTIONAL(declaration, MDField, ); \
6016 OPTIONAL(name, MDStringField, ); \
6017 OPTIONAL(file, MDField, ); \
6018 OPTIONAL(line, LineField, );
6020#undef VISIT_MD_FIELDS
6023 (Context, scope.Val, declaration.Val,
name.Val,
6024 file.Val, line.Val));
6030bool LLParser::parseDINamespace(
MDNode *&Result,
bool IsDistinct) {
6031#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6032 REQUIRED(scope, MDField, ); \
6033 OPTIONAL(name, MDStringField, ); \
6034 OPTIONAL(exportSymbols, MDBoolField, );
6036#undef VISIT_MD_FIELDS
6039 (Context, scope.Val,
name.Val, exportSymbols.Val));
6046bool LLParser::parseDIMacro(
MDNode *&Result,
bool IsDistinct) {
6047#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6048 REQUIRED(type, DwarfMacinfoTypeField, ); \
6049 OPTIONAL(line, LineField, ); \
6050 REQUIRED(name, MDStringField, ); \
6051 OPTIONAL(value, MDStringField, );
6053#undef VISIT_MD_FIELDS
6056 (Context, type.Val, line.Val,
name.Val, value.Val));
6062bool LLParser::parseDIMacroFile(
MDNode *&Result,
bool IsDistinct) {
6063#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6064 OPTIONAL(type, DwarfMacinfoTypeField, (dwarf::DW_MACINFO_start_file)); \
6065 OPTIONAL(line, LineField, ); \
6066 REQUIRED(file, MDField, ); \
6067 OPTIONAL(nodes, MDField, );
6069#undef VISIT_MD_FIELDS
6072 (Context, type.Val, line.Val,
file.Val,
nodes.Val));
6080bool LLParser::parseDIModule(
MDNode *&Result,
bool IsDistinct) {
6081#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6082 REQUIRED(scope, MDField, ); \
6083 REQUIRED(name, MDStringField, ); \
6084 OPTIONAL(configMacros, MDStringField, ); \
6085 OPTIONAL(includePath, MDStringField, ); \
6086 OPTIONAL(apinotes, MDStringField, ); \
6087 OPTIONAL(file, MDField, ); \
6088 OPTIONAL(line, LineField, ); \
6089 OPTIONAL(isDecl, MDBoolField, );
6091#undef VISIT_MD_FIELDS
6094 configMacros.Val, includePath.Val,
6095 apinotes.Val, line.Val, isDecl.Val));
6101bool LLParser::parseDITemplateTypeParameter(
MDNode *&Result,
bool IsDistinct) {
6102#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6103 OPTIONAL(name, MDStringField, ); \
6104 REQUIRED(type, MDField, ); \
6105 OPTIONAL(defaulted, MDBoolField, );
6107#undef VISIT_MD_FIELDS
6110 (Context,
name.Val, type.Val, defaulted.Val));
6118bool LLParser::parseDITemplateValueParameter(
MDNode *&Result,
bool IsDistinct) {
6119#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6120 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_template_value_parameter)); \
6121 OPTIONAL(name, MDStringField, ); \
6122 OPTIONAL(type, MDField, ); \
6123 OPTIONAL(defaulted, MDBoolField, ); \
6124 REQUIRED(value, MDField, );
6127#undef VISIT_MD_FIELDS
6130 DITemplateValueParameter,
6131 (Context, tag.Val,
name.Val, type.Val, defaulted.Val, value.Val));
6140bool LLParser::parseDIGlobalVariable(
MDNode *&Result,
bool IsDistinct) {
6141#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6142 OPTIONAL(name, MDStringField, (MDStringField::EmptyIs::Error)); \
6143 OPTIONAL(scope, MDField, ); \
6144 OPTIONAL(linkageName, MDStringField, ); \
6145 OPTIONAL(file, MDField, ); \
6146 OPTIONAL(line, LineField, ); \
6147 OPTIONAL(type, MDField, ); \
6148 OPTIONAL(isLocal, MDBoolField, ); \
6149 OPTIONAL(isDefinition, MDBoolField, (true)); \
6150 OPTIONAL(templateParams, MDField, ); \
6151 OPTIONAL(declaration, MDField, ); \
6152 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
6153 OPTIONAL(annotations, MDField, );
6155#undef VISIT_MD_FIELDS
6159 (Context, scope.Val,
name.Val, linkageName.Val,
file.Val,
6160 line.Val, type.Val, isLocal.Val, isDefinition.Val,
6161 declaration.Val, templateParams.Val, align.Val,
6173bool LLParser::parseDILocalVariable(
MDNode *&Result,
bool IsDistinct) {
6174#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6175 REQUIRED(scope, MDField, ( false)); \
6176 OPTIONAL(name, MDStringField, ); \
6177 OPTIONAL(arg, MDUnsignedField, (0, UINT16_MAX)); \
6178 OPTIONAL(file, MDField, ); \
6179 OPTIONAL(line, LineField, ); \
6180 OPTIONAL(type, MDField, ); \
6181 OPTIONAL(flags, DIFlagField, ); \
6182 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
6183 OPTIONAL(annotations, MDField, );
6185#undef VISIT_MD_FIELDS
6188 (Context, scope.Val,
name.Val,
file.Val, line.Val,
6189 type.Val, arg.Val, flags.Val, align.Val,
6196bool LLParser::parseDILabel(
MDNode *&Result,
bool IsDistinct) {
6197#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6198 REQUIRED(scope, MDField, ( false)); \
6199 REQUIRED(name, MDStringField, ); \
6200 REQUIRED(file, MDField, ); \
6201 REQUIRED(line, LineField, ); \
6202 OPTIONAL(column, ColumnField, ); \
6203 OPTIONAL(isArtificial, MDBoolField, ); \
6204 OPTIONAL(coroSuspendIdx, MDUnsignedField, );
6206#undef VISIT_MD_FIELDS
6208 std::optional<unsigned> CoroSuspendIdx =
6209 coroSuspendIdx.Seen ? std::optional<unsigned>(coroSuspendIdx.Val)
6213 (Context, scope.Val,
name.Val,
file.Val, line.Val,
6214 column.Val, isArtificial.Val, CoroSuspendIdx));
6220bool LLParser::parseDIExpressionBody(
MDNode *&Result,
bool IsDistinct) {
6233 return tokError(Twine(
"invalid DWARF op '") + Lex.getStrVal() +
"'");
6242 return tokError(Twine(
"invalid DWARF attribute encoding '") +
6243 Lex.getStrVal() +
"'");
6246 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
6247 return tokError(
"expected unsigned integer");
6249 auto &
U = Lex.getAPSIntVal();
6251 return tokError(
"element too large, limit is " + Twine(
UINT64_MAX));
6265bool LLParser::parseDIExpression(
MDNode *&Result,
bool IsDistinct) {
6267 assert(Lex.getStrVal() ==
"DIExpression" &&
"Expected '!DIExpression'");
6270 return parseDIExpressionBody(Result, IsDistinct);
6275bool LLParser::parseDIArgList(
Metadata *&MD, PerFunctionState *PFS) {
6276 assert(PFS &&
"Expected valid function state");
6287 if (parseValueAsMetadata(MD,
"expected value-as-metadata operand", PFS))
6301bool LLParser::parseDIGlobalVariableExpression(
MDNode *&Result,
6303#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6304 REQUIRED(var, MDField, ); \
6305 REQUIRED(expr, MDField, );
6307#undef VISIT_MD_FIELDS
6310 GET_OR_DISTINCT(DIGlobalVariableExpression, (Context, var.Val, expr.Val));
6317bool LLParser::parseDIObjCProperty(
MDNode *&Result,
bool IsDistinct) {
6318#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6319 OPTIONAL(name, MDStringField, ); \
6320 OPTIONAL(file, MDField, ); \
6321 OPTIONAL(line, LineField, ); \
6322 OPTIONAL(setter, MDStringField, ); \
6323 OPTIONAL(getter, MDStringField, ); \
6324 OPTIONAL(attributes, MDUnsignedField, (0, UINT32_MAX)); \
6325 OPTIONAL(type, MDField, );
6327#undef VISIT_MD_FIELDS
6330 (Context,
name.Val,
file.Val, line.Val, setter.Val,
6331 getter.Val, attributes.Val, type.Val));
6338bool LLParser::parseDIImportedEntity(
MDNode *&Result,
bool IsDistinct) {
6339#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
6340 REQUIRED(tag, DwarfTagField, ); \
6341 REQUIRED(scope, MDField, ); \
6342 OPTIONAL(entity, MDField, ); \
6343 OPTIONAL(file, MDField, ); \
6344 OPTIONAL(line, LineField, ); \
6345 OPTIONAL(name, MDStringField, ); \
6346 OPTIONAL(elements, MDField, );
6348#undef VISIT_MD_FIELDS
6351 (Context, tag.Val, scope.Val, entity.Val,
file.Val,
6352 line.Val,
name.Val, elements.Val));
6356#undef PARSE_MD_FIELD
6368bool LLParser::parseMetadataAsValue(
Value *&V, PerFunctionState &PFS) {
6371 if (parseMetadata(MD, &PFS))
6382bool LLParser::parseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
6383 PerFunctionState *PFS) {
6386 if (parseType(Ty, TypeMsg, Loc))
6389 return error(Loc,
"invalid metadata-value-metadata roundtrip");
6392 if (parseValue(Ty, V, PFS))
6407bool LLParser::parseMetadata(
Metadata *&MD, PerFunctionState *PFS) {
6411 if (Lex.getStrVal() ==
"DIArgList") {
6413 if (parseDIArgList(AL, PFS))
6419 if (parseSpecializedMDNode(
N)) {
6429 return parseValueAsMetadata(MD,
"expected metadata operand", PFS);
6439 if (parseMDString(S))
6449 if (parseMDNodeTail(
N))
6460 PerFunctionState *PFS) {
6462 return error(
ID.Loc,
"functions are not values, refer to them as pointers");
6467 return error(
ID.Loc,
"invalid use of function-local name");
6468 V = PFS->getVal(
ID.UIntVal, Ty,
ID.Loc);
6469 return V ==
nullptr;
6472 return error(
ID.Loc,
"invalid use of function-local name");
6473 V = PFS->getVal(
ID.StrVal, Ty,
ID.Loc);
6474 return V ==
nullptr;
6477 return error(
ID.Loc,
"invalid type for inline asm constraint string");
6481 ID.FTy,
ID.StrVal,
ID.StrVal2,
ID.UIntVal & 1, (
ID.UIntVal >> 1) & 1,
6486 V = getGlobalVal(
ID.StrVal, Ty,
ID.Loc);
6489 return V ==
nullptr;
6491 V = getGlobalVal(
ID.UIntVal, Ty,
ID.Loc);
6494 return V ==
nullptr;
6497 return error(
ID.Loc,
"integer constant must have integer type");
6499 V = ConstantInt::get(Context,
ID.APSIntVal);
6504 return error(
ID.Loc,
"floating point constant invalid for type");
6510 bool IsSNAN =
ID.APFloatVal.isSignaling();
6525 APInt Payload =
ID.APFloatVal.bitcastToAPInt();
6527 ID.APFloatVal.isNegative(), &Payload);
6530 V = ConstantFP::get(Context,
ID.APFloatVal);
6532 if (
V->getType() != Ty)
6533 return error(
ID.Loc,
"floating point constant does not have type '" +
6539 return error(
ID.Loc,
"null must be a pointer type");
6545 return error(
ID.Loc,
"invalid type for undef constant");
6550 return error(
ID.Loc,
"invalid empty array initializer");
6556 return error(
ID.Loc,
"invalid type for null constant");
6559 return error(
ID.Loc,
"invalid type for null constant");
6564 return error(
ID.Loc,
"invalid type for none constant");
6570 return error(
ID.Loc,
"invalid type for poison constant");
6574 if (
ID.ConstantVal->getType() != Ty)
6575 return error(
ID.Loc,
"constant expression type mismatch: got type '" +
6582 return error(
ID.Loc,
"vector constant must have vector type");
6584 return error(
ID.Loc,
"constant expression type mismatch: got type '" +
6586 "' but expected '" +
6594 if (
ST->getNumElements() !=
ID.UIntVal)
6596 "initializer with struct type has wrong # elements");
6598 return error(
ID.Loc,
"packed'ness of initializer and type don't match");
6601 for (
unsigned i = 0, e =
ID.UIntVal; i != e; ++i)
6602 if (
ID.ConstantStructElts[i]->getType() !=
ST->getElementType(i))
6605 "element " + Twine(i) +
6606 " of struct initializer doesn't match struct element type");
6609 ST,
ArrayRef(
ID.ConstantStructElts.get(),
ID.UIntVal));
6611 return error(
ID.Loc,
"constant expression type mismatch");
6620 auto Loc = Lex.getLoc();
6621 if (parseValID(
ID,
nullptr))
6634 if (convertValIDToValue(Ty,
ID, V,
nullptr))
6644 return error(Loc,
"expected a constant value");
6648bool LLParser::parseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
6651 return parseValID(
ID, PFS, Ty) ||
6652 convertValIDToValue(Ty,
ID, V, PFS);
6655bool LLParser::parseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
6657 return parseType(Ty) || parseValue(Ty, V, PFS);
6660bool LLParser::parseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &
Loc,
6661 PerFunctionState &PFS) {
6664 if (parseTypeAndValue(V, PFS))
6667 return error(Loc,
"expected a basic block");
6676 if (!Name.starts_with(
"llvm.dbg."))
6679 return FnID == Intrinsic::dbg_declare || FnID == Intrinsic::dbg_value ||
6680 FnID == Intrinsic::dbg_assign;
6688bool LLParser::parseFunctionHeader(
Function *&Fn,
bool IsDefine,
6689 unsigned &FunctionNumber,
6692 LocTy LinkageLoc = Lex.getLoc();
6694 unsigned Visibility;
6695 unsigned DLLStorageClass;
6697 AttrBuilder RetAttrs(M->getContext());
6700 Type *RetType =
nullptr;
6701 LocTy RetTypeLoc = Lex.getLoc();
6702 if (parseOptionalLinkage(
Linkage, HasLinkage, Visibility, DLLStorageClass,
6704 parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
6705 parseType(RetType, RetTypeLoc,
true ))
6714 return error(LinkageLoc,
"invalid linkage for function definition");
6724 return error(LinkageLoc,
"invalid linkage for function declaration");
6728 return error(LinkageLoc,
"invalid function linkage type");
6732 return error(LinkageLoc,
6733 "symbol with local linkage must have default visibility");
6736 return error(LinkageLoc,
6737 "symbol with local linkage cannot have a DLL storage class");
6740 return error(RetTypeLoc,
"invalid function return type");
6742 LocTy NameLoc = Lex.getLoc();
6744 std::string FunctionName;
6746 FunctionName = Lex.getStrVal();
6748 FunctionNumber = Lex.getUIntVal();
6749 if (checkValueID(NameLoc,
"function",
"@", NumberedVals.getNext(),
6753 return tokError(
"expected function name");
6759 return tokError(
"expected '(' in function argument list");
6763 AttrBuilder FuncAttrs(M->getContext());
6764 std::vector<unsigned> FwdRefAttrGrps;
6767 std::string Partition;
6768 MaybeAlign Alignment;
6771 unsigned AddrSpace = 0;
6777 if (parseArgumentList(ArgList, UnnamedArgNums, IsVarArg) ||
6778 parseOptionalUnnamedAddr(UnnamedAddr) ||
6779 parseOptionalProgramAddrSpace(AddrSpace) ||
6780 parseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
6784 parseOptionalComdat(FunctionName,
C) ||
6785 parseOptionalAlignment(Alignment) ||
6786 (EatIfPresent(
lltok::kw_gc) && parseStringConstant(GC)) ||
6790 parseGlobalTypeAndValue(PersonalityFn)))
6793 if (FuncAttrs.contains(Attribute::Builtin))
6794 return error(BuiltinLoc,
"'builtin' attribute not valid on function");
6797 if (MaybeAlign
A = FuncAttrs.getAlignment()) {
6799 FuncAttrs.removeAttribute(Attribute::Alignment);
6804 std::vector<Type*> ParamTypeList;
6807 for (
const ArgInfo &Arg : ArgList) {
6808 ParamTypeList.push_back(Arg.Ty);
6809 Attrs.push_back(Arg.Attrs);
6816 if (PAL.hasParamAttr(0, Attribute::StructRet) && !RetType->
isVoidTy())
6817 return error(RetTypeLoc,
"functions with 'sret' argument must return void");
6823 GlobalValue *FwdFn =
nullptr;
6824 if (!FunctionName.empty()) {
6827 auto FRVI = ForwardRefVals.find(FunctionName);
6828 if (FRVI != ForwardRefVals.end()) {
6829 FwdFn = FRVI->second.first;
6831 return error(FRVI->second.second,
6832 "invalid forward reference to "
6835 "' with wrong type: "
6839 ForwardRefVals.erase(FRVI);
6840 }
else if ((Fn = M->getFunction(FunctionName))) {
6842 return error(NameLoc,
6843 "invalid redefinition of function '" + FunctionName +
"'");
6844 }
else if (M->getNamedValue(FunctionName)) {
6845 return error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
6851 if (FunctionNumber == (
unsigned)-1)
6852 FunctionNumber = NumberedVals.getNext();
6856 auto I = ForwardRefValIDs.find(FunctionNumber);
6857 if (
I != ForwardRefValIDs.end()) {
6858 FwdFn =
I->second.first;
6860 return error(NameLoc,
"type of definition and forward reference of '@" +
6861 Twine(FunctionNumber) +
6866 ForwardRefValIDs.erase(
I);
6875 if (FunctionName.empty())
6876 NumberedVals.add(FunctionNumber, Fn);
6891 if (!
GC.empty()) Fn->
setGC(GC);
6894 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
6898 for (
unsigned i = 0, e = ArgList.size(); i != e; ++i, ++ArgIt) {
6900 if (ArgList[i].
Name.empty())
continue;
6903 ArgIt->
setName(ArgList[i].Name);
6905 if (ArgIt->
getName() != ArgList[i].Name)
6906 return error(ArgList[i].Loc,
6907 "redefinition of argument '%" + ArgList[i].Name +
"'");
6920 if (FunctionName.empty()) {
6922 ID.UIntVal = FunctionNumber;
6925 ID.StrVal = FunctionName;
6927 auto Blocks = ForwardRefBlockAddresses.find(
ID);
6928 if (Blocks != ForwardRefBlockAddresses.end())
6929 return error(Blocks->first.Loc,
6930 "cannot take blockaddress inside a declaration");
6934bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
6936 if (FunctionNumber == -1) {
6938 ID.StrVal = std::string(F.getName());
6941 ID.UIntVal = FunctionNumber;
6944 auto Blocks = P.ForwardRefBlockAddresses.find(
ID);
6945 if (Blocks == P.ForwardRefBlockAddresses.end())
6948 for (
const auto &
I : Blocks->second) {
6949 const ValID &BBID =
I.first;
6950 GlobalValue *GV =
I.second;
6953 "Expected local id or name");
6960 return P.error(BBID.
Loc,
"referenced value is not a basic block");
6963 ResolvedVal = P.checkValidVariableType(BBID.
Loc, BBID.
StrVal, GV->
getType(),
6971 P.ForwardRefBlockAddresses.erase(Blocks);
6977bool LLParser::parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
6978 ArrayRef<unsigned> UnnamedArgNums) {
6980 return tokError(
"expected '{' in function body");
6983 PerFunctionState PFS(*
this, Fn, FunctionNumber, UnnamedArgNums);
6987 if (PFS.resolveForwardRefBlockAddresses())
6993 return tokError(
"function body requires at least one basic block");
6997 if (parseBasicBlock(PFS))
7001 if (parseUseListOrder(&PFS))
7008 return PFS.finishFunction();
7013bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
7017 LocTy NameLoc = Lex.getLoc();
7019 Name = Lex.getStrVal();
7022 NameID = Lex.getUIntVal();
7026 BasicBlock *BB = PFS.defineBB(Name, NameID, NameLoc);
7030 std::string NameStr;
7035 auto DeleteDbgRecord = [](DbgRecord *DR) { DR->deleteRecord(); };
7036 using DbgRecordPtr = std::unique_ptr<DbgRecord,
decltype(DeleteDbgRecord)>;
7043 if (SeenOldDbgInfoFormat)
7044 return error(Lex.getLoc(),
"debug record should not appear in a module "
7045 "containing debug info intrinsics");
7046 SeenNewDbgInfoFormat =
true;
7050 if (parseDebugRecord(DR, PFS))
7052 TrailingDbgRecord.emplace_back(DR, DeleteDbgRecord);
7057 LocTy NameLoc = Lex.getLoc();
7062 NameID = Lex.getUIntVal();
7064 if (parseToken(
lltok::equal,
"expected '=' after instruction id"))
7067 NameStr = Lex.getStrVal();
7069 if (parseToken(
lltok::equal,
"expected '=' after instruction name"))
7073 switch (parseInstruction(Inst, BB, PFS)) {
7076 case InstError:
return true;
7083 if (parseInstructionMetadata(*Inst))
7086 case InstExtraComma:
7091 if (parseInstructionMetadata(*Inst))
7097 if (PFS.setInstName(NameID, NameStr, NameLoc, Inst))
7101 for (DbgRecordPtr &DR : TrailingDbgRecord)
7103 TrailingDbgRecord.clear();
7106 assert(TrailingDbgRecord.empty() &&
7107 "All debug values should have been attached to an instruction.");
7116bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
7119 LocTy DVRLoc = Lex.getLoc();
7121 return error(DVRLoc,
"expected debug record type here");
7122 RecordKind
RecordType = StringSwitch<RecordKind>(Lex.getStrVal())
7123 .Case(
"declare", RecordKind::ValueKind)
7124 .Case(
"value", RecordKind::ValueKind)
7125 .Case(
"assign", RecordKind::ValueKind)
7126 .Case(
"label", RecordKind::LabelKind);
7135 if (parseMDNode(Label))
7140 if (parseMDNode(DbgLoc))
7148 LocType
ValueType = StringSwitch<LocType>(Lex.getStrVal())
7149 .Case(
"declare", LocType::Declare)
7150 .Case(
"value", LocType::Value)
7151 .Case(
"assign", LocType::Assign);
7159 if (parseMetadata(ValLocMD, &PFS))
7166 if (parseMDNode(Variable))
7173 if (parseMDNode(Expression))
7179 MDNode *AssignID =
nullptr;
7180 Metadata *AddressLocation =
nullptr;
7181 MDNode *AddressExpression =
nullptr;
7184 if (parseMDNode(AssignID))
7190 if (parseMetadata(AddressLocation, &PFS))
7196 if (parseMDNode(AddressExpression))
7210 ValueType, ValLocMD, Variable, Expression, AssignID, AddressLocation,
7220int LLParser::parseInstruction(Instruction *&Inst, BasicBlock *BB,
7221 PerFunctionState &PFS) {
7224 return tokError(
"found end of file when expecting more instructions");
7225 LocTy Loc = Lex.getLoc();
7226 unsigned KeywordVal = Lex.getUIntVal();
7231 return error(Loc,
"expected instruction opcode");
7235 return parseRet(Inst, BB, PFS);
7237 return parseBr(Inst, PFS);
7239 return parseSwitch(Inst, PFS);
7241 return parseIndirectBr(Inst, PFS);
7243 return parseInvoke(Inst, PFS);
7245 return parseResume(Inst, PFS);
7247 return parseCleanupRet(Inst, PFS);
7249 return parseCatchRet(Inst, PFS);
7251 return parseCatchSwitch(Inst, PFS);
7253 return parseCatchPad(Inst, PFS);
7255 return parseCleanupPad(Inst, PFS);
7257 return parseCallBr(Inst, PFS);
7260 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7261 int Res = parseUnaryOp(Inst, PFS, KeywordVal,
true);
7277 if (parseArithmetic(Inst, PFS, KeywordVal,
false))
7289 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7290 int Res = parseArithmetic(Inst, PFS, KeywordVal,
true);
7304 if (parseArithmetic(Inst, PFS, KeywordVal,
false))
7312 return parseArithmetic(Inst, PFS, KeywordVal,
7316 if (parseLogical(Inst, PFS, KeywordVal))
7324 return parseLogical(Inst, PFS, KeywordVal);
7327 if (parseCompare(Inst, PFS, KeywordVal))
7334 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7335 int Res = parseCompare(Inst, PFS, KeywordVal);
7347 bool Res = parseCast(Inst, PFS, KeywordVal);
7359 if (parseCast(Inst, PFS, KeywordVal))
7376 return parseCast(Inst, PFS, KeywordVal);
7379 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7380 if (parseCast(Inst, PFS, KeywordVal))
7389 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7390 int Res = parseSelect(Inst, PFS);
7395 return error(Loc,
"fast-math-flags specified for select without "
7396 "floating-point scalar or vector return type");
7402 return parseVAArg(Inst, PFS);
7404 return parseExtractElement(Inst, PFS);
7406 return parseInsertElement(Inst, PFS);
7408 return parseShuffleVector(Inst, PFS);
7410 FastMathFlags FMF = EatFastMathFlagsIfPresent();
7411 int Res = parsePHI(Inst, PFS);
7416 return error(Loc,
"fast-math-flags specified for phi without "
7417 "floating-point scalar or vector return type");
7423 return parseLandingPad(Inst, PFS);
7425 return parseFreeze(Inst, PFS);
7437 return parseAlloc(Inst, PFS);
7439 return parseLoad(Inst, PFS);
7441 return parseStore(Inst, PFS);
7443 return parseCmpXchg(Inst, PFS);
7445 return parseAtomicRMW(Inst, PFS);
7447 return parseFence(Inst, PFS);
7449 return parseGetElementPtr(Inst, PFS);
7451 return parseExtractValue(Inst, PFS);
7453 return parseInsertValue(Inst, PFS);
7458bool LLParser::parseCmpPredicate(
unsigned &
P,
unsigned Opc) {
7459 if (
Opc == Instruction::FCmp) {
7460 switch (Lex.getKind()) {
7462 return tokError(
"expected fcmp predicate (e.g. 'oeq')");
7481 switch (Lex.getKind()) {
7483 return tokError(
"expected icmp predicate (e.g. 'eq')");
7507bool LLParser::parseRet(Instruction *&Inst, BasicBlock *BB,
7508 PerFunctionState &PFS) {
7509 SMLoc TypeLoc = Lex.getLoc();
7511 if (parseType(Ty,
true ))
7514 Type *ResType = PFS.getFunction().getReturnType();
7518 return error(TypeLoc,
"value doesn't match function result type '" +
7526 if (parseValue(Ty, RV, PFS))
7530 return error(TypeLoc,
"value doesn't match function result type '" +
7540bool LLParser::parseBr(Instruction *&Inst, PerFunctionState &PFS) {
7544 if (parseTypeAndValue(Op0, Loc, PFS))
7553 return error(Loc,
"branch condition must have 'i1' type");
7555 if (parseToken(
lltok::comma,
"expected ',' after branch condition") ||
7556 parseTypeAndBasicBlock(Op1, Loc, PFS) ||
7557 parseToken(
lltok::comma,
"expected ',' after true destination") ||
7558 parseTypeAndBasicBlock(Op2, Loc2, PFS))
7570bool LLParser::parseSwitch(Instruction *&Inst, PerFunctionState &PFS) {
7571 LocTy CondLoc, BBLoc;
7574 if (parseTypeAndValue(
Cond, CondLoc, PFS) ||
7575 parseToken(
lltok::comma,
"expected ',' after switch condition") ||
7576 parseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
7580 if (!
Cond->getType()->isIntegerTy())
7581 return error(CondLoc,
"switch condition must have integer type");
7584 SmallPtrSet<Value*, 32> SeenCases;
7590 if (parseTypeAndValue(Constant, CondLoc, PFS) ||
7591 parseToken(
lltok::comma,
"expected ',' after case value") ||
7592 parseTypeAndBasicBlock(DestBB, PFS))
7595 if (!SeenCases.
insert(Constant).second)
7596 return error(CondLoc,
"duplicate case value in switch");
7598 return error(CondLoc,
"case value is not a constant integer");
7606 for (
const auto &[OnVal, Dest] : Table)
7607 SI->addCase(OnVal, Dest);
7615bool LLParser::parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) {
7618 if (parseTypeAndValue(
Address, AddrLoc, PFS) ||
7619 parseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
7623 if (!
Address->getType()->isPointerTy())
7624 return error(AddrLoc,
"indirectbr address must have pointer type");
7627 SmallVector<BasicBlock*, 16> DestList;
7631 if (parseTypeAndBasicBlock(DestBB, PFS))
7636 if (parseTypeAndBasicBlock(DestBB, PFS))
7642 if (parseToken(
lltok::rsquare,
"expected ']' at end of block list"))
7646 for (BasicBlock *Dest : DestList)
7656 FunctionType *&FuncTy) {
7662 for (
const ParamInfo &Arg : ArgList)
7676bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
7677 LocTy CallLoc = Lex.getLoc();
7678 AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
7679 std::vector<unsigned> FwdRefAttrGrps;
7682 unsigned InvokeAddrSpace;
7683 Type *RetType =
nullptr;
7690 if (parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
7691 parseOptionalProgramAddrSpace(InvokeAddrSpace) ||
7692 parseType(RetType, RetTypeLoc,
true ) ||
7693 parseValID(CalleeID, &PFS) || parseParameterList(ArgList, PFS) ||
7694 parseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
7696 parseOptionalOperandBundles(BundleList, PFS) ||
7698 parseTypeAndBasicBlock(NormalBB, PFS) ||
7700 parseTypeAndBasicBlock(UnwindBB, PFS))
7707 if (resolveFunctionType(RetType, ArgList, Ty))
7708 return error(RetTypeLoc,
"Invalid result type for LLVM function");
7714 if (convertValIDToValue(
PointerType::get(Context, InvokeAddrSpace), CalleeID,
7719 SmallVector<Value *, 8>
Args;
7726 for (
const ParamInfo &Arg : ArgList) {
7727 Type *ExpectedTy =
nullptr;
7730 }
else if (!Ty->isVarArg()) {
7731 return error(Arg.Loc,
"too many arguments specified");
7734 if (ExpectedTy && ExpectedTy != Arg.V->getType())
7735 return error(Arg.Loc,
"argument is not of expected type '" +
7737 Args.push_back(Arg.V);
7742 return error(CallLoc,
"not enough parameters specified for call");
7751 II->setCallingConv(CC);
7752 II->setAttributes(PAL);
7753 ForwardRefAttrGroups[
II] = FwdRefAttrGrps;
7760bool LLParser::parseResume(Instruction *&Inst, PerFunctionState &PFS) {
7762 if (parseTypeAndValue(Exn, ExnLoc, PFS))
7770bool LLParser::parseExceptionArgs(SmallVectorImpl<Value *> &Args,
7771 PerFunctionState &PFS) {
7772 if (parseToken(
lltok::lsquare,
"expected '[' in catchpad/cleanuppad"))
7777 if (!
Args.empty() &&
7778 parseToken(
lltok::comma,
"expected ',' in argument list"))
7783 Type *ArgTy =
nullptr;
7784 if (parseType(ArgTy, ArgLoc))
7789 if (parseMetadataAsValue(V, PFS))
7792 if (parseValue(ArgTy, V, PFS))
7804bool LLParser::parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS) {
7805 Value *CleanupPad =
nullptr;
7807 if (parseToken(
lltok::kw_from,
"expected 'from' after cleanupret"))
7822 if (parseTypeAndBasicBlock(UnwindBB, PFS)) {
7833bool LLParser::parseCatchRet(Instruction *&Inst, PerFunctionState &PFS) {
7834 Value *CatchPad =
nullptr;
7836 if (parseToken(
lltok::kw_from,
"expected 'from' after catchret"))
7843 if (parseToken(
lltok::kw_to,
"expected 'to' in catchret") ||
7844 parseTypeAndBasicBlock(BB, PFS))
7853bool LLParser::parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS) {
7861 return tokError(
"expected scope value for catchswitch");
7866 if (parseToken(
lltok::lsquare,
"expected '[' with catchswitch labels"))
7872 if (parseTypeAndBasicBlock(DestBB, PFS))
7877 if (parseToken(
lltok::rsquare,
"expected ']' after catchswitch labels"))
7880 if (parseToken(
lltok::kw_unwind,
"expected 'unwind' after catchswitch scope"))
7888 if (parseTypeAndBasicBlock(UnwindBB, PFS))
7894 for (BasicBlock *DestBB : Table)
7895 CatchSwitch->addHandler(DestBB);
7902bool LLParser::parseCatchPad(Instruction *&Inst, PerFunctionState &PFS) {
7903 Value *CatchSwitch =
nullptr;
7909 return tokError(
"expected scope value for catchpad");
7914 SmallVector<Value *, 8>
Args;
7915 if (parseExceptionArgs(Args, PFS))
7924bool LLParser::parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS) {
7925 Value *ParentPad =
nullptr;
7932 return tokError(
"expected scope value for cleanuppad");
7937 SmallVector<Value *, 8>
Args;
7938 if (parseExceptionArgs(Args, PFS))
7954bool LLParser::parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
7955 unsigned Opc,
bool IsFP) {
7957 if (parseTypeAndValue(
LHS, Loc, PFS))
7964 return error(Loc,
"invalid operand type for instruction");
7974bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) {
7975 LocTy CallLoc = Lex.getLoc();
7976 AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
7977 std::vector<unsigned> FwdRefAttrGrps;
7980 Type *RetType =
nullptr;
7987 if (parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
7988 parseType(RetType, RetTypeLoc,
true ) ||
7989 parseValID(CalleeID, &PFS) || parseParameterList(ArgList, PFS) ||
7990 parseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
7992 parseOptionalOperandBundles(BundleList, PFS) ||
7994 parseTypeAndBasicBlock(DefaultDest, PFS) ||
7999 SmallVector<BasicBlock *, 16> IndirectDests;
8003 if (parseTypeAndBasicBlock(DestBB, PFS))
8008 if (parseTypeAndBasicBlock(DestBB, PFS))
8014 if (parseToken(
lltok::rsquare,
"expected ']' at end of block list"))
8021 if (resolveFunctionType(RetType, ArgList, Ty))
8022 return error(RetTypeLoc,
"Invalid result type for LLVM function");
8033 SmallVector<Value *, 8>
Args;
8040 for (
const ParamInfo &Arg : ArgList) {
8041 Type *ExpectedTy =
nullptr;
8044 }
else if (!Ty->isVarArg()) {
8045 return error(Arg.Loc,
"too many arguments specified");
8048 if (ExpectedTy && ExpectedTy != Arg.V->getType())
8049 return error(Arg.Loc,
"argument is not of expected type '" +
8051 Args.push_back(Arg.V);
8056 return error(CallLoc,
"not enough parameters specified for call");
8068 ForwardRefAttrGroups[CBI] = FwdRefAttrGrps;
8082bool LLParser::parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
8083 unsigned Opc,
bool IsFP) {
8085 if (parseTypeAndValue(
LHS, Loc, PFS) ||
8086 parseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
8094 return error(Loc,
"invalid operand type for instruction");
8102bool LLParser::parseLogical(Instruction *&Inst, PerFunctionState &PFS,
8105 if (parseTypeAndValue(
LHS, Loc, PFS) ||
8106 parseToken(
lltok::comma,
"expected ',' in logical operation") ||
8112 "instruction requires integer or integer vector operands");
8121bool LLParser::parseCompare(Instruction *&Inst, PerFunctionState &PFS,
8127 if (parseCmpPredicate(Pred,
Opc) || parseTypeAndValue(
LHS, Loc, PFS) ||
8128 parseToken(
lltok::comma,
"expected ',' after compare value") ||
8132 if (
Opc == Instruction::FCmp) {
8134 return error(Loc,
"fcmp requires floating point operands");
8137 assert(
Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
8140 return error(Loc,
"icmp requires integer operands");
8152bool LLParser::parseCast(Instruction *&Inst, PerFunctionState &PFS,
8156 Type *DestTy =
nullptr;
8157 if (parseTypeAndValue(
Op, Loc, PFS) ||
8158 parseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
8163 return error(Loc,
"invalid cast opcode for cast from '" +
8172bool LLParser::parseSelect(Instruction *&Inst, PerFunctionState &PFS) {
8174 Value *Op0, *Op1, *Op2;
8175 if (parseTypeAndValue(Op0, Loc, PFS) ||
8176 parseToken(
lltok::comma,
"expected ',' after select condition") ||
8177 parseTypeAndValue(Op1, PFS) ||
8178 parseToken(
lltok::comma,
"expected ',' after select value") ||
8179 parseTypeAndValue(Op2, PFS))
8183 return error(Loc, Reason);
8191bool LLParser::parseVAArg(Instruction *&Inst, PerFunctionState &PFS) {
8193 Type *EltTy =
nullptr;
8195 if (parseTypeAndValue(
Op, PFS) ||
8196 parseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
8197 parseType(EltTy, TypeLoc))
8201 return error(TypeLoc,
"va_arg requires operand with first class type");
8203 Inst =
new VAArgInst(
Op, EltTy);
8209bool LLParser::parseExtractElement(Instruction *&Inst, PerFunctionState &PFS) {
8212 if (parseTypeAndValue(Op0, Loc, PFS) ||
8213 parseToken(
lltok::comma,
"expected ',' after extract value") ||
8214 parseTypeAndValue(Op1, PFS))
8218 return error(Loc,
"invalid extractelement operands");
8226bool LLParser::parseInsertElement(Instruction *&Inst, PerFunctionState &PFS) {
8228 Value *Op0, *Op1, *Op2;
8229 if (parseTypeAndValue(Op0, Loc, PFS) ||
8230 parseToken(
lltok::comma,
"expected ',' after insertelement value") ||
8231 parseTypeAndValue(Op1, PFS) ||
8232 parseToken(
lltok::comma,
"expected ',' after insertelement value") ||
8233 parseTypeAndValue(Op2, PFS))
8237 return error(Loc,
"invalid insertelement operands");
8245bool LLParser::parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS) {
8247 Value *Op0, *Op1, *Op2;
8248 if (parseTypeAndValue(Op0, Loc, PFS) ||
8249 parseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
8250 parseTypeAndValue(Op1, PFS) ||
8251 parseToken(
lltok::comma,
"expected ',' after shuffle value") ||
8252 parseTypeAndValue(Op2, PFS))
8256 return error(Loc,
"invalid shufflevector operands");
8258 Inst =
new ShuffleVectorInst(Op0, Op1, Op2);
8264int LLParser::parsePHI(Instruction *&Inst, PerFunctionState &PFS) {
8268 if (parseType(Ty, TypeLoc))
8272 return error(TypeLoc,
"phi node must have first class type");
8275 bool AteExtraComma =
false;
8287 AteExtraComma =
true;
8291 if (parseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
8292 parseValue(Ty, Op0, PFS) ||
8293 parseToken(
lltok::comma,
"expected ',' after insertelement value") ||
8302 for (
const auto &[Val, BB] : PHIVals)
8305 return AteExtraComma ? InstExtraComma : InstNormal;
8314bool LLParser::parseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
8317 if (parseType(Ty, TyLoc))
8330 return tokError(
"expected 'catch' or 'filter' clause type");
8334 if (parseTypeAndValue(V, VLoc, PFS))
8341 return error(VLoc,
"'catch' clause has an invalid type");
8344 return error(VLoc,
"'filter' clause has an invalid type");
8349 return error(VLoc,
"clause argument must be a constant");
8353 Inst = LP.release();
8359bool LLParser::parseFreeze(Instruction *&Inst, PerFunctionState &PFS) {
8362 if (parseTypeAndValue(
Op, Loc, PFS))
8365 Inst =
new FreezeInst(
Op);
8378bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS,
8380 AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
8381 std::vector<unsigned> FwdRefAttrGrps;
8383 unsigned CallAddrSpace;
8385 Type *RetType =
nullptr;
8390 LocTy CallLoc = Lex.getLoc();
8394 "expected 'tail call', 'musttail call', or 'notail call'"))
8397 FastMathFlags FMF = EatFastMathFlagsIfPresent();
8399 if (parseOptionalCallingConv(CC) || parseOptionalReturnAttrs(RetAttrs) ||
8400 parseOptionalProgramAddrSpace(CallAddrSpace) ||
8401 parseType(RetType, RetTypeLoc,
true ) ||
8402 parseValID(CalleeID, &PFS) ||
8404 PFS.getFunction().isVarArg()) ||
8405 parseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false, BuiltinLoc) ||
8406 parseOptionalOperandBundles(BundleList, PFS))
8413 if (resolveFunctionType(RetType, ArgList, Ty))
8414 return error(RetTypeLoc,
"Invalid result type for LLVM function");
8420 if (convertValIDToValue(
PointerType::get(Context, CallAddrSpace), CalleeID,
8427 SmallVector<Value*, 8>
Args;
8433 for (
const ParamInfo &Arg : ArgList) {
8434 Type *ExpectedTy =
nullptr;
8437 }
else if (!Ty->isVarArg()) {
8438 return error(Arg.Loc,
"too many arguments specified");
8441 if (ExpectedTy && ExpectedTy != Arg.V->getType())
8442 return error(Arg.Loc,
"argument is not of expected type '" +
8444 Args.push_back(Arg.V);
8445 Attrs.push_back(Arg.Attrs);
8449 return error(CallLoc,
"not enough parameters specified for call");
8462 return error(CallLoc,
"fast-math-flags specified for call without "
8463 "floating-point scalar or vector return type");
8470 if (SeenNewDbgInfoFormat) {
8472 return error(CallLoc,
"llvm.dbg intrinsic should not appear in a module "
8473 "using non-intrinsic debug info");
8475 SeenOldDbgInfoFormat =
true;
8478 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
8490int LLParser::parseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
8492 LocTy SizeLoc, TyLoc, ASLoc;
8493 MaybeAlign Alignment;
8494 unsigned AddrSpace = 0;
8497 bool IsInAlloca = EatIfPresent(lltok::kw_inalloca);
8498 bool IsSwiftError = EatIfPresent(lltok::kw_swifterror);
8500 if (parseType(Ty, TyLoc))
8504 return error(TyLoc,
"invalid type for alloca");
8506 bool AteExtraComma =
false;
8508 if (Lex.getKind() == lltok::kw_align) {
8509 if (parseOptionalAlignment(Alignment))
8511 if (parseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
8514 ASLoc = Lex.getLoc();
8515 if (parseOptionalAddrSpace(AddrSpace))
8518 AteExtraComma =
true;
8520 if (parseTypeAndValue(
Size, SizeLoc, PFS))
8523 if (Lex.getKind() == lltok::kw_align) {
8524 if (parseOptionalAlignment(Alignment))
8526 if (parseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
8529 ASLoc = Lex.getLoc();
8530 if (parseOptionalAddrSpace(AddrSpace))
8533 AteExtraComma =
true;
8539 if (
Size && !
Size->getType()->isIntegerTy())
8540 return error(SizeLoc,
"element count must have integer type");
8542 SmallPtrSet<Type *, 4> Visited;
8543 if (!Alignment && !Ty->
isSized(&Visited))
8544 return error(TyLoc,
"Cannot allocate unsized type");
8546 Alignment = M->getDataLayout().getPrefTypeAlign(Ty);
8547 AllocaInst *AI =
new AllocaInst(Ty, AddrSpace,
Size, *Alignment);
8551 return AteExtraComma ? InstExtraComma : InstNormal;
8558int LLParser::parseLoad(Instruction *&Inst, PerFunctionState &PFS) {
8560 MaybeAlign Alignment;
8561 bool AteExtraComma =
false;
8562 bool isAtomic =
false;
8571 bool isVolatile =
false;
8578 LocTy ExplicitTypeLoc = Lex.getLoc();
8579 if (parseType(Ty) ||
8580 parseToken(
lltok::comma,
"expected comma after load's type") ||
8581 parseTypeAndValue(Val, Loc, PFS) ||
8582 parseScopeAndOrdering(isAtomic, SSID, Ordering) ||
8583 parseOptionalCommaAlign(Alignment, AteExtraComma))
8587 return error(Loc,
"load operand must be a pointer to a first class type");
8588 if (isAtomic && !Alignment)
8589 return error(Loc,
"atomic load must have explicit non-zero alignment");
8592 return error(Loc,
"atomic load cannot use Release ordering");
8594 SmallPtrSet<Type *, 4> Visited;
8595 if (!Alignment && !Ty->
isSized(&Visited))
8596 return error(ExplicitTypeLoc,
"loading unsized types is not allowed");
8598 Alignment = M->getDataLayout().getABITypeAlign(Ty);
8599 Inst =
new LoadInst(Ty, Val,
"", isVolatile, *Alignment, Ordering, SSID);
8600 return AteExtraComma ? InstExtraComma : InstNormal;
8608int LLParser::parseStore(Instruction *&Inst, PerFunctionState &PFS) {
8610 MaybeAlign Alignment;
8611 bool AteExtraComma =
false;
8612 bool isAtomic =
false;
8621 bool isVolatile =
false;
8627 if (parseTypeAndValue(Val, Loc, PFS) ||
8628 parseToken(
lltok::comma,
"expected ',' after store operand") ||
8629 parseTypeAndValue(
Ptr, PtrLoc, PFS) ||
8630 parseScopeAndOrdering(isAtomic, SSID, Ordering) ||
8631 parseOptionalCommaAlign(Alignment, AteExtraComma))
8634 if (!
Ptr->getType()->isPointerTy())
8635 return error(PtrLoc,
"store operand must be a pointer");
8637 return error(Loc,
"store operand must be a first class value");
8638 if (isAtomic && !Alignment)
8639 return error(Loc,
"atomic store must have explicit non-zero alignment");
8642 return error(Loc,
"atomic store cannot use Acquire ordering");
8643 SmallPtrSet<Type *, 4> Visited;
8645 return error(Loc,
"storing unsized types is not allowed");
8647 Alignment = M->getDataLayout().getABITypeAlign(Val->
getType());
8649 Inst =
new StoreInst(Val,
Ptr, isVolatile, *Alignment, Ordering, SSID);
8650 return AteExtraComma ? InstExtraComma : InstNormal;
8657int LLParser::parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) {
8659 bool AteExtraComma =
false;
8663 bool isVolatile =
false;
8664 bool isWeak =
false;
8665 MaybeAlign Alignment;
8673 if (parseTypeAndValue(
Ptr, PtrLoc, PFS) ||
8674 parseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
8675 parseTypeAndValue(Cmp, CmpLoc, PFS) ||
8676 parseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
8677 parseTypeAndValue(New, NewLoc, PFS) ||
8678 parseScopeAndOrdering(
true , SSID, SuccessOrdering) ||
8679 parseOrdering(FailureOrdering) ||
8680 parseOptionalCommaAlign(Alignment, AteExtraComma))
8684 return tokError(
"invalid cmpxchg success ordering");
8686 return tokError(
"invalid cmpxchg failure ordering");
8687 if (!
Ptr->getType()->isPointerTy())
8688 return error(PtrLoc,
"cmpxchg operand must be a pointer");
8689 if (
Cmp->getType() !=
New->getType())
8690 return error(NewLoc,
"compare value and new value type do not match");
8691 if (!
New->getType()->isFirstClassType())
8692 return error(NewLoc,
"cmpxchg operand must be a first class value");
8694 const Align DefaultAlignment(
8695 PFS.getFunction().getDataLayout().getTypeStoreSize(
8698 AtomicCmpXchgInst *CXI =
8699 new AtomicCmpXchgInst(
Ptr, Cmp, New, Alignment.value_or(DefaultAlignment),
8700 SuccessOrdering, FailureOrdering, SSID);
8705 return AteExtraComma ? InstExtraComma : InstNormal;
8711int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
8713 bool AteExtraComma =
false;
8716 bool isVolatile =
false;
8719 MaybeAlign Alignment;
8724 switch (Lex.getKind()) {
8726 return tokError(
"expected binary operation in atomicrmw");
8777 if (parseTypeAndValue(
Ptr, PtrLoc, PFS) ||
8778 parseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
8779 parseTypeAndValue(Val, ValLoc, PFS) ||
8780 parseScopeAndOrdering(
true , SSID, Ordering) ||
8781 parseOptionalCommaAlign(Alignment, AteExtraComma))
8785 return tokError(
"atomicrmw cannot be unordered");
8786 if (!
Ptr->getType()->isPointerTy())
8787 return error(PtrLoc,
"atomicrmw operand must be a pointer");
8789 return error(ValLoc,
"atomicrmw operand may not be scalable");
8798 " operand must be an integer, floating point, or pointer type");
8802 return error(ValLoc,
"atomicrmw " +
8804 " operand must be a floating point type");
8808 return error(ValLoc,
"atomicrmw " +
8810 " operand must be an integer");
8815 PFS.getFunction().getDataLayout().getTypeStoreSizeInBits(
8818 return error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized"
8820 const Align DefaultAlignment(
8821 PFS.getFunction().getDataLayout().getTypeStoreSize(
8823 AtomicRMWInst *RMWI =
8825 Alignment.value_or(DefaultAlignment), Ordering, SSID);
8828 return AteExtraComma ? InstExtraComma : InstNormal;
8833int LLParser::parseFence(Instruction *&Inst, PerFunctionState &PFS) {
8836 if (parseScopeAndOrdering(
true , SSID, Ordering))
8840 return tokError(
"fence cannot be unordered");
8842 return tokError(
"fence cannot be monotonic");
8844 Inst =
new FenceInst(Context, Ordering, SSID);
8850int LLParser::parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
8852 Value *Val =
nullptr;
8868 if (parseType(Ty) ||
8869 parseToken(
lltok::comma,
"expected comma after getelementptr's type") ||
8870 parseTypeAndValue(
Ptr, Loc, PFS))
8875 if (!BasePointerType)
8876 return error(Loc,
"base of getelementptr must be a pointer");
8878 SmallVector<Value*, 16> Indices;
8879 bool AteExtraComma =
false;
8882 ElementCount GEPWidth =
BaseType->isVectorTy()
8888 AteExtraComma =
true;
8891 if (parseTypeAndValue(Val, EltLoc, PFS))
8894 return error(EltLoc,
"getelementptr index must be an integer");
8897 ElementCount ValNumEl = ValVTy->getElementCount();
8901 "getelementptr vector index has a wrong number of elements");
8902 GEPWidth = ValNumEl;
8907 SmallPtrSet<Type*, 4> Visited;
8909 return error(Loc,
"base element of getelementptr must be sized");
8913 return error(Loc,
"getelementptr cannot target structure that contains "
8914 "scalable vector type");
8917 return error(Loc,
"invalid getelementptr indices");
8920 GEP->setNoWrapFlags(NW);
8921 return AteExtraComma ? InstExtraComma : InstNormal;
8926int LLParser::parseExtractValue(Instruction *&Inst, PerFunctionState &PFS) {
8928 SmallVector<unsigned, 4> Indices;
8930 if (parseTypeAndValue(Val, Loc, PFS) ||
8931 parseIndexList(Indices, AteExtraComma))
8935 return error(Loc,
"extractvalue operand must be aggregate type");
8938 return error(Loc,
"invalid indices for extractvalue");
8940 return AteExtraComma ? InstExtraComma : InstNormal;
8945int LLParser::parseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
8947 SmallVector<unsigned, 4> Indices;
8949 if (parseTypeAndValue(Val0, Loc0, PFS) ||
8950 parseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
8951 parseTypeAndValue(Val1, Loc1, PFS) ||
8952 parseIndexList(Indices, AteExtraComma))
8956 return error(Loc0,
"insertvalue operand must be aggregate type");
8960 return error(Loc0,
"invalid indices for insertvalue");
8961 if (IndexedType != Val1->
getType())
8962 return error(Loc1,
"insertvalue operand and field disagree in type: '" +
8966 return AteExtraComma ? InstExtraComma : InstNormal;
8977bool LLParser::parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts) {
8992 if (parseMetadata(MD,
nullptr))
8997 return parseToken(
lltok::rbrace,
"expected end of metadata node");
9003bool LLParser::sortUseListOrder(
Value *V, ArrayRef<unsigned> Indexes,
9005 if (!
V->hasUseList())
9008 return error(Loc,
"value has no uses");
9010 unsigned NumUses = 0;
9011 SmallDenseMap<const Use *, unsigned, 16> Order;
9012 for (
const Use &U :
V->uses()) {
9013 if (++NumUses > Indexes.
size())
9015 Order[&
U] = Indexes[NumUses - 1];
9018 return error(Loc,
"value only has one use");
9019 if (Order.
size() != Indexes.
size() || NumUses > Indexes.
size())
9021 "wrong number of indexes, expected " + Twine(
V->getNumUses()));
9023 V->sortUseList([&](
const Use &L,
const Use &R) {
9031bool LLParser::parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes) {
9032 SMLoc Loc = Lex.getLoc();
9036 return tokError(
"expected non-empty list of uselistorder indexes");
9043 bool IsOrdered =
true;
9044 assert(Indexes.
empty() &&
"Expected empty order vector");
9047 if (parseUInt32(Index))
9052 Max = std::max(Max, Index);
9053 IsOrdered &= Index == Indexes.
size();
9061 if (Indexes.
size() < 2)
9062 return error(Loc,
"expected >= 2 uselistorder indexes");
9065 "expected distinct uselistorder indexes in range [0, size)");
9067 return error(Loc,
"expected uselistorder indexes to change the order");
9074bool LLParser::parseUseListOrder(PerFunctionState *PFS) {
9075 SMLoc Loc = Lex.getLoc();
9080 SmallVector<unsigned, 16> Indexes;
9081 if (parseTypeAndValue(V, PFS) ||
9082 parseToken(
lltok::comma,
"expected comma in uselistorder directive") ||
9083 parseUseListOrderIndexes(Indexes))
9086 return sortUseListOrder(V, Indexes, Loc);
9091bool LLParser::parseUseListOrderBB() {
9093 SMLoc Loc = Lex.getLoc();
9097 SmallVector<unsigned, 16> Indexes;
9098 if (parseValID(Fn,
nullptr) ||
9099 parseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
9100 parseValID(Label,
nullptr) ||
9101 parseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
9102 parseUseListOrderIndexes(Indexes))
9108 GV = M->getNamedValue(Fn.
StrVal);
9110 GV = NumberedVals.get(Fn.
UIntVal);
9112 return error(Fn.
Loc,
"expected function name in uselistorder_bb");
9115 "invalid function forward reference in uselistorder_bb");
9118 return error(Fn.
Loc,
"expected function name in uselistorder_bb");
9119 if (
F->isDeclaration())
9120 return error(Fn.
Loc,
"invalid declaration in uselistorder_bb");
9124 return error(
Label.Loc,
"invalid numeric label in uselistorder_bb");
9126 return error(
Label.Loc,
"expected basic block name in uselistorder_bb");
9127 Value *
V =
F->getValueSymbolTable()->lookup(
Label.StrVal);
9129 return error(
Label.Loc,
"invalid basic block in uselistorder_bb");
9131 return error(
Label.Loc,
"expected basic block in uselistorder_bb");
9133 return sortUseListOrder(V, Indexes, Loc);
9139bool LLParser::parseModuleEntry(
unsigned ID) {
9148 parseStringConstant(Path) ||
9156 if (parseUInt32(Hash[0]) || parseToken(
lltok::comma,
"expected ',' here") ||
9157 parseUInt32(Hash[1]) || parseToken(
lltok::comma,
"expected ',' here") ||
9158 parseUInt32(Hash[2]) || parseToken(
lltok::comma,
"expected ',' here") ||
9159 parseUInt32(Hash[3]) || parseToken(
lltok::comma,
"expected ',' here") ||
9160 parseUInt32(Hash[4]))
9167 auto ModuleEntry = Index->addModule(Path, Hash);
9168 ModuleIdMap[
ID] = ModuleEntry->first();
9175bool LLParser::parseTypeIdEntry(
unsigned ID) {
9184 parseStringConstant(Name))
9187 TypeIdSummary &TIS = Index->getOrInsertTypeIdSummary(Name);
9189 parseTypeIdSummary(TIS) || parseToken(
lltok::rparen,
"expected ')' here"))
9194 auto FwdRefTIDs = ForwardRefTypeIds.find(
ID);
9195 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
9196 for (
auto TIDRef : FwdRefTIDs->second) {
9198 "Forward referenced type id GUID expected to be 0");
9201 ForwardRefTypeIds.erase(FwdRefTIDs);
9209bool LLParser::parseTypeIdSummary(TypeIdSummary &TIS) {
9213 parseTypeTestResolution(TIS.
TTRes))
9218 if (parseOptionalWpdResolutions(TIS.
WPDRes))
9229 ValueInfo(
false, (GlobalValueSummaryMapTy::value_type *)-8);
9235bool LLParser::parseTypeIdCompatibleVtableEntry(
unsigned ID) {
9244 parseStringConstant(Name))
9248 Index->getOrInsertTypeIdCompatibleVtableSummary(Name);
9255 IdToIndexMapType IdToIndexMap;
9268 if (parseGVReference(VI, GVId))
9275 IdToIndexMap[GVId].push_back(std::make_pair(TI.size(),
Loc));
9276 TI.push_back({
Offset, VI});
9284 for (
auto I : IdToIndexMap) {
9285 auto &Infos = ForwardRefValueInfos[
I.first];
9286 for (
auto P :
I.second) {
9288 "Forward referenced ValueInfo expected to be empty");
9289 Infos.emplace_back(&TI[
P.first].VTableVI,
P.second);
9299 auto FwdRefTIDs = ForwardRefTypeIds.find(
ID);
9300 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
9301 for (
auto TIDRef : FwdRefTIDs->second) {
9303 "Forward referenced type id GUID expected to be 0");
9306 ForwardRefTypeIds.erase(FwdRefTIDs);
9318bool LLParser::parseTypeTestResolution(TypeTestResolution &TTRes) {
9326 switch (Lex.getKind()) {
9346 return error(Lex.getLoc(),
"unexpected TypeTestResolution kind");
9358 switch (Lex.getKind()) {
9373 if (parseToken(
lltok::colon,
"expected ':'") || parseUInt32(Val))
9386 return error(Lex.getLoc(),
"expected optional TypeTestResolution field");
9399bool LLParser::parseOptionalWpdResolutions(
9400 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap) {
9408 WholeProgramDevirtResolution WPDRes;
9412 parseToken(
lltok::comma,
"expected ',' here") || parseWpdRes(WPDRes) ||
9415 WPDResMap[
Offset] = WPDRes;
9432bool LLParser::parseWpdRes(WholeProgramDevirtResolution &WPDRes) {
9440 switch (Lex.getKind()) {
9451 return error(Lex.getLoc(),
"unexpected WholeProgramDevirtResolution kind");
9457 switch (Lex.getKind()) {
9465 if (parseOptionalResByArg(WPDRes.
ResByArg))
9469 return error(Lex.getLoc(),
9470 "expected optional WholeProgramDevirtResolution field");
9487bool LLParser::parseOptionalResByArg(
9488 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
9496 std::vector<uint64_t>
Args;
9497 if (parseArgs(Args) || parseToken(
lltok::comma,
"expected ',' here") ||
9505 WholeProgramDevirtResolution::ByArg ByArg;
9506 switch (Lex.getKind()) {
9520 return error(Lex.getLoc(),
9521 "unexpected WholeProgramDevirtResolution::ByArg kind");
9527 switch (Lex.getKind()) {
9531 parseUInt64(ByArg.
Info))
9537 parseUInt32(ByArg.
Byte))
9543 parseUInt32(ByArg.
Bit))
9547 return error(Lex.getLoc(),
9548 "expected optional whole program devirt field");
9555 ResByArg[
Args] = ByArg;
9566bool LLParser::parseArgs(std::vector<uint64_t> &Args) {
9574 if (parseUInt64(Val))
9576 Args.push_back(Val);
9585static const auto FwdVIRef = (GlobalValueSummaryMapTy::value_type *)-8;
9590 assert(!(ReadOnly && WriteOnly));
9600bool LLParser::addGlobalValueToIndex(
9602 unsigned ID, std::unique_ptr<GlobalValueSummary> Summary,
LocTy Loc) {
9607 VI = Index->getOrInsertValueInfo(GUID);
9611 auto *GV = M->getNamedValue(Name);
9613 return error(Loc,
"Reference to undefined global \"" + Name +
"\"");
9615 VI = Index->getOrInsertValueInfo(GV);
9619 "Need a source_filename to compute GUID for local");
9622 VI = Index->getOrInsertValueInfo(GUID, Index->saveString(Name));
9627 auto FwdRefVIs = ForwardRefValueInfos.find(
ID);
9628 if (FwdRefVIs != ForwardRefValueInfos.end()) {
9629 for (
auto VIRef : FwdRefVIs->second) {
9631 "Forward referenced ValueInfo expected to be empty");
9634 ForwardRefValueInfos.erase(FwdRefVIs);
9638 auto FwdRefAliasees = ForwardRefAliasees.find(
ID);
9639 if (FwdRefAliasees != ForwardRefAliasees.end()) {
9640 for (
auto AliaseeRef : FwdRefAliasees->second) {
9641 assert(!AliaseeRef.first->hasAliasee() &&
9642 "Forward referencing alias already has aliasee");
9643 assert(Summary &&
"Aliasee must be a definition");
9644 AliaseeRef.first->setAliasee(VI,
Summary.get());
9646 ForwardRefAliasees.erase(FwdRefAliasees);
9651 Index->addGlobalValueSummary(VI, std::move(Summary));
9654 if (
ID == NumberedValueInfos.size())
9655 NumberedValueInfos.push_back(VI);
9658 if (
ID > NumberedValueInfos.size())
9659 NumberedValueInfos.resize(
ID + 1);
9660 NumberedValueInfos[
ID] =
VI;
9668bool LLParser::parseSummaryIndexFlags() {
9675 if (parseUInt64(Flags))
9678 Index->setFlags(Flags);
9684bool LLParser::parseBlockCount() {
9690 uint64_t BlockCount;
9691 if (parseUInt64(BlockCount))
9694 Index->setBlockCount(BlockCount);
9702bool LLParser::parseGVEntry(
unsigned ID) {
9710 LocTy Loc = Lex.getLoc();
9713 switch (Lex.getKind()) {
9717 parseStringConstant(Name))
9723 if (parseToken(
lltok::colon,
"expected ':' here") || parseUInt64(GUID))
9727 return error(Lex.getLoc(),
"expected name or guid tag");
9750 switch (Lex.getKind()) {
9752 if (parseFunctionSummary(Name, GUID,
ID))
9756 if (parseVariableSummary(Name, GUID,
ID))
9760 if (parseAliasSummary(Name, GUID,
ID))
9764 return error(Lex.getLoc(),
"expected summary type");
9782 LocTy Loc = Lex.getLoc();
9786 StringRef ModulePath;
9787 GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
9790 false,
false,
false,
9794 FunctionSummary::TypeIdInfo TypeIdInfo;
9795 std::vector<FunctionSummary::ParamAccess> ParamAccesses;
9797 std::vector<CallsiteInfo> Callsites;
9798 std::vector<AllocInfo> Allocs;
9800 FunctionSummary::FFlags FFlags = {};
9803 parseModuleReference(ModulePath) ||
9804 parseToken(
lltok::comma,
"expected ',' here") || parseGVFlags(GVFlags) ||
9807 parseToken(
lltok::colon,
"expected ':' here") || parseUInt32(InstCount))
9812 switch (Lex.getKind()) {
9814 if (parseOptionalFFlags(FFlags))
9818 if (parseOptionalCalls(Calls))
9822 if (parseOptionalTypeIdInfo(TypeIdInfo))
9826 if (parseOptionalRefs(Refs))
9830 if (parseOptionalParamAccesses(ParamAccesses))
9834 if (parseOptionalAllocs(Allocs))
9838 if (parseOptionalCallsites(Callsites))
9842 return error(Lex.getLoc(),
"expected optional function summary field");
9849 auto FS = std::make_unique<FunctionSummary>(
9850 GVFlags, InstCount, FFlags, std::move(Refs), std::move(Calls),
9856 std::move(ParamAccesses), std::move(Callsites), std::move(Allocs));
9858 FS->setModulePath(ModulePath);
9860 return addGlobalValueToIndex(Name, GUID,
9862 std::move(FS), Loc);
9870 LocTy Loc = Lex.getLoc();
9874 StringRef ModulePath;
9875 GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
9878 false,
false,
false,
9880 GlobalVarSummary::GVarFlags GVarFlags(
false,
9888 parseModuleReference(ModulePath) ||
9889 parseToken(
lltok::comma,
"expected ',' here") || parseGVFlags(GVFlags) ||
9891 parseGVarFlags(GVarFlags))
9896 switch (Lex.getKind()) {
9898 if (parseOptionalVTableFuncs(VTableFuncs))
9902 if (parseOptionalRefs(Refs))
9906 return error(Lex.getLoc(),
"expected optional variable summary field");
9914 std::make_unique<GlobalVarSummary>(GVFlags, GVarFlags, std::move(Refs));
9916 GS->setModulePath(ModulePath);
9917 GS->setVTableFuncs(std::move(VTableFuncs));
9919 return addGlobalValueToIndex(Name, GUID,
9921 std::move(GS), Loc);
9930 LocTy Loc = Lex.getLoc();
9933 StringRef ModulePath;
9934 GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
9937 false,
false,
false,
9941 parseModuleReference(ModulePath) ||
9942 parseToken(
lltok::comma,
"expected ',' here") || parseGVFlags(GVFlags) ||
9948 ValueInfo AliaseeVI;
9950 if (parseGVReference(AliaseeVI, GVId))
9956 auto AS = std::make_unique<AliasSummary>(GVFlags);
9958 AS->setModulePath(ModulePath);
9962 ForwardRefAliasees[GVId].emplace_back(AS.get(), Loc);
9964 auto Summary = Index->findSummaryInModule(AliaseeVI, ModulePath);
9965 assert(Summary &&
"Aliasee must be a definition");
9966 AS->setAliasee(AliaseeVI, Summary);
9969 return addGlobalValueToIndex(Name, GUID,
9971 std::move(AS), Loc);
9976bool LLParser::parseFlag(
unsigned &Val) {
9977 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
9978 return tokError(
"expected integer");
9979 Val = (unsigned)Lex.getAPSIntVal().getBoolValue();
9995bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) {
9999 if (parseToken(
lltok::colon,
"expected ':' in funcFlags") ||
10005 switch (Lex.getKind()) {
10008 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10014 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10020 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10026 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10032 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10038 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10044 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10050 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10056 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10062 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Val))
10067 return error(Lex.getLoc(),
"expected function flag type");
10071 if (parseToken(
lltok::rparen,
"expected ')' in funcFlags"))
10082bool LLParser::parseOptionalCalls(
10083 SmallVectorImpl<FunctionSummary::EdgeTy> &Calls) {
10087 if (parseToken(
lltok::colon,
"expected ':' in calls") ||
10091 IdToIndexMapType IdToIndexMap;
10100 LocTy Loc = Lex.getLoc();
10102 if (parseGVReference(VI, GVId))
10106 unsigned RelBF = 0;
10107 unsigned HasTailCall =
false;
10111 switch (Lex.getKind()) {
10114 if (parseToken(
lltok::colon,
"expected ':'") || parseHotness(Hotness))
10119 if (parseToken(
lltok::colon,
"expected ':'") || parseUInt32(RelBF))
10124 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(HasTailCall))
10128 return error(Lex.getLoc(),
"expected hotness, relbf, or tail");
10132 return tokError(
"Expected only one of hotness or relbf");
10137 IdToIndexMap[GVId].push_back(std::make_pair(Calls.
size(), Loc));
10147 for (
auto I : IdToIndexMap) {
10148 auto &Infos = ForwardRefValueInfos[
I.first];
10149 for (
auto P :
I.second) {
10151 "Forward referenced ValueInfo expected to be empty");
10152 Infos.emplace_back(&Calls[
P.first].first,
P.second);
10165 switch (Lex.getKind()) {
10169 case lltok::kw_cold:
10175 case lltok::kw_hot:
10182 return error(Lex.getLoc(),
"invalid call edge hotness");
10191bool LLParser::parseOptionalVTableFuncs(
VTableFuncList &VTableFuncs) {
10195 if (parseToken(
lltok::colon,
"expected ':' in vTableFuncs") ||
10199 IdToIndexMapType IdToIndexMap;
10203 if (parseToken(
lltok::lparen,
"expected '(' in vTableFunc") ||
10208 LocTy Loc = Lex.getLoc();
10210 if (parseGVReference(VI, GVId))
10223 IdToIndexMap[GVId].push_back(std::make_pair(VTableFuncs.size(), Loc));
10224 VTableFuncs.push_back({
VI,
Offset});
10226 if (parseToken(
lltok::rparen,
"expected ')' in vTableFunc"))
10232 for (
auto I : IdToIndexMap) {
10233 auto &Infos = ForwardRefValueInfos[
I.first];
10234 for (
auto P :
I.second) {
10236 "Forward referenced ValueInfo expected to be empty");
10237 Infos.emplace_back(&VTableFuncs[
P.first].FuncVI,
P.second);
10241 if (parseToken(
lltok::rparen,
"expected ')' in vTableFuncs"))
10248bool LLParser::parseParamNo(uint64_t &ParamNo) {
10250 parseToken(
lltok::colon,
"expected ':' here") || parseUInt64(ParamNo))
10256bool LLParser::parseParamAccessOffset(ConstantRange &
Range) {
10259 auto ParseAPSInt = [&](
APSInt &Val) {
10261 return tokError(
"expected integer");
10262 Val = Lex.getAPSIntVal();
10264 Val.setIsSigned(
true);
10286bool LLParser::parseParamAccessCall(FunctionSummary::ParamAccess::Call &
Call,
10287 IdLocListType &IdLocList) {
10295 LocTy Loc = Lex.getLoc();
10296 if (parseGVReference(VI, GVId))
10300 IdLocList.emplace_back(GVId, Loc);
10303 parseParamNo(
Call.ParamNo) ||
10305 parseParamAccessOffset(
Call.Offsets))
10317bool LLParser::parseParamAccess(FunctionSummary::ParamAccess &Param,
10318 IdLocListType &IdLocList) {
10320 parseParamNo(
Param.ParamNo) ||
10322 parseParamAccessOffset(
Param.Use))
10331 FunctionSummary::ParamAccess::Call
Call;
10332 if (parseParamAccessCall(
Call, IdLocList))
10349bool LLParser::parseOptionalParamAccesses(
10350 std::vector<FunctionSummary::ParamAccess> &Params) {
10358 IdLocListType VContexts;
10359 size_t CallsNum = 0;
10361 FunctionSummary::ParamAccess ParamAccess;
10362 if (parseParamAccess(ParamAccess, VContexts))
10364 CallsNum += ParamAccess.
Calls.size();
10365 assert(VContexts.size() == CallsNum);
10367 Params.emplace_back(std::move(ParamAccess));
10375 IdLocListType::const_iterator ItContext = VContexts.begin();
10376 for (
auto &PA : Params) {
10377 for (
auto &
C : PA.Calls) {
10379 ForwardRefValueInfos[ItContext->first].emplace_back(&
C.Callee,
10380 ItContext->second);
10384 assert(ItContext == VContexts.end());
10391bool LLParser::parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs) {
10395 if (parseToken(
lltok::colon,
"expected ':' in refs") ||
10399 struct ValueContext {
10404 std::vector<ValueContext> VContexts;
10408 VC.Loc = Lex.getLoc();
10409 if (parseGVReference(
VC.VI,
VC.GVId))
10411 VContexts.push_back(VC);
10417 llvm::sort(VContexts, [](
const ValueContext &VC1,
const ValueContext &VC2) {
10418 return VC1.VI.getAccessSpecifier() < VC2.VI.getAccessSpecifier();
10421 IdToIndexMapType IdToIndexMap;
10422 for (
auto &VC : VContexts) {
10427 IdToIndexMap[
VC.GVId].push_back(std::make_pair(Refs.
size(),
VC.Loc));
10433 for (
auto I : IdToIndexMap) {
10434 auto &Infos = ForwardRefValueInfos[
I.first];
10435 for (
auto P :
I.second) {
10437 "Forward referenced ValueInfo expected to be empty");
10438 Infos.emplace_back(&Refs[
P.first],
P.second);
10452bool LLParser::parseOptionalTypeIdInfo(
10453 FunctionSummary::TypeIdInfo &TypeIdInfo) {
10462 switch (Lex.getKind()) {
10464 if (parseTypeTests(TypeIdInfo.
TypeTests))
10488 return error(Lex.getLoc(),
"invalid typeIdInfo list type");
10492 if (parseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
10501bool LLParser::parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests) {
10509 IdToIndexMapType IdToIndexMap;
10513 unsigned ID = Lex.getUIntVal();
10514 LocTy Loc = Lex.getLoc();
10518 IdToIndexMap[
ID].push_back(std::make_pair(TypeTests.size(), Loc));
10520 }
else if (parseUInt64(GUID))
10522 TypeTests.push_back(GUID);
10527 for (
auto I : IdToIndexMap) {
10528 auto &Ids = ForwardRefTypeIds[
I.first];
10529 for (
auto P :
I.second) {
10530 assert(TypeTests[
P.first] == 0 &&
10531 "Forward referenced type id GUID expected to be 0");
10532 Ids.emplace_back(&TypeTests[
P.first],
P.second);
10536 if (parseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
10544bool LLParser::parseVFuncIdList(
10545 lltok::Kind Kind, std::vector<FunctionSummary::VFuncId> &VFuncIdList) {
10546 assert(Lex.getKind() == Kind);
10553 IdToIndexMapType IdToIndexMap;
10555 FunctionSummary::VFuncId VFuncId;
10556 if (parseVFuncId(VFuncId, IdToIndexMap, VFuncIdList.size()))
10558 VFuncIdList.push_back(VFuncId);
10566 for (
auto I : IdToIndexMap) {
10567 auto &Ids = ForwardRefTypeIds[
I.first];
10568 for (
auto P :
I.second) {
10569 assert(VFuncIdList[
P.first].GUID == 0 &&
10570 "Forward referenced type id GUID expected to be 0");
10571 Ids.emplace_back(&VFuncIdList[
P.first].GUID,
P.second);
10580bool LLParser::parseConstVCallList(
10582 std::vector<FunctionSummary::ConstVCall> &ConstVCallList) {
10583 assert(Lex.getKind() == Kind);
10590 IdToIndexMapType IdToIndexMap;
10592 FunctionSummary::ConstVCall ConstVCall;
10593 if (parseConstVCall(ConstVCall, IdToIndexMap, ConstVCallList.size()))
10595 ConstVCallList.push_back(ConstVCall);
10603 for (
auto I : IdToIndexMap) {
10604 auto &Ids = ForwardRefTypeIds[
I.first];
10605 for (
auto P :
I.second) {
10606 assert(ConstVCallList[
P.first].VFunc.GUID == 0 &&
10607 "Forward referenced type id GUID expected to be 0");
10608 Ids.emplace_back(&ConstVCallList[
P.first].VFunc.GUID,
P.second);
10617bool LLParser::parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
10618 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
10620 parseVFuncId(ConstVCall.
VFunc, IdToIndexMap, Index))
10624 if (parseArgs(ConstVCall.
Args))
10636bool LLParser::parseVFuncId(FunctionSummary::VFuncId &VFuncId,
10637 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
10647 unsigned ID = Lex.getUIntVal();
10648 LocTy Loc = Lex.getLoc();
10652 IdToIndexMap[
ID].push_back(std::make_pair(Index, Loc));
10654 }
else if (parseToken(
lltok::kw_guid,
"expected 'guid' here") ||
10656 parseUInt64(VFuncId.
GUID))
10662 parseUInt64(VFuncId.
Offset) ||
10674bool LLParser::parseGVFlags(GlobalValueSummary::GVFlags &GVFlags) {
10684 switch (Lex.getKind()) {
10691 assert(HasLinkage &&
"Linkage not optional in summary entry");
10698 parseOptionalVisibility(Flag);
10703 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10709 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10715 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10721 if (parseToken(
lltok::colon,
"expected ':'") || parseFlag(Flag))
10730 if (parseOptionalImportType(Lex.getKind(), IK))
10732 GVFlags.
ImportType =
static_cast<unsigned>(IK);
10736 return error(Lex.getLoc(),
"expected gv flag type");
10750bool LLParser::parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags) {
10758 auto ParseRest = [
this](
unsigned int &Val) {
10762 return parseFlag(Val);
10767 switch (Lex.getKind()) {
10768 case lltok::kw_readonly:
10769 if (ParseRest(Flag))
10773 case lltok::kw_writeonly:
10774 if (ParseRest(Flag))
10779 if (ParseRest(Flag))
10784 if (ParseRest(Flag))
10789 return error(Lex.getLoc(),
"expected gvar flag type");
10797bool LLParser::parseModuleReference(StringRef &ModulePath) {
10804 unsigned ModuleID = Lex.getUIntVal();
10805 auto I = ModuleIdMap.find(ModuleID);
10807 assert(
I != ModuleIdMap.end());
10808 ModulePath =
I->second;
10814bool LLParser::parseGVReference(ValueInfo &VI,
unsigned &GVId) {
10817 WriteOnly = EatIfPresent(lltok::kw_writeonly);
10821 GVId = Lex.getUIntVal();
10823 if (GVId < NumberedValueInfos.size() && NumberedValueInfos[GVId]) {
10825 VI = NumberedValueInfos[GVId];
10842bool LLParser::parseOptionalAllocs(std::vector<AllocInfo> &Allocs) {
10846 if (parseToken(
lltok::colon,
"expected ':' in allocs") ||
10858 SmallVector<uint8_t> Versions;
10861 if (parseAllocType(V))
10866 if (parseToken(
lltok::rparen,
"expected ')' in versions") ||
10870 std::vector<MIBInfo> MIBs;
10871 if (parseMemProfs(MIBs))
10874 Allocs.push_back({Versions, MIBs});
10891bool LLParser::parseMemProfs(std::vector<MIBInfo> &MIBs) {
10895 if (parseToken(
lltok::colon,
"expected ':' in memprof") ||
10901 if (parseToken(
lltok::lparen,
"expected '(' in memprof") ||
10910 if (parseToken(
lltok::comma,
"expected ',' in memprof") ||
10916 SmallVector<unsigned> StackIdIndices;
10920 uint64_t StackId = 0;
10921 if (parseUInt64(StackId))
10923 StackIdIndices.
push_back(Index->addOrGetStackIdIndex(StackId));
10944bool LLParser::parseAllocType(uint8_t &
AllocType) {
10945 switch (Lex.getKind()) {
10952 case lltok::kw_cold:
10955 case lltok::kw_hot:
10959 return error(Lex.getLoc(),
"invalid alloc type");
10972bool LLParser::parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites) {
10976 if (parseToken(
lltok::colon,
"expected ':' in callsites") ||
10980 IdToIndexMapType IdToIndexMap;
10983 if (parseToken(
lltok::lparen,
"expected '(' in callsite") ||
10990 LocTy Loc = Lex.getLoc();
10992 if (parseGVReference(VI, GVId))
10996 if (parseToken(
lltok::comma,
"expected ',' in callsite") ||
11002 SmallVector<unsigned> Clones;
11005 if (parseUInt32(V))
11011 parseToken(
lltok::comma,
"expected ',' in callsite") ||
11017 SmallVector<unsigned> StackIdIndices;
11021 uint64_t StackId = 0;
11022 if (parseUInt64(StackId))
11024 StackIdIndices.
push_back(Index->addOrGetStackIdIndex(StackId));
11035 IdToIndexMap[GVId].
push_back(std::make_pair(Callsites.size(), Loc));
11036 Callsites.push_back({
VI, Clones, StackIdIndices});
11044 for (
auto I : IdToIndexMap) {
11045 auto &Infos = ForwardRefValueInfos[
I.first];
11046 for (
auto P :
I.second) {
11048 "Forward referenced ValueInfo expected to be empty");
11049 Infos.emplace_back(&Callsites[
P.first].Callee,
P.second);
11053 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 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 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.
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.
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.
@ 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 ...
static LLVM_ABI const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI const fltSemantics & IEEEdouble() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEhalf() LLVM_READNONE
static LLVM_ABI const fltSemantics & BFloat() LLVM_READNONE
std::vector< uint64_t > Args
unsigned ReturnDoesNotAlias
unsigned MustBeUnreachable
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
static constexpr uint32_t RangeWidth
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.