Skip to content

Commit

Permalink
Proper one-time initialization in OpSet::get<OpTs...>()
Browse files Browse the repository at this point in the history
Also return a reference to the static variable to avoid a copy on return.
  • Loading branch information
nhaehnle committed Feb 2, 2024
1 parent 3f9e17f commit c82337d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions include/llvm-dialects/Dialect/OpSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ class OpSet final {

// Construct an OpSet from a set of dialect ops, given as template
// arguments.
template <typename... OpTs> static const OpSet get() {
static OpSet set;
(... && appendT<OpTs>(set));
template <typename... OpTs> static const OpSet &get() {
static const auto set = ([]() {
OpSet set;
(void)(... && ([&set]() {
set.tryInsertOp(OpDescription::get<OpTs>());
return true;
})());
return set;
})();
return set;
}

Expand Down Expand Up @@ -169,15 +175,6 @@ class OpSet final {
}

private:
// Generates an `OpDescription` for a given `OpT`, extracts the
// internal operation representation and collects it in the set.
template <typename OpT> static bool appendT(OpSet &set) {
static OpDescription desc = OpDescription::get<OpT>();
set.tryInsertOp(desc);

return true;
}

// Checks if `mnemonic` can be described by any of the stored dialect
// operations.
bool isMatchingDialectOp(llvm::StringRef mnemonic) const {
Expand Down

0 comments on commit c82337d

Please sign in to comment.