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);
297 std::optional<MemoryEffects> parseMemoryAttr();
298 unsigned parseNoFPClassAttr();
299 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
303 bool parseOptionalStackAlignment(
unsigned &Alignment);
304 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
305 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
306 bool &AteExtraComma);
307 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
308 std::optional<unsigned> &HowManyArg);
309 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
310 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
311 bool &AteExtraComma);
312 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
314 if (parseIndexList(Indices, AteExtraComma))
317 return tokError(
"expected index");
322 bool parseTopLevelEntities();
323 bool validateEndOfModule(
bool UpgradeDebugInfo);
324 bool validateEndOfIndex();
326 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
327 bool parseModuleAsm();
328 bool parseSourceFileName();
329 bool parseUnnamedType();
330 bool parseNamedType();
334 bool parseGlobalType(
bool &IsConstant);
335 bool parseUnnamedGlobal();
336 bool parseNamedGlobal();
337 bool parseGlobal(
const std::string &
Name,
LocTy NameLoc,
unsigned Linkage,
338 bool HasLinkage,
unsigned Visibility,
339 unsigned DLLStorageClass,
bool DSOLocal,
342 bool parseAliasOrIFunc(
const std::string &
Name,
LocTy NameLoc,
unsigned L,
343 unsigned Visibility,
unsigned DLLStorageClass,
347 bool parseStandaloneMetadata();
348 bool parseNamedMetadata();
349 bool parseMDString(MDString *&Result);
350 bool parseMDNodeID(MDNode *&Result);
351 bool parseUnnamedAttrGrp();
352 bool parseFnAttributeValuePairs(AttrBuilder &
B,
353 std::vector<unsigned> &FwdRefAttrGrps,
354 bool inAttrGrp,
LocTy &BuiltinLoc);
355 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
359 bool skipModuleSummaryEntry();
360 bool parseSummaryEntry();
361 bool parseModuleEntry(
unsigned ID);
362 bool parseModuleReference(StringRef &ModulePath);
363 bool parseGVReference(ValueInfo &VI,
unsigned &GVId);
364 bool parseSummaryIndexFlags();
365 bool parseBlockCount();
366 bool parseGVEntry(
unsigned ID);
370 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
371 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
372 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
373 bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
375 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
376 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
378 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
379 bool parseConstVCallList(
381 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
382 using IdToIndexMapType =
383 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
384 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
385 IdToIndexMapType &IdToIndexMap,
unsigned Index);
386 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
387 IdToIndexMapType &IdToIndexMap,
unsigned Index);
389 bool parseOptionalParamAccesses(
390 std::vector<FunctionSummary::ParamAccess> &Params);
391 bool parseParamNo(
uint64_t &ParamNo);
392 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
393 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
394 IdLocListType &IdLocList);
395 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
396 IdLocListType &IdLocList);
397 bool parseParamAccessOffset(ConstantRange &Range);
398 bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
399 bool parseTypeIdEntry(
unsigned ID);
400 bool parseTypeIdSummary(TypeIdSummary &TIS);
401 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
402 bool parseTypeTestResolution(TypeTestResolution &TTRes);
403 bool parseOptionalWpdResolutions(
404 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
405 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
406 bool parseOptionalResByArg(
407 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
409 bool parseArgs(std::vector<uint64_t> &Args);
412 std::unique_ptr<GlobalValueSummary> Summary);
413 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
414 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
416 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
419 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
420 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
421 return parseType(Result,
"expected type", AllowVoid);
423 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
424 bool AllowVoid =
false) {
426 return parseType(Result, Msg, AllowVoid);
428 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
430 return parseType(Result, AllowVoid);
432 bool parseAnonStructType(
Type *&Result,
bool Packed);
433 bool parseStructBody(SmallVectorImpl<Type *> &Body);
434 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
435 std::pair<Type *, LocTy> &Entry,
438 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
439 bool parseFunctionType(
Type *&Result);
440 bool parseTargetExtType(
Type *&Result);
443 class PerFunctionState {
446 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
447 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
448 std::vector<Value*> NumberedVals;
454 PerFunctionState(LLParser &p, Function &f,
int functionNumber);
457 Function &getFunction()
const {
return F; }
459 bool finishFunction();
469 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
483 bool resolveForwardRefBlockAddresses();
486 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
487 PerFunctionState *PFS);
489 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
492 bool parseConstantValue(Type *Ty, Constant *&
C);
493 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
494 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
495 return parseValue(Ty, V, &PFS);
498 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
500 return parseValue(Ty, V, &PFS);
503 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
504 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
505 return parseTypeAndValue(V, &PFS);
507 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
509 return parseTypeAndValue(V, PFS);
511 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
512 PerFunctionState &PFS);
513 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
515 return parseTypeAndBasicBlock(BB, Loc, PFS);
522 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
523 : Loc(loc),
V(
v),
Attrs(attrs) {}
525 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
526 PerFunctionState &PFS,
bool IsMustTailCall =
false,
527 bool InVarArgsFunc =
false);
530 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
531 PerFunctionState &PFS);
533 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
534 PerFunctionState &PFS);
536 bool resolveFunctionType(Type *RetType,
537 const SmallVector<ParamInfo, 16> &ArgList,
541 bool parseValID(ValID &
ID, PerFunctionState *PFS,
542 Type *ExpectedTy =
nullptr);
543 bool parseGlobalValue(Type *Ty, Constant *&
C);
544 bool parseGlobalTypeAndValue(Constant *&V);
545 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
546 std::optional<unsigned> *InRangeOp =
nullptr);
547 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
548 bool parseSanitizer(GlobalVariable *GV);
549 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
550 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
551 PerFunctionState *PFS);
552 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
553 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
554 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
555 bool parseMDNode(MDNode *&
N);
556 bool parseMDNodeTail(MDNode *&
N);
557 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
558 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
559 bool parseInstructionMetadata(Instruction &Inst);
560 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
561 bool parseOptionalFunctionMetadata(Function &
F);
563 template <
class FieldTy>
564 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
565 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
566 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
567 template <
class ParserTy>
568 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
569 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
571#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
572 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
573#include "llvm/IR/Metadata.def"
581 ArgInfo(
LocTy L, Type *ty, AttributeSet Attr,
const std::string &
N)
582 : Loc(L), Ty(ty), Attrs(Attr), Name(
N) {}
584 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &IsVarArg);
585 bool parseFunctionHeader(Function *&Fn,
bool IsDefine);
586 bool parseFunctionBody(Function &Fn);
587 bool parseBasicBlock(PerFunctionState &PFS);
589 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
593 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
594 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
595 PerFunctionState &PFS);
596 bool parseCmpPredicate(
unsigned &
P,
unsigned Opc);
598 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
599 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
600 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
601 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
602 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
603 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
604 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
605 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
606 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
607 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
608 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
609 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
611 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
613 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
614 unsigned Opc,
bool IsFP);
615 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
616 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
617 bool parseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
618 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
619 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
620 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
621 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
622 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
623 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
624 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
625 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
627 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
628 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
629 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
630 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
631 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
632 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
633 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
634 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
635 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
636 bool parseFreeze(Instruction *&
I, PerFunctionState &PFS);
639 bool parseUseListOrder(PerFunctionState *PFS =
nullptr);
640 bool parseUseListOrderBB();
641 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
642 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::@39 Kind