[m-rev.] for post-commit review: document status of clang support

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Oct 3 16:06:25 AEDT 2011


On Mon, 3 Oct 2011, Zoltan Somogyi wrote:

> On 03-Oct-2011, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>> If you are using a more recent
>> version of
>> +LLVM then you should be able to safely increase the optimization level
>> used by
>> +clang by applying the following patch:
>
> Is there a way of detecting automatically whether clang is recent enough,
> and if yes, making the change also happen automatically?

I've committed the following, which addresses the above.

Julien.

-----------------------------

Branches: main, 11.07

Only force -O0 for old versions of clang; more recent versions do not encounter
problems when compiling Mercury generated C code.

configure.in:
scripts/mgnuc.in:
 	As above.

README.clang:
 	Conform to the above change.

Index: README.clang
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/README.clang,v
retrieving revision 1.1
diff -u -r1.1 README.clang
--- README.clang	2 Oct 2011 13:09:07 -0000	1.1
+++ README.clang	3 Oct 2011 05:00:24 -0000
@@ -12,40 +12,5 @@
  about 2.9 contain bugs that require most C compiler optimizations to be
  disabled when compiling Mercury generated C code with clang (i.e. the generated
  C files have to be compiled at -O0).  If you are using a more recent version of
-LLVM then you should be able to safely increase the optimization level used by
-clang by applying the following patch:
-
-Index: configure.in
-===================================================================
-RCS file: /home/mercury/mercury1/repository/mercury/configure.in,v
-retrieving revision 1.593
-diff -u -r1.593 configure.in
---- configure.in	21 Sep 2011 06:11:30 -0000	1.593
-+++ configure.in	2 Oct 2011 12:57:59 -0000
-@@ -4483,7 +4483,7 @@
-         # XXX we need go through the warning and optimization options for clang
-         # more carefully.
-         CFLAGS_FOR_WARNINGS="-w"
--        CFLAGS_FOR_OPT="-fomit-frame-pointer"
-+        CFLAGS_FOR_OPT="-O2 -fomit-frame-pointer"
-         CFLAGS_FOR_DEBUG="-g"
-         CFLAGS_FOR_NO_STRICT_ALIASING="-fno-strict-aliasing"
-         MCFLAGS_FOR_CC=
-Index: scripts/mgnuc.in
-===================================================================
-RCS file: /home/mercury/mercury1/repository/mercury/scripts/mgnuc.in,v
-retrieving revision 1.137
-diff -u -r1.137 mgnuc.in
---- scripts/mgnuc.in	25 Aug 2011 14:16:53 -0000	1.137
-+++ scripts/mgnuc.in	2 Oct 2011 12:57:37 -0000
-@@ -72,7 +72,7 @@
-     *clang*)
-         ANSI_OPTS="-ansi"
-         CHECK_OPTS="-w"
--        OPT_OPTS="-O0 $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
-+        OPT_OPTS="-O2 $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
-         DEBUG_OPT="-g"
-         COMPILER=clang
-         ;;
-
-
+LLVM then the configure script will automatically enable a higher level of
+optimization.
Index: configure.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/configure.in,v
retrieving revision 1.593
diff -u -r1.593 configure.in
--- configure.in	21 Sep 2011 06:11:30 -0000	1.593
+++ configure.in	3 Oct 2011 05:00:24 -0000
@@ -4446,6 +4446,11 @@
  # Note that changes here may require changes in scripts/mgnuc.in and
  # compiler/compile_target_code.m.

+# Older versions of clang / LLVM cannot compile the C code generated by the
+# Mercury compiler at higher optimization levels.
+#
+OPT_FLAGS_FOR_CLANG="-O0"
+
  case "$mercury_cv_cc_type" in

      gcc*)
@@ -4483,7 +4488,18 @@
          # XXX we need go through the warning and optimization options for clang
          # more carefully.
          CFLAGS_FOR_WARNINGS="-w"
-        CFLAGS_FOR_OPT="-fomit-frame-pointer"
+ 
+        # Disable C compiler optimizations for old versions of clang.
+        # (See above for details.) 
+        case "$C_COMPILER_TYPE" in
+            clang_0_*|clang_1_*|clang_2_*)
+                CFLAGS_FOR_OPT="-O0 -fomit-frame-pointer"
+            ;;
+            *)
+                CFLAGS_FOR_OPT="-O2 -fomit-frame-pointer"
+                OPT_FLAGS_FOR_CLANG="-O2"
+            ;;
+        esac
          CFLAGS_FOR_DEBUG="-g"
          CFLAGS_FOR_NO_STRICT_ALIASING="-fno-strict-aliasing"
          MCFLAGS_FOR_CC=
@@ -4520,6 +4536,7 @@
  AC_SUBST([CFLAGS_FOR_DEBUG])
  AC_SUBST([CFLAGS_FOR_NO_STRICT_ALIASING])
  AC_SUBST([MCFLAGS_FOR_CC])
+AC_SUBST([OPT_FLAGS_FOR_CLANG])
  AC_SUBST([C_COMPILER_TYPE])

  #-----------------------------------------------------------------------------#
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.137
diff -u -r1.137 mgnuc.in
--- scripts/mgnuc.in	25 Aug 2011 14:16:53 -0000	1.137
+++ scripts/mgnuc.in	3 Oct 2011 05:00:25 -0000
@@ -72,7 +72,7 @@
      *clang*)
          ANSI_OPTS="-ansi"
          CHECK_OPTS="-w"
-        OPT_OPTS="-O0 $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
+        OPT_OPTS="@OPT_FLAGS_FOR_CLANG@ $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
          DEBUG_OPT="-g"
          COMPILER=clang
          ;;
--------------------------------------------------------------------------
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