LLVM 20.0.0git
MemProfiler.h
Go to the documentation of this file.
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
16#include "llvm/IR/PassManager.h"
18
19#include <unordered_map>
20
21namespace llvm {
22class Function;
23class IndexedInstrProfReader;
24class Module;
25class TargetLibraryInfo;
26
27namespace vfs {
28class FileSystem;
29} // namespace vfs
30
31/// Public interface to the memory profiler pass for instrumenting code to
32/// profile memory accesses.
33///
34/// The profiler itself is a function pass that works by inserting various
35/// calls to the MemProfiler runtime library functions. The runtime library
36/// essentially replaces malloc() and free() with custom implementations that
37/// record data about the allocations.
38class MemProfilerPass : public PassInfoMixin<MemProfilerPass> {
39public:
40 explicit MemProfilerPass();
42 static bool isRequired() { return true; }
43};
44
45/// Public interface to the memory profiler module pass for instrumenting code
46/// to profile memory allocations and accesses.
47class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> {
48public:
51 static bool isRequired() { return true; }
52};
53
54class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
55public:
56 explicit MemProfUsePass(std::string MemoryProfileFile,
59
60private:
61 std::string MemoryProfileFileName;
63};
64
65namespace memprof {
66
67// Extract all calls from the IR. Arrange them in a map from caller GUIDs to a
68// list of call sites, each of the form {LineLocation, CalleeGUID}.
71
73 uint64_t operator()(const LineLocation &Loc) const {
74 return Loc.getHashCode();
75 }
76};
77
79 std::unordered_map<LineLocation, LineLocation, LineLocationHash>;
80
81// Compute an undrifting map. The result is a map from caller GUIDs to an inner
82// map that maps source locations in the profile to those in the current IR.
85 const TargetLibraryInfo &TLI);
86
87} // namespace memprof
88} // namespace llvm
89
90#endif
This header defines various interfaces for pass management in LLVM.
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Reader for the indexed binary instrprof format.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Public interface to the memory profiler pass for instrumenting code to profile memory accesses.
Definition: MemProfiler.h:38
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static bool isRequired()
Definition: MemProfiler.h:42
Public interface to the memory profiler module pass for instrumenting code to profile memory allocati...
Definition: MemProfiler.h:47
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
Provides information about what library functions are available for the current target.
DenseMap< uint64_t, LocToLocMap > computeUndriftMap(Module &M, IndexedInstrProfReader *MemProfReader, const TargetLibraryInfo &TLI)
std::unordered_map< LineLocation, LineLocation, LineLocationHash > LocToLocMap
Definition: MemProfiler.h:79
DenseMap< uint64_t, SmallVector< CallEdgeTy, 0 > > extractCallsFromIR(Module &M, const TargetLibraryInfo &TLI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69
uint64_t operator()(const LineLocation &Loc) const
Definition: MemProfiler.h:73
uint64_t getHashCode() const
Definition: MemProf.h:906