@@ -413,32 +413,28 @@ bool GlobalMergeFunc::merge(Module &M, const StableFunctionMap *FunctionMap) {
413
413
bool Changed = false ;
414
414
415
415
// Collect stable functions related to the current module.
416
- DenseMap<stable_hash, SmallVector<Function *>> HashToFuncs;
417
- DenseMap<Function *, FunctionHashInfo> FuncToFI ;
416
+ DenseMap<stable_hash, SmallVector<std::pair< Function *, FunctionHashInfo>>>
417
+ HashToFuncs ;
418
418
auto &Maps = FunctionMap->getFunctionMap ();
419
419
for (auto &F : M) {
420
420
if (!isEligibleFunction (&F))
421
421
continue ;
422
422
auto FI = llvm::StructuralHashWithDifferences (F, ignoreOp);
423
- if (Maps.contains (FI.FunctionHash )) {
424
- HashToFuncs[FI.FunctionHash ].push_back (&F);
425
- FuncToFI.try_emplace (&F, std::move (FI));
426
- }
423
+ if (Maps.contains (FI.FunctionHash ))
424
+ HashToFuncs[FI.FunctionHash ].emplace_back (&F, std::move (FI));
427
425
}
428
426
429
427
for (auto &[Hash, Funcs] : HashToFuncs) {
430
428
std::optional<ParamLocsVecTy> ParamLocsVec;
431
429
SmallVector<FuncMergeInfo> FuncMergeInfos;
430
+ auto &SFS = Maps.at (Hash);
431
+ assert (!SFS.empty ());
432
+ auto &RFS = SFS[0 ];
432
433
433
434
// Iterate functions with the same hash.
434
- for (auto &F : Funcs) {
435
- auto &SFS = Maps.at (Hash);
436
- auto &FI = FuncToFI.at (F);
437
-
435
+ for (auto &[F, FI] : Funcs) {
438
436
// Check if the function is compatible with any stable function
439
437
// in terms of the number of instructions and ignored operands.
440
- assert (!SFS.empty ());
441
- auto &RFS = SFS[0 ];
442
438
if (RFS->InstCount != FI.IndexInstruction ->size ())
443
439
continue ;
444
440
@@ -473,8 +469,8 @@ bool GlobalMergeFunc::merge(Module &M, const StableFunctionMap *FunctionMap) {
473
469
*ParamLocsVec))
474
470
continue ;
475
471
476
- // As long as we found one stable function matching the current one,
477
- // we create a candidate for merging and move on to the next function.
472
+ // If a stable function matching the current one is found ,
473
+ // create a candidate for merging and proceed to the next function.
478
474
FuncMergeInfos.emplace_back (SF.get (), F, FI.IndexInstruction .get ());
479
475
break ;
480
476
}
0 commit comments