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() {
197 FMF.setAllowContract(
true);
205 bool ParseOptionalToken(
lltok::Kind T,
bool &Present,
206 LocTy *Loc =
nullptr) {
217 bool ParseStringConstant(std::string &Result);
218 bool ParseUInt32(
unsigned &Val);
219 bool ParseUInt32(
unsigned &Val,
LocTy &Loc) {
221 return ParseUInt32(Val);
223 bool ParseUInt64(uint64_t &Val);
224 bool ParseUInt64(uint64_t &Val,
LocTy &Loc) {
226 return ParseUInt64(Val);
229 bool ParseStringAttribute(AttrBuilder &
B);
234 bool ParseOptionalAddrSpace(
unsigned &AddrSpace);
235 bool ParseOptionalParamAttrs(AttrBuilder &
B);
236 bool ParseOptionalReturnAttrs(AttrBuilder &
B);
237 bool ParseOptionalLinkage(
unsigned &Linkage,
bool &HasLinkage,
238 unsigned &
Visibility,
unsigned &DLLStorageClass);
239 void ParseOptionalVisibility(
unsigned &
Visibility);
240 void ParseOptionalDLLStorageClass(
unsigned &DLLStorageClass);
241 bool ParseOptionalCallingConv(
unsigned &CC);
242 bool ParseOptionalAlignment(
unsigned &Alignment);
243 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
248 bool ParseOptionalStackAlignment(
unsigned &Alignment);
249 bool ParseOptionalCommaAlign(
unsigned &Alignment,
bool &AteExtraComma);
250 bool ParseOptionalCommaAddrSpace(
unsigned &AddrSpace,
LocTy &Loc,
251 bool &AteExtraComma);
252 bool ParseOptionalCommaInAlloca(
bool &IsInAlloca);
253 bool parseAllocSizeArguments(
unsigned &ElemSizeArg,
254 Optional<unsigned> &HowManyArg);
255 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,
256 bool &AteExtraComma);
257 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
259 if (ParseIndexList(Indices, AteExtraComma))
return true;
261 return TokError(
"expected index");
266 bool ParseTopLevelEntities();
267 bool ValidateEndOfModule();
268 bool ParseTargetDefinition();
269 bool ParseModuleAsm();
270 bool ParseSourceFileName();
272 bool ParseUnnamedType();
273 bool ParseNamedType();
277 bool ParseGlobalType(
bool &IsConstant);
278 bool ParseUnnamedGlobal();
279 bool ParseNamedGlobal();
280 bool ParseGlobal(
const std::string &
Name,
LocTy Loc,
unsigned Linkage,
282 unsigned DLLStorageClass,
285 bool parseIndirectSymbol(
const std::string &
Name,
LocTy Loc,
287 unsigned DLLStorageClass,
291 bool ParseStandaloneMetadata();
292 bool ParseNamedMetadata();
293 bool ParseMDString(MDString *&Result);
294 bool ParseMDNodeID(MDNode *&Result);
295 bool ParseUnnamedAttrGrp();
296 bool ParseFnAttributeValuePairs(AttrBuilder &
B,
297 std::vector<unsigned> &FwdRefAttrGrps,
298 bool inAttrGrp,
LocTy &BuiltinLoc);
301 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
302 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
303 return ParseType(Result,
"expected type", AllowVoid);
305 bool ParseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
306 bool AllowVoid =
false) {
308 return ParseType(Result, Msg, AllowVoid);
310 bool ParseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
312 return ParseType(Result, AllowVoid);
314 bool ParseAnonStructType(
Type *&Result,
bool Packed);
315 bool ParseStructBody(SmallVectorImpl<Type*> &Body);
316 bool ParseStructDefinition(SMLoc TypeLoc, StringRef
Name,
317 std::pair<Type*, LocTy> &Entry,
320 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
321 bool ParseFunctionType(
Type *&Result);
324 class PerFunctionState {
327 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
328 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
329 std::vector<Value*> NumberedVals;
338 Function &getFunction()
const {
return F; }
340 bool FinishFunction();
350 bool SetInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
364 bool resolveForwardRefBlockAddresses();
367 bool ConvertValIDToValue(
Type *Ty, ValID &
ID, Value *&V,
368 PerFunctionState *PFS);
370 bool parseConstantValue(
Type *Ty, Constant *&
C);
371 bool ParseValue(
Type *Ty, Value *&V, PerFunctionState *PFS);
372 bool ParseValue(
Type *Ty, Value *&V, PerFunctionState &PFS) {
373 return ParseValue(Ty, V, &PFS);
376 bool ParseValue(
Type *Ty, Value *&V,
LocTy &Loc,
377 PerFunctionState &PFS) {
379 return ParseValue(Ty, V, &PFS);
382 bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
383 bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
384 return ParseTypeAndValue(V, &PFS);
386 bool ParseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
388 return ParseTypeAndValue(V, PFS);
391 PerFunctionState &PFS);
392 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
394 return ParseTypeAndBasicBlock(BB, Loc, PFS);
402 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
403 : Loc(loc), V(v),
Attrs(attrs) {}
405 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
406 PerFunctionState &PFS,
407 bool IsMustTailCall =
false,
408 bool InVarArgsFunc =
false);
411 ParseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
412 PerFunctionState &PFS);
414 bool ParseExceptionArgs(SmallVectorImpl<Value *> &
Args,
415 PerFunctionState &PFS);
418 bool ParseValID(ValID &
ID, PerFunctionState *PFS =
nullptr);
419 bool ParseGlobalValue(
Type *Ty, Constant *&V);
420 bool ParseGlobalTypeAndValue(Constant *&V);
421 bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
422 Optional<unsigned> *InRangeOp =
nullptr);
423 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
424 bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS);
425 bool ParseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
426 PerFunctionState *PFS);
427 bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS);
428 bool ParseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
429 bool ParseMDNode(MDNode *&MD);
430 bool ParseMDNodeTail(MDNode *&MD);
431 bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs);
432 bool ParseMetadataAttachment(
unsigned &
Kind, MDNode *&MD);
433 bool ParseInstructionMetadata(Instruction &Inst);
434 bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO);
435 bool ParseOptionalFunctionMetadata(Function &
F);
437 template <
class FieldTy>
438 bool ParseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
439 template <
class FieldTy>
bool ParseMDField(StringRef
Name, FieldTy &Result);
440 template <
class ParserTy>
441 bool ParseMDFieldsImplBody(ParserTy
parseField);
442 template <
class ParserTy>
444 bool ParseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
446 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
447 bool Parse##CLASS(MDNode *&Result, bool IsDistinct);
448 #include "llvm/IR/Metadata.def"
456 ArgInfo(
LocTy L,
Type *ty, AttributeSet Attr,
const std::string &
N)
457 : Loc(L), Ty(ty),
Attrs(Attr),
Name(N) {}
459 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
460 bool ParseFunctionHeader(Function *&Fn,
bool isDefine);
461 bool ParseFunctionBody(Function &Fn);
462 bool ParseBasicBlock(PerFunctionState &PFS);
464 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
468 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
469 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
470 PerFunctionState &PFS);
471 bool ParseCmpPredicate(
unsigned &Pred,
unsigned Opc);
473 bool ParseRet(Instruction *&Inst,
BasicBlock *BB, PerFunctionState &PFS);
474 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
475 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
476 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
477 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
478 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
479 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
480 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
481 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
482 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
483 bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
485 bool ParseArithmetic(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc,
487 bool ParseLogical(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
488 bool ParseCompare(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
489 bool ParseCast(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
490 bool ParseSelect(Instruction *&
I, PerFunctionState &PFS);
491 bool ParseVA_Arg(Instruction *&
I, PerFunctionState &PFS);
492 bool ParseExtractElement(Instruction *&
I, PerFunctionState &PFS);
493 bool ParseInsertElement(Instruction *&
I, PerFunctionState &PFS);
494 bool ParseShuffleVector(Instruction *&
I, PerFunctionState &PFS);
495 int ParsePHI(Instruction *&
I, PerFunctionState &PFS);
496 bool ParseLandingPad(Instruction *&
I, PerFunctionState &PFS);
497 bool ParseCall(Instruction *&
I, PerFunctionState &PFS,
499 int ParseAlloc(Instruction *&
I, PerFunctionState &PFS);
500 int ParseLoad(Instruction *&
I, PerFunctionState &PFS);
501 int ParseStore(Instruction *&
I, PerFunctionState &PFS);
502 int ParseCmpXchg(Instruction *&
I, PerFunctionState &PFS);
503 int ParseAtomicRMW(Instruction *&
I, PerFunctionState &PFS);
504 int ParseFence(Instruction *&
I, PerFunctionState &PFS);
505 int ParseGetElementPtr(Instruction *&
I, PerFunctionState &PFS);
506 int ParseExtractValue(Instruction *&
I, PerFunctionState &PFS);
507 int ParseInsertValue(Instruction *&
I, PerFunctionState &PFS);
510 bool ParseUseListOrder(PerFunctionState *PFS =
nullptr);
511 bool ParseUseListOrderBB();
512 bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
513 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
enum llvm::ValID::@272 Kind
A Module instance is used to store all the information related to an LLVM module. ...
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
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
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.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
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)
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)