[llvm] [OpenMP] Implement EnumSet container (PR #211323)

Tom Eccles via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 07:50:09 PDT 2026


================
@@ -17,11 +17,118 @@
 #include "llvm/Support/Compiler.h"
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Bitset.h"
 #include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace llvm::omp {
+template <typename Enum, size_t Size> struct EnumSet;
+
+namespace detail {
+template <size_t Size>
+static constexpr inline size_t findFirstSet(size_t Begin, size_t End,
+                                            const llvm::Bitset<Size> &Set) {
+  unsigned FirstWord = Begin / 64;
+  unsigned LastWord = End / 64;
+
+  for (unsigned I = FirstWord; I <= LastWord; ++I) {
+    uint64_t Word = Set.getWord64(I);
+    if (I == FirstWord && Begin % 64 != 0) {
+      Word &= ~uint64_t() << (Begin % 64);
+    }
+    auto Count = static_cast<unsigned>(llvm::countr_zero_constexpr(Word));
+    if (Count < 64) {
+      unsigned Idx = I * 64 + Count;
+      if (Idx >= Begin && Idx < End)
+        return Idx;
+    }
+  }
+  return Size;
+}
+
+template <typename Enum, size_t Size> struct EnumSetIterator {
----------------
tblah wrote:

Codex tells me that a C++17 LegacyForwardIterator would need to be copy assignable and have an `iterator_category` for `std::iterator_traits`. It says this breaks functions like `std::distance` (verified by reproducer).

Not supporting the whole of LegacyForwardIterator is fine by me so long as this does everything you need it to. I just wanted to flag it in case you intended for these to work (it seemed so from the PR description).

https://github.com/llvm/llvm-project/pull/211323


More information about the llvm-commits mailing list