public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] New feature to reuse one multilib among different targets
@ 2012-10-10  7:58 Terry Guo
  2012-10-10 14:59 ` Joseph S. Myers
  0 siblings, 1 reply; 13+ messages in thread
From: Terry Guo @ 2012-10-10  7:58 UTC (permalink / raw)
  To: joseph; +Cc: gcc-patches

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

Hello Joseph,

Please help to review this new Multilib feature. It intends to provide user
a chance to define their own multilib selection rules. Those rules will be
appended to rules generated by gcc script genmultilib. Thus when gcc can't
find suitable multilib from its own rules, it can fall back to certain
existing multilib according to rules provided by user. This feature is
called multilib reuse.

With multilib reuse, we can link a better multilib rather than always using
the default multilib when fail to find exactly matched multilib. This
feature also can help to reduce the total number of multilib variants.

For simplicity, the rules used by multilib reuse are same with the rules in
variable multilib_select. For example, to reuse multilib (in folder dirM and
built with option "optA optB optC") among targets "optA optD optE" and "optA
optF optG", we can define following reuse rules:

MULTILIB_REUSE = dirM optA optD optE;dirM optA optF optG;

The above method requires user to define such rules in Multilib Makefile
fragment and those rules are eventually turned into gcc built-in rules. Any
change to them require to rebuild the gcc. To make it easy to adjust reuse
rules, my patch turns MULTILIB_REUSE into a gcc spec named multilib_reuse.
So follow the way how gcc handle spec, it's easy to change reuse rules
without rebuilding the gcc. Suppose we need to share same multilib with
target "optH optI optJ", we can write following spec file and feed it to
gcc:

*multilib_reuse:
+ dirM optH optI optJ;

In summary, we can use fragment to provide some pre-decided rules and use
spec to change rules on the fly.

Does this feature make sense and is it ok to trunk? Please advise. Thanks.

BR,
Terry

2012-10-10  Terry Guo  <terry.guo@arm.com>

        * genmultilib (MULTILIB_REUSE): New macro.
        * Makefile.in (s-mlib): Add a new argument MULTILIB_REUSE.
        * gcc.c (multilib_reuse): New spec.
        (set_multilib_dir): Use multilib_reuse.

[-- Attachment #2: gcc-multilib-reuse.patch --]
[-- Type: application/octet-stream, Size: 4027 bytes --]

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 9376e00..82986a8 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1800,10 +1800,11 @@ s-mlib: $(srcdir)/genmultilib Makefile
 	    "$(MULTILIB_EXCLUSIONS)" \
 	    "$(MULTILIB_OSDIRNAMES)" \
 	    "$(MULTILIB_REQUIRED)" \
+	    "$(MULTILIB_REUSE)" \
 	    "@enable_multilib@" \
 	    > tmp-mlib.h; \
 	else \
-	  $(SHELL) $(srcdir)/genmultilib '' '' '' '' '' '' '' '' no\
+	  $(SHELL) $(srcdir)/genmultilib '' '' '' '' '' '' '' '' '' no\
 	    > tmp-mlib.h; \
 	fi
 	$(SHELL) $(srcdir)/../move-if-change tmp-mlib.h multilib.h
diff --git a/gcc/gcc.c b/gcc/gcc.c
index bbca6d8..94f29f1 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1212,6 +1212,7 @@ static struct spec_list static_specs[] =
   INIT_STATIC_SPEC ("multilib_matches",		&multilib_matches),
   INIT_STATIC_SPEC ("multilib_exclusions",	&multilib_exclusions),
   INIT_STATIC_SPEC ("multilib_options",		&multilib_options),
+  INIT_STATIC_SPEC ("multilib_reuse",		&multilib_reuse),
   INIT_STATIC_SPEC ("linker",			&linker_name_spec),
   INIT_STATIC_SPEC ("linker_plugin_file",	&linker_plugin_file_spec),
   INIT_STATIC_SPEC ("lto_wrapper",		&lto_wrapper_spec),
@@ -7471,10 +7472,16 @@ set_multilib_dir (void)
 
   first = 1;
   p = multilib_select;
+
+  /* Append multilib reuse rules if any.  With those rules, we can reuse
+     one multilib for certain different targets.  */
+  if (strlen(multilib_reuse) > 0)
+    p = concat (p, multilib_reuse, NULL);
+
   while (*p != '\0')
     {
-      /* Ignore newlines.  */
-      if (*p == '\n')
+      /* Ignore newlines and spaces.  */
+      if (*p == '\n' || *p == ' ')
 	{
 	  ++p;
 	  continue;
@@ -7487,8 +7494,8 @@ set_multilib_dir (void)
 	  if (*p == '\0')
 	    {
 	    invalid_select:
-	      fatal_error ("multilib select %qs is invalid",
-			   multilib_select);
+	      fatal_error ("multilib select %qs%qs is invalid",
+			   multilib_select, multilib_reuse);
 	    }
 	  ++p;
 	}
diff --git a/gcc/genmultilib b/gcc/genmultilib
index dc4751b..fca24db 100644
--- a/gcc/genmultilib
+++ b/gcc/genmultilib
@@ -84,6 +84,15 @@
 # This argument can be used together with MULTILIB_EXCEPTIONS and will take
 # effect after the MULTILIB_EXCEPTIONS.
 
+# The optional ninth argument is a set of predefined multilib selection rules
+# which will be appended to variable multilib_select defined in gcc.c and can
+# eventually impact how gcc selects multilib.  The rules in this argument will
+# be used only when gcc can't find suitable multilib from multilib_select.
+# This argument enables us to reuse one multilib among certain targets,
+# for example we can reuse multilib built with options "optA optB optC"
+# among options "optA optD optE" and "optA optF optG" with rules:
+# dirA optA optB optC;dirA optA optD optE;dirA optA optF optG;
+
 # The last option should be "yes" if multilibs are enabled.  If it is not
 # "yes", all GCC multilib dir names will be ".".
 
@@ -104,7 +113,7 @@
 #   genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt'
 #		'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*'
 #		'' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany'
-#		'../lib64 ../lib32 alt' '' yes
+#		'../lib64 ../lib32 alt' '' '' yes
 # This produces:
 #   ". !m64 !m32 !mno-app-regs !mcmodel=medany;",
 #   "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;",
@@ -133,7 +142,8 @@ extra=$5
 exclusions=$6
 osdirnames=$7
 multilib_required=$8
-enable_multilib=$9
+multilib_reuse=$9
+enable_multilib=${10}
 
 echo "static const char *const multilib_raw[] = {"
 
@@ -443,6 +453,10 @@ moptions=`echo ${options} | sed -e 's,[ 	][ 	]*, ,g'`
 echo ""
 echo "static const char *multilib_options = \"${moptions}\";"
 
+# Output the multilib reuse rules now
+echo ""
+echo "static const char *multilib_reuse = \"${multilib_reuse}\";"
+
 # Finally output the disable flag if specified
 if [ "x${disable_multilib}" = xyes ]; then
   echo ""

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

end of thread, other threads:[~2013-01-13 10:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-10  7:58 [RFC] New feature to reuse one multilib among different targets Terry Guo
2012-10-10 14:59 ` Joseph S. Myers
2012-11-08  1:37   ` Terry Guo
2012-11-08 21:11     ` Joseph S. Myers
2012-11-09  7:36       ` Terry Guo
2012-11-09 16:35         ` Joseph S. Myers
2012-11-13  4:47           ` Terry Guo
2012-11-23  9:12             ` Ping: " Terry Guo
2012-12-04  2:36               ` Ping-2: " Terry Guo
2012-12-06 18:04             ` Joseph S. Myers
2012-12-07 13:24               ` Terry Guo
2013-01-07 16:13                 ` Joseph S. Myers
2013-01-13 10:28                   ` Terry Guo

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