1//===--------- Definition of the MemProfiler class --------------*- 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 file declares the MemProfiler class.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
13#define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
14
15#include "llvm/ADT/IntrusiveRefCntPtr.h"
16#include "llvm/IR/PassManager.h"
17
18namespace llvm {
19class Function;
20class Module;
21
22namespace vfs {
23class FileSystem;
24} // namespace vfs
25
26/// Public interface to the memory profiler pass for instrumenting code to
27/// profile memory accesses.
28///
29/// The profiler itself is a function pass that works by inserting various
30/// calls to the MemProfiler runtime library functions. The runtime library
31/// essentially replaces malloc() and free() with custom implementations that
32/// record data about the allocations.
33class MemProfilerPass : public PassInfoMixin<MemProfilerPass> {
34public:
35 explicit MemProfilerPass();
36 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
37 static bool isRequired() { return true; }
38};
39
40/// Public interface to the memory profiler module pass for instrumenting code
41/// to profile memory allocations and accesses.
42class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> {
43public:
44 explicit ModuleMemProfilerPass();
45 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
46 static bool isRequired() { return true; }
47};
48
49class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
50public:
51 explicit MemProfUsePass(std::string MemoryProfileFile,
52 IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
53 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
54
55private:
56 std::string MemoryProfileFileName;
57 IntrusiveRefCntPtr<vfs::FileSystem> FS;
58};
59
60} // namespace llvm
61
62#endif
63

source code of llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h