13 #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H 14 #define LLVM_LIB_ASMPARSER_LLPARSER_H 71 : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy),
72 StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal),
82 "Ordering not defined for this ValID kind yet");
83 return StrVal < RHS.
StrVal;
111 unsigned MDKind, MDSlot;
119 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
121 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
122 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
125 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
126 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
127 std::vector<GlobalValue*> NumberedVals;
130 std::map<std::string, LocTy> ForwardRefComdats;
134 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
135 class PerFunctionState;
139 PerFunctionState *BlockAddressPFS;
142 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
143 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
146 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
147 ForwardRefValueInfos;
148 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
150 std::vector<ValueInfo> NumberedValueInfos;
153 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
157 std::map<unsigned, StringRef> ModuleIdMap;
166 std::string SourceFileName;
171 SlotMapping *Slots =
nullptr,
bool UpgradeDebugInfo =
true,
173 : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index),
174 Slots(Slots), BlockAddressPFS(nullptr),
175 UpgradeDebugInfo(UpgradeDebugInfo), DataLayoutStr(DataLayoutString) {
176 if (!DataLayoutStr.
empty())
191 return Lex.
Error(L, Msg);
193 bool TokError(
const Twine &Msg)
const {
199 void restoreParsingState(
const SlotMapping *Slots);
210 Comdat *getComdat(
const std::string &
Name, LocTy Loc);
215 if (Lex.
getKind() !=
T)
return false;
240 bool ParseOptionalToken(
lltok::Kind T,
bool &Present,
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);
258 bool ParseUInt64(uint64_t &Val);
259 bool ParseUInt64(uint64_t &Val, LocTy &Loc) {
261 return ParseUInt64(Val);
263 bool ParseFlag(
unsigned &Val);
270 bool ParseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
271 bool ParseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
272 return ParseOptionalAddrSpace(
277 bool ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
278 unsigned &
Visibility,
unsigned &DLLStorageClass,
280 void ParseOptionalDSOLocal(
bool &DSOLocal);
281 void ParseOptionalVisibility(
unsigned &Res);
282 void ParseOptionalDLLStorageClass(
unsigned &Res);
283 bool ParseOptionalCallingConv(
unsigned &CC);
284 bool ParseOptionalAlignment(
unsigned &Alignment);
285 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
290 bool ParseOptionalStackAlignment(
unsigned &Alignment);
291 bool ParseOptionalCommaAlign(
unsigned &Alignment,
bool &AteExtraComma);
292 bool ParseOptionalCommaAddrSpace(
unsigned &AddrSpace, LocTy &Loc,
293 bool &AteExtraComma);
294 bool ParseOptionalCommaInAlloca(
bool &IsInAlloca);
295 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
298 bool &AteExtraComma);
301 if (ParseIndexList(Indices, AteExtraComma))
return true;
303 return TokError(
"expected index");
308 bool ParseTopLevelEntities();
309 bool ValidateEndOfModule();
310 bool ValidateEndOfIndex();
311 bool ParseTargetDefinition();
312 bool ParseModuleAsm();
313 bool ParseSourceFileName();
315 bool ParseUnnamedType();
316 bool ParseNamedType();
320 bool ParseGlobalType(
bool &IsConstant);
321 bool ParseUnnamedGlobal();
322 bool ParseNamedGlobal();
323 bool ParseGlobal(
const std::string &Name, LocTy NameLoc,
unsigned Linkage,
324 bool HasLinkage,
unsigned Visibility,
325 unsigned DLLStorageClass,
bool DSOLocal,
328 bool parseIndirectSymbol(
const std::string &Name, LocTy NameLoc,
329 unsigned L,
unsigned Visibility,
330 unsigned DLLStorageClass,
bool DSOLocal,
334 bool ParseStandaloneMetadata();
335 bool ParseNamedMetadata();
336 bool ParseMDString(
MDString *&Result);
337 bool ParseMDNodeID(
MDNode *&Result);
338 bool ParseUnnamedAttrGrp();
340 std::vector<unsigned> &FwdRefAttrGrps,
341 bool inAttrGrp, LocTy &BuiltinLoc);
344 bool SkipModuleSummaryEntry();
345 bool ParseSummaryEntry();
346 bool ParseModuleEntry(
unsigned ID);
347 bool ParseModuleReference(
StringRef &ModulePath);
348 bool ParseGVReference(
ValueInfo &
VI,
unsigned &GVId);
349 bool ParseGVEntry(
unsigned ID);
356 bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
359 bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
361 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
362 bool ParseConstVCallList(
364 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
365 using IdToIndexMapType =
366 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
368 IdToIndexMapType &IdToIndexMap,
unsigned Index);
370 IdToIndexMapType &IdToIndexMap,
unsigned Index);
371 bool ParseOptionalRefs(std::vector<ValueInfo> &Refs);
372 bool ParseTypeIdEntry(
unsigned ID);
375 bool ParseOptionalWpdResolutions(
376 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
378 bool ParseOptionalResByArg(
381 bool ParseArgs(std::vector<uint64_t> &
Args);
384 std::unique_ptr<GlobalValueSummary> Summary);
387 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
388 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
389 return ParseType(Result,
"expected type", AllowVoid);
391 bool ParseType(
Type *&Result,
const Twine &Msg, LocTy &Loc,
392 bool AllowVoid =
false) {
394 return ParseType(Result, Msg, AllowVoid);
396 bool ParseType(
Type *&Result, LocTy &Loc,
bool AllowVoid =
false) {
398 return ParseType(Result, AllowVoid);
400 bool ParseAnonStructType(
Type *&Result,
bool Packed);
403 std::pair<Type*, LocTy> &Entry,
406 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
407 bool ParseFunctionType(
Type *&Result);
410 class PerFunctionState {
413 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
414 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
415 std::vector<Value*> NumberedVals;
426 bool FinishFunction();
431 Value *GetVal(
const std::string &Name,
Type *Ty, LocTy Loc,
bool IsCall);
432 Value *GetVal(
unsigned ID,
Type *Ty, LocTy Loc,
bool IsCall);
436 bool SetInstName(
int NameID,
const std::string &NameStr, LocTy NameLoc,
442 BasicBlock *GetBB(
const std::string &Name, LocTy Loc);
448 BasicBlock *DefineBB(
const std::string &Name, LocTy Loc);
450 bool resolveForwardRefBlockAddresses();
454 PerFunctionState *PFS,
bool IsCall);
456 Value *checkValidVariableType(LocTy Loc,
const Twine &Name,
Type *Ty,
457 Value *Val,
bool IsCall);
460 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS);
461 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState &PFS) {
462 return ParseValue(Ty, V, &PFS);
465 bool ParseValue(
Type *Ty,
Value *&V, LocTy &Loc,
466 PerFunctionState &PFS) {
468 return ParseValue(Ty, V, &PFS);
471 bool ParseTypeAndValue(
Value *&V, PerFunctionState *PFS);
472 bool ParseTypeAndValue(
Value *&V, PerFunctionState &PFS) {
473 return ParseTypeAndValue(V, &PFS);
475 bool ParseTypeAndValue(
Value *&V, LocTy &Loc, PerFunctionState &PFS) {
477 return ParseTypeAndValue(V, PFS);
479 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
480 PerFunctionState &PFS);
481 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
483 return ParseTypeAndBasicBlock(BB, Loc, PFS);
495 PerFunctionState &PFS,
496 bool IsMustTailCall =
false,
497 bool InVarArgsFunc =
false);
501 PerFunctionState &PFS);
504 PerFunctionState &PFS);
507 bool ParseValID(
ValID &ID, PerFunctionState *PFS =
nullptr);
509 bool ParseGlobalTypeAndValue(
Constant *&V);
513 bool ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS);
514 bool ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
515 PerFunctionState *PFS);
516 bool ParseMetadata(
Metadata *&MD, PerFunctionState *PFS);
517 bool ParseMDTuple(
MDNode *&MD,
bool IsDistinct =
false);
518 bool ParseMDNode(
MDNode *&N);
519 bool ParseMDNodeTail(
MDNode *&N);
521 bool ParseMetadataAttachment(
unsigned &Kind,
MDNode *&MD);
523 bool ParseGlobalObjectMetadataAttachment(
GlobalObject &GO);
524 bool ParseOptionalFunctionMetadata(
Function &
F);
526 template <
class FieldTy>
527 bool ParseMDField(LocTy Loc,
StringRef Name, FieldTy &Result);
528 template <
class FieldTy>
bool ParseMDField(
StringRef Name, FieldTy &Result);
529 template <
class ParserTy>
530 bool ParseMDFieldsImplBody(ParserTy
parseField);
531 template <
class ParserTy>
532 bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
533 bool ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct =
false);
535 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 536 bool Parse##CLASS(MDNode *&Result, bool IsDistinct); 537 #include "llvm/IR/Metadata.def" 545 ArgInfo(LocTy L, Type *ty, AttributeSet Attr,
const std::string &N)
548 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
549 bool ParseFunctionHeader(Function *&Fn,
bool isDefine);
550 bool ParseFunctionBody(Function &Fn);
551 bool ParseBasicBlock(PerFunctionState &PFS);
553 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
557 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
558 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
559 PerFunctionState &PFS);
560 bool ParseCmpPredicate(
unsigned &
P,
unsigned Opc);
562 bool ParseRet(Instruction *&Inst,
BasicBlock *BB, PerFunctionState &PFS);
563 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
564 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
565 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
566 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
567 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
568 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
569 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
570 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
571 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
572 bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
573 bool ParseCallBr(Instruction *&Inst, PerFunctionState &PFS);
575 bool ParseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
577 bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
578 unsigned OperandType);
579 bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
580 bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
581 bool ParseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
582 bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS);
583 bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS);
584 bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
585 bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
586 bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
587 int ParsePHI(Instruction *&Inst, PerFunctionState &PFS);
588 bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
589 bool ParseCall(Instruction *&Inst, PerFunctionState &PFS,
591 int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS);
592 int ParseLoad(Instruction *&Inst, PerFunctionState &PFS);
593 int ParseStore(Instruction *&Inst, PerFunctionState &PFS);
594 int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
595 int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
596 int ParseFence(Instruction *&Inst, PerFunctionState &PFS);
597 int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
598 int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
599 int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
602 bool ParseUseListOrder(PerFunctionState *PFS =
nullptr);
603 bool ParseUseListOrderBB();
604 bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
605 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
void setFast(bool B=true)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This class represents lattice values for constants.
Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool operator<(const ValID &RHS) const
LLVMContext & getContext()
void setDataLayout(StringRef Desc)
Set the data layout.
void setNoInfs(bool B=true)
ELFYAML::ELF_STV Visibility
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
AtomicOrdering
Atomic ordering for LLVM's memory model.
Class to represent function types.
Type * parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a string Asm that starts with a type.
static Function * getFunction(Constant *C)
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setNoSignedZeros(bool B=true)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This is an important base class in LLVM.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
All type identifier related information.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
lltok::Kind getKind() const
static bool isAtomic(Instruction *I)
An "identifier" for a virtual function.
Struct that holds a reference to a particular GUID in a global value summary.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
void setApproxFunc(bool B=true)
unsigned getProgramAddressSpace() const
void setNoNaNs(bool B=true)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
A specification for a virtual function call with all constant integer arguments.
LinkageTypes
An enumeration for the kinds of linkage for global values.
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, ModuleSummaryIndex *Index, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
FunctionNumber(functionNumber)
OperandType
Operands are tagged with one of the values of this enum.
ValID - Represents a reference of a definition of some sort with no type.
void setAllowContract(bool B=true)
std::unique_ptr< Constant *[]> ConstantStructElts
void setAllowReciprocal(bool B=true)
Flags specific to function summaries.
bool Error(LocTy ErrorLoc, const Twine &Msg) const
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
void setAllowReassoc(bool B=true)
Flag setters.
enum llvm::ValID::@335 Kind
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
static bool parseField(amd_kernel_code_t &C, MCAsmParser &MCParser, raw_ostream &Err)