[m-rev.] diff: avoid excessive compilation times on Mac OS X in debug grades

Julien Fischer juliensf at csse.unimelb.edu.au
Wed May 19 13:47:05 AEST 2010


On Mon, 17 May 2010, Julien Fischer wrote:

> On Mac OS X force the debug grades to be compiled by GCC at -O0.
> Using -O2 (the default), results in excessive compilation times.
> (There is at least one open GCC bug, #26854, concerning excessive
> compilation times on Darwin - it is likely we are also bumping
> into this.)
>
> (I will update mmc --make separately.)

Here is the version of the workaround for mmc --make.

Julien.

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

Branches: main, 10.04

Compile C files at -O0 in debugging grades on Mac OS X, when using mmc --make.
This works around performance problems in gcc.

compiler/compile_target_code.m:
 	As above.

scripts/mgnuc.in:
 	Add from the spot that implements the workaround for the mgnuc script.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.155
diff -u -r1.155 compile_target_code.m
--- compiler/compile_target_code.m	17 May 2010 06:31:45 -0000	1.155
+++ compiler/compile_target_code.m	19 May 2010 03:43:43 -0000
@@ -858,11 +858,31 @@
      ;
          AppleGCCRegWorkaroundOpt = ""
      ),
- 
+ 
+    % Workaround performance problem(s) with gcc that causes the C files
+    % generated in debugging grades to compile very slowly at -O1 and above.
+    % (Changes here need to be reflected in scripts/mgnuc.in.)
+    (
+        ExecTrace = yes,
+        arch_is_apple_darwin(FullArch)
+    ->
+        OverrideOpts = "-O0"
+    ;
+        OverrideOpts = ""
+    ),
+
      % Be careful with the order here!  Some options override others,
      % e.g. CFLAGS_FOR_REGS must come after OptimizeOpt so that
      % it can override -fomit-frame-pointer with -fno-omit-frame-pointer.
      % Also be careful that each option is separated by spaces.
+    % 
+    % In general, user supplied C compiler flags, i.e. CFLAGS below, should
+    % be able to override those introduced by the Mercury compiler.
+    % In some circumstances we want to prevent the user doing this, typically
+    % where we know the behaviour of a particular C compiler is buggy; the
+    % last option, OverrideOpts, does this -- because of this it must be
+    % listed after CFLAGS.
+    %
      string.append_list([
          SubDirInclOpt, InclOpt,
          OptimizeOpt, " ",
@@ -894,7 +914,8 @@
          AppleGCCRegWorkaroundOpt,
          C_FnAlignOpt,
          WarningOpt, " ", 
-        CFLAGS], AllCFlags).
+        CFLAGS, " ",
+        OverrideOpts], AllCFlags).

  %-----------------------------------------------------------------------------%

@@ -3016,6 +3037,21 @@

  %-----------------------------------------------------------------------------%

+    % Succeeds if the configuration name for this machine matches
+    % *-apple-darwin*, i.e. its an x86 / x86_64 / ppc machine with Mac OS X.
+    %
+:- pred arch_is_apple_darwin(string::in) is semidet.
+
+arch_is_apple_darwin(FullArch) :-
+    ArchComponents = string.split_at_char(('-'), FullArch),
+    % See the comments at the head of config.sub for details for details
+    % of how autoconf handles configuration names.
+    ArchComponents = [_CPU, Mfr, OS],
+    Mfr = "apple",
+    string.prefix(OS, "darwin").
+
+%-----------------------------------------------------------------------------%
+
  :- func this_file = string.

  this_file = "compile_target_code.m".
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.128
diff -u -r1.128 mgnuc.in
--- scripts/mgnuc.in	17 May 2010 08:21:07 -0000	1.128
+++ scripts/mgnuc.in	19 May 2010 03:43:43 -0000
@@ -613,6 +613,8 @@
  # At -O2 compilation times on Mac OS X are extremely slow for
  # Apple GCC 4.{0,2}.  We must force GCC to use -O0 here in order
  # to get acceptable compilation times.
+# Changes to this need to be reflected in the predicate 
+# gather_c_compiler_flags/3 in compiler/compile_target_code.m.

  case $FULLARCH in *apple*darwin*)
      case $debug in true)
--------------------------------------------------------------------------
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