[PATCH] D106426: [FuncSpec] Support specialising recursive functions
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 21 01:08:56 PDT 2021
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: ChuanqiXu, chill, jaykang10, fhahn.
Herald added subscribers: snehasish, ormris, hiraditya.
SjoerdMeijer requested review of this revision.
Herald added a project: LLVM.
This adds support for specialising recursive functions. For example, consider this program:
int Global = 1;
void recursiveFunc(int *arg) {
if (*arg < 4) {
print(*arg);
recursiveFunc(*arg + 1);
}
}
void main() {
recursiveFunc(&Global);
}
after 3 iterations of function specialisation, followed by inlining of the specialised versions of `recursiveFunc`, the main function looks like this:
void main() {
print(1);
print(2);
print(3);
}
To support this, the following has been added:
- Update the solver and state of the new specialised functions,
- An optimisation to propagate constant stack values after each iteration of function specialisation, which is necessary for the next iteration to recognise the constant values and trigger.
https://reviews.llvm.org/D106426
Files:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive.ll
llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll
llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll
llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll
llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106426.360374.patch
Type: text/x-patch
Size: 18389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210721/f8d17deb/attachment.bin>
More information about the llvm-commits
mailing list