diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index d1023a73d6068..5a47a79d8f8ff 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1650,6 +1650,8 @@ class Record { DumpInfo(SMLoc Loc, Init *Message) : Loc(Loc), Message(Message) {} }; + enum RecordKind { RK_Def, RK_AnonymousDef, RK_Class, RK_MultiClass }; + private: Init *Name; // Location where record was instantiated, followed by the location of @@ -1676,24 +1678,22 @@ class Record { // Unique record ID. unsigned ID; - bool IsAnonymous; - bool IsClass; + RecordKind Kind; void checkName(); public: // Constructs a record. explicit Record(Init *N, ArrayRef locs, RecordKeeper &records, - bool Anonymous = false, bool Class = false) + RecordKind Kind = RK_Def) : Name(N), Locs(locs.begin(), locs.end()), TrackedRecords(records), - ID(getNewUID(N->getRecordKeeper())), IsAnonymous(Anonymous), - IsClass(Class) { + ID(getNewUID(N->getRecordKeeper())), Kind(Kind) { checkName(); } explicit Record(StringRef N, ArrayRef locs, RecordKeeper &records, - bool Class = false) - : Record(StringInit::get(records, N), locs, records, false, Class) {} + RecordKind Kind = RK_Def) + : Record(StringInit::get(records, N), locs, records, Kind) {} // When copy-constructing a Record, we must still guarantee a globally unique // ID number. Don't copy CorrespondingDefInit either, since it's owned by the @@ -1702,8 +1702,7 @@ class Record { : Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs), Values(O.Values), Assertions(O.Assertions), SuperClasses(O.SuperClasses), TrackedRecords(O.TrackedRecords), - ID(getNewUID(O.getRecords())), IsAnonymous(O.IsAnonymous), - IsClass(O.IsClass) {} + ID(getNewUID(O.getRecords())), Kind(O.Kind) {} static unsigned getNewUID(RecordKeeper &RK); @@ -1743,7 +1742,11 @@ class Record { /// get the corresponding DefInit. DefInit *getDefInit(); - bool isClass() const { return IsClass; } + bool isClass() const { return Kind == RK_Class; } + + bool isMultiClass() const { return Kind == RK_MultiClass; } + + bool isAnonymous() const { return Kind == RK_AnonymousDef; } ArrayRef getTemplateArgs() const { return TemplateArgs; @@ -1871,10 +1874,6 @@ class Record { return TrackedRecords; } - bool isAnonymous() const { - return IsAnonymous; - } - void dump() const; //===--------------------------------------------------------------------===// diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 675969003ab3c..aa981fdab4b3e 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2263,9 +2263,9 @@ void VarDefInit::Profile(FoldingSetNodeID &ID) const { DefInit *VarDefInit::instantiate() { if (!Def) { RecordKeeper &Records = Class->getRecords(); - auto NewRecOwner = std::make_unique(Records.getNewAnonymousName(), - Class->getLoc(), Records, - /*IsAnonymous=*/true); + auto NewRecOwner = + std::make_unique(Records.getNewAnonymousName(), Class->getLoc(), + Records, Record::RK_AnonymousDef); Record *NewRec = NewRecOwner.get(); // Copy values from class to instance diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 16854c7d1f05a..21d6ca0e7b8d3 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -111,10 +111,11 @@ static void checkConcrete(Record &R) { /// Return an Init with a qualifier prefix referring /// to CurRec's name. -static Init *QualifyName(Record &CurRec, Init *Name, bool IsMC = false) { +static Init *QualifyName(Record &CurRec, Init *Name) { RecordKeeper &RK = CurRec.getRecords(); Init *NewName = BinOpInit::getStrConcat( - CurRec.getNameInit(), StringInit::get(RK, IsMC ? "::" : ":")); + CurRec.getNameInit(), + StringInit::get(RK, CurRec.isMultiClass() ? "::" : ":")); NewName = BinOpInit::getStrConcat(NewName, Name); if (BinOpInit *BinOp = dyn_cast(NewName)) @@ -123,16 +124,16 @@ static Init *QualifyName(Record &CurRec, Init *Name, bool IsMC = false) { } static Init *QualifyName(MultiClass *MC, Init *Name) { - return QualifyName(MC->Rec, Name, /*IsMC=*/true); + return QualifyName(MC->Rec, Name); } /// Return the qualified version of the implicit 'NAME' template argument. -static Init *QualifiedNameOfImplicitName(Record &Rec, bool IsMC = false) { - return QualifyName(Rec, StringInit::get(Rec.getRecords(), "NAME"), IsMC); +static Init *QualifiedNameOfImplicitName(Record &Rec) { + return QualifyName(Rec, StringInit::get(Rec.getRecords(), "NAME")); } static Init *QualifiedNameOfImplicitName(MultiClass *MC) { - return QualifiedNameOfImplicitName(MC->Rec, /*IsMC=*/true); + return QualifiedNameOfImplicitName(MC->Rec); } Init *TGVarScope::getVar(RecordKeeper &Records, MultiClass *ParsingMultiClass, @@ -143,11 +144,10 @@ Init *TGVarScope::getVar(RecordKeeper &Records, MultiClass *ParsingMultiClass, if (It != Vars.end()) return It->second; - auto FindValueInArgs = [&](Record *Rec, StringInit *Name, - bool IsMC) -> Init * { + auto FindValueInArgs = [&](Record *Rec, StringInit *Name) -> Init * { if (!Rec) return nullptr; - Init *ArgName = QualifyName(*Rec, Name, IsMC); + Init *ArgName = QualifyName(*Rec, Name); if (Rec->isTemplateArg(ArgName)) { RecordVal *RV = Rec->getValue(ArgName); assert(RV && "Template arg doesn't exist??"); @@ -177,7 +177,7 @@ Init *TGVarScope::getVar(RecordKeeper &Records, MultiClass *ParsingMultiClass, // The variable is a class template argument? if (CurRec->isClass()) - if (auto *V = FindValueInArgs(CurRec, Name, /*IsMC=*/false)) + if (auto *V = FindValueInArgs(CurRec, Name)) return V; } break; @@ -194,7 +194,7 @@ Init *TGVarScope::getVar(RecordKeeper &Records, MultiClass *ParsingMultiClass, case SK_MultiClass: { // The variable is a multiclass template argument? if (CurMultiClass) - if (auto *V = FindValueInArgs(&CurMultiClass->Rec, Name, /*IsMC=*/true)) + if (auto *V = FindValueInArgs(&CurMultiClass->Rec, Name)) return V; break; } @@ -772,8 +772,7 @@ ParseSubClassReference(Record *CurRec, bool isDefm) { return Result; } - if (ParseTemplateArgValueList(Result.TemplateArgs, CurRec, Result.Rec, - isDefm)) { + if (ParseTemplateArgValueList(Result.TemplateArgs, CurRec, Result.Rec)) { Result.Rec = nullptr; // Error parsing value list. return Result; } @@ -810,7 +809,7 @@ ParseSubMultiClassReference(MultiClass *CurMC) { } if (ParseTemplateArgValueList(Result.TemplateArgs, &CurMC->Rec, - &Result.MC->Rec, true)) { + &Result.MC->Rec)) { Result.MC = nullptr; // Error parsing value list. return Result; } @@ -3160,8 +3159,7 @@ void TGParser::ParseValueList(SmallVectorImpl &Result, Record *CurRec, // PostionalArgValueList ::= [Value {',' Value}*] // NamedArgValueList ::= [NameValue '=' Value {',' NameValue '=' Value}*] bool TGParser::ParseTemplateArgValueList( - SmallVectorImpl &Result, Record *CurRec, Record *ArgsRec, - bool IsDefm) { + SmallVectorImpl &Result, Record *CurRec, Record *ArgsRec) { assert(Result.empty() && "Result vector is not empty"); ArrayRef TArgs = ArgsRec->getTemplateArgs(); @@ -3192,7 +3190,7 @@ bool TGParser::ParseTemplateArgValueList( "The name of named argument should be a valid identifier"); auto *Name = cast(Value); - Init *QualifiedName = QualifyName(*ArgsRec, Name, /*IsMC=*/IsDefm); + Init *QualifiedName = QualifyName(*ArgsRec, Name); auto *NamedArg = ArgsRec->getValue(QualifiedName); if (!NamedArg) return Error(ValueLoc, @@ -3610,9 +3608,8 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) { return true; if (isa(Name)) { - CurRec = - std::make_unique(Records.getNewAnonymousName(), DefLoc, Records, - /*Anonymous=*/true); + CurRec = std::make_unique(Records.getNewAnonymousName(), DefLoc, + Records, Record::RK_AnonymousDef); } else { CurRec = std::make_unique(Name, NameLoc, Records); } @@ -3930,9 +3927,8 @@ bool TGParser::ParseClass() { CurRec->updateClassLoc(Lex.getLoc()); } else { // If this is the first reference to this class, create and add it. - auto NewRec = - std::make_unique(Lex.getCurStrVal(), Lex.getLoc(), Records, - /*Class=*/true); + auto NewRec = std::make_unique(Lex.getCurStrVal(), Lex.getLoc(), + Records, Record::RK_Class); CurRec = NewRec.get(); Records.addClass(std::move(NewRec)); } diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h index c5365ff270924..0929154fed3d4 100644 --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/lib/TableGen/TGParser.h @@ -85,7 +85,7 @@ struct MultiClass { void dump() const; MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records) - : Rec(Name, Loc, Records) {} + : Rec(Name, Loc, Records, Record::RK_MultiClass) {} }; class TGVarScope { @@ -293,8 +293,7 @@ class TGParser { void ParseValueList(SmallVectorImpl &Result, Record *CurRec, RecTy *ItemType = nullptr); bool ParseTemplateArgValueList(SmallVectorImpl &Result, - Record *CurRec, Record *ArgsRec, - bool IsDefm = false); + Record *CurRec, Record *ArgsRec); void ParseDagArgList( SmallVectorImpl> &Result, Record *CurRec);