13#ifndef LLVM_ASMPARSER_LLPARSER_H
14#define LLVM_ASMPARSER_LLPARSER_H
98 "Comparing ValIDs of different kinds");
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;
182 bool UpgradeDebugInfo;
184 bool SeenNewDbgInfoFormat =
false;
185 bool SeenOldDbgInfoFormat =
false;
187 std::string SourceFileName;
193 : Context(Context), OPLex(
F, SM, Err, Context),
194 Lex(
F, SM, Err, Context), M(M),
Index(
Index), Slots(Slots),
195 BlockAddressPFS(nullptr) {}
197 bool UpgradeDebugInfo,
205 const SlotMapping *Slots);
208 const SlotMapping *Slots);
214 bool tokError(
const Twine &Msg) {
return error(Lex.
getLoc(), Msg); }
216 bool checkValueID(
LocTy L, StringRef Kind, StringRef Prefix,
217 unsigned NextID,
unsigned ID);
221 void restoreParsingState(
const SlotMapping *Slots);
226 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
227 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
231 Comdat *getComdat(
const std::string &
Name,
LocTy Loc);
236 if (Lex.
getKind() !=
T)
return false;
241 FastMathFlags EatFastMathFlagsIfPresent() {
251 FMF.setAllowContract(
true);
262 LocTy *Loc =
nullptr) {
273 bool parseStringConstant(std::string &Result);
274 bool parseUInt32(
unsigned &Val);
275 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
277 return parseUInt32(Val);
282 return parseUInt64(Val);
284 bool parseFlag(
unsigned &Val);
286 bool parseStringAttribute(AttrBuilder &
B);
291 bool parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
292 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
293 return parseOptionalAddrSpace(
294 AddrSpace,
M->getDataLayout().getProgramAddressSpace());
298 bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
299 bool parseOptionalParamAttrs(AttrBuilder &
B) {
300 return parseOptionalParamOrReturnAttrs(
B,
true);
302 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
303 return parseOptionalParamOrReturnAttrs(
B,
false);
305 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
306 unsigned &Visibility,
unsigned &DLLStorageClass,
308 void parseOptionalDSOLocal(
bool &DSOLocal);
309 void parseOptionalVisibility(
unsigned &Res);
312 void parseOptionalDLLStorageClass(
unsigned &Res);
313 bool parseOptionalCallingConv(
unsigned &
CC);
314 bool parseOptionalAlignment(MaybeAlign &Alignment,
315 bool AllowParens =
false);
320 std::optional<MemoryEffects> parseMemoryAttr();
321 unsigned parseNoFPClassAttr();
322 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
326 bool parseOptionalStackAlignment(
unsigned &Alignment);
327 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
328 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
329 bool &AteExtraComma);
330 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
331 std::optional<unsigned> &HowManyArg);
332 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
333 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
334 bool &AteExtraComma);
335 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
337 if (parseIndexList(Indices, AteExtraComma))
340 return tokError(
"expected index");
345 bool parseTopLevelEntities();
346 void dropUnknownMetadataReferences();
347 bool validateEndOfModule(
bool UpgradeDebugInfo);
348 bool validateEndOfIndex();
350 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
351 bool parseModuleAsm();
352 bool parseSourceFileName();
353 bool parseUnnamedType();
354 bool parseNamedType();
358 bool parseGlobalType(
bool &IsConstant);
359 bool parseUnnamedGlobal();
360 bool parseNamedGlobal();
361 bool parseGlobal(
const std::string &
Name,
unsigned NameID,
LocTy NameLoc,
362 unsigned Linkage,
bool HasLinkage,
unsigned Visibility,
363 unsigned DLLStorageClass,
bool DSOLocal,
366 bool parseAliasOrIFunc(
const std::string &
Name,
unsigned NameID,
367 LocTy NameLoc,
unsigned L,
unsigned Visibility,
368 unsigned DLLStorageClass,
bool DSOLocal,
372 bool parseStandaloneMetadata();
373 bool parseNamedMetadata();
374 bool parseMDString(MDString *&Result);
375 bool parseMDNodeID(MDNode *&Result);
376 bool parseUnnamedAttrGrp();
377 bool parseFnAttributeValuePairs(AttrBuilder &
B,
378 std::vector<unsigned> &FwdRefAttrGrps,
379 bool inAttrGrp,
LocTy &BuiltinLoc);
380 bool parseRangeAttr(AttrBuilder &
B);
381 bool parseInitializesAttr(AttrBuilder &
B);
382 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
386 bool skipModuleSummaryEntry();
387 bool parseSummaryEntry();
388 bool parseModuleEntry(
unsigned ID);
389 bool parseModuleReference(StringRef &ModulePath);
390 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
391 bool parseSummaryIndexFlags();
392 bool parseBlockCount();
393 bool parseGVEntry(
unsigned ID);
397 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
398 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
399 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
400 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
402 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
403 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
405 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
406 bool parseConstVCallList(
408 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
409 using IdToIndexMapType =
410 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
411 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
412 IdToIndexMapType &IdToIndexMap,
unsigned Index);
413 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
414 IdToIndexMapType &IdToIndexMap,
unsigned Index);
416 bool parseOptionalParamAccesses(
417 std::vector<FunctionSummary::ParamAccess> &Params);
418 bool parseParamNo(
uint64_t &ParamNo);
419 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
420 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
421 IdLocListType &IdLocList);
422 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
423 IdLocListType &IdLocList);
424 bool parseParamAccessOffset(ConstantRange &
Range);
425 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
426 bool parseTypeIdEntry(
unsigned ID);
427 bool parseTypeIdSummary(TypeIdSummary &TIS);
428 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
429 bool parseTypeTestResolution(TypeTestResolution &TTRes);
430 bool parseOptionalWpdResolutions(
431 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
432 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
433 bool parseOptionalResByArg(
434 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
436 bool parseArgs(std::vector<uint64_t> &Args);
439 std::unique_ptr<GlobalValueSummary> Summary,
441 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
442 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
444 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
447 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
448 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
449 return parseType(Result,
"expected type", AllowVoid);
451 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
452 bool AllowVoid =
false) {
454 return parseType(Result, Msg, AllowVoid);
456 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
458 return parseType(Result, AllowVoid);
460 bool parseAnonStructType(
Type *&Result,
bool Packed);
461 bool parseStructBody(SmallVectorImpl<Type *> &Body);
462 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
463 std::pair<Type *, LocTy> &Entry,
466 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
467 bool parseFunctionType(
Type *&Result);
468 bool parseTargetExtType(
Type *&Result);
471 class PerFunctionState {
474 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
475 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
476 NumberedValues<Value *> NumberedVals;
483 PerFunctionState(LLParser &p, Function &f,
int functionNumber,
484 ArrayRef<unsigned> UnnamedArgNums);
487 Function &getFunction()
const {
return F; }
489 bool finishFunction();
499 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
513 bool resolveForwardRefBlockAddresses();
516 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
517 PerFunctionState *PFS);
519 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
522 bool parseConstantValue(Type *Ty, Constant *&
C);
523 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
524 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
525 return parseValue(Ty, V, &PFS);
528 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
530 return parseValue(Ty, V, &PFS);
533 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
534 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
535 return parseTypeAndValue(V, &PFS);
537 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
539 return parseTypeAndValue(V, PFS);
541 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
542 PerFunctionState &PFS);
543 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
545 return parseTypeAndBasicBlock(BB, Loc, PFS);
552 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
553 : Loc(loc),
V(
v),
Attrs(attrs) {}
555 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
556 PerFunctionState &PFS,
bool IsMustTailCall =
false,
557 bool InVarArgsFunc =
false);
560 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
561 PerFunctionState &PFS);
563 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
564 PerFunctionState &PFS);
566 bool resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
570 bool parseValID(ValID &
ID, PerFunctionState *PFS,
571 Type *ExpectedTy =
nullptr);
572 bool parseGlobalValue(Type *Ty, Constant *&
C);
573 bool parseGlobalTypeAndValue(Constant *&V);
574 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
575 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
576 bool parseSanitizer(GlobalVariable *GV);
577 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
578 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
579 PerFunctionState *PFS);
580 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
581 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
582 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
583 bool parseMDNode(MDNode *&
N);
584 bool parseMDNodeTail(MDNode *&
N);
585 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
586 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
587 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
588 bool parseInstructionMetadata(Instruction &Inst);
589 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
590 bool parseOptionalFunctionMetadata(Function &
F);
592 template <
class FieldTy>
593 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
594 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
595 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
596 template <
class ParserTy>
597 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
598 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
599 bool parseDIExpressionBody(MDNode *&Result,
bool IsDistinct);
601#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
602 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
603#include "llvm/IR/Metadata.def"
611 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
612 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
614 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
615 SmallVectorImpl<unsigned> &UnnamedArgNums,
617 bool parseFunctionHeader(Function *&Fn,
bool IsDefine,
618 unsigned &FunctionNumber,
619 SmallVectorImpl<unsigned> &UnnamedArgNums);
620 bool parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
621 ArrayRef<unsigned> UnnamedArgNums);
622 bool parseBasicBlock(PerFunctionState &PFS);
624 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
628 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
629 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
630 PerFunctionState &PFS);
631 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
633 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
634 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
635 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
636 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
637 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
638 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
639 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
640 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
641 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
642 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
643 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
644 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
646 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
648 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
649 unsigned Opc,
bool IsFP);
650 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
651 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
652 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
653 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
654 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
655 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
656 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
657 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
658 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
659 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
660 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
662 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
663 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
664 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
665 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
666 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
667 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
668 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
669 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
670 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
671 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
674 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
675 bool parseUseListOrderBB();
676 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
677 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.
bool ParseError(LocTy ErrorLoc, const Twine &Msg)
lltok::Kind getKind() 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.
enum llvm::ValID::@40 Kind
std::unique_ptr< Constant *[]> ConstantStructElts
bool operator<(const ValID &RHS) const