14 #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H 15 #define LLVM_LIB_ASMPARSER_LLPARSER_H 72 : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy),
73 StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal),
83 "Ordering not defined for this ValID kind yet");
84 return StrVal < RHS.
StrVal;
112 unsigned MDKind, MDSlot;
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;
143 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
144 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
147 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
148 ForwardRefValueInfos;
149 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
151 std::vector<ValueInfo> NumberedValueInfos;
154 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
158 std::map<unsigned, StringRef> ModuleIdMap;
167 std::string SourceFileName;
172 SlotMapping *Slots =
nullptr,
bool UpgradeDebugInfo =
true,
174 : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index),
175 Slots(Slots), BlockAddressPFS(nullptr),
176 UpgradeDebugInfo(UpgradeDebugInfo), DataLayoutStr(DataLayoutString) {
177 if (!DataLayoutStr.
empty())
192 return Lex.
Error(L, Msg);
194 bool TokError(
const Twine &Msg)
const {
200 void restoreParsingState(
const SlotMapping *Slots);
211 Comdat *getComdat(
const std::string &
Name, LocTy Loc);
216 if (Lex.
getKind() !=
T)
return false;
241 bool ParseOptionalToken(
lltok::Kind T,
bool &Present,
242 LocTy *Loc =
nullptr) {
253 bool ParseStringConstant(std::string &Result);
254 bool ParseUInt32(
unsigned &Val);
255 bool ParseUInt32(
unsigned &Val, LocTy &Loc) {
257 return ParseUInt32(Val);
259 bool ParseUInt64(uint64_t &Val);
260 bool ParseUInt64(uint64_t &Val, LocTy &Loc) {
262 return ParseUInt64(Val);
264 bool ParseFlag(
unsigned &Val);
271 bool ParseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS = 0);
272 bool ParseOptionalProgramAddrSpace(
unsigned &AddrSpace) {
273 return ParseOptionalAddrSpace(
278 bool ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
279 unsigned &
Visibility,
unsigned &DLLStorageClass,
281 void ParseOptionalDSOLocal(
bool &DSOLocal);
282 void ParseOptionalVisibility(
unsigned &Res);
283 void ParseOptionalDLLStorageClass(
unsigned &Res);
284 bool ParseOptionalCallingConv(
unsigned &CC);
285 bool ParseOptionalAlignment(
unsigned &Alignment);
286 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
291 bool ParseOptionalStackAlignment(
unsigned &Alignment);
292 bool ParseOptionalCommaAlign(
unsigned &Alignment,
bool &AteExtraComma);
293 bool ParseOptionalCommaAddrSpace(
unsigned &AddrSpace, LocTy &Loc,
294 bool &AteExtraComma);
295 bool ParseOptionalCommaInAlloca(
bool &IsInAlloca);
296 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
299 bool &AteExtraComma);
302 if (ParseIndexList(Indices, AteExtraComma))
return true;
304 return TokError(
"expected index");
309 bool ParseTopLevelEntities();
310 bool ValidateEndOfModule();
311 bool ValidateEndOfIndex();
312 bool ParseTargetDefinition();
313 bool ParseModuleAsm();
314 bool ParseSourceFileName();
316 bool ParseUnnamedType();
317 bool ParseNamedType();
321 bool ParseGlobalType(
bool &IsConstant);
322 bool ParseUnnamedGlobal();
323 bool ParseNamedGlobal();
324 bool ParseGlobal(
const std::string &Name, LocTy NameLoc,
unsigned Linkage,
325 bool HasLinkage,
unsigned Visibility,
326 unsigned DLLStorageClass,
bool DSOLocal,
329 bool parseIndirectSymbol(
const std::string &Name, LocTy NameLoc,
330 unsigned L,
unsigned Visibility,
331 unsigned DLLStorageClass,
bool DSOLocal,
335 bool ParseStandaloneMetadata();
336 bool ParseNamedMetadata();
337 bool ParseMDString(
MDString *&Result);
338 bool ParseMDNodeID(
MDNode *&Result);
339 bool ParseUnnamedAttrGrp();
341 std::vector<unsigned> &FwdRefAttrGrps,
342 bool inAttrGrp, LocTy &BuiltinLoc);
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);
372 bool ParseOptionalRefs(std::vector<ValueInfo> &Refs);
373 bool ParseTypeIdEntry(
unsigned ID);
376 bool ParseOptionalWpdResolutions(
377 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
379 bool ParseOptionalResByArg(
382 bool ParseArgs(std::vector<uint64_t> &
Args);
385 std::unique_ptr<GlobalValueSummary> Summary);
388 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
389 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
390 return ParseType(Result,
"expected type", AllowVoid);
392 bool ParseType(
Type *&Result,
const Twine &Msg, LocTy &Loc,
393 bool AllowVoid =
false) {
395 return ParseType(Result, Msg, AllowVoid);
397 bool ParseType(
Type *&Result, LocTy &Loc,
bool AllowVoid =
false) {
399 return ParseType(Result, AllowVoid);
401 bool ParseAnonStructType(
Type *&Result,
bool Packed);
404 std::pair<Type*, LocTy> &Entry,
407 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
408 bool ParseFunctionType(
Type *&Result);
411 class PerFunctionState {
414 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
415 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
416 std::vector<Value*> NumberedVals;
427 bool FinishFunction();
432 Value *GetVal(
const std::string &Name,
Type *Ty, LocTy Loc,
bool IsCall);
433 Value *GetVal(
unsigned ID,
Type *Ty, LocTy Loc,
bool IsCall);
437 bool SetInstName(
int NameID,
const std::string &NameStr, LocTy NameLoc,
443 BasicBlock *GetBB(
const std::string &Name, LocTy Loc);
449 BasicBlock *DefineBB(
const std::string &Name, LocTy Loc);
451 bool resolveForwardRefBlockAddresses();
455 PerFunctionState *PFS,
bool IsCall);
457 Value *checkValidVariableType(LocTy Loc,
const Twine &Name,
Type *Ty,
458 Value *Val,
bool IsCall);
461 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS);
462 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState &PFS) {
463 return ParseValue(Ty, V, &PFS);
466 bool ParseValue(
Type *Ty,
Value *&V, LocTy &Loc,
467 PerFunctionState &PFS) {
469 return ParseValue(Ty, V, &PFS);
472 bool ParseTypeAndValue(
Value *&V, PerFunctionState *PFS);
473 bool ParseTypeAndValue(
Value *&V, PerFunctionState &PFS) {
474 return ParseTypeAndValue(V, &PFS);
476 bool ParseTypeAndValue(
Value *&V, LocTy &Loc, PerFunctionState &PFS) {
478 return ParseTypeAndValue(V, PFS);
480 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
481 PerFunctionState &PFS);
482 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
484 return ParseTypeAndBasicBlock(BB, Loc, PFS);
496 PerFunctionState &PFS,
497 bool IsMustTailCall =
false,
498 bool InVarArgsFunc =
false);
502 PerFunctionState &PFS);
505 PerFunctionState &PFS);
508 bool ParseValID(
ValID &ID, PerFunctionState *PFS =
nullptr);
510 bool ParseGlobalTypeAndValue(
Constant *&V);
514 bool ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS);
515 bool ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
516 PerFunctionState *PFS);
517 bool ParseMetadata(
Metadata *&MD, PerFunctionState *PFS);
518 bool ParseMDTuple(
MDNode *&MD,
bool IsDistinct =
false);
519 bool ParseMDNode(
MDNode *&N);
520 bool ParseMDNodeTail(
MDNode *&N);
522 bool ParseMetadataAttachment(
unsigned &Kind,
MDNode *&MD);
524 bool ParseGlobalObjectMetadataAttachment(
GlobalObject &GO);
525 bool ParseOptionalFunctionMetadata(
Function &
F);
527 template <
class FieldTy>
528 bool ParseMDField(LocTy Loc,
StringRef Name, FieldTy &Result);
529 template <
class FieldTy>
bool ParseMDField(
StringRef Name, FieldTy &Result);
530 template <
class ParserTy>
531 bool ParseMDFieldsImplBody(ParserTy
parseField);
532 template <
class ParserTy>
533 bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
534 bool ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct =
false);
536 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 537 bool Parse##CLASS(MDNode *&Result, bool IsDistinct); 538 #include "llvm/IR/Metadata.def" 546 ArgInfo(LocTy L, Type *ty, AttributeSet Attr,
const std::string &N)
549 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
550 bool ParseFunctionHeader(Function *&Fn,
bool isDefine);
551 bool ParseFunctionBody(Function &Fn);
552 bool ParseBasicBlock(PerFunctionState &PFS);
554 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
558 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
559 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
560 PerFunctionState &PFS);
561 bool ParseCmpPredicate(
unsigned &
P,
unsigned Opc);
563 bool ParseRet(Instruction *&Inst,
BasicBlock *BB, PerFunctionState &PFS);
564 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
565 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
566 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
567 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
568 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
569 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
570 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
571 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
572 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
573 bool ParseCleanupPad(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. ...
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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...
AtomicOrdering
Atomic ordering for LLVM's memory model.
Class to represent function types.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
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)