14 #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H
15 #define LLVM_LIB_ASMPARSER_LLPARSER_H
79 "Ordering not defined for this ValID kind yet");
105 unsigned MDKind, MDSlot;
113 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
115 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
116 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
119 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
120 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
121 std::vector<GlobalValue*> NumberedVals;
124 std::map<std::string, LocTy> ForwardRefComdats;
128 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
129 class PerFunctionState;
133 PerFunctionState *BlockAddressPFS;
136 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
137 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
143 Slots(Slots), BlockAddressPFS(nullptr) {}
151 return Lex.
Error(L, Msg);
153 bool TokError(
const Twine &Msg)
const {
160 GlobalValue *GetGlobalVal(
const std::string &
N,
Type *Ty,
LocTy Loc);
161 GlobalValue *GetGlobalVal(
unsigned ID,
Type *Ty,
LocTy Loc);
165 Comdat *getComdat(
const std::string &
N,
LocTy Loc);
170 if (Lex.
getKind() !=
T)
return false;
175 FastMathFlags EatFastMathFlagsIfPresent() {
189 bool ParseOptionalToken(
lltok::Kind T,
bool &Present,
190 LocTy *Loc =
nullptr) {
201 bool ParseStringConstant(std::string &Result);
202 bool ParseUInt32(
unsigned &Val);
203 bool ParseUInt32(
unsigned &Val,
LocTy &Loc) {
205 return ParseUInt32(Val);
207 bool ParseUInt64(uint64_t &Val);
208 bool ParseUInt64(uint64_t &Val,
LocTy &Loc) {
210 return ParseUInt64(Val);
215 bool parseOptionalUnnamedAddr(
bool &UnnamedAddr) {
218 bool ParseOptionalAddrSpace(
unsigned &AddrSpace);
219 bool ParseOptionalParamAttrs(AttrBuilder &B);
220 bool ParseOptionalReturnAttrs(AttrBuilder &B);
221 bool ParseOptionalLinkage(
unsigned &Linkage,
bool &HasLinkage);
222 bool ParseOptionalLinkage(
unsigned &Linkage) {
223 bool HasLinkage;
return ParseOptionalLinkage(Linkage, HasLinkage);
225 bool ParseOptionalVisibility(
unsigned &
Visibility);
226 bool ParseOptionalDLLStorageClass(
unsigned &DLLStorageClass);
227 bool ParseOptionalCallingConv(
unsigned &CC);
228 bool ParseOptionalAlignment(
unsigned &Alignment);
229 bool ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind, uint64_t &Bytes);
233 bool ParseOptionalStackAlignment(
unsigned &Alignment);
234 bool ParseOptionalCommaAlign(
unsigned &Alignment,
bool &AteExtraComma);
235 bool ParseOptionalCommaInAlloca(
bool &IsInAlloca);
236 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,
bool &AteExtraComma);
237 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
239 if (ParseIndexList(Indices, AteExtraComma))
return true;
241 return TokError(
"expected index");
246 bool ParseTopLevelEntities();
247 bool ValidateEndOfModule();
248 bool ParseTargetDefinition();
249 bool ParseModuleAsm();
251 bool ParseUnnamedType();
252 bool ParseNamedType();
256 bool ParseGlobalType(
bool &IsConstant);
257 bool ParseUnnamedGlobal();
258 bool ParseNamedGlobal();
259 bool ParseGlobal(
const std::string &
Name,
LocTy Loc,
unsigned Linkage,
261 unsigned DLLStorageClass,
263 bool ParseAlias(
const std::string &
Name,
LocTy Loc,
unsigned Linkage,
264 unsigned Visibility,
unsigned DLLStorageClass,
267 bool ParseStandaloneMetadata();
268 bool ParseNamedMetadata();
269 bool ParseMDString(MDString *&Result);
270 bool ParseMDNodeID(MDNode *&Result);
271 bool ParseUnnamedAttrGrp();
272 bool ParseFnAttributeValuePairs(AttrBuilder &B,
273 std::vector<unsigned> &FwdRefAttrGrps,
274 bool inAttrGrp,
LocTy &BuiltinLoc);
277 bool ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid =
false);
278 bool ParseType(
Type *&Result,
bool AllowVoid =
false) {
279 return ParseType(Result,
"expected type", AllowVoid);
281 bool ParseType(
Type *&Result,
const Twine &Msg,
LocTy &Loc,
282 bool AllowVoid =
false) {
284 return ParseType(Result, Msg, AllowVoid);
286 bool ParseType(
Type *&Result,
LocTy &Loc,
bool AllowVoid =
false) {
288 return ParseType(Result, AllowVoid);
290 bool ParseAnonStructType(
Type *&Result,
bool Packed);
291 bool ParseStructBody(SmallVectorImpl<Type*> &Body);
292 bool ParseStructDefinition(SMLoc TypeLoc, StringRef
Name,
293 std::pair<Type*, LocTy> &Entry,
296 bool ParseArrayVectorType(
Type *&Result,
bool isVector);
297 bool ParseFunctionType(
Type *&Result);
300 class PerFunctionState {
303 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
304 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
305 std::vector<Value*> NumberedVals;
314 Function &getFunction()
const {
return F; }
316 bool FinishFunction();
326 bool SetInstName(
int NameID,
const std::string &NameStr,
LocTy NameLoc,
340 bool resolveForwardRefBlockAddresses();
343 bool ConvertValIDToValue(
Type *Ty, ValID &
ID, Value *&V,
344 PerFunctionState *PFS);
346 bool ParseValue(
Type *Ty, Value *&V, PerFunctionState *PFS);
347 bool ParseValue(
Type *Ty, Value *&V, PerFunctionState &PFS) {
348 return ParseValue(Ty, V, &PFS);
350 bool ParseValue(
Type *Ty, Value *&V,
LocTy &Loc,
351 PerFunctionState &PFS) {
353 return ParseValue(Ty, V, &PFS);
356 bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
357 bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
358 return ParseTypeAndValue(V, &PFS);
360 bool ParseTypeAndValue(Value *&V,
LocTy &Loc, PerFunctionState &PFS) {
362 return ParseTypeAndValue(V, PFS);
365 PerFunctionState &PFS);
366 bool ParseTypeAndBasicBlock(
BasicBlock *&BB, PerFunctionState &PFS) {
368 return ParseTypeAndBasicBlock(BB, Loc, PFS);
376 ParamInfo(
LocTy loc, Value *v, AttributeSet attrs)
377 : Loc(loc), V(v), Attrs(attrs) {}
379 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
380 PerFunctionState &PFS,
381 bool IsMustTailCall =
false,
382 bool InVarArgsFunc =
false);
385 bool ParseValID(ValID &
ID, PerFunctionState *PFS =
nullptr);
387 bool ParseGlobalTypeAndValue(
Constant *&V);
388 bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
389 bool parseOptionalComdat(StringRef GlobalName, Comdat *&
C);
390 bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS);
391 bool ParseValueAsMetadata(Metadata *&MD,
const Twine &TypeMsg,
392 PerFunctionState *PFS);
393 bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS);
394 bool ParseMDTuple(MDNode *&MD,
bool IsDistinct =
false);
395 bool ParseMDNode(MDNode *&MD);
396 bool ParseMDNodeTail(MDNode *&MD);
397 bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs);
398 bool ParseMetadataAttachment(
unsigned &
Kind, MDNode *&MD);
399 bool ParseInstructionMetadata(Instruction &Inst);
400 bool ParseOptionalFunctionMetadata(
Function &
F);
402 template <
class FieldTy>
403 bool ParseMDField(
LocTy Loc, StringRef
Name, FieldTy &Result);
404 template <
class FieldTy>
bool ParseMDField(StringRef
Name, FieldTy &Result);
405 template <
class ParserTy>
406 bool ParseMDFieldsImplBody(ParserTy parseField);
407 template <
class ParserTy>
408 bool ParseMDFieldsImpl(ParserTy parseField,
LocTy &ClosingLoc);
409 bool ParseSpecializedMDNode(MDNode *&
N,
bool IsDistinct =
false);
411 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
412 bool Parse##CLASS(MDNode *&Result, bool IsDistinct);
413 #include "llvm/IR/Metadata.def"
421 ArgInfo(
LocTy L,
Type *ty, AttributeSet Attr,
const std::string &
N)
422 : Loc(L), Ty(ty), Attrs(Attr),
Name(N) {}
424 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg);
425 bool ParseFunctionHeader(
Function *&Fn,
bool isDefine);
426 bool ParseFunctionBody(
Function &Fn);
427 bool ParseBasicBlock(PerFunctionState &PFS);
429 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
433 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
434 int ParseInstruction(Instruction *&Inst,
BasicBlock *BB,
435 PerFunctionState &PFS);
436 bool ParseCmpPredicate(
unsigned &Pred,
unsigned Opc);
438 bool ParseRet(Instruction *&Inst,
BasicBlock *BB, PerFunctionState &PFS);
439 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
440 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
441 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
442 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
443 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
445 bool ParseArithmetic(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc,
447 bool ParseLogical(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
448 bool ParseCompare(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
449 bool ParseCast(Instruction *&
I, PerFunctionState &PFS,
unsigned Opc);
450 bool ParseSelect(Instruction *&
I, PerFunctionState &PFS);
451 bool ParseVA_Arg(Instruction *&
I, PerFunctionState &PFS);
452 bool ParseExtractElement(Instruction *&
I, PerFunctionState &PFS);
453 bool ParseInsertElement(Instruction *&
I, PerFunctionState &PFS);
454 bool ParseShuffleVector(Instruction *&
I, PerFunctionState &PFS);
455 int ParsePHI(Instruction *&
I, PerFunctionState &PFS);
456 bool ParseLandingPad(Instruction *&
I, PerFunctionState &PFS);
457 bool ParseCall(Instruction *&
I, PerFunctionState &PFS,
459 int ParseAlloc(Instruction *&
I, PerFunctionState &PFS);
460 int ParseLoad(Instruction *&
I, PerFunctionState &PFS);
461 int ParseStore(Instruction *&
I, PerFunctionState &PFS);
462 int ParseCmpXchg(Instruction *&
I, PerFunctionState &PFS);
463 int ParseAtomicRMW(Instruction *&
I, PerFunctionState &PFS);
464 int ParseFence(Instruction *&
I, PerFunctionState &PFS);
465 int ParseGetElementPtr(Instruction *&
I, PerFunctionState &PFS);
466 int ParseExtractValue(Instruction *&
I, PerFunctionState &PFS);
467 int ParseInsertValue(Instruction *&
I, PerFunctionState &PFS);
470 bool ParseUseListOrder(PerFunctionState *PFS =
nullptr);
471 bool ParseUseListOrderBB();
472 bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
473 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
A Module instance is used to store all the information related to an LLVM module. ...
LLVMContext & getContext()
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...
bool operator<(const ValID &RHS) const
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
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)
Constant ** ConstantStructElts
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.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
This struct contains the mapping from the slot numbers to unnamed metadata nodes and global values...
FunctionNumber(functionNumber)
ValID - Represents a reference of a definition of some sort with no type.
OperandType
Types of operands to CF instructions.
enum llvm::ValID::@195 Kind
lltok::Kind getKind() const
const ARM::ArchExtKind Kind
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...