//===-- SymbolStringPool.h -- Thread-safe pool for JIT symbols --*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Contains a thread-safe string pool suitable for use with ORC. // //===----------------------------------------------------------------------===// #ifndef LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H #define LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringMap.h" #include <atomic> #include <mutex> namespace llvm { class raw_ostream; namespace orc { class SymbolStringPtrBase; class SymbolStringPtr; class NonOwningSymbolStringPtr; /// String pool for symbol names used by the JIT. class SymbolStringPool { … }; /// Base class for both owning and non-owning symbol-string ptrs. /// /// All symbol-string ptrs are convertible to bool, dereferenceable and /// comparable. /// /// SymbolStringPtrBases are default-constructible and constructible /// from nullptr to enable comparison with these values. class SymbolStringPtrBase { … }; /// Pointer to a pooled string representing a symbol name. class SymbolStringPtr : public SymbolStringPtrBase { … }; /// Provides unsafe access to ownership operations on SymbolStringPtr. /// This class can be used to manage SymbolStringPtr instances from C. class SymbolStringPoolEntryUnsafe { … }; /// Non-owning SymbolStringPool entry pointer. Instances are comparable with /// SymbolStringPtr instances and guaranteed to have the same hash, but do not /// affect the ref-count of the pooled string (and are therefore cheaper to /// copy). /// /// NonOwningSymbolStringPtrs are silently invalidated if the pool entry's /// ref-count drops to zero, so they should only be used in contexts where a /// corresponding SymbolStringPtr is known to exist (which will guarantee that /// the ref-count stays above zero). E.g. in a graph where nodes are /// represented by SymbolStringPtrs the edges can be represented by pairs of /// NonOwningSymbolStringPtrs and this will make the introduction of deletion /// of edges cheaper. class NonOwningSymbolStringPtr : public SymbolStringPtrBase { … }; inline SymbolStringPtr::SymbolStringPtr(NonOwningSymbolStringPtr Other) : … { … } inline SymbolStringPool::~SymbolStringPool() { … } inline SymbolStringPtr SymbolStringPool::intern(StringRef S) { … } inline void SymbolStringPool::clearDeadEntries() { … } inline bool SymbolStringPool::empty() const { … } inline size_t SymbolStringPool::getRefCount(const SymbolStringPtrBase &S) const { … } } // end namespace orc template <> struct DenseMapInfo<orc::SymbolStringPtr> { … }; template <> struct DenseMapInfo<orc::NonOwningSymbolStringPtr> { … }; } // end namespace llvm #endif // LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H