[m-rev.] for post-commit review: eliminate more redundant work

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Sep 8 23:50:58 AEST 2009


On Tue, 8 Sep 2009, Zoltan Somogyi wrote:

> More compiler speedups for hlc grades by eliminating redundant work.
>
> compiler/c_util.m:
> 	c_util.set_line_num used to account for 7% of the compilation time
> 	on training_cars_full.m, mostly because of unnecessary name mangling,
> 	as well as repeated lookups of the line_numbers option.
>
> 	After this diff, we don't mangle names that do not need to be mangled
> 	(testing the need for mangling as rarely as possible), and we provide
> 	a means for our caller to tell us that line numbers are required,
> 	since in some cases they already know.

...

> Index: compiler/c_util.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/c_util.m,v
> retrieving revision 1.41
> diff -u -b -r1.41 c_util.m
> --- compiler/c_util.m	24 Aug 2009 07:29:41 -0000	1.41
> +++ compiler/c_util.m	4 Sep 2009 07:11:36 -0000

...

> +    % Decide whether the given string can be printed directly, using
> +    % io.write_string, rather than output_quoted_string. The latter can take
> +    % more than 7% of the compiler's runtime!
> +    %
> +:- pred can_print_directly(string::in, bool::out, io::di, io::uo) is det.
> +
> +can_print_directly(_, no, !IO).
> +
> +:- pragma foreign_proc("C",
> +    can_print_directly(Str::in, CanPrintDirectly::out, _IO0::di, _IO::uo),
> +    [will_not_call_mercury, promise_pure],
> +"{
> +    static  MR_String   last_string;
> +    static  MR_bool     last_can_print_directly;
> +    MR_bool             can_print_directly;
> +    const char          *s;
> +    int                 len;
> +
> +    /* We cache the result of the last decision. */
> +    if (Str == last_string) {
> +        CanPrintDirectly = last_can_print_directly;
> +    } else {
> +        can_print_directly = MR_TRUE;
> +
> +        for (s = Str; *s != '\\0'; s++) {
> +            if (! (isalnum(*s) || *s == '_' || *s == '/' || *s == '.')) {
> +                can_print_directly = MR_FALSE;
> +                printf(""XXX %d XXX\\n"", *s);
> +                break;

Presumably the printf() there should not be there.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list