[PATCH] D115458: [FuncSpec] Decouple Cost and Benefit analysis, to sort candidates.
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 9 11:30:43 PST 2021
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: ChuanqiXu, snehasish, labrinea.
Herald added subscribers: ormris, mgrang, hiraditya.
SjoerdMeijer requested review of this revision.
Herald added a project: LLVM.
This looks like a big change/rewrite, but it is not as bad as it looks as it mostly is the same code that is refactored to decouple the cost and benefit analysis. The biggest change is top-level function `specializeFunctions` that now drives the transformation likes this:
specializeFunctions() {
Cost = getSpecializationCost(F);
calculateGains(F, Cost);
specializeFunction(F);
}
while this is just a restructuring and decoupling of the cost and benefit analysis, this separation helps the actual functional change in `calculateGains`. We now sort the candidates based on the expected specialisation gain, which we didn't do before. For this, a book keeping struct `ArgInfo` was introduced. If we have a list of N candidates, but we only want specialise less than N as set by option -func-specialization-max-constants, we sort the list and discard the candidates that give the least benefit.
Given a formal argument, this change results in selecting the best actual argument(s). In a follow up, I want to go one step further and compare all functions and all arguments. But that will mostly build on top of this refactoring and change, and will be less change; this is enough change for now.
https://reviews.llvm.org/D115458
Files:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115458.393230.patch
Type: text/x-patch
Size: 14412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211209/1cf56aad/attachment.bin>
More information about the llvm-commits
mailing list