Index: include/llvm/TableGen/Record.h =================================================================== --- include/llvm/TableGen/Record.h +++ include/llvm/TableGen/Record.h @@ -1503,6 +1503,7 @@ class RecordKeeper { using RecordMap = std::map>; RecordMap Classes, Defs; + unsigned AnonCounter = 0; public: const RecordMap &getClasses() const { return Classes; } @@ -1532,6 +1533,8 @@ assert(Ins && "Record already exists"); } + Init *getNewAnonymousName(); + //===--------------------------------------------------------------------===// // High-level helper methods, useful for tablegen backends... Index: lib/TableGen/Record.cpp =================================================================== --- lib/TableGen/Record.cpp +++ lib/TableGen/Record.cpp @@ -1833,6 +1833,12 @@ return OS; } +/// GetNewAnonymousName - Generate a unique anonymous name that can be used as +/// an identifier. +Init *RecordKeeper::getNewAnonymousName() { + return StringInit::get("anonymous_" + utostr(AnonCounter++)); +} + std::vector RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const { Record *Class = getClass(ClassName); Index: lib/TableGen/TGParser.h =================================================================== --- lib/TableGen/TGParser.h +++ lib/TableGen/TGParser.h @@ -68,8 +68,6 @@ // Record tracker RecordKeeper &Records; - unsigned AnonCounter; - // A "named boolean" indicating how to parse identifiers. Usually // identifiers map to some existing object but in special cases // (e.g. parsing def names) no such object exists yet because we are @@ -84,7 +82,7 @@ public: TGParser(SourceMgr &SrcMgr, RecordKeeper &records) - : Lex(SrcMgr), CurMultiClass(nullptr), Records(records), AnonCounter(0) {} + : Lex(SrcMgr), CurMultiClass(nullptr), Records(records) {} /// ParseFile - Main entrypoint for parsing a tblgen file. These parser /// routines return true on error, or false on success. @@ -110,8 +108,6 @@ bool AddSubMultiClass(MultiClass *CurMC, SubMultiClassReference &SubMultiClass); - Init *GetNewAnonymousName(); - // IterRecord: Map an iterator name to a value. struct IterRecord { VarInit *IterVar; Index: lib/TableGen/TGParser.cpp =================================================================== --- lib/TableGen/TGParser.cpp +++ lib/TableGen/TGParser.cpp @@ -411,7 +411,7 @@ if (!IterRec->isAnonymous()) return Error(Loc, "def already exists: " +IterRec->getNameInitAsString()); - IterRec->setName(GetNewAnonymousName()); + IterRec->setName(Records.getNewAnonymousName()); } Record *IterRecSave = IterRec.get(); // Keep a copy before release. @@ -432,12 +432,6 @@ K == tgtok::MultiClass || K == tgtok::Foreach; } -/// GetNewAnonymousName - Generate a unique anonymous name that can be used as -/// an identifier. -Init *TGParser::GetNewAnonymousName() { - return StringInit::get("anonymous_" + utostr(AnonCounter++)); -} - /// ParseObjectName - If an object name is specified, return it. Otherwise, /// return 0. /// ObjectName ::= Value [ '#' Value ]* @@ -1369,8 +1363,9 @@ SMLoc EndLoc = Lex.getLoc(); // Create the new record, set it as CurRec temporarily. - auto NewRecOwner = llvm::make_unique(GetNewAnonymousName(), NameLoc, - Records, /*IsAnonymous=*/true); + auto NewRecOwner = + make_unique(Records.getNewAnonymousName(), NameLoc, Records, + /*IsAnonymous=*/true); Record *NewRec = NewRecOwner.get(); // Keep a copy since we may release. SCRef.RefRange = SMRange(NameLoc, EndLoc); SCRef.Rec = Class; @@ -2163,8 +2158,8 @@ if (Name) CurRecOwner = make_unique(Name, DefLoc, Records); else - CurRecOwner = llvm::make_unique(GetNewAnonymousName(), DefLoc, - Records, /*IsAnonymous=*/true); + CurRecOwner = make_unique(Records.getNewAnonymousName(), DefLoc, + Records, /*IsAnonymous=*/true); Record *CurRec = CurRecOwner.get(); // Keep a copy since we may release. if (!CurMultiClass && Loops.empty()) { @@ -2509,7 +2504,7 @@ bool IsAnonymous = false; if (!DefmPrefix) { - DefmPrefix = GetNewAnonymousName(); + DefmPrefix = Records.getNewAnonymousName(); IsAnonymous = true; }