diff options
-rw-r--r-- | llvm/include/llvm/ProfileData/InstrProfReader.h | 11 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/MemProfUse.cpp | 20 |
2 files changed, 31 insertions, 0 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h index deb5cd1..bccbc20 100644 --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -729,6 +729,11 @@ public: LLVM_ABI DenseMap<uint64_t, SmallVector<memprof::CallEdgeTy, 0>> getMemProfCallerCalleePairs() const; + // Returns non-owned pointer to data access profile data. + memprof::DataAccessProfData *getDataAccessProfileData() const { + return DataAccessProfileData.get(); + } + // Return the entire MemProf profile. LLVM_ABI memprof::AllMemProfData getAllMemProfData() const; @@ -900,6 +905,12 @@ public: return MemProfReader.getSummary(); } + /// Returns non-owned pointer to the data access profile data. + /// Will be null if unavailable (version < 4). + memprof::DataAccessProfData *getDataAccessProfileData() const { + return MemProfReader.getDataAccessProfileData(); + } + Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) override; Error printBinaryIds(raw_ostream &OS) override; }; diff --git a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp index a9a0731..ca8ebea 100644 --- a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp @@ -22,6 +22,7 @@ #include "llvm/IR/Function.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" +#include "llvm/ProfileData/DataAccessProf.h" #include "llvm/ProfileData/InstrProf.h" #include "llvm/ProfileData/InstrProfReader.h" #include "llvm/ProfileData/MemProfCommon.h" @@ -750,5 +751,24 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) { } } + memprof::DataAccessProfData *DataAccessProf = + MemProfReader->getDataAccessProfileData(); + + if (!DataAccessProf) { + return PreservedAnalyses::none(); + } + + for (GlobalVariable &G : M.globals()) { + bool Cold = DataAccessProf->isKnownColdSymbol(G.getName()); + std::optional<DataAccessProfRecord> Record = + DataAccessProf->getProfileRecord(G.getName()); + if (Record && Record->AccessCount > 0) { + G.setSectionPrefix("hot"); + } + if (Cold) { + G.setSectionPrefix("unlikely"); + } + } + return PreservedAnalyses::none(); } |