summaryrefslogtreecommitdiffstats
path: root/opt.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-02-01 00:04:33 -0500
committerTavian Barnes <tavianator@tavianator.com>2019-02-09 17:06:38 -0500
commitd64db6bad79e10f92c56e5572d6ae9072d62b3a3 (patch)
treef1f334c165afecd1907e9c4cf377878ba172c35a /opt.c
parent563b5f9d48e54dc2f5d61a23ce2171e005da201a (diff)
downloadbfs-d64db6bad79e10f92c56e5572d6ae9072d62b3a3.tar.xz
Add some documentation comments
Diffstat (limited to 'opt.c')
-rw-r--r--opt.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/opt.c b/opt.c
index 1157754..dd98ca0 100644
--- a/opt.c
+++ b/opt.c
@@ -14,6 +14,31 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
****************************************************************************/
+/**
+ * The expression optimizer. Different optimization levels are supported:
+ *
+ * -O1: basic logical simplifications, like folding (-true -and -foo) to -foo.
+ *
+ * -O2: dead code elimination and data flow analysis. struct opt_facts is used
+ * to record data flow facts that are true at various points of evaluation.
+ * Specifically, struct opt_facts records the facts that must be true before an
+ * expression is evaluated (state->facts), and those that must be true after the
+ * expression is evaluated, given that it returns true (state->facts_when_true)
+ * or false (state->facts_when_true). Additionally, state->facts_when_impure
+ * records the possible data flow facts before any expressions with side effects
+ * are evaluated.
+ *
+ * -O3: expression re-ordering to reduce expected cost. In an expression like
+ * (-foo -and -bar), if both -foo and -bar are pure (no side effects), they can
+ * be re-ordered to (-bar -and -foo). This is profitable if the expected cost
+ * is lower for the re-ordered expression, for example if -foo is very slow or
+ * -bar is likely to return false.
+ *
+ * -O4/-Ofast: aggressive optimizations that may affect correctness in corner
+ * cases. The main effect is to use facts_when_impure to determine if any side-
+ * effects are reachable at all, and skipping the traversal if not.
+ */
+
#include "cmdline.h"
#include "color.h"
#include "eval.h"