LLVM  15.0.0git
Classes | Namespaces | Functions
IntrusiveRefCntPtr.h File Reference
#include <atomic>
#include <cassert>
#include <cstddef>
#include <memory>
Include dependency graph for IntrusiveRefCntPtr.h:
This graph shows which files directly or indirectly include this file:

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< From >
 Define a template that can be specialized by smart pointers to reflect the fact that they are automatically dereferenced, and are not involved with the template selection process... More...
 
struct  llvm::simplify_type< IntrusiveRefCntPtr< T > >
 
struct  llvm::simplify_type< const IntrusiveRefCntPtr< T > >
 

Namespaces

 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. More...
 

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.
}

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

IntrusiveRefCntPtr works with any class that

Definition in file IntrusiveRefCntPtr.h.

foo
< i32 > tmp foo
Definition: README.txt:383
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1237