RFR: 8342943: Replace predicate walking and cloning code for main/post loops with a predicate visitor
Christian Hagedorn
chagedorn at openjdk.org
Wed Oct 30 15:37:22 UTC 2024
#### Replacing the Remaining Predicate Walking and Cloning Code
The goal is to replace and unify all the remaining custom predicate walking and cloning code currently used for:
- <s>[JDK-8341977](https://bugs.openjdk.org/browse/JDK-8341977): Loop Peeling</s> (integrated with https://github.com/openjdk/jdk/pull/21679))
- [JDK-8342943](https://bugs.openjdk.org/browse/JDK-8342943): Main and Post Loop (this PR)
- [JDK-8342945](https://bugs.openjdk.org/browse/JDK-8342945): Loop Unswitching and removing useless Assertion Predicate (upcoming)
- [JDK-8342946](https://bugs.openjdk.org/browse/JDK-8342946): Main and Post Loop (upcoming)
---
(Sections taken over from https://github.com/openjdk/jdk/pull/21679)
#### Single Template Assertion Predicate Check
This replacement allows us to have a single `TemplateAssertionPredicate::is_predicate()` check that is called for all predicate matching code. This enables the removal of uncommon traps for Template Assertion Predicates with [JDK-8342047](https://bugs.openjdk.org/browse/JDK-8342047) which is a missing piece in order to fix the remaining problems with Assertion Predicates ([JDK-8288981](https://bugs.openjdk.org/browse/JDK-8288981)).
#### Common Refactorings for all the Patches in this Series
In each of the patch, I will do similar refactoring ideas:
- Replace the existing code in the corresponding `PhaseIdealLoop` method with call to a new (or existing) predicate visitor which extends the `PredicateVisitor` interface.
- The visitor implements the Assertion Predicate `visit()` methods to implement the cloning and initialization of the Template Assertion Predicates.
- The predicate visitor is then passed to the `PredicateIterator` which walks through all predicates found at a loop and applies the visitor for each predicate.
- The visitor creates new nodes (if there are Template Assertion Predicates) either in place or at the loop entry of a target loop. In the latter case, the calling code of the `PredicateIterator` must make sure to connect the tail of the newly created predicate chain after the old loop entry to the target loop head.
- Keep the semantics which includes to only apply the Template Assertion Predicate processing if there are Parse Predicates. This limitation should eventually be removed. But I want to do that separately at a later point.
---
#### Refactorings of this Patch
This patch replaces the predicate walking and cloning code for **main and post loops**. The code can reuse the code established with [JDK-8341977](https://bugs.openjdk.org/browse/JDK-8341977).This patch includes:
- Replacing Assertion Predicate code for the main loop.
- Replacing Assertion Predicate code for the post loop:
- Moved code inside `insert_post_loop()` to solve two problems:
- Before this patch, Assertion Predicates for the main and post loop have only been created after creating the pre and post loop. This made the rewiring logic for data nodes more complicated because we could have nodes being part of the pre, main or post loop. By moving the Assertion Predicate creation to `insert_post_loop()`, we do not need to worry about the pre loop data nodes (not created, yet) when processing the post loop. Similarly, we do not need to worry about the post loop data nodes (already processed) when creating Assertion Predicates for the main loop.
- A post loop is also inserted as vector post loop with `insert_vector_post_loop()`. I'm not sure if there was a problem with omitting the Assertion Predicates there. Either way, it's now fixed for any kind of post loop.
- To correctly rewire data dependencies, we need to check if a node is part of the original loop body or the cloned loop body. To do that, I've introduced an interface `NodeInLoopBody` with [JDK-8341977](https://bugs.openjdk.org/browse/JDK-8341977) with an implementation for the original loop body (i.e. `NodeInOriginalLoopBody`). We now also need the other case and thus I've added the class `NodeInClonedLoopBody`.
Thanks,
Christian
-------------
Commit messages:
- swap parameters
- 8342943: Replace predicate walking and cloning code for main/post loops with a predicate visitor
Changes: https://git.openjdk.org/jdk/pull/21790/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=21790&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8342943
Stats: 275 lines in 5 files changed: 94 ins; 164 del; 17 mod
Patch: https://git.openjdk.org/jdk/pull/21790.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21790/head:pull/21790
PR: https://git.openjdk.org/jdk/pull/21790
More information about the hotspot-compiler-dev
mailing list