Monday, March 28, 2011

Optimization Levels

-O optimization levels run from -1 to 6. Which options are enabled in these levels don’t seem to be documented in the User’s Guide or the mmc(1) man page. They are however documented in the compiler source code. -O2 is the default.

Note: Order matters! For example, --introduce-accumulators followed by -O6 will actually disable --introduce-accumulators, because it is disabled in -O6. For this reason you should put -O options first on the command line.

-O-1

Disables all optimizations which can be disabled.
  • --no-common-data
  • --no-llds-optimize
  • --no-optimize-jumps
  • --no-optimize-labels
  • --no-optimize-peep
  • --no-smart-indexing
  • --no-static-ground-cells

-O0

Minimizes compilation time.
  • --excess-assign
  • --optimize-dead-procs
  • --optimize-repeat 1
  • --no-c-optimize
  • --no-emit-c-loops
  • --no-middle-rec
  • --no-optimize-delay-slot
  • --no-optimize-frames
  • --no-optimize-tailcalls
  • --no-use-local-vars

-O1

Cheap optimizations with good payoff.
  • --no-common-struct
  • --no-follow-code
  • --no-inline-simple
  • --no-inline-single-use
  • --no-optimize-fulljumps
  • --no-optimize-initializations
  • --no-simple-neg

-O2

Optimizations with good payoff.
  • --inline-compound-threshold 10
  • --optimize-dups
  • --optimize-repeat 1
  • --user-guided-type-specialization

-O3

Slow optimizations with good payoff.
  • --constraint-propagation
  • --deforestation
  • --local-constraint-propagation
  • --optimize-higher-order
  • --optimize-reassign
  • --optimize-repeat 4
  • --optimize-saved-vars
  • --optimize-unused-args

-O4

Slow optimizations.
  • --higher-order-size-limit 30
  • --inline-compound-threshold 20
  • --inline-simple-threshold 8

-O5

Very slow optimizations.
  • --delay-constructs
  • --eliminate-local-vars
  • --higher-order-size-limit 40
  • --inline-compound-threshold 100
  • --loop-invariants
  • --optimize-repeat 5

-O6

Unreasonably slow optimizations.
  • --everything-in-one-c-function
  • --inline-alloc
  • --use-macro-for-redo-fail

--optimize-space

Optimize for code size rather than speed. This can be used in conjunction with one of the other levels, keeping in mind the aforementioned rules of ordering.
  • --optimize-dead-procs
  • --optimize-dups
  • --optimize-proc-dups
  • --optimize-reassign
  • --unneeded-code-copy-limit 1
  • --no-optimize-fulljumps

Additionally, --optimize-space turns off the following options if set:
  • --inline-alloc
  • --loop-invariants
  • --use-macro-for-redo-fail
  • --no-optimize-labels

Optimizations never enabled

These can make code run slower.
  • --checked-nondet-tailcalls
  • --constraint-propagation
  • --introduce-accumulators (buggy with trailed updates)
  • --optimize-constructor-last-call
  • --optimize-duplicate-calls (buggy with array.init)
  • --type-specialization
  • --unneeded-code

Additionally, intermodule optimizations are never enabled by -O because they require special handling by mmc --make.

No comments:

Post a Comment