[all-commits] [llvm/llvm-project] 30fbb0: [FuncSpec] Support specialising recursive functions

sjoerdmeijer via All-commits all-commits at lists.llvm.org
Wed Aug 4 00:42:17 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 30fbb06979077740961ebc46853e28ab1f999f9d
      https://github.com/llvm/llvm-project/commit/30fbb06979077740961ebc46853e28ab1f999f9d
  Author: Sjoerd Meijer <sjoerd.meijer at arm.com>
  Date:   2021-08-04 (Wed, 04 Aug 2021)

  Changed paths:
    M llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
    M llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll

  Log Message:
  -----------
  [FuncSpec] Support specialising recursive functions

This adds support for specialising recursive functions. For example:

    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.

Specialising recursive functions is (at the moment) controlled by option
-func-specialization-max-iters and is opt-in for compile-time reasons. I.e.,
the default is -func-specialization-max-iters=1, but for the example above we
would need to use -func-specialization-max-iters=3. Future work is to see if we
can increase the default, or improve the cost-model/heuristics to control
compile-times.

Differential Revision: https://reviews.llvm.org/D106426




More information about the All-commits mailing list