14#ifndef LLVM_ADT_IMMUTABLEMAP_H
15#define LLVM_ADT_IMMUTABLEMAP_H
27template <
typename T,
typename S>
61template <
typename KeyT,
typename ValT,
62 typename ValInfo = ImutKeyValueInfo<KeyT, ValT>,
63 bool Canonicalize =
true>
99 TreeTy *
T = F.add(Old.
Root.get(), std::pair<key_type, data_type>(K,
D));
100 if constexpr (Canonicalize)
117 template <
typename CombineFn>
119 CombineFn
Combine,
bool KeepUnmatched,
120 bool SkipShared =
false) {
121 static_assert(!Canonicalize,
122 "mergeWith does not canonicalize the nodes it creates");
124 KeepUnmatched, SkipShared));
129 if constexpr (Canonicalize)
141 return Root ?
Root->contains(K) :
false;
149 if constexpr (Canonicalize)
157 if constexpr (Canonicalize)
195 iterator() =
default;
209 if (
T)
return &
T->getValue().second;
227 return Root ?
Root->getHeight() : 0;
231 ID.AddPointer(M.Root.get());
240template <
typename KeyT,
typename ValT,
241typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
267 :
Root(
X.getRootWithoutRetain()),
Factory(
F.getTreeFactory()) {}
283 Factory->add(
Root.get(), std::pair<key_type, data_type>(K,
D));
293 return Root ?
Root->contains(K) :
false;
327 iterator() =
default;
341 if (
T)
return &
T->getValue().second;
359 return Root ?
Root->getHeight() : 0;
363 ID.AddPointer(M.Root.get());
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines a hash set that can be used to remove duplication of nodes in a graph.
This file defines the ImutAVLTree and ImmutableSet classes.
static constexpr Value * getValue(Ty &ValueOrUse)
This class is used to gather all the unique data bits of a node.
key_type_ref getKey() const
data_type_ref getData() const
friend class ImmutableMapRef
unsigned getHeight() const
ImmutableMap< KeyT, ValT > asImmutableMap() const
static ImmutableMapRef getEmptyMap(FactoryTy *F)
void Profile(FoldingSetNodeID &ID) const
bool operator!=(const ImmutableMapRef &RHS) const
bool contains(key_type_ref K) const
static void Profile(FoldingSetNodeID &ID, const ImmutableMapRef &M)
typename ValInfo::data_type data_type
typename ValInfo::data_type_ref data_type_ref
typename ValInfo::key_type key_type
IntrusiveRefCntPtr< TreeTy > Root
ImutAVLTree< ValInfo > TreeTy
typename ValInfo::value_type_ref value_type_ref
bool operator==(const ImmutableMapRef &RHS) const
ImmutableMapRef remove(key_type_ref K) const
typename ValInfo::key_type_ref key_type_ref
value_type * getMaxElement() const
Returns the <key,value> pair in the ImmutableMap for which key is the highest in the ordering of keys...
ImmutableMapRef add(key_type_ref K, data_type_ref D) const
typename ValInfo::value_type value_type
ImmutableMapRef(const TreeTy *R, FactoryTy *F)
Constructs a map from a pointer to a tree root.
data_type * lookup(key_type_ref K) const
ImmutableMapRef(const ImmutableMap< KeyT, ValT > &X, typename ImmutableMap< KeyT, ValT >::Factory &F)
typename TreeTy::Factory FactoryTy
TreeTy::Factory * getTreeFactory() const
ImmutableMap getEmptyMap()
ImmutableMap remove(ImmutableMap Old, key_type_ref K)
Factory(BumpPtrAllocator &Alloc)
Factory & operator=(const Factory &)=delete
ImmutableMap mergeWith(ImmutableMap A, ImmutableMap B, CombineFn Combine, bool KeepUnmatched, bool SkipShared=false)
Merges A and B in a single traversal (see ImutAVLFactory::mergeTrees), sharing subtrees the two maps ...
ImmutableMap add(ImmutableMap Old, key_type_ref K, data_type_ref D)
Factory(const Factory &)=delete
key_type_ref getKey() const
data_type_ref getData() const
friend class ImmutableMap
typename ValInfo::data_type_ref data_type_ref
TreeTy * getRootWithoutRetain() const
typename ValInfo::key_type_ref key_type_ref
typename ValInfo::value_type_ref value_type_ref
value_type * getMaxElement() const
Returns the <key,value> pair in the ImmutableMap for which key is the highest in the ordering of keys...
typename ValInfo::key_type key_type
typename ValInfo::value_type value_type
typename ValInfo::data_type data_type
void Profile(FoldingSetNodeID &ID) const
bool operator!=(const ImmutableMap &RHS) const
ImmutableMap(const TreeTy *R)
Constructs a map from a pointer to a tree root.
bool contains(key_type_ref K) const
unsigned getHeight() const
data_type * lookup(key_type_ref K) const
IntrusiveRefCntPtr< TreeTy > Root
bool operator==(const ImmutableMap &RHS) const
Compares two maps for equality.
ImutAVLTree< ValInfo, Canonicalize > TreeTy
static void Profile(FoldingSetNodeID &ID, const ImmutableMap &M)
ImutAVLFactory< ValInfo, Canonicalize > Factory
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
ImutAVLValueIterator()=default
static bool isLess(key_type_ref LHS, key_type_ref RHS)
static bool isEqual(key_type_ref LHS, key_type_ref RHS)
Traits class used by ImmutableMap.
const value_type & value_type_ref
static void Profile(FoldingSetNodeID &ID, value_type_ref V)
static bool isLess(key_type_ref L, key_type_ref R)
static key_type_ref KeyOfValue(value_type_ref V)
const std::pair< T, S > value_type
static data_type_ref DataOfValue(value_type_ref V)
static bool isDataEqual(data_type_ref L, data_type_ref R)
static bool isEqual(key_type_ref L, key_type_ref R)
static void Profile(FoldingSetNodeID &ID, value_type_ref X)