[PATCH] D88307: [DON'T MERGE] Jump-threading for finite state automata

Justin Kreiner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 10 13:39:33 PST 2021


jkreiner added a comment.

Hi, I just wanted to give an update about the pass @amehsan mentioned before. We revised the implementation so that it handles more general cases such as the std::merge example provided above. The core idea remains the same of using an analyze-then-transform approach to first find paths in an FSM that have the opportunity to be threaded, and then transforming them to skip over the expensive switch operation when it is possible to do so.

The main difference with the previous algorithm is that we do not expect all the paths to be contained in a single loop. Instead we look at all paths that form a cycle through some switch block. This means that we can consider every switch block in the program as a starting point. If the condition is predictable along these paths (i.e. it can be traced back to a constant) then there is an opportunity for threading. At this point we can label the blocks that decide the next state and create duplicate paths that branch directly to the next case.

There are 2 challenges we encountered that will complicate the transformation, but we have solutions for them:

1. The state variable is sometimes assigned multiple times in one iteration, and we do not know until runtime which state will be chosen. This means that one duplicated path may have to jump to another duplicated path.
2. The state variable is sometimes assigned in the switch block itself. We may be able to treat it as a special case and avoid code duplication.

Lastly, I reviewed the Codasip paper mentioned above, now available here: https://news.codasip.com/whitepaper-llvm-jump-threading.
Note that this paper is based on this thesis for KIT: https://pp.ipd.kit.edu/uploads/publikationen/priesner17masterarbeit.pdf.

I think that our approach should handle the same FSM cases as Codasip. One limitation is that we jump thread the switch entirely versus Codasip which could jump thread individual cases. It is possible to extend this algorithm in the future to jump thread individual cases, if it proves to be useful.

I am currently working out some details, but I will upstream the analysis phase of this pass shortly. In the mean time any feedback about this approach would be appreciated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88307/new/

https://reviews.llvm.org/D88307



More information about the llvm-commits mailing list