File indexing completed on 2026-05-10 08:43:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef LLVM_CGDATA_STABLEFUNCTIONMAP_H
0017 #define LLVM_CGDATA_STABLEFUNCTIONMAP_H
0018
0019 #include "llvm/ADT/DenseMap.h"
0020 #include "llvm/ADT/StringMap.h"
0021 #include "llvm/IR/StructuralHash.h"
0022
0023 namespace llvm {
0024
0025 using IndexPairHash = std::pair<IndexPair, stable_hash>;
0026 using IndexOperandHashVecType = SmallVector<IndexPairHash>;
0027
0028
0029
0030 struct StableFunction {
0031
0032 stable_hash Hash;
0033
0034 std::string FunctionName;
0035
0036 std::string ModuleName;
0037
0038 unsigned InstCount;
0039
0040 IndexOperandHashVecType IndexOperandHashes;
0041
0042 StableFunction(stable_hash Hash, const std::string FunctionName,
0043 const std::string ModuleName, unsigned InstCount,
0044 IndexOperandHashVecType &&IndexOperandHashes)
0045 : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName),
0046 InstCount(InstCount),
0047 IndexOperandHashes(std::move(IndexOperandHashes)) {}
0048 StableFunction() = default;
0049 };
0050
0051 struct StableFunctionMap {
0052
0053 struct StableFunctionEntry {
0054
0055 stable_hash Hash;
0056
0057 unsigned FunctionNameId;
0058
0059 unsigned ModuleNameId;
0060
0061 unsigned InstCount;
0062
0063 std::unique_ptr<IndexOperandHashMapType> IndexOperandHashMap;
0064
0065 StableFunctionEntry(
0066 stable_hash Hash, unsigned FunctionNameId, unsigned ModuleNameId,
0067 unsigned InstCount,
0068 std::unique_ptr<IndexOperandHashMapType> IndexOperandHashMap)
0069 : Hash(Hash), FunctionNameId(FunctionNameId),
0070 ModuleNameId(ModuleNameId), InstCount(InstCount),
0071 IndexOperandHashMap(std::move(IndexOperandHashMap)) {}
0072 };
0073
0074 using HashFuncsMapType =
0075 DenseMap<stable_hash, SmallVector<std::unique_ptr<StableFunctionEntry>>>;
0076
0077
0078 const HashFuncsMapType &getFunctionMap() const { return HashToFuncs; }
0079
0080
0081 const SmallVector<std::string> getNames() const { return IdToName; }
0082
0083
0084
0085 unsigned getIdOrCreateForName(StringRef Name);
0086
0087
0088 std::optional<std::string> getNameForId(unsigned Id) const;
0089
0090
0091
0092
0093 void insert(const StableFunction &Func);
0094
0095
0096 void merge(const StableFunctionMap &OtherMap);
0097
0098
0099 bool empty() const { return size() == 0; }
0100
0101 enum SizeType {
0102 UniqueHashCount,
0103 TotalFunctionCount,
0104 MergeableFunctionCount,
0105
0106 };
0107
0108
0109
0110 size_t size(SizeType Type = UniqueHashCount) const;
0111
0112
0113 void finalize(bool SkipTrim = false);
0114
0115 private:
0116
0117
0118
0119 void insert(std::unique_ptr<StableFunctionEntry> FuncEntry) {
0120 assert(!Finalized && "Cannot insert after finalization");
0121 HashToFuncs[FuncEntry->Hash].emplace_back(std::move(FuncEntry));
0122 }
0123
0124
0125 HashFuncsMapType HashToFuncs;
0126
0127 SmallVector<std::string> IdToName;
0128
0129 StringMap<unsigned> NameToId;
0130
0131 bool Finalized = false;
0132
0133 friend struct StableFunctionMapRecord;
0134 };
0135
0136 }
0137
0138 #endif