Skip to content

Commit 00ebf33

Browse files
committed
[TableGen] Change callback function to require const RecordKeeper
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.
1 parent 428ae0f commit 00ebf33

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
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 = 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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,6 @@ using namespace TableGen::Emitter;
2525

2626
const size_t MAX_LINE_LEN = 80U;
2727

28-
// CommandLine options of class type are not directly supported with some
29-
// specific exceptions like std::string which are safe to copy. In our case,
30-
// the `FnT` function_ref object is also safe to copy. So provide a
31-
// specialization of `OptionValue` for `FnT` type that stores it as a copy.
32-
// This is essentially similar to OptionValue<std::string> specialization for
33-
// strings.
34-
template <> struct cl::OptionValue<FnT> final : cl::OptionValueCopy<FnT> {
35-
OptionValue() = default;
36-
37-
OptionValue(const FnT &V) { this->setValue(V); }
38-
39-
OptionValue<FnT> &operator=(const FnT &V) {
40-
setValue(V);
41-
return *this;
42-
}
43-
};
44-
4528
namespace {
4629
struct OptCreatorT {
4730
static void *call() {
@@ -60,7 +43,7 @@ Opt::Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault) {
6043

6144
/// Apply callback specified on the command line. Returns true if no callback
6245
/// was applied.
63-
bool llvm::TableGen::Emitter::ApplyCallback(RecordKeeper &Records,
46+
bool llvm::TableGen::Emitter::ApplyCallback(const RecordKeeper &Records,
6447
raw_ostream &OS) {
6548
FnT Fn = CallbackFunction->getValue();
6649
if (!Fn)

0 commit comments

Comments
 (0)