Re: Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-05 Thread David Malcolm
On Tue, 2019-02-05 at 21:40 +, Andrea Corallo wrote:
> David Malcolm writes:
> 
> > On Sat, 2019-02-02 at 16:34 +0100, Jakub Jelinek wrote:
> > > On Sat, Feb 02, 2019 at 10:18:43AM -0500, David Malcolm wrote:
> > > > > > Alternatively, should these patches go into a branch of
> > > > > > queued
> > > > > > jit
> > > > > > changes for gcc 10?
> > > > > 
> > > > > Is there anything like an ABI involved? If so we should avoid
> > > > > breaking it all the time. Otherwise JIT is not release
> > > > > critical
> > > > > and
> > > > > thus if you break it in the wrong moment it's your own fault.
> > > > 
> > > > The two patches each add a new API entrypoint, but libgccjit
> > > > uses
> > > > symbol-versioning to extend the ABI, without bumping the
> > > > SONAME:
> > > >   https://gcc.gnu.org/onlinedocs/jit/topics/compatibility.html
> > > > So it's not an ABI break as such.
> > > 
> > > I'd say it depends on how quickly the copyright paperwork can be
> > > done, the
> > > patch can't be added until that is resolved.  While gccjit is not
> > > release
> > > critical, it would be nice not to break it late, so say if it can
> > > be
> > > committed by end of February/mid March, I guess it is fine, given
> > > the
> > > assumption we'd like to release mid April to end of April, if it
> > > can't be
> > > done by then, might be better to postpone to GCC 10.
> > > 
> > >   Jakub
> > 
> > Jakub and Richard: thanks.
> > 
> > I've double-checked the gcc_jit_context_add_driver_option patch and
> > it
> > looks good (it's a different patch that we're waiting on paperwork
> > for).
> > 
> > Andrea: are you able to commit this, or should I do this on your
> > behalf?
> > 
> > Dave
> 
> Hi David,
> I have no repo write access so if you could push it that would be
> great.
> 
> Thanks a lot

I've committed it to trunk as r268563.

Dave


Re: Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-05 Thread Andrea Corallo


David Malcolm writes:

> On Sat, 2019-02-02 at 16:34 +0100, Jakub Jelinek wrote:
>> On Sat, Feb 02, 2019 at 10:18:43AM -0500, David Malcolm wrote:
>> > > > Alternatively, should these patches go into a branch of queued
>> > > > jit
>> > > > changes for gcc 10?
>> > >
>> > > Is there anything like an ABI involved? If so we should avoid
>> > > breaking it all the time. Otherwise JIT is not release critical
>> > > and
>> > > thus if you break it in the wrong moment it's your own fault.
>> >
>> > The two patches each add a new API entrypoint, but libgccjit uses
>> > symbol-versioning to extend the ABI, without bumping the SONAME:
>> >   https://gcc.gnu.org/onlinedocs/jit/topics/compatibility.html
>> > So it's not an ABI break as such.
>>
>> I'd say it depends on how quickly the copyright paperwork can be
>> done, the
>> patch can't be added until that is resolved.  While gccjit is not
>> release
>> critical, it would be nice not to break it late, so say if it can be
>> committed by end of February/mid March, I guess it is fine, given the
>> assumption we'd like to release mid April to end of April, if it
>> can't be
>> done by then, might be better to postpone to GCC 10.
>>
>>  Jakub
>
> Jakub and Richard: thanks.
>
> I've double-checked the gcc_jit_context_add_driver_option patch and it
> looks good (it's a different patch that we're waiting on paperwork
> for).
>
> Andrea: are you able to commit this, or should I do this on your
> behalf?
>
> Dave

Hi David,
I have no repo write access so if you could push it that would be great.

Thanks a lot

  Andrea


Re: Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-05 Thread David Malcolm
On Sat, 2019-02-02 at 16:34 +0100, Jakub Jelinek wrote:
> On Sat, Feb 02, 2019 at 10:18:43AM -0500, David Malcolm wrote:
> > > > Alternatively, should these patches go into a branch of queued
> > > > jit
> > > > changes for gcc 10?
> > > 
> > > Is there anything like an ABI involved? If so we should avoid
> > > breaking it all the time. Otherwise JIT is not release critical
> > > and
> > > thus if you break it in the wrong moment it's your own fault. 
> > 
> > The two patches each add a new API entrypoint, but libgccjit uses
> > symbol-versioning to extend the ABI, without bumping the SONAME:
> >   https://gcc.gnu.org/onlinedocs/jit/topics/compatibility.html
> > So it's not an ABI break as such.
> 
> I'd say it depends on how quickly the copyright paperwork can be
> done, the
> patch can't be added until that is resolved.  While gccjit is not
> release
> critical, it would be nice not to break it late, so say if it can be
> committed by end of February/mid March, I guess it is fine, given the
> assumption we'd like to release mid April to end of April, if it
> can't be
> done by then, might be better to postpone to GCC 10.
> 
>   Jakub

Jakub and Richard: thanks.

I've double-checked the gcc_jit_context_add_driver_option patch and it
looks good (it's a different patch that we're waiting on paperwork
for).

Andrea: are you able to commit this, or should I do this on your
behalf?

Dave


Re: Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-02 Thread Jakub Jelinek
On Sat, Feb 02, 2019 at 10:18:43AM -0500, David Malcolm wrote:
> > > Alternatively, should these patches go into a branch of queued jit
> > > changes for gcc 10?
> > 
> > Is there anything like an ABI involved? If so we should avoid
> > breaking it all the time. Otherwise JIT is not release critical and
> > thus if you break it in the wrong moment it's your own fault. 
> 
> The two patches each add a new API entrypoint, but libgccjit uses
> symbol-versioning to extend the ABI, without bumping the SONAME:
>   https://gcc.gnu.org/onlinedocs/jit/topics/compatibility.html
> So it's not an ABI break as such.

I'd say it depends on how quickly the copyright paperwork can be done, the
patch can't be added until that is resolved.  While gccjit is not release
critical, it would be nice not to break it late, so say if it can be
committed by end of February/mid March, I guess it is fine, given the
assumption we'd like to release mid April to end of April, if it can't be
done by then, might be better to postpone to GCC 10.

Jakub


Re: Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-02 Thread David Malcolm
On Sat, 2019-02-02 at 08:26 +0100, Richard Biener wrote:
> On February 1, 2019 10:11:12 PM GMT+01:00, David Malcolm  dhat.com> wrote:
> > On Mon, 2019-01-21 at 08:40 +, Andrea Corallo wrote:
> > > Hi all,
> > > Second version of the patch addressing David's comment about all-
> > > non-
> > > failing-tests.h
> > > 
> > > Adds gcc_jit_context_add_driver_option to the libgccjit ABI and a
> > > testcase for it.
> > > 
> > > Using this interface is now possible to pass options affecting
> > > assembler and linker.
> > > 
> > > Does not introduce regressions running make check-jit
> > 
> > Thanks; the patch looks good.
> > 
> > [CCing the release managers]
> > 
> > Given that gcc development is now in stage 4, we really shouldn't
> > be
> > adding new features, but I'm wondering if an exception can be made
> > for
> > libgccjit?  (this patch purely touches the jit subdirectories).
> > 
> > There's one other late-breaking change, here:
> >  [PATCH][jit] Add thread-local globals to the libgccjit frontend
> >https://gcc.gnu.org/ml/gcc-patches/2019-01/msg00227.html
> > which is nearly ready, but is awaiting copyright assignment
> > paperwork.
> > 
> > Alternatively, should these patches go into a branch of queued jit
> > changes for gcc 10?
> 
> Is there anything like an ABI involved? If so we should avoid
> breaking it all the time. Otherwise JIT is not release critical and
> thus if you break it in the wrong moment it's your own fault. 

The two patches each add a new API entrypoint, but libgccjit uses
symbol-versioning to extend the ABI, without bumping the SONAME:
  https://gcc.gnu.org/onlinedocs/jit/topics/compatibility.html
So it's not an ABI break as such.

Dave


> Richard. 
> 
> > Thanks
> > Dave
> > 
> > 
> > > Bests
> > > 
> > >   Andrea
> > > 
> > > 
> > > gcc/jit/ChangeLog
> > > 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
> > > 
> > > * docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
> > > * docs/topics/contexts.rst (Additional driver options): New
> > > section.
> > > * jit-playback.c (invoke_driver): Add call to
> > > append_driver_options.
> > > * jit-recording.c: Within namespace gcc::jit...
> > > (recording::context::~context): Free the optnames within
> > > m_driver_options.
> > > (recording::context::add_driver_option): New method.
> > > (recording::context::append_driver_options): New method.
> > > (recording::context::dump_reproducer_to_file): Add driver
> > > options.
> > > * jit-recording.h: Within namespace gcc::jit...
> > > (recording::context::add_driver_option): New method.
> > > (recording::context::append_driver_options): New method.
> > > (recording::context::m_driver_options): New field.
> > > * libgccjit++.h (gccjit::context::add_driver_option): New
> > > method.
> > > * libgccjit.c (gcc_jit_context_add_driver_option): New API
> > > entrypoint.
> > > * libgccjit.h (gcc_jit_context_add_driver_option): New API
> > > entrypoint.
> > > (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
> > > macro.
> > > * libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.
> > > 
> > > 
> > > 
> > > gcc/testsuite/ChangeLog
> > > 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
> > > 
> > > * jit.dg/add-driver-options-testlib.c: Add support file for
> > > test-add-driver-options.c testcase.
> > > * jit.dg/all-non-failing-tests.h: Add note about
> > > test-add-driver-options.c
> > > * jit.dg/jit.exp (jit-dg-test): Update to support
> > > add-driver-options-testlib.c compilation.
> > > * jit.dg/test-add-driver-options.c: New testcase.
> > > 
> 
> 


Re: Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-01 Thread Richard Biener
On February 1, 2019 10:11:12 PM GMT+01:00, David Malcolm  
wrote:
>On Mon, 2019-01-21 at 08:40 +, Andrea Corallo wrote:
>> Hi all,
>> Second version of the patch addressing David's comment about all-non-
>> failing-tests.h
>> 
>> Adds gcc_jit_context_add_driver_option to the libgccjit ABI and a
>> testcase for it.
>> 
>> Using this interface is now possible to pass options affecting
>> assembler and linker.
>> 
>> Does not introduce regressions running make check-jit
>
>Thanks; the patch looks good.
>
>[CCing the release managers]
>
>Given that gcc development is now in stage 4, we really shouldn't be
>adding new features, but I'm wondering if an exception can be made for
>libgccjit?  (this patch purely touches the jit subdirectories).
>
>There's one other late-breaking change, here:
>  [PATCH][jit] Add thread-local globals to the libgccjit frontend
>https://gcc.gnu.org/ml/gcc-patches/2019-01/msg00227.html
>which is nearly ready, but is awaiting copyright assignment paperwork.
>
>Alternatively, should these patches go into a branch of queued jit
>changes for gcc 10?

Is there anything like an ABI involved? If so we should avoid breaking it all 
the time. Otherwise JIT is not release critical and thus if you break it in the 
wrong moment it's your own fault. 

Richard. 

>Thanks
>Dave
>
>
>> Bests
>> 
>>   Andrea
>> 
>> 
>> gcc/jit/ChangeLog
>> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
>> 
>> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
>> * docs/topics/contexts.rst (Additional driver options): New
>> section.
>> * jit-playback.c (invoke_driver): Add call to append_driver_options.
>> * jit-recording.c: Within namespace gcc::jit...
>> (recording::context::~context): Free the optnames within
>> m_driver_options.
>> (recording::context::add_driver_option): New method.
>> (recording::context::append_driver_options): New method.
>> (recording::context::dump_reproducer_to_file): Add driver
>> options.
>> * jit-recording.h: Within namespace gcc::jit...
>> (recording::context::add_driver_option): New method.
>> (recording::context::append_driver_options): New method.
>> (recording::context::m_driver_options): New field.
>> * libgccjit++.h (gccjit::context::add_driver_option): New
>> method.
>> * libgccjit.c (gcc_jit_context_add_driver_option): New API
>> entrypoint.
>> * libgccjit.h (gcc_jit_context_add_driver_option): New API
>> entrypoint.
>> (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
>> macro.
>> * libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.
>> 
>> 
>> 
>> gcc/testsuite/ChangeLog
>> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
>> 
>> * jit.dg/add-driver-options-testlib.c: Add support file for
>> test-add-driver-options.c testcase.
>> * jit.dg/all-non-failing-tests.h: Add note about
>> test-add-driver-options.c
>> * jit.dg/jit.exp (jit-dg-test): Update to support
>> add-driver-options-testlib.c compilation.
>> * jit.dg/test-add-driver-options.c: New testcase.
>> 



Late-breaking jit features (was Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option)

2019-02-01 Thread David Malcolm
On Mon, 2019-01-21 at 08:40 +, Andrea Corallo wrote:
> Hi all,
> Second version of the patch addressing David's comment about all-non-
> failing-tests.h
> 
> Adds gcc_jit_context_add_driver_option to the libgccjit ABI and a
> testcase for it.
> 
> Using this interface is now possible to pass options affecting
> assembler and linker.
> 
> Does not introduce regressions running make check-jit

Thanks; the patch looks good.

[CCing the release managers]

Given that gcc development is now in stage 4, we really shouldn't be
adding new features, but I'm wondering if an exception can be made for
libgccjit?  (this patch purely touches the jit subdirectories).

There's one other late-breaking change, here:
  [PATCH][jit] Add thread-local globals to the libgccjit frontend
https://gcc.gnu.org/ml/gcc-patches/2019-01/msg00227.html
which is nearly ready, but is awaiting copyright assignment paperwork.

Alternatively, should these patches go into a branch of queued jit
changes for gcc 10?

Thanks
Dave


> Bests
> 
>   Andrea
> 
> 
> gcc/jit/ChangeLog
> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
> 
> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
> * docs/topics/contexts.rst (Additional driver options): New
> section.
> * jit-playback.c (invoke_driver): Add call to append_driver_options.
> * jit-recording.c: Within namespace gcc::jit...
> (recording::context::~context): Free the optnames within
> m_driver_options.
> (recording::context::add_driver_option): New method.
> (recording::context::append_driver_options): New method.
> (recording::context::dump_reproducer_to_file): Add driver
> options.
> * jit-recording.h: Within namespace gcc::jit...
> (recording::context::add_driver_option): New method.
> (recording::context::append_driver_options): New method.
> (recording::context::m_driver_options): New field.
> * libgccjit++.h (gccjit::context::add_driver_option): New
> method.
> * libgccjit.c (gcc_jit_context_add_driver_option): New API
> entrypoint.
> * libgccjit.h (gcc_jit_context_add_driver_option): New API
> entrypoint.
> (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
> macro.
> * libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.
> 
> 
> 
> gcc/testsuite/ChangeLog
> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
> 
> * jit.dg/add-driver-options-testlib.c: Add support file for
> test-add-driver-options.c testcase.
> * jit.dg/all-non-failing-tests.h: Add note about
> test-add-driver-options.c
> * jit.dg/jit.exp (jit-dg-test): Update to support
> add-driver-options-testlib.c compilation.
> * jit.dg/test-add-driver-options.c: New testcase.
> 


Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option

2019-01-21 Thread Kyrill Tkachov

Hi David,

On 19/01/19 01:36, David Malcolm wrote:

On Fri, 2019-01-18 at 19:25 +, Andrea Corallo wrote:
> Hi all,
> this patch add gcc_jit_context_add_driver_option to the libgccjit ABI
> and a testcase for it.
>
> Using this interface is now possible to pass options affecting
> assembler and linker.
>
> Does not introduce any new regression running make check-jit.
>
> Bests
>
>   Andrea
>
>
> gcc/jit/ChangeLog
> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
>
> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
> * docs/topics/contexts.rst (Additional driver options): New
> section.
> * jit-playback.c (invoke_driver): Add call to append_driver_options.
> * jit-recording.c: Within namespace gcc::jit...
> (recording::context::~context): Free the optnames within
> m_driver_options.
> (recording::context::add_driver_option): New method.
> (recording::context::append_driver_options): New method.
> (recording::context::dump_reproducer_to_file): Add driver
> options.
> * jit-recording.h: Within namespace gcc::jit...
> (recording::context::add_driver_option): New method.
> (recording::context::append_driver_options): New method.
> (recording::context::m_driver_options): New field.
> * libgccjit++.h (gccjit::context::add_driver_option): New
> method.
> * libgccjit.c (gcc_jit_context_add_driver_option): New API
> entrypoint.
> * libgccjit.h (gcc_jit_context_add_driver_option): New API
> entrypoint.
> (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
> macro.
> * libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.
>
>
> gcc/testsuite/ChangeLog
> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
>
> * jit.dg/add-driver-options-testlib.c: Add support file for
> test-add-driver-options.c testcase.
> * jit.dg/all-non-failing-tests.h: Add test-add-driver-options.c
> * jit.dg/jit.exp (jit-dg-test): Update to support
> add-driver-options-testlib.c compilation.
> * jit.dg/test-add-driver-options.c: New testcase.

Thanks for this patch.

One nit:

[...snip...]

> diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h 
b/gcc/testsuite/jit.dg/all-non-failing-tests.h
> index bf02e12..9f816b4 100644
> --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h
> +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h
> @@ -251,6 +251,13 @@
>  #undef create_code
>  #undef verify_code
>
> +/* test-add-driver-options.c */
> +#define create_code create_code_add_driver_options
> +#define verify_code verify_code_add_driver_options
> +#include "test-add-driver-options.c"
> +#undef create_code
> +#undef verify_code
> +
>  /* Now expose the individual testcases as instances of this struct.  */
>
>  struct testcase

The purpose of the above file is to allow for copies of tests to be
built into test-combination.c and test-threads.c (to shake out state-
handling bugs).  If you're going to embed the test into those, then
they'd also need to be added to the "testcases" array towards the end
of that header.

But given that the new test adds options that affect the whole context,
it's probably best not to embed it into those combined tests.  Instead,
add a comment to all-non-failing-tests.h, similar to the one that
reads:

  /* test-extra-options.c: We don't use this one, since the extra options
 affect the whole context.  */

(changing the filename, of course).

Other than that the patch looks good.

Do you have your copyright assignment paperwork in place?



I believe Andrea's copyright assignment should be covered by the copyright 
assignment from Arm.

Thanks,
Kyrill


Also, we're currently in stage 4 of development for gcc 9, so adding a
feature to libgccjit probably requires Release Manager approval.
(Given the recent discussion on the jit mailing list, this might not be
the only late-breaking jit patch).

Dave




[PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option

2019-01-21 Thread Andrea Corallo
Hi all,
Second version of the patch addressing David's comment about 
all-non-failing-tests.h

Adds gcc_jit_context_add_driver_option to the libgccjit ABI and a testcase for 
it.

Using this interface is now possible to pass options affecting assembler and 
linker.

Does not introduce regressions running make check-jit

Bests

  Andrea


gcc/jit/ChangeLog
2019-01-16  Andrea Corallo  andrea.cora...@arm.com

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
* docs/topics/contexts.rst (Additional driver options): New
section.
* jit-playback.c (invoke_driver): Add call to append_driver_options.
* jit-recording.c: Within namespace gcc::jit...
(recording::context::~context): Free the optnames within
m_driver_options.
(recording::context::add_driver_option): New method.
(recording::context::append_driver_options): New method.
(recording::context::dump_reproducer_to_file): Add driver
options.
* jit-recording.h: Within namespace gcc::jit...
(recording::context::add_driver_option): New method.
(recording::context::append_driver_options): New method.
(recording::context::m_driver_options): New field.
* libgccjit++.h (gccjit::context::add_driver_option): New
method.
* libgccjit.c (gcc_jit_context_add_driver_option): New API
entrypoint.
* libgccjit.h (gcc_jit_context_add_driver_option): New API
entrypoint.
(LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
macro.
* libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.



gcc/testsuite/ChangeLog
2019-01-16  Andrea Corallo  andrea.cora...@arm.com

* jit.dg/add-driver-options-testlib.c: Add support file for
test-add-driver-options.c testcase.
* jit.dg/all-non-failing-tests.h: Add note about
test-add-driver-options.c
* jit.dg/jit.exp (jit-dg-test): Update to support
add-driver-options-testlib.c compilation.
* jit.dg/test-add-driver-options.c: New testcase.

diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst
index 38d338b..abefa56 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -168,6 +168,12 @@ entrypoints:
 
 ``LIBGCCJIT_ABI_10``
 
-
 ``LIBGCCJIT_ABI_10`` covers the addition of
 :func:`gcc_jit_context_new_rvalue_from_vector`
+
+.. _LIBGCCJIT_ABI_11:
+
+``LIBGCCJIT_ABI_11``
+
+``LIBGCCJIT_ABI_11`` covers the addition of
+:func:`gcc_jit_context_add_driver_option`
diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst
index 95964ca..2f8aeb7 100644
--- a/gcc/jit/docs/topics/contexts.rst
+++ b/gcc/jit/docs/topics/contexts.rst
@@ -546,3 +546,36 @@ Additional command-line options
.. code-block:: c
 
   #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option
+
+.. function:: void gcc_jit_context_add_driver_option (gcc_jit_context *ctxt,\
+		  const char *optname)
+
+   Add an arbitrary gcc driver option to the context, for use by
+   :func:`gcc_jit_context_compile` and
+   :func:`gcc_jit_context_compile_to_file`.
+
+   The parameter ``optname`` must be non-NULL.  The underlying buffer is
+   copied, so that it does not need to outlive the call.
+
+   Extra options added by `gcc_jit_context_add_driver_option` are
+   applied *after* all other options potentially overriding them.
+   Options from parent contexts are inherited by child contexts; options
+   from the parent are applied *before* those from the child.
+
+   For example:
+
+   .. code-block:: c
+
+  gcc_jit_context_add_driver_option (ctxt, "-lm");
+  gcc_jit_context_add_driver_option (ctxt, "-fuse-linker-plugin");
+
+   Note that only some options are likely to be meaningful; there is no
+   "frontend" within libgccjit, so typically only those affecting
+   assembler and linker are likely to be useful.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_11`; you can test for
+   its presence using
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 86f588d..b74495c 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -2459,6 +2459,10 @@ invoke_driver (const char *ctxt_progname,
   if (0)
 ADD_ARG ("-v");
 
+  /* Add any user-provided driver extra options.  */
+
+  m_recording_ctxt->append_driver_options ();
+
 #undef ADD_ARG
 
   /* pex_one's error-handling requires pname to be non-NULL.  */
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index 04cc6a6..8ffd0d4 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -616,6 +616,8 @@ recording::context::~context ()
   char *optname;
   FOR_EACH_VEC_ELT (m_command_line_options, i, optname)
 free (optname);
+  FOR_EACH_VEC_ELT (m_driver_options, i, optname)
+free (optname);
 
   if (m_builtins_manager)
 delete m_builtins_manager;
@@ -1307,6 +1309,31 @@ recording::context::append_command_line_options (vec  *argvec)
 argvec->safe_push (xstrdup (optname));
 }
 
+/* Add the given optname to this context's list of 

Re: [PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option

2019-01-18 Thread David Malcolm
On Fri, 2019-01-18 at 19:25 +, Andrea Corallo wrote:
> Hi all,
> this patch add gcc_jit_context_add_driver_option to the libgccjit ABI
> and a testcase for it.
> 
> Using this interface is now possible to pass options affecting
> assembler and linker.
> 
> Does not introduce any new regression running make check-jit.
> 
> Bests
> 
>   Andrea
> 
> 
> gcc/jit/ChangeLog
> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
> 
> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
> * docs/topics/contexts.rst (Additional driver options): New
> section.
> * jit-playback.c (invoke_driver): Add call to append_driver_options.
> * jit-recording.c: Within namespace gcc::jit...
> (recording::context::~context): Free the optnames within
> m_driver_options.
> (recording::context::add_driver_option): New method.
> (recording::context::append_driver_options): New method.
> (recording::context::dump_reproducer_to_file): Add driver
> options.
> * jit-recording.h: Within namespace gcc::jit...
> (recording::context::add_driver_option): New method.
> (recording::context::append_driver_options): New method.
> (recording::context::m_driver_options): New field.
> * libgccjit++.h (gccjit::context::add_driver_option): New
> method.
> * libgccjit.c (gcc_jit_context_add_driver_option): New API
> entrypoint.
> * libgccjit.h (gcc_jit_context_add_driver_option): New API
> entrypoint.
> (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
> macro.
> * libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.
> 
> 
> gcc/testsuite/ChangeLog
> 2019-01-16  Andrea Corallo  andrea.cora...@arm.com
> 
> * jit.dg/add-driver-options-testlib.c: Add support file for
> test-add-driver-options.c testcase.
> * jit.dg/all-non-failing-tests.h: Add test-add-driver-options.c
> * jit.dg/jit.exp (jit-dg-test): Update to support
> add-driver-options-testlib.c compilation.
> * jit.dg/test-add-driver-options.c: New testcase.

Thanks for this patch.

One nit:

[...snip...]

> diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h 
> b/gcc/testsuite/jit.dg/all-non-failing-tests.h
> index bf02e12..9f816b4 100644
> --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h
> +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h
> @@ -251,6 +251,13 @@
>  #undef create_code
>  #undef verify_code
>  
> +/* test-add-driver-options.c */
> +#define create_code create_code_add_driver_options
> +#define verify_code verify_code_add_driver_options
> +#include "test-add-driver-options.c"
> +#undef create_code
> +#undef verify_code
> +
>  /* Now expose the individual testcases as instances of this struct.  */
>  
>  struct testcase

The purpose of the above file is to allow for copies of tests to be
built into test-combination.c and test-threads.c (to shake out state-
handling bugs).  If you're going to embed the test into those, then
they'd also need to be added to the "testcases" array towards the end
of that header.

But given that the new test adds options that affect the whole context,
it's probably best not to embed it into those combined tests.  Instead,
add a comment to all-non-failing-tests.h, similar to the one that
reads:

  /* test-extra-options.c: We don't use this one, since the extra options
 affect the whole context.  */

(changing the filename, of course).

Other than that the patch looks good.

Do you have your copyright assignment paperwork in place?

Also, we're currently in stage 4 of development for gcc 9, so adding a
feature to libgccjit probably requires Release Manager approval. 
(Given the recent discussion on the jit mailing list, this might not be
the only late-breaking jit patch).

Dave


[PATCH][gcc] libgccjit: introduce gcc_jit_context_add_driver_option

2019-01-18 Thread Andrea Corallo
Hi all,
this patch add gcc_jit_context_add_driver_option to the libgccjit ABI and a 
testcase for it.

Using this interface is now possible to pass options affecting assembler and 
linker.

Does not introduce any new regression running make check-jit.

Bests

  Andrea


gcc/jit/ChangeLog
2019-01-16  Andrea Corallo  andrea.cora...@arm.com

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
* docs/topics/contexts.rst (Additional driver options): New
section.
* jit-playback.c (invoke_driver): Add call to append_driver_options.
* jit-recording.c: Within namespace gcc::jit...
(recording::context::~context): Free the optnames within
m_driver_options.
(recording::context::add_driver_option): New method.
(recording::context::append_driver_options): New method.
(recording::context::dump_reproducer_to_file): Add driver
options.
* jit-recording.h: Within namespace gcc::jit...
(recording::context::add_driver_option): New method.
(recording::context::append_driver_options): New method.
(recording::context::m_driver_options): New field.
* libgccjit++.h (gccjit::context::add_driver_option): New
method.
* libgccjit.c (gcc_jit_context_add_driver_option): New API
entrypoint.
* libgccjit.h (gcc_jit_context_add_driver_option): New API
entrypoint.
(LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option): New
macro.
* libgccjit.map (LIBGCCJIT_ABI_11): New ABI tag.


gcc/testsuite/ChangeLog
2019-01-16  Andrea Corallo  andrea.cora...@arm.com

* jit.dg/add-driver-options-testlib.c: Add support file for
test-add-driver-options.c testcase.
* jit.dg/all-non-failing-tests.h: Add test-add-driver-options.c
* jit.dg/jit.exp (jit-dg-test): Update to support
add-driver-options-testlib.c compilation.
* jit.dg/test-add-driver-options.c: New testcase.


diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst
index 38d338b..abefa56 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -168,6 +168,12 @@ entrypoints:
 
 ``LIBGCCJIT_ABI_10``
 
-
 ``LIBGCCJIT_ABI_10`` covers the addition of
 :func:`gcc_jit_context_new_rvalue_from_vector`
+
+.. _LIBGCCJIT_ABI_11:
+
+``LIBGCCJIT_ABI_11``
+
+``LIBGCCJIT_ABI_11`` covers the addition of
+:func:`gcc_jit_context_add_driver_option`
diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst
index 95964ca..2f8aeb7 100644
--- a/gcc/jit/docs/topics/contexts.rst
+++ b/gcc/jit/docs/topics/contexts.rst
@@ -546,3 +546,36 @@ Additional command-line options
.. code-block:: c
 
   #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option
+
+.. function:: void gcc_jit_context_add_driver_option (gcc_jit_context *ctxt,\
+		  const char *optname)
+
+   Add an arbitrary gcc driver option to the context, for use by
+   :func:`gcc_jit_context_compile` and
+   :func:`gcc_jit_context_compile_to_file`.
+
+   The parameter ``optname`` must be non-NULL.  The underlying buffer is
+   copied, so that it does not need to outlive the call.
+
+   Extra options added by `gcc_jit_context_add_driver_option` are
+   applied *after* all other options potentially overriding them.
+   Options from parent contexts are inherited by child contexts; options
+   from the parent are applied *before* those from the child.
+
+   For example:
+
+   .. code-block:: c
+
+  gcc_jit_context_add_driver_option (ctxt, "-lm");
+  gcc_jit_context_add_driver_option (ctxt, "-fuse-linker-plugin");
+
+   Note that only some options are likely to be meaningful; there is no
+   "frontend" within libgccjit, so typically only those affecting
+   assembler and linker are likely to be useful.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_11`; you can test for
+   its presence using
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 86f588d..b74495c 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -2459,6 +2459,10 @@ invoke_driver (const char *ctxt_progname,
   if (0)
 ADD_ARG ("-v");
 
+  /* Add any user-provided driver extra options.  */
+
+  m_recording_ctxt->append_driver_options ();
+
 #undef ADD_ARG
 
   /* pex_one's error-handling requires pname to be non-NULL.  */
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index b9c6544..b9f2250 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -218,6 +218,12 @@ public:
   append_command_line_options (vec  *argvec);
 
   void
+  add_driver_option (const char *optname);
+
+  void
+  append_driver_options (auto_string_vec *argvec);
+
+  void
   enable_dump (const char *dumpname,
 	   char **out_ptr);
 
@@ -317,6 +323,7 @@ private:
   bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
   bool m_inner_bool_options[NUM_INNER_BOOL_OPTIONS];
   auto_vec  m_command_line_options;
+  auto_vec  m_driver_options;
 
   /* Dumpfiles that were requested via gcc_jit_context_enable_dump.  */