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