[m-rev.] for review: gcc 4 with llds grades

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Nov 24 20:12:34 AEDT 2009


On Mon, 23 Nov 2009, Peter Wang wrote:

> Make it possible to use gcc global registers and non-local gotos with gcc 4.x.
>
> Tested with asm_fast.gc on Linux/x86 with gcc 4.1.2, 4.2.4, 4.3.3, 4.4.2;
> and on Linux/x86-64 with gcc 4.2.4. 
> I also did limited testing of reg.gc,
> which also worked.

We should try it on Darwin/x86 too.

> Some low-level C grades do not build with the current version of the compiler
> so were not tested: fast.gc, jump.gc, asm_jump.gc.
>
> configure.in:
> 	Check if the C compiler accepts `-fno-move-loop-invariants'.
>
> 	Add `-fno-move-loop-invariants' to gcc flags for non-local gotos.
> 	This is enough for `asm_jump.gc' to work (tested with an earlier
> 	version of the compiler).
>
> 	Remove code to force `none' grades with gcc 4.x.
>
> runtime/mercury_goto.h:
> 	Add a hack to prevent gcc 4.x removing stores to the succip register
> 	before a jump.  Along with `-fno-move-loop-invariants', this lets
> 	`asm_fast.gc' work.
>
> 	This hack is currently only used for the x86 and x86-64 definitions of
> 	MR_ASM_JUMP/MR_JUMP, but is possibly required on other architectures,
> 	too.
>
> runtime/RESERVED_MACRO_NAMES:
> 	Add a macro which can be defined by gcc.
>
> diff --git a/configure.in b/configure.in
> index 3e77a7b..10d8289 100644
> --- a/configure.in
> +++ b/configure.in
> @@ -838,6 +838,19 @@ else
> fi
>
> AC_SUBST(CFLAGS_FOR_NO_STRICT_ALIASING)
> +
> +AC_MSG_CHECKING(whether we can use -fno-move-loop-invariants)
> +if $CC -O2 -Wall -fno-move-loop-invariants -c conftest.c \
> +    </dev/null >&AC_FD_CC 2>&1
> +then
> +    AC_MSG_RESULT(yes)
> +    CFLAGS_FOR_NO_MOVE_LOOP_INVARIANTS="-fno-move-loop-invariants"
> +else
> +    AC_MSG_RESULT(no)
> +    CFLAGS_FOR_NO_MOVE_LOOP_INVARIANTS=
> +fi
> +
> +AC_SUBST(CFLAGS_FOR_NO_MOVE_LOOP_INVARIANTS)

Why is CFLAGS_FOR_NO_MOVE_LOOP_INVARIANTS an output variable?  Its value
is not used beyond the configure script.

...

> #-----------------------------------------------------------------------------#
> @@ -2329,6 +2342,9 @@ AC_SUBST(MR_DARWIN_SETJMP_WORKAROUND)
> # (Actually I don't know if `-fno-functions-cse' is really needed.
> # Maybe you can get away without it.  But better to err on the safe side...)
> #
> +# For x86, x86-64 and possibly other architectures, when using non-local
> +# gotos with gcc 4.x we need `-fno-move-loop-invariants'.
> +#
> # For alpha, mips, and ARM, and probably on other architectures, when using
> # non-local gotos we need -fomit-frame-pointer, otherwise when compiling
> # with --no-c-optimize we run into a problem similar to the one above:
> @@ -2359,6 +2375,7 @@ case "$ac_cv_prog_gcc" in yes)
>             CFLAGS_FOR_GOTOS="-fno-defer-pop -fno-function-cse -fno-gcse"
>             ;;
>     esac
> +    CFLAGS_FOR_GOTOS="$CFLAGS_FOR_GOTOS $CFLAGS_FOR_NO_MOVE_LOOP_INVARIANTS"
>     case "$host" in
>         mips-sgi-irix5.*)
>             # Non-local gotos don't work with shared libraries on Irix 5,
> @@ -2993,16 +3010,6 @@ case "$mercury_cv_user_base_grade" in
>                 BEST_LLDS_BASE_GRADE=none
>             fi
>         fi
> -
> -        # Force the use of the none base grade if the C compiler
> -        # is GCC 4.{1,2,3,4}.  The asm_fast and reg grades either
> -        # don't work or are unstable with those versions.
> -        # (See bugs #39, #66 and #78 in the Mercury bug database.)
> -        case "$mercury_cv_gcc_version" in
> -            4_1_*|4_2_*|4_3_*|4_4_*)
> -                BEST_LLDS_BASE_GRADE=none
> -            ;;
> -        esac

I suggest leaving a commented out version of the above code, so that if
the workaround needs to be applied to a future version of GCC it is
obvious how and where to do it.

...

> diff --git a/runtime/mercury_goto.h b/runtime/mercury_goto.h
> index 1e499d5..7a87864 100644
> --- a/runtime/mercury_goto.h
> +++ b/runtime/mercury_goto.h
> @@ -353,6 +353,20 @@
> #elif defined(__i386__) || defined(__mc68000__) || defined(__x86_64__)
>
>   /*
> +  ** This hack is to prevent gcc 4.x optimizing away stores to succip before
> +  ** jumping to a label in asm_fast.gc.

s/asm_fast.gc/asm_fast*/

It presumably has nothing to do with the presence or absence of garbage
collection.

The diff looks good otherwise.

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