21#define DEBUG_TYPE "outlined-hash-tree"
31 io.mapRequired(
"Hash", res.
Hash);
32 io.mapRequired(
"Terminals", res.
Terminals);
40 io.mapRequired(Key.str().c_str(), NodeStable);
42 if (Key.getAsInteger(0, Id)) {
43 io.setError(
"Id not an integer");
46 V.insert({Id, NodeStable});
50 for (
auto Iter = V.begin(); Iter != V.end(); ++Iter)
51 io.mapRequired(utostr(Iter->first).c_str(), Iter->second);
60 convertToStableData(IdNodeStableMap);
64 for (
const auto &[Id, NodeStable] : IdNodeStableMap) {
69 for (
auto SuccessorId : NodeStable.SuccessorIds)
76 auto NumIdNodeStableMap =
77 endian::readNext<uint32_t, endianness::little, unaligned>(
Ptr);
79 for (
unsigned I = 0;
I < NumIdNodeStableMap; ++
I) {
80 auto Id = endian::readNext<uint32_t, endianness::little, unaligned>(
Ptr);
83 endian::readNext<uint64_t, endianness::little, unaligned>(
Ptr);
85 endian::readNext<uint32_t, endianness::little, unaligned>(
Ptr);
86 auto NumSuccessorIds =
87 endian::readNext<uint32_t, endianness::little, unaligned>(
Ptr);
88 for (
unsigned J = 0; J < NumSuccessorIds; ++J)
90 endian::readNext<uint32_t, endianness::little, unaligned>(
Ptr));
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) {
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) {
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(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
This is an optimization pass for GlobalISel generic memory operations.
void sort(IteratorTy Start, IteratorTy End)
std::map< unsigned, HashNodeStable > IdHashNodeStableMapTy
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.
void serializeYAML(yaml::Output &YOS) const
Serialize the outlined hash tree to a YAML stream.
void deserializeYAML(yaml::Input &YIS)
Deserialize the outlined hash tree from a YAML stream.
void deserialize(const unsigned char *&Ptr)
Deserialize the outlined hash tree from a raw_ostream.
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)
static void mapping(IO &io, HashNodeStable &res)