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