13#ifndef LLVM_ASMPARSER_LLPARSER_H
14#define LLVM_ASMPARSER_LLPARSER_H
85 assert(
Kind ==
RHS.Kind &&
"Comparing ValIDs of different kinds");
90 "Ordering not defined for this ValID kind yet");
120 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
122 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
123 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
126 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
127 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
128 std::vector<GlobalValue*> NumberedVals;
131 std::map<std::string, LocTy> ForwardRefComdats;
135 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
136 class PerFunctionState;
140 PerFunctionState *BlockAddressPFS;
147 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
148 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
151 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
152 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
155 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
156 ForwardRefValueInfos;
157 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
159 std::vector<ValueInfo> NumberedValueInfos;
162 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
166 std::map<unsigned, StringRef> ModuleIdMap;
170 bool UpgradeDebugInfo;
172 std::string SourceFileName;
180 BlockAddressPFS(nullptr) {}
182 bool UpgradeDebugInfo,
190 const SlotMapping *Slots);
196 bool tokError(
const Twine &Msg)
const {
return error(Lex.
getLoc(), Msg); }
200 void restoreParsingState(
const SlotMapping *Slots);
205 GlobalValue *getGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
206 GlobalValue *getGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
210 Comdat *getComdat(
const std::string &
Name,
LocTy Loc);
215 if (Lex.
getKind() !=
T)
return false;
220 FastMathFlags EatFastMathFlagsIfPresent() {
230 FMF.setAllowContract(
true);
241 LocTy *Loc =
nullptr) {
252 bool parseStringConstant(std::string &Result);
253 bool parseUInt32(
unsigned &Val);
254 bool parseUInt32(
unsigned &Val,
LocTy &Loc) {
256 return parseUInt32(Val);
261 return parseUInt64(Val);
263 bool parseFlag(
unsigned &Val);
265 bool parseStringAttribute(AttrBuilder &
B);
270 bool parseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
271 bool parseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
272 return parseOptionalAddrSpace(
273 AddrSpace,
M->getDataLayout().getProgramAddressSpace());
277 bool parseOptionalParamOrReturnAttrs(AttrBuilder &
B,
bool IsParam);
278 bool parseOptionalParamAttrs(AttrBuilder &
B) {
279 return parseOptionalParamOrReturnAttrs(
B,
true);
281 bool parseOptionalReturnAttrs(AttrBuilder &
B) {
282 return parseOptionalParamOrReturnAttrs(
B,
false);
284 bool parseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
285 unsigned &Visibility,
unsigned &DLLStorageClass,
287 void parseOptionalDSOLocal(
bool &DSOLocal);
288 void parseOptionalVisibility(
unsigned &Res);
289 void parseOptionalDLLStorageClass(
unsigned &Res);
290 bool parseOptionalCallingConv(
unsigned &
CC);
291 bool parseOptionalAlignment(MaybeAlign &Alignment,
292 bool AllowParens =
false);
296 std::optional<MemoryEffects> parseMemoryAttr();
297 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
301 bool parseOptionalStackAlignment(
unsigned &Alignment);
302 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
303 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
304 bool &AteExtraComma);
305 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
306 std::optional<unsigned> &HowManyArg);
307 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
308 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
309 bool &AteExtraComma);
310 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
312 if (parseIndexList(Indices, AteExtraComma))
315 return tokError(
"expected index");
320 bool parseTopLevelEntities();
321 bool validateEndOfModule(
bool UpgradeDebugInfo);
322 bool validateEndOfIndex();
324 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
325 bool parseModuleAsm();
326 bool parseSourceFileName();
327 bool parseUnnamedType();
328 bool parseNamedType();
332 bool parseGlobalType(
bool &IsConstant);
333 bool parseUnnamedGlobal();
334 bool parseNamedGlobal();
335 bool parseGlobal(
const std::string &
Name,
LocTy NameLoc,
unsigned Linkage,
336 bool HasLinkage,
unsigned Visibility,
337 unsigned DLLStorageClass,
bool DSOLocal,
340 bool parseAliasOrIFunc(
const std::string &
Name,
LocTy NameLoc,
unsigned L,
341 unsigned Visibility,
unsigned DLLStorageClass,
345 bool parseStandaloneMetadata();
346 bool parseNamedMetadata();
347 bool parseMDString(MDString *&Result);
348 bool parseMDNodeID(MDNode *&Result);
349 bool parseUnnamedAttrGrp();
350 bool parseFnAttributeValuePairs(AttrBuilder &
B,
351 std::vector<unsigned> &FwdRefAttrGrps,
352 bool inAttrGrp,
LocTy &BuiltinLoc);
353 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
357 bool skipModuleSummaryEntry();
358 bool parseSummaryEntry();
359 bool parseModuleEntry(
unsigned ID);
360 bool parseModuleReference(StringRef &ModulePath);
361 bool parseGVReference(ValueInfo &
VI,
unsigned &GVId);
362 bool parseSummaryIndexFlags();
363 bool parseBlockCount();
364 bool parseGVEntry(
unsigned ID);
368 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
369 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
370 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
371 bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
373 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
374 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
376 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
377 bool parseConstVCallList(
379 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
380 using IdToIndexMapType =
381 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
382 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
383 IdToIndexMapType &IdToIndexMap,
unsigned Index);
384 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
385 IdToIndexMapType &IdToIndexMap,
unsigned Index);
387 bool parseOptionalParamAccesses(
388 std::vector<FunctionSummary::ParamAccess> &Params);
389 bool parseParamNo(
uint64_t &ParamNo);
390 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
391 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
392 IdLocListType &IdLocList);
393 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
394 IdLocListType &IdLocList);
395 bool parseParamAccessOffset(ConstantRange &Range);
396 bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
397 bool parseTypeIdEntry(
unsigned ID);
398 bool parseTypeIdSummary(TypeIdSummary &TIS);
399 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
400 bool parseTypeTestResolution(TypeTestResolution &TTRes);
401 bool parseOptionalWpdResolutions(
402 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
403 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
404 bool parseOptionalResByArg(
405 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
407 bool parseArgs(std::vector<uint64_t> &Args);
410 std::unique_ptr<GlobalValueSummary> Summary);
411 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
412 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
414 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
417 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
418 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
419 return parseType(Result,
"expected type", AllowVoid);
421 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
422 bool AllowVoid =
false) {
424 return parseType(Result, Msg, AllowVoid);
426 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
428 return parseType(Result, AllowVoid);
430 bool parseAnonStructType(
Type *&Result,
bool Packed);
431 bool parseStructBody(SmallVectorImpl<Type *> &Body);
432 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
433 std::pair<Type *, LocTy> &Entry,
436 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
437 bool parseFunctionType(
Type *&Result);
438 bool parseTargetExtType(
Type *&Result);
441 class PerFunctionState {
444 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
445 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
446 std::vector<Value*> NumberedVals;
452 PerFunctionState(LLParser &p, Function &f,
int functionNumber);
455 Function &getFunction()
const {
return F; }
457 bool finishFunction();
467 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
481 bool resolveForwardRefBlockAddresses();
484 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
485 PerFunctionState *PFS);
487 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
490 bool parseConstantValue(Type *Ty, Constant *&
C);
491 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
492 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
493 return parseValue(Ty, V, &PFS);
496 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
498 return parseValue(Ty, V, &PFS);
501 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
502 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
503 return parseTypeAndValue(V, &PFS);
505 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
507 return parseTypeAndValue(V, PFS);
509 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
510 PerFunctionState &PFS);
511 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
513 return parseTypeAndBasicBlock(BB, Loc, PFS);
520 ParamInfo(
LocTy loc, Value *v, AttributeSet
attrs)
523 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
524 PerFunctionState &PFS,
bool IsMustTailCall =
false,
525 bool InVarArgsFunc =
false);
528 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
529 PerFunctionState &PFS);
531 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
532 PerFunctionState &PFS);
534 bool resolveFunctionType(Type *RetType,
535 const SmallVector<ParamInfo, 16> &ArgList,
539 bool parseValID(ValID &
ID, PerFunctionState *PFS,
540 Type *ExpectedTy =
nullptr);
541 bool parseGlobalValue(Type *Ty, Constant *&
C);
542 bool parseGlobalTypeAndValue(Constant *&V);
543 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
544 std::optional<unsigned> *InRangeOp =
nullptr);
545 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
546 bool parseSanitizer(GlobalVariable *GV);
547 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
548 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
549 PerFunctionState *PFS);
550 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
551 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
552 bool parseMDNode(MDNode *&
N);
553 bool parseMDNodeTail(MDNode *&
N);
554 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
555 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
556 bool parseInstructionMetadata(Instruction &Inst);
557 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
558 bool parseOptionalFunctionMetadata(Function &
F);
560 template <
class FieldTy>
561 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
562 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
563 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
564 template <
class ParserTy>
565 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
566 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
568#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
569 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
570#include "llvm/IR/Metadata.def"
571 bool parseDIArgList(MDNode *&Result,
bool IsDistinct,
572 PerFunctionState *PFS);
580 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
581 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
583 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &IsVarArg);
584 bool parseFunctionHeader(Function *&Fn,
bool IsDefine);
585 bool parseFunctionBody(Function &Fn);
586 bool parseBasicBlock(PerFunctionState &PFS);
588 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
592 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
593 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
594 PerFunctionState &PFS);
595 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
597 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
598 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
599 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
600 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
601 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
602 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
603 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
604 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
605 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
606 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
607 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
608 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
610 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
612 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
613 unsigned Opc,
bool IsFP);
614 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
615 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
616 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
617 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
618 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
619 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
620 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
621 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
622 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
623 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
624 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
626 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
627 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
628 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
629 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
630 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
631 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
632 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
633 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
634 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
635 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
638 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
639 bool parseUseListOrderBB();
640 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
641 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.
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::@37 Kind