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 
66  ValID() = default;
67  ValID(const ValID &RHS)
68  : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy),
72  }
73 
74  bool operator<(const ValID &RHS) const {
75  if (Kind == t_LocalID || Kind == t_GlobalID)
76  return UIntVal < RHS.UIntVal;
79  "Ordering not defined for this ValID kind yet");
80  return StrVal < RHS.StrVal;
81  }
82  };
83 
84  class LLParser {
85  public:
87  private:
88  LLVMContext &Context;
89  LLLexer Lex;
90  // Module being parsed, null if we are only parsing summary index.
91  Module *M;
92  // Summary index being parsed, null if we are only parsing Module.
93  ModuleSummaryIndex *Index;
94  SlotMapping *Slots;
95 
96  SmallVector<Instruction*, 64> InstsWithTBAATag;
97 
98  // Type resolution handling data structures. The location is set when we
99  // have processed a use of the type but not a definition yet.
101  std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
102 
103  std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
104  std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
105 
106  // Global Value reference information.
107  std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
108  std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
109  std::vector<GlobalValue*> NumberedVals;
110 
111  // Comdat forward reference information.
112  std::map<std::string, LocTy> ForwardRefComdats;
113 
114  // References to blockaddress. The key is the function ValID, the value is
115  // a list of references to blocks in that function.
116  std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
117  class PerFunctionState;
118  /// Reference to per-function state to allow basic blocks to be
119  /// forward-referenced by blockaddress instructions within the same
120  /// function.
121  PerFunctionState *BlockAddressPFS;
122 
123  // Attribute builder reference information.
124  std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
125  std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
126 
127  // Summary global value reference information.
128  std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
129  ForwardRefValueInfos;
130  std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
131  ForwardRefAliasees;
132  std::vector<ValueInfo> NumberedValueInfos;
133 
134  // Summary type id reference information.
135  std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
136  ForwardRefTypeIds;
137 
138  // Map of module ID to path.
139  std::map<unsigned, StringRef> ModuleIdMap;
140 
141  /// Only the llvm-as tool may set this to false to bypass
142  /// UpgradeDebuginfo so it can generate broken bitcode.
143  bool UpgradeDebugInfo;
144 
145  std::string SourceFileName;
146 
147  public:
150  SlotMapping *Slots = nullptr)
151  : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index),
152  Slots(Slots), BlockAddressPFS(nullptr) {}
153  bool Run(
154  bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback =
155  [](StringRef) { return None; });
156 
157  bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
158 
159  bool parseTypeAtBeginning(Type *&Ty, unsigned &Read,
160  const SlotMapping *Slots);
161 
163 
164  private:
165  bool error(LocTy L, const Twine &Msg) const { return Lex.Error(L, Msg); }
166  bool tokError(const Twine &Msg) const { return error(Lex.getLoc(), Msg); }
167 
168  /// Restore the internal name and slot mappings using the mappings that
169  /// were created at an earlier parsing stage.
170  void restoreParsingState(const SlotMapping *Slots);
171 
172  /// getGlobalVal - Get a value with the specified name or ID, creating a
173  /// forward reference record if needed. This can return null if the value
174  /// exists but does not have the right type.
175  GlobalValue *getGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
176  GlobalValue *getGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
177 
178  /// Get a Comdat with the specified name, creating a forward reference
179  /// record if needed.
180  Comdat *getComdat(const std::string &Name, LocTy Loc);
181 
182  // Helper Routines.
183  bool parseToken(lltok::Kind T, const char *ErrMsg);
184  bool EatIfPresent(lltok::Kind T) {
185  if (Lex.getKind() != T) return false;
186  Lex.Lex();
187  return true;
188  }
189 
190  FastMathFlags EatFastMathFlagsIfPresent() {
191  FastMathFlags FMF;
192  while (true)
193  switch (Lex.getKind()) {
194  case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue;
195  case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
196  case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
197  case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
198  case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
199  case lltok::kw_contract:
200  FMF.setAllowContract(true);
201  Lex.Lex();
202  continue;
203  case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue;
204  case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue;
205  default: return FMF;
206  }
207  return FMF;
208  }
209 
210  bool parseOptionalToken(lltok::Kind T, bool &Present,
211  LocTy *Loc = nullptr) {
212  if (Lex.getKind() != T) {
213  Present = false;
214  } else {
215  if (Loc)
216  *Loc = Lex.getLoc();
217  Lex.Lex();
218  Present = true;
219  }
220  return false;
221  }
222  bool parseStringConstant(std::string &Result);
223  bool parseUInt32(unsigned &Val);
224  bool parseUInt32(unsigned &Val, LocTy &Loc) {
225  Loc = Lex.getLoc();
226  return parseUInt32(Val);
227  }
228  bool parseUInt64(uint64_t &Val);
229  bool parseUInt64(uint64_t &Val, LocTy &Loc) {
230  Loc = Lex.getLoc();
231  return parseUInt64(Val);
232  }
233  bool parseFlag(unsigned &Val);
234 
235  bool parseStringAttribute(AttrBuilder &B);
236 
237  bool parseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
238  bool parseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
239  bool parseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
240  bool parseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0);
241  bool parseOptionalProgramAddrSpace(unsigned &AddrSpace) {
242  return parseOptionalAddrSpace(
243  AddrSpace, M->getDataLayout().getProgramAddressSpace());
244  };
245  bool parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B,
246  bool InAttrGroup);
247  bool parseOptionalParamOrReturnAttrs(AttrBuilder &B, bool IsParam);
248  bool parseOptionalParamAttrs(AttrBuilder &B) {
249  return parseOptionalParamOrReturnAttrs(B, true);
250  }
251  bool parseOptionalReturnAttrs(AttrBuilder &B) {
252  return parseOptionalParamOrReturnAttrs(B, false);
253  }
254  bool parseOptionalLinkage(unsigned &Res, bool &HasLinkage,
255  unsigned &Visibility, unsigned &DLLStorageClass,
256  bool &DSOLocal);
257  void parseOptionalDSOLocal(bool &DSOLocal);
258  void parseOptionalVisibility(unsigned &Res);
259  void parseOptionalDLLStorageClass(unsigned &Res);
260  bool parseOptionalCallingConv(unsigned &CC);
261  bool parseOptionalAlignment(MaybeAlign &Alignment,
262  bool AllowParens = false);
263  bool parseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
264  bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
265  AtomicOrdering &Ordering);
266  bool parseScope(SyncScope::ID &SSID);
267  bool parseOrdering(AtomicOrdering &Ordering);
268  bool parseOptionalStackAlignment(unsigned &Alignment);
269  bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
270  bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
271  bool &AteExtraComma);
272  bool parseAllocSizeArguments(unsigned &BaseSizeArg,
273  Optional<unsigned> &HowManyArg);
274  bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
275  bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
276  bool &AteExtraComma);
277  bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
278  bool AteExtraComma;
279  if (parseIndexList(Indices, AteExtraComma))
280  return true;
281  if (AteExtraComma)
282  return tokError("expected index");
283  return false;
284  }
285 
286  // Top-Level Entities
287  bool parseTopLevelEntities();
288  bool validateEndOfModule(bool UpgradeDebugInfo);
289  bool validateEndOfIndex();
290  bool parseTargetDefinitions();
291  bool parseTargetDefinition();
292  bool parseModuleAsm();
293  bool parseSourceFileName();
294  bool parseUnnamedType();
295  bool parseNamedType();
296  bool parseDeclare();
297  bool parseDefine();
298 
299  bool parseGlobalType(bool &IsConstant);
300  bool parseUnnamedGlobal();
301  bool parseNamedGlobal();
302  bool parseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage,
303  bool HasLinkage, unsigned Visibility,
304  unsigned DLLStorageClass, bool DSOLocal,
306  GlobalVariable::UnnamedAddr UnnamedAddr);
307  bool parseAliasOrIFunc(const std::string &Name, LocTy NameLoc, unsigned L,
308  unsigned Visibility, unsigned DLLStorageClass,
309  bool DSOLocal, GlobalVariable::ThreadLocalMode TLM,
310  GlobalVariable::UnnamedAddr UnnamedAddr);
311  bool parseComdat();
312  bool parseStandaloneMetadata();
313  bool parseNamedMetadata();
314  bool parseMDString(MDString *&Result);
315  bool parseMDNodeID(MDNode *&Result);
316  bool parseUnnamedAttrGrp();
317  bool parseFnAttributeValuePairs(AttrBuilder &B,
318  std::vector<unsigned> &FwdRefAttrGrps,
319  bool inAttrGrp, LocTy &BuiltinLoc);
320  bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
321  Attribute::AttrKind AttrKind);
322 
323  // Module Summary Index Parsing.
324  bool skipModuleSummaryEntry();
325  bool parseSummaryEntry();
326  bool parseModuleEntry(unsigned ID);
327  bool parseModuleReference(StringRef &ModulePath);
328  bool parseGVReference(ValueInfo &VI, unsigned &GVId);
329  bool parseSummaryIndexFlags();
330  bool parseBlockCount();
331  bool parseGVEntry(unsigned ID);
332  bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
333  bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
334  bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
335  bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
336  bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
337  bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
338  bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
339  bool parseHotness(CalleeInfo::HotnessType &Hotness);
340  bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
341  bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
342  bool parseVFuncIdList(lltok::Kind Kind,
343  std::vector<FunctionSummary::VFuncId> &VFuncIdList);
344  bool parseConstVCallList(
346  std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
347  using IdToIndexMapType =
348  std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
349  bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
350  IdToIndexMapType &IdToIndexMap, unsigned Index);
351  bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
352  IdToIndexMapType &IdToIndexMap, unsigned Index);
353  bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
354  bool parseOptionalParamAccesses(
355  std::vector<FunctionSummary::ParamAccess> &Params);
356  bool parseParamNo(uint64_t &ParamNo);
357  using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
358  bool parseParamAccess(FunctionSummary::ParamAccess &Param,
359  IdLocListType &IdLocList);
360  bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
361  IdLocListType &IdLocList);
362  bool parseParamAccessOffset(ConstantRange &Range);
363  bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
364  bool parseTypeIdEntry(unsigned ID);
365  bool parseTypeIdSummary(TypeIdSummary &TIS);
366  bool parseTypeIdCompatibleVtableEntry(unsigned ID);
367  bool parseTypeTestResolution(TypeTestResolution &TTRes);
368  bool parseOptionalWpdResolutions(
369  std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
370  bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
371  bool parseOptionalResByArg(
372  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
373  &ResByArg);
374  bool parseArgs(std::vector<uint64_t> &Args);
375  void addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
377  std::unique_ptr<GlobalValueSummary> Summary);
378 
379  // Type Parsing.
380  bool parseType(Type *&Result, const Twine &Msg, bool AllowVoid = false);
381  bool parseType(Type *&Result, bool AllowVoid = false) {
382  return parseType(Result, "expected type", AllowVoid);
383  }
384  bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
385  bool AllowVoid = false) {
386  Loc = Lex.getLoc();
387  return parseType(Result, Msg, AllowVoid);
388  }
389  bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
390  Loc = Lex.getLoc();
391  return parseType(Result, AllowVoid);
392  }
393  bool parseAnonStructType(Type *&Result, bool Packed);
394  bool parseStructBody(SmallVectorImpl<Type *> &Body);
395  bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
396  std::pair<Type *, LocTy> &Entry,
397  Type *&ResultTy);
398 
399  bool parseArrayVectorType(Type *&Result, bool IsVector);
400  bool parseFunctionType(Type *&Result);
401 
402  // Function Semantic Analysis.
403  class PerFunctionState {
404  LLParser &P;
405  Function &F;
406  std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
407  std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
408  std::vector<Value*> NumberedVals;
409 
410  /// FunctionNumber - If this is an unnamed function, this is the slot
411  /// number of it, otherwise it is -1.
412  int FunctionNumber;
413  public:
414  PerFunctionState(LLParser &p, Function &f, int functionNumber);
415  ~PerFunctionState();
416 
417  Function &getFunction() const { return F; }
418 
419  bool finishFunction();
420 
421  /// GetVal - Get a value with the specified name or ID, creating a
422  /// forward reference record if needed. This can return null if the value
423  /// exists but does not have the right type.
424  Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
425  Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
426 
427  /// setInstName - After an instruction is parsed and inserted into its
428  /// basic block, this installs its name.
429  bool setInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
430  Instruction *Inst);
431 
432  /// GetBB - Get a basic block with the specified name or ID, creating a
433  /// forward reference record if needed. This can return null if the value
434  /// is not a BasicBlock.
435  BasicBlock *getBB(const std::string &Name, LocTy Loc);
436  BasicBlock *getBB(unsigned ID, LocTy Loc);
437 
438  /// DefineBB - Define the specified basic block, which is either named or
439  /// unnamed. If there is an error, this returns null otherwise it returns
440  /// the block being defined.
441  BasicBlock *defineBB(const std::string &Name, int NameID, LocTy Loc);
442 
443  bool resolveForwardRefBlockAddresses();
444  };
445 
446  bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
447  PerFunctionState *PFS);
448 
449  Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
450  Value *Val);
451 
452  bool parseConstantValue(Type *Ty, Constant *&C);
453  bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
454  bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
455  return parseValue(Ty, V, &PFS);
456  }
457 
458  bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
459  Loc = Lex.getLoc();
460  return parseValue(Ty, V, &PFS);
461  }
462 
463  bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
464  bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
465  return parseTypeAndValue(V, &PFS);
466  }
467  bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
468  Loc = Lex.getLoc();
469  return parseTypeAndValue(V, PFS);
470  }
471  bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
472  PerFunctionState &PFS);
473  bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
474  LocTy Loc;
475  return parseTypeAndBasicBlock(BB, Loc, PFS);
476  }
477 
478  struct ParamInfo {
479  LocTy Loc;
480  Value *V;
481  AttributeSet Attrs;
482  ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
483  : Loc(loc), V(v), Attrs(attrs) {}
484  };
485  bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
486  PerFunctionState &PFS, bool IsMustTailCall = false,
487  bool InVarArgsFunc = false);
488 
489  bool
490  parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
491  PerFunctionState &PFS);
492 
493  bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
494  PerFunctionState &PFS);
495 
496  // Constant Parsing.
497  bool parseValID(ValID &ID, PerFunctionState *PFS,
498  Type *ExpectedTy = nullptr);
499  bool parseGlobalValue(Type *Ty, Constant *&C);
500  bool parseGlobalTypeAndValue(Constant *&V);
501  bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
502  Optional<unsigned> *InRangeOp = nullptr);
503  bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
504  bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
505  bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
506  PerFunctionState *PFS);
507  bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
508  bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
509  bool parseMDNode(MDNode *&N);
510  bool parseMDNodeTail(MDNode *&N);
511  bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
512  bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
513  bool parseInstructionMetadata(Instruction &Inst);
514  bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
515  bool parseOptionalFunctionMetadata(Function &F);
516 
517  template <class FieldTy>
518  bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
519  template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
520  template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
521  template <class ParserTy>
522  bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
523  bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
524 
525 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
526  bool parse##CLASS(MDNode *&Result, bool IsDistinct);
527 #include "llvm/IR/Metadata.def"
528  bool parseDIArgList(MDNode *&Result, bool IsDistinct,
529  PerFunctionState *PFS);
530 
531  // Function Parsing.
532  struct ArgInfo {
533  LocTy Loc;
534  Type *Ty;
535  AttributeSet Attrs;
536  std::string Name;
537  ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
538  : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
539  };
540  bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &IsVarArg);
541  bool parseFunctionHeader(Function *&Fn, bool IsDefine);
542  bool parseFunctionBody(Function &Fn);
543  bool parseBasicBlock(PerFunctionState &PFS);
544 
545  enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
546 
547  // Instruction Parsing. Each instruction parsing routine can return with a
548  // normal result, an error result, or return having eaten an extra comma.
549  enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
550  int parseInstruction(Instruction *&Inst, BasicBlock *BB,
551  PerFunctionState &PFS);
552  bool parseCmpPredicate(unsigned &P, unsigned Opc);
553 
554  bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
555  bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
556  bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
557  bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
558  bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
559  bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
560  bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
561  bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
562  bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
563  bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
564  bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
565  bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
566 
567  bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
568  bool IsFP);
569  bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
570  unsigned Opc, bool IsFP);
571  bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
572  bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
573  bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
574  bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
575  bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
576  bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
577  bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
578  bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
579  int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
580  bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
581  bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
583  int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
584  int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
585  int parseStore(Instruction *&Inst, PerFunctionState &PFS);
586  int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
587  int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
588  int parseFence(Instruction *&Inst, PerFunctionState &PFS);
589  int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
590  int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
591  int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
592  bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
593 
594  // Use-list order directives.
595  bool parseUseListOrder(PerFunctionState *PFS = nullptr);
596  bool parseUseListOrderBB();
597  bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
598  bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
599  };
600 } // End llvm namespace
601 
602 #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 file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::LLParser::LocTy
LLLexer::LocTy LocTy
Definition: LLParser.h:86
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:4027
Parser.h
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:255
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:1168
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
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:84
attrs
function attrs
Definition: FunctionAttrs.cpp:1875
F
#define F(x, y, z)
Definition: MD5.cpp: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:194
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
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:148
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:108
llvm::ValID::FTy
FunctionType * FTy
Definition: LLParser.h:59
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
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:74
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
llvm::CallInst::TailCallKind
TailCallKind
Definition: Instructions.h:1652
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:873
I
#define I(x, y, z)
Definition: MD5.cpp:59
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:67
llvm::lltok::kw_ninf
@ kw_ninf
Definition: LLToken.h:103
llvm::ValID::UIntVal
unsigned UIntVal
Definition: LLParser.h:58
llvm::ValID::ValID
ValID(const ValID &RHS)
Definition: LLParser.h:67
llvm::ReplayInlineScope::Function
@ Function
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:52
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:1078
N
#define N
llvm::ValID::t_Zero
@ t_Zero
Definition: LLParser.h:49
llvm::LLParser::getContext
LLVMContext & getContext()
Definition: LLParser.h:162
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::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:37
llvm::ValID::t_APFloat
@ t_APFloat
Definition: LLParser.h:48