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/IR/Function.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/Pass.h"
19 
20 namespace llvm {
21 
22 /// Public interface to the memory profiler pass for instrumenting code to
23 /// profile memory accesses.
24 ///
25 /// The profiler itself is a function pass that works by inserting various
26 /// calls to the MemProfiler runtime library functions. The runtime library
27 /// essentially replaces malloc() and free() with custom implementations that
28 /// record data about the allocations.
29 class MemProfilerPass : public PassInfoMixin<MemProfilerPass> {
30 public:
31   explicit MemProfilerPass();
32   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
33   static bool isRequired() { return true; }
34 };
35 
36 /// Public interface to the memory profiler module pass for instrumenting code
37 /// to profile memory allocations and accesses.
38 class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> {
39 public:
40   explicit ModuleMemProfilerPass();
41   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
42   static bool isRequired() { return true; }
43 };
44 
45 // Insert MemProfiler instrumentation
46 FunctionPass *createMemProfilerFunctionPass();
47 ModulePass *createModuleMemProfilerLegacyPassPass();
48 
49 } // namespace llvm
50 
51 #endif
52