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