13#ifndef LLVM_LIB_TABLEGEN_TGPARSER_H
14#define LLVM_LIB_TABLEGEN_TGPARSER_H
26struct SubClassReference;
27struct SubMultiClassReference;
31 std::vector<unsigned>
Bits;
41 std::unique_ptr<Record>
Rec;
42 std::unique_ptr<ForeachLoop>
Loop;
44 std::unique_ptr<Record::DumpInfo>
Dump;
97 std::unique_ptr<TGVarScope> Parent;
99 std::map<std::string, const Init *, std::less<>> Vars;
113 CurMultiClass(Multiclass) {}
118 return std::move(Parent);
123 bool TrackReferenceLocs)
const;
130 return Vars.find(
Name) != Vars.end();
134 bool Ins = Vars.insert(std::make_pair(std::string(
Name),
I)).second;
136 assert(Ins &&
"Local variable already exists");
144 std::vector<SmallVector<LetRecord, 4>> LetStack;
145 std::map<std::string, std::unique_ptr<MultiClass>> MultiClasses;
146 std::map<std::string, const RecTy *> TypeAliases;
150 std::vector<std::unique_ptr<ForeachLoop>> Loops;
159 std::unique_ptr<TGVarScope> CurScope;
175 bool NoWarnOnUnusedTemplateArgs =
false;
176 bool TrackReferenceLocs =
false;
180 const bool NoWarnOnUnusedTemplateArgs =
false,
181 const bool TrackReferenceLocs =
false)
182 : Lex(SM, Macros), CurMultiClass(nullptr), Records(records),
183 NoWarnOnUnusedTemplateArgs(NoWarnOnUnusedTemplateArgs),
184 TrackReferenceLocs(TrackReferenceLocs) {}
202 CurScope = std::make_unique<TGVarScope>(std::move(CurScope));
206 return CurScope.get();
209 CurScope = std::make_unique<TGVarScope>(std::move(CurScope), Rec);
210 return CurScope.get();
213 CurScope = std::make_unique<TGVarScope>(std::move(CurScope),
Loop);
214 return CurScope.get();
217 CurScope = std::make_unique<TGVarScope>(std::move(CurScope), Multiclass);
218 return CurScope.get();
221 assert(ExpectedStackTop == CurScope.get() &&
222 "Mismatched pushes and pops of local variable scopes");
223 CurScope = CurScope->extractParent();
233 bool AllowSelfAssignment =
false,
bool OverrideDefLoc =
true);
243 std::vector<RecordsEntry> *Dest,
SMLoc *Loc =
nullptr);
244 bool resolve(
const std::vector<RecordsEntry> &Source, SubstStack &Substs,
245 bool Final, std::vector<RecordsEntry> *Dest,
246 SMLoc *Loc =
nullptr);
247 bool addDefOne(std::unique_ptr<Record> Rec);
249 using ArgValueHandler = std::function<void(
const Init *,
const Init *)>;
250 bool resolveArguments(
252 ArgValueHandler ArgValueHandler = [](
const Init *,
const Init *) {});
253 bool resolveArgumentsOfClass(MapResolver &R,
const Record *Rec,
254 ArrayRef<const ArgumentInit *> ArgValues,
256 bool resolveArgumentsOfMultiClass(SubstStack &Substs, MultiClass *MC,
257 ArrayRef<const ArgumentInit *> ArgValues,
258 const Init *DefmName, SMLoc Loc);
262 bool ParseObjectList(MultiClass *MC =
nullptr);
263 bool ParseObject(MultiClass *MC);
265 bool ParseMultiClass();
266 bool ParseDefm(MultiClass *CurMultiClass);
267 bool ParseDef(MultiClass *CurMultiClass);
270 bool ParseDefvar(Record *CurRec =
nullptr);
271 bool ParseDump(MultiClass *CurMultiClass, Record *CurRec =
nullptr);
272 bool ParseForeach(MultiClass *CurMultiClass);
273 bool ParseIf(MultiClass *CurMultiClass);
274 bool ParseIfBody(MultiClass *CurMultiClass, StringRef Kind);
275 bool ParseAssert(MultiClass *CurMultiClass, Record *CurRec =
nullptr);
276 bool ParseTopLevelLet(MultiClass *CurMultiClass);
277 void ParseLetList(SmallVectorImpl<LetRecord> &Result);
279 bool ParseObjectBody(Record *CurRec);
280 bool ParseBody(Record *CurRec);
281 bool ParseBodyItem(Record *CurRec);
283 bool ParseTemplateArgList(Record *CurRec);
284 const Init *ParseDeclaration(Record *CurRec,
bool ParsingTemplateArgs);
285 const VarInit *ParseForeachDeclaration(
const Init *&ForeachListValue);
287 SubClassReference ParseSubClassReference(Record *CurRec,
bool isDefm);
288 SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
290 const Init *ParseIDValue(Record *CurRec,
const StringInit *
Name,
291 SMRange NameLoc, IDParseMode
Mode = ParseValueMode);
292 const Init *ParseSimpleValue(Record *CurRec,
const RecTy *ItemType =
nullptr,
293 IDParseMode
Mode = ParseValueMode);
294 const Init *ParseValue(Record *CurRec,
const RecTy *ItemType =
nullptr,
295 IDParseMode
Mode = ParseValueMode);
296 void ParseValueList(SmallVectorImpl<const Init *> &Result, Record *CurRec,
297 const RecTy *ItemType =
nullptr);
298 bool ParseTemplateArgValueList(SmallVectorImpl<const ArgumentInit *> &Result,
299 Record *CurRec,
const Record *ArgsRec);
300 void ParseDagArgList(
301 SmallVectorImpl<std::pair<const Init *, const StringInit *>> &Result,
303 bool ParseOptionalRangeList(SmallVectorImpl<unsigned> &Ranges);
304 bool ParseOptionalBitList(SmallVectorImpl<unsigned> &Ranges);
305 const TypedInit *ParseSliceElement(Record *CurRec);
306 const TypedInit *ParseSliceElements(Record *CurRec,
bool Single =
false);
307 void ParseRangeList(SmallVectorImpl<unsigned> &Result);
308 bool ParseRangePiece(SmallVectorImpl<unsigned> &Ranges,
309 const TypedInit *FirstItem =
nullptr);
310 const RecTy *ParseType();
311 const Init *ParseOperation(Record *CurRec,
const RecTy *ItemType);
312 const Init *ParseOperationSubstr(Record *CurRec,
const RecTy *ItemType);
313 const Init *ParseOperationFind(Record *CurRec,
const RecTy *ItemType);
314 const Init *ParseOperationForEachFilter(Record *CurRec,
315 const RecTy *ItemType);
316 const Init *ParseOperationCond(Record *CurRec,
const RecTy *ItemType);
317 const RecTy *ParseOperatorType();
318 const Init *ParseObjectName(MultiClass *CurMultiClass);
319 const Record *ParseClassID();
320 MultiClass *ParseMultiClassID();
321 bool ApplyLetStack(Record *CurRec);
322 bool ApplyLetStack(RecordsEntry &Entry);
323 bool CheckTemplateArgValues(SmallVectorImpl<const ArgumentInit *> &Values,
324 SMLoc Loc,
const Record *ArgsRec);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Represents a single loop in the control flow graph.
This class represents a field in a record, including its name, type, value, and source location.
Represents a location in source code.
Represents a range in source code.
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.
"foo" - Represent an initialization by a string value.
StringRef - Represent a constant reference to a string, i.e.
TGLexer - TableGen Lexer class.
std::set< std::string > DependenciesSetTy
const DependenciesSetTy & getDependencies() const
void PopScope(TGVarScope *ExpectedStackTop)
const TGLexer::DependenciesSetTy & getDependencies() const
bool Error(SMLoc L, const Twine &Msg) const
TGVarScope * PushScope(ForeachLoop *Loop)
TGVarScope * PushScope(Record *Rec)
bool TokError(const Twine &Msg) const
TGParser(SourceMgr &SM, ArrayRef< std::string > Macros, RecordKeeper &records, const bool NoWarnOnUnusedTemplateArgs=false, const bool TrackReferenceLocs=false)
TGVarScope * PushScope(MultiClass *Multiclass)
bool ParseFile()
ParseFile - Main entrypoint for parsing a tblgen file.
TGVarScope(std::unique_ptr< TGVarScope > Parent, Record *Rec)
std::unique_ptr< TGVarScope > extractParent()
TGVarScope(std::unique_ptr< TGVarScope > Parent, ForeachLoop *Loop)
void addVar(StringRef Name, const Init *I)
bool varAlreadyDefined(StringRef Name) const
const Init * getVar(RecordKeeper &Records, MultiClass *ParsingMultiClass, const StringInit *Name, SMRange NameLoc, bool TrackReferenceLocs) const
TGVarScope(std::unique_ptr< TGVarScope > Parent, MultiClass *Multiclass)
TGVarScope(std::unique_ptr< TGVarScope > Parent)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
'Opcode' - Represent a reference to an entire variable object.
This is an optimization pass for GlobalISel generic memory operations.
void PrintError(const Twine &Msg)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
SmallVector< Init *, 16 > Elements
ForeachLoop - Record the iteration state associated with a for loop.
ForeachLoop(SMLoc Loc, const VarInit *IVar, const Init *LValue)
std::vector< RecordsEntry > Entries
LetRecord(const StringInit *N, ArrayRef< unsigned > B, const Init *V, SMLoc L)
std::vector< unsigned > Bits
std::vector< RecordsEntry > Entries
MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records)
RecordsEntry - Holds exactly one of a Record, ForeachLoop, or AssertionInfo.
RecordsEntry(std::unique_ptr< Record::DumpInfo > Dump)
RecordsEntry(std::unique_ptr< ForeachLoop > Loop)
std::unique_ptr< ForeachLoop > Loop
std::unique_ptr< Record::AssertionInfo > Assertion
std::unique_ptr< Record::DumpInfo > Dump
RecordsEntry(std::unique_ptr< Record > Rec)
std::unique_ptr< Record > Rec
RecordsEntry(std::unique_ptr< Record::AssertionInfo > Assertion)