From 95276331d269cf0d93c242fcd5dfaab909237df7 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 6 Oct 2024 09:19:00 -0700 Subject: Update DCE comments --- chapter04/README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/chapter04/README.md b/chapter04/README.md index 8bf29f94..e71ff8a7 100644 --- a/chapter04/README.md +++ b/chapter04/README.md @@ -352,16 +352,21 @@ The peephole method does following: `peephole()` calls `deadCodeElim()` which is shown below. -## Dead Code Elimination(DCE) -We call DCE every time we lose a use of a Node; when replacing via peeps and exciting scopes. -DCE recursively deletes Nodes: +## Dead Code Elimination(DCE) -- `delUse` deletes a Node use; if the use count goes to zero recursively. -- `kill` deletes all inputs on self, while calling `delUse` to remove the matching use. +We call `kill` every time a Node makes the 1-user-to-0-users transition during +graph editing. This commonly happens when replacing via peeps and exiting +scopes. This recursive `kill` amounts to Dead Code Elimination in many other +compilers; here we call it in a very fine-grained way. Many Nodes will be +created by the parser, only to be killed before the very next lexeme is parsed. For more information please read the [appendix section](appendix/dce.md#appendix) on dead code elimination. +The suggestively called `deadCodeElim` function is a thin wrapper over `kill` +used by `peepholeOpt` to avoid prematurely killing a Node which only briefly +makes the 1->0 users transition. + ```java // m is the new Node, self is the old. // Return 'm', which may have zero uses but is alive nonetheless. -- cgit v1.2.3