[m-rev.] diff: non-local gotos and gcc 4

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Jul 25 18:04:39 AEST 2006


Most of this patch is due to Peter Hawkins.

Estimated hours taken: 1.5 (+ unknown by Peter Hawkins)
Branches: main, release

Get the asm_fast* grades working on systems using gcc version 4 and above.

runtime/mercury_goto.h:
 	Prevent gcc 4 and above from trying to cache memory values in
 	registers around labels that are used as the target of a non-local
 	goto.  (Ideally we would do this by disabling the optimization that
 	causes the problem at the command line but there isn't a documented
 	way to turn this one off.)

configure.in:
 	Conform to the above changes so that we can enable the asm_fast*
 	grades on systems using gcc 4 and above.

Julien.

Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.456
diff -u -r1.456 configure.in
--- configure.in	4 Jul 2006 04:46:37 -0000	1.456
+++ configure.in	25 Jul 2006 07:30:05 -0000
@@ -2147,6 +2147,7 @@

  AC_CACHE_VAL(mercury_cv_gcc_labels,
  	AC_TRY_RUN([
+	extern void exit(int);
  	void *entry_foo_1;
  	void *entry_bar_1;
  	void *succip;
@@ -2158,6 +2159,7 @@
  	return_label:
  		return;
  	foo_1:
+		__asm__ __volatile__("":::"memory");
  		if (global != 42) exit(1);
  		goto *entry_bar_1;
  	}
@@ -2167,6 +2169,7 @@
  	return_label:
  		return;
  	bar_1:
+		__asm__ __volatile__("":::"memory");
  		if (global != 42) exit(1);
  		goto *succip;
  	}
@@ -2180,6 +2183,7 @@
  		goto *entry_foo_1;
  		exit(1);
  	last:
+		__asm__ __volatile__("":::"memory");
  		if (global != 42) exit(1);
  		exit(0);
  	}
Index: runtime/mercury_goto.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.43
diff -u -r1.43 mercury_goto.h
--- runtime/mercury_goto.h	4 Jan 2006 05:16:30 -0000	1.43
+++ runtime/mercury_goto.h	25 Jul 2006 08:01:51 -0000
@@ -696,7 +696,31 @@
    					general-purpose register
    	)
    */
-
+ 
+  /*
+  ** The following macro expands into a dummy assembler statement that
+  ** contains no code.  It is used to suppress optimizations in gcc 4
+  ** and above that try to cache memory values in registers before labels
+  ** that Mercury uses as the target of non-local gotos.  It has no effect
+  ** with versions of gcc before version 4.
+  */
+  #define MR_PRETEND_REGS_ARE_USED \
+	__asm__ __volatile("":::"memory")
+  /*
+  Explanation:
+  	__asm__
+	__volatile__		 	Don't optimize this asm away.
+	(
+		""			Empty assembler code.
+		:			No outputs.
+		:			No inputs.
+		:"memory"		Tells gcc that this "instruction" might
+					clobber the register contents so it
+					shouldn't cache memory values in 
+					registers.
+	)
+   */
+
    /*
    ** Since we're jumping into and out of the middle of functions,
    ** we need to make sure that gcc thinks that (1) the function's address
@@ -757,17 +781,21 @@
  	}					\
  	label:					\
  	MR_PRETEND_ADDRESS_IS_USED(&&MR_entry(label));	\
-	{
+	{ \
+	MR_PRETEND_REGS_ARE_USED;
      #define MR_define_static(label)		\
  		MR_ASM_STATIC_ENTRY(label) 	\
  	}					\
  	label:					\
  	MR_PRETEND_ADDRESS_IS_USED(&&MR_entry(label));	\
-	{
+	{ \
+	MR_PRETEND_REGS_ARE_USED;
      /*
      ** The MR_PRETEND_ADDRESS_IS_USED macro is necessary to
      ** prevent an over-zealous gcc from optimizing away `label'
-    ** and the code that followed.
+    ** and the code that followed.  The MR_PRETEND_REGS_ARE_USED
+    ** macro is used to prevent gcc from caching values in registers
+    ** before the label.
      */
      #define MR_init_entry(label)	\
  	MR_PRETEND_ADDRESS_IS_USED(&&label); \

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at csse.unimelb.edu.au
administrative address: owner-mercury-reviews at csse.unimelb.edu.au
unsubscribe: Address: mercury-reviews-request at csse.unimelb.edu.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list