diff options
| author | XmiliaH <45106915+XmiliaH@users.noreply.github.com> | 2023-10-29 18:36:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-29 10:36:17 -0700 |
| commit | 400948bc57df2088e44b25f064ff739873ee1085 (patch) | |
| tree | 6f1686e2a5a97396107149eedcbbbfe130b57673 | |
| parent | c7a3752481c3c33cc7e460a75daf2a07d2c15c25 (diff) | |
| download | Simple-400948bc57df2088e44b25f064ff739873ee1085.tar.gz Simple-400948bc57df2088e44b25f064ff739873ee1085.zip | |
Backport fix for set_def killing new_def (#21)
| -rw-r--r-- | chapter02/src/main/java/com/seaofnodes/simple/node/Node.java | 9 | ||||
| -rw-r--r-- | chapter03/src/main/java/com/seaofnodes/simple/node/Node.java | 8 |
2 files changed, 11 insertions, 6 deletions
diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java index 43dea8e1..7c39083e 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java @@ -154,6 +154,12 @@ public abstract class Node { */ void set_def(int idx, Node new_def ) { Node old_def = in(idx); + if( old_def == new_def ) return; // No change + // If new def is not null, add the corresponding def->use edge + // This needs to happen before removing the old node's def->use edge as + // the new_def might get killed if the old node kills it recursively. + if( new_def != null ) + new_def._outputs.add(this); if( old_def != null ) { // If the old def exists, remove a use->def edge ArrayList<Node> outs = old_def._outputs; int lidx = outs.size()-1; // Last index @@ -168,9 +174,6 @@ public abstract class Node { } // Set the new_def over the old (killed) edge _inputs.set(idx,new_def); - // If new def is not null, add the corresponding use->def edge - if( new_def != null ) - new_def._outputs.add(this); } diff --git a/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java index 6b7d673a..9c71c424 100644 --- a/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java @@ -155,14 +155,16 @@ public abstract class Node { Node set_def(int idx, Node new_def ) { Node old_def = in(idx); if( old_def == new_def ) return this; // No change + // If new def is not null, add the corresponding def->use edge + // This needs to happen before removing the old node's def->use edge as + // the new_def might get killed if the old node kills it recursively. + if( new_def != null ) + new_def._outputs.add(this); if( old_def != null && // If the old def exists, remove a def->use edge old_def.delUse(this) ) // If we removed the last use, the old def is now dead old_def.kill(); // Kill old def // Set the new_def over the old (killed) edge _inputs.set(idx,new_def); - // If new def is not null, add the corresponding def->use edge - if( new_def != null ) - new_def._outputs.add(this); // Return self for easy flow-coding return this; } |
