LLVM  14.0.0git
LLParser.h
Go to the documentation of this file.
1 //===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the parser class for .ll files.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ASMPARSER_LLPARSER_H
14 #define LLVM_ASMPARSER_LLPARSER_H
15 
16 #include "LLLexer.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/AsmParser/Parser.h"
20 #include "llvm/IR/Attributes.h"
21 #include "llvm/IR/Instructions.h"
23 #include "llvm/IR/Operator.h"
24 #include "llvm/IR/Type.h"
25 #include <map>
26 
27 namespace llvm {
28  class Module;
29  class Function;
30  class Value;
31  class BasicBlock;
32  class Instruction;
33  class Constant;
34  class GlobalValue;
35  class Comdat;
36  class MDString;
37  class MDNode;
38  struct SlotMapping;
39 
40  /// ValID - Represents a reference of a definition of some sort with no type.
41  /// There are several cases where we have to parse the value but where the
42  /// type can depend on later context. This may either be a numeric reference
43  /// or a symbolic (%var) reference. This is just a discriminated union.
44  struct ValID {
45  enum {
46  t_LocalID, t_GlobalID, // ID in UIntVal.
47  t_LocalName, t_GlobalName, // Name in StrVal.
48  t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal.
49  t_Null, t_Undef, t_Zero, t_None, t_Poison, // No value.
50  t_EmptyArray, // No value: []
51  t_Constant, // Value in ConstantVal.
52  t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal.
53  t_ConstantStruct, // Value in ConstantStructElts.
54  t_PackedConstantStruct // Value in ConstantStructElts.
55  } Kind = t_LocalID;
56 
58  unsigned UIntVal;
59  FunctionType *FTy = nullptr;
60  std::string StrVal, StrVal2;
64  std::unique_ptr<Constant *[]> ConstantStructElts;
65  bool NoCFI = false;
66 
67  ValID() = default;
68  ValID(const ValID &RHS)
72  NoCFI(RHS.NoCFI) {
73  assert(!RHS.ConstantStructElts);
74  }
75 
76  bool operator<(const ValID &RHS) const {
77  if (Kind == t_LocalID || Kind == t_GlobalID)
78  return UIntVal < RHS.UIntVal;
81  "Ordering not defined for this ValID kind yet");
82  return StrVal < RHS.StrVal;
83  }
84  };
85 
86  class LLParser {
87  public:
89  private:
90  LLVMContext &Context;
91  LLLexer Lex;
92  // Module being parsed, null if we are only parsing summary index.
93  Module *M;
94  // Summary index being parsed, null if we are only parsing Module.
95  ModuleSummaryIndex *Index;
96  SlotMapping *Slots;
97 
98  SmallVector<Instruction*, 64> InstsWithTBAATag;
99 
100  // Type resolution handling data structures. The location is set when we
101  // have processed a use of the type but not a definition yet.
103  std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
104 
105  std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
106  std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
107 
108  // Global Value reference information.
109  std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
110  std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
111  std::vector<GlobalValue*> NumberedVals;
112 
113  // Comdat forward reference information.
114  std::map<std::string, LocTy> ForwardRefComdats;
115 
116  // References to blockaddress. The key is the function ValID, the value is
117  // a list of references to blocks in that function.
118  std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
119  class PerFunctionState;
120  /// Reference to per-function state to allow basic blocks to be
121  /// forward-referenced by blockaddress instructions within the same
122  /// function.
123  PerFunctionState *BlockAddressPFS;
124 
125  // Attribute builder reference information.
126  std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
127  std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
128 
129  // Summary global value reference information.
130  std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
131  ForwardRefValueInfos;
132  std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
133  ForwardRefAliasees;
134  std::vector<ValueInfo> NumberedValueInfos;
135 
136  // Summary type id reference information.
137  std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
138  ForwardRefTypeIds;
139 
140  // Map of module ID to path.
141  std::map<unsigned, StringRef> ModuleIdMap;
142 
143  /// Only the llvm-as tool may set this to false to bypass
144  /// UpgradeDebuginfo so it can generate broken bitcode.
145  bool UpgradeDebugInfo;
146 
147  std::string SourceFileName;
148 
149  public:
152  SlotMapping *Slots = nullptr)
153  : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index),
154  Slots(Slots), BlockAddressPFS(nullptr) {}
155  bool Run(
156  bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback =
157  [](StringRef) { return None; });
158 
159  bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
160 
161  bool parseTypeAtBeginning(Type *&Ty, unsigned &Read,
162  const SlotMapping *Slots);
163 
165 
166  private:
167  bool error(LocTy L, const Twine &Msg) const { return Lex.Error(L, Msg); }
168  bool tokError(const Twine &Msg) const { return error(Lex.getLoc(), Msg); }
169 
170  /// Restore the internal name and slot mappings using the mappings that
171  /// were created at an earlier parsing stage.
172  void restoreParsingState(const SlotMapping *Slots);
173 
174  /// getGlobalVal - Get a value with the specified name or ID, creating a
175  /// forward reference record if needed. This can return null if the value
176  /// exists but does not have the right type.
177  GlobalValue *getGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
178  GlobalValue *getGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
179 
180  /// Get a Comdat with the specified name, creating a forward reference
181  /// record if needed.
182  Comdat *getComdat(const std::string &Name, LocTy Loc);
183 
184  // Helper Routines.
185  bool parseToken(lltok::Kind T, const char *ErrMsg);
186  bool EatIfPresent(lltok::Kind T) {
187  if (Lex.getKind() != T) return false;
188  Lex.Lex();
189  return true;
190  }
191 
192  FastMathFlags EatFastMathFlagsIfPresent() {
193  FastMathFlags FMF;
194  while (true)
195  switch (Lex.getKind()) {
196  case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue;
197  case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
198  case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
199  case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
200  case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
201  case lltok::kw_contract:
202  FMF.setAllowContract(true);
203  Lex.Lex();
204  continue;
205  case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue;
206  case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue;
207  default: return FMF;
208  }
209  return FMF;
210  }
211 
212  bool parseOptionalToken(lltok::Kind T, bool &Present,
213  LocTy *Loc = nullptr) {
214  if (Lex.getKind() != T) {
215  Present = false;
216  } else {
217  if (Loc)
218  *Loc = Lex.getLoc();
219  Lex.Lex();
220  Present = true;
221  }
222  return false;
223  }
224  bool parseStringConstant(std::string &Result);
225  bool parseUInt32(unsigned &Val);
226  bool parseUInt32(unsigned &Val, LocTy &Loc) {
227  Loc = Lex.getLoc();
228  return parseUInt32(Val);
229  }
230  bool parseUInt64(uint64_t &Val);
231  bool parseUInt64(uint64_t &Val, LocTy &Loc) {
232  Loc = Lex.getLoc();
233  return parseUInt64(Val);
234  }
235  bool parseFlag(unsigned &Val);
236 
237  bool parseStringAttribute(AttrBuilder &B);
238 
239  bool parseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
240  bool parseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
241  bool parseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
242  bool parseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0);
243  bool parseOptionalProgramAddrSpace(unsigned &AddrSpace) {
244  return parseOptionalAddrSpace(
245  AddrSpace, M->getDataLayout().getProgramAddressSpace());
246  };
247  bool parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B,
248  bool InAttrGroup);
249  bool parseOptionalParamOrReturnAttrs(AttrBuilder &B, bool IsParam);
250  bool parseOptionalParamAttrs(AttrBuilder &B) {
251  return parseOptionalParamOrReturnAttrs(B, true);
252  }
253  bool parseOptionalReturnAttrs(AttrBuilder &B) {
254  return parseOptionalParamOrReturnAttrs(B, false);
255  }
256  bool parseOptionalLinkage(unsigned &Res, bool &HasLinkage,
257  unsigned &Visibility, unsigned &DLLStorageClass,
258  bool &DSOLocal);
259  void parseOptionalDSOLocal(bool &DSOLocal);
260  void parseOptionalVisibility(unsigned &Res);
261  void parseOptionalDLLStorageClass(unsigned &Res);
262  bool parseOptionalCallingConv(unsigned &CC);
263  bool parseOptionalAlignment(MaybeAlign &Alignment,
264  bool AllowParens = false);
265  bool parseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
266  bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
267  AtomicOrdering &Ordering);
268  bool parseScope(SyncScope::ID &SSID);
269  bool parseOrdering(AtomicOrdering &Ordering);
270  bool parseOptionalStackAlignment(unsigned &Alignment);
271  bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
272  bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
273  bool &AteExtraComma);
274  bool parseAllocSizeArguments(unsigned &BaseSizeArg,
275  Optional<unsigned> &HowManyArg);
276  bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
277  bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
278  bool &AteExtraComma);
279  bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
280  bool AteExtraComma;
281  if (parseIndexList(Indices, AteExtraComma))
282  return true;
283  if (AteExtraComma)
284  return tokError("expected index");
285  return false;
286  }
287 
288  // Top-Level Entities
289  bool parseTopLevelEntities();
290  bool validateEndOfModule(bool UpgradeDebugInfo);
291  bool validateEndOfIndex();
292  bool parseTargetDefinitions();
293  bool parseTargetDefinition();
294  bool parseModuleAsm();
295  bool parseSourceFileName();
296  bool parseUnnamedType();
297  bool parseNamedType();
298  bool parseDeclare();
299  bool parseDefine();
300 
301  bool parseGlobalType(bool &IsConstant);
302  bool parseUnnamedGlobal();
303  bool parseNamedGlobal();
304  bool parseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage,
305  bool HasLinkage, unsigned Visibility,
306  unsigned DLLStorageClass, bool DSOLocal,
308  GlobalVariable::UnnamedAddr UnnamedAddr);
309  bool parseAliasOrIFunc(const std::string &Name, LocTy NameLoc, unsigned L,
310  unsigned Visibility, unsigned DLLStorageClass,
311  bool DSOLocal, GlobalVariable::ThreadLocalMode TLM,
312  GlobalVariable::UnnamedAddr UnnamedAddr);
313  bool parseComdat();
314  bool parseStandaloneMetadata();
315  bool parseNamedMetadata();
316  bool parseMDString(MDString *&Result);
317  bool parseMDNodeID(MDNode *&Result);
318  bool parseUnnamedAttrGrp();
319  bool parseFnAttributeValuePairs(AttrBuilder &B,
320  std::vector<unsigned> &FwdRefAttrGrps,
321  bool inAttrGrp, LocTy &BuiltinLoc);
322  bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
323  Attribute::AttrKind AttrKind);
324 
325  // Module Summary Index Parsing.
326  bool skipModuleSummaryEntry();
327  bool parseSummaryEntry();
328  bool parseModuleEntry(unsigned ID);
329  bool parseModuleReference(StringRef &ModulePath);
330  bool parseGVReference(ValueInfo &VI, unsigned &GVId);
331  bool parseSummaryIndexFlags();
332  bool parseBlockCount();
333  bool parseGVEntry(unsigned ID);
334  bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
335  bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
336  bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
337  bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
338  bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
339  bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
340  bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
341  bool parseHotness(CalleeInfo::HotnessType &Hotness);
342  bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
343  bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
344  bool parseVFuncIdList(lltok::Kind Kind,
345  std::vector<FunctionSummary::VFuncId> &VFuncIdList);
346  bool parseConstVCallList(
348  std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
349  using IdToIndexMapType =
350  std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
351  bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
352  IdToIndexMapType &IdToIndexMap, unsigned Index);
353  bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
354  IdToIndexMapType &IdToIndexMap, unsigned Index);
355  bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
356  bool parseOptionalParamAccesses(
357  std::vector<FunctionSummary::ParamAccess> &Params);
358  bool parseParamNo(uint64_t &ParamNo);
359  using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
360  bool parseParamAccess(FunctionSummary::ParamAccess &Param,
361  IdLocListType &IdLocList);
362  bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
363  IdLocListType &IdLocList);
364  bool parseParamAccessOffset(ConstantRange &Range);
365  bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
366  bool parseTypeIdEntry(unsigned ID);
367  bool parseTypeIdSummary(TypeIdSummary &TIS);
368  bool parseTypeIdCompatibleVtableEntry(unsigned ID);
369  bool parseTypeTestResolution(TypeTestResolution &TTRes);
370  bool parseOptionalWpdResolutions(
371  std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
372  bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
373  bool parseOptionalResByArg(
374  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
375  &ResByArg);
376  bool parseArgs(std::vector<uint64_t> &Args);
377  void addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
379  std::unique_ptr<GlobalValueSummary> Summary);
380 
381  // Type Parsing.
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);
385  }
386  bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
387  bool AllowVoid = false) {
388  Loc = Lex.getLoc();
389  return parseType(Result, Msg, AllowVoid);
390  }
391  bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
392  Loc = Lex.getLoc();
393  return parseType(Result, AllowVoid);
394  }
395  bool parseAnonStructType(Type *&Result, bool Packed);
396  bool parseStructBody(SmallVectorImpl<Type *> &Body);
397  bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
398  std::pair<Type *, LocTy> &Entry,
399  Type *&ResultTy);
400 
401  bool parseArrayVectorType(Type *&Result, bool IsVector);
402  bool parseFunctionType(Type *&Result);
403 
404  // Function Semantic Analysis.
405  class PerFunctionState {
406  LLParser &P;
407  Function &F;
408  std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
409  std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
410  std::vector<Value*> NumberedVals;
411 
412  /// FunctionNumber - If this is an unnamed function, this is the slot
413  /// number of it, otherwise it is -1.
414  int FunctionNumber;
415  public:
416  PerFunctionState(LLParser &p, Function &f, int functionNumber);
417  ~PerFunctionState();
418 
419  Function &getFunction() const { return F; }
420 
421  bool finishFunction();
422 
423  /// GetVal - Get a value with the specified name or ID, creating a
424  /// forward reference record if needed. This can return null if the value
425  /// exists but does not have the right type.
426  Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
427  Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
428 
429  /// setInstName - After an instruction is parsed and inserted into its
430  /// basic block, this installs its name.
431  bool setInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
432  Instruction *Inst);
433 
434  /// GetBB - Get a basic block with the specified name or ID, creating a
435  /// forward reference record if needed. This can return null if the value
436  /// is not a BasicBlock.
437  BasicBlock *getBB(const std::string &Name, LocTy Loc);
438  BasicBlock *getBB(unsigned ID, LocTy Loc);
439 
440  /// DefineBB - Define the specified basic block, which is either named or
441  /// unnamed. If there is an error, this returns null otherwise it returns
442  /// the block being defined.
443  BasicBlock *defineBB(const std::string &Name, int NameID, LocTy Loc);
444 
445  bool resolveForwardRefBlockAddresses();
446  };
447 
448  bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
449  PerFunctionState *PFS);
450 
451  Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
452  Value *Val);
453 
454  bool parseConstantValue(Type *Ty, Constant *&C);
455  bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
456  bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
457  return parseValue(Ty, V, &PFS);
458  }
459 
460  bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
461  Loc = Lex.getLoc();
462  return parseValue(Ty, V, &PFS);
463  }
464 
465  bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
466  bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
467  return parseTypeAndValue(V, &PFS);
468  }
469  bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
470  Loc = Lex.getLoc();
471  return parseTypeAndValue(V, PFS);
472  }
473  bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
474  PerFunctionState &PFS);
475  bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
476  LocTy Loc;
477  return parseTypeAndBasicBlock(BB, Loc, PFS);
478  }
479 
480  struct ParamInfo {
481  LocTy Loc;
482  Value *V;
483  AttributeSet Attrs;
484  ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
485  : Loc(loc), V(v), Attrs(attrs) {}
486  };
487  bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
488  PerFunctionState &PFS, bool IsMustTailCall = false,
489  bool InVarArgsFunc = false);
490 
491  bool
492  parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
493  PerFunctionState &PFS);
494 
495  bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
496  PerFunctionState &PFS);
497 
498  // Constant Parsing.
499  bool parseValID(ValID &ID, PerFunctionState *PFS,
500  Type *ExpectedTy = nullptr);
501  bool parseGlobalValue(Type *Ty, Constant *&C);
502  bool parseGlobalTypeAndValue(Constant *&V);
503  bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
504  Optional<unsigned> *InRangeOp = nullptr);
505  bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
506  bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
507  bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
508  PerFunctionState *PFS);
509  bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
510  bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
511  bool parseMDNode(MDNode *&N);
512  bool parseMDNodeTail(MDNode *&N);
513  bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
514  bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
515  bool parseInstructionMetadata(Instruction &Inst);
516  bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
517  bool parseOptionalFunctionMetadata(Function &F);
518 
519  template <class FieldTy>
520  bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
521  template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
522  template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
523  template <class ParserTy>
524  bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
525  bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
526 
527 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
528  bool parse##CLASS(MDNode *&Result, bool IsDistinct);
529 #include "llvm/IR/Metadata.def"
530  bool parseDIArgList(MDNode *&Result, bool IsDistinct,
531  PerFunctionState *PFS);
532 
533  // Function Parsing.
534  struct ArgInfo {
535  LocTy Loc;
536  Type *Ty;
537  AttributeSet Attrs;
538  std::string Name;
539  ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
540  : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
541  };
542  bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &IsVarArg);
543  bool parseFunctionHeader(Function *&Fn, bool IsDefine);
544  bool parseFunctionBody(Function &Fn);
545  bool parseBasicBlock(PerFunctionState &PFS);
546 
547  enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
548 
549  // Instruction Parsing. Each instruction parsing routine can return with a
550  // normal result, an error result, or return having eaten an extra comma.
551  enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
552  int parseInstruction(Instruction *&Inst, BasicBlock *BB,
553  PerFunctionState &PFS);
554  bool parseCmpPredicate(unsigned &P, unsigned Opc);
555 
556  bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
557  bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
558  bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
559  bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
560  bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
561  bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
562  bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
563  bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
564  bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
565  bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
566  bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
567  bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
568 
569  bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
570  bool IsFP);
571  bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
572  unsigned Opc, bool IsFP);
573  bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
574  bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
575  bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
576  bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
577  bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
578  bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
579  bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
580  bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
581  int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
582  bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
583  bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
585  int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
586  int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
587  int parseStore(Instruction *&Inst, PerFunctionState &PFS);
588  int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
589  int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
590  int parseFence(Instruction *&Inst, PerFunctionState &PFS);
591  int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
592  int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
593  int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
594  bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
595 
596  // Use-list order directives.
597  bool parseUseListOrder(PerFunctionState *PFS = nullptr);
598  bool parseUseListOrderBB();
599  bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
600  bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
601  };
602 } // End llvm namespace
603 
604 #endif
llvm::GlobalValue::GUID
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:509
llvm::LLLexer
Definition: LLLexer.h:28
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::GlobalValue::UnnamedAddr
UnnamedAddr
Definition: GlobalValue.h:190
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:22
llvm::LLParser::LocTy
LLLexer::LocTy LocTy
Definition: LLParser.h:88
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::ValID::t_LocalID
@ t_LocalID
Definition: LLParser.h:46
Optional.h
llvm::lltok::kw_arcp
@ kw_arcp
Definition: LLToken.h:105
llvm::UpgradeDebugInfo
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
Definition: AutoUpgrade.cpp:4152
Parser.h
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:235
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::LLParser::parseTypeAtBeginning
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
Definition: LLParser.cpp:98
llvm::ValID::t_PackedConstantStruct
@ t_PackedConstantStruct
Definition: LLParser.h:54
llvm::ValID::t_Constant
@ t_Constant
Definition: LLParser.h:51
llvm::ValID::t_Poison
@ t_Poison
Definition: LLParser.h:49
llvm::LLLexer::Error
bool Error(LocTy ErrorLoc, const Twine &Msg) const
Definition: LLLexer.cpp:28
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1176
llvm::LLLexer::getLoc
LocTy getLoc() const
Definition: LLLexer.h:57
llvm::ValID::StrVal2
std::string StrVal2
Definition: LLParser.h:60
error
#define error(X)
Definition: SymbolRecordMapping.cpp:14
T
#define T
Definition: Mips16ISelLowering.cpp:341
Operator.h
llvm::ValID::ConstantStructElts
std::unique_ptr< Constant *[]> ConstantStructElts
Definition: LLParser.h:64
RHS
Value * RHS
Definition: X86PartialReduction.cpp:74
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
p
the resulting code requires compare and branches when and if * p
Definition: README.txt:396
llvm::lltok::kw_nnan
@ kw_nnan
Definition: LLToken.h:102
ModuleSummaryIndex.h
llvm::LLParser
Definition: LLParser.h:86
attrs
function attrs
Definition: FunctionAttrs.cpp:1901
F
#define F(x, y, z)
Definition: MD5.cpp:55
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::parseType
Type * parseType(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type in the given string.
Definition: Parser.cpp:194
llvm::LLLexer::getKind
lltok::Kind getKind() const
Definition: LLLexer.h:58
llvm::ValID::ValID
ValID()=default
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::lltok::kw_contract
@ kw_contract
Definition: LLToken.h:106
f
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
llvm::LLParser::LLParser
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, ModuleSummaryIndex *Index, LLVMContext &Context, SlotMapping *Slots=nullptr)
Definition: LLParser.h:150
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ValID::APSIntVal
APSInt APSIntVal
Definition: LLParser.h:61
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:251
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:163
llvm::CalleeInfo::HotnessType
HotnessType
Definition: ModuleSummaryIndex.h:58
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::APSInt
An arbitrary precision integer that knows its signedness.
Definition: APSInt.h:22
llvm::lltok::kw_fast
@ kw_fast
Definition: LLToken.h:109
llvm::ValID::t_GlobalName
@ t_GlobalName
Definition: LLParser.h:47
StringMap.h
llvm::LLParser::Run
bool Run(bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback=[](StringRef) { return None;})
Run: module ::= toplevelentity*.
Definition: LLParser.cpp:63
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:153
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
Type.h
llvm::ValID::t_Undef
@ t_Undef
Definition: LLParser.h:49
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:109
llvm::ValID::FTy
FunctionType * FTy
Definition: LLParser.h:59
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::ValID::Loc
LLLexer::LocTy Loc
Definition: LLParser.h:57
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition: AtomicOrdering.h:56
llvm::APFloat
Definition: APFloat.h:701
llvm::SlotMapping
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:32
VI
@ VI
Definition: SIInstrInfo.cpp:7695
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::ValID::operator<
bool operator<(const ValID &RHS) const
Definition: LLParser.h:76
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
uint64_t
llvm::CallInst::TailCallKind
TailCallKind
Definition: Instructions.h:1655
llvm::ValID::t_InlineAsm
@ t_InlineAsm
Definition: LLParser.h:52
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::SyncScope::ID
uint8_t ID
Definition: LLVMContext.h:47
llvm::VTableFuncList
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
Definition: ModuleSummaryIndex.h:883
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:71
llvm::ValID::t_APSInt
@ t_APSInt
Definition: LLParser.h:48
TemplateParamKind::Type
@ Type
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ValID::Kind
enum llvm::ValID::@38 Kind
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::LLLexer::Lex
lltok::Kind Lex()
Definition: LLLexer.h:52
llvm::ValID
ValID - Represents a reference of a definition of some sort with no type.
Definition: LLParser.h:44
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::lltok::kw_ninf
@ kw_ninf
Definition: LLToken.h:103
llvm::ValID::UIntVal
unsigned UIntVal
Definition: LLParser.h:58
llvm::ValID::NoCFI
bool NoCFI
Definition: LLParser.h:65
llvm::ValID::ValID
ValID(const ValID &RHS)
Definition: LLParser.h:68
llvm::ValID::t_LocalName
@ t_LocalName
Definition: LLParser.h:47
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::LLParser::parseStandaloneConstantValue
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
Definition: LLParser.cpp:85
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
LLLexer.h
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::ValID::ConstantVal
Constant * ConstantVal
Definition: LLParser.h:63
Attributes.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::GlobalValue::ThreadLocalMode
ThreadLocalMode
Definition: GlobalValue.h:178
llvm::ValID::t_GlobalID
@ t_GlobalID
Definition: LLParser.h:46
llvm::lltok::kw_nsz
@ kw_nsz
Definition: LLToken.h:104
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::ValID::t_EmptyArray
@ t_EmptyArray
Definition: LLParser.h:50
llvm::lltok::kw_afn
@ kw_afn
Definition: LLToken.h:108
llvm::ValID::t_Null
@ t_Null
Definition: LLParser.h:49
getVal
static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)
Definition: ProfileSummary.cpp:120
Instructions.h
llvm::ValID::t_ConstantStruct
@ t_ConstantStruct
Definition: LLParser.h:53
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1088
N
#define N
llvm::ValID::t_Zero
@ t_Zero
Definition: LLParser.h:49
llvm::LLParser::getContext
LLVMContext & getContext()
Definition: LLParser.h:164
llvm::ValID::t_None
@ t_None
Definition: LLParser.h:49
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::lltok::kw_reassoc
@ kw_reassoc
Definition: LLToken.h:107
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::ValID::APFloatVal
APFloat APFloatVal
Definition: LLParser.h:62
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::ValID::StrVal
std::string StrVal
Definition: LLParser.h:60
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::ValID::t_APFloat
@ t_APFloat
Definition: LLParser.h:48