Skip to content

Commit 885ac29

Browse files
committed
[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.
1 parent 81935c5 commit 885ac29

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

llvm/include/llvm/Analysis/CtxProfAnalysis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_ANALYSIS_CTXPROFANALYSIS_H
1010
#define LLVM_ANALYSIS_CTXPROFANALYSIS_H
1111

12-
#include "llvm/ADT/DenseMap.h"
1312
#include "llvm/IR/GlobalValue.h"
1413
#include "llvm/IR/InstrTypes.h"
1514
#include "llvm/IR/IntrinsicInst.h"

llvm/include/llvm/ProfileData/PGOCtxProfReader.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
#ifndef LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
1616
#define LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
1717

18-
#include "llvm/ADT/DenseSet.h"
1918
#include "llvm/Bitstream/BitstreamReader.h"
2019
#include "llvm/IR/GlobalValue.h"
2120
#include "llvm/ProfileData/PGOCtxProfWriter.h"
2221
#include "llvm/Support/Error.h"
2322
#include <map>
24-
#include <vector>
2523

2624
namespace llvm {
2725
/// A node (context) in the loaded contextual profile, suitable for mutation
@@ -34,7 +32,7 @@ namespace llvm {
3432
class PGOCtxProfContext final {
3533
public:
3634
using CallTargetMapTy = std::map<GlobalValue::GUID, PGOCtxProfContext>;
37-
using CallsiteMapTy = DenseMap<uint32_t, CallTargetMapTy>;
35+
using CallsiteMapTy = std::map<uint32_t, CallTargetMapTy>;
3836

3937
private:
4038
friend class PGOCtxProfileReader;
@@ -97,7 +95,16 @@ class PGOCtxProfContext final {
9795
return Callsites.find(I)->second;
9896
}
9997

100-
void getContainedGuids(DenseSet<GlobalValue::GUID> &Guids) const;
98+
/// Insert this node's GUID as well as the GUIDs of the transitive closure of
99+
/// child nodes, into the provided set (technically, all that is required of
100+
/// `TSetOfGUIDs` is to have an `insert(GUID)` member)
101+
template <class TSetOfGUIDs>
102+
void getContainedGuids(TSetOfGUIDs &Guids) const {
103+
Guids.insert(GUID);
104+
for (const auto &[_, Callsite] : Callsites)
105+
for (const auto &[_, Callee] : Callsite)
106+
Callee.getContainedGuids(Guids);
107+
}
101108
};
102109

103110
class PGOCtxProfileReader final {

llvm/lib/ProfileData/PGOCtxProfReader.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ PGOCtxProfContext::getOrEmplace(uint32_t Index, GlobalValue::GUID G,
4444
return Iter->second;
4545
}
4646

47-
void PGOCtxProfContext::getContainedGuids(
48-
DenseSet<GlobalValue::GUID> &Guids) const {
49-
Guids.insert(GUID);
50-
for (const auto &[_, Callsite] : Callsites)
51-
for (const auto &[_, Callee] : Callsite)
52-
Callee.getContainedGuids(Guids);
53-
}
54-
5547
Expected<BitstreamEntry> PGOCtxProfileReader::advance() {
5648
return Cursor.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);
5749
}

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ class WorkloadImportsManager : public ModuleImportsManager {
722722
return;
723723
}
724724
const auto &CtxMap = *Ctx;
725-
DenseSet<GlobalValue::GUID> ContainedGUIDs;
725+
SetVector<GlobalValue::GUID> ContainedGUIDs;
726726
for (const auto &[RootGuid, Root] : CtxMap) {
727727
// Avoid ContainedGUIDs to get in/out of scope. Reuse its memory for
728728
// subsequent roots, but clear its contents.

0 commit comments

Comments
 (0)