File indexing completed on 2026-05-10 08:44:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
0013 #define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
0014
0015 #include "llvm/ADT/IntrusiveRefCntPtr.h"
0016 #include "llvm/IR/PassManager.h"
0017 #include "llvm/ProfileData/MemProf.h"
0018
0019 #include <unordered_map>
0020
0021 namespace llvm {
0022 class Function;
0023 class IndexedInstrProfReader;
0024 class Module;
0025 class TargetLibraryInfo;
0026
0027 namespace vfs {
0028 class FileSystem;
0029 }
0030
0031
0032
0033
0034
0035
0036
0037
0038 class MemProfilerPass : public PassInfoMixin<MemProfilerPass> {
0039 public:
0040 explicit MemProfilerPass();
0041 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0042 static bool isRequired() { return true; }
0043 };
0044
0045
0046
0047 class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> {
0048 public:
0049 explicit ModuleMemProfilerPass();
0050 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
0051 static bool isRequired() { return true; }
0052 };
0053
0054 class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
0055 public:
0056 explicit MemProfUsePass(std::string MemoryProfileFile,
0057 IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
0058 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
0059
0060 private:
0061 std::string MemoryProfileFileName;
0062 IntrusiveRefCntPtr<vfs::FileSystem> FS;
0063 };
0064
0065 namespace memprof {
0066
0067
0068
0069 DenseMap<uint64_t, SmallVector<CallEdgeTy, 0>> extractCallsFromIR(
0070 Module &M, const TargetLibraryInfo &TLI,
0071 function_ref<bool(uint64_t)> IsPresentInProfile = [](uint64_t) {
0072 return true;
0073 });
0074
0075 struct LineLocationHash {
0076 uint64_t operator()(const LineLocation &Loc) const {
0077 return Loc.getHashCode();
0078 }
0079 };
0080
0081 using LocToLocMap =
0082 std::unordered_map<LineLocation, LineLocation, LineLocationHash>;
0083
0084
0085
0086 DenseMap<uint64_t, LocToLocMap>
0087 computeUndriftMap(Module &M, IndexedInstrProfReader *MemProfReader,
0088 const TargetLibraryInfo &TLI);
0089
0090 }
0091 }
0092
0093 #endif