[llvm] [CGData] Global Merge Functions (PR #112671)
Zhaoxuan Jiang via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 17 01:25:42 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) *
----------------
nocchijiang wrote:
`GlobalMergingParamOverhead` could potentially be fine grained for different kinds of constant. I ran some tests from Swift repo to test the compatibility between the Apple implementation and this one, and found that some tested functions were not merged because it overestimated the cost for some parameters of small scalar type. This should not make a noticeable difference in production, though.
https://github.com/llvm/llvm-project/pull/112671
More information about the llvm-commits
mailing list