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;
186 bool UpgradeDebugInfo;
188 bool SeenNewDbgInfoFormat =
false;
189 bool SeenOldDbgInfoFormat =
false;
191 std::string SourceFileName;
198 : Context(Context), OPLex(
F, SM, Err, Context),
199 Lex(
F, SM, Err, Context), M(M), Index(Index), Slots(Slots),
200 BlockAddressPFS(nullptr), ParserContext(ParserContext) {}
210 const SlotMapping *Slots);
213 const SlotMapping *Slots);
219 bool tokError(
const Twine &Msg) {
return error(Lex.
getLoc(), Msg); }
221 bool checkValueID(
LocTy L, StringRef Kind, StringRef Prefix,
222 unsigned NextID,
unsigned ID);
226 void restoreParsingState(
const SlotMapping *Slots);
231 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
232 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
236 Comdat *getComdat(
const std::string &Name,
LocTy Loc);
241 if (Lex.getKind() !=
T)
return false;
246 FastMathFlags EatFastMathFlagsIfPresent() {
249 switch (Lex.getKind()) {
253 case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex();
continue;
254 case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex();
continue;
256 FMF.setAllowContract(
true);
260 case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex();
continue;
267 LocTy *Loc =
nullptr) {
268 if (Lex.getKind() !=
T) {
278 bool parseStringConstant(std::string &Result);
279 bool parseUInt32(
unsigned &Val);
280 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
282 return parseUInt32(Val);
284 bool parseUInt64(uint64_t &Val);
285 bool parseUInt64(uint64_t &Val,
LocTy &Loc) {
287 return parseUInt64(Val);
289 bool parseFlag(
unsigned &Val);
291 bool parseStringAttribute(AttrBuilder &
B);
296 bool parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
297 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
298 return parseOptionalAddrSpace(
299 AddrSpace, M->getDataLayout().getProgramAddressSpace());
303 bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
304 bool parseOptionalParamAttrs(AttrBuilder &
B) {
305 return parseOptionalParamOrReturnAttrs(
B,
true);
307 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
308 return parseOptionalParamOrReturnAttrs(
B,
false);
310 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
311 unsigned &Visibility,
unsigned &DLLStorageClass,
313 void parseOptionalDSOLocal(
bool &DSOLocal);
314 void parseOptionalVisibility(
unsigned &Res);
317 void parseOptionalDLLStorageClass(
unsigned &Res);
318 bool parseOptionalCallingConv(
unsigned &CC);
319 bool parseOptionalAlignment(MaybeAlign &Alignment,
320 bool AllowParens =
false);
323 std::optional<uint64_t> &Bytes,
324 bool ErrorNoBytes =
true);
327 std::optional<MemoryEffects> parseMemoryAttr();
328 unsigned parseNoFPClassAttr();
329 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
333 bool parseOptionalStackAlignment(
unsigned &Alignment);
334 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
335 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
336 bool &AteExtraComma);
337 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
338 std::optional<unsigned> &HowManyArg);
339 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
340 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
341 bool &AteExtraComma);
342 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
344 if (parseIndexList(Indices, AteExtraComma))
347 return tokError(
"expected index");
352 bool parseTopLevelEntities();
353 void dropUnknownMetadataReferences();
354 bool validateEndOfModule(
bool UpgradeDebugInfo);
355 bool validateEndOfIndex();
357 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
358 bool parseModuleAsm();
359 bool parseSourceFileName();
360 bool parseUnnamedType();
361 bool parseNamedType();
365 bool parseGlobalType(
bool &IsConstant);
366 bool parseUnnamedGlobal();
367 bool parseNamedGlobal();
368 bool parseGlobal(
const std::string &Name,
unsigned NameID,
LocTy NameLoc,
369 unsigned Linkage,
bool HasLinkage,
unsigned Visibility,
370 unsigned DLLStorageClass,
bool DSOLocal,
373 bool parseAliasOrIFunc(
const std::string &Name,
unsigned NameID,
374 LocTy NameLoc,
unsigned L,
unsigned Visibility,
375 unsigned DLLStorageClass,
bool DSOLocal,
379 bool parseStandaloneMetadata();
380 bool parseNamedMetadata();
381 bool parseMDString(MDString *&Result);
382 bool parseMDNodeID(MDNode *&Result);
383 bool parseUnnamedAttrGrp();
384 bool parseFnAttributeValuePairs(AttrBuilder &
B,
385 std::vector<unsigned> &FwdRefAttrGrps,
386 bool inAttrGrp,
LocTy &BuiltinLoc);
387 bool parseRangeAttr(AttrBuilder &
B);
388 bool parseInitializesAttr(AttrBuilder &
B);
389 bool parseCapturesAttr(AttrBuilder &
B);
390 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
394 bool skipModuleSummaryEntry();
395 bool parseSummaryEntry();
396 bool parseModuleEntry(
unsigned ID);
397 bool parseModuleReference(StringRef &ModulePath);
398 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
399 bool parseSummaryIndexFlags();
400 bool parseBlockCount();
401 bool parseGVEntry(
unsigned ID);
405 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
406 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
407 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
408 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
410 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
411 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
413 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
414 bool parseConstVCallList(
416 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
417 using IdToIndexMapType =
418 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
419 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
420 IdToIndexMapType &IdToIndexMap,
unsigned Index);
421 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
422 IdToIndexMapType &IdToIndexMap,
unsigned Index);
424 bool parseOptionalParamAccesses(
425 std::vector<FunctionSummary::ParamAccess> &Params);
426 bool parseParamNo(uint64_t &ParamNo);
427 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
428 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
429 IdLocListType &IdLocList);
430 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &
Call,
431 IdLocListType &IdLocList);
432 bool parseParamAccessOffset(ConstantRange &
Range);
433 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
434 bool parseTypeIdEntry(
unsigned ID);
435 bool parseTypeIdSummary(TypeIdSummary &TIS);
436 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
437 bool parseTypeTestResolution(TypeTestResolution &TTRes);
438 bool parseOptionalWpdResolutions(
439 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
440 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
441 bool parseOptionalResByArg(
442 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
444 bool parseArgs(std::vector<uint64_t> &Args);
447 std::unique_ptr<GlobalValueSummary> Summary,
449 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
450 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
452 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
455 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
456 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
457 return parseType(Result,
"expected type", AllowVoid);
459 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
460 bool AllowVoid =
false) {
462 return parseType(Result, Msg, AllowVoid);
464 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
466 return parseType(Result, AllowVoid);
468 bool parseAnonStructType(
Type *&Result,
bool Packed);
469 bool parseStructBody(SmallVectorImpl<Type *> &Body);
470 bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
471 std::pair<Type *, LocTy> &Entry,
474 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
475 bool parseFunctionType(
Type *&Result);
476 bool parseTargetExtType(
Type *&Result);
479 class PerFunctionState {
482 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
483 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
484 NumberedValues<Value *> NumberedVals;
491 PerFunctionState(
LLParser &p, Function &f,
int functionNumber,
492 ArrayRef<unsigned> UnnamedArgNums);
495 Function &getFunction()
const {
return F; }
497 bool finishFunction();
507 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
521 bool resolveForwardRefBlockAddresses();
524 bool convertValIDToValue(
Type *Ty, ValID &
ID,
Value *&V,
525 PerFunctionState *PFS);
527 Value *checkValidVariableType(
LocTy Loc,
const Twine &Name,
Type *Ty,
530 bool parseConstantValue(
Type *Ty, Constant *&
C);
531 bool parseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS);
532 bool parseValue(
Type *Ty,
Value *&V, PerFunctionState &PFS) {
533 return parseValue(Ty, V, &PFS);
536 bool parseValue(
Type *Ty,
Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
538 return parseValue(Ty, V, &PFS);
541 bool parseTypeAndValue(
Value *&V, PerFunctionState *PFS);
542 bool parseTypeAndValue(
Value *&V, PerFunctionState &PFS) {
543 return parseTypeAndValue(V, &PFS);
545 bool parseTypeAndValue(
Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
547 return parseTypeAndValue(V, PFS);
549 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
550 PerFunctionState &PFS);
551 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
553 return parseTypeAndBasicBlock(BB, Loc, PFS);
560 ParamInfo(
LocTy loc,
Value *v, AttributeSet attrs)
561 : Loc(loc), V(
v), Attrs(attrs) {}
563 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
564 PerFunctionState &PFS,
bool IsMustTailCall =
false,
565 bool InVarArgsFunc =
false);
568 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
569 PerFunctionState &PFS);
571 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
572 PerFunctionState &PFS);
575 FunctionType *&FuncTy);
578 bool parseValID(ValID &
ID, PerFunctionState *PFS,
579 Type *ExpectedTy =
nullptr);
580 bool parseGlobalValue(
Type *Ty, Constant *&
C);
581 bool parseGlobalTypeAndValue(Constant *&V);
582 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
583 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
584 bool parseSanitizer(GlobalVariable *GV);
585 bool parseMetadataAsValue(
Value *&V, PerFunctionState &PFS);
586 bool parseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
587 PerFunctionState *PFS);
588 bool parseDIArgList(
Metadata *&MD, PerFunctionState *PFS);
589 bool parseMetadata(
Metadata *&MD, PerFunctionState *PFS);
590 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
591 bool parseMDNode(MDNode *&
N);
592 bool parseMDNodeTail(MDNode *&
N);
593 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
594 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
595 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
596 bool parseInstructionMetadata(Instruction &Inst);
597 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
598 bool parseOptionalFunctionMetadata(Function &
F);
600 template <
class FieldTy>
601 bool parseMDField(
LocTy Loc, StringRef Name, FieldTy &Result);
602 template <
class FieldTy>
bool parseMDField(StringRef Name, FieldTy &Result);
603 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
604 template <
class ParserTy>
605 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
606 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
607 bool parseDIExpressionBody(MDNode *&Result,
bool IsDistinct);
609#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
610 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
611#include "llvm/IR/Metadata.def"
619 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
620 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
622 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
623 SmallVectorImpl<unsigned> &UnnamedArgNums,
625 bool parseFunctionHeader(Function *&Fn,
bool IsDefine,
626 unsigned &FunctionNumber,
627 SmallVectorImpl<unsigned> &UnnamedArgNums);
628 bool parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
629 ArrayRef<unsigned> UnnamedArgNums);
630 bool parseBasicBlock(PerFunctionState &PFS);
632 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
636 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
637 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
638 PerFunctionState &PFS);
639 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
641 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
642 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
643 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
644 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
645 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
646 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
647 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
648 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
649 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
650 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
651 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
652 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
654 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
656 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
657 unsigned Opc,
bool IsFP);
658 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
659 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
660 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
661 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
662 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
663 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
664 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
665 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
666 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
667 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
668 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
670 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
671 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
672 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
673 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
674 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
675 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
676 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
677 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
678 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
679 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
682 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
683 bool parseUseListOrderBB();
684 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
685 bool sortUseListOrder(
Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);