LLVM 20.0.0git
Classes | Namespaces | Functions
IntrusiveRefCntPtr.h File Reference

This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes. More...

#include <atomic>
#include <cassert>
#include <cstddef>
#include <memory>

Go to the source code of this file.

Classes

class  llvm::RefCountedBase< Derived >
 A CRTP mixin class that adds reference counting to a type. More...
 
class  llvm::ThreadSafeRefCountedBase< Derived >
 A thread-safe version of RefCountedBase. More...
 
struct  llvm::IntrusiveRefCntPtrInfo< T >
 Class you can specialize to provide custom retain/release functionality for a type. More...
 
class  llvm::IntrusiveRefCntPtr< T >
 A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCountedBase. More...
 
struct  llvm::simplify_type< IntrusiveRefCntPtr< T > >
 
struct  llvm::simplify_type< const IntrusiveRefCntPtr< T > >
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Functions

template<class T , class U >
bool llvm::operator== (const IntrusiveRefCntPtr< T > &A, const IntrusiveRefCntPtr< U > &B)
 
template<class T , class U >
bool llvm::operator!= (const IntrusiveRefCntPtr< T > &A, const IntrusiveRefCntPtr< U > &B)
 
template<class T , class U >
bool llvm::operator== (const IntrusiveRefCntPtr< T > &A, U *B)
 
template<class T , class U >
bool llvm::operator!= (const IntrusiveRefCntPtr< T > &A, U *B)
 
template<class T , class U >
bool llvm::operator== (T *A, const IntrusiveRefCntPtr< U > &B)
 
template<class T , class U >
bool llvm::operator!= (T *A, const IntrusiveRefCntPtr< U > &B)
 
template<class T >
bool llvm::operator== (std::nullptr_t, const IntrusiveRefCntPtr< T > &B)
 
template<class T >
bool llvm::operator== (const IntrusiveRefCntPtr< T > &A, std::nullptr_t B)
 
template<class T >
bool llvm::operator!= (std::nullptr_t A, const IntrusiveRefCntPtr< T > &B)
 
template<class T >
bool llvm::operator!= (const IntrusiveRefCntPtr< T > &A, std::nullptr_t B)
 
template<typename T , typename... Args>
IntrusiveRefCntPtr< Tllvm::makeIntrusiveRefCnt (Args &&...A)
 Factory function for creating intrusive ref counted pointers.
 

Detailed Description

This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.

IntrusiveRefCntPtr is a smart pointer to an object which maintains a reference count. (ThreadSafe)RefCountedBase is a mixin class that adds a refcount member variable and methods for updating the refcount. An object that inherits from (ThreadSafe)RefCountedBase deletes itself when its refcount hits zero.

For example:

class MyClass : public RefCountedBase<MyClass> {};
void foo() {
// Constructing an IntrusiveRefCntPtr increases the pointee's refcount
// by 1 (from 0 in this case).
IntrusiveRefCntPtr<MyClass> Ptr1(new MyClass());
// Copying an IntrusiveRefCntPtr increases the pointee's refcount by 1.
IntrusiveRefCntPtr<MyClass> Ptr2(Ptr1);
// Constructing an IntrusiveRefCntPtr has no effect on the object's
// refcount. After a move, the moved-from pointer is null.
IntrusiveRefCntPtr<MyClass> Ptr3(std::move(Ptr1));
assert(Ptr1 == nullptr);
// Clearing an IntrusiveRefCntPtr decreases the pointee's refcount by 1.
Ptr2.reset();
// The object deletes itself when we return from the function, because
// Ptr3's destructor decrements its refcount to 0.
}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

You can use IntrusiveRefCntPtr with isa<T>(), dyn_cast<T>(), etc.:

IntrusiveRefCntPtr<MyClass> Ptr(new MyClass());
OtherClass *Other = dyn_cast<OtherClass>(Ptr); // Ptr.get() not required
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1309

IntrusiveRefCntPtr works with any class that

Definition in file IntrusiveRefCntPtr.h.