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 19 #include "llvm/CGData/CGDataPatchItem.h" 20 #include "llvm/CGData/StableFunctionMap.h" 21 #include "llvm/ObjectYAML/YAML.h" 22 #include "llvm/Support/Compiler.h" 23 #include "llvm/Support/raw_ostream.h" 24 25 namespace llvm { 26 27 struct StableFunctionMapRecord { 28 std::unique_ptr<StableFunctionMap> FunctionMap; 29 StableFunctionMapRecordStableFunctionMapRecord30 StableFunctionMapRecord() { 31 FunctionMap = std::make_unique<StableFunctionMap>(); 32 } 33 StableFunctionMapRecordStableFunctionMapRecord34 StableFunctionMapRecord(std::unique_ptr<StableFunctionMap> FunctionMap) 35 : FunctionMap(std::move(FunctionMap)) {} 36 37 /// A static helper function to serialize the stable function map without 38 /// owning the stable function map. 39 LLVM_ABI static void serialize(raw_ostream &OS, 40 const StableFunctionMap *FunctionMap, 41 std::vector<CGDataPatchItem> &PatchItems); 42 43 /// Serialize the stable function map to a raw_ostream. 44 LLVM_ABI void serialize(raw_ostream &OS, 45 std::vector<CGDataPatchItem> &PatchItems) const; 46 47 /// Deserialize the stable function map from a raw_ostream. 48 LLVM_ABI void deserialize(const unsigned char *&Ptr, 49 bool ReadStableFunctionMapNames = true); 50 51 /// Serialize the stable function map to a YAML stream. 52 LLVM_ABI void serializeYAML(yaml::Output &YOS) const; 53 54 /// Deserialize the stable function map from a YAML stream. 55 LLVM_ABI void deserializeYAML(yaml::Input &YIS); 56 57 /// Finalize the stable function map by trimming content. 58 void finalize(bool SkipTrim = false) { FunctionMap->finalize(SkipTrim); } 59 60 /// Merge the stable function map into this one. mergeStableFunctionMapRecord61 void merge(const StableFunctionMapRecord &Other) { 62 FunctionMap->merge(*Other.FunctionMap); 63 } 64 65 /// \returns true if the stable function map is empty. emptyStableFunctionMapRecord66 bool empty() const { return FunctionMap->empty(); } 67 68 /// Print the stable function map in a YAML format. 69 void print(raw_ostream &OS = llvm::errs()) const { 70 yaml::Output YOS(OS); 71 serializeYAML(YOS); 72 } 73 }; 74 75 } // namespace llvm 76 77 #endif 78