Skip to content

Commit 850482d

Browse files
committed
Revert "Add unit tests for size returning new funcs in the MemProf use pass. (llvm#105473)"
This reverts commit 2e426fe.
1 parent 7fc67b5 commit 850482d

File tree

5 files changed

+29
-199
lines changed

5 files changed

+29
-199
lines changed

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,10 @@ class IndexedMemProfReader {
670670

671671
public:
672672
IndexedMemProfReader() = default;
673-
virtual ~IndexedMemProfReader() = default;
674673

675674
Error deserialize(const unsigned char *Start, uint64_t MemProfOffset);
676675

677-
virtual Expected<memprof::MemProfRecord>
676+
Expected<memprof::MemProfRecord>
678677
getMemProfRecord(const uint64_t FuncNameHash) const;
679678
};
680679

@@ -769,14 +768,11 @@ class IndexedInstrProfReader : public InstrProfReader {
769768
uint64_t *MismatchedFuncSum = nullptr);
770769

771770
/// Return the memprof record for the function identified by
772-
/// llvm::md5(Name). Marked virtual so that unit tests can mock this function.
771+
/// llvm::md5(Name).
773772
Expected<memprof::MemProfRecord> getMemProfRecord(uint64_t FuncNameHash) {
774773
return MemProfReader.getMemProfRecord(FuncNameHash);
775774
}
776775

777-
/// Return the underlying memprof reader.
778-
IndexedMemProfReader &getIndexedMemProfReader() { return MemProfReader; }
779-
780776
/// Fill Counts with the profile data for the given function name.
781777
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
782778
std::vector<uint64_t> &Counts);

llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
#define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
1414

1515
#include "llvm/ADT/IntrusiveRefCntPtr.h"
16-
#include "llvm/IR/ModuleSummaryIndex.h"
1716
#include "llvm/IR/PassManager.h"
18-
#include "llvm/ProfileData/InstrProfReader.h"
19-
#include "llvm/Support/VirtualFileSystem.h"
2017

2118
namespace llvm {
2219
class Function;
2320
class Module;
24-
class TargetLibraryInfo;
21+
22+
namespace vfs {
23+
class FileSystem;
24+
} // namespace vfs
2525

2626
/// Public interface to the memory profiler pass for instrumenting code to
2727
/// profile memory accesses.
@@ -52,17 +52,6 @@ class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
5252
IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
5353
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
5454

55-
struct AllocMatchInfo {
56-
uint64_t TotalSize = 0;
57-
AllocationType AllocType = AllocationType::None;
58-
bool Matched = false;
59-
};
60-
61-
void
62-
readMemprof(Function &F, const IndexedMemProfReader &MemProfReader,
63-
const TargetLibraryInfo &TLI,
64-
std::map<uint64_t, AllocMatchInfo> &FullStackIdToAllocMatchInfo);
65-
6655
private:
6756
std::string MemoryProfileFileName;
6857
IntrusiveRefCntPtr<vfs::FileSystem> FS;

llvm/lib/Transforms/Instrumentation/MemProfiler.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/Support/CommandLine.h"
4040
#include "llvm/Support/Debug.h"
4141
#include "llvm/Support/HashBuilder.h"
42+
#include "llvm/Support/VirtualFileSystem.h"
4243
#include "llvm/TargetParser/Triple.h"
4344
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
4445
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -54,7 +55,6 @@ namespace llvm {
5455
extern cl::opt<bool> PGOWarnMissing;
5556
extern cl::opt<bool> NoPGOWarnMismatch;
5657
extern cl::opt<bool> NoPGOWarnMismatchComdatWeak;
57-
using AllocMatchInfo = ::llvm::MemProfUsePass::AllocMatchInfo;
5858
} // namespace llvm
5959

6060
constexpr int LLVM_MEM_PROFILER_VERSION = 1;
@@ -148,11 +148,10 @@ static cl::opt<int> ClDebugMax("memprof-debug-max", cl::desc("Debug max inst"),
148148

149149
// By default disable matching of allocation profiles onto operator new that
150150
// already explicitly pass a hot/cold hint, since we don't currently
151-
// override these hints anyway. Not static so that it can be set in the unit
152-
// test too.
153-
cl::opt<bool> ClMemProfMatchHotColdNew(
151+
// override these hints anyway.
152+
static cl::opt<bool> ClMemProfMatchHotColdNew(
154153
"memprof-match-hot-cold-new",
155-
cl::desc(
154+
cl::desc(
156155
"Match allocation profiles onto existing hot/cold operator new calls"),
157156
cl::Hidden, cl::init(false));
158157

@@ -790,11 +789,17 @@ static bool isAllocationWithHotColdVariant(Function *Callee,
790789
}
791790
}
792791

793-
void MemProfUsePass::readMemprof(
794-
Function &F, const IndexedMemProfReader &MemProfReader,
795-
const TargetLibraryInfo &TLI,
796-
std::map<uint64_t, AllocMatchInfo> &FullStackIdToAllocMatchInfo) {
797-
auto &Ctx = F.getContext();
792+
struct AllocMatchInfo {
793+
uint64_t TotalSize = 0;
794+
AllocationType AllocType = AllocationType::None;
795+
bool Matched = false;
796+
};
797+
798+
static void
799+
readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
800+
const TargetLibraryInfo &TLI,
801+
std::map<uint64_t, AllocMatchInfo> &FullStackIdToAllocMatchInfo) {
802+
auto &Ctx = M.getContext();
798803
// Previously we used getIRPGOFuncName() here. If F is local linkage,
799804
// getIRPGOFuncName() returns FuncName with prefix 'FileName;'. But
800805
// llvm-profdata uses FuncName in dwarf to create GUID which doesn't
@@ -805,7 +810,7 @@ void MemProfUsePass::readMemprof(
805810
auto FuncName = F.getName();
806811
auto FuncGUID = Function::getGUID(FuncName);
807812
std::optional<memprof::MemProfRecord> MemProfRec;
808-
auto Err = MemProfReader.getMemProfRecord(FuncGUID).moveInto(MemProfRec);
813+
auto Err = MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec);
809814
if (Err) {
810815
handleAllErrors(std::move(Err), [&](const InstrProfError &IPE) {
811816
auto Err = IPE.get();
@@ -833,8 +838,8 @@ void MemProfUsePass::readMemprof(
833838
Twine(" Hash = ") + std::to_string(FuncGUID))
834839
.str();
835840

836-
Ctx.diagnose(DiagnosticInfoPGOProfile(F.getParent()->getName().data(),
837-
Msg, DS_Warning));
841+
Ctx.diagnose(
842+
DiagnosticInfoPGOProfile(M.getName().data(), Msg, DS_Warning));
838843
});
839844
return;
840845
}
@@ -1031,15 +1036,15 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
10311036
return PreservedAnalyses::all();
10321037
}
10331038

1034-
std::unique_ptr<IndexedInstrProfReader> IndexedReader =
1039+
std::unique_ptr<IndexedInstrProfReader> MemProfReader =
10351040
std::move(ReaderOrErr.get());
1036-
if (!IndexedReader) {
1041+
if (!MemProfReader) {
10371042
Ctx.diagnose(DiagnosticInfoPGOProfile(
1038-
MemoryProfileFileName.data(), StringRef("Cannot get IndexedReader")));
1043+
MemoryProfileFileName.data(), StringRef("Cannot get MemProfReader")));
10391044
return PreservedAnalyses::all();
10401045
}
10411046

1042-
if (!IndexedReader->hasMemoryProfile()) {
1047+
if (!MemProfReader->hasMemoryProfile()) {
10431048
Ctx.diagnose(DiagnosticInfoPGOProfile(MemoryProfileFileName.data(),
10441049
"Not a memory profile"));
10451050
return PreservedAnalyses::all();
@@ -1052,13 +1057,12 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
10521057
// it to an allocation in the IR.
10531058
std::map<uint64_t, AllocMatchInfo> FullStackIdToAllocMatchInfo;
10541059

1055-
const auto &MemProfReader = IndexedReader->getIndexedMemProfReader();
10561060
for (auto &F : M) {
10571061
if (F.isDeclaration())
10581062
continue;
10591063

10601064
const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
1061-
readMemprof(F, MemProfReader, TLI, FullStackIdToAllocMatchInfo);
1065+
readMemprof(M, F, MemProfReader.get(), TLI, FullStackIdToAllocMatchInfo);
10621066
}
10631067

10641068
if (ClPrintMemProfMatchInfo) {

llvm/unittests/Transforms/Instrumentation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ set(LLVM_LINK_COMPONENTS
99

1010
add_llvm_unittest(InstrumentationTests
1111
PGOInstrumentationTest.cpp
12-
MemProfilerTest.cpp
1312
)
1413

1514
target_link_libraries(InstrumentationTests PRIVATE LLVMTestingSupport)

llvm/unittests/Transforms/Instrumentation/MemProfilerTest.cpp

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)