mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 10 Add constant propagation within modules. This occurs during simplification and simply attempts to evaluate "known" calls that have all their inputs bound to constants and replaces the call with constructions of the outputs. Currently the "known" calls are (most) of the arithmetic predicates, and the comparison of ints and floats. compiler/instmap.m: add merge_instmap_deltas which merges a list of intmap deltas rather than just two of them. compiler/mercury_compile.m: compiler/options.m: add (and use) the option --optimize-constant-propagation compiler/simplify.m: add a bool to the simplify struct to turn on/off constant propagation. in the simplification of calls, check to see if all the inputs are bound to constants. If we know how to evaluate this call at compile time, then do so. This may change the instmap delta. For branched goals, we merge the instmap deltas to recompute the instmap delta for the goal as a whole so that we know when every branch binds a variable to the same constant. compiler/notes/compiler_design.html: mention constant propagation. doc/user_guide.texi: mention constant propagation. compiler/const_prop.m: code that attempts to evaluate calls at compile time. It contains tables of calls that we know how to evaluate.