LLVM 22.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_CGDATA_OUTLINEDHASHTREERECORD_H
17#define LLVM_CGDATA_OUTLINEDHASHTREERECORD_H
18
21
22namespace llvm {
23
24/// HashNodeStable is the serialized, stable, and compact representation
25/// of a HashNode.
27 llvm::yaml::Hex64 Hash;
28 unsigned Terminals;
29 std::vector<unsigned> SuccessorIds;
30};
31
32using IdHashNodeStableMapTy = std::map<unsigned, HashNodeStable>;
35
37 std::unique_ptr<OutlinedHashTree> HashTree;
38
39 OutlinedHashTreeRecord() { HashTree = std::make_unique<OutlinedHashTree>(); }
40 OutlinedHashTreeRecord(std::unique_ptr<OutlinedHashTree> HashTree)
41 : HashTree(std::move(HashTree)) {};
42
43 /// Serialize the outlined hash tree to a raw_ostream.
44 LLVM_ABI void serialize(raw_ostream &OS) const;
45 /// Deserialize the outlined hash tree from a raw_ostream.
46 LLVM_ABI void deserialize(const unsigned char *&Ptr);
47 /// Serialize the outlined hash tree to a YAML stream.
48 LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
49 /// Deserialize the outlined hash tree from a YAML stream.
50 LLVM_ABI void deserializeYAML(yaml::Input &YIS);
51
52 /// Merge the other outlined hash tree into this one.
54 HashTree->merge(Other.HashTree.get());
55 }
56
57 /// \returns true if the outlined hash tree is empty.
58 bool empty() const { return HashTree->empty(); }
59
60 /// Print the outlined hash tree in a YAML format.
61 void print(raw_ostream &OS = llvm::errs()) const {
62 yaml::Output YOS(OS);
63 serializeYAML(YOS);
64 }
65
66private:
67 /// Convert the outlined hash tree to stable data.
68 void convertToStableData(IdHashNodeStableMapTy &IdNodeStableMap) const;
69
70 /// Convert the stable data back to the outlined hash tree.
71 void convertFromStableData(const IdHashNodeStableMapTy &IdNodeStableMap);
72};
73
74} // end namespace llvm
75
76#endif // LLVM_CGDATA_OUTLINEDHASHTREERECORD_H
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::map< unsigned, HashNodeStable > IdHashNodeStableMapTy
LLVM_ABI 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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
HashNodeStable is the serialized, stable, and compact representation of a HashNode.
std::vector< unsigned > SuccessorIds
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.
OutlinedHashTreeRecord(std::unique_ptr< OutlinedHashTree > HashTree)
LLVM_ABI 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.