133 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
135 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
136 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
139 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
140 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
144 std::map<std::string, LocTy> ForwardRefComdats;
148 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
149 class PerFunctionState;
153 PerFunctionState *BlockAddressPFS;
160 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
161 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
164 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
165 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
168 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
169 ForwardRefValueInfos;
170 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
172 std::vector<ValueInfo> NumberedValueInfos;
175 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
179 std::map<unsigned, StringRef> ModuleIdMap;
190 bool UpgradeDebugInfo;
192 bool SeenNewDbgInfoFormat =
false;
193 bool SeenOldDbgInfoFormat =
false;
195 std::string SourceFileName;
197 FileLoc getTokLineColumnPos() {
199 return Lex.getTokLineColumnPos();
203 FileLoc getPrevTokEndLineColumnPos() {
214 : Context(Context), OPLex(
F,
SM, Err, Context),
215 Lex(
F,
SM, Err, Context), M(M), Index(Index), Slots(Slots),
216 BlockAddressPFS(nullptr), ParserContext(ParserContext) {}
226 const SlotMapping *Slots);
229 const SlotMapping *Slots);
235 bool tokError(
const Twine &Msg) {
return error(Lex.
getLoc(), Msg); }
237 bool checkValueID(
LocTy L, StringRef Kind, StringRef Prefix,
238 unsigned NextID,
unsigned ID);
242 void restoreParsingState(
const SlotMapping *Slots);
247 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
248 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
252 Comdat *getComdat(
const std::string &Name,
LocTy Loc);
257 if (Lex.getKind() !=
T)
return false;
262 FastMathFlags EatFastMathFlagsIfPresent() {
265 switch (Lex.getKind()) {
269 case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex();
continue;
270 case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex();
continue;
272 FMF.setAllowContract(
true);
276 case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex();
continue;
283 LocTy *Loc =
nullptr) {
284 if (Lex.getKind() !=
T) {
294 bool parseStringConstant(std::string &Result);
295 bool parseUInt32(
unsigned &Val);
296 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
298 return parseUInt32(Val);
300 bool parseUInt64(uint64_t &Val);
301 bool parseUInt64(uint64_t &Val,
LocTy &Loc) {
303 return parseUInt64(Val);
305 bool parseFlag(
unsigned &Val);
307 bool parseStringAttribute(AttrBuilder &
B);
312 bool parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
313 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
314 return parseOptionalAddrSpace(
315 AddrSpace, M->getDataLayout().getProgramAddressSpace());
319 bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
320 bool parseOptionalParamAttrs(AttrBuilder &
B) {
321 return parseOptionalParamOrReturnAttrs(
B,
true);
323 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
324 return parseOptionalParamOrReturnAttrs(
B,
false);
326 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
327 unsigned &Visibility,
unsigned &DLLStorageClass,
329 void parseOptionalDSOLocal(
bool &DSOLocal);
330 void parseOptionalVisibility(
unsigned &Res);
333 void parseOptionalDLLStorageClass(
unsigned &Res);
334 bool parseOptionalCallingConv(
unsigned &CC);
335 bool parseOptionalAlignment(MaybeAlign &Alignment,
336 bool AllowParens =
false);
337 bool parseOptionalPrefAlignment(MaybeAlign &Alignment);
340 std::optional<uint64_t> &Bytes,
341 bool ErrorNoBytes =
true);
344 std::optional<MemoryEffects> parseMemoryAttr();
345 std::optional<DenormalMode> parseDenormalFPEnvEntry();
346 std::optional<DenormalFPEnv> parseDenormalFPEnvAttr();
347 unsigned parseNoFPClassAttr();
348 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
352 bool parseOptionalStackAlignment(
unsigned &Alignment);
353 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
354 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
355 bool &AteExtraComma);
356 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
357 std::optional<unsigned> &HowManyArg);
358 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
359 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
360 bool &AteExtraComma);
361 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
363 if (parseIndexList(Indices, AteExtraComma))
366 return tokError(
"expected index");
371 bool parseTopLevelEntities();
372 void dropUnknownMetadataReferences();
373 bool validateEndOfModule(
bool UpgradeDebugInfo);
374 bool validateEndOfIndex();
376 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
377 bool parseModuleAsm();
378 bool parseSourceFileName();
379 bool parseUnnamedType();
380 bool parseNamedType();
384 bool parseGlobalType(
bool &IsConstant);
385 bool parseUnnamedGlobal();
386 bool parseNamedGlobal();
387 bool parseGlobal(
const std::string &Name,
unsigned NameID,
LocTy NameLoc,
388 unsigned Linkage,
bool HasLinkage,
unsigned Visibility,
389 unsigned DLLStorageClass,
bool DSOLocal,
392 bool parseAliasOrIFunc(
const std::string &Name,
unsigned NameID,
393 LocTy NameLoc,
unsigned L,
unsigned Visibility,
394 unsigned DLLStorageClass,
bool DSOLocal,
398 bool parseStandaloneMetadata();
399 bool parseNamedMetadata();
400 bool parseMDString(MDString *&Result);
401 bool parseMDNodeID(MDNode *&Result);
402 bool parseUnnamedAttrGrp();
403 bool parseFnAttributeValuePairs(AttrBuilder &
B,
404 std::vector<unsigned> &FwdRefAttrGrps,
405 bool inAttrGrp,
LocTy &BuiltinLoc);
406 bool parseRangeAttr(AttrBuilder &
B);
407 bool parseInitializesAttr(AttrBuilder &
B);
408 bool parseCapturesAttr(AttrBuilder &
B);
409 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
413 bool skipModuleSummaryEntry();
414 bool parseSummaryEntry();
415 bool parseModuleEntry(
unsigned ID);
416 bool parseModuleReference(StringRef &ModulePath);
417 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
418 bool parseSummaryIndexFlags();
419 bool parseBlockCount();
420 bool parseGVEntry(
unsigned ID);
424 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
425 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
426 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
427 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
429 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
430 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
432 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
433 bool parseConstVCallList(
435 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
436 using IdToIndexMapType =
437 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
438 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
439 IdToIndexMapType &IdToIndexMap,
unsigned Index);
440 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
441 IdToIndexMapType &IdToIndexMap,
unsigned Index);
443 bool parseOptionalParamAccesses(
444 std::vector<FunctionSummary::ParamAccess> &Params);
445 bool parseParamNo(uint64_t &ParamNo);
446 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
447 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
448 IdLocListType &IdLocList);
449 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &
Call,
450 IdLocListType &IdLocList);
451 bool parseParamAccessOffset(ConstantRange &
Range);
452 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
453 bool parseTypeIdEntry(
unsigned ID);
454 bool parseTypeIdSummary(TypeIdSummary &TIS);
455 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
456 bool parseTypeTestResolution(TypeTestResolution &TTRes);
457 bool parseOptionalWpdResolutions(
458 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
459 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
460 bool parseOptionalResByArg(
461 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
463 bool parseArgs(std::vector<uint64_t> &Args);
466 std::unique_ptr<GlobalValueSummary> Summary,
468 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
469 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
471 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
474 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
475 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
476 return parseType(Result,
"expected type", AllowVoid);
478 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
479 bool AllowVoid =
false) {
481 return parseType(Result, Msg, AllowVoid);
483 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
485 return parseType(Result, AllowVoid);
487 bool parseAnonStructType(
Type *&Result,
bool Packed);
488 bool parseStructBody(SmallVectorImpl<Type *> &Body);
489 bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
490 std::pair<Type *, LocTy> &Entry,
493 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
494 bool parseFunctionType(
Type *&Result);
495 bool parseTargetExtType(
Type *&Result);
498 class PerFunctionState {
501 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
502 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
503 NumberedValues<Value *> NumberedVals;
510 PerFunctionState(
LLParser &p, Function &f,
int functionNumber,
511 ArrayRef<unsigned> UnnamedArgNums);
514 Function &getFunction()
const {
return F; }
516 bool finishFunction();
526 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
540 bool resolveForwardRefBlockAddresses();
543 bool convertValIDToValue(
Type *Ty, ValID &
ID,
Value *&V,
544 PerFunctionState *PFS);
546 Value *checkValidVariableType(
LocTy Loc,
const Twine &Name,
Type *Ty,
549 bool parseConstantValue(
Type *Ty, Constant *&
C);
550 bool parseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS);
551 bool parseValue(
Type *Ty,
Value *&V, PerFunctionState &PFS) {
552 return parseValue(Ty, V, &PFS);
555 bool parseValue(
Type *Ty,
Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
557 return parseValue(Ty, V, &PFS);
560 bool parseTypeAndValue(
Value *&V, PerFunctionState *PFS);
561 bool parseTypeAndValue(
Value *&V, PerFunctionState &PFS) {
562 return parseTypeAndValue(V, &PFS);
564 bool parseTypeAndValue(
Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
566 return parseTypeAndValue(V, PFS);
568 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
569 PerFunctionState &PFS);
570 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
572 return parseTypeAndBasicBlock(BB, Loc, PFS);
579 ParamInfo(
LocTy loc,
Value *v, AttributeSet attrs)
580 : Loc(loc), V(
v), Attrs(attrs) {}
582 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
583 PerFunctionState &PFS,
bool IsMustTailCall =
false,
584 bool InVarArgsFunc =
false);
587 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
588 PerFunctionState &PFS);
590 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
591 PerFunctionState &PFS);
594 FunctionType *&FuncTy);
597 bool parseValID(ValID &
ID, PerFunctionState *PFS,
598 Type *ExpectedTy =
nullptr);
599 bool parseGlobalValue(
Type *Ty, Constant *&
C);
600 bool parseGlobalTypeAndValue(Constant *&V);
601 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
602 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
603 bool parseSanitizer(GlobalVariable *GV);
604 bool parseMetadataAsValue(
Value *&V, PerFunctionState &PFS);
605 bool parseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
606 PerFunctionState *PFS);
607 bool parseDIArgList(
Metadata *&MD, PerFunctionState *PFS);
608 bool parseMetadata(
Metadata *&MD, PerFunctionState *PFS);
609 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
610 bool parseMDNode(MDNode *&
N);
611 bool parseMDNodeTail(MDNode *&
N);
612 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
613 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
614 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
615 bool parseInstructionMetadata(Instruction &Inst);
616 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
617 bool parseOptionalFunctionMetadata(Function &
F);
619 template <
class FieldTy>
620 bool parseMDField(
LocTy Loc, StringRef Name, FieldTy &Result);
621 template <
class FieldTy>
bool parseMDField(StringRef Name, FieldTy &Result);
622 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
623 template <
class ParserTy>
624 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
625 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
626 bool parseDIExpressionBody(MDNode *&Result,
bool IsDistinct);
628#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
629 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
630#include "llvm/IR/Metadata.def"
636 std::optional<FileLocRange> IdentLoc;
639 ArgInfo(
LocTy L, Type *ty, std::optional<FileLocRange> IdentLoc,
640 AttributeSet Attr,
const std::string &
N)
641 : Loc(L), Ty(ty), IdentLoc(IdentLoc), Attrs(Attr), Name(
N) {}
643 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
644 SmallVectorImpl<unsigned> &UnnamedArgNums,
646 bool parseFunctionHeader(Function *&Fn,
bool IsDefine,
647 unsigned &FunctionNumber,
648 SmallVectorImpl<unsigned> &UnnamedArgNums);
649 bool parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
650 ArrayRef<unsigned> UnnamedArgNums);
651 bool parseBasicBlock(PerFunctionState &PFS);
653 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
657 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
658 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
659 PerFunctionState &PFS);
660 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
662 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
663 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
664 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
665 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
666 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
667 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
668 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
669 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
670 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
671 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
672 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
673 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
675 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
677 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
678 unsigned Opc,
bool IsFP);
679 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
680 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
681 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
682 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
683 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
684 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
685 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
686 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
687 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
688 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
689 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
691 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
692 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
693 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
694 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
695 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
696 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
697 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
698 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
699 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
700 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
703 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
704 bool parseUseListOrderBB();
705 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
706 bool sortUseListOrder(
Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);