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

Peter Wang novalazy at gmail.com
Mon Nov 23 17:51:40 AEDT 2009


Branches: main

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.

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)
 rm -f conftest*
 
 #-----------------------------------------------------------------------------#
@@ -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
      ;;
 esac
 
diff --git a/runtime/RESERVED_MACRO_NAMES b/runtime/RESERVED_MACRO_NAMES
index 9a65cc6..b1097b1 100644
--- a/runtime/RESERVED_MACRO_NAMES
+++ b/runtime/RESERVED_MACRO_NAMES
@@ -67,6 +67,7 @@ sigcontext_struct
 _GNU_SOURCE
 __EXTENSIONS__
 __OPTIMIZE__
+__GCC_HAVE_DWARF2_CFI_ASM
 #-----------------------------------------------------------------------------#
 # These are defined in when threads are enabled.
 _REENTRANT
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.
+  */
+  #if defined(MR_USE_GCC_GLOBAL_REGISTERS)
+    #define MR_FORCE_SUCCIP_STORE			\
+	__asm__ __volatile__(""				\
+	    : "=r"(MR_succip_word)			\
+	    : "0"(MR_succip_word)			\
+	    )
+  #else
+    #define MR_FORCE_SUCCIP_STORE   (void)
+  #endif
+
+  /*
   ** The following hack works around a stack leak on the i386.
   ** (and apparently the 68000 and x86_64 too).
   **
@@ -380,11 +394,13 @@
     #define MR_ASM_JUMP(label)				\
 	{ register int stack_pointer __asm__("esp");	\
 	__asm__("" : : "g"(stack_pointer)); }		\
+	MR_FORCE_SUCCIP_STORE;				\
 	goto *(label)
   #elif defined(__x86_64__)
     #define MR_ASM_JUMP(label)				\
 	{ register int stack_pointer __asm__("rsp");	\
 	__asm__("" : : "g"(stack_pointer)); }		\
+	MR_FORCE_SUCCIP_STORE;				\
 	goto *(label)
   #elif defined(__mc68000__)
     #define MR_ASM_JUMP(label)				\

--------------------------------------------------------------------------
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