Next: , Previous: , Up: Mercury grades   [Contents][Index]


3.3 Base grades

The base grade specifies what target language to compile the Mercury program to, and if the compiler can do this in several different ways, selects one of those ways. There are three MLDS and three LLDS base grades.

The available MLDS base grades, and the option values they correspond to, are

hlc

--target c and --high-level-code

java

--target java and --high-level-code

csharp

--target c and --high-level-code

These base grades each call for the generation of relatively natural-looking code in the selected target language.

The available LLDS base grades, and the option values they correspond to, are

none

--target c, --no-high-level-code, --no-gcc-global-registers, and --no-gcc-non-local-gotos

reg

--target c, --no-no-high-level-code, --gcc-global-registers, and --no-gcc-non-local-gotos

asm_fast

--target c, --no-high-level-code, --gcc-global-registers, --gcc-non-local-gotos and --asm--labels

These base grades each call for the generation of assembly-like code in C syntax, but they differ in what GNU extensions to C, if any, the generated code will use. There are three extensions that they can potentially use:

--gcc-global-registers

specifies the use of a GNU extension that allows the generated code to tell gcc that a given global variable should be stored in a machine register. The Mercury implementation can use this mechanism to speed up access to the most frequently used virtual registers of the Mercury abstract machine, such as the return address register (which is used on every call) and the pointer to the top of the det stack (which is used at the start and end of the code of all predicates that cannot succeed more than once).

--gcc-non-local-gotos

specifies the use of a GNU extension that allows the generated code to simply take the address of a C label, store that address somewhere, and to later retrieve that address and jump to it. This speeds up transfers of control (conditional branches and unconditional jumps) within a single C function.

--asm--labels

specifies the use of a GNU extension that the address of a label to be made global, i.e. accessible from even outside the C function in which it occurs. With the appropriate precautions, which the Mercury system of course takes, this speeds up transfers of control from anywhere to anywhere else in the Mercury program.

The base grade none calls for no GNU extensions to be used. It is therefore the slowest of the LLDS base grades, but it is also the most portable. The base grade reg is faster and less portable, and the base grade asm_fast is faster and less portable still. In general, using more GNU C extensions will make the program faster, but some platforms, compilers or compiler versions do not support specific extensions.

While it is in theory possible to combine --gcc-non-local-gotos with --no-asm--labels, in practice there is no advantage in doing so. And while it is also possible to combine --gcc-non-local-gotos --asm--labels with --no-gcc-global-registers, we do not know of any platforms on which --gcc-non-local-gotos and --asm--labels work but --gcc-global-registers does not. This is why we use only three out of the eight possible combinations of the values of these three options.

The default base grade is system dependent, but will be either ‘hlc’ or ‘asm_fast’, as these are the two fastest.


Next: , Previous: , Up: Mercury grades   [Contents][Index]