public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, driver] Ignore -ftree-parallelize-loops={0,1}
@ 2015-07-07  7:54 Tom de Vries
  2015-07-13 10:58 ` Tom de Vries
  0 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2015-07-07  7:54 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

Hi,

currently, we have these spec strings in gcc/gcc.c involving 
ftree-parallelize-loops:
...
%{fopenacc|fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}
%{fopenacc|fopenmp|ftree-parallelize-loops=*:-pthread}"
...

Actually, ftree-parallelize-loops={0,1} means that no parallelization is 
done, but these spec strings still get activated for these values.


Attached patch fixes that, by introducing a spec function gt (short for 
greather than), and using it in the spec lines.

[ I've also tried this approach using the already existing spec function 
version-compare:
...
%{fopenacc|fopenmp:%:include(libgomp.spec)%(link_gomp)}
%:version-compare(>=  2 ftree-parallelize-loops=
                   %:include(libgomp.spec)%(link_gomp))
...
But that didn't work out. The function evaluation mechanism evaluates 
the arguments before testing the function, so we evaluate 
'%:include(libgomp.spec)' unconditionally. The gcc build breaks on the 
first xgcc invocation with linking due to a missing libgomp.spec. ]


Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

[-- Attachment #2: 0001-Ignore-ftree-parallelize-loops-0-1-using-gt.patch --]
[-- Type: text/x-patch, Size: 3141 bytes --]

Ignore -ftree-parallelize-loops={0,1} using gt

---
 gcc/gcc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index 0f29b78..34fb437 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -274,6 +274,7 @@ static const char *compare_debug_self_opt_spec_function (int, const char **);
 static const char *compare_debug_auxbase_opt_spec_function (int, const char **);
 static const char *pass_through_libs_spec_func (int, const char **);
 static const char *replace_extension_spec_func (int, const char **);
+static const char *greater_than_spec_func (int, const char **);
 static char *convert_white_space (char *);
 \f
 /* The Specs Language
@@ -881,7 +882,7 @@ proper position among the other output files.  */
     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} " VTABLE_VERIFICATION_SPEC " \
     %{static:} %{L*} %(mfwrap) %(link_libgcc) " SANITIZER_EARLY_SPEC " %o\
     " CHKP_SPEC " \
-    %{fopenacc|fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\
+    %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*} 1):%:include(libgomp.spec)%(link_gomp)} \
     %{fcilkplus:%:include(libcilkrts.spec)%(link_cilkrts)}\
     %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
     %(mflib) " STACK_SPLIT_SPEC "\
@@ -1042,7 +1043,8 @@ static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
 /* Linking to libgomp implies pthreads.  This is particularly important
    for targets that use different start files and suchlike.  */
 #ifndef GOMP_SELF_SPECS
-#define GOMP_SELF_SPECS "%{fopenacc|fopenmp|ftree-parallelize-loops=*: " \
+#define GOMP_SELF_SPECS \
+  "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*} 1): " \
   "-pthread}"
 #endif
 
@@ -1482,6 +1484,7 @@ static const struct spec_function static_spec_functions[] =
   { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function },
   { "pass-through-libs",	pass_through_libs_spec_func },
   { "replace-extension",	replace_extension_spec_func },
+  { "gt",			greater_than_spec_func },
 #ifdef EXTRA_SPEC_FUNCTIONS
   EXTRA_SPEC_FUNCTIONS
 #endif
@@ -9428,6 +9431,47 @@ replace_extension_spec_func (int argc, const char **argv)
   return result;
 }
 
+/* Returns "" if the n in ARGV[1] == -opt=<n> is greater than ARGV[2].
+   Otherwise, return NULL.  */
+
+static const char *
+greater_than_spec_func (int argc, const char **argv)
+{
+  char *converted;
+
+  if (argc == 1)
+    return NULL;
+
+  gcc_assert (argc == 3);
+  gcc_assert (argv[0][0] == '-');
+  gcc_assert (argv[0][1] == '\0');
+
+  /* Point p to <n> in in -opt=<n>.  */
+  const char *p = argv[1];
+  while (true)
+    {
+      char c = *p;
+      if (c == '\0')
+	gcc_unreachable ();
+
+      ++p;
+
+      if (c == '=')
+	break;
+    }
+
+  long arg = strtol (p, &converted, 10);
+  gcc_assert (converted != p);
+
+  long lim = strtol (argv[2], &converted, 10);
+  gcc_assert (converted != argv[2]);
+
+  if (arg > lim)
+    return "";
+
+  return NULL;
+}
+
 /* Insert backslash before spaces in ORIG (usually a file path), to 
    avoid being broken by spec parser.
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-04-08 13:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07  7:54 [patch, driver] Ignore -ftree-parallelize-loops={0,1} Tom de Vries
2015-07-13 10:58 ` Tom de Vries
2015-07-14  4:55   ` Jeff Law
2015-07-14  8:36     ` Tom de Vries
2016-03-17 16:28       ` Thomas Schwinge
2016-04-08 10:36         ` Thomas Schwinge
2016-04-08 11:39           ` Tom de Vries
2016-04-08 11:44             ` Jakub Jelinek
2016-04-08 13:48               ` Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).