LLVM 22.0.0git
StableFunctionMapRecord.h
Go to the documentation of this file.
1//===- StableFunctionMapRecord.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 StableFunctionMapRecord structure, which provides
10// functionality for managing and serializing a StableFunctionMap. It includes
11// methods for serialization to and from raw and YAML streams, as well as
12// utilities for merging and finalizing function maps.
13//
14//===---------------------------------------------------------------------===//
15
16#ifndef LLVM_CGDATA_STABLEFUNCTIONMAPRECORD_H
17#define LLVM_CGDATA_STABLEFUNCTIONMAPRECORD_H
18
24
25namespace llvm {
26
27/// The structure of the serialized stable function map is as follows:
28/// - Number of unique function/module names
29/// - Total size of unique function/module names for opt-in skipping
30/// - Unique function/module names
31/// - Padding to align to 4 bytes
32/// - Number of StableFunctionEntries
33/// - Hashes of each StableFunctionEntry
34/// - Fixed-size fields for each StableFunctionEntry (the order is consistent
35/// with the hashes above):
36/// - FunctionNameId
37/// - ModuleNameId
38/// - InstCount
39/// - Relative offset to the beginning of IndexOperandHashes for this entry
40/// - Total size of variable-sized IndexOperandHashes for lazy-loading support
41/// - Variable-sized IndexOperandHashes for each StableFunctionEntry:
42/// - Number of IndexOperandHashes
43/// - Contents of each IndexOperandHashes
44/// - InstIndex
45/// - OpndIndex
46/// - OpndHash
48 std::unique_ptr<StableFunctionMap> FunctionMap;
49
51 FunctionMap = std::make_unique<StableFunctionMap>();
52 }
53
54 StableFunctionMapRecord(std::unique_ptr<StableFunctionMap> FunctionMap)
56
57 /// A static helper function to serialize the stable function map without
58 /// owning the stable function map.
59 LLVM_ABI static void serialize(raw_ostream &OS,
61 std::vector<CGDataPatchItem> &PatchItems);
62
63 /// A static helper function to deserialize the stable function map entry.
64 /// Ptr should be pointing to the start of the fixed-sized fields of the
65 /// entry when passed in.
66 LLVM_ABI static void deserializeEntry(const unsigned char *Ptr,
67 stable_hash Hash,
69
70 /// Serialize the stable function map to a raw_ostream.
72 std::vector<CGDataPatchItem> &PatchItems) const;
73
74 /// Deserialize the stable function map from a raw_ostream.
75 LLVM_ABI void deserialize(const unsigned char *&Ptr);
76
77 /// Lazily deserialize the stable function map from `Buffer` starting at
78 /// `Offset`. The individual stable function entry would be read lazily from
79 /// `Buffer` when the function map is accessed.
80 LLVM_ABI void lazyDeserialize(std::shared_ptr<MemoryBuffer> Buffer,
82
83 /// Serialize the stable function map to a YAML stream.
84 LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
85
86 /// Deserialize the stable function map from a YAML stream.
88
89 /// Finalize the stable function map by trimming content.
90 void finalize(bool SkipTrim = false) { FunctionMap->finalize(SkipTrim); }
91
92 /// Merge the stable function map into this one.
94 FunctionMap->merge(*Other.FunctionMap);
95 }
96
97 /// \returns true if the stable function map is empty.
98 bool empty() const { return FunctionMap->empty(); }
99
100 /// Print the stable function map in a YAML format.
101 void print(raw_ostream &OS = llvm::errs()) const {
102 yaml::Output YOS(OS);
103 serializeYAML(YOS);
104 }
105
106 /// Set whether to read stable function names from the buffer.
107 /// Has no effect if the function map is read from a YAML stream.
109 assert(
110 FunctionMap->empty() &&
111 "Cannot change ReadStableFunctionMapNames after the map is populated");
112 FunctionMap->ReadStableFunctionMapNames = Read;
113 }
114
115private:
116 void deserialize(const unsigned char *&Ptr, bool Lazy);
117};
118
119} // namespace llvm
120
121#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
The Input class is used to parse a yaml document into in-memory structs and vectors.
The Output class is used to generate a yaml document from in-memory structs and vectors.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
uint64_t stable_hash
An opaque object representing a stable hash code.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Other
Any other memory.
Definition ModRef.h:68
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:851
void merge(const StableFunctionMapRecord &Other)
Merge the stable function map into this one.
void finalize(bool SkipTrim=false)
Finalize the stable function map by trimming content.
static LLVM_ABI void deserializeEntry(const unsigned char *Ptr, stable_hash Hash, StableFunctionMap *FunctionMap)
A static helper function to deserialize the stable function map entry.
LLVM_ABI void deserialize(const unsigned char *&Ptr)
Deserialize the stable function map from a raw_ostream.
std::unique_ptr< StableFunctionMap > FunctionMap
void print(raw_ostream &OS=llvm::errs()) const
Print the stable function map in a YAML format.
static LLVM_ABI void serialize(raw_ostream &OS, const StableFunctionMap *FunctionMap, std::vector< CGDataPatchItem > &PatchItems)
A static helper function to serialize the stable function map without owning the stable function map.
StableFunctionMapRecord(std::unique_ptr< StableFunctionMap > FunctionMap)
void setReadStableFunctionMapNames(bool Read)
Set whether to read stable function names from the buffer.
LLVM_ABI void deserializeYAML(yaml::Input &YIS)
Deserialize the stable function map from a YAML stream.
LLVM_ABI void lazyDeserialize(std::shared_ptr< MemoryBuffer > Buffer, uint64_t Offset)
Lazily deserialize the stable function map from Buffer starting at Offset.
LLVM_ABI void serializeYAML(yaml::Output &YOS) const
Serialize the stable function map to a YAML stream.