From 0d6ea008be0e5ad4d824e318726dfd6b048abf2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Date: Fri, 2 Feb 2024 03:08:30 +0100 Subject: [PATCH] Proper one-time initialization in OpSet::get() Also return a reference to the static variable to avoid a copy on return. --- include/llvm-dialects/Dialect/OpSet.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/include/llvm-dialects/Dialect/OpSet.h b/include/llvm-dialects/Dialect/OpSet.h index 6f39599..3bb0b3e 100644 --- a/include/llvm-dialects/Dialect/OpSet.h +++ b/include/llvm-dialects/Dialect/OpSet.h @@ -89,9 +89,15 @@ class OpSet final { // Construct an OpSet from a set of dialect ops, given as template // arguments. - template static const OpSet get() { - static OpSet set; - (... && appendT(set)); + template static const OpSet &get() { + static const auto set = ([]() { + OpSet set; + (void)(... && ([&set]() { + set.tryInsertOp(OpDescription::get()); + return true; + })()); + return set; + })(); return set; } @@ -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 static bool appendT(OpSet &set) { - static OpDescription desc = OpDescription::get(); - set.tryInsertOp(desc); - - return true; - } - // Checks if `mnemonic` can be described by any of the stored dialect // operations. bool isMatchingDialectOp(llvm::StringRef mnemonic) const {