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

Proper one-time initialization in OpSet::get<OpTs...>() #87

Merged
merged 1 commit into from
Feb 2, 2024
Merged
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
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
Loading