LLVM 24.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 /// DIAssignID metadata does not support temporary RAUW so we cannot use
123 /// the normal metadata forward reference resolution method. Instead,
124 /// non-temporary DIAssignID are attached to instructions (recorded here)
125 /// then replaced later.
126 DenseMap<MDNode *, SmallVector<Instruction *, 2>> TempDIAssignIDAttachments;
127
128 // Type resolution handling data structures. The location is set when we
129 // have processed a use of the type but not a definition yet.
131 std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
132
133 std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
134 std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
135
136 // Global Value reference information.
137 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
138 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
140
141 // Comdat forward reference information.
142 std::map<std::string, LocTy> ForwardRefComdats;
143
144 // References to blockaddress. The key is the function ValID, the value is
145 // a list of references to blocks in that function.
146 std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
147 class PerFunctionState;
148 /// Reference to per-function state to allow basic blocks to be
149 /// forward-referenced by blockaddress instructions within the same
150 /// function.
151 PerFunctionState *BlockAddressPFS;
152
153 // References to dso_local_equivalent. The key is the global's ValID, the
154 // value is a placeholder value that will be replaced. Note there are two
155 // maps for tracking ValIDs that are GlobalNames and ValIDs that are
156 // GlobalIDs. These are needed because "operator<" doesn't discriminate
157 // between the two.
158 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
159 std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
160
161 // Attribute builder reference information.
162 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
163 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
164
165 // Summary global value reference information.
166 std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
167 ForwardRefValueInfos;
168 std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
169 ForwardRefAliasees;
170 std::vector<ValueInfo> NumberedValueInfos;
171
172 // Summary type id reference information.
173 std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
174 ForwardRefTypeIds;
175
176 // Map of module ID to path.
177 std::map<unsigned, StringRef> ModuleIdMap;
178
179 /// Keeps track of source locations for Values, BasicBlocks, and Functions.
180 AsmParserContext *ParserContext;
181
182 /// retainedNodes of these subprograms should be cleaned up from incorrectly
183 /// scoped local types.
184 SmallVector<DISubprogram *> NewDistinctSPs;
185
187 PendingDbgRecords;
189 PendingDbgInsts;
190
191 /// Only the llvm-as tool may set this to false to bypass
192 /// UpgradeDebuginfo so it can generate broken bitcode.
193 bool UpgradeDebugInfo;
194
195 bool SeenNewDbgInfoFormat = false;
196 bool SeenOldDbgInfoFormat = false;
197
198 std::string SourceFileName;
199
200 FileLoc getTokLineColumnPos() {
201 if (ParserContext)
202 return Lex.getTokLineColumnPos();
203 return {0u, 0u};
204 }
205
206 FileLoc getPrevTokEndLineColumnPos() {
207 if (ParserContext)
208 return Lex.getPrevTokEndLineColumnPos();
209 return {0u, 0u};
210 }
211
212 public:
214 ModuleSummaryIndex *Index, LLVMContext &Context,
215 SlotMapping *Slots = nullptr,
216 AsmParserContext *ParserContext = nullptr)
217 : Context(Context), OPLex(F, SM, Err, Context),
218 Lex(F, SM, Err, Context), M(M), Index(Index), Slots(Slots),
219 BlockAddressPFS(nullptr), ParserContext(ParserContext) {}
220 LLVM_ABI bool Run(
221 bool UpgradeDebugInfo,
222 DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
223 return std::nullopt;
224 });
225
227 const SlotMapping *Slots);
228
229 LLVM_ABI bool parseTypeAtBeginning(Type *&Ty, unsigned &Read,
230 const SlotMapping *Slots);
231
232 LLVM_ABI bool parseDIExpressionBodyAtBeginning(MDNode *&Result,
233 unsigned &Read,
234 const SlotMapping *Slots);
235
236 LLVM_ABI bool parseMetadataDefinitions(SlotMapping &Slots,
237 ArrayRef<SMLoc> DefinitionEnds);
238
239 LLVMContext &getContext() { return Context; }
240
241 private:
242 bool error(LocTy L, const Twine &Msg) { return Lex.ParseError(L, Msg); }
243 bool tokError(const Twine &Msg) { return error(Lex.getLoc(), Msg); }
244
245 bool checkValueID(LocTy L, StringRef Kind, StringRef Prefix,
246 unsigned NextID, unsigned ID);
247
248 /// Restore the internal name and slot mappings using the mappings that
249 /// were created at an earlier parsing stage.
250 void restoreParsingState(const SlotMapping *Slots);
251
252 /// getGlobalVal - Get a value with the specified name or ID, creating a
253 /// forward reference record if needed. This can return null if the value
254 /// exists but does not have the right type.
255 GlobalValue *getGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
256 GlobalValue *getGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
257
258 /// Get a Comdat with the specified name, creating a forward reference
259 /// record if needed.
260 Comdat *getComdat(const std::string &Name, LocTy Loc);
261
262 // Helper Routines.
263 bool parseToken(lltok::Kind T, const char *ErrMsg);
264 bool EatIfPresent(lltok::Kind T) {
265 if (Lex.getKind() != T) return false;
266 Lex.Lex();
267 return true;
268 }
269
270 FastMathFlags EatFastMathFlagsIfPresent() {
271 FastMathFlags FMF;
272 while (true)
273 switch (Lex.getKind()) {
274 case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue;
275 case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
276 case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
277 case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
278 case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
280 FMF.setAllowContract(true);
281 Lex.Lex();
282 continue;
283 case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue;
284 case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue;
285 default: return FMF;
286 }
287 return FMF;
288 }
289
290 bool parseOptionalToken(lltok::Kind T, bool &Present,
291 LocTy *Loc = nullptr) {
292 if (Lex.getKind() != T) {
293 Present = false;
294 } else {
295 if (Loc)
296 *Loc = Lex.getLoc();
297 Lex.Lex();
298 Present = true;
299 }
300 return false;
301 }
302 bool parseStringConstant(std::string &Result);
303 LLVM_ABI bool parseUInt32(unsigned &Val);
304 bool parseUInt32(unsigned &Val, LocTy &Loc) {
305 Loc = Lex.getLoc();
306 return parseUInt32(Val);
307 }
308 LLVM_ABI bool parseUInt64(uint64_t &Val);
309 bool parseUInt64(uint64_t &Val, LocTy &Loc) {
310 Loc = Lex.getLoc();
311 return parseUInt64(Val);
312 }
313 bool parseFlag(unsigned &Val);
314
315 bool parseStringAttribute(AttrBuilder &B);
316
317 bool parseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
318 bool parseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
319 bool parseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
320 LLVM_ABI bool parseOptionalAddrSpace(unsigned &AddrSpace,
321 unsigned DefaultAS = 0);
322 bool parseOptionalProgramAddrSpace(unsigned &AddrSpace) {
323 return parseOptionalAddrSpace(
324 AddrSpace, M->getDataLayout().getProgramAddressSpace());
325 };
326 bool parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B,
327 bool InAttrGroup);
328 LLVM_ABI bool parseOptionalParamOrReturnAttrs(AttrBuilder &B, bool IsParam);
329 bool parseOptionalParamAttrs(AttrBuilder &B) {
330 return parseOptionalParamOrReturnAttrs(B, true);
331 }
332 bool parseOptionalReturnAttrs(AttrBuilder &B) {
333 return parseOptionalParamOrReturnAttrs(B, false);
334 }
335 bool parseOptionalLinkage(unsigned &Res, bool &HasLinkage,
336 unsigned &Visibility, unsigned &DLLStorageClass,
337 bool &DSOLocal);
338 void parseOptionalDSOLocal(bool &DSOLocal);
339 void parseOptionalVisibility(unsigned &Res);
340 bool parseOptionalImportType(lltok::Kind Kind,
342 void parseOptionalDLLStorageClass(unsigned &Res);
343 bool parseOptionalCallingConv(unsigned &CC);
344 bool parseOptionalAlignment(MaybeAlign &Alignment,
345 bool AllowParens = false);
346 bool parseOptionalPrefAlignment(MaybeAlign &Alignment);
347 bool parseOptionalCodeModel(CodeModel::Model &model);
348 bool parseOptionalAttrBytes(lltok::Kind AttrKind,
349 std::optional<uint64_t> &Bytes,
350 bool ErrorNoBytes = true);
351 bool parseOptionalUWTableKind(UWTableKind &Kind);
352 bool parseAllocKind(AllocFnKind &Kind);
353 std::optional<MemoryEffects> parseMemoryAttr();
354 std::optional<DenormalMode> parseDenormalFPEnvEntry();
355 std::optional<DenormalFPEnv> parseDenormalFPEnvAttr();
356 unsigned parseNoFPClassAttr();
357 bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
358 AtomicOrdering &Ordering);
359 bool parseScope(SyncScope::ID &SSID);
360 bool parseOrdering(AtomicOrdering &Ordering);
361 bool parseOptionalStackAlignment(unsigned &Alignment);
362 bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
363 bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
364 bool &AteExtraComma);
365 bool parseAllocSizeArguments(unsigned &BaseSizeArg,
366 std::optional<unsigned> &HowManyArg);
367 bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
368 LLVM_ABI bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
369 bool &AteExtraComma);
370 bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
371 bool AteExtraComma;
372 if (parseIndexList(Indices, AteExtraComma))
373 return true;
374 if (AteExtraComma)
375 return tokError("expected index");
376 return false;
377 }
378
379 // Top-Level Entities
380 bool parseTopLevelEntities();
381 void dropUnknownMetadataReferences();
382 bool validateEndOfModule(bool UpgradeDebugInfo);
383 bool validateEndOfIndex();
384 bool parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback);
385 bool parseTargetDefinition(std::string &TentativeDLStr, LocTy &DLStrLoc);
386 bool parseModuleAsm();
387 bool parseSourceFileName();
388 bool parseUnnamedType();
389 bool parseNamedType();
390 bool parseDeclare();
391 bool parseDefine();
392
393 bool parseGlobalType(bool &IsConstant);
394 bool parseUnnamedGlobal();
395 bool parseNamedGlobal();
396 bool parseGlobal(const std::string &Name, unsigned NameID, LocTy NameLoc,
397 unsigned Linkage, bool HasLinkage, unsigned Visibility,
398 unsigned DLLStorageClass, bool DSOLocal,
400 GlobalVariable::UnnamedAddr UnnamedAddr);
401 bool parseAliasOrIFunc(const std::string &Name, unsigned NameID,
402 LocTy NameLoc, unsigned L, unsigned Visibility,
403 unsigned DLLStorageClass, bool DSOLocal,
405 GlobalVariable::UnnamedAddr UnnamedAddr);
406 bool parseComdat();
407 bool parseStandaloneMetadata();
408 bool parseNamedMetadata();
409 bool parseMDString(MDString *&Result);
410 bool parseMDNodeID(MDNode *&Result);
411 bool parseUnnamedAttrGrp();
412 bool parseFnAttributeValuePairs(AttrBuilder &B,
413 std::vector<unsigned> &FwdRefAttrGrps,
414 bool inAttrGrp, LocTy &BuiltinLoc);
415 bool parseRangeAttr(AttrBuilder &B);
416 bool parseInitializesAttr(AttrBuilder &B);
417 bool parseCapturesAttr(AttrBuilder &B);
418 bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
419 Attribute::AttrKind AttrKind);
420
421 // Module Summary Index Parsing.
422 bool skipModuleSummaryEntry();
423 bool parseSummaryEntry();
424 bool parseModuleEntry(unsigned ID);
425 bool parseModuleReference(StringRef &ModulePath);
426 bool parseGVReference(ValueInfo &VI, unsigned &GVId);
427 bool parseSummaryIndexFlags();
428 bool parseBlockCount();
429 bool parseGVEntry(unsigned ID);
430 bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
431 bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
432 bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
433 bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
434 bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
435 bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
436 bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
437 bool parseHotness(CalleeInfo::HotnessType &Hotness);
438 bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
439 bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
440 bool parseVFuncIdList(lltok::Kind Kind,
441 std::vector<FunctionSummary::VFuncId> &VFuncIdList);
442 bool parseConstVCallList(
443 lltok::Kind Kind,
444 std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
445 using IdToIndexMapType =
446 std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
447 bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
448 IdToIndexMapType &IdToIndexMap, unsigned Index);
449 bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
450 IdToIndexMapType &IdToIndexMap, unsigned Index);
451 bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
452 bool parseOptionalParamAccesses(
453 std::vector<FunctionSummary::ParamAccess> &Params);
454 bool parseParamNo(uint64_t &ParamNo);
455 using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
456 bool parseParamAccess(FunctionSummary::ParamAccess &Param,
457 IdLocListType &IdLocList);
458 bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
459 IdLocListType &IdLocList);
460 bool parseParamAccessOffset(ConstantRange &Range);
461 bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
462 bool parseTypeIdEntry(unsigned ID);
463 bool parseTypeIdSummary(TypeIdSummary &TIS);
464 bool parseTypeIdCompatibleVtableEntry(unsigned ID);
465 bool parseTypeTestResolution(TypeTestResolution &TTRes);
466 bool parseOptionalWpdResolutions(
467 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
468 bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
469 bool parseOptionalResByArg(
470 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
471 &ResByArg);
472 bool parseArgs(std::vector<uint64_t> &Args);
473 bool addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
475 std::unique_ptr<GlobalValueSummary> Summary,
476 LocTy Loc);
477 bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
478 bool parseMemProfs(std::vector<MIBInfo> &MIBs);
479 bool parseAllocType(uint8_t &AllocType);
480 bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
481
482 // Type Parsing.
483 LLVM_ABI bool parseType(Type *&Result, const Twine &Msg,
484 bool AllowVoid = false);
485 bool parseType(Type *&Result, bool AllowVoid = false) {
486 return parseType(Result, "expected type", AllowVoid);
487 }
488 bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
489 bool AllowVoid = false) {
490 Loc = Lex.getLoc();
491 return parseType(Result, Msg, AllowVoid);
492 }
493 bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
494 Loc = Lex.getLoc();
495 return parseType(Result, AllowVoid);
496 }
497 bool parseAnonStructType(Type *&Result, bool Packed);
498 bool parseStructBody(SmallVectorImpl<Type *> &Body);
499 bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
500 std::pair<Type *, LocTy> &Entry,
501 Type *&ResultTy);
502
503 bool parseArrayVectorType(Type *&Result, bool IsVector);
504 bool parseFunctionType(Type *&Result);
505 bool parseTargetExtType(Type *&Result);
506
507 // Function Semantic Analysis.
508 class PerFunctionState {
509 LLParser &P;
510 Function &F;
511 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
512 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
513 NumberedValues<Value *> NumberedVals;
514
515 /// FunctionNumber - If this is an unnamed function, this is the slot
516 /// number of it, otherwise it is -1.
517 int FunctionNumber;
518
519 public:
520 LLVM_ABI PerFunctionState(LLParser &p, Function &f, int functionNumber,
521 ArrayRef<unsigned> UnnamedArgNums);
522 LLVM_ABI ~PerFunctionState();
523
524 Function &getFunction() const { return F; }
525
526 LLVM_ABI bool finishFunction();
527
528 /// GetVal - Get a value with the specified name or ID, creating a
529 /// forward reference record if needed. This can return null if the value
530 /// exists but does not have the right type.
531 LLVM_ABI Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
532 LLVM_ABI Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
533
534 /// setInstName - After an instruction is parsed and inserted into its
535 /// basic block, this installs its name.
536 LLVM_ABI bool setInstName(int NameID, const std::string &NameStr,
537 LocTy NameLoc, Instruction *Inst);
538
539 /// GetBB - Get a basic block with the specified name or ID, creating a
540 /// forward reference record if needed. This can return null if the value
541 /// is not a BasicBlock.
542 LLVM_ABI BasicBlock *getBB(const std::string &Name, LocTy Loc);
543 LLVM_ABI BasicBlock *getBB(unsigned ID, LocTy Loc);
544
545 /// DefineBB - Define the specified basic block, which is either named or
546 /// unnamed. If there is an error, this returns null otherwise it returns
547 /// the block being defined.
548 LLVM_ABI BasicBlock *defineBB(const std::string &Name, int NameID,
549 LocTy Loc);
550
551 LLVM_ABI bool resolveForwardRefBlockAddresses();
552 };
553
554 bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
555 PerFunctionState *PFS);
556
557 Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
558 Value *Val);
559
560 bool parseConstantValue(Type *Ty, Constant *&C);
561 LLVM_ABI bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
562 bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
563 return parseValue(Ty, V, &PFS);
564 }
565
566 bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
567 Loc = Lex.getLoc();
568 return parseValue(Ty, V, &PFS);
569 }
570
571 LLVM_ABI bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
572 bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
573 return parseTypeAndValue(V, &PFS);
574 }
575 bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
576 Loc = Lex.getLoc();
577 return parseTypeAndValue(V, PFS);
578 }
579 LLVM_ABI bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
580 PerFunctionState &PFS);
581 bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
582 LocTy Loc;
583 return parseTypeAndBasicBlock(BB, Loc, PFS);
584 }
585
586 struct ParamInfo {
587 LocTy Loc;
588 Value *V;
589 AttributeSet Attrs;
590 ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
591 : Loc(loc), V(v), Attrs(attrs) {}
592 };
593 bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
594 PerFunctionState &PFS, bool IsMustTailCall = false,
595 bool InVarArgsFunc = false);
596
597 bool
598 parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
599 PerFunctionState &PFS);
600
601 bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
602 PerFunctionState &PFS);
603
604 bool resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
605 FunctionType *&FuncTy);
606
607 // Constant Parsing.
608 bool parseValID(ValID &ID, PerFunctionState *PFS,
609 Type *ExpectedTy = nullptr);
610 bool parseGlobalValue(Type *Ty, Constant *&C);
611 bool parseGlobalTypeAndValue(Constant *&V);
612 bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
613 bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
614 bool parseSanitizer(GlobalVariable *GV);
615 bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
616 bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
617 PerFunctionState *PFS);
618 bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
619 bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
620 bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
621 bool parseMDNode(MDNode *&N);
622 bool parseMDNodeTail(MDNode *&N);
623 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
624 bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
625 bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
626 bool parseInstructionMetadata(Instruction &Inst);
627 bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
628 bool parseOptionalFunctionMetadata(Function &F);
629
630 template <class FieldTy>
631 bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
632 template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
633 template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
634 template <class ParserTy>
635 bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
636 bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
637 bool parseDIExpressionBody(MDNode *&Result, bool IsDistinct);
638
639#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
640 bool parse##CLASS(MDNode *&Result, bool IsDistinct);
641#include "llvm/IR/Metadata.def"
642
643 // Function Parsing.
644 struct ArgInfo {
645 LocTy Loc;
646 Type *Ty;
647 std::optional<FileLocRange> IdentLoc;
648 AttributeSet Attrs;
649 std::string Name;
650 ArgInfo(LocTy L, Type *ty, std::optional<FileLocRange> IdentLoc,
651 AttributeSet Attr, const std::string &N)
652 : Loc(L), Ty(ty), IdentLoc(IdentLoc), Attrs(Attr), Name(N) {}
653 };
654 bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
655 SmallVectorImpl<unsigned> &UnnamedArgNums,
656 bool &IsVarArg);
657 bool parseFunctionHeader(Function *&Fn, bool IsDefine,
658 unsigned &FunctionNumber,
659 SmallVectorImpl<unsigned> &UnnamedArgNums);
660 bool parseFunctionBody(Function &Fn, unsigned FunctionNumber,
661 ArrayRef<unsigned> UnnamedArgNums);
662 bool parseBasicBlock(PerFunctionState &PFS);
663
664 enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
665
666 // Instruction Parsing. Each instruction parsing routine can return with a
667 // normal result, an error result, or return having eaten an extra comma.
668 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
669 int parseInstruction(Instruction *&Inst, BasicBlock *BB,
670 PerFunctionState &PFS);
671 bool parseCmpPredicate(unsigned &P, unsigned Opc);
672
673 bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
674 bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
675 bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
676 bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
677 bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
678 bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
679 bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
680 bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
681 bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
682 bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
683 bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
684 bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
685
686 bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
687 bool IsFP);
688 bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
689 unsigned Opc, bool IsFP);
690 bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
691 bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
692 bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
693 bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
694 bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
695 bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
696 bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
697 bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
698 bool parseBitExtract(Instruction *&Inst, PerFunctionState &PFS);
699 bool parseBitInsert(Instruction *&Inst, PerFunctionState &PFS);
700 int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
701 bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
702 bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
704 int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
705 int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
706 int parseStore(Instruction *&Inst, PerFunctionState &PFS);
707 int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
708 int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
709 int parseFence(Instruction *&Inst, PerFunctionState &PFS);
710 int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
711 int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
712 int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
713 bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
714
715 // Use-list order directives.
716 bool parseUseListOrder(PerFunctionState *PFS = nullptr);
717 bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
718 bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
719 };
720} // End llvm namespace
721
722#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
unsigned uint64_t
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")
#define LLVM_ABI
Definition Compiler.h:215
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))
static Expected< size_t > parseArgs(StringRef Section, mcdxbc::SourceInfo::ProgramArgs &Args)
#define P(N)
const char * Msg
#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:125
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:99
std::pair< unsigned, unsigned > getPrevTokEndLineColumnPos()
Get the line, column position of the end of the previous token, zero-indexed exclusive.
Definition LLLexer.h:92
LocTy getLoc() const
Definition LLLexer.h:71
SMLoc LocTy
Definition LLLexer.h:70
LLVM_ABI bool parseDIExpressionBodyAtBeginning(MDNode *&Result, unsigned &Read, const SlotMapping *Slots)
Definition LLParser.cpp:170
LLLexer::LocTy LocTy
Definition LLParser.h:110
LLVMContext & getContext()
Definition LLParser.h:239
LLVM_ABI bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
Definition LLParser.cpp:154
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, ModuleSummaryIndex *Index, LLVMContext &Context, SlotMapping *Slots=nullptr, AsmParserContext *ParserContext=nullptr)
Definition LLParser.h:213
LLVM_ABI bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
Definition LLParser.cpp:141
LLVM_ABI bool parseMetadataDefinitions(SlotMapping &Slots, ArrayRef< SMLoc > DefinitionEnds)
Definition LLParser.cpp:185
LLVM_ABI bool Run(bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Run: module ::= toplevelentity*.
Definition LLParser.cpp:122
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1081
A single uniqued string.
Definition Metadata.h:733
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:68
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:305
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:34
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:46
LLVM Value Representation.
Definition Value.h:75
CallInst * Call
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
This is an optimization pass for GlobalISel generic memory operations.
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
AllocFnKind
Definition Attributes.h:54
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
UWTableKind
Definition CodeGen.h:299
AtomicOrdering
Atomic ordering for LLVM's memory model.
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
Definition Parser.h:37
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
Struct holding Line:Column location.
Definition FileLoc.h:18
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