Next: , Previous: Overall optimization options, Up: Optimization options   [Contents][Index]

9.10.2 High-level (HLDS -> HLDS) optimization options

These optimizations are high-level transformations on our HLDS (high-level data structure).


Disable all forms of inlining.


Disable the inlining of simple procedures.


Generate builtins (e.g. arithmetic operators) as calls to out-of-line procedures. This is done by default when debugging, as without this option the execution of builtins is not traced.


Disable the inlining of procedures called only once.

--inline-compound-threshold threshold

Inline a procedure if its size (measured roughly in terms of the number of connectives in its internal form), multiplied by the number of times it is called, is below the given threshold.

--inline-simple-threshold threshold

Inline a procedure if its size is less than the given threshold.

--intermod-inline-simple-threshold threshold

Similar to –inline-simple-threshold, except used to determine which predicates should be included in ‘.opt’ files. Note that changing this between writing the ‘.opt’ file and compiling to C may cause link errors, and too high a value may result in reduced performance.

--inline-vars-threshold threshold

Don’t inline a call if it would result in a procedure containing more than threshold variables. Procedures containing large numbers of variables can cause slow compilation.


Given a set of mutually recursive procedures (an SCC, or strongly connected component, of the call graph) in which each procedure contains exactly tail call to a procedure in the SCC, so that the tail recursive calls form a linear chain through the SCC, inline the callee at every one of those mutually tail recursive call sites. This converts mutual tail recursion into self tail recursion, which the MLDS backend can turn into code that runs in constant stack space.


Optimize loop invariants by moving computations within a loop that are the same on every iteration to the outside so they are only calculated once.


Disable optimization of common term structures.


Enable the constraint propagation transformation, which attempts to transform the code so that goals which can fail are executed as early as possible.


Enable the constraint propagation transformation, but only rearrange goals within each procedure. Specialized versions of procedures will not be created.


Don’t migrate builtin goals into branched goals.


Remove unused predicate arguments. The compiler will generate more efficient code for polymorphic predicates.


Perform unused argument removal across module boundaries. This option implies ‘--optimize-unused-args’ and ‘--intermodule-optimization’.


Remove goals from computation paths where their outputs are not needed, provided the language semantics options allow the deletion or movement of the goal.

--unneeded-code-copy-limit limit

Gives the maximum number of places to which a goal may be copied when removing it from computation paths on which its outputs are not needed. A value of zero forbids goal movement and allows only goal deletion; a value of one prevents any increase in the size of the code.


Specialize calls to higher-order predicates where the higher-order arguments are known.


Specialize calls to polymorphic predicates where the polymorphic types are known.


Enable specialization of polymorphic predicates for which there are ‘pragma type_spec’ declarations. See the “Type specialization” section in the “Pragmas” chapter of the Mercury Language Reference Manual for more details.

--higher-order-size-limit limit

Set the maximum goal size of specialized versions created by ‘--optimize-higher-order’ and ‘--type-specialization’. Goal size is measured as the number of calls, unifications and branched goals.

--higher-order-arg-limit limit

Set the maximum size of higher-order arguments to be specialized by ‘--optimize-higher-order’ and ‘--type-specialization’.


Given calls to some frequently used library functions and predicates, mainly those that do arithmetic, evaluate them at compile time, if all their input arguments are constants.


Attempt to introduce accumulating variables into procedures, so as to make the procedure tail recursive.


Enable the optimization of “last” calls that are followed by constructor application.


Enable dead procedure elimination.


Remove excess assignment unifications.


Do not attempt to interpret the format string in calls to string.format and related predicates at compile time; always leave this to be done at runtime.


When a switch on a variable has an inner switch on that same variable inside one of its arms, split up that arm of the outer switch along the same lines, effectively inlining the inner switch.


Optimize away multiple calls to a predicate with the same input arguments.


Reorder goals to move construction unifications after primitive goals that can fail.


Minimize the number of variables that have to be saved across calls.


Enable deforestation. Deforestation is a program transformation whose aim is to avoid the construction of intermediate data structures and to avoid repeated traversals over data structures within a conjunction.

--deforestation-depth-limit limit

Specify a depth limit to prevent infinite loops in the deforestation algorithm. A value of -1 specifies no depth limit. The default is 4.

--deforestation-vars-threshold threshold

Specify a rough limit on the number of variables in a procedure created by deforestation. A value of -1 specifies no limit. The default is 200.

--deforestation-size-threshold threshold

Specify a rough limit on the size of a goal to be optimized by deforestation. A value of -1 specifies no limit. The default is 15.


Try to identify those procedures that cannot throw an exception. This information can be used by some optimization passes.


Enable trail usage analysis. Identify those procedures that will not modify the trail. This information is used to reduce the overhead of trailing.


Identify those goals that do not calls procedures that are evaluated using minimal model tabling. This information is used to reduce the overhead of minimal model tabling.

Next: , Previous: Overall optimization options, Up: Optimization options   [Contents][Index]