[llvm] [NFC] clang-format llvm/include/llvm/Support/Registry.h (PR #173295)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 22 10:39:15 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Balázs Benics (steakhal)
<details>
<summary>Changes</summary>
This is in preparation of #<!-- -->173290.
---
Full diff: https://github.com/llvm/llvm-project/pull/173295.diff
1 Files Affected:
- (modified) llvm/include/llvm/Support/Registry.h (+100-100)
``````````diff
diff --git a/llvm/include/llvm/Support/Registry.h b/llvm/include/llvm/Support/Registry.h
index acd3b06fde6e7..01f785a8fd633 100644
--- a/llvm/include/llvm/Support/Registry.h
+++ b/llvm/include/llvm/Support/Registry.h
@@ -21,121 +21,121 @@
#include <memory>
namespace llvm {
- /// A simple registry entry which provides only a name, description, and
- /// no-argument constructor.
- template <typename T>
- class SimpleRegistryEntry {
- StringRef Name, Desc;
- std::unique_ptr<T> (*Ctor)();
+/// A simple registry entry which provides only a name, description, and
+/// no-argument constructor.
+template <typename T> class SimpleRegistryEntry {
+ StringRef Name, Desc;
+ std::unique_ptr<T> (*Ctor)();
+
+public:
+ SimpleRegistryEntry(StringRef N, StringRef D, std::unique_ptr<T> (*C)())
+ : Name(N), Desc(D), Ctor(C) {}
+
+ StringRef getName() const { return Name; }
+ StringRef getDesc() const { return Desc; }
+ std::unique_ptr<T> instantiate() const { return Ctor(); }
+};
+
+/// A global registry used in conjunction with static constructors to make
+/// pluggable components (like targets or garbage collectors) "just work" when
+/// linked with an executable.
+template <typename T> class Registry {
+public:
+ using type = T;
+ using entry = SimpleRegistryEntry<T>;
+
+ class node;
+ class iterator;
+
+private:
+ Registry() = delete;
+
+ friend class node;
+ // These must be must two separate declarations to workaround a 20 year
+ // old MSVC bug with dllexport and multiple static fields in the same
+ // declaration causing error C2487 "member of dll interface class may not
+ // be declared with dll interface".
+ // https://developercommunity.visualstudio.com/t/c2487-in-dllexport-class-with-static-members/69878
+ static inline node *Head = nullptr;
+ static inline node *Tail = nullptr;
+
+public:
+ /// Node in linked list of entries.
+ ///
+ class node {
+ friend class iterator;
+ friend Registry<T>;
+
+ node *Next;
+ const entry &Val;
public:
- SimpleRegistryEntry(StringRef N, StringRef D, std::unique_ptr<T> (*C)())
- : Name(N), Desc(D), Ctor(C) {}
-
- StringRef getName() const { return Name; }
- StringRef getDesc() const { return Desc; }
- std::unique_ptr<T> instantiate() const { return Ctor(); }
+ node(const entry &V) : Next(nullptr), Val(V) {}
};
- /// A global registry used in conjunction with static constructors to make
- /// pluggable components (like targets or garbage collectors) "just work" when
- /// linked with an executable.
- template <typename T>
- class Registry {
- public:
- using type = T;
- using entry = SimpleRegistryEntry<T>;
-
- class node;
- class iterator;
-
- private:
- Registry() = delete;
+ /// Add a node to the Registry: this is the interface between the plugin and
+ /// the executable.
+ ///
+ /// This function is exported by the executable and called by the plugin to
+ /// add a node to the executable's registry. Therefore it's not defined here
+ /// to avoid it being instantiated in the plugin and is instead defined in
+ /// the executable (see LLVM_INSTANTIATE_REGISTRY below).
+ static void add_node(node *N) {
+ if (Tail)
+ Tail->Next = N;
+ else
+ Head = N;
+ Tail = N;
+ }
- friend class node;
- // These must be must two separate declarations to workaround a 20 year
- // old MSVC bug with dllexport and multiple static fields in the same
- // declaration causing error C2487 "member of dll interface class may not
- // be declared with dll interface".
- // https://developercommunity.visualstudio.com/t/c2487-in-dllexport-class-with-static-members/69878
- static inline node *Head = nullptr;
- static inline node *Tail = nullptr;
+ /// Iterators for registry entries.
+ ///
+ class iterator
+ : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
+ const entry> {
+ const node *Cur;
public:
- /// Node in linked list of entries.
- ///
- class node {
- friend class iterator;
- friend Registry<T>;
-
- node *Next;
- const entry& Val;
-
- public:
- node(const entry &V) : Next(nullptr), Val(V) {}
- };
-
- /// Add a node to the Registry: this is the interface between the plugin and
- /// the executable.
- ///
- /// This function is exported by the executable and called by the plugin to
- /// add a node to the executable's registry. Therefore it's not defined here
- /// to avoid it being instantiated in the plugin and is instead defined in
- /// the executable (see LLVM_INSTANTIATE_REGISTRY below).
- static void add_node(node *N) {
- if (Tail)
- Tail->Next = N;
- else
- Head = N;
- Tail = N;
+ explicit iterator(const node *N) : Cur(N) {}
+
+ bool operator==(const iterator &That) const { return Cur == That.Cur; }
+ iterator &operator++() {
+ Cur = Cur->Next;
+ return *this;
}
+ const entry &operator*() const { return Cur->Val; }
+ };
- /// Iterators for registry entries.
- ///
- class iterator
- : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
- const entry> {
- const node *Cur;
+ // begin is not defined here in order to avoid usage of an undefined static
+ // data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
+ static iterator begin() { return iterator(Head); }
+ static iterator end() { return iterator(nullptr); }
- public:
- explicit iterator(const node *N) : Cur(N) {}
+ static iterator_range<iterator> entries() {
+ return make_range(begin(), end());
+ }
- bool operator==(const iterator &That) const { return Cur == That.Cur; }
- iterator &operator++() { Cur = Cur->Next; return *this; }
- const entry &operator*() const { return Cur->Val; }
- };
+ /// A static registration template. Use like such:
+ ///
+ /// Registry<Collector>::Add<FancyGC>
+ /// X("fancy-gc", "Newfangled garbage collector.");
+ ///
+ /// Use of this template requires that:
+ ///
+ /// 1. The registered subclass has a default constructor.
+ template <typename V> class Add {
+ entry Entry;
+ node Node;
- // begin is not defined here in order to avoid usage of an undefined static
- // data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
- static iterator begin() { return iterator(Head); }
- static iterator end() { return iterator(nullptr); }
+ static std::unique_ptr<T> CtorFn() { return std::make_unique<V>(); }
- static iterator_range<iterator> entries() {
- return make_range(begin(), end());
+ public:
+ Add(StringRef Name, StringRef Desc)
+ : Entry(Name, Desc, CtorFn), Node(Entry) {
+ add_node(&Node);
}
-
- /// A static registration template. Use like such:
- ///
- /// Registry<Collector>::Add<FancyGC>
- /// X("fancy-gc", "Newfangled garbage collector.");
- ///
- /// Use of this template requires that:
- ///
- /// 1. The registered subclass has a default constructor.
- template <typename V>
- class Add {
- entry Entry;
- node Node;
-
- static std::unique_ptr<T> CtorFn() { return std::make_unique<V>(); }
-
- public:
- Add(StringRef Name, StringRef Desc)
- : Entry(Name, Desc, CtorFn), Node(Entry) {
- add_node(&Node);
- }
- };
};
+};
} // end namespace llvm
``````````
</details>
https://github.com/llvm/llvm-project/pull/173295
More information about the llvm-commits
mailing list