Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:23

0001 //===- OutlinedHashTreeRecord.h --------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===---------------------------------------------------------------------===//
0008 //
0009 // This defines the OutlinedHashTreeRecord class. This class holds the outlined
0010 // hash tree for both serialization and deserialization processes. It utilizes
0011 // two data formats for serialization: raw binary data and YAML.
0012 // These two formats can be used interchangeably.
0013 //
0014 //===---------------------------------------------------------------------===//
0015 
0016 #ifndef LLVM_CGDATA_OUTLINEDHASHTREERECORD_H
0017 #define LLVM_CGDATA_OUTLINEDHASHTREERECORD_H
0018 
0019 #include "llvm/CGData/OutlinedHashTree.h"
0020 
0021 namespace llvm {
0022 
0023 /// HashNodeStable is the serialized, stable, and compact representation
0024 /// of a HashNode.
0025 struct HashNodeStable {
0026   llvm::yaml::Hex64 Hash;
0027   unsigned Terminals;
0028   std::vector<unsigned> SuccessorIds;
0029 };
0030 
0031 using IdHashNodeStableMapTy = std::map<unsigned, HashNodeStable>;
0032 using IdHashNodeMapTy = DenseMap<unsigned, HashNode *>;
0033 using HashNodeIdMapTy = DenseMap<const HashNode *, unsigned>;
0034 
0035 struct OutlinedHashTreeRecord {
0036   std::unique_ptr<OutlinedHashTree> HashTree;
0037 
0038   OutlinedHashTreeRecord() { HashTree = std::make_unique<OutlinedHashTree>(); }
0039   OutlinedHashTreeRecord(std::unique_ptr<OutlinedHashTree> HashTree)
0040       : HashTree(std::move(HashTree)) {};
0041 
0042   /// Serialize the outlined hash tree to a raw_ostream.
0043   void serialize(raw_ostream &OS) const;
0044   /// Deserialize the outlined hash tree from a raw_ostream.
0045   void deserialize(const unsigned char *&Ptr);
0046   /// Serialize the outlined hash tree to a YAML stream.
0047   void serializeYAML(yaml::Output &YOS) const;
0048   /// Deserialize the outlined hash tree from a YAML stream.
0049   void deserializeYAML(yaml::Input &YIS);
0050 
0051   /// Merge the other outlined hash tree into this one.
0052   void merge(const OutlinedHashTreeRecord &Other) {
0053     HashTree->merge(Other.HashTree.get());
0054   }
0055 
0056   /// \returns true if the outlined hash tree is empty.
0057   bool empty() const { return HashTree->empty(); }
0058 
0059   /// Print the outlined hash tree in a YAML format.
0060   void print(raw_ostream &OS = llvm::errs()) const {
0061     yaml::Output YOS(OS);
0062     serializeYAML(YOS);
0063   }
0064 
0065 private:
0066   /// Convert the outlined hash tree to stable data.
0067   void convertToStableData(IdHashNodeStableMapTy &IdNodeStableMap) const;
0068 
0069   /// Convert the stable data back to the outlined hash tree.
0070   void convertFromStableData(const IdHashNodeStableMapTy &IdNodeStableMap);
0071 };
0072 
0073 } // end namespace llvm
0074 
0075 #endif // LLVM_CGDATA_OUTLINEDHASHTREERECORD_H