39
39
#include " llvm/Support/CommandLine.h"
40
40
#include " llvm/Support/Debug.h"
41
41
#include " llvm/Support/HashBuilder.h"
42
+ #include " llvm/Support/VirtualFileSystem.h"
42
43
#include " llvm/TargetParser/Triple.h"
43
44
#include " llvm/Transforms/Utils/BasicBlockUtils.h"
44
45
#include " llvm/Transforms/Utils/ModuleUtils.h"
@@ -54,7 +55,6 @@ namespace llvm {
54
55
extern cl::opt<bool > PGOWarnMissing;
55
56
extern cl::opt<bool > NoPGOWarnMismatch;
56
57
extern cl::opt<bool > NoPGOWarnMismatchComdatWeak;
57
- using AllocMatchInfo = ::llvm::MemProfUsePass::AllocMatchInfo;
58
58
} // namespace llvm
59
59
60
60
constexpr int LLVM_MEM_PROFILER_VERSION = 1 ;
@@ -148,11 +148,10 @@ static cl::opt<int> ClDebugMax("memprof-debug-max", cl::desc("Debug max inst"),
148
148
149
149
// By default disable matching of allocation profiles onto operator new that
150
150
// 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 (
154
153
" memprof-match-hot-cold-new" ,
155
- cl::desc (
154
+ cl::desc (
156
155
" Match allocation profiles onto existing hot/cold operator new calls" ),
157
156
cl::Hidden, cl::init(false ));
158
157
@@ -790,11 +789,17 @@ static bool isAllocationWithHotColdVariant(Function *Callee,
790
789
}
791
790
}
792
791
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 ();
798
803
// Previously we used getIRPGOFuncName() here. If F is local linkage,
799
804
// getIRPGOFuncName() returns FuncName with prefix 'FileName;'. But
800
805
// llvm-profdata uses FuncName in dwarf to create GUID which doesn't
@@ -805,7 +810,7 @@ void MemProfUsePass::readMemprof(
805
810
auto FuncName = F.getName ();
806
811
auto FuncGUID = Function::getGUID (FuncName);
807
812
std::optional<memprof::MemProfRecord> MemProfRec;
808
- auto Err = MemProfReader. getMemProfRecord (FuncGUID).moveInto (MemProfRec);
813
+ auto Err = MemProfReader-> getMemProfRecord (FuncGUID).moveInto (MemProfRec);
809
814
if (Err) {
810
815
handleAllErrors (std::move (Err), [&](const InstrProfError &IPE) {
811
816
auto Err = IPE.get ();
@@ -833,8 +838,8 @@ void MemProfUsePass::readMemprof(
833
838
Twine (" Hash = " ) + std::to_string (FuncGUID))
834
839
.str ();
835
840
836
- Ctx.diagnose (DiagnosticInfoPGOProfile (F. getParent ()-> getName (). data (),
837
- Msg, DS_Warning));
841
+ Ctx.diagnose (
842
+ DiagnosticInfoPGOProfile (M. getName (). data (), Msg, DS_Warning));
838
843
});
839
844
return ;
840
845
}
@@ -1031,15 +1036,15 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
1031
1036
return PreservedAnalyses::all ();
1032
1037
}
1033
1038
1034
- std::unique_ptr<IndexedInstrProfReader> IndexedReader =
1039
+ std::unique_ptr<IndexedInstrProfReader> MemProfReader =
1035
1040
std::move (ReaderOrErr.get ());
1036
- if (!IndexedReader ) {
1041
+ if (!MemProfReader ) {
1037
1042
Ctx.diagnose (DiagnosticInfoPGOProfile (
1038
- MemoryProfileFileName.data (), StringRef (" Cannot get IndexedReader " )));
1043
+ MemoryProfileFileName.data (), StringRef (" Cannot get MemProfReader " )));
1039
1044
return PreservedAnalyses::all ();
1040
1045
}
1041
1046
1042
- if (!IndexedReader ->hasMemoryProfile ()) {
1047
+ if (!MemProfReader ->hasMemoryProfile ()) {
1043
1048
Ctx.diagnose (DiagnosticInfoPGOProfile (MemoryProfileFileName.data (),
1044
1049
" Not a memory profile" ));
1045
1050
return PreservedAnalyses::all ();
@@ -1052,13 +1057,12 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
1052
1057
// it to an allocation in the IR.
1053
1058
std::map<uint64_t , AllocMatchInfo> FullStackIdToAllocMatchInfo;
1054
1059
1055
- const auto &MemProfReader = IndexedReader->getIndexedMemProfReader ();
1056
1060
for (auto &F : M) {
1057
1061
if (F.isDeclaration ())
1058
1062
continue ;
1059
1063
1060
1064
const TargetLibraryInfo &TLI = FAM.getResult <TargetLibraryAnalysis>(F);
1061
- readMemprof (F, MemProfReader, TLI, FullStackIdToAllocMatchInfo);
1065
+ readMemprof (M, F, MemProfReader. get () , TLI, FullStackIdToAllocMatchInfo);
1062
1066
}
1063
1067
1064
1068
if (ClPrintMemProfMatchInfo) {
0 commit comments