003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/include/llvm/ADT
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
include
/
llvm
/
ADT
/
📁
..
📄
APFloat.h
(48.83 KB)
📄
APInt.h
(74.48 KB)
📄
APSInt.h
(11.75 KB)
📄
AllocatorList.h
(7.53 KB)
📄
Any.h
(5.05 KB)
📄
ArrayRef.h
(17.92 KB)
📄
BitVector.h
(29.74 KB)
📄
Bitfields.h
(11.65 KB)
📄
BitmaskEnum.h
(5.53 KB)
📄
BreadthFirstIterator.h
(4.82 KB)
📄
CachedHashString.h
(5.9 KB)
📄
CoalescingBitVector.h
(14.91 KB)
📄
DAGDeltaAlgorithm.h
(3.13 KB)
📄
DeltaAlgorithm.h
(3.54 KB)
📄
DenseMap.h
(43.14 KB)
📄
DenseMapInfo.h
(11.4 KB)
📄
DenseSet.h
(9.33 KB)
📄
DepthFirstIterator.h
(10.37 KB)
📄
DirectedGraph.h
(9.56 KB)
📄
EnumeratedArray.h
(1.6 KB)
📄
EpochTracker.h
(3.2 KB)
📄
EquivalenceClasses.h
(10.52 KB)
📄
FloatingPointMode.h
(5.62 KB)
📄
FoldingSet.h
(30.16 KB)
📄
FunctionExtras.h
(14.55 KB)
📄
GraphTraits.h
(5.71 KB)
📄
Hashing.h
(25.12 KB)
📄
ImmutableList.h
(7.57 KB)
📄
ImmutableMap.h
(10.84 KB)
📄
ImmutableSet.h
(37.52 KB)
📄
IndexedMap.h
(2.5 KB)
📄
IntEqClasses.h
(2.87 KB)
📄
IntervalMap.h
(72.88 KB)
📄
IntrusiveRefCntPtr.h
(8.1 KB)
📄
MapVector.h
(7.79 KB)
📄
None.h
(983 B)
📄
Optional.h
(10.82 KB)
📄
PackedVector.h
(4.17 KB)
📄
PointerEmbeddedInt.h
(4.05 KB)
📄
PointerIntPair.h
(8.72 KB)
📄
PointerSumType.h
(11.61 KB)
📄
PointerUnion.h
(10.17 KB)
📄
PostOrderIterator.h
(11.05 KB)
📄
PriorityQueue.h
(2.69 KB)
📄
PriorityWorklist.h
(8.11 KB)
📄
SCCIterator.h
(8.02 KB)
📄
STLExtras.h
(70.56 KB)
📄
ScopeExit.h
(1.83 KB)
📄
ScopedHashTable.h
(8.27 KB)
📄
Sequence.h
(2.59 KB)
📄
SetOperations.h
(2.58 KB)
📄
SetVector.h
(9.39 KB)
📄
SmallBitVector.h
(20.36 KB)
📄
SmallPtrSet.h
(16.93 KB)
📄
SmallSet.h
(8.37 KB)
📄
SmallString.h
(8.55 KB)
📄
SmallVector.h
(32.33 KB)
📄
SparseBitVector.h
(26.2 KB)
📄
SparseMultiSet.h
(17.83 KB)
📄
SparseSet.h
(11.41 KB)
📄
Statistic.h
(7.01 KB)
📄
StringExtras.h
(13.25 KB)
📄
StringMap.h
(15.7 KB)
📄
StringMapEntry.h
(4.83 KB)
📄
StringRef.h
(31.68 KB)
📄
StringSet.h
(1.51 KB)
📄
StringSwitch.h
(6.25 KB)
📄
TinyPtrVector.h
(10.19 KB)
📄
Triple.h
(27.4 KB)
📄
Twine.h
(17.48 KB)
📄
TypeSwitch.h
(5.82 KB)
📄
UniqueVector.h
(3.09 KB)
📄
Waymarking.h
(11.96 KB)
📄
bit.h
(2.26 KB)
📄
edit_distance.h
(3.57 KB)
📄
fallible_iterator.h
(8.31 KB)
📄
ilist.h
(13.68 KB)
📄
ilist_base.h
(2.72 KB)
📄
ilist_iterator.h
(7.21 KB)
📄
ilist_node.h
(9.84 KB)
📄
ilist_node_base.h
(1.7 KB)
📄
ilist_node_options.h
(5.07 KB)
📄
iterator.h
(13.46 KB)
📄
iterator_range.h
(2.22 KB)
📄
simple_ilist.h
(10.78 KB)
Editing: ScopedHashTable.h
//===- ScopedHashTable.h - A simple scoped hash table -----------*- 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 // //===----------------------------------------------------------------------===// // // This file implements an efficient scoped hash table, which is useful for // things like dominator-based optimizations. This allows clients to do things // like this: // // ScopedHashTable<int, int> HT; // { // ScopedHashTableScope<int, int> Scope1(HT); // HT.insert(0, 0); // HT.insert(1, 1); // { // ScopedHashTableScope<int, int> Scope2(HT); // HT.insert(0, 42); // } // } // // Looking up the value for "0" in the Scope2 block will return 42. Looking // up the value for 0 before 42 is inserted or after Scope2 is popped will // return 0. // //===----------------------------------------------------------------------===// #ifndef LLVM_ADT_SCOPEDHASHTABLE_H #define LLVM_ADT_SCOPEDHASHTABLE_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/Support/AllocatorBase.h" #include <cassert> #include <new> namespace llvm { template <typename K, typename V, typename KInfo = DenseMapInfo<K>, typename AllocatorTy = MallocAllocator> class ScopedHashTable; template <typename K, typename V> class ScopedHashTableVal { ScopedHashTableVal *NextInScope; ScopedHashTableVal *NextForKey; K Key; V Val; ScopedHashTableVal(const K &key, const V &val) : Key(key), Val(val) {} public: const K &getKey() const { return Key; } const V &getValue() const { return Val; } V &getValue() { return Val; } ScopedHashTableVal *getNextForKey() { return NextForKey; } const ScopedHashTableVal *getNextForKey() const { return NextForKey; } ScopedHashTableVal *getNextInScope() { return NextInScope; } template <typename AllocatorTy> static ScopedHashTableVal *Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator) { ScopedHashTableVal *New = Allocator.template Allocate<ScopedHashTableVal>(); // Set up the value. new (New) ScopedHashTableVal(key, val); New->NextInScope = nextInScope; New->NextForKey = nextForKey; return New; } template <typename AllocatorTy> void Destroy(AllocatorTy &Allocator) { // Free memory referenced by the item. this->~ScopedHashTableVal(); Allocator.Deallocate(this); } }; template <typename K, typename V, typename KInfo = DenseMapInfo<K>, typename AllocatorTy = MallocAllocator> class ScopedHashTableScope { /// HT - The hashtable that we are active for. ScopedHashTable<K, V, KInfo, AllocatorTy> &HT; /// PrevScope - This is the scope that we are shadowing in HT. ScopedHashTableScope *PrevScope; /// LastValInScope - This is the last value that was inserted for this scope /// or null if none have been inserted yet. ScopedHashTableVal<K, V> *LastValInScope; public: ScopedHashTableScope(ScopedHashTable<K, V, KInfo, AllocatorTy> &HT); ScopedHashTableScope(ScopedHashTableScope &) = delete; ScopedHashTableScope &operator=(ScopedHashTableScope &) = delete; ~ScopedHashTableScope(); ScopedHashTableScope *getParentScope() { return PrevScope; } const ScopedHashTableScope *getParentScope() const { return PrevScope; } private: friend class ScopedHashTable<K, V, KInfo, AllocatorTy>; ScopedHashTableVal<K, V> *getLastValInScope() { return LastValInScope; } void setLastValInScope(ScopedHashTableVal<K, V> *Val) { LastValInScope = Val; } }; template <typename K, typename V, typename KInfo = DenseMapInfo<K>> class ScopedHashTableIterator { ScopedHashTableVal<K, V> *Node; public: ScopedHashTableIterator(ScopedHashTableVal<K, V> *node) : Node(node) {} V &operator*() const { assert(Node && "Dereference end()"); return Node->getValue(); } V *operator->() const { return &Node->getValue(); } bool operator==(const ScopedHashTableIterator &RHS) const { return Node == RHS.Node; } bool operator!=(const ScopedHashTableIterator &RHS) const { return Node != RHS.Node; } inline ScopedHashTableIterator& operator++() { // Preincrement assert(Node && "incrementing past end()"); Node = Node->getNextForKey(); return *this; } ScopedHashTableIterator operator++(int) { // Postincrement ScopedHashTableIterator tmp = *this; ++*this; return tmp; } }; template <typename K, typename V, typename KInfo, typename AllocatorTy> class ScopedHashTable { public: /// ScopeTy - This is a helpful typedef that allows clients to get easy access /// to the name of the scope for this hash table. using ScopeTy = ScopedHashTableScope<K, V, KInfo, AllocatorTy>; using size_type = unsigned; private: friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>; using ValTy = ScopedHashTableVal<K, V>; DenseMap<K, ValTy*, KInfo> TopLevelMap; ScopeTy *CurScope = nullptr; AllocatorTy Allocator; public: ScopedHashTable() = default; ScopedHashTable(AllocatorTy A) : Allocator(A) {} ScopedHashTable(const ScopedHashTable &) = delete; ScopedHashTable &operator=(const ScopedHashTable &) = delete; ~ScopedHashTable() { assert(!CurScope && TopLevelMap.empty() && "Scope imbalance!"); } /// Access to the allocator. AllocatorTy &getAllocator() { return Allocator; } const AllocatorTy &getAllocator() const { return Allocator; } /// Return 1 if the specified key is in the table, 0 otherwise. size_type count(const K &Key) const { return TopLevelMap.count(Key); } V lookup(const K &Key) const { auto I = TopLevelMap.find(Key); if (I != TopLevelMap.end()) return I->second->getValue(); return V(); } void insert(const K &Key, const V &Val) { insertIntoScope(CurScope, Key, Val); } using iterator = ScopedHashTableIterator<K, V, KInfo>; iterator end() { return iterator(0); } iterator begin(const K &Key) { typename DenseMap<K, ValTy*, KInfo>::iterator I = TopLevelMap.find(Key); if (I == TopLevelMap.end()) return end(); return iterator(I->second); } ScopeTy *getCurScope() { return CurScope; } const ScopeTy *getCurScope() const { return CurScope; } /// insertIntoScope - This inserts the specified key/value at the specified /// (possibly not the current) scope. While it is ok to insert into a scope /// that isn't the current one, it isn't ok to insert *underneath* an existing /// value of the specified key. void insertIntoScope(ScopeTy *S, const K &Key, const V &Val) { assert(S && "No scope active!"); ScopedHashTableVal<K, V> *&KeyEntry = TopLevelMap[Key]; KeyEntry = ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val, Allocator); S->setLastValInScope(KeyEntry); } }; /// ScopedHashTableScope ctor - Install this as the current scope for the hash /// table. template <typename K, typename V, typename KInfo, typename Allocator> ScopedHashTableScope<K, V, KInfo, Allocator>:: ScopedHashTableScope(ScopedHashTable<K, V, KInfo, Allocator> &ht) : HT(ht) { PrevScope = HT.CurScope; HT.CurScope = this; LastValInScope = nullptr; } template <typename K, typename V, typename KInfo, typename Allocator> ScopedHashTableScope<K, V, KInfo, Allocator>::~ScopedHashTableScope() { assert(HT.CurScope == this && "Scope imbalance!"); HT.CurScope = PrevScope; // Pop and delete all values corresponding to this scope. while (ScopedHashTableVal<K, V> *ThisEntry = LastValInScope) { // Pop this value out of the TopLevelMap. if (!ThisEntry->getNextForKey()) { assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry && "Scope imbalance!"); HT.TopLevelMap.erase(ThisEntry->getKey()); } else { ScopedHashTableVal<K, V> *&KeyEntry = HT.TopLevelMap[ThisEntry->getKey()]; assert(KeyEntry == ThisEntry && "Scope imbalance!"); KeyEntry = ThisEntry->getNextForKey(); } // Pop this value out of the scope. LastValInScope = ThisEntry->getNextInScope(); // Delete this entry. ThisEntry->Destroy(HT.getAllocator()); } } } // end namespace llvm #endif // LLVM_ADT_SCOPEDHASHTABLE_H
Upload File
Create Folder