13#ifndef LLVM_ASMPARSER_LLPARSER_H
14#define LLVM_ASMPARSER_LLPARSER_H
94 assert(
Kind ==
RHS.Kind &&
"Comparing ValIDs of different kinds");
99 "Ordering not defined for this ValID kind yet");
129 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
131 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
132 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
135 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
136 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
140 std::map<std::string, LocTy> ForwardRefComdats;
144 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
145 class PerFunctionState;
149 PerFunctionState *BlockAddressPFS;
156 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
157 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
160 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
161 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
164 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
165 ForwardRefValueInfos;
166 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
168 std::vector<ValueInfo> NumberedValueInfos;
171 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
175 std::map<unsigned, StringRef> ModuleIdMap;
179 bool UpgradeDebugInfo;
181 bool SeenNewDbgInfoFormat =
false;
182 bool SeenOldDbgInfoFormat =
false;
184 std::string SourceFileName;
192 BlockAddressPFS(nullptr) {}
194 bool UpgradeDebugInfo,
202 const SlotMapping *Slots);
208 bool tokError(
const Twine &Msg)
const {
return error(Lex.
getLoc(), Msg); }
210 bool checkValueID(
LocTy L, StringRef Kind, StringRef Prefix,
211 unsigned NextID,
unsigned ID)
const;
215 void restoreParsingState(
const SlotMapping *Slots);
220 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
221 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
225 Comdat *getComdat(
const std::string &
Name,
LocTy Loc);
230 if (Lex.
getKind() !=
T)
return false;
235 FastMathFlags EatFastMathFlagsIfPresent() {
245 FMF.setAllowContract(
true);
256 LocTy *Loc =
nullptr) {
267 bool parseStringConstant(std::string &Result);
268 bool parseUInt32(
unsigned &Val);
269 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
271 return parseUInt32(Val);
276 return parseUInt64(Val);
278 bool parseFlag(
unsigned &Val);
280 bool parseStringAttribute(AttrBuilder &
B);
285 bool parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
286 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
287 return parseOptionalAddrSpace(
288 AddrSpace,
M->getDataLayout().getProgramAddressSpace());
292 bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
293 bool parseOptionalParamAttrs(AttrBuilder &
B) {
294 return parseOptionalParamOrReturnAttrs(
B,
true);
296 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
297 return parseOptionalParamOrReturnAttrs(
B,
false);
299 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
300 unsigned &Visibility,
unsigned &DLLStorageClass,
302 void parseOptionalDSOLocal(
bool &DSOLocal);
303 void parseOptionalVisibility(
unsigned &Res);
306 void parseOptionalDLLStorageClass(
unsigned &Res);
307 bool parseOptionalCallingConv(
unsigned &
CC);
308 bool parseOptionalAlignment(MaybeAlign &Alignment,
309 bool AllowParens =
false);
314 std::optional<MemoryEffects> parseMemoryAttr();
315 unsigned parseNoFPClassAttr();
316 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
320 bool parseOptionalStackAlignment(
unsigned &Alignment);
321 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
322 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
323 bool &AteExtraComma);
324 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
325 std::optional<unsigned> &HowManyArg);
326 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
327 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
328 bool &AteExtraComma);
329 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
331 if (parseIndexList(Indices, AteExtraComma))
334 return tokError(
"expected index");
339 bool parseTopLevelEntities();
340 bool finalizeDebugInfoFormat(
Module *M);
341 void dropUnknownMetadataReferences();
342 bool validateEndOfModule(
bool UpgradeDebugInfo);
343 bool validateEndOfIndex();
345 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
346 bool parseModuleAsm();
347 bool parseSourceFileName();
348 bool parseUnnamedType();
349 bool parseNamedType();
353 bool parseGlobalType(
bool &IsConstant);
354 bool parseUnnamedGlobal();
355 bool parseNamedGlobal();
356 bool parseGlobal(
const std::string &
Name,
unsigned NameID,
LocTy NameLoc,
357 unsigned Linkage,
bool HasLinkage,
unsigned Visibility,
358 unsigned DLLStorageClass,
bool DSOLocal,
361 bool parseAliasOrIFunc(
const std::string &
Name,
unsigned NameID,
362 LocTy NameLoc,
unsigned L,
unsigned Visibility,
363 unsigned DLLStorageClass,
bool DSOLocal,
367 bool parseStandaloneMetadata();
368 bool parseNamedMetadata();
369 bool parseMDString(MDString *&Result);
370 bool parseMDNodeID(MDNode *&Result);
371 bool parseUnnamedAttrGrp();
372 bool parseFnAttributeValuePairs(AttrBuilder &
B,
373 std::vector<unsigned> &FwdRefAttrGrps,
374 bool inAttrGrp,
LocTy &BuiltinLoc);
375 bool parseRangeAttr(AttrBuilder &
B);
376 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
380 bool skipModuleSummaryEntry();
381 bool parseSummaryEntry();
382 bool parseModuleEntry(
unsigned ID);
383 bool parseModuleReference(StringRef &ModulePath);
384 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
385 bool parseSummaryIndexFlags();
386 bool parseBlockCount();
387 bool parseGVEntry(
unsigned ID);
391 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
392 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
393 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
394 bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
396 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
397 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
399 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
400 bool parseConstVCallList(
402 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
403 using IdToIndexMapType =
404 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
405 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
406 IdToIndexMapType &IdToIndexMap,
unsigned Index);
407 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
408 IdToIndexMapType &IdToIndexMap,
unsigned Index);
410 bool parseOptionalParamAccesses(
411 std::vector<FunctionSummary::ParamAccess> &Params);
412 bool parseParamNo(
uint64_t &ParamNo);
413 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
414 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
415 IdLocListType &IdLocList);
416 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
417 IdLocListType &IdLocList);
418 bool parseParamAccessOffset(ConstantRange &Range);
419 bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
420 bool parseTypeIdEntry(
unsigned ID);
421 bool parseTypeIdSummary(TypeIdSummary &TIS);
422 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
423 bool parseTypeTestResolution(TypeTestResolution &TTRes);
424 bool parseOptionalWpdResolutions(
425 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
426 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
427 bool parseOptionalResByArg(
428 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
430 bool parseArgs(std::vector<uint64_t> &Args);
433 std::unique_ptr<GlobalValueSummary> Summary,
435 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
436 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
438 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
441 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
442 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
443 return parseType(Result,
"expected type", AllowVoid);
445 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
446 bool AllowVoid =
false) {
448 return parseType(Result, Msg, AllowVoid);
450 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
452 return parseType(Result, AllowVoid);
454 bool parseAnonStructType(
Type *&Result,
bool Packed);
455 bool parseStructBody(SmallVectorImpl<Type *> &Body);
456 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
457 std::pair<Type *, LocTy> &Entry,
460 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
461 bool parseFunctionType(
Type *&Result);
462 bool parseTargetExtType(
Type *&Result);
465 class PerFunctionState {
468 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
469 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
470 NumberedValues<Value *> NumberedVals;
477 PerFunctionState(LLParser &p, Function &f,
int functionNumber,
478 ArrayRef<unsigned> UnnamedArgNums);
481 Function &getFunction()
const {
return F; }
483 bool finishFunction();
493 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
507 bool resolveForwardRefBlockAddresses();
510 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
511 PerFunctionState *PFS);
513 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
516 bool parseConstantValue(Type *Ty, Constant *&
C);
517 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
518 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
519 return parseValue(Ty, V, &PFS);
522 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
524 return parseValue(Ty, V, &PFS);
527 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
528 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
529 return parseTypeAndValue(V, &PFS);
531 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
533 return parseTypeAndValue(V, PFS);
535 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
536 PerFunctionState &PFS);
537 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
539 return parseTypeAndBasicBlock(BB, Loc, PFS);
546 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
547 : Loc(loc),
V(
v),
Attrs(attrs) {}
549 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
550 PerFunctionState &PFS,
bool IsMustTailCall =
false,
551 bool InVarArgsFunc =
false);
554 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
555 PerFunctionState &PFS);
557 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
558 PerFunctionState &PFS);
560 bool resolveFunctionType(Type *RetType,
561 const SmallVector<ParamInfo, 16> &ArgList,
565 bool parseValID(ValID &
ID, PerFunctionState *PFS,
566 Type *ExpectedTy =
nullptr);
567 bool parseGlobalValue(Type *Ty, Constant *&
C);
568 bool parseGlobalTypeAndValue(Constant *&V);
569 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
570 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
571 bool parseSanitizer(GlobalVariable *GV);
572 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
573 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
574 PerFunctionState *PFS);
575 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
576 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
577 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
578 bool parseMDNode(MDNode *&
N);
579 bool parseMDNodeTail(MDNode *&
N);
580 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
581 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
582 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
583 bool parseInstructionMetadata(Instruction &Inst);
584 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
585 bool parseOptionalFunctionMetadata(Function &
F);
587 template <
class FieldTy>
588 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
589 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
590 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
591 template <
class ParserTy>
592 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
593 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
595#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
596 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
597#include "llvm/IR/Metadata.def"
605 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
606 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
608 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
609 SmallVectorImpl<unsigned> &UnnamedArgNums,
611 bool parseFunctionHeader(Function *&Fn,
bool IsDefine,
612 unsigned &FunctionNumber,
613 SmallVectorImpl<unsigned> &UnnamedArgNums);
614 bool parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
615 ArrayRef<unsigned> UnnamedArgNums);
616 bool parseBasicBlock(PerFunctionState &PFS);
618 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
622 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
623 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
624 PerFunctionState &PFS);
625 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
627 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
628 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
629 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
630 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
631 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
632 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
633 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
634 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
635 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
636 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
637 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
638 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
640 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
642 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
643 unsigned Opc,
bool IsFP);
644 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
645 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
646 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
647 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
648 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
649 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
650 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
651 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
652 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
653 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
654 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
656 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
657 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
658 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
659 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
660 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
661 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
662 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
663 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
664 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
665 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
668 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
669 bool parseUseListOrderBB();
670 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
671 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
This file defines the StringMap class.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
An arbitrary precision integer that knows its signedness.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
This is an important base class in LLVM.
Class to represent function types.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LinkageTypes
An enumeration for the kinds of linkage for global values.
lltok::Kind getKind() const
bool Error(LocTy ErrorLoc, const Twine &Msg) const
LLVMContext & getContext()
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, ModuleSummaryIndex *Index, LLVMContext &Context, SlotMapping *Slots=nullptr)
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
This is an important class for using LLVM in a threaded context.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Mapping from value ID to value, which also remembers what the next unused ID is.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Represents a location in source code.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
An efficient, type-erasing, non-owning reference to a callable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
AtomicOrdering
Atomic ordering for LLVM's memory model.
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
ValID - Represents a reference of a definition of some sort with no type.
std::unique_ptr< Constant *[]> ConstantStructElts
bool operator<(const ValID &RHS) const
enum llvm::ValID::@36 Kind