diff options
| author | Dibyendu Majumdar <dibyendumajumdar@users.noreply.github.com> | 2023-12-07 09:26:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-07 09:26:54 +0000 |
| commit | 499906b94893cb808df96810d46441857ae432d4 (patch) | |
| tree | bad8c25c95ca59065f04bf24a9791962b51af017 /chapter07/README.md | |
| parent | 6415e3ae9013e3a9ae0437553ea0c3702381469b (diff) | |
| download | Simple-499906b94893cb808df96810d46441857ae432d4.tar.gz Simple-499906b94893cb808df96810d46441857ae432d4.zip | |
Backport some of the code refactoring to previous chapters (#50)
* #44 Revise docs and comments
* #44 Add starting scope to xScopes
* #44 back some of the code refactoring port to previous chapters
* #44 add_def should not be public
* #44 add_def should not be public. Rename method names so that they are camelcase
Diffstat (limited to 'chapter07/README.md')
| -rw-r--r-- | chapter07/README.md | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/chapter07/README.md b/chapter07/README.md index c6bcdee4..3e6a7692 100644 --- a/chapter07/README.md +++ b/chapter07/README.md @@ -70,7 +70,7 @@ created until we complete parsing the loop body. This is because our phis are no ## Detailed Steps 1. We start by creating a new subclass of `Region`, the `Loop`. The `Loop` gets two control inputs, - the first one is the entry point, i.e. the current binding to `$ctrl`, and second one (`null`) is a placeholder for the back edge that is + the first is the entry point, i.e. the current binding to `$ctrl`, and second (`null`) is a placeholder for the back edge that is set after loop is parsed. The absence of a back edge is used as an indicator to switch off peepholes of the region and associated phis. @@ -94,7 +94,7 @@ created until we complete parsing the loop body. This is because our phis are no ```java // boolean loop=true if this is a loop region - String[] reverse = reverse_names(); + String[] names = reverseNames(); // Get the variable names dup.add_def(ctrl()); // Control input is just copied for( int i=1; i<nIns(); i++ ) { if ( !loop ) { dup.add_def(in(i)); } @@ -102,7 +102,7 @@ created until we complete parsing the loop body. This is because our phis are no // Loop region // Create a phi node with second input as null - to be filled in // by endLoop() below - dup.add_def(new PhiNode(reverse[i], ctrl(), in(i), null).peephole()); + dup.add_def(new PhiNode(names[i], ctrl(), in(i), null).peephole()); // Ensure our node has the same phi in case we created one set_def(i, dup.in(i)); } @@ -124,8 +124,9 @@ created until we complete parsing the loop body. This is because our phis are no Node ifF = new ProjNode(ifNode, 1, "False").peephole(); ``` -4. We set the control token to the `True` projection node `ifT`, but before that we make another clone of - the current scope. +4. We make another clone of the current scope. This will be the exit scope that will live after the loop ends, + therefore `$ctrl` in the exit scope is set to the `False` projection. + The exit scope captures any side effects of the loop's predicate. ```java // The exit scope, accounting for any side effects in the predicate @@ -133,9 +134,6 @@ created until we complete parsing the loop body. This is because our phis are no exit.ctrl(ifF); ``` - The new scope is saved as the exit scope that will live after the loop ends, therefore `$ctrl` in the exit scope is - set to the `False` projection. The exit scope captures any side effects of the loop's predicate. - 5. We now set the control to the `True` projection and parse the loop body. ```java @@ -171,7 +169,13 @@ created until we complete parsing the loop body. This is because our phis are no ``` 7. Finally, both the original scope (head) we started with, and the duplicate created for the body are killed. - At exit the false control is the current control, and exit scope is set as the current scope. + At exit the false control is the current control (step 4), and exit scope is set as the current scope. + + ```java + // At exit the false control is the current control, and + // the scope is the exit scope after the exit test. + return (_scope = exit); + ``` ### Visualization |
