[llvm] [CGData] Stable Function Map (PR #112662)
Vincent Lee via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 00:27:30 PDT 2024
================
@@ -0,0 +1,136 @@
+//===- StableFunctionMap.h -------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---------------------------------------------------------------------===//
+//
+// This defines the StableFunctionMap class, to track similar functions.
+// It provides a mechanism to map stable hashes of functions to their
+// corresponding metadata. It includes structures for storing function details
+// and methods for managing and querying these mappings.
+//
+//===---------------------------------------------------------------------===//
+
+#ifndef LLVM_CGDATA_STABLEFUNCTIONMAP_H
+#define LLVM_CGDATA_STABLEFUNCTIONMAP_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/IR/StructuralHash.h"
+
+namespace llvm {
+
+using IndexPairHash = std::pair<IndexPair, stable_hash>;
+using IndexOperandHashVecType = SmallVector<IndexPairHash>;
+
+/// A stable function is a function with a stable hash while tracking the
+/// locations of ignored operands and their hashes.
+struct StableFunction {
+ /// The combined stable hash of the function.
+ stable_hash Hash;
+ /// The name of the function.
+ std::string FunctionName;
+ /// The name of the module the function is in.
+ std::string ModuleName;
+ /// The number of instructions.
+ unsigned InstCount;
+ /// A vector of pairs of IndexPair and operand hash which was skipped.
+ IndexOperandHashVecType IndexOperandHashes;
+
+ StableFunction(stable_hash Hash, const std::string FunctionName,
+ const std::string ModuleName, unsigned InstCount,
+ IndexOperandHashVecType &&IndexOperandHashes)
+ : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName),
+ InstCount(InstCount),
+ IndexOperandHashes(std::move(IndexOperandHashes)) {}
+ StableFunction() = default;
+};
+
+/// An efficient form of StableFunction for fast look-up
+struct StableFunctionEntry {
----------------
thevinster wrote:
Should this be an internal implementation within `StableFunctionMap`? It doesn't seem like it could be defined without a StableFunctionMap calculating the Ids, right? We could always make this public again if there is a use case for it.
https://github.com/llvm/llvm-project/pull/112662
More information about the llvm-commits
mailing list