LLVM 22.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 parseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
323 bool parseOptionalUWTableKind(UWTableKind &Kind);
324 bool parseAllocKind(AllocFnKind &Kind);
325 std::optional<MemoryEffects> parseMemoryAttr();
326 unsigned parseNoFPClassAttr();
327 bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
328 AtomicOrdering &Ordering);
329 bool parseScope(SyncScope::ID &SSID);
330 bool parseOrdering(AtomicOrdering &Ordering);
331 bool parseOptionalStackAlignment(unsigned &Alignment);
332 bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
333 bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
334 bool &AteExtraComma);
335 bool parseAllocSizeArguments(unsigned &BaseSizeArg,
336 std::optional<unsigned> &HowManyArg);
337 bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
338 bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
339 bool &AteExtraComma);
340 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
341 bool AteExtraComma;
342 if (parseIndexList(Indices, AteExtraComma))
343 return true;
344 if (AteExtraComma)
345 return tokError("expected index");
346 return false;
347 }
348
349 // Top-Level Entities
350 bool parseTopLevelEntities();
351 void dropUnknownMetadataReferences();
352 bool validateEndOfModule(bool UpgradeDebugInfo);
353 bool validateEndOfIndex();
354 bool parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback);
355 bool parseTargetDefinition(std::string &TentativeDLStr, LocTy &DLStrLoc);
356 bool parseModuleAsm();
357 bool parseSourceFileName();
358 bool parseUnnamedType();
359 bool parseNamedType();
360 bool parseDeclare();
361 bool parseDefine();
362
363 bool parseGlobalType(bool &IsConstant);
364 bool parseUnnamedGlobal();
365 bool parseNamedGlobal();
366 bool parseGlobal(const std::string &Name, unsigned NameID, LocTy NameLoc,
367 unsigned Linkage, bool HasLinkage, unsigned Visibility,
368 unsigned DLLStorageClass, bool DSOLocal,
370 GlobalVariable::UnnamedAddr UnnamedAddr);
371 bool parseAliasOrIFunc(const std::string &Name, unsigned NameID,
372 LocTy NameLoc, unsigned L, unsigned Visibility,
373 unsigned DLLStorageClass, bool DSOLocal,
375 GlobalVariable::UnnamedAddr UnnamedAddr);
376 bool parseComdat();
377 bool parseStandaloneMetadata();
378 bool parseNamedMetadata();
379 bool parseMDString(MDString *&Result);
380 bool parseMDNodeID(MDNode *&Result);
381 bool parseUnnamedAttrGrp();
382 bool parseFnAttributeValuePairs(AttrBuilder &B,
383 std::vector<unsigned> &FwdRefAttrGrps,
384 bool inAttrGrp, LocTy &BuiltinLoc);
385 bool parseRangeAttr(AttrBuilder &B);
386 bool parseInitializesAttr(AttrBuilder &B);
387 bool parseCapturesAttr(AttrBuilder &B);
388 bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
389 Attribute::AttrKind AttrKind);
390
391 // Module Summary Index Parsing.
392 bool skipModuleSummaryEntry();
393 bool parseSummaryEntry();
394 bool parseModuleEntry(unsigned ID);
395 bool parseModuleReference(StringRef &ModulePath);
396 bool parseGVReference(ValueInfo &VI, unsigned &GVId);
397 bool parseSummaryIndexFlags();
398 bool parseBlockCount();
399 bool parseGVEntry(unsigned ID);
400 bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
401 bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
402 bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
403 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
404 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
405 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
406 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
407 bool parseHotness(CalleeInfo::HotnessType &Hotness);
408 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
409 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
410 bool parseVFuncIdList(lltok::Kind Kind,
411 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
412 bool parseConstVCallList(
413 lltok::Kind Kind,
414 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
415 using IdToIndexMapType =
416 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
417 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
418 IdToIndexMapType &IdToIndexMap, unsigned Index);
419 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
420 IdToIndexMapType &IdToIndexMap, unsigned Index);
421 bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
422 bool parseOptionalParamAccesses(
423 std::vector<FunctionSummary::ParamAccess> &Params);
424 bool parseParamNo(uint64_t &ParamNo);
425 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
426 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
427 IdLocListType &IdLocList);
428 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
429 IdLocListType &IdLocList);
430 bool parseParamAccessOffset(ConstantRange &Range);
431 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
432 bool parseTypeIdEntry(unsigned ID);
433 bool parseTypeIdSummary(TypeIdSummary &TIS);
434 bool parseTypeIdCompatibleVtableEntry(unsigned ID);
435 bool parseTypeTestResolution(TypeTestResolution &TTRes);
436 bool parseOptionalWpdResolutions(
437 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
438 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
439 bool parseOptionalResByArg(
440 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
441 &ResByArg);
442 bool parseArgs(std::vector<uint64_t> &Args);
443 bool addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
445 std::unique_ptr<GlobalValueSummary> Summary,
446 LocTy Loc);
447 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
448 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
449 bool parseAllocType(uint8_t &AllocType);
450 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
451
452 // Type Parsing.
453 bool parseType(Type *&Result, const Twine &Msg, bool AllowVoid = false);
454 bool parseType(Type *&Result, bool AllowVoid = false) {
455 return parseType(Result, "expected type", AllowVoid);
456 }
457 bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
458 bool AllowVoid = false) {
459 Loc = Lex.getLoc();
460 return parseType(Result, Msg, AllowVoid);
461 }
462 bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
463 Loc = Lex.getLoc();
464 return parseType(Result, AllowVoid);
465 }
466 bool parseAnonStructType(Type *&Result, bool Packed);
467 bool parseStructBody(SmallVectorImpl<Type *> &Body);
468 bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
469 std::pair<Type *, LocTy> &Entry,
470 Type *&ResultTy);
471
472 bool parseArrayVectorType(Type *&Result, bool IsVector);
473 bool parseFunctionType(Type *&Result);
474 bool parseTargetExtType(Type *&Result);
475
476 // Function Semantic Analysis.
477 class PerFunctionState {
478 LLParser &P;
479 Function &F;
480 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
481 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
482 NumberedValues<Value *> NumberedVals;
483
484 /// FunctionNumber - If this is an unnamed function, this is the slot
485 /// number of it, otherwise it is -1.
486 int FunctionNumber;
487
488 public:
489 PerFunctionState(LLParser &p, Function &f, int functionNumber,
490 ArrayRef<unsigned> UnnamedArgNums);
491 ~PerFunctionState();
492
493 Function &getFunction() const { return F; }
494
495 bool finishFunction();
496
497 /// GetVal - Get a value with the specified name or ID, creating a
498 /// forward reference record if needed. This can return null if the value
499 /// exists but does not have the right type.
500 Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
501 Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
502
503 /// setInstName - After an instruction is parsed and inserted into its
504 /// basic block, this installs its name.
505 bool setInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
506 Instruction *Inst);
507
508 /// GetBB - Get a basic block with the specified name or ID, creating a
509 /// forward reference record if needed. This can return null if the value
510 /// is not a BasicBlock.
511 BasicBlock *getBB(const std::string &Name, LocTy Loc);
512 BasicBlock *getBB(unsigned ID, LocTy Loc);
513
514 /// DefineBB - Define the specified basic block, which is either named or
515 /// unnamed. If there is an error, this returns null otherwise it returns
516 /// the block being defined.
517 BasicBlock *defineBB(const std::string &Name, int NameID, LocTy Loc);
518
519 bool resolveForwardRefBlockAddresses();
520 };
521
522 bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
523 PerFunctionState *PFS);
524
525 Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
526 Value *Val);
527
528 bool parseConstantValue(Type *Ty, Constant *&C);
529 bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
530 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
531 return parseValue(Ty, V, &PFS);
532 }
533
534 bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
535 Loc = Lex.getLoc();
536 return parseValue(Ty, V, &PFS);
537 }
538
539 bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
540 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
541 return parseTypeAndValue(V, &PFS);
542 }
543 bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
544 Loc = Lex.getLoc();
545 return parseTypeAndValue(V, PFS);
546 }
547 bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
548 PerFunctionState &PFS);
549 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
550 LocTy Loc;
551 return parseTypeAndBasicBlock(BB, Loc, PFS);
552 }
553
554 struct ParamInfo {
555 LocTy Loc;
556 Value *V;
557 AttributeSet Attrs;
558 ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
559 : Loc(loc), V(v), Attrs(attrs) {}
560 };
561 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
562 PerFunctionState &PFS, bool IsMustTailCall = false,
563 bool InVarArgsFunc = false);
564
565 bool
566 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
567 PerFunctionState &PFS);
568
569 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
570 PerFunctionState &PFS);
571
572 bool resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
573 FunctionType *&FuncTy);
574
575 // Constant Parsing.
576 bool parseValID(ValID &ID, PerFunctionState *PFS,
577 Type *ExpectedTy = nullptr);
578 bool parseGlobalValue(Type *Ty, Constant *&C);
579 bool parseGlobalTypeAndValue(Constant *&V);
580 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
581 bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
582 bool parseSanitizer(GlobalVariable *GV);
583 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
584 bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
585 PerFunctionState *PFS);
586 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
587 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
588 bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
589 bool parseMDNode(MDNode *&N);
590 bool parseMDNodeTail(MDNode *&N);
591 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
592 bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
593 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
594 bool parseInstructionMetadata(Instruction &Inst);
595 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
596 bool parseOptionalFunctionMetadata(Function &F);
597
598 template <class FieldTy>
599 bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
600 template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
601 template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
602 template <class ParserTy>
603 bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
604 bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
605 bool parseDIExpressionBody(MDNode *&Result, bool IsDistinct);
606
607#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
608 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
609#include "llvm/IR/Metadata.def"
610
611 // Function Parsing.
612 struct ArgInfo {
613 LocTy Loc;
614 Type *Ty;
615 AttributeSet Attrs;
616 std::string Name;
617 ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
618 : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
619 };
620 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
621 SmallVectorImpl<unsigned> &UnnamedArgNums,
622 bool &IsVarArg);
623 bool parseFunctionHeader(Function *&Fn, bool IsDefine,
624 unsigned &FunctionNumber,
625 SmallVectorImpl<unsigned> &UnnamedArgNums);
626 bool parseFunctionBody(Function &Fn, unsigned FunctionNumber,
627 ArrayRef<unsigned> UnnamedArgNums);
628 bool parseBasicBlock(PerFunctionState &PFS);
629
630 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
631
632 // Instruction Parsing. Each instruction parsing routine can return with a
633 // normal result, an error result, or return having eaten an extra comma.
634 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
635 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
636 PerFunctionState &PFS);
637 bool parseCmpPredicate(unsigned &P, unsigned Opc);
638
639 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
640 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
641 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
642 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
643 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
644 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
645 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
646 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
647 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
648 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
649 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
650 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
651
652 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
653 bool IsFP);
654 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
655 unsigned Opc, bool IsFP);
656 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
657 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
658 bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
659 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
660 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
661 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
662 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
663 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
664 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
665 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
666 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
668 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
669 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
670 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
671 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
672 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
673 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
674 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
675 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
676 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
677 bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
678
679 // Use-list order directives.
680 bool parseUseListOrder(PerFunctionState *PFS = nullptr);
681 bool parseUseListOrderBB();
682 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
683 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
684 };
685} // End llvm namespace
686
687#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:55
#define I(x, y, z)
Definition MD5.cpp:58
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:88
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:123
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:107
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:94
bool Run(bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Run: module ::= toplevelentity*.
Definition LLParser.cpp:75
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1078
A single uniqued string.
Definition Metadata.h:721
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.
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:148
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:33
@ 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