21#define DEBUG_TYPE "outlined-hash-tree"
42 if (
Key.getAsInteger(0, Id)) {
46 V.insert({Id, NodeStable});
50 for (
auto Iter = V.begin(); Iter != V.end(); ++Iter)
60 convertToStableData(IdNodeStableMap);
64 for (
const auto &[Id, NodeStable] : IdNodeStableMap) {
69 for (
auto SuccessorId : NodeStable.SuccessorIds)
76 auto NumIdNodeStableMap =
79 for (
unsigned I = 0;
I < NumIdNodeStableMap; ++
I) {
86 auto NumSuccessorIds =
88 for (
unsigned J = 0; J < NumSuccessorIds; ++J)
92 IdNodeStableMap[Id] = std::move(NodeStable);
95 convertFromStableData(IdNodeStableMap);
100 convertToStableData(IdNodeStableMap);
102 YOS << IdNodeStableMap;
108 YIS >> IdNodeStableMap;
111 convertFromStableData(IdNodeStableMap);
114void OutlinedHashTreeRecord::convertToStableData(
119 [&NodeIdMap](
const HashNode *Current) {
120 size_t Index = NodeIdMap.
size();
121 NodeIdMap[Current] = Index;
123 "Duplicate key in NodeIdMap: 'Current' should be unique.");
128 for (
auto &
P : NodeIdMap) {
129 auto *
Node =
P.first;
134 for (
auto &
P :
Node->Successors)
135 NodeStable.
SuccessorIds.push_back(NodeIdMap[
P.second.get()]);
136 IdNodeStableMap[Id] = NodeStable;
140 for (
auto &
P : IdNodeStableMap)
144void OutlinedHashTreeRecord::convertFromStableData(
149 assert(IdNodeMap[0]->Successors.empty());
151 for (
auto &
P : IdNodeStableMap) {
153 const HashNodeStable &NodeStable =
P.second;
155 HashNode *Curr = IdNodeMap[
Id];
160 assert(Successors.empty());
162 auto Sucessor = std::make_unique<HashNode>();
163 IdNodeMap[SuccessorId] = Sucessor.get();
164 auto Hash = IdNodeStableMap.
at(SuccessorId).Hash;
165 Successors[Hash] = std::move(Sucessor);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
const ValueT & at(const_arg_type_t< KeyT > Val) const
at - Return the entry for the specified key, or abort if no such entry exists.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
void mapRequired(const char *Key, T &Val)
virtual void setError(const Twine &)=0
The Output class is used to generate a yaml document from in-memory structs and vectors.
value_type readNext(const CharT *&memory, endianness endian)
Read a value of a particular endianness from a buffer, and increment the buffer past that value.
This is an optimization pass for GlobalISel generic memory operations.
std::string utostr(uint64_t X, bool isNeg=false)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
DenseMap< unsigned, HashNode * > IdHashNodeMapTy
std::map< unsigned, HashNodeStable > IdHashNodeStableMapTy
DenseMap< const HashNode *, unsigned > HashNodeIdMapTy
HashNodeStable is the serialized, stable, and compact representation of a HashNode.
std::vector< unsigned > SuccessorIds
A HashNode is an entry in an OutlinedHashTree, holding a hash value and a collection of Successors (o...
std::unordered_map< stable_hash, std::unique_ptr< HashNode > > Successors
The successors of this node.
std::optional< unsigned > Terminals
The number of terminals in the sequence ending at this node.
stable_hash Hash
The hash value of the node.
LLVM_ABI void serializeYAML(yaml::Output &YOS) const
Serialize the outlined hash tree to a YAML stream.
LLVM_ABI void deserializeYAML(yaml::Input &YIS)
Deserialize the outlined hash tree from a YAML stream.
LLVM_ABI void deserialize(const unsigned char *&Ptr)
Deserialize the outlined hash tree from a raw_ostream.
LLVM_ABI void serialize(raw_ostream &OS) const
Serialize the outlined hash tree to a raw_ostream.
std::unique_ptr< OutlinedHashTree > HashTree
Adapter to write values to a stream in a particular byte order.
void write(ArrayRef< value_type > Val)
static void output(IO &io, IdHashNodeStableMapTy &V)
static void inputOne(IO &io, StringRef Key, IdHashNodeStableMapTy &V)
This class should be specialized by any type that needs to be converted to/from a YAML mapping in the...
static void mapping(IO &io, HashNodeStable &res)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.