Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC][LLVM][TableGen] Change RecordKeeper::getClass to return const pointer #112261

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions llvm/include/llvm/TableGen/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -1355,11 +1355,11 @@ class VarDefInit final
public FoldingSetNode,
public TrailingObjects<VarDefInit, const ArgumentInit *> {
SMLoc Loc;
Record *Class;
const Record *Class;
const DefInit *Def = nullptr; // after instantiation
unsigned NumArgs;

explicit VarDefInit(SMLoc Loc, Record *Class, unsigned N);
explicit VarDefInit(SMLoc Loc, const Record *Class, unsigned N);

const DefInit *instantiate();

Expand All @@ -1373,7 +1373,7 @@ class VarDefInit final
static bool classof(const Init *I) {
return I->getKind() == IK_VarDefInit;
}
static const VarDefInit *get(SMLoc Loc, Record *Class,
static const VarDefInit *get(SMLoc Loc, const Record *Class,
ArrayRef<const ArgumentInit *> Args);

void Profile(FoldingSetNodeID &ID) const;
Expand Down Expand Up @@ -2000,7 +2000,7 @@ class RecordKeeper {
const GlobalMap &getGlobals() const { return ExtraGlobals; }

/// Get the class with the specified name.
Record *getClass(StringRef Name) const {
const Record *getClass(StringRef Name) const {
auto I = Classes.find(Name);
return I == Classes.end() ? nullptr : I->second.get();
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/TableGen/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ const RecTy *DefInit::getFieldType(const StringInit *FieldName) const {

std::string DefInit::getAsString() const { return std::string(Def->getName()); }

static void ProfileVarDefInit(FoldingSetNodeID &ID, Record *Class,
static void ProfileVarDefInit(FoldingSetNodeID &ID, const Record *Class,
ArrayRef<const ArgumentInit *> Args) {
ID.AddInteger(Args.size());
ID.AddPointer(Class);
Expand All @@ -2303,11 +2303,11 @@ static void ProfileVarDefInit(FoldingSetNodeID &ID, Record *Class,
ID.AddPointer(I);
}

VarDefInit::VarDefInit(SMLoc Loc, Record *Class, unsigned N)
VarDefInit::VarDefInit(SMLoc Loc, const Record *Class, unsigned N)
: TypedInit(IK_VarDefInit, RecordRecTy::get(Class)), Loc(Loc), Class(Class),
NumArgs(N) {}

const VarDefInit *VarDefInit::get(SMLoc Loc, Record *Class,
const VarDefInit *VarDefInit::get(SMLoc Loc, const Record *Class,
ArrayRef<const ArgumentInit *> Args) {
FoldingSetNodeID ID;
ProfileVarDefInit(ID, Class, Args);
Expand Down
27 changes: 14 additions & 13 deletions llvm/lib/TableGen/TGParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace llvm {

struct SubClassReference {
SMRange RefRange;
Record *Rec = nullptr;
const Record *Rec = nullptr;
SmallVector<const ArgumentInit *, 4> TemplateArgs;

SubClassReference() = default;
Expand Down Expand Up @@ -110,7 +110,7 @@ static void checkConcrete(Record &R) {

/// Return an Init with a qualifier prefix referring
/// to CurRec's name.
static const Init *QualifyName(Record &CurRec, const Init *Name) {
static const Init *QualifyName(const Record &CurRec, const Init *Name) {
RecordKeeper &RK = CurRec.getRecords();
const Init *NewName = BinOpInit::getStrConcat(
CurRec.getNameInit(),
Expand All @@ -127,7 +127,7 @@ static const Init *QualifyName(MultiClass *MC, const Init *Name) {
}

/// Return the qualified version of the implicit 'NAME' template argument.
static const Init *QualifiedNameOfImplicitName(Record &Rec) {
static const Init *QualifiedNameOfImplicitName(const Record &Rec) {
return QualifyName(Rec, StringInit::get(Rec.getRecords(), "NAME"));
}

Expand Down Expand Up @@ -298,7 +298,7 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName,
/// AddSubClass - Add SubClass as a subclass to CurRec, resolving its template
/// args as SubClass's template arguments.
bool TGParser::AddSubClass(Record *CurRec, SubClassReference &SubClass) {
Record *SC = SubClass.Rec;
const Record *SC = SubClass.Rec;
MapResolver R(CurRec);

// Loop over all the subclass record's fields. Add regular fields to the new
Expand Down Expand Up @@ -588,7 +588,7 @@ bool TGParser::addDefOne(std::unique_ptr<Record> Rec) {
return false;
}

bool TGParser::resolveArguments(Record *Rec,
bool TGParser::resolveArguments(const Record *Rec,
ArrayRef<const ArgumentInit *> ArgValues,
SMLoc Loc, ArgValueHandler ArgValueHandler) {
ArrayRef<const Init *> ArgNames = Rec->getTemplateArgs();
Expand Down Expand Up @@ -632,7 +632,7 @@ bool TGParser::resolveArguments(Record *Rec,

/// Resolve the arguments of class and set them to MapResolver.
/// Returns true if failed.
bool TGParser::resolveArgumentsOfClass(MapResolver &R, Record *Rec,
bool TGParser::resolveArgumentsOfClass(MapResolver &R, const Record *Rec,
ArrayRef<const ArgumentInit *> ArgValues,
SMLoc Loc) {
return resolveArguments(
Expand Down Expand Up @@ -710,13 +710,13 @@ const Init *TGParser::ParseObjectName(MultiClass *CurMultiClass) {
///
/// ClassID ::= ID
///
Record *TGParser::ParseClassID() {
const Record *TGParser::ParseClassID() {
if (Lex.getCode() != tgtok::Id) {
TokError("expected name for ClassID");
return nullptr;
}

Record *Result = Records.getClass(Lex.getCurStrVal());
const Record *Result = Records.getClass(Lex.getCurStrVal());
if (!Result) {
std::string Msg("Couldn't find class '" + Lex.getCurStrVal() + "'");
if (MultiClasses[Lex.getCurStrVal()].get())
Expand Down Expand Up @@ -2708,7 +2708,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType,
// Value ::= CLASSID '<' ArgValueList '>' (CLASSID has been consumed)
// This is supposed to synthesize a new anonymous definition, deriving
// from the class with the template arguments, but no body.
Record *Class = Records.getClass(Name->getValue());
const Record *Class = Records.getClass(Name->getValue());
if (!Class) {
Error(NameLoc.Start,
"Expected a class name, got '" + Name->getValue() + "'");
Expand Down Expand Up @@ -3196,7 +3196,7 @@ void TGParser::ParseValueList(SmallVectorImpl<const Init *> &Result,
// NamedArgValueList ::= [NameValue '=' Value {',' NameValue '=' Value}*]
bool TGParser::ParseTemplateArgValueList(
SmallVectorImpl<const ArgumentInit *> &Result, Record *CurRec,
Record *ArgsRec) {
const Record *ArgsRec) {
assert(Result.empty() && "Result vector is not empty");
ArrayRef<const Init *> TArgs = ArgsRec->getTemplateArgs();

Expand Down Expand Up @@ -3990,7 +3990,7 @@ bool TGParser::ParseClass() {
return TokError("expected class name after 'class' keyword");

const std::string &Name = Lex.getCurStrVal();
Record *CurRec = Records.getClass(Name);
Record *CurRec = const_cast<Record *>(Records.getClass(Name));
if (CurRec) {
// If the body was previously defined, this is an error.
if (!CurRec->getValues().empty() ||
Expand Down Expand Up @@ -4411,7 +4411,8 @@ bool TGParser::ParseFile() {
// If necessary, replace an argument with a cast to the required type.
// The argument count has already been checked.
bool TGParser::CheckTemplateArgValues(
SmallVectorImpl<const ArgumentInit *> &Values, SMLoc Loc, Record *ArgsRec) {
SmallVectorImpl<const ArgumentInit *> &Values, SMLoc Loc,
const Record *ArgsRec) {
ArrayRef<const Init *> TArgs = ArgsRec->getTemplateArgs();

for (const ArgumentInit *&Value : Values) {
Expand All @@ -4421,7 +4422,7 @@ bool TGParser::CheckTemplateArgValues(
if (Value->isNamed())
ArgName = Value->getName();

RecordVal *Arg = ArgsRec->getValue(ArgName);
const RecordVal *Arg = ArgsRec->getValue(ArgName);
const RecTy *ArgType = Arg->getType();

if (const auto *ArgValue = dyn_cast<TypedInit>(Value->getValue())) {
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/TableGen/TGParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ class TGParser {

using ArgValueHandler = std::function<void(const Init *, const Init *)>;
bool resolveArguments(
Record *Rec, ArrayRef<const ArgumentInit *> ArgValues, SMLoc Loc,
const Record *Rec, ArrayRef<const ArgumentInit *> ArgValues, SMLoc Loc,
ArgValueHandler ArgValueHandler = [](const Init *, const Init *) {});
bool resolveArgumentsOfClass(MapResolver &R, Record *Rec,
bool resolveArgumentsOfClass(MapResolver &R, const Record *Rec,
ArrayRef<const ArgumentInit *> ArgValues,
SMLoc Loc);
bool resolveArgumentsOfMultiClass(SubstStack &Substs, MultiClass *MC,
Expand Down Expand Up @@ -296,7 +296,7 @@ class TGParser {
void ParseValueList(SmallVectorImpl<const Init *> &Result, Record *CurRec,
const RecTy *ItemType = nullptr);
bool ParseTemplateArgValueList(SmallVectorImpl<const ArgumentInit *> &Result,
Record *CurRec, Record *ArgsRec);
Record *CurRec, const Record *ArgsRec);
void ParseDagArgList(
SmallVectorImpl<std::pair<const Init *, const StringInit *>> &Result,
Record *CurRec);
Expand All @@ -316,12 +316,12 @@ class TGParser {
const Init *ParseOperationCond(Record *CurRec, const RecTy *ItemType);
const RecTy *ParseOperatorType();
const Init *ParseObjectName(MultiClass *CurMultiClass);
Record *ParseClassID();
const Record *ParseClassID();
MultiClass *ParseMultiClassID();
bool ApplyLetStack(Record *CurRec);
bool ApplyLetStack(RecordsEntry &Entry);
bool CheckTemplateArgValues(SmallVectorImpl<const ArgumentInit *> &Values,
SMLoc Loc, Record *ArgsRec);
SMLoc Loc, const Record *ArgsRec);
};

} // end namespace llvm
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ struct TupleExpander : SetTheory::Expander {
return;

// Precompute some types.
Record *RegisterCl = Def->getRecords().getClass("Register");
const Record *RegisterCl = Def->getRecords().getClass("Register");
const RecTy *RegisterRecTy = RecordRecTy::get(RegisterCl);
std::vector<StringRef> RegNames =
Def->getValueAsListOfStrings("RegAsmNames");
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ static bool emitSerializationFns(const RecordKeeper &records, raw_ostream &os) {
utilsString;
raw_string_ostream dSerFn(dSerFnString), dDesFn(dDesFnString),
serFn(serFnString), deserFn(deserFnString);
Record *attrClass = records.getClass("Attr");
const Record *attrClass = records.getClass("Attr");

// Emit the serialization and deserialization functions simultaneously.
StringRef opVar("op");
Expand Down
Loading