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(
MaybeAlign &Alignment);
285 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
290 bool ParseOptionalStackAlignment(
unsigned &Alignment);
291 bool ParseOptionalCommaAlign(
MaybeAlign &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);
342 bool ParseByValWithOptionalType(
Type *&Result);
345 bool SkipModuleSummaryEntry();
346 bool ParseSummaryEntry();
347 bool ParseModuleEntry(
unsigned ID);
348 bool ParseModuleReference(
StringRef &ModulePath);
349 bool ParseGVReference(
ValueInfo &
VI,
unsigned &GVId);
350 bool ParseGVEntry(
unsigned ID);
357 bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
360 bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
362 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
363 bool ParseConstVCallList(
365 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
366 using IdToIndexMapType =
367 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
369 IdToIndexMapType &IdToIndexMap,
unsigned Index);
371 IdToIndexMapType &IdToIndexMap,
unsigned Index);
373 bool ParseOptionalRefs(std::vector<ValueInfo> &Refs);
374 bool ParseTypeIdEntry(
unsigned ID);
376 bool ParseTypeIdCompatibleVtableEntry(
unsigned ID);
378 bool ParseOptionalWpdResolutions(
379 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
381 bool ParseOptionalResByArg(
384 bool ParseArgs(std::vector<uint64_t> &
Args);
387 std::unique_ptr<GlobalValueSummary> Summary);
390 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
391 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
392 return ParseType(Result,
"expected type", AllowVoid);
394 bool ParseType(
Type *&Result,
const Twine &Msg, LocTy &Loc,
395 bool AllowVoid =
false) {
397 return ParseType(Result, Msg, AllowVoid);
399 bool ParseType(
Type *&Result, LocTy &Loc,
bool AllowVoid =
false) {
401 return ParseType(Result, AllowVoid);
403 bool ParseAnonStructType(
Type *&Result,
bool Packed);
406 std::pair<Type*, LocTy> &
Entry,
409 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
410 bool ParseFunctionType(
Type *&Result);
413 class PerFunctionState {
416 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
417 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
418 std::vector<Value*> NumberedVals;
429 bool FinishFunction();
434 Value *GetVal(
const std::string &Name,
Type *Ty, LocTy Loc,
bool IsCall);
435 Value *GetVal(
unsigned ID,
Type *Ty, LocTy Loc,
bool IsCall);
439 bool SetInstName(
int NameID,
const std::string &NameStr, LocTy NameLoc,
445 BasicBlock *GetBB(
const std::string &Name, LocTy Loc);
451 BasicBlock *DefineBB(
const std::string &Name,
int NameID, LocTy Loc);
453 bool resolveForwardRefBlockAddresses();
457 PerFunctionState *PFS,
bool IsCall);
459 Value *checkValidVariableType(LocTy Loc,
const Twine &Name,
Type *Ty,
460 Value *Val,
bool IsCall);
463 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS);
464 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState &PFS) {
465 return ParseValue(Ty, V, &PFS);
468 bool ParseValue(
Type *Ty,
Value *&V, LocTy &Loc,
469 PerFunctionState &PFS) {
471 return ParseValue(Ty, V, &PFS);
474 bool ParseTypeAndValue(
Value *&V, PerFunctionState *PFS);
475 bool ParseTypeAndValue(
Value *&V, PerFunctionState &PFS) {
476 return ParseTypeAndValue(V, &PFS);
478 bool ParseTypeAndValue(
Value *&V, LocTy &Loc, PerFunctionState &PFS) {
480 return ParseTypeAndValue(V, PFS);
482 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
483 PerFunctionState &PFS);
484 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
486 return ParseTypeAndBasicBlock(BB, Loc, PFS);
498 PerFunctionState &PFS,
499 bool IsMustTailCall =
false,
500 bool InVarArgsFunc =
false);
504 PerFunctionState &PFS);
507 PerFunctionState &PFS);
510 bool ParseValID(
ValID &ID, PerFunctionState *PFS =
nullptr);
512 bool ParseGlobalTypeAndValue(
Constant *&V);
516 bool ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS);
517 bool ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
518 PerFunctionState *PFS);
519 bool ParseMetadata(
Metadata *&MD, PerFunctionState *PFS);
520 bool ParseMDTuple(
MDNode *&MD,
bool IsDistinct =
false);
521 bool ParseMDNode(
MDNode *&N);
522 bool ParseMDNodeTail(
MDNode *&N);
524 bool ParseMetadataAttachment(
unsigned &Kind,
MDNode *&MD);
526 bool ParseGlobalObjectMetadataAttachment(
GlobalObject &GO);
527 bool ParseOptionalFunctionMetadata(
Function &
F);
529 template <
class FieldTy>
530 bool ParseMDField(LocTy Loc,
StringRef Name, FieldTy &Result);
531 template <
class FieldTy>
bool ParseMDField(
StringRef Name, FieldTy &Result);
532 template <
class ParserTy>
533 bool ParseMDFieldsImplBody(ParserTy
parseField);
534 template <
class ParserTy>
535 bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
536 bool ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct =
false);
538 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 539 bool Parse##CLASS(MDNode *&Result, bool IsDistinct); 540 #include "llvm/IR/Metadata.def" 548 ArgInfo(LocTy L, Type *ty, AttributeSet Attr,
const std::string &N)
551 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
552 bool ParseFunctionHeader(Function *&Fn,
bool isDefine);
553 bool ParseFunctionBody(Function &Fn);
554 bool ParseBasicBlock(PerFunctionState &PFS);
556 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
560 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
561 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
562 PerFunctionState &PFS);
563 bool ParseCmpPredicate(
unsigned &
P,
unsigned Opc);
566 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
567 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
568 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
569 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
570 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
571 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
572 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
573 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
574 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
575 bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
576 bool ParseCallBr(Instruction *&Inst, PerFunctionState &PFS);
578 bool ParseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
580 bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
582 bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
583 bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
584 bool ParseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
585 bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS);
586 bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS);
587 bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
588 bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
589 bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
590 int ParsePHI(Instruction *&Inst, PerFunctionState &PFS);
591 bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
592 bool ParseCall(Instruction *&Inst, PerFunctionState &PFS,
594 int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS);
595 int ParseLoad(Instruction *&Inst, PerFunctionState &PFS);
596 int ParseStore(Instruction *&Inst, PerFunctionState &PFS);
597 int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
598 int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
599 int ParseFence(Instruction *&Inst, PerFunctionState &PFS);
600 int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
601 int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
602 int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
603 bool ParseFreeze(Instruction *&
I, PerFunctionState &PFS);
606 bool ParseUseListOrder(PerFunctionState *PFS =
nullptr);
607 bool ParseUseListOrderBB();
608 bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
609 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)
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)
enum llvm::ValID::@356 Kind
An "identifier" for a virtual function.
Struct that holds a reference to a particular GUID in a global value summary.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
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)
ValID - Represents a reference of a definition of some sort with no type.
Linkage
Describes symbol linkage.
void setAllowContract(bool B=true)
ParseRet
Utilities for the Vector Function ABI name parser.
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())
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
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.
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)