Go to the first, previous, next, last section, table of contents.

`-O*': convenient "packages" of optimisation flags.

There are many options that affect the quality of code produced by GHC. Most people only have a general goal, something like "Compile quickly" or "Make my program run like greased lightning." The following "packages" of optimisations (or lack thereof) should suffice.

Once you choose a `-O*' "package," stick with it -- don't chop and change. Modules' interfaces will change with a shift to a new `-O*' option, and you may have to recompile a large chunk of all importing modules before your program can again be run safelysection See section The recompilation checker.

No `-O*'-type option specified:
This is taken to mean: "Please compile quickly; I'm not over-bothered about compiled-code quality." So, for example: `ghc -c Foo.hs'
`-O' or `-O1':
Means: "Generate good-quality code without taking too long about it." Thus, for example: `ghc -c -O Main.lhs'
Means: "Apply every non-dangerous optimisation, even if it means significantly longer compile times." The avoided "dangerous" optimisations are those that can make runtime or space worse if you're unlucky. They are normally turned on or off individually. At the moment, `-O2' is unlikely to produce better code than `-O'.
Compile via C, and don't use the native-code generator. (There are many cases when GHC does this on its own.) You might pick up a little bit of speed by compiling via C. If you use `_ccall_'s or `_casm_'s, you probably have to use `-fvia-C'. The lower-case incantation, `-fvia-c', is synonymous.
Says to run GCC with `-O2', which may be worth a few percent in execution speed. Don't forget `-fvia-C', lest you use the native-code generator and bypass GCC altogether!
This option will make GHC "forget" any -Oish options it has seen so far. Sometimes useful; for example: `make all EXTRA_HC_OPTS=-Onot'.
`-Ofile <file>':
For those who need absolute control over exactly what options are used (e.g., compiler writers, sometimes :-), a list of options can be put in a file and then slurped in with `-Ofile'. In that file, comments are of the `#'-to-end-of-line variety; blank lines and most whitespace is ignored. Please ask if you are baffled and would like an example of `-Ofile'!

At Glasgow, we don't use a `-O*' flag for day-to-day work. We use `-O' to get respectable speed; e.g., when we want to measure something. When we want to go for broke, we tend to use `-O -fvia-C -O2-for-C' (and we go for lots of coffee breaks).

The easiest way to see what `-O' (etc) "really mean" is to run with `-v', then stand back in amazement. Alternatively, just look at the `@HsC_minus<blah>' lists in the `ghc' driver script.

Go to the first, previous, next, last section, table of contents.