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 parseCapturesAttr(AttrBuilder &
B);
383 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
387 bool skipModuleSummaryEntry();
388 bool parseSummaryEntry();
389 bool parseModuleEntry(
unsigned ID);
390 bool parseModuleReference(StringRef &ModulePath);
391 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
392 bool parseSummaryIndexFlags();
393 bool parseBlockCount();
394 bool parseGVEntry(
unsigned ID);
398 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
399 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
400 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
401 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
403 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
404 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
406 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
407 bool parseConstVCallList(
409 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
410 using IdToIndexMapType =
411 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
412 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
413 IdToIndexMapType &IdToIndexMap,
unsigned Index);
414 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
415 IdToIndexMapType &IdToIndexMap,
unsigned Index);
417 bool parseOptionalParamAccesses(
418 std::vector<FunctionSummary::ParamAccess> &Params);
419 bool parseParamNo(
uint64_t &ParamNo);
420 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
421 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
422 IdLocListType &IdLocList);
423 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
424 IdLocListType &IdLocList);
425 bool parseParamAccessOffset(ConstantRange &
Range);
426 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
427 bool parseTypeIdEntry(
unsigned ID);
428 bool parseTypeIdSummary(TypeIdSummary &TIS);
429 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
430 bool parseTypeTestResolution(TypeTestResolution &TTRes);
431 bool parseOptionalWpdResolutions(
432 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
433 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
434 bool parseOptionalResByArg(
435 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
437 bool parseArgs(std::vector<uint64_t> &Args);
440 std::unique_ptr<GlobalValueSummary> Summary,
442 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
443 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
445 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
448 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
449 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
450 return parseType(Result,
"expected type", AllowVoid);
452 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
453 bool AllowVoid =
false) {
455 return parseType(Result, Msg, AllowVoid);
457 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
459 return parseType(Result, AllowVoid);
461 bool parseAnonStructType(
Type *&Result,
bool Packed);
462 bool parseStructBody(SmallVectorImpl<Type *> &Body);
463 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
464 std::pair<Type *, LocTy> &Entry,
467 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
468 bool parseFunctionType(
Type *&Result);
469 bool parseTargetExtType(
Type *&Result);
472 class PerFunctionState {
475 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
476 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
477 NumberedValues<Value *> NumberedVals;
484 PerFunctionState(LLParser &p, Function &f,
int functionNumber,
485 ArrayRef<unsigned> UnnamedArgNums);
488 Function &getFunction()
const {
return F; }
490 bool finishFunction();
500 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
514 bool resolveForwardRefBlockAddresses();
517 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
518 PerFunctionState *PFS);
520 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
523 bool parseConstantValue(Type *Ty, Constant *&
C);
524 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
525 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
526 return parseValue(Ty, V, &PFS);
529 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
531 return parseValue(Ty, V, &PFS);
534 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
535 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
536 return parseTypeAndValue(V, &PFS);
538 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
540 return parseTypeAndValue(V, PFS);
542 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
543 PerFunctionState &PFS);
544 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
546 return parseTypeAndBasicBlock(BB, Loc, PFS);
553 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
554 : Loc(loc),
V(
v),
Attrs(attrs) {}
556 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
557 PerFunctionState &PFS,
bool IsMustTailCall =
false,
558 bool InVarArgsFunc =
false);
561 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
562 PerFunctionState &PFS);
564 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
565 PerFunctionState &PFS);
567 bool resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
571 bool parseValID(ValID &
ID, PerFunctionState *PFS,
572 Type *ExpectedTy =
nullptr);
573 bool parseGlobalValue(Type *Ty, Constant *&
C);
574 bool parseGlobalTypeAndValue(Constant *&V);
575 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
576 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
577 bool parseSanitizer(GlobalVariable *GV);
578 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
579 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
580 PerFunctionState *PFS);
581 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
582 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
583 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
584 bool parseMDNode(MDNode *&
N);
585 bool parseMDNodeTail(MDNode *&
N);
586 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
587 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
588 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
589 bool parseInstructionMetadata(Instruction &Inst);
590 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
591 bool parseOptionalFunctionMetadata(Function &
F);
593 template <
class FieldTy>
594 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
595 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
596 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
597 template <
class ParserTy>
598 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
599 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
600 bool parseDIExpressionBody(MDNode *&Result,
bool IsDistinct);
602#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
603 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
604#include "llvm/IR/Metadata.def"
612 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
613 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
615 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
616 SmallVectorImpl<unsigned> &UnnamedArgNums,
618 bool parseFunctionHeader(Function *&Fn,
bool IsDefine,
619 unsigned &FunctionNumber,
620 SmallVectorImpl<unsigned> &UnnamedArgNums);
621 bool parseFunctionBody(Function &Fn,
unsigned FunctionNumber,
622 ArrayRef<unsigned> UnnamedArgNums);
623 bool parseBasicBlock(PerFunctionState &PFS);
625 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
629 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
630 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
631 PerFunctionState &PFS);
632 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
634 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
635 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
636 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
637 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
638 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
639 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
640 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
641 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
642 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
643 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
644 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
645 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
647 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
649 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
650 unsigned Opc,
bool IsFP);
651 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
652 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
653 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
654 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
655 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
656 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
657 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
658 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
659 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
660 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
661 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
663 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
664 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
665 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
666 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
667 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
668 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
669 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
670 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
671 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
672 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
675 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
676 bool parseUseListOrderBB();
677 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
678 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