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