1 //===--------- Definition of the MemProfiler class --------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares the MemProfiler class. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H 14 #define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H 15 16 #include "llvm/IR/Function.h" 17 #include "llvm/IR/Module.h" 18 #include "llvm/IR/PassManager.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); isRequired()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); isRequired()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