[llvm] [FuncSpec] Only compute Latency bonus when necessary (PR #113159)
Hari Limaye via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 09:22:04 PDT 2024
================
@@ -875,48 +909,67 @@ bool FunctionSpecializer::findSpecializations(Function *F, unsigned FuncSize,
AllSpecs[Index].CallSites.push_back(&CS);
} else {
// Calculate the specialisation gain.
- Bonus B;
+ Cost CodeSize;
unsigned Score = 0;
InstCostVisitor Visitor = getInstCostVisitorFor(F);
for (ArgInfo &A : S.Args) {
- B += Visitor.getSpecializationBonus(A.Formal, A.Actual);
+ CodeSize += Visitor.getCodeSizeSavingsForArg(A.Formal, A.Actual);
Score += getInliningBonus(A.Formal, A.Actual);
}
- B += Visitor.getBonusFromPendingPHIs();
-
+ CodeSize += Visitor.getCodeSizeSavingsFromPendingPHIs();
- LLVM_DEBUG(dbgs() << "FnSpecialization: Specialization bonus {CodeSize = "
- << B.CodeSize << ", Latency = " << B.Latency
- << ", Inlining = " << Score << "}\n");
-
- FunctionGrowth[F] += FuncSize - B.CodeSize;
-
- auto IsProfitable = [](Bonus &B, unsigned Score, unsigned FuncSize,
- unsigned FuncGrowth) -> bool {
+ auto IsProfitable = [&]() -> bool {
// No check required.
if (ForceSpecialization)
return true;
+
+ unsigned CodeSizeSavings = getCostValue(CodeSize);
+ // TODO: We should only accumulate codesize increase of specializations
+ // that are actually created.
+ FunctionGrowth[F] += FuncSize - CodeSizeSavings;
----------------
hazzlim wrote:
Yeah actually - that still wouldn't work because we wouldn't be able to distinguish if the Score represented CodeSizeSavings or inlining bonus. I think we'd need to add something like `CodeSizeCost` to the `Spec` struct in order to pass this information through to where we actually do the specializations?
My feeling is that it would make the most sense to leave this as it is for this PR and make these changes in a follow up PR, if you agree?
https://github.com/llvm/llvm-project/pull/113159
More information about the llvm-commits
mailing list