132 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
134 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
135 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
138 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
139 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
143 std::map<std::string, LocTy> ForwardRefComdats;
147 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
148 class PerFunctionState;
152 PerFunctionState *BlockAddressPFS;
159 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
160 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
163 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
164 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
167 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
168 ForwardRefValueInfos;
169 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
171 std::vector<ValueInfo> NumberedValueInfos;
174 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
178 std::map<unsigned, StringRef> ModuleIdMap;
199 bool SeenNewDbgInfoFormat =
false;
200 bool SeenOldDbgInfoFormat =
false;
202 std::string SourceFileName;
204 FileLoc getTokLineColumnPos() {
206 return Lex.getTokLineColumnPos();
210 FileLoc getPrevTokEndLineColumnPos() {
221 : Context(Context), OPLex(
F, SM, Err, Context),
222 Lex(
F, SM, Err, Context), M(M), Index(Index), Slots(Slots),
223 BlockAddressPFS(nullptr), ParserContext(ParserContext) {}
231 const SlotMapping *Slots);
234 const SlotMapping *Slots);
238 const SlotMapping *Slots);
249 bool checkValueID(
LocTy L, StringRef Kind, StringRef Prefix,
250 unsigned NextID,
unsigned ID);
254 void restoreParsingState(
const SlotMapping *Slots);
259 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
260 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
264 Comdat *getComdat(
const std::string &Name,
LocTy Loc);
269 if (Lex.getKind() !=
T)
return false;
274 FastMathFlags EatFastMathFlagsIfPresent() {
277 switch (Lex.getKind()) {
281 case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex();
continue;
282 case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex();
continue;
284 FMF.setAllowContract(
true);
288 case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex();
continue;
295 LocTy *Loc =
nullptr) {
296 if (Lex.getKind() !=
T) {
306 bool parseStringConstant(std::string &Result);
307 LLVM_ABI bool parseUInt32(
unsigned &Val);
308 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
310 return parseUInt32(Val);
315 return parseUInt64(Val);
317 bool parseFlag(
unsigned &Val);
319 bool parseStringAttribute(AttrBuilder &
B);
324 LLVM_ABI bool parseOptionalAddrSpace(
unsigned &AddrSpace,
325 unsigned DefaultAS = 0);
326 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
327 return parseOptionalAddrSpace(
328 AddrSpace, M->getDataLayout().getProgramAddressSpace());
332 LLVM_ABI bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
333 bool parseOptionalParamAttrs(AttrBuilder &
B) {
334 return parseOptionalParamOrReturnAttrs(
B,
true);
336 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
337 return parseOptionalParamOrReturnAttrs(
B,
false);
339 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
340 unsigned &Visibility,
unsigned &DLLStorageClass,
342 void parseOptionalDSOLocal(
bool &DSOLocal);
343 void parseOptionalVisibility(
unsigned &Res);
346 void parseOptionalDLLStorageClass(
unsigned &Res);
347 bool parseOptionalCallingConv(
unsigned &
CC);
348 bool parseOptionalAlignment(MaybeAlign &Alignment,
349 bool AllowParens =
false);
350 bool parseOptionalPrefAlignment(MaybeAlign &Alignment);
353 std::optional<uint64_t> &Bytes,
354 bool ErrorNoBytes =
true);
357 std::optional<MemoryEffects> parseMemoryAttr();
358 std::optional<DenormalMode> parseDenormalFPEnvEntry();
359 std::optional<DenormalFPEnv> parseDenormalFPEnvAttr();
360 unsigned parseNoFPClassAttr();
361 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
365 bool parseOptionalStackAlignment(
unsigned &Alignment);
366 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
367 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
368 bool &AteExtraComma);
369 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
370 std::optional<unsigned> &HowManyArg);
371 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
372 LLVM_ABI bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
373 bool &AteExtraComma);
374 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
376 if (parseIndexList(Indices, AteExtraComma))
379 return tokError(
"expected index");
384 bool parseTopLevelEntities();
385 void dropUnknownMetadataReferences();
387 bool validateEndOfIndex();
389 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
390 bool parseModuleAsm();
391 bool parseSourceFileName();
392 bool parseUnnamedType();
393 bool parseNamedType();
397 bool parseGlobalType(
bool &IsConstant);
398 bool parseUnnamedGlobal();
399 bool parseNamedGlobal();
400 bool parseGlobal(
const std::string &Name,
unsigned NameID,
LocTy NameLoc,
401 unsigned Linkage,
bool HasLinkage,
unsigned Visibility,
402 unsigned DLLStorageClass,
bool DSOLocal,
405 bool parseAliasOrIFunc(
const std::string &Name,
unsigned NameID,
406 LocTy NameLoc,
unsigned L,
unsigned Visibility,
407 unsigned DLLStorageClass,
bool DSOLocal,
411 bool parseStandaloneMetadata();
412 bool parseNamedMetadata();
413 bool parseMDString(MDString *&Result);
414 bool parseMDNodeID(MDNode *&Result);
415 bool parseUnnamedAttrGrp();
416 bool parseFnAttributeValuePairs(AttrBuilder &
B,
417 std::vector<unsigned> &FwdRefAttrGrps,
418 bool inAttrGrp,
LocTy &BuiltinLoc);
419 bool parseRangeAttr(AttrBuilder &
B);
420 bool parseInitializesAttr(AttrBuilder &
B);
421 bool parseCapturesAttr(AttrBuilder &
B);
422 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
426 bool skipModuleSummaryEntry();
427 bool parseSummaryEntry();
428 bool parseModuleEntry(
unsigned ID);
429 bool parseModuleReference(StringRef &ModulePath);
430 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
431 bool parseSummaryIndexFlags();
432 bool parseBlockCount();
433 bool parseCfiFunctions();
434 bool parseGVEntry(
unsigned ID);
438 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
439 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
440 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
441 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
443 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
444 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
446 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
447 bool parseConstVCallList(
449 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
450 using IdToIndexMapType =
451 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
452 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
453 IdToIndexMapType &IdToIndexMap,
unsigned Index);
454 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
455 IdToIndexMapType &IdToIndexMap,
unsigned Index);
457 bool parseOptionalParamAccesses(
458 std::vector<FunctionSummary::ParamAccess> &Params);
459 bool parseParamNo(
uint64_t &ParamNo);
460 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
461 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
462 IdLocListType &IdLocList);
463 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &
Call,
464 IdLocListType &IdLocList);
465 bool parseParamAccessOffset(ConstantRange &
Range);
466 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
467 bool parseTypeIdEntry(
unsigned ID);
468 bool parseTypeIdSummary(TypeIdSummary &TIS);
469 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
470 bool parseTypeTestResolution(TypeTestResolution &TTRes);
471 bool parseOptionalWpdResolutions(
472 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
473 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
474 bool parseOptionalResByArg(
475 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
477 bool parseArgs(std::vector<uint64_t> &Args);
480 std::unique_ptr<GlobalValueSummary> Summary,
482 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
483 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
484 bool parseAllocType(uint8_t &AllocType);
485 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
489 bool AllowVoid =
false);
490 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
491 return parseType(Result,
"expected type", AllowVoid);
493 bool parseType(
Type *&Result,
const Twine &
Msg,
LocTy &Loc,
494 bool AllowVoid =
false) {
496 return parseType(Result,
Msg, AllowVoid);
498 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
500 return parseType(Result, AllowVoid);
502 bool parseAnonStructType(
Type *&Result,
bool Packed);
503 bool parseStructBody(SmallVectorImpl<Type *> &Body);
504 bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
505 std::pair<Type *, LocTy> &Entry,
508 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
509 bool parseFunctionType(
Type *&Result);
510 bool parseTargetExtType(
Type *&Result);
513 class PerFunctionState {
516 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
517 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
518 NumberedValues<Value *> NumberedVals;
526 ArrayRef<unsigned> UnnamedArgNums);
529 Function &getFunction()
const {
return F; }
541 LLVM_ABI bool setInstName(
int NameID,
const std::string &NameStr,
542 LocTy NameLoc, Instruction *Inst);
556 LLVM_ABI bool resolveForwardRefBlockAddresses();
559 bool convertValIDToValue(
Type *Ty, ValID &ID,
Value *&
V,
560 PerFunctionState *PFS);
562 Value *checkValidVariableType(
LocTy Loc,
const Twine &Name,
Type *Ty,
565 bool parseConstantValue(
Type *Ty, Constant *&
C);
567 bool parseValue(
Type *Ty,
Value *&
V, PerFunctionState &PFS) {
568 return parseValue(Ty,
V, &PFS);
571 bool parseValue(
Type *Ty,
Value *&
V,
LocTy &Loc, PerFunctionState &PFS) {
573 return parseValue(Ty,
V, &PFS);
576 LLVM_ABI bool parseTypeAndValue(
Value *&
V, PerFunctionState *PFS);
577 bool parseTypeAndValue(
Value *&
V, PerFunctionState &PFS) {
578 return parseTypeAndValue(
V, &PFS);
580 bool parseTypeAndValue(
Value *&
V,
LocTy &Loc, PerFunctionState &PFS) {
582 return parseTypeAndValue(
V, PFS);
584 LLVM_ABI bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
585 PerFunctionState &PFS);
586 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
588 return parseTypeAndBasicBlock(BB, Loc, PFS);
595 ParamInfo(
LocTy loc,
Value *v, AttributeSet attrs)
596 : Loc(loc), V(
v), Attrs(attrs) {}
598 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
599 PerFunctionState &PFS,
bool IsMustTailCall =
false,
600 bool InVarArgsFunc =
false);
603 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
604 PerFunctionState &PFS);
606 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
607 PerFunctionState &PFS);
610 FunctionType *&FuncTy);
613 bool parseValID(ValID &ID, PerFunctionState *PFS,
614 Type *ExpectedTy =
nullptr);
615 bool parseGlobalValue(
Type *Ty, Constant *&
C);
616 bool parseGlobalTypeAndValue(Constant *&
V);
617 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
618 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
619 bool parseSanitizer(GlobalVariable *GV);
620 bool parseMetadataAsValue(
Value *&
V, PerFunctionState &PFS);
621 bool parseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
622 PerFunctionState *PFS);
623 bool parseDIArgList(
Metadata *&MD, PerFunctionState *PFS);
624 bool parseMetadata(
Metadata *&MD, PerFunctionState *PFS);
625 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
626 bool parseMDNode(MDNode *&
N);
627 bool parseMDNodeTail(MDNode *&
N);
628 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
629 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
630 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
631 bool parseInstructionMetadata(Instruction &Inst);
632 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
633 bool parseOptionalFunctionMetadata(
Function &
F);
635 bool parseFLMDEntry(
LocTy Loc, FLScope &Result, uint32_t Index,
636 MDFunctionLocalContext *Context);
637 bool parseFLMDEntry(
LocTy Loc, FLSrcLoc &Result, uint32_t Index,
638 MDFunctionLocalContext *Context);
639 bool parseFLMDEntry(
LocTy Loc, FLInlinedCall &Result, uint32_t Index,
640 MDFunctionLocalContext *Context);
641 template <
class FLMDTy>
642 bool parseFLMDStorage(
LocTy Loc, SmallVectorImpl<FLMDTy> &Result,
643 MDFunctionLocalContext *Context);
644 template <
class FieldTy>
645 bool parseMDField(
LocTy Loc, StringRef Name, FieldTy &Result);
646 template <
class FieldTy>
bool parseMDField(StringRef Name, FieldTy &Result);
647 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
648 template <
class ParserTy>
649 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
650 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
651 bool parseDIExpressionBody(MDNode *&Result,
bool IsDistinct);
653#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
654 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
655#include "llvm/IR/Metadata.def"
661 std::optional<FileLocRange> IdentLoc;
664 ArgInfo(
LocTy L, Type *ty, std::optional<FileLocRange> IdentLoc,
665 AttributeSet Attr,
const std::string &
N)
666 : Loc(L), Ty(ty), IdentLoc(IdentLoc), Attrs(Attr), Name(
N) {}
668 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
669 SmallVectorImpl<unsigned> &UnnamedArgNums,
671 bool parseFunctionHeader(
Function *&Fn,
bool IsDefine,
672 unsigned &FunctionNumber,
673 SmallVectorImpl<unsigned> &UnnamedArgNums);
674 bool parseFunctionBody(
Function &Fn,
unsigned FunctionNumber,
675 ArrayRef<unsigned> UnnamedArgNums);
676 bool parseBasicBlock(PerFunctionState &PFS);
678 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
682 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
683 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
684 PerFunctionState &PFS);
685 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
687 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
688 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
689 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
690 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
691 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
692 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
693 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
694 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
695 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
696 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
697 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
698 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
700 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
702 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
703 unsigned Opc,
bool IsFP);
704 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
705 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
706 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
707 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
708 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
709 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
710 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
711 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
712 bool parseBitExtract(Instruction *&Inst, PerFunctionState &PFS);
713 bool parseBitInsert(Instruction *&Inst, PerFunctionState &PFS);
714 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
715 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
716 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
718 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
719 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
720 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
721 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
722 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
723 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
724 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
725 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
726 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
727 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
730 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
731 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
732 bool sortUseListOrder(
Value *
V, ArrayRef<unsigned> Indexes, SMLoc Loc);