@@ -42,43 +42,29 @@ class MemProfReader {
42
42
using Iterator = InstrProfIterator<GuidMemProfRecordPair, MemProfReader>;
43
43
Iterator end () { return Iterator (); }
44
44
Iterator begin () {
45
- Iter = FunctionProfileData .begin ();
45
+ Iter = MemProfData. Records .begin ();
46
46
return Iterator (this );
47
47
}
48
48
49
- // Take the complete profile data.
50
- IndexedMemProfData takeMemProfData () {
51
- // TODO: Once we replace the three member variables, namely IdToFrame,
52
- // CSIdToCallStack, and FunctionProfileData, with MemProfData, replace the
53
- // following code with just "return std::move(MemProfData);".
54
- IndexedMemProfData MemProfData;
55
- // Copy key-value pairs because IdToFrame uses DenseMap, whereas
56
- // IndexedMemProfData::Frames uses MapVector.
57
- for (const auto &[FrameId, F] : IdToFrame)
58
- MemProfData.Frames .try_emplace (FrameId, F);
59
- // Copy key-value pairs because CSIdToCallStack uses DenseMap, whereas
60
- // IndexedMemProfData::CallStacks uses MapVector.
61
- for (const auto &[CSId, CS] : CSIdToCallStack)
62
- MemProfData.CallStacks .try_emplace (CSId, CS);
63
- MemProfData.Records = FunctionProfileData;
64
- return MemProfData;
65
- }
49
+ // Take the complete profile data. Once this function is invoked,
50
+ // MemProfReader no longer owns the MemProf profile.
51
+ IndexedMemProfData takeMemProfData () { return std::move (MemProfData); }
66
52
67
53
virtual Error
68
54
readNextRecord (GuidMemProfRecordPair &GuidRecord,
69
55
std::function<const Frame (const FrameId)> Callback = nullptr) {
70
- if (FunctionProfileData .empty ())
56
+ if (MemProfData. Records .empty ())
71
57
return make_error<InstrProfError>(instrprof_error::empty_raw_profile);
72
58
73
- if (Iter == FunctionProfileData .end ())
59
+ if (Iter == MemProfData. Records .end ())
74
60
return make_error<InstrProfError>(instrprof_error::eof);
75
61
76
62
if (Callback == nullptr )
77
63
Callback =
78
64
std::bind (&MemProfReader::idToFrame, this , std::placeholders::_1);
79
65
80
- CallStackIdConverter<decltype (CSIdToCallStack )> CSIdConv (CSIdToCallStack,
81
- Callback);
66
+ CallStackIdConverter<decltype (MemProfData. CallStacks )> CSIdConv (
67
+ MemProfData. CallStacks , Callback);
82
68
83
69
const IndexedMemProfRecord &IndexedRecord = Iter->second ;
84
70
GuidRecord = {
@@ -97,28 +83,18 @@ class MemProfReader {
97
83
virtual ~MemProfReader () = default ;
98
84
99
85
// Initialize the MemProfReader with the given MemProf profile.
100
- MemProfReader (IndexedMemProfData MemProfData) {
101
- for (const auto &[FrameId, F] : MemProfData.Frames )
102
- IdToFrame.try_emplace (FrameId, F);
103
- for (const auto &[CSId, CS] : MemProfData.CallStacks )
104
- CSIdToCallStack.try_emplace (CSId, CS);
105
- FunctionProfileData = std::move (MemProfData.Records );
106
- }
86
+ MemProfReader (IndexedMemProfData &&MemProfData)
87
+ : MemProfData(std::move(MemProfData)) {}
107
88
108
89
protected:
109
90
// A helper method to extract the frame from the IdToFrame map.
110
91
const Frame &idToFrame (const FrameId Id) const {
111
- auto It = IdToFrame .find (Id);
112
- assert (It != IdToFrame .end () && " Id not found in map." );
113
- return It->getSecond () ;
92
+ auto It = MemProfData. Frames .find (Id);
93
+ assert (It != MemProfData. Frames .end () && " Id not found in map." );
94
+ return It->second ;
114
95
}
115
- // A mapping from FrameId (a hash of the contents) to the frame.
116
- llvm::DenseMap<FrameId, Frame> IdToFrame;
117
- // A mapping from CallStackId to the call stack.
118
- llvm::DenseMap<CallStackId, llvm::SmallVector<FrameId>> CSIdToCallStack;
119
- // A mapping from function GUID, hash of the canonical function symbol to the
120
- // memprof profile data for that function, i.e allocation and callsite info.
121
- llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> FunctionProfileData;
96
+ // A complete pacakge of the MemProf profile.
97
+ IndexedMemProfData MemProfData;
122
98
// An iterator to the internal function profile data structure.
123
99
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord>::iterator Iter;
124
100
};
0 commit comments