Skip to content

Commit b91f0de

Browse files
authored
[TableGen] Change backend callback to require const RecordKeeper (#111064)
Change TableGen backend callback function to require a const RecordKeeper argument (by changing it from function_ref to just a function pointer). This undoes parts of #104716 which was added to enable gradual migration of TableGen backends to use const RecordKeeper (by allowing either const or non-const references). Now that all backends have been migrated to const reference, we do not need this. 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 d883ef1 commit b91f0de

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/include/llvm/TableGen/TableGenBackend.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class RecordKeeper;
2323
class raw_ostream;
2424

2525
namespace TableGen::Emitter {
26-
// Supports const and non-const forms of callback functions.
27-
using FnT = function_ref<void(RecordKeeper &Records, raw_ostream &OS)>;
26+
using FnT = function_ref<void(const RecordKeeper &Records, raw_ostream &OS)>;
2827

2928
/// Creating an `Opt` object registers the command line option \p Name with
3029
/// TableGen backend and associates the callback \p CB with that option. If
@@ -37,15 +36,17 @@ struct Opt {
3736
/// Convienence wrapper around `Opt` that registers `EmitterClass::run` as the
3837
/// callback.
3938
template <class EmitterC> class OptClass : Opt {
40-
static void run(RecordKeeper &RK, raw_ostream &OS) { EmitterC(RK).run(OS); }
39+
static void run(const RecordKeeper &RK, raw_ostream &OS) {
40+
EmitterC(RK).run(OS);
41+
}
4142

4243
public:
4344
OptClass(StringRef Name, StringRef Desc) : Opt(Name, run, Desc) {}
4445
};
4546

4647
/// Apply callback for any command line option registered above. Returns false
4748
/// is no callback was applied.
48-
bool ApplyCallback(RecordKeeper &Records, raw_ostream &OS);
49+
bool ApplyCallback(const RecordKeeper &Records, raw_ostream &OS);
4950

5051
} // namespace TableGen::Emitter
5152

llvm/lib/TableGen/TableGenBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Opt::Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault) {
6060

6161
/// Apply callback specified on the command line. Returns true if no callback
6262
/// was applied.
63-
bool llvm::TableGen::Emitter::ApplyCallback(RecordKeeper &Records,
63+
bool llvm::TableGen::Emitter::ApplyCallback(const RecordKeeper &Records,
6464
raw_ostream &OS) {
6565
FnT Fn = CallbackFunction->getValue();
6666
if (!Fn)

0 commit comments

Comments
 (0)