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