[m-dev.] for review: MLDS switch optimization
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Nov 9 04:06:00 AEDT 2000
On 09-Nov-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> On 07-Nov-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > @@ -1756,6 +1776,9 @@
> > =(Info),
> > { ml_gen_info_get_module_info(Info, ModuleInfo) },
> > { module_info_globals(ModuleInfo, Globals) }.
> > +
> > +ml_gen_info_new_label(Label, Info, Info^label := Label) :-
> > + Label = Info^label + 1.
> >
> > ml_gen_info_new_func_label(Label, Info, Info^func_label := Label) :-
> > Label = Info^func_label + 1.
>
> We should really use the counter module in the library to implement
> counters such as this.
Yes. I just haven't gotten around to that yet.
The surrounding code was written before the existance of the
counter module and for this change I thought it best to
be consistent with the surrounding code.
> > -/******
> > - % Is it worth including this? We already have `computed_goto'...
> > + % This representation for switches is very general:
> > + % it allows switching on any type, and cases can match
> > + % on ranges as well as on values.
> > + % Many target languages only allow switches on ints or enums.
> > + % Some (e.g. C#) also allow switches on strings.
> > + % Most target languages only allow matching on values;
> > + % only some (e.g. GNU C) allow matching on ranges.
>
> This comment is fine, but it doesn't say what the consequences are.
> Should the backend be responsible for simplifying switches to what is
> available, or should the MLDS code generator look at the backend before
> generating a switch? (your code does the latter).
OK, good point. I'll add
% The MLDS code generator should only generate switches
% that the target will support.
> > +mlds_output_case_cond(Indent, Context, match_range(Low, High)) -->
> > + % This uses the GNU C extension `case <Low> ... <High>:'.
> > + mlds_indent(Context, Indent),
> > + io__write_string("case "),
> > + mlds_output_rval(Low),
> > + io__write_string(" ... "),
> > + mlds_output_rval(High),
> > + io__write_string(":\n").
>
> Isn't this going to cause Pete Ross to thump you when it breaks the
> VC++ backend?
>
> Have I missed the bit where you avoid generating this for non GNU C
> compilers? Or is it not used yet?
Currently this is not used, since the MLDS code generator doesn't
generate switches with `match_range' cases. I just put it in to
keep the MLDS data structure as general as possible.
(Perhaps I'm overdoing the generality here...)
For the IL back-end, feel free to handle match_range by just calling
error/1.
> > +% This option is not yet documented because it is not yet useful -- currently
> > +% we don't take advantage of GNU C's computed gotos extension.
> > +% "--no-prefer-switch",
> > +% "\tGenerate code using computed gotos rather than switches.",
> > +% "\tThis makes the generated code less readable, but potentially",
> > +% "\tslightly more efficient.",
> > +% "\tThis option has no effect unless the `--high-level-code' option",
> > +% "\tis enabled. It also has no effect if the `--target' option is",
> > +% "\tset to `il'.",
> > +
>
> Perhaps you're over-doing it by adding commented out documentation to
> describe the cases where an unimplemented option has no effect.
The option in question _is_ implemented ;-)
It's just not yet useful.
We do use MLDS computed gotos. If you use the option, you will see
that we generate different C code as a result. It's just that in the
mlds_to_c stage we map those to ordinary C switches and gotos, rather
than to GNU C computed gotos, and so the result is no more efficient.
Given that it's no more efficient and that it's less readable, it's
not useful.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list