15
15
16
16
#include " llvm/CGData/StableFunctionMap.h"
17
17
#include " llvm/ADT/SmallSet.h"
18
- #include " llvm/CGData/StableFunctionMapRecord.h"
19
18
#include " llvm/Support/CommandLine.h"
20
19
#include " llvm/Support/Debug.h"
21
- #include < mutex>
22
20
23
21
#define DEBUG_TYPE " stable-function-map"
24
22
@@ -95,10 +93,9 @@ void StableFunctionMap::insert(const StableFunction &Func) {
95
93
96
94
void StableFunctionMap::merge (const StableFunctionMap &OtherMap) {
97
95
assert (!Finalized && " Cannot merge after finalization" );
98
- deserializeLazyLoadingEntries ();
99
96
for (auto &[Hash, Funcs] : OtherMap.HashToFuncs ) {
100
- auto &ThisFuncs = HashToFuncs[Hash]. Entries ;
101
- for (auto &Func : Funcs. Entries ) {
97
+ auto &ThisFuncs = HashToFuncs[Hash];
98
+ for (auto &Func : Funcs) {
102
99
auto FuncNameId =
103
100
getIdOrCreateForName (*OtherMap.getNameForId (Func->FunctionNameId ));
104
101
auto ModuleNameId =
@@ -117,63 +114,25 @@ size_t StableFunctionMap::size(SizeType Type) const {
117
114
case UniqueHashCount:
118
115
return HashToFuncs.size ();
119
116
case TotalFunctionCount: {
120
- deserializeLazyLoadingEntries ();
121
117
size_t Count = 0 ;
122
118
for (auto &Funcs : HashToFuncs)
123
- Count += Funcs.second .Entries . size ();
119
+ Count += Funcs.second .size ();
124
120
return Count;
125
121
}
126
122
case MergeableFunctionCount: {
127
- deserializeLazyLoadingEntries ();
128
123
size_t Count = 0 ;
129
124
for (auto &[Hash, Funcs] : HashToFuncs)
130
- if (Funcs.Entries . size () >= 2 )
131
- Count += Funcs.Entries . size ();
125
+ if (Funcs.size () >= 2 )
126
+ Count += Funcs.size ();
132
127
return Count;
133
128
}
134
129
}
135
130
llvm_unreachable (" Unhandled size type" );
136
131
}
137
132
138
- const StableFunctionMap::StableFunctionEntries &
139
- StableFunctionMap::at (HashFuncsMapType::key_type FunctionHash) const {
140
- auto It = HashToFuncs.find (FunctionHash);
141
- if (isLazilyLoaded ())
142
- deserializeLazyLoadingEntry (It);
143
- return It->second .Entries ;
144
- }
145
-
146
- void StableFunctionMap::deserializeLazyLoadingEntry (
147
- HashFuncsMapType::iterator It) const {
148
- assert (isLazilyLoaded () && " Cannot deserialize non-lazily-loaded map" );
149
- auto &[Hash, Storage] = *It;
150
- std::call_once (Storage.LazyLoadFlag ,
151
- [this , HashArg = Hash, &StorageArg = Storage]() {
152
- for (auto Offset : StorageArg.Offsets )
153
- StableFunctionMapRecord::deserializeEntry (
154
- reinterpret_cast <const unsigned char *>(Offset),
155
- HashArg, const_cast <StableFunctionMap *>(this ));
156
- });
157
- }
158
-
159
- void StableFunctionMap::deserializeLazyLoadingEntries () const {
160
- if (!isLazilyLoaded ())
161
- return ;
162
- for (auto It = HashToFuncs.begin (); It != HashToFuncs.end (); ++It)
163
- deserializeLazyLoadingEntry (It);
164
- }
165
-
166
- const StableFunctionMap::HashFuncsMapType &
167
- StableFunctionMap::getFunctionMap () const {
168
- // Ensure all entries are deserialized before returning the raw map.
169
- if (isLazilyLoaded ())
170
- deserializeLazyLoadingEntries ();
171
- return HashToFuncs;
172
- }
173
-
174
133
using ParamLocs = SmallVector<IndexPair>;
175
- static void
176
- removeIdenticalIndexPair ( StableFunctionMap::StableFunctionEntries &SFS) {
134
+ static void removeIdenticalIndexPair (
135
+ SmallVector<std::unique_ptr< StableFunctionMap::StableFunctionEntry>> &SFS) {
177
136
auto &RSF = SFS[0 ];
178
137
unsigned StableFunctionCount = SFS.size ();
179
138
@@ -200,7 +159,9 @@ removeIdenticalIndexPair(StableFunctionMap::StableFunctionEntries &SFS) {
200
159
SF->IndexOperandHashMap ->erase (Pair);
201
160
}
202
161
203
- static bool isProfitable (const StableFunctionMap::StableFunctionEntries &SFS) {
162
+ static bool isProfitable (
163
+ const SmallVector<std::unique_ptr<StableFunctionMap::StableFunctionEntry>>
164
+ &SFS) {
204
165
unsigned StableFunctionCount = SFS.size ();
205
166
if (StableFunctionCount < GlobalMergingMinMerges)
206
167
return false ;
@@ -241,11 +202,8 @@ static bool isProfitable(const StableFunctionMap::StableFunctionEntries &SFS) {
241
202
}
242
203
243
204
void StableFunctionMap::finalize (bool SkipTrim) {
244
- deserializeLazyLoadingEntries ();
245
- SmallVector<HashFuncsMapType::iterator> ToDelete;
246
205
for (auto It = HashToFuncs.begin (); It != HashToFuncs.end (); ++It) {
247
- auto &[StableHash, Storage] = *It;
248
- auto &SFS = Storage.Entries ;
206
+ auto &[StableHash, SFS] = *It;
249
207
250
208
// Group stable functions by ModuleIdentifier.
251
209
llvm::stable_sort (SFS, [&](const std::unique_ptr<StableFunctionEntry> &L,
@@ -278,7 +236,7 @@ void StableFunctionMap::finalize(bool SkipTrim) {
278
236
}
279
237
}
280
238
if (Invalid) {
281
- ToDelete. push_back (It);
239
+ HashToFuncs. erase (It);
282
240
continue ;
283
241
}
284
242
@@ -290,10 +248,8 @@ void StableFunctionMap::finalize(bool SkipTrim) {
290
248
removeIdenticalIndexPair (SFS);
291
249
292
250
if (!isProfitable (SFS))
293
- ToDelete. push_back (It);
251
+ HashToFuncs. erase (It);
294
252
}
295
- for (auto It : ToDelete)
296
- HashToFuncs.erase (It);
297
253
298
254
Finalized = true ;
299
255
}
0 commit comments