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