[m-rev.] for review: separate gcc and clang specific code in the runtime

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jul 27 17:51:57 AEST 2011


For review by anyone.

Branches: main, 11.07

Avoid using the __GNUC__ macro in the runtime as a test for the presence of
gcc, since clang also defines that macro.  Since clang doesn't support all
of the GNU C extensions, we can't actually use __GNUC__ without also checking
whether we are actually using clang.

runtime/mercury_conf_param.h:
 	Add three new macros, MR_CLANG, MR_GNUC and MR_MSVC that are defined
 	only when the C compiler is clang, gcc, or Visual C respectively.
 	(In particular, MR_GNUC will _not_ be defined when the C compiler
 	is clang.)

runtime/mercury.c:
runtime/mercury.h:
runtime/mercury_atomic_ops.c:
runtime/mercury_atomic_ops.h
runtime/mercury_bitmap.h:
runtime/mercury_float.h:
runtime/mercury_getopt.c:
runtime/mercury_goto.h:
runtime/mercury_heap.h:
runtime/mercury_std.h:
 	Replace uses of the __GNUC__ and __clang__ macros with the above.

runtime/mercury_regs.h:
 	As above, also #include mercury_conf_param.h directly since
 	this file is #included by some of the tests in the configure
 	script.

Julien.

Index: runtime/mercury.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury.c,v
retrieving revision 1.45
diff -u -r1.45 mercury.c
--- runtime/mercury.c	20 May 2011 04:16:53 -0000	1.45
+++ runtime/mercury.c	27 Jul 2011 05:21:36 -0000
@@ -83,7 +83,7 @@
      }
  )

-#if defined(MR_AVOID_MACROS) || !defined(__GNUC__)
+#if defined(MR_AVOID_MACROS) || !defined(MR_GNUC)

  MR_OUTLINE_DEFN(
      MR_Box
@@ -100,7 +100,7 @@
      }
  )

-#endif /* MR_AVOID_MACROS || !__GNUC__ */
+#endif /* MR_AVOID_MACROS || !MR_GNUC */

  #if defined(MR_AVOID_MACROS)

Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.77
diff -u -r1.77 mercury.h
--- runtime/mercury.h	20 May 2011 04:16:54 -0000	1.77
+++ runtime/mercury.h	27 Jul 2011 05:20:48 -0000
@@ -85,7 +85,7 @@
  ** The jmp_buf type used by MR_builtin_setjmp()
  ** to save the stack context when implementing commits.
  */
-#ifdef __GNUC__
+#ifdef MR_GNUC
    /*
    ** For GCC, we use `__builtin_setjmp' and `__builtin_longjmp'.
    ** These are documented (in gcc/builtins.c in the GCC source code)
@@ -160,7 +160,7 @@
  **	2.  The call to __builtin_longjmp() must not be in the same
  **	    function as the call to __builtin_setjmp().
  */
-#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#if (MR_GNUC > 2 || (MR_GNUC == 2 && __GNUC_MINOR__ >= 8))
    #ifndef MR_DARWIN_SETJMP_WORKAROUND
      #define MR_builtin_setjmp(buf)	__builtin_setjmp((buf))
      #define MR_builtin_longjmp(buf, val)	__builtin_longjmp((buf), (val))
@@ -178,7 +178,7 @@

  #ifdef MR_CONSERVATIVE_GC
    #ifdef MR_INLINE_ALLOC
-    #ifndef __GNUC__
+    #ifndef MR_GNUC
        #error "MR_INLINE_ALLOC requires GNU C"
      #endif
      /*
@@ -229,7 +229,7 @@

  #else /* !MR_CONSERVATIVE_GC */

-  #ifndef __GNUC__
+  #ifndef MR_GNUC
      /*
      ** We need GNU C's `({...})' expressions.
      ** It's not worth worrying about compilers other than GNU C for
@@ -266,7 +266,7 @@
  ** XXX we should optimize the case where sizeof(MR_Float) == sizeof(MR_Box)
  */

-#if defined(__GNUC__) && !defined(MR_AVOID_MACROS)
+#if defined(MR_GNUC) && !defined(MR_AVOID_MACROS)
    #define MR_box_float(f) ({						\
  	MR_Float *MR_box_float_ptr;					\
  									\
Index: runtime/mercury_atomic_ops.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_atomic_ops.c,v
retrieving revision 1.12
diff -u -r1.12 mercury_atomic_ops.c
--- runtime/mercury_atomic_ops.c	20 May 2011 04:16:54 -0000	1.12
+++ runtime/mercury_atomic_ops.c	27 Jul 2011 05:15:38 -0000
@@ -142,7 +142,7 @@
  ** Profiling of the parallel runtime.
  */

-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))
  /*
  ** True if the RDTSCP and RDTSC instructions are available respectively.
  */
@@ -152,7 +152,7 @@

  MR_uint_least64_t MR_cpu_cycles_per_sec = 0;

-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))

  /* Set this to 1 to enable some printfs below */
  #define MR_DEBUG_CPU_FEATURE_DETECTION 0 
@@ -177,12 +177,12 @@
  static MR_uint_least64_t
  parse_freq_from_x86_brand_string(char *string);

-#endif /* __GNUC__ && (__i386__ || __x86_64__) */
+#endif /* MR_GNUC && (__i386__ || __x86_64__) */

  void
  MR_do_cpu_feature_detection(void)
  {
-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))
      MR_Unsigned     a, b, c, d;
      MR_Unsigned     eflags, old_eflags;
      MR_Unsigned     maximum_extended_page;
@@ -386,10 +386,10 @@
          }
  #endif
      }
-#endif /* __GNUC__ && (__i386__ || __x86_64__) */
+#endif /* MR_GNUC && (__i386__ || __x86_64__) */
  }

-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))
  static MR_uint_least64_t
  parse_freq_from_x86_brand_string(char *string)
  {
@@ -450,12 +450,12 @@
      */
      return (MR_uint_least64_t)(strtod(&string[freq_index], NULL) * multiplier);
  }
-#endif /* __GNUC__ && (__i386__ || __x86_64__) */
+#endif /* MR_GNUC && (__i386__ || __x86_64__) */

  void
  MR_profiling_start_timer(MR_Timer *timer)
  {
-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))
      /*
      ** If we don't have enough data to fill in all the fields of this structure
      ** we leave them alone, we won't check them later without checking
@@ -472,7 +472,7 @@
  void
  MR_profiling_stop_timer(MR_Timer *timer, MR_Stats *stats)
  {
-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))
      MR_Timer            now;
      MR_int_least64_t    duration;
      MR_uint_least64_t   duration_squared;
@@ -510,16 +510,16 @@
          MR_US_UNLOCK(&(stats->MR_stat_sums_lock));
    #endif
      }
-#else /* not __GNUC__ && (__i386__ || __x86_64__) */
+#else /* not MR_GNUC && (__i386__ || __x86_64__) */
      /* No TSC support on this architecture or with this C compiler */
      MR_atomic_inc_int(&(stats->MR_stat_count_recorded));
-#endif /* not __GNUC__ && (__i386__ || __x86_64__) */
+#endif /* not MR_GNUC && (__i386__ || __x86_64__) */
  }

  MR_uint_least64_t
  MR_read_cpu_tsc(void)
  {
-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))
      MR_uint_least64_t   tsc;

      if (MR_rdtsc_is_available) {
@@ -528,15 +528,15 @@
          tsc = 0;
      }
      return tsc;
-#else /* not __GNUC__ && (__i386__ || __x86_64__) */
+#else /* not MR_GNUC && (__i386__ || __x86_64__) */
      return 0;
-#endif /* not __GNUC__ && (__i386__ || __x86_64__) */
+#endif /* not MR_GNUC && (__i386__ || __x86_64__) */
  }

  /*
  ** It's convenient that this instruction is the same on both i386 and x86_64
  */
-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#if defined(MR_GNUC) && (defined(__i386__) || defined(__x86_64__))

  static __inline__ void
  MR_cpuid(MR_Unsigned code, MR_Unsigned sub_code,
@@ -596,7 +596,7 @@
      *tsc |= tsc_low;
  }

-#endif /* __GNUC__ && (__i386__ || __x86_64__) */
+#endif /* MR_GNUC && (__i386__ || __x86_64__) */

  #endif /* MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */

Index: runtime/mercury_atomic_ops.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_atomic_ops.h,v
retrieving revision 1.17
diff -u -r1.17 mercury_atomic_ops.h
--- runtime/mercury_atomic_ops.h	5 Apr 2011 10:27:26 -0000	1.17
+++ runtime/mercury_atomic_ops.h	27 Jul 2011 05:18:23 -0000
@@ -52,7 +52,7 @@
   * References: Intel and AMD documentation for PAUSE, Intel optimisation
   * guide.
   */
-#if defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) ) && \
+#if defined(MR_GNUC) && ( defined(__i386__) || defined(__x86_64__) ) && \
      !defined(MR_DO_NOT_USE_CPU_RELAX)

      #define MR_ATOMIC_PAUSE                                                 \
@@ -148,7 +148,7 @@
  /*---------------------------------------------------------------------------*/
  /*---------------------------------------------------------------------------*/

-#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && \
+#if (MR_GNUC > 4 || (MR_GNUC == 4 && __GNUC_MINOR__ >= 1)) && \
      !defined(MR_AVOID_COMPILER_INTRINSICS)

      /*
@@ -159,7 +159,7 @@
              return __sync_bool_compare_and_swap(addr, old, new_val);        \
          } while (0)

-#elif defined(__GNUC__) && defined(__x86_64__)
+#elif defined(MR_GNUC) && defined(__x86_64__)

      #define MR_COMPARE_AND_SWAP_WORD_BODY                                   \
          do {                                                                \
@@ -173,7 +173,7 @@
              return (MR_bool) result;                                        \
          } while (0)

-#elif defined(__GNUC__) && defined(__i386__)
+#elif defined(MR_GNUC) && defined(__i386__)

      /* Really 486 or better. */
      #define MR_COMPARE_AND_SWAP_WORD_BODY                                   \
@@ -208,7 +208,7 @@

  /*---------------------------------------------------------------------------*/

-#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && \
+#if (MR_GNUC > 4 || (MR_GNUC == 4 && __GNUC_MINOR__ >= 1)) && \
      !defined(MR_AVOID_COMPILER_INTRINSICS)

      #define MR_ATOMIC_ADD_AND_FETCH_WORD_BODY                               \
@@ -270,7 +270,7 @@

  /*---------------------------------------------------------------------------*/

-#if defined(__GNUC__) && defined(__x86_64__) && \
+#if defined(MR_GNUC) && defined(__x86_64__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      #define MR_ATOMIC_ADD_WORD_BODY                                         \
@@ -285,7 +285,7 @@
      #define MR_ATOMIC_ADD_INT_BODY MR_ATOMIC_ADD_WORD_BODY
      #define MR_ATOMIC_ADD_UINT_BODY MR_ATOMIC_ADD_WORD_BODY

-#elif defined(__GNUC__) && defined(__i386__)
+#elif defined(MR_GNUC) && defined(__i386__)

      #define MR_ATOMIC_ADD_WORD_BODY                                         \
          do {                                                                \
@@ -331,7 +331,7 @@

  /*---------------------------------------------------------------------------*/

-#if defined(__GNUC__) && defined(__x86_64__) && \
+#if defined(MR_GNUC) && defined(__x86_64__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      #define MR_ATOMIC_SUB_INT_BODY                                          \
@@ -343,7 +343,7 @@
                  );                                                          \
          } while (0)

-#elif defined(__GNUC__) && defined(__i386__)
+#elif defined(MR_GNUC) && defined(__i386__)

      #define MR_ATOMIC_SUB_INT_BODY                                          \
          do {                                                                \
@@ -354,7 +354,7 @@
                  );                                                          \
          } while (0)

-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+#elif MR_GNUC > 4 || (MR_GNUC == 4 && __GNUC_MINOR__ >= 1)

      #define MR_ATOMIC_SUB_INT_BODY                                          \
          do {                                                                \
@@ -373,7 +373,7 @@

  /*---------------------------------------------------------------------------*/

-#if defined(__GNUC__) && defined(__x86_64__) && \
+#if defined(MR_GNUC) && defined(__x86_64__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      #define MR_ATOMIC_INC_WORD_BODY                                         \
@@ -388,7 +388,7 @@
      #define MR_ATOMIC_INC_INT_BODY MR_ATOMIC_INC_WORD_BODY
      #define MR_ATOMIC_INC_UINT_BODY MR_ATOMIC_INC_WORD_BODY

-#elif defined(__GNUC__) && defined(__i386__) && \
+#elif defined(MR_GNUC) && defined(__i386__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      /* Really 486 or better. */
@@ -438,7 +438,7 @@

  /*---------------------------------------------------------------------------*/

-#if defined(__GNUC__) && defined(__x86_64__) && \
+#if defined(MR_GNUC) && defined(__x86_64__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      #define MR_ATOMIC_DEC_INT_BODY                                          \
@@ -450,7 +450,7 @@
                  );                                                          \
          } while (0)

-#elif defined(__GNUC__) && defined(__i386__) && \
+#elif defined(MR_GNUC) && defined(__i386__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      /* Really 486 or better. */
@@ -486,7 +486,7 @@
  ** Note that on x86(_64) we have to use the sub instruction rather than the
  ** dec instruction because we need it to set the CPU flags.
  */
-#if defined(__GNUC__) && defined(__x86_64__) && \
+#if defined(MR_GNUC) && defined(__x86_64__) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

  /*
@@ -511,7 +511,7 @@
      #define MR_ATOMIC_DEC_AND_IS_ZERO_UINT_BODY \
          MR_ATOMIC_DEC_AND_IS_ZERO_WORD_BODY

-#elif defined(__GNUC__) && defined(__i386__)
+#elif defined(MR_GNUC) && defined(__i386__)

      #define MR_ATOMIC_DEC_AND_IS_ZERO_WORD_BODY                              \
          do {                                                                \
@@ -529,7 +529,7 @@
      #define MR_ATOMIC_DEC_AND_IS_ZERO_UINT_BODY \
          MR_ATOMIC_DEC_AND_IS_ZERO_WORD_BODY

-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+#elif MR_GNUC > 4 || (MR_GNUC == 4 && __GNUC_MINOR__ >= 1)

      #define MR_ATOMIC_DEC_AND_IS_ZERO_WORD_BODY                             \
          do {                                                                \
@@ -569,7 +569,7 @@
  /*
  ** Memory fence operations.
  */
-#if defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) ) && \
+#if defined(MR_GNUC) && ( defined(__i386__) || defined(__x86_64__) ) && \
      !defined(MR_AVOID_HANDWRITTEN_ASSEMBLER)

      /*
@@ -598,7 +598,7 @@
              __asm__ __volatile__("mfence");                                 \
          } while(0)

-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+#elif MR_GNUC > 4 || (MR_GNUC == 4 && __GNUC_MINOR__ >= 1)

      /*
      ** Our memory fences are better than GCC's.  GCC only implements a full
Index: runtime/mercury_bitmap.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_bitmap.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_bitmap.h
--- runtime/mercury_bitmap.h	20 May 2011 04:16:54 -0000	1.4
+++ runtime/mercury_bitmap.h	27 Jul 2011 05:16:11 -0000
@@ -55,7 +55,7 @@

  MR_Integer MR_bitmap_cmp(MR_ConstBitmapPtr, MR_ConstBitmapPtr);

-#ifdef __GNUC__
+#if defined(MR_GNUC)
  #define MR_bitmap_cmp(b1, b2)                                           \
      ({                                                                  \
          MR_Integer bitmap_cmp_result;                                   \
@@ -111,7 +111,7 @@

  MR_Integer    MR_hash_bitmap(MR_ConstBitmapPtr);

-#ifdef __GNUC__
+#if defined(MR_GNUC)
  #define MR_hash_bitmap(b)                                               \
      ({                                                                  \
          MR_Integer hash_bitmap_result;                                  \
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.118
diff -u -r1.118 mercury_conf_param.h
--- runtime/mercury_conf_param.h	20 May 2011 04:16:54 -0000	1.118
+++ runtime/mercury_conf_param.h	27 Jul 2011 07:46:13 -0000
@@ -1054,4 +1054,29 @@

  /*---------------------------------------------------------------------------*/

+/*
+** C compilers.
+*/
+
+/*
+** MR_CLANG -- The C compiler is clang.
+**
+** MR_GNUC -- The C compiler is GCC.  We use this macro instead of __GNUC__
+**            since clang also defines __GNUC__.
+	      The value of this macro gives the major version number.
+**
+** MR_MSVC -- The C compiler is Visual C.
+**	      The value of this macro gives the version number.
+*/
+
+#if defined(__clang__)
+    #define MR_CLANG __clang__
+#elif defined(__GNUC__)
+    #define MR_GNUC __GNUC__
+#elif defined(_MSC_VER)
+    #define MR_MSVC _MSC_VER
+#endif
+
+/*---------------------------------------------------------------------------*/
+
  #endif /* MERCURY_CONF_PARAM_H */
Index: runtime/mercury_float.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_float.h,v
retrieving revision 1.20
diff -u -r1.20 mercury_float.h
--- runtime/mercury_float.h	20 May 2011 04:16:54 -0000	1.20
+++ runtime/mercury_float.h	27 Jul 2011 05:19:14 -0000
@@ -65,7 +65,7 @@
      )
  #endif

-#ifdef __GNUC__
+#ifdef MR_GNUC
    #define MR_float_const(f) ({ static const MR_Float d = f; (MR_Word) &d; })
  #else
    #define MR_float_const(f) MR_float_to_word(f)	/* inefficient */
@@ -84,7 +84,7 @@

    #define MR_float_const(f) MR_float_to_word(f)

-  #ifdef __GNUC__
+  #ifdef MR_GNUC

      /* GNU C allows you to cast to a union type */
      #define MR_float_to_word(f) (__extension__ \
@@ -92,14 +92,14 @@
      #define MR_word_to_float(w) (__extension__ \
  				((union MR_Float_Word)(MR_Word)(w)).f)

-  #else /* not __GNUC__ */
+  #else /* not MR_GNUC */

      static MR_Word MR_float_to_word(MR_Float f)
  	{ union MR_Float_Word tmp; tmp.f = f; return tmp.w; }
      static MR_Float MR_word_to_float(MR_Word w)
  	{ union MR_Float_Word tmp; tmp.w = w; return tmp.f; }

-  #endif /* not __GNUC__ */
+  #endif /* not MR_GNUC */

  #endif /* not MR_BOXED_FLOAT */

Index: runtime/mercury_getopt.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_getopt.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_getopt.c
--- runtime/mercury_getopt.c	5 Feb 2002 10:19:06 -0000	1.3
+++ runtime/mercury_getopt.c	27 Jul 2011 05:19:46 -0000
@@ -226,7 +226,7 @@

  /* If using GCC, we can safely declare strlen this way.
     If not using GCC, it is ok not to declare it.  */
-#ifdef __GNUC__
+#ifdef MR_GNUC
  /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
     That was relevant to code that was here before.  */
  #if !defined (__STDC__) || !__STDC__
@@ -234,7 +234,7 @@
     and has done so at least since version 2.4.5. -- rms.  */
  extern int strlen (const char *);
  #endif /* not __STDC__ */
-#endif /* __GNUC__ */
+#endif /* MR_GNUC */

  #endif /* not __GNU_LIBRARY__ */

Index: runtime/mercury_goto.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.56
diff -u -r1.56 mercury_goto.h
--- runtime/mercury_goto.h	8 Jul 2010 03:17:09 -0000	1.56
+++ runtime/mercury_goto.h	27 Jul 2011 05:20:08 -0000
@@ -770,7 +770,7 @@

  #if defined(MR_USE_GCC_NONLOCAL_GOTOS)

-  #ifndef __GNUC__
+  #ifndef MR_GNUC
    #error "You must use gcc if you define MR_USE_GCC_NONLOCAL_GOTOS"
    #endif

@@ -845,7 +845,7 @@
    ** falls through. For older versions of gcc, we don't do this, since it
    ** adds significantly to the code size.
    */
-  #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 91)
+  #if MR_GNUC > 2 || (MR_GNUC == 2 && __GNUC_MINOR__ > 91)
      /* gcc version > egcs 1.1.2 */
      #define MR_BEGIN_MODULE(module_name)				\
  	MR_MODULE_STATIC_OR_EXTERN void module_name(void);		\
Index: runtime/mercury_heap.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.43
diff -u -r1.43 mercury_heap.h
--- runtime/mercury_heap.h	20 May 2011 04:16:54 -0000	1.43
+++ runtime/mercury_heap.h	27 Jul 2011 05:20:58 -0000
@@ -139,7 +139,7 @@
      ** of words.
      */

-    #ifndef __GNUC__
+    #ifndef MR_GNUC
        /*
        ** Without the gcc extensions __builtin_constant_p() and ({...}),
        ** MR_INLINE_ALLOC would probably be a performance _loss_.
Index: runtime/mercury_regs.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_regs.h,v
retrieving revision 1.29
diff -u -r1.29 mercury_regs.h
--- runtime/mercury_regs.h	10 May 2007 05:24:16 -0000	1.29
+++ runtime/mercury_regs.h	27 Jul 2011 07:38:28 -0000
@@ -8,6 +8,13 @@
  #define MERCURY_REGS_H

  #include "mercury_conf.h"
+/*
+** NOTE: we need to include mercury_conf_param.h separately here since some
+** of the tests in the configure script need MR_GNUC to be defined and
+** mercury_conf.h might will not exist until *after* we have run the configure
+** script has been run.
+*/
+#include "mercury_conf_param.h"
  #include "mercury_types.h"

  /*---------------------------------------------------------------------------*/
@@ -19,7 +26,7 @@
  ** Similarly for comma expressions and conditional expressions.
  */

-#ifdef __GNUC__
+#ifdef MR_GNUC
    #define MR_LVALUE_CAST(type, lval)	((type)(lval))
    #define MR_LVALUE_SEQ(expr, lval)	((expr),(lval))
    #define MR_LVALUE_COND(expr, x, y)	((expr)?(x):(y))
@@ -74,7 +81,7 @@
  ** The hardware description layer
  */
  #if defined(MR_USE_GCC_GLOBAL_REGISTERS)
-  #ifndef __GNUC__
+  #ifndef MR_GNUC
      #error "You must use gcc if you define MR_USE_GCC_GLOBAL_REGISTERS."
    #endif

Index: runtime/mercury_std.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_std.h,v
retrieving revision 1.32
diff -u -r1.32 mercury_std.h
--- runtime/mercury_std.h	12 Jul 2011 03:21:58 -0000	1.32
+++ runtime/mercury_std.h	27 Jul 2011 05:22:10 -0000
@@ -161,8 +161,8 @@
    #define MR_INLINE			inline
    #define MR_EXTERN_INLINE		inline
    #define MR_OUTLINE_DEFN(DECL,BODY)
-#elif defined(__clang__)
-  /* clang: note that since clang also defines the macro __GNUC__
+#elif defined(MR_CLANG)
+  /* clang: note that since clang also defines the macro MR_GNUC
    ** we must handle it before we handle the GCC case.
    ** XXX why don't the C99 definitions work for clang?
    */
@@ -170,7 +170,7 @@
    #define MR_INLINE			static
    #define MR_EXTERN_INLINE		static
    #define MR_OUTLINE_DEFN(DECL,BODY)
-#elif defined(__GNUC__) 
+#elif defined(MR_GNUC)
    /* GNU C */
    #define MR_STATIC_INLINE		static __inline__
    #define MR_INLINE			static __inline__
@@ -194,7 +194,7 @@

  /* A macro for declaring functions that never return */

-#if __GNUC__
+#if MR_GNUC
    #define MR_NO_RETURN __attribute__((noreturn))
  #else
    #define MR_NO_RETURN
@@ -229,7 +229,7 @@
  ** optimization is more likely to be important than squeezing the last 1%
  ** in performance.
  */
-#if defined(MR_USE_REGPARM) && defined(__GNUC__) && defined(__i386__)
+#if defined(MR_USE_REGPARM) && defined(MR_GNUC) && defined(__i386__)
    #define MR_CALL __attribute__((__stdcall__, __regparm__(2)))
  #else
    #define MR_CALL

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