LLVM 18.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"
19#include "llvm/IR/Attributes.h"
20#include "llvm/IR/FMF.h"
23#include "llvm/Support/ModRef.h"
24#include <map>
25#include <optional>
26
27namespace llvm {
28 class Module;
29 class ConstantRange;
30 class FunctionType;
31 class GlobalObject;
32 class SMDiagnostic;
33 class SMLoc;
34 class SourceMgr;
35 class Type;
36 struct MaybeAlign;
37 class Function;
38 class Value;
39 class BasicBlock;
40 class Instruction;
41 class Constant;
42 class GlobalValue;
43 class Comdat;
44 class MDString;
45 class MDNode;
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.
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.
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;
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 parseOptionalCodeModel(CodeModel::Model &model);
294 bool parseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
295 bool parseOptionalUWTableKind(UWTableKind &Kind);
296 bool parseAllocKind(AllocFnKind &Kind);
297 std::optional<MemoryEffects> parseMemoryAttr();
298 unsigned parseNoFPClassAttr();
299 bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
300 AtomicOrdering &Ordering);
301 bool parseScope(SyncScope::ID &SSID);
302 bool parseOrdering(AtomicOrdering &Ordering);
303 bool parseOptionalStackAlignment(unsigned &Alignment);
304 bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
305 bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
306 bool &AteExtraComma);
307 bool parseAllocSizeArguments(unsigned &BaseSizeArg,
308 std::optional<unsigned> &HowManyArg);
309 bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
310 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
311 bool &AteExtraComma);
312 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
313 bool AteExtraComma;
314 if (parseIndexList(Indices, AteExtraComma))
315 return true;
316 if (AteExtraComma)
317 return tokError("expected index");
318 return false;
319 }
320
321 // Top-Level Entities
322 bool parseTopLevelEntities();
323 bool validateEndOfModule(bool UpgradeDebugInfo);
324 bool validateEndOfIndex();
325 bool parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback);
326 bool parseTargetDefinition(std::string &TentativeDLStr, LocTy &DLStrLoc);
327 bool parseModuleAsm();
328 bool parseSourceFileName();
329 bool parseUnnamedType();
330 bool parseNamedType();
331 bool parseDeclare();
332 bool parseDefine();
333
334 bool parseGlobalType(bool &IsConstant);
335 bool parseUnnamedGlobal();
336 bool parseNamedGlobal();
337 bool parseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage,
338 bool HasLinkage, unsigned Visibility,
339 unsigned DLLStorageClass, bool DSOLocal,
341 GlobalVariable::UnnamedAddr UnnamedAddr);
342 bool parseAliasOrIFunc(const std::string &Name, LocTy NameLoc, unsigned L,
343 unsigned Visibility, unsigned DLLStorageClass,
344 bool DSOLocal, GlobalVariable::ThreadLocalMode TLM,
345 GlobalVariable::UnnamedAddr UnnamedAddr);
346 bool parseComdat();
347 bool parseStandaloneMetadata();
348 bool parseNamedMetadata();
349 bool parseMDString(MDString *&Result);
350 bool parseMDNodeID(MDNode *&Result);
351 bool parseUnnamedAttrGrp();
352 bool parseFnAttributeValuePairs(AttrBuilder &B,
353 std::vector<unsigned> &FwdRefAttrGrps,
354 bool inAttrGrp, LocTy &BuiltinLoc);
355 bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
356 Attribute::AttrKind AttrKind);
357
358 // Module Summary Index Parsing.
359 bool skipModuleSummaryEntry();
360 bool parseSummaryEntry();
361 bool parseModuleEntry(unsigned ID);
362 bool parseModuleReference(StringRef &ModulePath);
363 bool parseGVReference(ValueInfo &VI, unsigned &GVId);
364 bool parseSummaryIndexFlags();
365 bool parseBlockCount();
366 bool parseGVEntry(unsigned ID);
367 bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
368 bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
369 bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
370 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
371 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
372 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
373 bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
374 bool parseHotness(CalleeInfo::HotnessType &Hotness);
375 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
376 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
377 bool parseVFuncIdList(lltok::Kind Kind,
378 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
379 bool parseConstVCallList(
380 lltok::Kind Kind,
381 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
382 using IdToIndexMapType =
383 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
384 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
385 IdToIndexMapType &IdToIndexMap, unsigned Index);
386 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
387 IdToIndexMapType &IdToIndexMap, unsigned Index);
388 bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
389 bool parseOptionalParamAccesses(
390 std::vector<FunctionSummary::ParamAccess> &Params);
391 bool parseParamNo(uint64_t &ParamNo);
392 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
393 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
394 IdLocListType &IdLocList);
395 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
396 IdLocListType &IdLocList);
397 bool parseParamAccessOffset(ConstantRange &Range);
398 bool parseOptionalRefs(std::vector<ValueInfo> &Refs);
399 bool parseTypeIdEntry(unsigned ID);
400 bool parseTypeIdSummary(TypeIdSummary &TIS);
401 bool parseTypeIdCompatibleVtableEntry(unsigned ID);
402 bool parseTypeTestResolution(TypeTestResolution &TTRes);
403 bool parseOptionalWpdResolutions(
404 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
405 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
406 bool parseOptionalResByArg(
407 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
408 &ResByArg);
409 bool parseArgs(std::vector<uint64_t> &Args);
410 void addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
411 GlobalValue::LinkageTypes Linkage, unsigned ID,
412 std::unique_ptr<GlobalValueSummary> Summary);
413 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
414 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
415 bool parseAllocType(uint8_t &AllocType);
416 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
417
418 // Type Parsing.
419 bool parseType(Type *&Result, const Twine &Msg, bool AllowVoid = false);
420 bool parseType(Type *&Result, bool AllowVoid = false) {
421 return parseType(Result, "expected type", AllowVoid);
422 }
423 bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
424 bool AllowVoid = false) {
425 Loc = Lex.getLoc();
426 return parseType(Result, Msg, AllowVoid);
427 }
428 bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
429 Loc = Lex.getLoc();
430 return parseType(Result, AllowVoid);
431 }
432 bool parseAnonStructType(Type *&Result, bool Packed);
433 bool parseStructBody(SmallVectorImpl<Type *> &Body);
434 bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
435 std::pair<Type *, LocTy> &Entry,
436 Type *&ResultTy);
437
438 bool parseArrayVectorType(Type *&Result, bool IsVector);
439 bool parseFunctionType(Type *&Result);
440 bool parseTargetExtType(Type *&Result);
441
442 // Function Semantic Analysis.
443 class PerFunctionState {
444 LLParser &P;
445 Function &F;
446 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
447 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
448 std::vector<Value*> NumberedVals;
449
450 /// FunctionNumber - If this is an unnamed function, this is the slot
451 /// number of it, otherwise it is -1.
452 int FunctionNumber;
453 public:
454 PerFunctionState(LLParser &p, Function &f, int functionNumber);
455 ~PerFunctionState();
456
457 Function &getFunction() const { return F; }
458
459 bool finishFunction();
460
461 /// GetVal - Get a value with the specified name or ID, creating a
462 /// forward reference record if needed. This can return null if the value
463 /// exists but does not have the right type.
464 Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
465 Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
466
467 /// setInstName - After an instruction is parsed and inserted into its
468 /// basic block, this installs its name.
469 bool setInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
470 Instruction *Inst);
471
472 /// GetBB - Get a basic block with the specified name or ID, creating a
473 /// forward reference record if needed. This can return null if the value
474 /// is not a BasicBlock.
475 BasicBlock *getBB(const std::string &Name, LocTy Loc);
476 BasicBlock *getBB(unsigned ID, LocTy Loc);
477
478 /// DefineBB - Define the specified basic block, which is either named or
479 /// unnamed. If there is an error, this returns null otherwise it returns
480 /// the block being defined.
481 BasicBlock *defineBB(const std::string &Name, int NameID, LocTy Loc);
482
483 bool resolveForwardRefBlockAddresses();
484 };
485
486 bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
487 PerFunctionState *PFS);
488
489 Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
490 Value *Val);
491
492 bool parseConstantValue(Type *Ty, Constant *&C);
493 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
494 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
495 return parseValue(Ty, V, &PFS);
496 }
497
498 bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
499 Loc = Lex.getLoc();
500 return parseValue(Ty, V, &PFS);
501 }
502
503 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
504 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
505 return parseTypeAndValue(V, &PFS);
506 }
507 bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
508 Loc = Lex.getLoc();
509 return parseTypeAndValue(V, PFS);
510 }
511 bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
512 PerFunctionState &PFS);
513 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
514 LocTy Loc;
515 return parseTypeAndBasicBlock(BB, Loc, PFS);
516 }
517
518 struct ParamInfo {
519 LocTy Loc;
520 Value *V;
521 AttributeSet Attrs;
522 ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
523 : Loc(loc), V(v), Attrs(attrs) {}
524 };
525 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
526 PerFunctionState &PFS, bool IsMustTailCall = false,
527 bool InVarArgsFunc = false);
528
529 bool
530 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
531 PerFunctionState &PFS);
532
533 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
534 PerFunctionState &PFS);
535
536 bool resolveFunctionType(Type *RetType,
537 const SmallVector<ParamInfo, 16> &ArgList,
538 FunctionType *&FuncTy);
539
540 // Constant Parsing.
541 bool parseValID(ValID &ID, PerFunctionState *PFS,
542 Type *ExpectedTy = nullptr);
543 bool parseGlobalValue(Type *Ty, Constant *&C);
544 bool parseGlobalTypeAndValue(Constant *&V);
545 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
546 std::optional<unsigned> *InRangeOp = nullptr);
547 bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
548 bool parseSanitizer(GlobalVariable *GV);
549 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
550 bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
551 PerFunctionState *PFS);
552 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
553 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
554 bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
555 bool parseMDNode(MDNode *&N);
556 bool parseMDNodeTail(MDNode *&N);
557 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
558 bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
559 bool parseInstructionMetadata(Instruction &Inst);
560 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
561 bool parseOptionalFunctionMetadata(Function &F);
562
563 template <class FieldTy>
564 bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
565 template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
566 template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
567 template <class ParserTy>
568 bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
569 bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
570
571#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
572 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
573#include "llvm/IR/Metadata.def"
574
575 // Function Parsing.
576 struct ArgInfo {
577 LocTy Loc;
578 Type *Ty;
579 AttributeSet Attrs;
580 std::string Name;
581 ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
582 : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
583 };
584 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &IsVarArg);
585 bool parseFunctionHeader(Function *&Fn, bool IsDefine);
586 bool parseFunctionBody(Function &Fn);
587 bool parseBasicBlock(PerFunctionState &PFS);
588
589 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
590
591 // Instruction Parsing. Each instruction parsing routine can return with a
592 // normal result, an error result, or return having eaten an extra comma.
593 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
594 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
595 PerFunctionState &PFS);
596 bool parseCmpPredicate(unsigned &P, unsigned Opc);
597
598 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
599 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
600 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
601 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
602 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
603 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
604 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
605 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
606 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
607 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
608 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
609 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
610
611 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
612 bool IsFP);
613 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
614 unsigned Opc, bool IsFP);
615 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
616 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
617 bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
618 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
619 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
620 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
621 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
622 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
623 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
624 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
625 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
627 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
628 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
629 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
630 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
631 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
632 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
633 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
634 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
635 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
636 bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
637
638 // Use-list order directives.
639 bool parseUseListOrder(PerFunctionState *PFS = nullptr);
640 bool parseUseListOrderBB();
641 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
642 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
643 };
644} // End llvm namespace
645
646#endif
This file defines the StringMap class.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
RelocType Type
Definition: COFFYAML.cpp:391
std::string Name
uint32_t Index
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
AllocType
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
LLVMContext & Context
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define error(X)
Value * RHS
An arbitrary precision integer that knows its signedness.
Definition: APSInt.h:23
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
This is an important base class in LLVM.
Definition: Constant.h:41
Class to represent function types.
Definition: DerivedTypes.h:103
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:583
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
lltok::Kind Lex()
Definition: LLLexer.h:52
lltok::Kind getKind() const
Definition: LLLexer.h:58
bool Error(LocTy ErrorLoc, const Twine &Msg) const
Definition: LLLexer.cpp:28
LocTy getLoc() const
Definition: LLLexer.h:57
LLLexer::LocTy LocTy
Definition: LLParser.h:97
LLVMContext & getContext()
Definition: LLParser.h:192
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, ModuleSummaryIndex *Index, LLVMContext &Context, SlotMapping *Slots=nullptr)
Definition: LLParser.h:175
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
Definition: LLParser.cpp:97
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
Definition: LLParser.cpp:84
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
Represents a location in source code.
Definition: SMLoc.h:23
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
An efficient, type-erasing, non-owning reference to a callable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
@ kw_reassoc
Definition: LLToken.h:106
@ kw_contract
Definition: LLToken.h:105
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AllocFnKind
Definition: Attributes.h:47
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
UWTableKind
Definition: CodeGen.h:120
AtomicOrdering
Atomic ordering for LLVM's memory model.
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
Definition: Parser.h:33
#define N
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:32
ValID - Represents a reference of a definition of some sort with no type.
Definition: LLParser.h:52
bool NoCFI
Definition: LLParser.h:73
unsigned UIntVal
Definition: LLParser.h:66
APFloat APFloatVal
Definition: LLParser.h:70
@ t_Constant
Definition: LLParser.h:59
@ t_PackedConstantStruct
Definition: LLParser.h:62
@ t_GlobalID
Definition: LLParser.h:54
@ t_EmptyArray
Definition: LLParser.h:58
@ t_GlobalName
Definition: LLParser.h:55
@ t_ConstantStruct
Definition: LLParser.h:61
@ t_LocalName
Definition: LLParser.h:55
@ t_InlineAsm
Definition: LLParser.h:60
ValID(const ValID &RHS)
Definition: LLParser.h:76
Constant * ConstantVal
Definition: LLParser.h:71
FunctionType * FTy
Definition: LLParser.h:67
std::unique_ptr< Constant *[]> ConstantStructElts
Definition: LLParser.h:72
bool operator<(const ValID &RHS) const
Definition: LLParser.h:84
APSInt APSIntVal
Definition: LLParser.h:69
LLLexer::LocTy Loc
Definition: LLParser.h:65
ValID()=default
enum llvm::ValID::@39 Kind
std::string StrVal
Definition: LLParser.h:68
std::string StrVal2
Definition: LLParser.h:68