[llvm] 885ac29 - [nfc][ctx_prof] Change some internal "set" types
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 10:35:01 PDT 2024
Author: Mircea Trofin
Date: 2024-09-12T10:34:53-07:00
New Revision: 885ac29910a23db923292fe3fc09d0ec105186dc
URL: https://github.com/llvm/llvm-project/commit/885ac29910a23db923292fe3fc09d0ec105186dc
DIFF: https://github.com/llvm/llvm-project/commit/885ac29910a23db923292fe3fc09d0ec105186dc.diff
LOG: [nfc][ctx_prof] Change some internal "set" types
- the set used for targets under a callsite is simpler to use if iterators
are stable (it gets manipulated during updates)
- the set used to fetch the transitive closure of GUIDs under a node can
be left as a choice to the user.
Added:
Modified:
llvm/include/llvm/Analysis/CtxProfAnalysis.h
llvm/include/llvm/ProfileData/PGOCtxProfReader.h
llvm/lib/ProfileData/PGOCtxProfReader.cpp
llvm/lib/Transforms/IPO/FunctionImport.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index d3b7ba96e4faa5..b3e64b26ee543c 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -9,7 +9,6 @@
#ifndef LLVM_ANALYSIS_CTXPROFANALYSIS_H
#define LLVM_ANALYSIS_CTXPROFANALYSIS_H
-#include "llvm/ADT/DenseMap.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/IntrinsicInst.h"
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
index e03481916dd48a..beda07d7b8286c 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
@@ -15,13 +15,11 @@
#ifndef LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
#define LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
-#include "llvm/ADT/DenseSet.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/ProfileData/PGOCtxProfWriter.h"
#include "llvm/Support/Error.h"
#include <map>
-#include <vector>
namespace llvm {
/// A node (context) in the loaded contextual profile, suitable for mutation
@@ -34,7 +32,7 @@ namespace llvm {
class PGOCtxProfContext final {
public:
using CallTargetMapTy = std::map<GlobalValue::GUID, PGOCtxProfContext>;
- using CallsiteMapTy = DenseMap<uint32_t, CallTargetMapTy>;
+ using CallsiteMapTy = std::map<uint32_t, CallTargetMapTy>;
private:
friend class PGOCtxProfileReader;
@@ -97,7 +95,16 @@ class PGOCtxProfContext final {
return Callsites.find(I)->second;
}
- void getContainedGuids(DenseSet<GlobalValue::GUID> &Guids) const;
+ /// Insert this node's GUID as well as the GUIDs of the transitive closure of
+ /// child nodes, into the provided set (technically, all that is required of
+ /// `TSetOfGUIDs` is to have an `insert(GUID)` member)
+ template <class TSetOfGUIDs>
+ void getContainedGuids(TSetOfGUIDs &Guids) const {
+ Guids.insert(GUID);
+ for (const auto &[_, Callsite] : Callsites)
+ for (const auto &[_, Callee] : Callsite)
+ Callee.getContainedGuids(Guids);
+ }
};
class PGOCtxProfileReader final {
diff --git a/llvm/lib/ProfileData/PGOCtxProfReader.cpp b/llvm/lib/ProfileData/PGOCtxProfReader.cpp
index 8354e30bd30679..496854e63c5653 100644
--- a/llvm/lib/ProfileData/PGOCtxProfReader.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfReader.cpp
@@ -44,14 +44,6 @@ PGOCtxProfContext::getOrEmplace(uint32_t Index, GlobalValue::GUID G,
return Iter->second;
}
-void PGOCtxProfContext::getContainedGuids(
- DenseSet<GlobalValue::GUID> &Guids) const {
- Guids.insert(GUID);
- for (const auto &[_, Callsite] : Callsites)
- for (const auto &[_, Callee] : Callsite)
- Callee.getContainedGuids(Guids);
-}
-
Expected<BitstreamEntry> PGOCtxProfileReader::advance() {
return Cursor.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);
}
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index ff0d78178bd188..261731fd565b02 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -722,7 +722,7 @@ class WorkloadImportsManager : public ModuleImportsManager {
return;
}
const auto &CtxMap = *Ctx;
- DenseSet<GlobalValue::GUID> ContainedGUIDs;
+ SetVector<GlobalValue::GUID> ContainedGUIDs;
for (const auto &[RootGuid, Root] : CtxMap) {
// Avoid ContainedGUIDs to get in/out of scope. Reuse its memory for
// subsequent roots, but clear its contents.
More information about the llvm-commits
mailing list