LLVM  8.0.0svn
LLParser.h
Go to the documentation of this file.
1 //===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the parser class for .ll files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H
15 #define LLVM_LIB_ASMPARSER_LLPARSER_H
16 
17 #include "LLLexer.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/IR/Attributes.h"
21 #include "llvm/IR/Instructions.h"
22 #include "llvm/IR/Module.h"
24 #include "llvm/IR/Operator.h"
25 #include "llvm/IR/Type.h"
26 #include "llvm/IR/ValueHandle.h"
27 #include <map>
28 
29 namespace llvm {
30  class Module;
31  class OpaqueType;
32  class Function;
33  class Value;
34  class BasicBlock;
35  class Instruction;
36  class Constant;
37  class GlobalValue;
38  class Comdat;
39  class MDString;
40  class MDNode;
41  struct SlotMapping;
42  class StructType;
43 
44  /// ValID - Represents a reference of a definition of some sort with no type.
45  /// There are several cases where we have to parse the value but where the
46  /// type can depend on later context. This may either be a numeric reference
47  /// or a symbolic (%var) reference. This is just a discriminated union.
48  struct ValID {
49  enum {
50  t_LocalID, t_GlobalID, // ID in UIntVal.
51  t_LocalName, t_GlobalName, // Name in StrVal.
52  t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal.
53  t_Null, t_Undef, t_Zero, t_None, // No value.
54  t_EmptyArray, // No value: []
55  t_Constant, // Value in ConstantVal.
56  t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal.
57  t_ConstantStruct, // Value in ConstantStructElts.
58  t_PackedConstantStruct // Value in ConstantStructElts.
59  } Kind = t_LocalID;
60 
62  unsigned UIntVal;
63  FunctionType *FTy = nullptr;
64  std::string StrVal, StrVal2;
68  std::unique_ptr<Constant *[]> ConstantStructElts;
69 
70  ValID() = default;
71  ValID(const ValID &RHS)
72  : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy),
73  StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal),
74  APFloatVal(RHS.APFloatVal), ConstantVal(RHS.ConstantVal) {
76  }
77 
78  bool operator<(const ValID &RHS) const {
79  if (Kind == t_LocalID || Kind == t_GlobalID)
80  return UIntVal < RHS.UIntVal;
81  assert((Kind == t_LocalName || Kind == t_GlobalName ||
82  Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
83  "Ordering not defined for this ValID kind yet");
84  return StrVal < RHS.StrVal;
85  }
86  };
87 
88  class LLParser {
89  public:
91  private:
93  LLLexer Lex;
94  // Module being parsed, null if we are only parsing summary index.
95  Module *M;
96  // Summary index being parsed, null if we are only parsing Module.
98  SlotMapping *Slots;
99 
100  // Instruction metadata resolution. Each instruction can have a list of
101  // MDRef info associated with them.
102  //
103  // The simpler approach of just creating temporary MDNodes and then calling
104  // RAUW on them when the definition is processed doesn't work because some
105  // instruction metadata kinds, such as dbg, get stored in the IR in an
106  // "optimized" format which doesn't participate in the normal value use
107  // lists. This means that RAUW doesn't work, even on temporary MDNodes
108  // which otherwise support RAUW. Instead, we defer resolving MDNode
109  // references until the definitions have been processed.
110  struct MDRef {
111  SMLoc Loc;
112  unsigned MDKind, MDSlot;
113  };
114 
115  SmallVector<Instruction*, 64> InstsWithTBAATag;
116 
117  // Type resolution handling data structures. The location is set when we
118  // have processed a use of the type but not a definition yet.
120  std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
121 
122  std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
123  std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
124 
125  // Global Value reference information.
126  std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
127  std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
128  std::vector<GlobalValue*> NumberedVals;
129 
130  // Comdat forward reference information.
131  std::map<std::string, LocTy> ForwardRefComdats;
132 
133  // References to blockaddress. The key is the function ValID, the value is
134  // a list of references to blocks in that function.
135  std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
136  class PerFunctionState;
137  /// Reference to per-function state to allow basic blocks to be
138  /// forward-referenced by blockaddress instructions within the same
139  /// function.
140  PerFunctionState *BlockAddressPFS;
141 
142  // Attribute builder reference information.
143  std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
144  std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
145 
146  // Summary global value reference information.
147  std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
148  ForwardRefValueInfos;
149  std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
150  ForwardRefAliasees;
151  std::vector<ValueInfo> NumberedValueInfos;
152 
153  // Summary type id reference information.
154  std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
155  ForwardRefTypeIds;
156 
157  // Map of module ID to path.
158  std::map<unsigned, StringRef> ModuleIdMap;
159 
160  /// Only the llvm-as tool may set this to false to bypass
161  /// UpgradeDebuginfo so it can generate broken bitcode.
162  bool UpgradeDebugInfo;
163 
164  /// DataLayout string to override that in LLVM assembly.
165  StringRef DataLayoutStr;
166 
167  std::string SourceFileName;
168 
169  public:
171  ModuleSummaryIndex *Index, LLVMContext &Context,
172  SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true,
173  StringRef DataLayoutString = "")
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())
178  M->setDataLayout(DataLayoutStr);
179  }
180  bool Run();
181 
182  bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
183 
184  bool parseTypeAtBeginning(Type *&Ty, unsigned &Read,
185  const SlotMapping *Slots);
186 
188 
189  private:
190 
191  bool Error(LocTy L, const Twine &Msg) const {
192  return Lex.Error(L, Msg);
193  }
194  bool TokError(const Twine &Msg) const {
195  return Error(Lex.getLoc(), Msg);
196  }
197 
198  /// Restore the internal name and slot mappings using the mappings that
199  /// were created at an earlier parsing stage.
200  void restoreParsingState(const SlotMapping *Slots);
201 
202  /// GetGlobalVal - Get a value with the specified name or ID, creating a
203  /// forward reference record if needed. This can return null if the value
204  /// exists but does not have the right type.
205  GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc,
206  bool IsCall);
207  GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall);
208 
209  /// Get a Comdat with the specified name, creating a forward reference
210  /// record if needed.
211  Comdat *getComdat(const std::string &Name, LocTy Loc);
212 
213  // Helper Routines.
214  bool ParseToken(lltok::Kind T, const char *ErrMsg);
215  bool EatIfPresent(lltok::Kind T) {
216  if (Lex.getKind() != T) return false;
217  Lex.Lex();
218  return true;
219  }
220 
221  FastMathFlags EatFastMathFlagsIfPresent() {
222  FastMathFlags FMF;
223  while (true)
224  switch (Lex.getKind()) {
225  case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue;
226  case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
227  case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
228  case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
229  case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
230  case lltok::kw_contract:
231  FMF.setAllowContract(true);
232  Lex.Lex();
233  continue;
234  case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue;
235  case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue;
236  default: return FMF;
237  }
238  return FMF;
239  }
240 
241  bool ParseOptionalToken(lltok::Kind T, bool &Present,
242  LocTy *Loc = nullptr) {
243  if (Lex.getKind() != T) {
244  Present = false;
245  } else {
246  if (Loc)
247  *Loc = Lex.getLoc();
248  Lex.Lex();
249  Present = true;
250  }
251  return false;
252  }
253  bool ParseStringConstant(std::string &Result);
254  bool ParseUInt32(unsigned &Val);
255  bool ParseUInt32(unsigned &Val, LocTy &Loc) {
256  Loc = Lex.getLoc();
257  return ParseUInt32(Val);
258  }
259  bool ParseUInt64(uint64_t &Val);
260  bool ParseUInt64(uint64_t &Val, LocTy &Loc) {
261  Loc = Lex.getLoc();
262  return ParseUInt64(Val);
263  }
264  bool ParseFlag(unsigned &Val);
265 
266  bool ParseStringAttribute(AttrBuilder &B);
267 
268  bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
269  bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
270  bool ParseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
271  bool ParseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0);
272  bool ParseOptionalProgramAddrSpace(unsigned &AddrSpace) {
273  return ParseOptionalAddrSpace(
274  AddrSpace, M->getDataLayout().getProgramAddressSpace());
275  };
276  bool ParseOptionalParamAttrs(AttrBuilder &B);
277  bool ParseOptionalReturnAttrs(AttrBuilder &B);
278  bool ParseOptionalLinkage(unsigned &Res, bool &HasLinkage,
279  unsigned &Visibility, unsigned &DLLStorageClass,
280  bool &DSOLocal);
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);
287  bool ParseScopeAndOrdering(bool isAtomic, SyncScope::ID &SSID,
288  AtomicOrdering &Ordering);
289  bool ParseScope(SyncScope::ID &SSID);
290  bool ParseOrdering(AtomicOrdering &Ordering);
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,
297  Optional<unsigned> &HowManyArg);
298  bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,
299  bool &AteExtraComma);
300  bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
301  bool AteExtraComma;
302  if (ParseIndexList(Indices, AteExtraComma)) return true;
303  if (AteExtraComma)
304  return TokError("expected index");
305  return false;
306  }
307 
308  // Top-Level Entities
309  bool ParseTopLevelEntities();
310  bool ValidateEndOfModule();
311  bool ValidateEndOfIndex();
312  bool ParseTargetDefinition();
313  bool ParseModuleAsm();
314  bool ParseSourceFileName();
315  bool ParseDepLibs(); // FIXME: Remove in 4.0.
316  bool ParseUnnamedType();
317  bool ParseNamedType();
318  bool ParseDeclare();
319  bool ParseDefine();
320 
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,
328  GlobalVariable::UnnamedAddr UnnamedAddr);
329  bool parseIndirectSymbol(const std::string &Name, LocTy NameLoc,
330  unsigned L, unsigned Visibility,
331  unsigned DLLStorageClass, bool DSOLocal,
333  GlobalVariable::UnnamedAddr UnnamedAddr);
334  bool parseComdat();
335  bool ParseStandaloneMetadata();
336  bool ParseNamedMetadata();
337  bool ParseMDString(MDString *&Result);
338  bool ParseMDNodeID(MDNode *&Result);
339  bool ParseUnnamedAttrGrp();
340  bool ParseFnAttributeValuePairs(AttrBuilder &B,
341  std::vector<unsigned> &FwdRefAttrGrps,
342  bool inAttrGrp, LocTy &BuiltinLoc);
343 
344  // Module Summary Index Parsing.
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);
351  bool ParseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
352  bool ParseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
353  bool ParseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
354  bool ParseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
355  bool ParseOptionalFFlags(FunctionSummary::FFlags &FFlags);
356  bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
357  bool ParseHotness(CalleeInfo::HotnessType &Hotness);
358  bool ParseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
359  bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
360  bool ParseVFuncIdList(lltok::Kind Kind,
361  std::vector<FunctionSummary::VFuncId> &VFuncIdList);
362  bool ParseConstVCallList(
363  lltok::Kind Kind,
364  std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
365  using IdToIndexMapType =
366  std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
367  bool ParseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
368  IdToIndexMapType &IdToIndexMap, unsigned Index);
369  bool ParseVFuncId(FunctionSummary::VFuncId &VFuncId,
370  IdToIndexMapType &IdToIndexMap, unsigned Index);
371  bool ParseOptionalRefs(std::vector<ValueInfo> &Refs);
372  bool ParseTypeIdEntry(unsigned ID);
373  bool ParseTypeIdSummary(TypeIdSummary &TIS);
374  bool ParseTypeTestResolution(TypeTestResolution &TTRes);
375  bool ParseOptionalWpdResolutions(
376  std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
377  bool ParseWpdRes(WholeProgramDevirtResolution &WPDRes);
378  bool ParseOptionalResByArg(
379  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
380  &ResByArg);
381  bool ParseArgs(std::vector<uint64_t> &Args);
382  void AddGlobalValueToIndex(std::string Name, GlobalValue::GUID,
383  GlobalValue::LinkageTypes Linkage, unsigned ID,
384  std::unique_ptr<GlobalValueSummary> Summary);
385 
386  // Type Parsing.
387  bool ParseType(Type *&Result, const Twine &Msg, bool AllowVoid = false);
388  bool ParseType(Type *&Result, bool AllowVoid = false) {
389  return ParseType(Result, "expected type", AllowVoid);
390  }
391  bool ParseType(Type *&Result, const Twine &Msg, LocTy &Loc,
392  bool AllowVoid = false) {
393  Loc = Lex.getLoc();
394  return ParseType(Result, Msg, AllowVoid);
395  }
396  bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
397  Loc = Lex.getLoc();
398  return ParseType(Result, AllowVoid);
399  }
400  bool ParseAnonStructType(Type *&Result, bool Packed);
401  bool ParseStructBody(SmallVectorImpl<Type*> &Body);
402  bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
403  std::pair<Type*, LocTy> &Entry,
404  Type *&ResultTy);
405 
406  bool ParseArrayVectorType(Type *&Result, bool isVector);
407  bool ParseFunctionType(Type *&Result);
408 
409  // Function Semantic Analysis.
410  class PerFunctionState {
411  LLParser &P;
412  Function &F;
413  std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
414  std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
415  std::vector<Value*> NumberedVals;
416 
417  /// FunctionNumber - If this is an unnamed function, this is the slot
418  /// number of it, otherwise it is -1.
419  int FunctionNumber;
420  public:
421  PerFunctionState(LLParser &p, Function &f, int functionNumber);
422  ~PerFunctionState();
423 
424  Function &getFunction() const { return F; }
425 
426  bool FinishFunction();
427 
428  /// GetVal - Get a value with the specified name or ID, creating a
429  /// forward reference record if needed. This can return null if the value
430  /// exists but does not have the right type.
431  Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc, bool IsCall);
432  Value *GetVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall);
433 
434  /// SetInstName - After an instruction is parsed and inserted into its
435  /// basic block, this installs its name.
436  bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
437  Instruction *Inst);
438 
439  /// GetBB - Get a basic block with the specified name or ID, creating a
440  /// forward reference record if needed. This can return null if the value
441  /// is not a BasicBlock.
442  BasicBlock *GetBB(const std::string &Name, LocTy Loc);
443  BasicBlock *GetBB(unsigned ID, LocTy Loc);
444 
445  /// DefineBB - Define the specified basic block, which is either named or
446  /// unnamed. If there is an error, this returns null otherwise it returns
447  /// the block being defined.
448  BasicBlock *DefineBB(const std::string &Name, LocTy Loc);
449 
450  bool resolveForwardRefBlockAddresses();
451  };
452 
453  bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
454  PerFunctionState *PFS, bool IsCall);
455 
456  Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
457  Value *Val, bool IsCall);
458 
459  bool parseConstantValue(Type *Ty, Constant *&C);
460  bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
461  bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
462  return ParseValue(Ty, V, &PFS);
463  }
464 
465  bool ParseValue(Type *Ty, Value *&V, LocTy &Loc,
466  PerFunctionState &PFS) {
467  Loc = Lex.getLoc();
468  return ParseValue(Ty, V, &PFS);
469  }
470 
471  bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
472  bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
473  return ParseTypeAndValue(V, &PFS);
474  }
475  bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
476  Loc = Lex.getLoc();
477  return ParseTypeAndValue(V, PFS);
478  }
479  bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
480  PerFunctionState &PFS);
481  bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
482  LocTy Loc;
483  return ParseTypeAndBasicBlock(BB, Loc, PFS);
484  }
485 
486 
487  struct ParamInfo {
488  LocTy Loc;
489  Value *V;
491  ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
492  : Loc(loc), V(v), Attrs(attrs) {}
493  };
494  bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
495  PerFunctionState &PFS,
496  bool IsMustTailCall = false,
497  bool InVarArgsFunc = false);
498 
499  bool
500  ParseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
501  PerFunctionState &PFS);
502 
503  bool ParseExceptionArgs(SmallVectorImpl<Value *> &Args,
504  PerFunctionState &PFS);
505 
506  // Constant Parsing.
507  bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr);
508  bool ParseGlobalValue(Type *Ty, Constant *&C);
509  bool ParseGlobalTypeAndValue(Constant *&V);
510  bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
511  Optional<unsigned> *InRangeOp = nullptr);
512  bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
513  bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS);
514  bool ParseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
515  PerFunctionState *PFS);
516  bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS);
517  bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false);
518  bool ParseMDNode(MDNode *&N);
519  bool ParseMDNodeTail(MDNode *&N);
520  bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
521  bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD);
522  bool ParseInstructionMetadata(Instruction &Inst);
523  bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO);
524  bool ParseOptionalFunctionMetadata(Function &F);
525 
526  template <class FieldTy>
527  bool ParseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
528  template <class FieldTy> bool ParseMDField(StringRef Name, FieldTy &Result);
529  template <class ParserTy>
530  bool ParseMDFieldsImplBody(ParserTy parseField);
531  template <class ParserTy>
532  bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
533  bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
534 
535 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
536  bool Parse##CLASS(MDNode *&Result, bool IsDistinct);
537 #include "llvm/IR/Metadata.def"
538 
539  // Function Parsing.
540  struct ArgInfo {
541  LocTy Loc;
542  Type *Ty;
543  AttributeSet Attrs;
544  std::string Name;
545  ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
546  : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
547  };
548  bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg);
549  bool ParseFunctionHeader(Function *&Fn, bool isDefine);
550  bool ParseFunctionBody(Function &Fn);
551  bool ParseBasicBlock(PerFunctionState &PFS);
552 
553  enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
554 
555  // Instruction Parsing. Each instruction parsing routine can return with a
556  // normal result, an error result, or return having eaten an extra comma.
557  enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
558  int ParseInstruction(Instruction *&Inst, BasicBlock *BB,
559  PerFunctionState &PFS);
560  bool ParseCmpPredicate(unsigned &P, unsigned Opc);
561 
562  bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
563  bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
564  bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
565  bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
566  bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
567  bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
568  bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
569  bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
570  bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
571  bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
572  bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
573 
574  bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
575  unsigned OperandType);
576  bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
577  bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
578  bool ParseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
579  bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS);
580  bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS);
581  bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
582  bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
583  bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
584  int ParsePHI(Instruction *&Inst, PerFunctionState &PFS);
585  bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
586  bool ParseCall(Instruction *&Inst, PerFunctionState &PFS,
588  int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS);
589  int ParseLoad(Instruction *&Inst, PerFunctionState &PFS);
590  int ParseStore(Instruction *&Inst, PerFunctionState &PFS);
591  int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
592  int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
593  int ParseFence(Instruction *&Inst, PerFunctionState &PFS);
594  int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
595  int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
596  int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
597 
598  // Use-list order directives.
599  bool ParseUseListOrder(PerFunctionState *PFS = nullptr);
600  bool ParseUseListOrderBB();
601  bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
602  bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
603  };
604 } // End llvm namespace
605 
606 #endif
LLLexer::LocTy Loc
Definition: LLParser.h:61
uint64_t CallInst * C
LLVMContext & Context
void setFast(bool B=true)
Definition: Operator.h:231
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:493
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
Definition: Parser.cpp:148
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
bool operator<(const ValID &RHS) const
Definition: LLParser.h:78
LLVMContext & getContext()
Definition: LLParser.h:187
void setDataLayout(StringRef Desc)
Set the data layout.
Definition: Module.cpp:357
void setNoInfs(bool B=true)
Definition: Operator.h:216
Metadata node.
Definition: Metadata.h:864
F(f)
unsigned UIntVal
Definition: LLParser.h:62
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:772
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:363
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
This file contains the simple types necessary to represent the attributes associated with functions a...
lltok::Kind Lex()
Definition: LLLexer.h:53
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
ValID(const ValID &RHS)
Definition: LLParser.h:71
Class to represent function types.
Definition: DerivedTypes.h:103
#define T
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
std::string StrVal
Definition: LLParser.h:64
Type * parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a string Asm that starts with a type.
Definition: Parser.cpp:176
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:221
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...
#define P(N)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setNoSignedZeros(bool B=true)
Definition: Operator.h:219
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
This is an important base class in LLVM.
Definition: Constant.h:42
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
Constant * ConstantVal
Definition: LLParser.h:67
APFloat APFloatVal
Definition: LLParser.h:66
All type identifier related information.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
lltok::Kind getKind() const
Definition: LLLexer.h:59
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.
unsigned DefaultAS
Definition: LLParser.cpp:1524
LocTy getLoc() const
Definition: LLLexer.h:58
APSInt APSIntVal
Definition: LLParser.h:65
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Module.h This file contains the declarations for the Module class.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
void setApproxFunc(bool B=true)
Definition: Operator.h:228
unsigned getProgramAddressSpace() const
Definition: DataLayout.h:260
ValID()=default
void setNoNaNs(bool B=true)
Definition: Operator.h:213
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
A specification for a virtual function call with all constant integer arguments.
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:48
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
Definition: SlotMapping.h:33
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, ModuleSummaryIndex *Index, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
Definition: LLParser.h:170
FunctionNumber(functionNumber)
Definition: LLParser.cpp:2729
OperandType
Operands are tagged with one of the values of this enum.
Definition: MCInstrDesc.h:44
ValID - Represents a reference of a definition of some sort with no type.
Definition: LLParser.h:48
enum llvm::ValID::@315 Kind
void setAllowContract(bool B=true)
Definition: Operator.h:225
#define N
std::unique_ptr< Constant *[]> ConstantStructElts
Definition: LLParser.h:68
void setAllowReciprocal(bool B=true)
Definition: Operator.h:222
Function attribute flags.
bool Error(LocTy ErrorLoc, const Twine &Msg) const
Definition: LLLexer.cpp:29
FunctionType * FTy
Definition: LLParser.h:63
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::string StrVal2
Definition: LLParser.h:64
LLLexer::LocTy LocTy
Definition: LLParser.h:90
LLVM Value Representation.
Definition: Value.h:73
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:604
Represents a location in source code.
Definition: SMLoc.h:24
void setAllowReassoc(bool B=true)
Flag setters.
Definition: Operator.h:210
Root of the metadata hierarchy.
Definition: Metadata.h:58
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
TLM
Definition: LLParser.cpp:1512
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260
static bool parseField(amd_kernel_code_t &C, MCAsmParser &MCParser, raw_ostream &Err)