diff options
| author | Tamas Hadhazy <helsgithub15@gmail.com> | 2024-10-05 15:06:35 +0100 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2024-10-06 09:20:04 -0700 |
| commit | 7e6709c956ec39a26d80c8f6252a736ad40debea (patch) | |
| tree | 9c7c4199d2beabaf1cb364766bef0adc2fee194c /chapter04/README.md | |
| parent | 17439b589db2851e7315042c0359df3bff436fdb (diff) | |
| download | Simple-7e6709c956ec39a26d80c8f6252a736ad40debea.tar.gz Simple-7e6709c956ec39a26d80c8f6252a736ad40debea.zip | |
add example 2
Diffstat (limited to 'chapter04/README.md')
| -rw-r--r-- | chapter04/README.md | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/chapter04/README.md b/chapter04/README.md index 8d09320c..5cfe9c6e 100644 --- a/chapter04/README.md +++ b/chapter04/README.md @@ -365,7 +365,7 @@ regardless of whether `peephole` is called or not. ### Delete unused nodes when popping the scope A node is unused if it has no outputs(users). - Consider the following example: + ### Example 1: ``` int a = 12; // the only output it has is the scope itself return 1; @@ -447,6 +447,20 @@ we can also get rid of `ConstantNode`(`this`) from the outputs of `Start`: ``` old_def.delUse(this) ``` +### Example 2: +``` +int a = 12; +int b = a + 1; +return 1; +``` +- Call `popN` on current scope. +- Realize that `b = a + 1;` has no uses - so we can kill it. +- In the kill function we can call `popN` but this time with the inputs of `b = a + 1;`(start killing them recursively) +- We start the killing process from the back and examine "1" first. This has no output other than the `AddNode`. Since `this = AddNode` calling `delUse` will mark "1" as dead. +- We now can kill "1" and call the `popN` function with one input(the control node). +- Now we examine "a" which has 2 uses at this point, the scope and `AddNode`. Since `this = AddNode` we will remove `AddNode` from its outputs, it will still have the scope as a user - so we can't delete it just yet. +- We move onto`a = 12`, since "a" has only one user left(the scope) and `this = scope` it can get killed easily. +- Same as before, we go through the inputs of "a" and will delete them from the outputs of the control node. *A constant node pointing to "Start"(ignored by the graph visualizer) but still maintains a connection:* |
