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 Module; 21 22 namespace vfs { 23 class 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. 33 class MemProfilerPass : public PassInfoMixin<MemProfilerPass> { 34 public: 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. 42 class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> { 43 public: 44 explicit ModuleMemProfilerPass(); 45 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 46 static bool isRequired() { return true; } 47 }; 48 49 class MemProfUsePass : public PassInfoMixin<MemProfUsePass> { 50 public: 51 explicit MemProfUsePass(std::string MemoryProfileFile, 52 IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr); 53 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 54 55 private: 56 std::string MemoryProfileFileName; 57 IntrusiveRefCntPtr<vfs::FileSystem> FS; 58 }; 59 60 } // namespace llvm 61 62 #endif 63