LLVM  17.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/StringMap.h"
18 #include "llvm/AsmParser/Parser.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/FMF.h"
21 #include "llvm/IR/Instructions.h"
23 #include <map>
24 #include <optional>
25 
26 namespace llvm {
27  class Module;
28  class ConstantRange;
29  class FunctionType;
30  class GlobalObject;
31  class SMDiagnostic;
32  class SMLoc;
33  class SourceMgr;
34  class Type;
35  struct MaybeAlign;
36  class Function;
37  class Value;
38  class BasicBlock;
39  class Instruction;
40  class Constant;
41  class GlobalValue;
42  class Comdat;
43  class MDString;
44  class MDNode;
45  class MemoryEffects;
46  struct SlotMapping;
47 
48  /// ValID - Represents a reference of a definition of some sort with no type.
49  /// There are several cases where we have to parse the value but where the
50  /// type can depend on later context. This may either be a numeric reference
51  /// or a symbolic (%var) reference. This is just a discriminated union.
52  struct ValID {
53  enum {
54  t_LocalID, t_GlobalID, // ID in UIntVal.
55  t_LocalName, t_GlobalName, // Name in StrVal.
56  t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal.
57  t_Null, t_Undef, t_Zero, t_None, t_Poison, // No value.
58  t_EmptyArray, // No value: []
59  t_Constant, // Value in ConstantVal.
60  t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal.
61  t_ConstantStruct, // Value in ConstantStructElts.
62  t_PackedConstantStruct // Value in ConstantStructElts.
63  } Kind = t_LocalID;
64 
66  unsigned UIntVal;
67  FunctionType *FTy = nullptr;
68  std::string StrVal, StrVal2;
72  std::unique_ptr<Constant *[]> ConstantStructElts;
73  bool NoCFI = false;
74 
75  ValID() = default;
76  ValID(const ValID &RHS)
80  NoCFI(RHS.NoCFI) {
81  assert(!RHS.ConstantStructElts);
82  }
83 
84  bool operator<(const ValID &RHS) const {
85  assert(Kind == RHS.Kind && "Comparing ValIDs of different kinds");
86  if (Kind == t_LocalID || Kind == t_GlobalID)
87  return UIntVal < RHS.UIntVal;
90  "Ordering not defined for this ValID kind yet");
91  return StrVal < RHS.StrVal;
92  }
93  };
94 
95  class LLParser {
96  public:
98  private:
99  LLVMContext &Context;
100  // Lexer to determine whether to use opaque pointers or not.
101  LLLexer OPLex;
102  LLLexer Lex;
103  // Module being parsed, null if we are only parsing summary index.
104  Module *M;
105  // Summary index being parsed, null if we are only parsing Module.
107  SlotMapping *Slots;
108 
109  SmallVector<Instruction*, 64> InstsWithTBAATag;
110 
111  /// DIAssignID metadata does not support temporary RAUW so we cannot use
112  /// the normal metadata forward reference resolution method. Instead,
113  /// non-temporary DIAssignID are attached to instructions (recorded here)
114  /// then replaced later.
115  DenseMap<MDNode *, SmallVector<Instruction *, 2>> TempDIAssignIDAttachments;
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  // References to dso_local_equivalent. The key is the global's ValID, the
143  // value is a placeholder value that will be replaced. Note there are two
144  // maps for tracking ValIDs that are GlobalNames and ValIDs that are
145  // GlobalIDs. These are needed because "operator<" doesn't discriminate
146  // between the two.
147  std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
148  std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
149 
150  // Attribute builder reference information.
151  std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
152  std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
153 
154  // Summary global value reference information.
155  std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
156  ForwardRefValueInfos;
157  std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
158  ForwardRefAliasees;
159  std::vector<ValueInfo> NumberedValueInfos;
160 
161  // Summary type id reference information.
162  std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
163  ForwardRefTypeIds;
164 
165  // Map of module ID to path.
166  std::map<unsigned, StringRef> ModuleIdMap;
167 
168  /// Only the llvm-as tool may set this to false to bypass
169  /// UpgradeDebuginfo so it can generate broken bitcode.
170  bool UpgradeDebugInfo;
171 
172  std::string SourceFileName;
173 
174  public:
177  SlotMapping *Slots = nullptr)
178  : Context(Context), OPLex(F, SM, Err, Context),
179  Lex(F, SM, Err, Context), M(M), Index(Index), Slots(Slots),
180  BlockAddressPFS(nullptr) {}
181  bool Run(
182  bool UpgradeDebugInfo,
183  DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
184  return std::nullopt;
185  });
186 
187  bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
188 
189  bool parseTypeAtBeginning(Type *&Ty, unsigned &Read,
190  const SlotMapping *Slots);
191 
193 
194  private:
195  bool error(LocTy L, const Twine &Msg) const { return Lex.Error(L, Msg); }
196  bool tokError(const Twine &Msg) const { return error(Lex.getLoc(), Msg); }
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  GlobalValue *getGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
207 
208  /// Get a Comdat with the specified name, creating a forward reference
209  /// record if needed.
210  Comdat *getComdat(const std::string &Name, LocTy Loc);
211 
212  // Helper Routines.
213  bool parseToken(lltok::Kind T, const char *ErrMsg);
214  bool EatIfPresent(lltok::Kind T) {
215  if (Lex.getKind() != T) return false;
216  Lex.Lex();
217  return true;
218  }
219 
220  FastMathFlags EatFastMathFlagsIfPresent() {
221  FastMathFlags FMF;
222  while (true)
223  switch (Lex.getKind()) {
224  case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue;
225  case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
226  case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
227  case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
228  case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
229  case lltok::kw_contract:
230  FMF.setAllowContract(true);
231  Lex.Lex();
232  continue;
233  case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue;
234  case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue;
235  default: return FMF;
236  }
237  return FMF;
238  }
239 
240  bool parseOptionalToken(lltok::Kind T, bool &Present,
241  LocTy *Loc = nullptr) {
242  if (Lex.getKind() != T) {
243  Present = false;
244  } else {
245  if (Loc)
246  *Loc = Lex.getLoc();
247  Lex.Lex();
248  Present = true;
249  }
250  return false;
251  }
252  bool parseStringConstant(std::string &Result);
253  bool parseUInt32(unsigned &Val);
254  bool parseUInt32(unsigned &Val, LocTy &Loc) {
255  Loc = Lex.getLoc();
256  return parseUInt32(Val);
257  }
258  bool parseUInt64(uint64_t &Val);
259  bool parseUInt64(uint64_t &Val, LocTy &Loc) {
260  Loc = Lex.getLoc();
261  return parseUInt64(Val);
262  }
263  bool parseFlag(unsigned &Val);
264 
265  bool parseStringAttribute(AttrBuilder &B);
266 
267  bool parseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
268  bool parseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
269  bool parseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
270  bool parseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0);
271  bool parseOptionalProgramAddrSpace(unsigned &AddrSpace) {
272  return parseOptionalAddrSpace(
273  AddrSpace, M->getDataLayout().getProgramAddressSpace());
274  };
275  bool parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B,
276  bool InAttrGroup);
277  bool parseOptionalParamOrReturnAttrs(AttrBuilder &B, bool IsParam);
278  bool parseOptionalParamAttrs(AttrBuilder &B) {
279  return parseOptionalParamOrReturnAttrs(B, true);
280  }
281  bool parseOptionalReturnAttrs(AttrBuilder &B) {
282  return parseOptionalParamOrReturnAttrs(B, false);
283  }
284  bool parseOptionalLinkage(unsigned &Res, bool &HasLinkage,
285  unsigned &Visibility, unsigned &DLLStorageClass,
286  bool &DSOLocal);
287  void parseOptionalDSOLocal(bool &DSOLocal);
288  void parseOptionalVisibility(unsigned &Res);
289  void parseOptionalDLLStorageClass(unsigned &Res);
290  bool parseOptionalCallingConv(unsigned &CC);
291  bool parseOptionalAlignment(MaybeAlign &Alignment,
292  bool AllowParens = false);
293  bool parseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
294  bool parseOptionalUWTableKind(UWTableKind &Kind);
295  bool parseAllocKind(AllocFnKind &Kind);
296  std::optional<MemoryEffects> parseMemoryAttr();
297  bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
298  AtomicOrdering &Ordering);
299  bool parseScope(SyncScope::ID &SSID);
300  bool parseOrdering(AtomicOrdering &Ordering);
301  bool parseOptionalStackAlignment(unsigned &Alignment);
302  bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
303  bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
304  bool &AteExtraComma);
305  bool parseAllocSizeArguments(unsigned &BaseSizeArg,
306  std::optional<unsigned> &HowManyArg);
307  bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
308  bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
309  bool &AteExtraComma);
310  bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
311  bool AteExtraComma;
312  if (parseIndexList(Indices, AteExtraComma))
313  return true;
314  if (AteExtraComma)
315  return tokError("expected index");
316  return false;
317  }
318 
319  // Top-Level Entities
320  bool parseTopLevelEntities();
321  bool validateEndOfModule(bool UpgradeDebugInfo);
322  bool validateEndOfIndex();
323  bool parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback);
324  bool parseTargetDefinition(std::string &TentativeDLStr, LocTy &DLStrLoc);
325  bool parseModuleAsm();
326  bool parseSourceFileName();
327  bool parseUnnamedType();
328  bool parseNamedType();
329  bool parseDeclare();
330  bool parseDefine();
331 
332  bool parseGlobalType(bool &IsConstant);
333  bool parseUnnamedGlobal();
334  bool parseNamedGlobal();
335  bool parseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage,
336  bool HasLinkage, unsigned Visibility,
337  unsigned DLLStorageClass, bool DSOLocal,
339  GlobalVariable::UnnamedAddr UnnamedAddr);
340  bool parseAliasOrIFunc(const std::string &Name, LocTy NameLoc, unsigned L,
341  unsigned Visibility, unsigned DLLStorageClass,
342  bool DSOLocal, GlobalVariable::ThreadLocalMode TLM,
343  GlobalVariable::UnnamedAddr UnnamedAddr);
344  bool parseComdat();
345  bool parseStandaloneMetadata();
346  bool parseNamedMetadata();
347  bool parseMDString(MDString *&Result);
348  bool parseMDNodeID(MDNode *&Result);
349  bool parseUnnamedAttrGrp();
350  bool parseFnAttributeValuePairs(AttrBuilder &B,
351  std::vector<unsigned> &FwdRefAttrGrps,
352  bool inAttrGrp, LocTy &BuiltinLoc);
353  bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
354  Attribute::AttrKind AttrKind);
355 
356  // Module Summary Index Parsing.
357  bool skipModuleSummaryEntry();
358  bool parseSummaryEntry();
359  bool parseModuleEntry(unsigned ID);
360  bool parseModuleReference(StringRef &ModulePath);
361  bool parseGVReference(ValueInfo &VI, unsigned &GVId);
362  bool parseSummaryIndexFlags();
363  bool parseBlockCount();
364  bool parseGVEntry(unsigned ID);
365  bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
366  bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
367  bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
368  bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
369  bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
370  bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
371  bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
372  bool parseHotness(CalleeInfo::HotnessType &Hotness);
373  bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
374  bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
375  bool parseVFuncIdList(lltok::Kind Kind,
376  std::vector<FunctionSummary::VFuncId> &VFuncIdList);
377  bool parseConstVCallList(
379  std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
380  using IdToIndexMapType =
381  std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
382  bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
383  IdToIndexMapType &IdToIndexMap, unsigned Index);
384  bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
385  IdToIndexMapType &IdToIndexMap, unsigned Index);
386  bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
387  bool parseOptionalParamAccesses(
388  std::vector<FunctionSummary::ParamAccess> &Params);
389  bool parseParamNo(uint64_t &ParamNo);
390  using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
391  bool parseParamAccess(FunctionSummary::ParamAccess &Param,
392  IdLocListType &IdLocList);
393  bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
394  IdLocListType &IdLocList);
395  bool parseParamAccessOffset(ConstantRange &Range);
396  bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
397  bool parseTypeIdEntry(unsigned ID);
398  bool parseTypeIdSummary(TypeIdSummary &TIS);
399  bool parseTypeIdCompatibleVtableEntry(unsigned ID);
400  bool parseTypeTestResolution(TypeTestResolution &TTRes);
401  bool parseOptionalWpdResolutions(
402  std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
403  bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
404  bool parseOptionalResByArg(
405  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
406  &ResByArg);
407  bool parseArgs(std::vector<uint64_t> &Args);
408  void addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
410  std::unique_ptr<GlobalValueSummary> Summary);
411  bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
412  bool parseMemProfs(std::vector<MIBInfo> &MIBs);
413  bool parseAllocType(uint8_t &AllocType);
414  bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
415 
416  // Type Parsing.
417  bool parseType(Type *&Result, const Twine &Msg, bool AllowVoid = false);
418  bool parseType(Type *&Result, bool AllowVoid = false) {
419  return parseType(Result, "expected type", AllowVoid);
420  }
421  bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
422  bool AllowVoid = false) {
423  Loc = Lex.getLoc();
424  return parseType(Result, Msg, AllowVoid);
425  }
426  bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
427  Loc = Lex.getLoc();
428  return parseType(Result, AllowVoid);
429  }
430  bool parseAnonStructType(Type *&Result, bool Packed);
431  bool parseStructBody(SmallVectorImpl<Type *> &Body);
432  bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
433  std::pair<Type *, LocTy> &Entry,
434  Type *&ResultTy);
435 
436  bool parseArrayVectorType(Type *&Result, bool IsVector);
437  bool parseFunctionType(Type *&Result);
438  bool parseTargetExtType(Type *&Result);
439 
440  // Function Semantic Analysis.
441  class PerFunctionState {
442  LLParser &P;
443  Function &F;
444  std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
445  std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
446  std::vector<Value*> NumberedVals;
447 
448  /// FunctionNumber - If this is an unnamed function, this is the slot
449  /// number of it, otherwise it is -1.
450  int FunctionNumber;
451  public:
452  PerFunctionState(LLParser &p, Function &f, int functionNumber);
453  ~PerFunctionState();
454 
455  Function &getFunction() const { return F; }
456 
457  bool finishFunction();
458 
459  /// GetVal - Get a value with the specified name or ID, creating a
460  /// forward reference record if needed. This can return null if the value
461  /// exists but does not have the right type.
462  Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
463  Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
464 
465  /// setInstName - After an instruction is parsed and inserted into its
466  /// basic block, this installs its name.
467  bool setInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
468  Instruction *Inst);
469 
470  /// GetBB - Get a basic block with the specified name or ID, creating a
471  /// forward reference record if needed. This can return null if the value
472  /// is not a BasicBlock.
473  BasicBlock *getBB(const std::string &Name, LocTy Loc);
474  BasicBlock *getBB(unsigned ID, LocTy Loc);
475 
476  /// DefineBB - Define the specified basic block, which is either named or
477  /// unnamed. If there is an error, this returns null otherwise it returns
478  /// the block being defined.
479  BasicBlock *defineBB(const std::string &Name, int NameID, LocTy Loc);
480 
481  bool resolveForwardRefBlockAddresses();
482  };
483 
484  bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
485  PerFunctionState *PFS);
486 
487  Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
488  Value *Val);
489 
490  bool parseConstantValue(Type *Ty, Constant *&C);
491  bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
492  bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
493  return parseValue(Ty, V, &PFS);
494  }
495 
496  bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
497  Loc = Lex.getLoc();
498  return parseValue(Ty, V, &PFS);
499  }
500 
501  bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
502  bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
503  return parseTypeAndValue(V, &PFS);
504  }
505  bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
506  Loc = Lex.getLoc();
507  return parseTypeAndValue(V, PFS);
508  }
509  bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
510  PerFunctionState &PFS);
511  bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
512  LocTy Loc;
513  return parseTypeAndBasicBlock(BB, Loc, PFS);
514  }
515 
516  struct ParamInfo {
517  LocTy Loc;
518  Value *V;
519  AttributeSet Attrs;
520  ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
521  : Loc(loc), V(v), Attrs(attrs) {}
522  };
523  bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
524  PerFunctionState &PFS, bool IsMustTailCall = false,
525  bool InVarArgsFunc = false);
526 
527  bool
528  parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
529  PerFunctionState &PFS);
530 
531  bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
532  PerFunctionState &PFS);
533 
534  bool resolveFunctionType(Type *RetType,
535  const SmallVector<ParamInfo, 16> &ArgList,
536  FunctionType *&FuncTy);
537 
538  // Constant Parsing.
539  bool parseValID(ValID &ID, PerFunctionState *PFS,
540  Type *ExpectedTy = nullptr);
541  bool parseGlobalValue(Type *Ty, Constant *&C);
542  bool parseGlobalTypeAndValue(Constant *&V);
543  bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
544  std::optional<unsigned> *InRangeOp = nullptr);
545  bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
546  bool parseSanitizer(GlobalVariable *GV);
547  bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
548  bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
549  PerFunctionState *PFS);
550  bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
551  bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
552  bool parseMDNode(MDNode *&N);
553  bool parseMDNodeTail(MDNode *&N);
554  bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
555  bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
556  bool parseInstructionMetadata(Instruction &Inst);
557  bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
558  bool parseOptionalFunctionMetadata(Function &F);
559 
560  template <class FieldTy>
561  bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
562  template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
563  template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
564  template <class ParserTy>
565  bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
566  bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
567 
568 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
569  bool parse##CLASS(MDNode *&Result, bool IsDistinct);
570 #include "llvm/IR/Metadata.def"
571  bool parseDIArgList(MDNode *&Result, bool IsDistinct,
572  PerFunctionState *PFS);
573 
574  // Function Parsing.
575  struct ArgInfo {
576  LocTy Loc;
577  Type *Ty;
578  AttributeSet Attrs;
579  std::string Name;
580  ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
581  : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
582  };
583  bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &IsVarArg);
584  bool parseFunctionHeader(Function *&Fn, bool IsDefine);
585  bool parseFunctionBody(Function &Fn);
586  bool parseBasicBlock(PerFunctionState &PFS);
587 
588  enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
589 
590  // Instruction Parsing. Each instruction parsing routine can return with a
591  // normal result, an error result, or return having eaten an extra comma.
592  enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
593  int parseInstruction(Instruction *&Inst, BasicBlock *BB,
594  PerFunctionState &PFS);
595  bool parseCmpPredicate(unsigned &P, unsigned Opc);
596 
597  bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
598  bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
599  bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
600  bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
601  bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
602  bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
603  bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
604  bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
605  bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
606  bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
607  bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
608  bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
609 
610  bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
611  bool IsFP);
612  bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
613  unsigned Opc, bool IsFP);
614  bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
615  bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
616  bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
617  bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
618  bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
619  bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
620  bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
621  bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
622  int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
623  bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
624  bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
626  int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
627  int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
628  int parseStore(Instruction *&Inst, PerFunctionState &PFS);
629  int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
630  int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
631  int parseFence(Instruction *&Inst, PerFunctionState &PFS);
632  int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
633  int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
634  int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
635  bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
636 
637  // Use-list order directives.
638  bool parseUseListOrder(PerFunctionState *PFS = nullptr);
639  bool parseUseListOrderBB();
640  bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
641  bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
642  };
643 } // End llvm namespace
644 
645 #endif
llvm::GlobalValue::GUID
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:583
llvm::LLLexer
Definition: LLLexer.h:28
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::GlobalValue::UnnamedAddr
UnnamedAddr
Definition: GlobalValue.h:205
llvm::ValID::t_Null
@ t_Null
Definition: LLParser.h:57
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FMF.h
llvm::LLParser::LocTy
LLLexer::LocTy LocTy
Definition: LLParser.h:97
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::lltok::kw_arcp
@ kw_arcp
Definition: LLToken.h:104
llvm::AArch64PACKey::ID
ID
Definition: AArch64BaseInfo.h:824
llvm::UpgradeDebugInfo
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
Definition: AutoUpgrade.cpp:4452
FunctionType
Definition: ItaniumDemangle.h:775
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:236
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:97
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:1199
llvm::LLLexer::getLoc
LocTy getLoc() const
Definition: LLLexer.h:57
llvm::ValID::t_GlobalName
@ t_GlobalName
Definition: LLParser.h:55
llvm::ValID::StrVal2
std::string StrVal2
Definition: LLParser.h:68
llvm::ValID::t_LocalName
@ t_LocalName
Definition: LLParser.h:55
error
#define error(X)
Definition: SymbolRecordMapping.cpp:14
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::ValID::ConstantStructElts
std::unique_ptr< Constant *[]> ConstantStructElts
Definition: LLParser.h:72
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
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:101
ModuleSummaryIndex.h
llvm::LLParser
Definition: LLParser.h:95
attrs
function attrs
Definition: FunctionAttrs.cpp:1851
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::ValID::t_APSInt
@ t_APSInt
Definition: LLParser.h:56
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:199
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ValID::Kind
enum llvm::ValID::@35 Kind
llvm::UWTableKind
UWTableKind
Definition: CodeGen.h:121
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:105
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:175
llvm::ValID::t_LocalID
@ t_LocalID
Definition: LLParser.h:54
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ValID::APSIntVal
APSInt APSIntVal
Definition: LLParser.h:69
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
llvm::CalleeInfo::HotnessType
HotnessType
Definition: ModuleSummaryIndex.h:59
llvm::dwarf::Index
Index
Definition: Dwarf.h:550
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:23
llvm::ValID::t_Undef
@ t_Undef
Definition: LLParser.h:57
llvm::ValID::t_EmptyArray
@ t_EmptyArray
Definition: LLParser.h:58
llvm::lltok::kw_fast
@ kw_fast
Definition: LLToken.h:108
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:156
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::ValID::FTy
FunctionType * FTy
Definition: LLParser.h:67
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:65
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition: AtomicOrdering.h:56
llvm::APFloat
Definition: APFloat.h:722
llvm::SlotMapping
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:32
VI
@ VI
Definition: SIInstrInfo.cpp:7994
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:84
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
uint64_t
llvm::CallInst::TailCallKind
TailCallKind
Definition: Instructions.h:1660
llvm::ValID::t_None
@ t_None
Definition: LLParser.h:57
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::DenseMap
Definition: DenseMap.h:714
llvm::SyncScope::ID
uint8_t ID
Definition: LLVMContext.h:46
llvm::VTableFuncList
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
Definition: ModuleSummaryIndex.h:994
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:86
TemplateParamKind::Type
@ Type
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ValID::t_ConstantStruct
@ t_ConstantStruct
Definition: LLParser.h:61
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:52
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::DataLayoutCallbackTy
llvm::function_ref< std::optional< std::string >StringRef, StringRef)> DataLayoutCallbackTy
Definition: Parser.h:30
llvm::lltok::kw_ninf
@ kw_ninf
Definition: LLToken.h:102
llvm::ValID::UIntVal
unsigned UIntVal
Definition: LLParser.h:66
llvm::ValID::NoCFI
bool NoCFI
Definition: LLParser.h:73
llvm::ValID::ValID
ValID(const ValID &RHS)
Definition: LLParser.h:76
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::LLParser::parseStandaloneConstantValue
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
Definition: LLParser.cpp:84
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
CC
auto CC
Definition: RISCVRedundantCopyElimination.cpp:79
Parser.h
llvm::ValID::ConstantVal
Constant * ConstantVal
Definition: LLParser.h:71
llvm::AMDGPU::SendMsg::Msg
const CustomOperand< const MCSubtargetInfo & > Msg[]
Definition: AMDGPUAsmUtils.cpp:39
Attributes.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::ValID::t_InlineAsm
@ t_InlineAsm
Definition: LLParser.h:60
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::GlobalValue::ThreadLocalMode
ThreadLocalMode
Definition: GlobalValue.h:191
llvm::ValID::t_Constant
@ t_Constant
Definition: LLParser.h:59
llvm::lltok::kw_nsz
@ kw_nsz
Definition: LLToken.h:103
llvm::LLParser::Run
bool Run(bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Run: module ::= toplevelentity*.
Definition: LLParser.cpp:65
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::lltok::kw_afn
@ kw_afn
Definition: LLToken.h:107
llvm::ValID::t_Zero
@ t_Zero
Definition: LLParser.h:57
llvm::ValID::t_Poison
@ t_Poison
Definition: LLParser.h:57
AllocType
AllocType
Definition: MemoryBuiltins.cpp:53
llvm::ValID::t_PackedConstantStruct
@ t_PackedConstantStruct
Definition: LLParser.h:62
getVal
static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)
Definition: ProfileSummary.cpp:119
Instructions.h
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1199
N
#define N
llvm::AllocFnKind
AllocFnKind
Definition: Attributes.h:49
llvm::LLParser::getContext
LLVMContext & getContext()
Definition: LLParser.h:192
llvm::ValID::t_APFloat
@ t_APFloat
Definition: LLParser.h:56
llvm::ValID::t_GlobalID
@ t_GlobalID
Definition: LLParser.h:54
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:106
StringMap.h
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::ValID::APFloatVal
APFloat APFloatVal
Definition: LLParser.h:70
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::ValID::StrVal
std::string StrVal
Definition: LLParser.h:68
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103