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 unsigned parseNoFPClassAttr();
298 bool parseScopeAndOrdering(
bool IsAtomic,
SyncScope::ID &SSID,
302 bool parseOptionalStackAlignment(
unsigned &Alignment);
303 bool parseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma);
304 bool parseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
305 bool &AteExtraComma);
306 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
307 std::optional<unsigned> &HowManyArg);
308 bool parseVScaleRangeArguments(
unsigned &MinValue,
unsigned &MaxValue);
309 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
310 bool &AteExtraComma);
311 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
313 if (parseIndexList(Indices, AteExtraComma))
316 return tokError(
"expected index");
321 bool parseTopLevelEntities();
322 bool validateEndOfModule(
bool UpgradeDebugInfo);
323 bool validateEndOfIndex();
325 bool parseTargetDefinition(std::string &TentativeDLStr,
LocTy &DLStrLoc);
326 bool parseModuleAsm();
327 bool parseSourceFileName();
328 bool parseUnnamedType();
329 bool parseNamedType();
333 bool parseGlobalType(
bool &IsConstant);
334 bool parseUnnamedGlobal();
335 bool parseNamedGlobal();
336 bool parseGlobal(
const std::string &
Name,
LocTy NameLoc,
unsigned Linkage,
337 bool HasLinkage,
unsigned Visibility,
338 unsigned DLLStorageClass,
bool DSOLocal,
341 bool parseAliasOrIFunc(
const std::string &
Name,
LocTy NameLoc,
unsigned L,
342 unsigned Visibility,
unsigned DLLStorageClass,
346 bool parseStandaloneMetadata();
347 bool parseNamedMetadata();
348 bool parseMDString(MDString *&Result);
349 bool parseMDNodeID(MDNode *&Result);
350 bool parseUnnamedAttrGrp();
351 bool parseFnAttributeValuePairs(AttrBuilder &
B,
352 std::vector<unsigned> &FwdRefAttrGrps,
353 bool inAttrGrp,
LocTy &BuiltinLoc);
354 bool parseRequiredTypeAttr(AttrBuilder &
B,
lltok::Kind AttrToken,
358 bool skipModuleSummaryEntry();
359 bool parseSummaryEntry();
360 bool parseModuleEntry(
unsigned ID);
361 bool parseModuleReference(StringRef &ModulePath);
362 bool parseGVReference(ValueInfo &
VI,
unsigned &GVId);
363 bool parseSummaryIndexFlags();
364 bool parseBlockCount();
365 bool parseGVEntry(
unsigned ID);
369 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
370 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
371 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
372 bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
374 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
375 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
377 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
378 bool parseConstVCallList(
380 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
381 using IdToIndexMapType =
382 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
383 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
384 IdToIndexMapType &IdToIndexMap,
unsigned Index);
385 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
386 IdToIndexMapType &IdToIndexMap,
unsigned Index);
388 bool parseOptionalParamAccesses(
389 std::vector<FunctionSummary::ParamAccess> &Params);
390 bool parseParamNo(
uint64_t &ParamNo);
391 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
392 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
393 IdLocListType &IdLocList);
394 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
395 IdLocListType &IdLocList);
396 bool parseParamAccessOffset(ConstantRange &Range);
397 bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
398 bool parseTypeIdEntry(
unsigned ID);
399 bool parseTypeIdSummary(TypeIdSummary &TIS);
400 bool parseTypeIdCompatibleVtableEntry(
unsigned ID);
401 bool parseTypeTestResolution(TypeTestResolution &TTRes);
402 bool parseOptionalWpdResolutions(
403 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
404 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
405 bool parseOptionalResByArg(
406 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
408 bool parseArgs(std::vector<uint64_t> &Args);
411 std::unique_ptr<GlobalValueSummary> Summary);
412 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
413 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
415 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
418 bool parseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
419 bool parseType(
Type *&Result,
bool AllowVoid =
false) {
420 return parseType(Result,
"expected type", AllowVoid);
422 bool parseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
423 bool AllowVoid =
false) {
425 return parseType(Result, Msg, AllowVoid);
427 bool parseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
429 return parseType(Result, AllowVoid);
431 bool parseAnonStructType(
Type *&Result,
bool Packed);
432 bool parseStructBody(SmallVectorImpl<Type *> &Body);
433 bool parseStructDefinition(SMLoc TypeLoc, StringRef
Name,
434 std::pair<Type *, LocTy> &Entry,
437 bool parseArrayVectorType(
Type *&Result,
bool IsVector);
438 bool parseFunctionType(
Type *&Result);
439 bool parseTargetExtType(
Type *&Result);
442 class PerFunctionState {
445 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
446 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
447 std::vector<Value*> NumberedVals;
453 PerFunctionState(LLParser &p, Function &f,
int functionNumber);
456 Function &getFunction()
const {
return F; }
458 bool finishFunction();
468 bool setInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
482 bool resolveForwardRefBlockAddresses();
485 bool convertValIDToValue(Type *Ty, ValID &
ID, Value *&V,
486 PerFunctionState *PFS);
488 Value *checkValidVariableType(
LocTy Loc,
const Twine &
Name, Type *Ty,
491 bool parseConstantValue(Type *Ty, Constant *&
C);
492 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
493 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
494 return parseValue(Ty, V, &PFS);
497 bool parseValue(Type *Ty, Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
499 return parseValue(Ty, V, &PFS);
502 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
503 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
504 return parseTypeAndValue(V, &PFS);
506 bool parseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
508 return parseTypeAndValue(V, PFS);
510 bool parseTypeAndBasicBlock(BasicBlock *&BB,
LocTy &Loc,
511 PerFunctionState &PFS);
512 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
514 return parseTypeAndBasicBlock(BB, Loc, PFS);
521 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
522 : Loc(loc),
V(
v),
Attrs(attrs) {}
524 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
525 PerFunctionState &PFS,
bool IsMustTailCall =
false,
526 bool InVarArgsFunc =
false);
529 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
530 PerFunctionState &PFS);
532 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
533 PerFunctionState &PFS);
535 bool resolveFunctionType(Type *RetType,
536 const SmallVector<ParamInfo, 16> &ArgList,
540 bool parseValID(ValID &
ID, PerFunctionState *PFS,
541 Type *ExpectedTy =
nullptr);
542 bool parseGlobalValue(Type *Ty, Constant *&
C);
543 bool parseGlobalTypeAndValue(Constant *&V);
544 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
545 std::optional<unsigned> *InRangeOp =
nullptr);
546 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
547 bool parseSanitizer(GlobalVariable *GV);
548 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
549 bool parseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
550 PerFunctionState *PFS);
551 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
552 bool parseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
553 bool parseMDNode(MDNode *&
N);
554 bool parseMDNodeTail(MDNode *&
N);
555 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
556 bool parseMetadataAttachment(
unsigned &Kind, MDNode *&MD);
557 bool parseInstructionMetadata(Instruction &Inst);
558 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
559 bool parseOptionalFunctionMetadata(Function &
F);
561 template <
class FieldTy>
562 bool parseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
563 template <
class FieldTy>
bool parseMDField(StringRef
Name, FieldTy &Result);
564 template <
class ParserTy>
bool parseMDFieldsImplBody(ParserTy ParseField);
565 template <
class ParserTy>
566 bool parseMDFieldsImpl(ParserTy ParseField,
LocTy &ClosingLoc);
567 bool parseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
569#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
570 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
571#include "llvm/IR/Metadata.def"
572 bool parseDIArgList(MDNode *&Result,
bool IsDistinct,
573 PerFunctionState *PFS);
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::@37 Kind