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;
190 : Context(Context), OPLex(
F, SM, Err, Context),
191 Lex(
F, SM, Err, Context), M(M),
Index(
Index), Slots(Slots),
192 BlockAddressPFS(nullptr) {}
194 bool UpgradeDebugInfo,
202 const SlotMapping *Slots);
205 const SlotMapping *Slots);
211 bool tokError(
const Twine &Msg)
const {
return error(Lex.
getLoc(), Msg); }
213 bool checkValueID(
LocTy L, StringRef Kind, StringRef Prefix,
214 unsigned NextID,
unsigned ID)
const;
218 void restoreParsingState(
const SlotMapping *Slots);
223 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
224 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
228 Comdat *getComdat(
const std::string &
Name,
LocTy Loc);
233 if (Lex.
getKind() !=
T)
return false;
238 FastMathFlags EatFastMathFlagsIfPresent() {
248 FMF.setAllowContract(
true);
259 LocTy *Loc =
nullptr) {
270 bool parseStringConstant(std::string &Result);
271 bool parseUInt32(
unsigned &Val);
272 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
274 return parseUInt32(Val);
279 return parseUInt64(Val);
281 bool parseFlag(
unsigned &Val);
283 bool parseStringAttribute(AttrBuilder &
B);
288 bool parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
289 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
290 return parseOptionalAddrSpace(
291 AddrSpace,
M->getDataLayout().getProgramAddressSpace());
295 bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
296 bool parseOptionalParamAttrs(AttrBuilder &
B) {
297 return parseOptionalParamOrReturnAttrs(
B,
true);
299 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
300 return parseOptionalParamOrReturnAttrs(
B,
false);
302 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
303 unsigned &Visibility,
unsigned &DLLStorageClass,
305 void parseOptionalDSOLocal(
bool &DSOLocal);
306 void parseOptionalVisibility(
unsigned &Res);
309 void parseOptionalDLLStorageClass(
unsigned &Res);
310 bool parseOptionalCallingConv(
unsigned &
CC);
311 bool parseOptionalAlignment(MaybeAlign &Alignment,
312 bool AllowParens =
false);
317 std::optional<MemoryEffects> parseMemoryAttr();
318 unsigned parseNoFPClassAttr();
319 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
323 bool parseOptionalStackAlignment(
unsigned &Alignment);
324 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
325 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
326 bool &AteExtraComma);
327 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
328 std::optional<unsigned> &HowManyArg);
329 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
330 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
331 bool &AteExtraComma);
332 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
334 if (parseIndexList(Indices, AteExtraComma))
337 return tokError(
"expected index");
342 bool parseTopLevelEntities();
343 void dropUnknownMetadataReferences();
344 bool validateEndOfModule(
bool UpgradeDebugInfo);
345 bool validateEndOfIndex();
347 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
348 bool parseModuleAsm();
349 bool parseSourceFileName();
350 bool parseUnnamedType();
351 bool parseNamedType();
355 bool parseGlobalType(
bool &IsConstant);
356 bool parseUnnamedGlobal();
357 bool parseNamedGlobal();
358 bool parseGlobal(
const std::string &
Name,
unsigned NameID,
LocTy NameLoc,
359 unsigned Linkage,
bool HasLinkage,
unsigned Visibility,
360 unsigned DLLStorageClass,
bool DSOLocal,
363 bool parseAliasOrIFunc(
const std::string &
Name,
unsigned NameID,
364 LocTy NameLoc,
unsigned L,
unsigned Visibility,
365 unsigned DLLStorageClass,
bool DSOLocal,
369 bool parseStandaloneMetadata();
370 bool parseNamedMetadata();
371 bool parseMDString(MDString *&Result);
372 bool parseMDNodeID(MDNode *&Result);
373 bool parseUnnamedAttrGrp();
374 bool parseFnAttributeValuePairs(AttrBuilder &
B,
375 std::vector<unsigned> &FwdRefAttrGrps,
376 bool inAttrGrp,
LocTy &BuiltinLoc);
377 bool parseRangeAttr(AttrBuilder &
B);
378 bool parseInitializesAttr(AttrBuilder &
B);
379 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
383 bool skipModuleSummaryEntry();
384 bool parseSummaryEntry();
385 bool parseModuleEntry(
unsigned ID);
386 bool parseModuleReference(StringRef &ModulePath);
387 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
388 bool parseSummaryIndexFlags();
389 bool parseBlockCount();
390 bool parseGVEntry(
unsigned ID);
394 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
395 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
396 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
397 bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
399 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
400 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
402 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
403 bool parseConstVCallList(
405 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
406 using IdToIndexMapType =
407 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
408 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
409 IdToIndexMapType &IdToIndexMap,
unsigned Index);
410 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
411 IdToIndexMapType &IdToIndexMap,
unsigned Index);
413 bool parseOptionalParamAccesses(
414 std::vector<FunctionSummary::ParamAccess> &Params);
415 bool parseParamNo(
uint64_t &ParamNo);
416 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
417 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
418 IdLocListType &IdLocList);
419 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
420 IdLocListType &IdLocList);
421 bool parseParamAccessOffset(ConstantRange &
Range);
422 bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
423 bool parseTypeIdEntry(
unsigned ID);
424 bool parseTypeIdSummary(TypeIdSummary &TIS);
425 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
426 bool parseTypeTestResolution(TypeTestResolution &TTRes);
427 bool parseOptionalWpdResolutions(
428 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
429 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
430 bool parseOptionalResByArg(
431 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
433 bool parseArgs(std::vector<uint64_t> &Args);
436 std::unique_ptr<GlobalValueSummary> Summary,
438 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
439 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
441 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
444 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
445 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
446 return parseType(Result,
"expected type", AllowVoid);
448 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
449 bool AllowVoid =
false) {
451 return parseType(Result, Msg, AllowVoid);
453 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
455 return parseType(Result, AllowVoid);
457 bool parseAnonStructType(
Type *&Result,
bool Packed);
458 bool parseStructBody(SmallVectorImpl<Type *> &Body);
459 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
460 std::pair<Type *, LocTy> &Entry,
463 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
464 bool parseFunctionType(
Type *&Result);
465 bool parseTargetExtType(
Type *&Result);
468 class PerFunctionState {
471 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
472 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
473 NumberedValues<Value *> NumberedVals;
480 PerFunctionState(LLParser &p, Function &f,
int functionNumber,
481 ArrayRef<unsigned> UnnamedArgNums);
484 Function &getFunction()
const {
return F; }
486 bool finishFunction();
496 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
510 bool resolveForwardRefBlockAddresses();
513 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
514 PerFunctionState *PFS);
516 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
519 bool parseConstantValue(Type *Ty, Constant *&
C);
520 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
521 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
522 return parseValue(Ty, V, &PFS);
525 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
527 return parseValue(Ty, V, &PFS);
530 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
531 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
532 return parseTypeAndValue(V, &PFS);
534 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
536 return parseTypeAndValue(V, PFS);
538 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
539 PerFunctionState &PFS);
540 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
542 return parseTypeAndBasicBlock(BB, Loc, PFS);
549 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
550 : Loc(loc),
V(
v),
Attrs(attrs) {}
552 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
553 PerFunctionState &PFS,
bool IsMustTailCall =
false,
554 bool InVarArgsFunc =
false);
557 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
558 PerFunctionState &PFS);
560 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
561 PerFunctionState &PFS);
563 bool resolveFunctionType(Type *RetType,
564 const SmallVector<ParamInfo, 16> &ArgList,
568 bool parseValID(ValID &
ID, PerFunctionState *PFS,
569 Type *ExpectedTy =
nullptr);
570 bool parseGlobalValue(Type *Ty, Constant *&
C);
571 bool parseGlobalTypeAndValue(Constant *&V);
572 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
573 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
574 bool parseSanitizer(GlobalVariable *GV);
575 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
576 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
577 PerFunctionState *PFS);
578 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
579 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
580 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
581 bool parseMDNode(MDNode *&
N);
582 bool parseMDNodeTail(MDNode *&
N);
583 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
584 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
585 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
586 bool parseInstructionMetadata(Instruction &Inst);
587 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
588 bool parseOptionalFunctionMetadata(Function &
F);
590 template <
class FieldTy>
591 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
592 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
593 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
594 template <
class ParserTy>
595 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
596 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
597 bool parseDIExpressionBody(MDNode *&Result,
bool IsDistinct);
599#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
600 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
601#include "llvm/IR/Metadata.def"
609 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
610 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
612 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
613 SmallVectorImpl<unsigned> &UnnamedArgNums,
615 bool parseFunctionHeader(Function *&Fn,
bool IsDefine,
616 unsigned &FunctionNumber,
617 SmallVectorImpl<unsigned> &UnnamedArgNums);
618 bool parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
619 ArrayRef<unsigned> UnnamedArgNums);
620 bool parseBasicBlock(PerFunctionState &PFS);
622 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
626 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
627 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
628 PerFunctionState &PFS);
629 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
631 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
632 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
633 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
634 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
635 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
636 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
637 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
638 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
639 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
640 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
641 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
642 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
644 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
646 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
647 unsigned Opc,
bool IsFP);
648 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
649 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
650 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
651 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
652 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
653 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
654 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
655 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
656 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
657 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
658 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
660 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
661 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
662 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
663 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
664 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
665 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
666 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
667 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
668 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
669 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
672 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
673 bool parseUseListOrderBB();
674 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
675 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...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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
bool parseDIExpressionBodyAtBeginning(MDNode *&Result, unsigned &Read, const SlotMapping *Slots)
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.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ 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::@39 Kind