Skip to content

Commit 667815c

Browse files
authored
[NFC][TableGen] Change RecordKeeper::getDef() to return const pointer (#110992)
This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
1 parent b78bfe7 commit 667815c

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,14 +1993,14 @@ class RecordKeeper {
19931993
}
19941994

19951995
/// Get the concrete record with the specified name.
1996-
Record *getDef(StringRef Name) const {
1996+
const Record *getDef(StringRef Name) const {
19971997
auto I = Defs.find(Name);
19981998
return I == Defs.end() ? nullptr : I->second.get();
19991999
}
20002000

20012001
/// Get the \p Init value of the specified global variable.
20022002
Init *getGlobal(StringRef Name) const {
2003-
if (Record *R = getDef(Name))
2003+
if (const Record *R = getDef(Name))
20042004
return R->getDefInit();
20052005
auto It = ExtraGlobals.find(Name);
20062006
return It == ExtraGlobals.end() ? nullptr : It->second;

llvm/lib/TableGen/Record.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
871871

872872
} else if (isa<RecordRecTy>(getType())) {
873873
if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
874-
Record *D = RK.getDef(Name->getValue());
874+
const Record *D = RK.getDef(Name->getValue());
875875
if (!D && CurRec) {
876876
// Self-references are allowed, but their resolution is delayed until
877877
// the final resolve to ensure that we get the correct type for them.
@@ -2113,7 +2113,7 @@ Init *ExistsOpInit::Fold(Record *CurRec, bool IsFinal) const {
21132113
if (StringInit *Name = dyn_cast<StringInit>(Expr)) {
21142114

21152115
// Look up all defined records to see if we can find one.
2116-
Record *D = CheckType->getRecordKeeper().getDef(Name->getValue());
2116+
const Record *D = CheckType->getRecordKeeper().getDef(Name->getValue());
21172117
if (D) {
21182118
// Check if types are compatible.
21192119
return IntInit::get(getRecordKeeper(),

llvm/lib/TableGen/SetTheory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct SequenceOp : public SetTheory::Operator {
222222
std::string Name;
223223
raw_string_ostream OS(Name);
224224
OS << format(Format.c_str(), unsigned(From));
225-
Record *Rec = Records.getDef(Name);
225+
const Record *Rec = Records.getDef(Name);
226226
if (!Rec)
227227
PrintFatalError(Loc, "No def named '" + Name + "': " +
228228
Expr->getAsString());

llvm/lib/TableGen/TGParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ bool TGParser::resolve(const std::vector<RecordsEntry> &Source,
541541
/// Resolve the record fully and add it to the record keeper.
542542
bool TGParser::addDefOne(std::unique_ptr<Record> Rec) {
543543
Init *NewName = nullptr;
544-
if (Record *Prev = Records.getDef(Rec->getNameInitAsString())) {
544+
if (const Record *Prev = Records.getDef(Rec->getNameInitAsString())) {
545545
if (!Rec->isAnonymous()) {
546546
PrintError(Rec->getLoc(),
547547
"def already exists: " + Rec->getNameInitAsString());
@@ -1108,7 +1108,7 @@ const RecTy *TGParser::ParseType() {
11081108
Lex.Lex();
11091109
return I->second;
11101110
}
1111-
if (Record *R = ParseClassID())
1111+
if (const Record *R = ParseClassID())
11121112
return RecordRecTy::get(R);
11131113
TokError("unknown class name");
11141114
return nullptr;

llvm/unittests/TableGen/ParserEntryPointTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TEST(Parser, SanityTest) {
3333
bool ProcessResult = TableGenParseFile(SrcMgr, Records);
3434
EXPECT_FALSE(ProcessResult);
3535

36-
Record *Foo = Records.getDef("Foo");
36+
const Record *Foo = Records.getDef("Foo");
3737
std::optional<StringRef> Field = Foo->getValueAsOptionalString("strField");
3838
EXPECT_TRUE(Field.has_value());
3939
EXPECT_EQ(*Field, "value");

llvm/utils/TableGen/Common/CodeGenSchedule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ void CodeGenSchedModels::collectProcModels() {
532532
ProcModels.reserve(ProcRecords.size() + 1);
533533

534534
// Use idx=0 for NoModel/NoItineraries.
535-
Record *NoModelDef = Records.getDef("NoSchedModel");
536-
Record *NoItinsDef = Records.getDef("NoItineraries");
535+
const Record *NoModelDef = Records.getDef("NoSchedModel");
536+
const Record *NoItinsDef = Records.getDef("NoItineraries");
537537
ProcModels.emplace_back(0, "NoSchedModel", NoModelDef, NoItinsDef);
538538
ProcModelMap[NoModelDef] = 0;
539539

0 commit comments

Comments
 (0)