@@ -413,32 +413,28 @@ bool GlobalMergeFunc::merge(Module &M, const StableFunctionMap *FunctionMap) {
413413 bool Changed = false ;
414414
415415 // 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 ;
418418 auto &Maps = FunctionMap->getFunctionMap ();
419419 for (auto &F : M) {
420420 if (!isEligibleFunction (&F))
421421 continue ;
422422 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));
427425 }
428426
429427 for (auto &[Hash, Funcs] : HashToFuncs) {
430428 std::optional<ParamLocsVecTy> ParamLocsVec;
431429 SmallVector<FuncMergeInfo> FuncMergeInfos;
430+ auto &SFS = Maps.at (Hash);
431+ assert (!SFS.empty ());
432+ auto &RFS = SFS[0 ];
432433
433434 // 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) {
438436 // Check if the function is compatible with any stable function
439437 // in terms of the number of instructions and ignored operands.
440- assert (!SFS.empty ());
441- auto &RFS = SFS[0 ];
442438 if (RFS->InstCount != FI.IndexInstruction ->size ())
443439 continue ;
444440
@@ -473,8 +469,8 @@ bool GlobalMergeFunc::merge(Module &M, const StableFunctionMap *FunctionMap) {
473469 *ParamLocsVec))
474470 continue ;
475471
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.
478474 FuncMergeInfos.emplace_back (SF.get (), F, FI.IndexInstruction .get ());
479475 break ;
480476 }
0 commit comments