[m-rev.] for review: improve debugging support for il grade.

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Oct 29 10:01:17 AEDT 2003


On 28-Oct-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> Improve the support for debugging in the il grade, by not optimizing
> the generated il code, unless needed for verifiability.
> 
> Using
> 	mmc --make --grade il --target-debug -O0 diff
> now generates code which is relatively easier to debug in an IL
> debugger.

This is a good idea, but whether or not the generated IL code is
peephole optimized should depend on the "-O" setting, not on whether
or not --target-debug is specified.  Otherwise there's too much danger
of Heisenbugs (bugs which go away when you enabled debugging).

Currently peephole optimization is enabled at "-O0".
I'd be happy to change that so that it was instead enabled at "-O1"
for the IL back-end if and only if this speeds up compilation at "-O0".

Otherwise, I'd say use "--target-debug -O-1" or
"--target-debug -O0 --no-optimize-peep" if you want
the IL code to be maximally easy to debug.
If that is too complicated, we could consider introducing
a new option (perhaps "--opt-debug", by analogy with to "--opt-space"?),
which disabled optimizations that inhibit debugging.

> Index: compiler/il_peephole.m
...
>  	% Peephole optimize a list of instructions.
> +	% Taking into account whether or not we are generating debuggable
> +	% code.
>  
> -:- pred il_peephole__optimize(list(ilasm__decl)::in, list(ilasm__decl)::out) 
> -	is det.
> +:- pred il_peephole__optimize(bool::in,
> +		list(ilasm__decl)::in, list(ilasm__decl)::out) is det.

The documentation here should not refer to generating debuggable code,
but should instead describe the boolean in terms of what kind of
optimizations are done: only those needed for verifiability, or all
peephole optimizations.  (Actually it might be nicer to use an enum
type rather than a boolean here.)

> +optimize(TargetDebug, Decls0, Decls) :-
> +	list__map_foldl(optimize_decl(TargetDebug), Decls0, Decls, no, _Mod).
...
> +optimize_decl(TargetDebug, Decl0, Decl, Mod0, Mod) :-
...
> +optimize_class_member(TargetDebug, Decl0, Decl, Mod0, Mod) :-
...
> +optimize_instrs(TargetDebug, Instrs0, Instrs, Mod) :-
...
> +opt_instr(TargetDebug, Instr0, Instrs0, Instrs, Mod) :-

s/TargetDebug/VerifyOnly/g (thoughout this file)

> Index: compiler/mlds_to_ilasm.m
> @@ -125,11 +125,12 @@
>  
>  		% Perform peephole optimization if requested.
>  	globals__io_lookup_bool_option(optimize_peep, Peephole),
> -	{ Peephole = yes ->
> -		il_peephole__optimize(ILAsm0, ILAsm)
> +	( { Peephole = yes } ->
> +		globals__io_lookup_bool_option(target_debug, TargetDebug),
> +		{ il_peephole__optimize(TargetDebug, ILAsm0, ILAsm) }
>  	;
> -		ILAsm0 = ILAsm
> -	},
> +		{ ILAsm0 = ILAsm }
> +	),
>  		% Output the assembly.
>  	ilasm__output(ILAsm),

That code should be something like this:

			% Perform peephole optimization if requested.
			% If peephole optimization was not requested,
			% we may still need to invoke the peephole
			% optimization pass, because some of the
			% peephole optimizations are actually needed for
			% verifiability of the generated IL.
		globals__io_lookup_bool_option(optimize_peep, Peephole),
		globals__io_lookup_bool_option(verifiable_code, Verifiable),
		( { Peephole = yes } ->
			{ VerifyOnly = no },
			{ il_peephole__optimize(VerifyOnly, ILAsm0, ILAsm) }
		; { Verifiable = yes } ->
			{ VerifyOnly = yes },
			{ il_peephole__optimize(VerifyOnly, ILAsm0, ILAsm) }
		;
			{ ILAsm0 = ILAsm }
		),

			% Output the assembly.
		ilasm__output(ILAsm),

Note that this actually fixes a bug: currently, if you specify `-0-1'
and `--verifiable-code', then peephole won't be invoked, so the generated
IL will not be verifiable.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list