14 #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H
15 #define LLVM_LIB_ASMPARSER_LLPARSER_H
82 "Ordering not defined for this ValID kind yet");
108 unsigned MDKind, MDSlot;
116 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
118 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
119 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
122 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
123 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
124 std::vector<GlobalValue*> NumberedVals;
127 std::map<std::string, LocTy> ForwardRefComdats;
131 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
132 class PerFunctionState;
136 PerFunctionState *BlockAddressPFS;
139 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
140 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
146 Slots(Slots), BlockAddressPFS(nullptr) {}
159 return Lex.
Error(L, Msg);
161 bool TokError(
const Twine &Msg)
const {
167 void restoreParsingState(
const SlotMapping *Slots);
172 GlobalValue *GetGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
173 GlobalValue *GetGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
177 Comdat *getComdat(
const std::string &
N,
LocTy Loc);
182 if (Lex.
getKind() !=
T)
return false;
187 FastMathFlags EatFastMathFlagsIfPresent() {
201 bool ParseOptionalToken(
lltok::Kind T,
bool &Present,
202 LocTy *Loc =
nullptr) {
213 bool ParseStringConstant(std::string &Result);
214 bool ParseUInt32(
unsigned &Val);
215 bool ParseUInt32(
unsigned &Val,
LocTy &Loc) {
217 return ParseUInt32(Val);
219 bool ParseUInt64(uint64_t &Val);
220 bool ParseUInt64(uint64_t &Val,
LocTy &Loc) {
222 return ParseUInt64(Val);
225 bool ParseStringAttribute(AttrBuilder &
B);
230 bool ParseOptionalAddrSpace(
unsigned &AddrSpace);
231 bool ParseOptionalParamAttrs(AttrBuilder &
B);
232 bool ParseOptionalReturnAttrs(AttrBuilder &
B);
233 bool ParseOptionalLinkage(
unsigned &Linkage,
bool &HasLinkage,
234 unsigned &
Visibility,
unsigned &DLLStorageClass);
235 void ParseOptionalVisibility(
unsigned &
Visibility);
236 void ParseOptionalDLLStorageClass(
unsigned &DLLStorageClass);
237 bool ParseOptionalCallingConv(
unsigned &CC);
238 bool ParseOptionalAlignment(
unsigned &Alignment);
239 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
243 bool ParseOptionalStackAlignment(
unsigned &Alignment);
244 bool ParseOptionalCommaAlign(
unsigned &Alignment,
bool &AteExtraComma);
245 bool ParseOptionalCommaInAlloca(
bool &IsInAlloca);
246 bool parseAllocSizeArguments(
unsigned &ElemSizeArg,
247 Optional<unsigned> &HowManyArg);
248 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,
249 bool &AteExtraComma);
250 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
252 if (ParseIndexList(Indices, AteExtraComma))
return true;
254 return TokError(
"expected index");
259 bool ParseTopLevelEntities();
260 bool ValidateEndOfModule();
261 bool ParseTargetDefinition();
262 bool ParseModuleAsm();
263 bool ParseSourceFileName();
265 bool ParseUnnamedType();
266 bool ParseNamedType();
270 bool ParseGlobalType(
bool &IsConstant);
271 bool ParseUnnamedGlobal();
272 bool ParseNamedGlobal();
273 bool ParseGlobal(
const std::string &
Name,
LocTy Loc,
unsigned Linkage,
275 unsigned DLLStorageClass,
278 bool parseIndirectSymbol(
const std::string &
Name,
LocTy Loc,
280 unsigned DLLStorageClass,
284 bool ParseStandaloneMetadata();
285 bool ParseNamedMetadata();
286 bool ParseMDString(MDString *&Result);
287 bool ParseMDNodeID(MDNode *&Result);
288 bool ParseUnnamedAttrGrp();
289 bool ParseFnAttributeValuePairs(AttrBuilder &
B,
290 std::vector<unsigned> &FwdRefAttrGrps,
291 bool inAttrGrp,
LocTy &BuiltinLoc);
294 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
295 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
296 return ParseType(Result,
"expected type", AllowVoid);
298 bool ParseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
299 bool AllowVoid =
false) {
301 return ParseType(Result, Msg, AllowVoid);
303 bool ParseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
305 return ParseType(Result, AllowVoid);
307 bool ParseAnonStructType(
Type *&Result,
bool Packed);
308 bool ParseStructBody(SmallVectorImpl<Type*> &Body);
309 bool ParseStructDefinition(SMLoc TypeLoc, StringRef
Name,
310 std::pair<Type*, LocTy> &Entry,
313 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
314 bool ParseFunctionType(
Type *&Result);
317 class PerFunctionState {
320 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
321 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
322 std::vector<Value*> NumberedVals;
331 Function &getFunction()
const {
return F; }
333 bool FinishFunction();
343 bool SetInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
357 bool resolveForwardRefBlockAddresses();
360 bool ConvertValIDToValue(
Type *Ty, ValID &
ID, Value *&V,
361 PerFunctionState *PFS);
363 bool parseConstantValue(
Type *Ty, Constant *&
C);
364 bool ParseValue(
Type *Ty, Value *&V, PerFunctionState *PFS);
365 bool ParseValue(
Type *Ty, Value *&V, PerFunctionState &PFS) {
366 return ParseValue(Ty, V, &PFS);
369 bool ParseValue(
Type *Ty, Value *&V,
LocTy &Loc,
370 PerFunctionState &PFS) {
372 return ParseValue(Ty, V, &PFS);
375 bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
376 bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
377 return ParseTypeAndValue(V, &PFS);
379 bool ParseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
381 return ParseTypeAndValue(V, PFS);
384 PerFunctionState &PFS);
385 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
387 return ParseTypeAndBasicBlock(BB, Loc, PFS);
395 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
396 : Loc(loc), V(v), Attrs(attrs) {}
398 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
399 PerFunctionState &PFS,
400 bool IsMustTailCall =
false,
401 bool InVarArgsFunc =
false);
404 ParseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
405 PerFunctionState &PFS);
407 bool ParseExceptionArgs(SmallVectorImpl<Value *> &
Args,
408 PerFunctionState &PFS);
411 bool ParseValID(ValID &
ID, PerFunctionState *PFS =
nullptr);
412 bool ParseGlobalValue(
Type *Ty, Constant *&V);
413 bool ParseGlobalTypeAndValue(Constant *&V);
414 bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
415 Optional<unsigned> *InRangeOp =
nullptr);
416 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
417 bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS);
418 bool ParseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
419 PerFunctionState *PFS);
420 bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS);
421 bool ParseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
422 bool ParseMDNode(MDNode *&MD);
423 bool ParseMDNodeTail(MDNode *&MD);
424 bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs);
425 bool ParseMetadataAttachment(
unsigned &
Kind, MDNode *&MD);
426 bool ParseInstructionMetadata(Instruction &Inst);
427 bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO);
428 bool ParseOptionalFunctionMetadata(Function &
F);
430 template <
class FieldTy>
431 bool ParseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
432 template <
class FieldTy>
bool ParseMDField(StringRef
Name, FieldTy &Result);
433 template <
class ParserTy>
434 bool ParseMDFieldsImplBody(ParserTy
parseField);
435 template <
class ParserTy>
437 bool ParseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
439 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
440 bool Parse##CLASS(MDNode *&Result, bool IsDistinct);
441 #include "llvm/IR/Metadata.def"
449 ArgInfo(
LocTy L,
Type *ty, AttributeSet Attr,
const std::string &
N)
450 : Loc(L), Ty(ty), Attrs(Attr),
Name(N) {}
452 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
453 bool ParseFunctionHeader(Function *&Fn,
bool isDefine);
454 bool ParseFunctionBody(Function &Fn);
455 bool ParseBasicBlock(PerFunctionState &PFS);
457 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
461 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
462 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
463 PerFunctionState &PFS);
464 bool ParseCmpPredicate(
unsigned &Pred,
unsigned Opc);
466 bool ParseRet(Instruction *&Inst,
BasicBlock *BB, PerFunctionState &PFS);
467 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
468 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
469 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
470 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
471 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
472 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
473 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
474 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
475 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
476 bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
478 bool ParseArithmetic(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc,
480 bool ParseLogical(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
481 bool ParseCompare(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
482 bool ParseCast(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
483 bool ParseSelect(Instruction *&
I, PerFunctionState &PFS);
484 bool ParseVA_Arg(Instruction *&
I, PerFunctionState &PFS);
485 bool ParseExtractElement(Instruction *&
I, PerFunctionState &PFS);
486 bool ParseInsertElement(Instruction *&
I, PerFunctionState &PFS);
487 bool ParseShuffleVector(Instruction *&
I, PerFunctionState &PFS);
488 int ParsePHI(Instruction *&
I, PerFunctionState &PFS);
489 bool ParseLandingPad(Instruction *&
I, PerFunctionState &PFS);
490 bool ParseCall(Instruction *&
I, PerFunctionState &PFS,
492 int ParseAlloc(Instruction *&
I, PerFunctionState &PFS);
493 int ParseLoad(Instruction *&
I, PerFunctionState &PFS);
494 int ParseStore(Instruction *&
I, PerFunctionState &PFS);
495 int ParseCmpXchg(Instruction *&
I, PerFunctionState &PFS);
496 int ParseAtomicRMW(Instruction *&
I, PerFunctionState &PFS);
497 int ParseFence(Instruction *&
I, PerFunctionState &PFS);
498 int ParseGetElementPtr(Instruction *&
I, PerFunctionState &PFS);
499 int ParseExtractValue(Instruction *&
I, PerFunctionState &PFS);
500 int ParseInsertValue(Instruction *&
I, PerFunctionState &PFS);
503 bool ParseUseListOrder(PerFunctionState *PFS =
nullptr);
504 bool ParseUseListOrderBB();
505 bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
506 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
A Module instance is used to store all the information related to an LLVM module. ...
enum llvm::ValID::@242 Kind
LLVMContext & getContext()
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
ELFYAML::ELF_STV Visibility
bool Run()
Run: module ::= toplevelentity*.
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.
bool operator<(const ValID &RHS) const
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
bool Error(LocTy L, const Twine &Msg) const
static bool isAtomic(Instruction *I)
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, SlotMapping *Slots=nullptr)
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)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
FunctionNumber(functionNumber)
ValID - Represents a reference of a definition of some sort with no type.
OperandType
Types of operands to CF instructions.
lltok::Kind getKind() const
std::unique_ptr< Constant *[]> ConstantStructElts
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
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)