[llvm] [CGData] Global Merge Functions (PR #112671)
Kyungwoo Lee via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 17 13:05:09 PST 2024
================
@@ -117,7 +149,38 @@ static void removeIdenticalIndexPair(
SF->IndexOperandHashMap->erase(Pair);
}
-void StableFunctionMap::finalize() {
+static bool isProfitable(
+ const SmallVector<std::unique_ptr<StableFunctionMap::StableFunctionEntry>>
+ &SFS) {
+ unsigned StableFunctionCount = SFS.size();
+ if (StableFunctionCount < GlobalMergingMinMerges)
+ return false;
+
+ unsigned InstCount = SFS[0]->InstCount;
+ if (InstCount < GlobalMergingMinInstrs)
+ return false;
+
+ unsigned ParamCount = SFS[0]->IndexOperandHashMap->size();
+ if (ParamCount > GlobalMergingMaxParams)
+ return false;
+
+ unsigned Benefit = InstCount * (StableFunctionCount - 1);
+ unsigned Cost =
+ (GlobalMergingParamOverhead * ParamCount + GlobalMergingCallOverhead) *
----------------
kyulee-com wrote:
> it overestimated the cost for some parameters of small scalar type.
It seems we need to incorporate some type information to accurately reflect the precise cost, in theory. Since the profit model is currently computed offline, I've refined the parameter count for greater precision, as mentioned above
> FYI the implementation that comes with this PR is not passing all the existing Swift repo tests despite lowering GlobalMergingParamOverhead to 0 to force merges to happen.
Despite some differences in the underlying assumptions, I'm curious about what the existing Swift merge can accomplish that this new pass cannot.
https://github.com/llvm/llvm-project/pull/112671
More information about the llvm-commits
mailing list