Skip to content

Commit 16c7b3c

Browse files
authored
[MemProf] Split MemProfiler into Instrumentation and Use. (#142811)
Most of the recent development on the MemProfiler has been on the Use part. The instrumentation has been quite stable for a while. As the complexity of the use grows (with undrifting, diagnostics etc) I figured it would be good to separate these two implementations.
1 parent c140783 commit 16c7b3c

File tree

9 files changed

+720
-661
lines changed

9 files changed

+720
-661
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
7070
#include "llvm/Transforms/Instrumentation/KCFI.h"
7171
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
72-
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
72+
#include "llvm/Transforms/Instrumentation/MemProfInstrumentation.h"
73+
#include "llvm/Transforms/Instrumentation/MemProfUse.h"
7374
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
7475
#include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
7576
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===--- MemProfInstrumentation.h - Memory profiler instrumentation ----*- C++
2+
//-*-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file declares the MemProf instrumentation pass classes.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROF_INSTRUMENTATION_H
14+
#define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROF_INSTRUMENTATION_H
15+
16+
#include "llvm/IR/PassManager.h"
17+
18+
namespace llvm {
19+
class Function;
20+
class Module;
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+
} // namespace llvm
46+
47+
#endif

llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h renamed to llvm/include/llvm/Transforms/Instrumentation/MemProfUse.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
//===--------- Definition of the MemProfiler class --------------*- C++ -*-===//
1+
//===--------- MemProfUse.h - Memory profiler use pass ----*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file declares the MemProfiler class.
9+
// This file declares the MemProfUsePass class and related utilities.
1010
//
1111
//===----------------------------------------------------------------------===//
12-
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
13-
#define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
12+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFUSE_H
13+
#define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFUSE_H
1414

1515
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1616
#include "llvm/IR/PassManager.h"
@@ -19,7 +19,6 @@
1919
#include <unordered_map>
2020

2121
namespace llvm {
22-
class Function;
2322
class IndexedInstrProfReader;
2423
class Module;
2524
class TargetLibraryInfo;
@@ -28,29 +27,6 @@ namespace vfs {
2827
class FileSystem;
2928
} // namespace vfs
3029

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.
38-
class MemProfilerPass : public PassInfoMixin<MemProfilerPass> {
39-
public:
40-
explicit MemProfilerPass();
41-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
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.
47-
class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> {
48-
public:
49-
explicit ModuleMemProfilerPass();
50-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
51-
static bool isRequired() { return true; }
52-
};
53-
5430
class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
5531
public:
5632
explicit MemProfUsePass(std::string MemoryProfileFile,

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@
240240
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
241241
#include "llvm/Transforms/Instrumentation/KCFI.h"
242242
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
243-
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
243+
#include "llvm/Transforms/Instrumentation/MemProfInstrumentation.h"
244+
#include "llvm/Transforms/Instrumentation/MemProfUse.h"
244245
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
245246
#include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
246247
#include "llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h"

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
#include "llvm/Transforms/Instrumentation/CGProfile.h"
7777
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
7878
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
79-
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
79+
#include "llvm/Transforms/Instrumentation/MemProfInstrumentation.h"
80+
#include "llvm/Transforms/Instrumentation/MemProfUse.h"
8081
#include "llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h"
8182
#include "llvm/Transforms/Instrumentation/PGOCtxProfLowering.h"
8283
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"

llvm/lib/Transforms/Instrumentation/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ add_llvm_component_library(LLVMInstrumentation
66
DataFlowSanitizer.cpp
77
GCOVProfiling.cpp
88
BlockCoverageInference.cpp
9-
MemProfiler.cpp
9+
MemProfInstrumentation.cpp
10+
MemProfUse.cpp
1011
MemorySanitizer.cpp
1112
NumericalStabilitySanitizer.cpp
1213
IndirectCallPromotion.cpp

0 commit comments

Comments
 (0)