[llvm] r326787 - TableGen: Move getNewAnonymousName into RecordKeeper
Nicolai Haehnle via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 6 05:48:54 PST 2018
Author: nha
Date: Tue Mar 6 05:48:54 2018
New Revision: 326787
URL: http://llvm.org/viewvc/llvm-project?rev=326787&view=rev
Log:
TableGen: Move getNewAnonymousName into RecordKeeper
Summary:
So that we will be able to generate new anonymous names more easily
outside the parser as well.
Change-Id: I28f396a7bdbc3ff0c665d466abbd3d31376e21b4
Reviewers: arsenm, craig.topper, tra, MartinO
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D43755
Modified:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/lib/TableGen/TGParser.h
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=326787&r1=326786&r2=326787&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Tue Mar 6 05:48:54 2018
@@ -1506,6 +1506,7 @@ class RecordKeeper {
using RecordMap = std::map<std::string, std::unique_ptr<Record>>;
RecordMap Classes, Defs;
FoldingSet<RecordRecTy> RecordTypePool;
+ unsigned AnonCounter = 0;
public:
const RecordMap &getClasses() const { return Classes; }
@@ -1535,6 +1536,8 @@ public:
assert(Ins && "Record already exists");
}
+ Init *getNewAnonymousName();
+
//===--------------------------------------------------------------------===//
// High-level helper methods, useful for tablegen backends...
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=326787&r1=326786&r2=326787&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Tue Mar 6 05:48:54 2018
@@ -1834,6 +1834,12 @@ raw_ostream &llvm::operator<<(raw_ostrea
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<Record *>
RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const {
Record *Class = getClass(ClassName);
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=326787&r1=326786&r2=326787&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Tue Mar 6 05:48:54 2018
@@ -406,7 +406,7 @@ bool TGParser::ProcessForeachDefs(Record
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.
@@ -427,12 +427,6 @@ static bool isObjectStart(tgtok::TokKind
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 ]*
@@ -1364,8 +1358,9 @@ Init *TGParser::ParseSimpleValue(Record
SMLoc EndLoc = Lex.getLoc();
// Create the new record, set it as CurRec temporarily.
- auto NewRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), NameLoc,
- Records, /*IsAnonymous=*/true);
+ auto NewRecOwner =
+ make_unique<Record>(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;
@@ -2158,8 +2153,8 @@ bool TGParser::ParseDef(MultiClass *CurM
if (Name)
CurRecOwner = make_unique<Record>(Name, DefLoc, Records);
else
- CurRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), DefLoc,
- Records, /*IsAnonymous=*/true);
+ CurRecOwner = make_unique<Record>(Records.getNewAnonymousName(), DefLoc,
+ Records, /*IsAnonymous=*/true);
Record *CurRec = CurRecOwner.get(); // Keep a copy since we may release.
if (!CurMultiClass && Loops.empty()) {
@@ -2504,7 +2499,7 @@ Record *TGParser::InstantiateMulticlassD
bool IsAnonymous = false;
if (!DefmPrefix) {
- DefmPrefix = GetNewAnonymousName();
+ DefmPrefix = Records.getNewAnonymousName();
IsAnonymous = true;
}
Modified: llvm/trunk/lib/TableGen/TGParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.h?rev=326787&r1=326786&r2=326787&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.h (original)
+++ llvm/trunk/lib/TableGen/TGParser.h Tue Mar 6 05:48:54 2018
@@ -68,8 +68,6 @@ class TGParser {
// 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 @@ class TGParser {
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 @@ private: // Semantic analysis methods.
bool AddSubMultiClass(MultiClass *CurMC,
SubMultiClassReference &SubMultiClass);
- Init *GetNewAnonymousName();
-
// IterRecord: Map an iterator name to a value.
struct IterRecord {
VarInit *IterVar;
More information about the llvm-commits
mailing list