[01/34] rs6000: Incorporate new builtins code into the build machinery

Message ID 47396f9d5d8e2f9ce7c08f2f412ce638394041a2.1627562851.git.wschmidt@linux.ibm.com
State New
Headers show
Series
  • Replace the Power target-specific builtin machinery
Related show

Commit Message

Qing Zhao via Gcc-patches July 29, 2021, 1:30 p.m.
Differences from previous version:
 - Removed the change to add rs6000-c.o to extra_objs (unnecessary)
 - Avoided race condition and documented how this works

2021-07-27  Bill Schmidt  <wschmidt@linux.ibm.com>

gcc/
	* config.gcc (powerpc*-*-*): Add rs6000-builtins.o to extra_objs.
	* config/rs6000/rs6000-gen-builtins.c (main): Close init_file
	last.
	* config/rs6000/t-rs6000 (rs6000-gen-builtins.o): New target.
	(rbtree.o): Likewise.
	(rs6000-gen-builtins): Likewise.
	(rs6000-builtins.c): Likewise.
	(rs6000-builtins.h): Likewise.
	(rs6000.o): Add dependency.
	(EXTRA_HEADERS): Add rs6000-vecdefines.h.
	(rs6000-vecdefines.h): New target.
	(rs6000-builtins.o): Likewise.
	(rs6000-call.o): Add rs6000-builtins.h as a dependency.
	(rs6000-c.o): Likewise.
---
 gcc/config.gcc                          |  1 +
 gcc/config/rs6000/rs6000-gen-builtins.c |  4 ++-
 gcc/config/rs6000/t-rs6000              | 46 ++++++++++++++++++++++---
 3 files changed, 45 insertions(+), 6 deletions(-)

-- 
2.27.0

Comments

Segher Boessenkool Aug. 4, 2021, 10:29 p.m. | #1
Hi!

On Thu, Jul 29, 2021 at 08:30:48AM -0500, Bill Schmidt wrote:
> 	* config/rs6000/rs6000-gen-builtins.c (main): Close init_file

> 	last.


That easily fits on one line?

> +rs6000-gen-builtins: rs6000-gen-builtins.o rbtree.o

> +	$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) -o $@ \

> +	    $(filter-out $(BUILD_LIBDEPS), $^) $(BUILD_LIBS)


I wonder what the difference is between BUILD_LINKERFLAGS and
BUILD_LDFLAGS?  Do you have any idea?

Okay for trunk.  Thanks!


Segher
Qing Zhao via Gcc-patches Aug. 5, 2021, 1:47 p.m. | #2
Hi Segher,

On 8/4/21 5:29 PM, Segher Boessenkool wrote:
> On Thu, Jul 29, 2021 at 08:30:48AM -0500, Bill Schmidt wrote:

> +rs6000-gen-builtins: rs6000-gen-builtins.o rbtree.o

>> +	$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) -o $@ \

>> +	    $(filter-out $(BUILD_LIBDEPS), $^) $(BUILD_LIBS)

> I wonder what the difference is between BUILD_LINKERFLAGS and

> BUILD_LDFLAGS?  Do you have any idea?

>

I couldn't find evidence that BUILD_LINKERFLAGS ever has anything that 
BUILD_LDFLAGS doesn't, but I put that down to my ignorance of the 
cobwebbed corners of the build system.  There is probably some configure 
magic that can set it, and I suspect it has something to do with cross 
builds; but it might also just be a leftover artifact.  I decided I 
should use the same build rule as the other gen- programs to make sure 
cross builds work as expected. Certainly open to better ideas if you 
have them!

Thanks,
Bill
Segher Boessenkool Aug. 5, 2021, 4:04 p.m. | #3
On Thu, Aug 05, 2021 at 08:47:54AM -0500, Bill Schmidt wrote:
> Hi Segher,

> 

> On 8/4/21 5:29 PM, Segher Boessenkool wrote:

> >On Thu, Jul 29, 2021 at 08:30:48AM -0500, Bill Schmidt wrote:

> >+rs6000-gen-builtins: rs6000-gen-builtins.o rbtree.o

> >>+	$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) -o $@ \

> >>+	    $(filter-out $(BUILD_LIBDEPS), $^) $(BUILD_LIBS)

> >I wonder what the difference is between BUILD_LINKERFLAGS and

> >BUILD_LDFLAGS?  Do you have any idea?

> >

> I couldn't find evidence that BUILD_LINKERFLAGS ever has anything that 

> BUILD_LDFLAGS doesn't, but I put that down to my ignorance of the 

> cobwebbed corners of the build system.  There is probably some configure 

> magic that can set it, and I suspect it has something to do with cross 

> builds; but it might also just be a leftover artifact.  I decided I 

> should use the same build rule as the other gen- programs to make sure 

> cross builds work as expected. Certainly open to better ideas if you 

> have them!


Oh no, the patch is fine as is, I approved it...  I'm just terminally
nosy :-)  It isn't clear what (if any) difference there is between the
two vars.  I do know you are just copying exising practice here.


Segher

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 93e2b3219b9..fe2205b4bc2 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -476,6 +476,7 @@  powerpc*-*-*)
 	cpu_type=rs6000
 	extra_objs="rs6000-string.o rs6000-p8swap.o rs6000-logue.o"
 	extra_objs="${extra_objs} rs6000-call.o rs6000-pcrel-opt.o"
+	extra_objs="${extra_objs} rs6000-builtins.o"
 	extra_headers="ppc-asm.h altivec.h htmintrin.h htmxlintrin.h"
 	extra_headers="${extra_headers} bmi2intrin.h bmiintrin.h"
 	extra_headers="${extra_headers} xmmintrin.h mm_malloc.h emmintrin.h"
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index e5d3b71b622..c401a44e104 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -2979,9 +2979,11 @@  main (int argc, const char **argv)
       exit (1);
     }
 
+  /* Always close init_file last.  This avoids race conditions in the
+     build machinery.  See comments in t-rs6000.  */
   fclose (header_file);
-  fclose (init_file);
   fclose (defines_file);
+  fclose (init_file);
 
   return 0;
 }
diff --git a/gcc/config/rs6000/t-rs6000 b/gcc/config/rs6000/t-rs6000
index 44f7ffb35fe..e0e8ab8d828 100644
--- a/gcc/config/rs6000/t-rs6000
+++ b/gcc/config/rs6000/t-rs6000
@@ -27,10 +27,6 @@  rs6000-pcrel-opt.o: $(srcdir)/config/rs6000/rs6000-pcrel-opt.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
 
-rs6000-c.o: $(srcdir)/config/rs6000/rs6000-c.c
-	$(COMPILE) $<
-	$(POSTCOMPILE)
-
 rs6000-string.o: $(srcdir)/config/rs6000/rs6000-string.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
@@ -47,7 +43,47 @@  rs6000-logue.o: $(srcdir)/config/rs6000/rs6000-logue.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
 
-rs6000-call.o: $(srcdir)/config/rs6000/rs6000-call.c
+rs6000-gen-builtins.o: $(srcdir)/config/rs6000/rs6000-gen-builtins.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+
+rbtree.o: $(srcdir)/config/rs6000/rbtree.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+
+rs6000-gen-builtins: rs6000-gen-builtins.o rbtree.o
+	$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) -o $@ \
+	    $(filter-out $(BUILD_LIBDEPS), $^) $(BUILD_LIBS)
+
+# TODO: Whenever GNU make 4.3 is the minimum required, we should use
+# grouped targets on this:
+#    rs6000-builtins.c rs6000-builtins.h rs6000-vecdefines.h &: <deps>
+#       <recipe>
+# For now, the header files depend on rs6000-builtins.c, which avoids
+# races because the .c file is closed last in rs6000-gen-builtins.c.
+rs6000-builtins.c: rs6000-gen-builtins \
+		   $(srcdir)/config/rs6000/rs6000-builtin-new.def \
+		   $(srcdir)/config/rs6000/rs6000-overload.def
+	./rs6000-gen-builtins $(srcdir)/config/rs6000/rs6000-builtin-new.def \
+		$(srcdir)/config/rs6000/rs6000-overload.def rs6000-builtins.h \
+		rs6000-builtins.c rs6000-vecdefines.h
+
+rs6000-builtins.h: rs6000-builtins.c
+
+rs6000.o: rs6000-builtins.h
+
+EXTRA_HEADERS += rs6000-vecdefines.h
+rs6000-vecdefines.h: rs6000-builtins.c
+
+rs6000-builtins.o: rs6000-builtins.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+
+rs6000-call.o: $(srcdir)/config/rs6000/rs6000-call.c rs6000-builtins.h
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+
+rs6000-c.o: $(srcdir)/config/rs6000/rs6000-c.c rs6000-builtins.h
 	$(COMPILE) $<
 	$(POSTCOMPILE)