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);
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);
273 bool ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
274 unsigned &
Visibility,
unsigned &DLLStorageClass,
276 void ParseOptionalDSOLocal(
bool &DSOLocal);
277 void ParseOptionalVisibility(
unsigned &Res);
278 void ParseOptionalDLLStorageClass(
unsigned &Res);
279 bool ParseOptionalCallingConv(
unsigned &CC);
280 bool ParseOptionalAlignment(
unsigned &Alignment);
281 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
286 bool ParseOptionalStackAlignment(
unsigned &Alignment);
287 bool ParseOptionalCommaAlign(
unsigned &Alignment,
bool &AteExtraComma);
288 bool ParseOptionalCommaAddrSpace(
unsigned &AddrSpace, LocTy &Loc,
289 bool &AteExtraComma);
290 bool ParseOptionalCommaInAlloca(
bool &IsInAlloca);
291 bool parseAllocSizeArguments(
unsigned &BaseSizeArg,
294 bool &AteExtraComma);
297 if (ParseIndexList(Indices, AteExtraComma))
return true;
299 return TokError(
"expected index");
304 bool ParseTopLevelEntities();
305 bool ValidateEndOfModule();
306 bool ValidateEndOfIndex();
307 bool ParseTargetDefinition();
308 bool ParseModuleAsm();
309 bool ParseSourceFileName();
311 bool ParseUnnamedType();
312 bool ParseNamedType();
316 bool ParseGlobalType(
bool &IsConstant);
317 bool ParseUnnamedGlobal();
318 bool ParseNamedGlobal();
319 bool ParseGlobal(
const std::string &Name, LocTy NameLoc,
unsigned Linkage,
320 bool HasLinkage,
unsigned Visibility,
321 unsigned DLLStorageClass,
bool DSOLocal,
324 bool parseIndirectSymbol(
const std::string &Name, LocTy NameLoc,
325 unsigned L,
unsigned Visibility,
326 unsigned DLLStorageClass,
bool DSOLocal,
330 bool ParseStandaloneMetadata();
331 bool ParseNamedMetadata();
332 bool ParseMDString(
MDString *&Result);
333 bool ParseMDNodeID(
MDNode *&Result);
334 bool ParseUnnamedAttrGrp();
336 std::vector<unsigned> &FwdRefAttrGrps,
337 bool inAttrGrp, LocTy &BuiltinLoc);
340 bool SkipModuleSummaryEntry();
341 bool ParseSummaryEntry();
342 bool ParseModuleEntry(
unsigned ID);
343 bool ParseModuleReference(
StringRef &ModulePath);
344 bool ParseGVReference(
ValueInfo &
VI,
unsigned &GVId);
345 bool ParseGVEntry(
unsigned ID);
351 bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
354 bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
356 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
357 bool ParseConstVCallList(
359 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
360 using IdToIndexMapType =
361 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
363 IdToIndexMapType &IdToIndexMap,
unsigned Index);
365 IdToIndexMapType &IdToIndexMap,
unsigned Index);
366 bool ParseOptionalRefs(std::vector<ValueInfo> &Refs);
367 bool ParseTypeIdEntry(
unsigned ID);
370 bool ParseOptionalWpdResolutions(
371 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
373 bool ParseOptionalResByArg(
376 bool ParseArgs(std::vector<uint64_t> &
Args);
379 std::unique_ptr<GlobalValueSummary> Summary);
382 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
383 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
384 return ParseType(Result,
"expected type", AllowVoid);
386 bool ParseType(
Type *&Result,
const Twine &Msg, LocTy &Loc,
387 bool AllowVoid =
false) {
389 return ParseType(Result, Msg, AllowVoid);
391 bool ParseType(
Type *&Result, LocTy &Loc,
bool AllowVoid =
false) {
393 return ParseType(Result, AllowVoid);
395 bool ParseAnonStructType(
Type *&Result,
bool Packed);
398 std::pair<Type*, LocTy> &Entry,
401 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
402 bool ParseFunctionType(
Type *&Result);
405 class PerFunctionState {
408 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
409 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
410 std::vector<Value*> NumberedVals;
421 bool FinishFunction();
426 Value *GetVal(
const std::string &Name,
Type *Ty, LocTy Loc,
bool IsCall);
427 Value *GetVal(
unsigned ID,
Type *Ty, LocTy Loc,
bool IsCall);
431 bool SetInstName(
int NameID,
const std::string &NameStr, LocTy NameLoc,
437 BasicBlock *GetBB(
const std::string &Name, LocTy Loc);
443 BasicBlock *DefineBB(
const std::string &Name, LocTy Loc);
445 bool resolveForwardRefBlockAddresses();
449 PerFunctionState *PFS,
bool IsCall);
452 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS);
453 bool ParseValue(
Type *Ty,
Value *&V, PerFunctionState &PFS) {
454 return ParseValue(Ty, V, &PFS);
457 bool ParseValue(
Type *Ty,
Value *&V, LocTy &Loc,
458 PerFunctionState &PFS) {
460 return ParseValue(Ty, V, &PFS);
463 bool ParseTypeAndValue(
Value *&V, PerFunctionState *PFS);
464 bool ParseTypeAndValue(
Value *&V, PerFunctionState &PFS) {
465 return ParseTypeAndValue(V, &PFS);
467 bool ParseTypeAndValue(
Value *&V, LocTy &Loc, PerFunctionState &PFS) {
469 return ParseTypeAndValue(V, PFS);
471 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
472 PerFunctionState &PFS);
473 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
475 return ParseTypeAndBasicBlock(BB, Loc, PFS);
487 PerFunctionState &PFS,
488 bool IsMustTailCall =
false,
489 bool InVarArgsFunc =
false);
493 PerFunctionState &PFS);
496 PerFunctionState &PFS);
499 bool ParseValID(
ValID &ID, PerFunctionState *PFS =
nullptr);
501 bool ParseGlobalTypeAndValue(
Constant *&V);
505 bool ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS);
506 bool ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
507 PerFunctionState *PFS);
508 bool ParseMetadata(
Metadata *&MD, PerFunctionState *PFS);
509 bool ParseMDTuple(
MDNode *&MD,
bool IsDistinct =
false);
511 bool ParseMDNodeTail(
MDNode *&N);
513 bool ParseMetadataAttachment(
unsigned &Kind,
MDNode *&MD);
515 bool ParseGlobalObjectMetadataAttachment(
GlobalObject &GO);
516 bool ParseOptionalFunctionMetadata(
Function &
F);
518 template <
class FieldTy>
519 bool ParseMDField(LocTy Loc,
StringRef Name, FieldTy &Result);
520 template <
class FieldTy>
bool ParseMDField(
StringRef Name, FieldTy &Result);
521 template <
class ParserTy>
522 bool ParseMDFieldsImplBody(ParserTy
parseField);
523 template <
class ParserTy>
524 bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
525 bool ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct =
false);
527 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 528 bool Parse##CLASS(MDNode *&Result, bool IsDistinct); 529 #include "llvm/IR/Metadata.def" 537 ArgInfo(LocTy L,
Type *ty, AttributeSet Attr,
const std::string &N)
540 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
541 bool ParseFunctionHeader(Function *&Fn,
bool isDefine);
542 bool ParseFunctionBody(Function &Fn);
543 bool ParseBasicBlock(PerFunctionState &PFS);
545 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
549 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
550 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
551 PerFunctionState &PFS);
552 bool ParseCmpPredicate(
unsigned &
P,
unsigned Opc);
554 bool ParseRet(Instruction *&Inst,
BasicBlock *BB, PerFunctionState &PFS);
555 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
556 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
557 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
558 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
559 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
560 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
561 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
562 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
563 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
564 bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
566 bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc,
568 bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
569 bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
570 bool ParseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc);
571 bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS);
572 bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS);
573 bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
574 bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
575 bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
576 int ParsePHI(Instruction *&Inst, PerFunctionState &PFS);
577 bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
578 bool ParseCall(Instruction *&Inst, PerFunctionState &PFS,
580 int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS);
581 int ParseLoad(Instruction *&Inst, PerFunctionState &PFS);
582 int ParseStore(Instruction *&Inst, PerFunctionState &PFS);
583 int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
584 int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
585 int ParseFence(Instruction *&Inst, PerFunctionState &PFS);
586 int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
587 int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
588 int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
591 bool ParseUseListOrder(PerFunctionState *PFS =
nullptr);
592 bool ParseUseListOrderBB();
593 bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
594 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.
Compute iterated dominance frontiers using a linear time algorithm.
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
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.
enum llvm::ValID::@311 Kind
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
void setApproxFunc(bool B=true)
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)
Function attribute flags.
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.
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)