LLVM 20.0.0git
OutlinedHashTreeRecord.h
Go to the documentation of this file.
1//===- OutlinedHashTreeRecord.h --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8//
9// This defines the OutlinedHashTreeRecord class. This class holds the outlined
10// hash tree for both serialization and deserialization processes. It utilizes
11// two data formats for serialization: raw binary data and YAML.
12// These two formats can be used interchangeably.
13//
14//===---------------------------------------------------------------------===//
15
16#ifndef LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H
17#define LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H
18
20
21namespace llvm {
22
23/// HashNodeStable is the serialized, stable, and compact representation
24/// of a HashNode.
26 llvm::yaml::Hex64 Hash;
27 unsigned Terminals;
28 std::vector<unsigned> SuccessorIds;
29};
30
31using IdHashNodeStableMapTy = std::map<unsigned, HashNodeStable>;
34
36 std::unique_ptr<OutlinedHashTree> HashTree;
37
38 OutlinedHashTreeRecord() { HashTree = std::make_unique<OutlinedHashTree>(); }
39 OutlinedHashTreeRecord(std::unique_ptr<OutlinedHashTree> HashTree)
40 : HashTree(std::move(HashTree)) {};
41
42 /// Serialize the outlined hash tree to a raw_ostream.
43 void serialize(raw_ostream &OS) const;
44 /// Deserialize the outlined hash tree from a raw_ostream.
45 void deserialize(const unsigned char *&Ptr);
46 /// Serialize the outlined hash tree to a YAML stream.
47 void serializeYAML(yaml::Output &YOS) const;
48 /// Deserialize the outlined hash tree from a YAML stream.
49 void deserializeYAML(yaml::Input &YIS);
50
51 /// Merge the other outlined hash tree into this one.
53 HashTree->merge(Other.HashTree.get());
54 }
55
56 /// \returns true if the outlined hash tree is empty.
57 bool empty() const { return HashTree->empty(); }
58
59 /// Print the outlined hash tree in a YAML format.
60 void print(raw_ostream &OS = llvm::errs()) const {
61 yaml::Output YOS(OS);
62 serializeYAML(YOS);
63 }
64
65private:
66 /// Convert the outlined hash tree to stable data.
67 void convertToStableData(IdHashNodeStableMapTy &IdNodeStableMap) const;
68
69 /// Convert the stable data back to the outlined hash tree.
70 void convertFromStableData(const IdHashNodeStableMapTy &IdNodeStableMap);
71};
72
73} // end namespace llvm
74
75#endif // LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H
raw_pwrite_stream & OS
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::map< unsigned, HashNodeStable > IdHashNodeStableMapTy
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Other
Any other memory.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
HashNodeStable is the serialized, stable, and compact representation of a HashNode.
std::vector< unsigned > SuccessorIds
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.
OutlinedHashTreeRecord(std::unique_ptr< OutlinedHashTree > HashTree)
void serialize(raw_ostream &OS) const
Serialize the outlined hash tree to a raw_ostream.
void print(raw_ostream &OS=llvm::errs()) const
Print the outlined hash tree in a YAML format.
std::unique_ptr< OutlinedHashTree > HashTree
void merge(const OutlinedHashTreeRecord &Other)
Merge the other outlined hash tree into this one.