[doc] Re: install.texi and alpha

2019-08-19 Thread Gerald Pfeifer
On Sun, 12 Mar 2017, Gerald Pfeifer wrote:
>> References to dependencies on really, really old versions of
>> binutils (talking 10+ years here) which I think we can remove.
>> Let me follow-up with some of you with concrete suggestions 
>> around that.
> 
> The alpha*-*-* section currently has this:
> 
>   We require binutils 2.11.2 or newer.
>   Previous binutils releases had a number of problems with DWARF 2
>   debugging information, not the least of which is incorrect linking of
>   shared libraries.
> 
> Okay to yank this?

I do not recall ever seeing a response, and it's now been two
further years, so I went ahead and committed the patch below.

Gerald

2019-08-20  Gerald Pfeifer  

* doc/install.texi (Specific, alpha): Remove note to use
binutils 2.11.2 or later.

Index: doc/install.texi
===
--- doc/install.texi(revision 274619)
+++ doc/install.texi(working copy)
@@ -3472,11 +3472,6 @@ This section contains general configuration inform
 Alpha-based platforms using ELF@.  In addition to reading this
 section, please read all other sections that match your target.
 
-We require binutils 2.11.2 or newer.
-Previous binutils releases had a number of problems with DWARF 2
-debugging information, not the least of which is incorrect linking of
-shared libraries.
-
 @html
 
 @end html


Re: [PATCH] issue consistent warning for past-the-end array stores (PR 91457)

2019-08-19 Thread Martin Sebor

On 8/19/19 8:10 AM, Richard Biener wrote:

On Sat, Aug 17, 2019 at 12:43 AM Martin Sebor  wrote:


With the recent enhancement to the strlen handling of multibyte
stores the g++.dg/warn/Warray-bounds-4.C for zero-length arrays
started failing on hppa (and probably elsewhere as well).  This
is partly the result of the added detection of past-the-end
writes into the strlen pass which detects more instances of
the problem than -Warray-bounds.  Since the IL each warning
works with varies between targets, the same invalid code can
be diagnosed by one warning one target and different warning
on another.

The attached patch does three things:

1) It enhances compute_objsize to also determine the size of
a flexible array member (and its various variants), including
from its initializer if necessary.  (This resolves 91457 but
introduces another warning where was previously just one.)
2) It guards the new instance of -Wstringop-overflow with
the no-warning bit on the assignment to avoid warning on code
that's already been diagnosed.
3) It arranges for -Warray-bounds to set the no-warning bit on
the enclosing expression to keep -Wstringop-overflow from issuing
another warning for the same problem.

Testing the compute_objsize enhancement to bring it up to par
with -Warray-bounds in turn exposed a weakness in the latter
warning for flexible array members.  Rather than snowballing
additional improvements into this one I decided to put that
off until later, so the new -Warray-bounds test has a bunch
of XFAILs.  I'll see if I can find the time to deal with those
either still in stage 1 or in stage 3 (one of them is actually
an ancient regression).


+static tree
+get_initializer_for (tree init, tree decl)
+{

can't you use fold_ctor_reference here?


Yes, but only with an additional enhancement.  Char initializers
for flexible array members aren't transformed to STRING_CSTs yet,
so without the size of the initializer specified, the function
returns the initializer for the smallest subobject, or char in
this case.  I've enhanced the function to handle them.



+/* Determine the size of the flexible array FLD from the initializer
+   expression for the struct object DECL in which the meber is declared
+   (possibly recursively).  Return the size or zero constant if it isn't
+   initialized.  */
+
+static tree
+get_flexarray_size (tree decl, tree fld)
+{
+  if (tree init = DECL_INITIAL (decl))
+{
+  init = get_initializer_for (init, fld);
+  if (init)
+   return TYPE_SIZE_UNIT (TREE_TYPE (init));
+}
+
+  return integer_zero_node;

so you're hoping that the (sub-)CONSTRUCTOR get_initializer_for
returns has a complete type but the initialized object didn't get it
completed.  Isnt that wishful thinking?


I don't know what you mean.  When might a CONSTRUCTOR not have
a complete type, and if/when it doesn't, why would that be
a problem here?  TYPE_SIZE_UNIT will evaluate to null meaning
"don't know" and that's fine.  Could you try to be more specific
about the problem you're pointing out?


And why return integer_zero_node
rather than NULL_TREE here?


Because the size of a flexible array member with no initializer
is zero.



+  if (TREE_CODE (dest) == COMPONENT_REF)
+{
+  *pdecl = TREE_OPERAND (dest, 1);
+
+  /* If the member has a size return it.  Otherwise it's a flexible
+array member.  */
+  if (tree size = DECL_SIZE_UNIT (*pdecl))
+   return size;

because here you do.


Not sure what you mean here either.  (This code was also a bit
out of date WRT to the patch I had tested.  Not sure how that
happened.  The attached patch is up to date.)



Also once you have an underlying VAR_DECL you can compute
the flexarray size by DECL_SIZE (var) - offset-of flexarray member.
Isn't that way cheaper than walking the initializer (possibly many
times?)


It would be nice if it were this easy.  Is the value of DECL_SIZE
(var) supposed to include the size of the flexible array member?
I don't see it mentioned in the comments in tree.h and in my tests
it only does in C but not in C++.  Is that a bug that in C++ it
doesn't?

Attached is an updated patch that uses fold_ctor_reference as you
suggested.  I've also made a few other minor changes to diagnose
a few more invalid strlen calls with out-of-bounds offsets.
(More still remain.)

Martin



Richard.



Martin

PS I imagine the new get_flexarray_size function will probably
need to move somewhere more appropriate so that other warnings
(like -Warray-bounds to remove the XFAILs) and optimizations
can make use of it.


PR tree-optimization/91457 - inconsistent warning for writing past the end of an array member

gcc/testsuite/ChangeLog:

	PR tree-optimization/91457
	* c-c++-common/Wstringop-overflow-2.c: New test.
	* g++.dg/warn/Warray-bounds-8.C: New test.
	* g++.dg/warn/Wstringop-overflow-3.C: New test.
	* gcc.dg/Wstringop-overflow-15.c: New test.

gcc/ChangeLog:

	PR tree-optimization/91457
	* builtins.c (c_strlen): Rename argument and 

Re: [PATCH 2/8] bpf: new GCC port

2019-08-19 Thread Jim Wilson
On Mon, Aug 19, 2019 at 5:01 AM Segher Boessenkool
 wrote:
>
> On Thu, Aug 15, 2019 at 12:22:46AM +0200, Jose E. Marchesi wrote:
> > --- a/configure
> > +++ b/configure
> > @@ -754,6 +754,7 @@ infodir
> >  docdir
> >  oldincludedir
> >  includedir
> > +runstatedir
> >  localstatedir
> >  sharedstatedir
> >  sysconfdir
>
> (etc.)
>
> You seem to have generated this with the wrong version of auto, or
> the wrong options, or the previous version was.  Please check?  Or, what
> else caused this change?

My experience is that this is a commonly added patch to the system
autoconf binary, e.g. /usr/bin/autoconf.  So you need to build your
own autoconf from the FSF sources to get an exact match.  Or maybe use
a different linux distro that doesn't modify autoconf.  But personally
I just build my own autoconf binaries to avoid this problem.

Jim


Re: [EXTERNAL]Re: [PATCH 1/2][MIPS] Emit .note.GNU-stack for soft-float linux targets.

2019-08-19 Thread Jeff Law
On 8/12/19 9:21 AM, Dragan Mladjenovic wrote:
> On 09.08.2019. 23:31, Jeff Law wrote:
>> On 8/5/19 4:47 AM, Dragan Mladjenovic wrote:
>>> From: "Dragan Mladjenovic" 
>>>
>>> gcc/ChangeLog:
>>>
>>> 2019-08-05  Dragan Mladjenovic  
>>>
>>> * config/mips/linux.h (NEED_INDICATE_EXEC_STACK): Define to
>>> TARGET_SOFT_FLOAT.
>>> * config/mips/mips.c (TARGET_ASM_FILE_END): Define to ...
>>> (mips_asm_file_end): New function. Delegate to
>>> file_end_indicate_exec_stack if NEED_INDICATE_EXEC_STACK is true.
>>> * config/mips/mips.h (NEED_INDICATE_EXEC_STACK): Define to 0.
>>>
>>> libgcc/ChangeLog:
>>>
>>> 2019-08-05  Dragan Mladjenovic  
>>>
>>> * config/mips/gnustack.h: New file.
>>> * config/mips/crti.S: Include gnustack.h.
>>> * config/mips/crtn.S: Likewise.
>>> * config/mips/mips16.S: Likewise.
>>> * config/mips/vr4120-div.S: Likewise.
>> Seems reasonable.  What testing has been done for this patch?  I don't
>> doubt it works for the MIPS linux targets, I'm more interested in making
>> sure it doesn't do the wrong thing for the embedded mips targets.
> 
> I've built a cross mips-mti-elf toolchain, albeit with reduced multilib, 
> but still there were not .note.GNU-stack in sysroot.
> Is this enough?
Yea.  Mostly just wanted to make sure the *-elf targets still build -- I
didn't expect problems, but it's good to have sanity checking.

> 
>  >
>  > Do you have write access to the repository?
>  >
> 
> I do not have write access to the repository.
We should probably fix that.

https://sourceware.org/cgi-bin/pdw/ps_form.cgi

List me as your sponsor.



jeff



Re: [PATCHv5] Fix not 8-byte aligned ldrd/strd on ARMv5 (PR 89544)

2019-08-19 Thread Jeff Law
On 8/15/19 1:47 PM, Bernd Edlinger wrote:
> On 8/15/19 6:29 PM, Richard Biener wrote:
 Please split it into the parts for the PR and parts making the
 asserts not trigger.

>>> Yes, will do.
>>>
> Okay, here is the rest of the PR 89544 fix,
> actually just an optimization, making the larger stack alignment
> known to the middle-end, and the test cases.
> 
> 
> Boot-strapped and reg-tested on x86_64-pc-linux-gnu and arm-linux-gnueabihf.
> Is it OK for trunk?
> 
> 
> Thanks
> Bernd.
> 
> 
> patch-arm-align-abi.diff
> 
> 2019-08-15  Bernd Edlinger  
> 
>   PR middle-end/89544
>   * function.c (assign_parm_find_stack_rtl): Use larger alignment
>   when possible.
> 
> testsuite:
> 2019-08-15  Bernd Edlinger  
> 
>   PR middle-end/89544
>   * gcc.target/arm/unaligned-argument-1.c: New test.
>   * gcc.target/arm/unaligned-argument-2.c: New test.
OK.

Given the sensitivity of this code, let's give the tester a chance to
run with this patch applied before we add the next one for sanitizing
the middle end interface.

jeff


Re: [PATCH] Improve DSE to handle redundant zero initializations.

2019-08-19 Thread Jeff Law
On 8/19/19 1:53 PM, Matthew Beliveau wrote:

>> Jeff
> 
> DSE-3.patch
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2019-08-19  Matthew Beliveau  
> 
>   * tree-ssa-dse.c (dse_optimize_redundant_stores): Improved check to
>   catch more redundant zero initialization cases.
>   (dse_dom_walker::dse_optimize_stmt): Likewise.
> 
>   * gcc.dg/tree-ssa/redundant-assign-zero-1.c: New test.
>   * gcc.dg/tree-ssa/redundant-assign-zero-2.c: New test.
OK for the trunk.  THanks for your patience.

Jeff


Re: [PATCH,i386] Don't use errno when freestanding (was: config/i386/xmmintrin.h: Only #include if __STDC_HOSTED__)

2019-08-19 Thread Jeff Law
On 8/18/19 10:29 AM, Gerald Pfeifer wrote:
> On Sat, 9 Dec 2017, Jakub Jelinek wrote:
>>> Some users on FreeBSD noticed a problem when trying to use GCC to
>>> build things in a standalone environment that manifests itself as
>>>
>>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/xmmintrin.h:34 
>>> from
>>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/immintrin.h:29 
>>> from
>>> /workspace/src/sys/crypto/aesni/intel_sha256.c:62 
>>> In function '_mm_malloc':
>>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/mm_malloc.h:39: 
>>> error: 'errno' undeclared (first use in this function)
>>>
>>> It turns out the clang version of xmmintrin.h does not include mm_malloc.h 
>>> if !__STDC_HOSTED__ whereas ours unconditionally does so.
>>
>> Wouldn't it be better to just ifdef out parts of gmm_malloc.h (pmm_malloc.h
>> should be ok)?
> 
> Very good point, Jakub.  Thank you!  
> 
> Somehow I thought I had submitted this updated patch, but apparently 
> not so. :-(  (This has been on my autotester for ages.)
> 
> Okay?  And if so, okay for GCC 9 after a while?
> 
> Gerald
> 
> 
> 2019-08-18  Gerald Pfeifer  
>  
>   * config/i386/gmm_malloc.h: Only include errno.h and use errno
>   if __STDC_HOSTED__.
OK.
jeff



Re: [PATCH] Intrinsic documentation for DIM, MOD and MODULO.

2019-08-19 Thread Jeff Law
On 8/19/19 10:19 AM, Steve Kargl wrote:
> On Mon, Aug 19, 2019 at 09:08:12AM -0600, Jeff Law wrote:
>> On 8/19/19 3:11 AM, Mark Eggleston wrote:
>>> The intrinsics DIM, MOD and MODULO can accept arguments of different
>>> kinds and return values with the larger of the two kinds. Notes to this
>>> effect have been added as they were missing from the documentation.
>>>
>>> Please find attached the patch.
>>>
>>> ChangeLog:
>>>
>>> gcc/fortran/ChangeLog
>>>
>>>     Mark Eggleston  
>>>
>>>     PR fortran/89236
>>>     * intrinsic.texi: Add GNU extension notes to DIM, MOD, MODULO.
>>>
>> Do we want to be more specific about what types are accepted as a GNU
>> extension for these operators?
>>
> 
> The current documentation already has that info.
Ah, in that case Mark's patch seems like a no-brainer :-)

Jeff


Re: [PATCH] Adding _Dependent_ptr type qualifier in C part 1/3

2019-08-19 Thread Joseph Myers
On Tue, 30 Jul 2019, Martin Sebor wrote:

> On 7/30/19 1:13 AM, Akshat Garg wrote:
> > Hi,
> > This patch includes C front-end code for a type qualifier _Dependent_ptr.
> 
> Just some very high-level comments/questions.  I only followed
> the _Dependent_ptr discussion from a distance and I'm likely
> missing some context so the first thing I looked for in this
> patch is documentation of the new qualifier.  Unless it's

The first question for any new thing that is syntactically a qualifier is: 
is it intended generally to be counted as a qualifier where the standard 
refers to qualified type, the unqualified version of a type, etc.?  Or is 
it, like _Atomic, a qualifier only syntactically and generally excluded 
from references to qualifiers?

For the _Atomic implementation I had to go through all the references to 
qualifiers or TYPE_MAIN_VARIANT in the front end and consider in each case 
whether it handled _Atomic correctly, given that _Atomic is not counted as 
a qualifier in the standard (so the unqualified version of const _Atomic 
int is _Atomic int not int, and so can't be derived simply by using 
TYPE_MAIN_VARIANT, for example).  Some cases didn't need changing because 
the handling (e.g. diagnostic for different types) was still appropriate 
for _Atomic even though not formally a qualifier, but plenty did need 
changing and associated tests added.

Such a check of front end code is probably unavoidable (before a change is 
ready for trunk, not necessarily for an initial rough RFC patch) for any 
new qualifier, whether it counts as a qualifier in standard terms or not 
(and the patch reviewer will need to do their own check of references to 
qualifiers or TYPE_MAIN_VARIANT that didn't get changed by the patch), but 
the answer to that question helps indicate whether the default is to 
expect code to need changing for the new qualifier or not.

> you point to it?  (In that case, or if a proposal is planned,
> the feature should probably either only be available with
> -std=c2x and -std=gnu2x or a pedantic warning should be issued

There should not be any -std=c2x (flag_isoc2x) conditionals simply based 
on "a proposal is planned".  flag_isoc2x conditionals (pedwarn_c11 calls, 
etc.) should be for cases where a feature is *accepted and committed into 
the C2x branch of Jens's git repository for the C standard*, not for 
something that might be proposed, or is proposed, but doesn't yet have 
specific text integrated into the text of the standard.

If something is simply proposed *and we've concluded it's a good feature 
to have as an extension in any case* then you have a normal 
pedwarn-if-pedantic (no condition on standard version) as for any GNU 
extension (and flag_isoc2x conditions / changes to use pedwarn_c11 instead 
can be added later if the extension is added to the standard).

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [13/13] Add a pass_by_reference flag to function_arg_info

2019-08-19 Thread Jeff Law
On 8/19/19 9:24 AM, Richard Sandiford wrote:
> This patch adds a flag that tells targets whether an argument
> has been converted to pass-by-reference form.  This replaces
> assign_parm_data_one::passed_pointer in function.c.
> 
> The flag is set automatically for places that call
> apply_pass_by_reference_rules.  Places that apply
> pass-by-reference manually need to set it themselves.
> 
> (After previous changes, no targets apply pass-by-reference
> manually.  They all go through apply_pass_by_reference_rules.)
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * calls.h (function_arg_info): Add a pass_by_reference field,
>   defaulting to false.
>   * calls.c (apply_pass_by_reference_rules): Set pass_by_reference
>   when applying pass-by-reference semantics.
>   (initialize_argument_information): Likewise.
>   (emit_library_call_value_1): Likewise.
>   * function.c (assign_parm_data_one): Remove passed_pointer field.
>   (assign_parm_find_data_types): Don't set it.
>   (assign_parm_find_stack_rtl, assign_parm_adjust_stack_rtl)
>   (assign_parm_setup_reg, assign_parms, gimplify_parameters): Use
>   arg.pass_by_reference instead of passed_pointer.
> 
OK.  I think that's the whole series.  I don't expect any problems, but
my tester will pick testing across the various targets ~24hrs after
you've committed the changes.

jeff


Re: [12/13] Make calls.c use function_arg_info internally

2019-08-19 Thread Jeff Law
On 8/19/19 9:23 AM, Richard Sandiford wrote:
> This patch makes the two main calls.c argument-processing
> routines track the state of the argument in a function_arg_info
> instead of using separate mode variables.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * calls.c (emit_library_call_value_1): Merge arg and orig_arg
>   into a single function_arg_info, updating its fields when we
>   apply pass-by-reference and promotion semantics.  Use the
>   function_arg_info to track the mode rather than keeping it in
>   a separate local variable.
>   (initialize_argument_information): Likewise.  Base the final
>   arg_to_skip on this new function_arg_info rather than creating
>   a new one from scratch.
> 
OK
jeff


Re: [11/13] Make function.c use function_arg_info internally

2019-08-19 Thread Jeff Law
On 8/19/19 9:22 AM, Richard Sandiford wrote:
> This patch adds a function_arg_info field to assign_parm_data_one,
> so that:
> 
>   - passed_type -> arg.type
>   - promoted_mode -> arg.mode
>   - named_arg -> arg.named
> 
> We can then pass this function_arg_info directly to the converted
> hooks.
> 
> Between the initialisation of the assign_parm_data_one and the
> application of promotion rules (which is a state internal to
> assign_parm_find_data_types), arg.mode is equivalent to passed_mode
> (i.e. to TYPE_MODE).
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * function.c (assign_parm_data_one): Replace passed_type,
>   promoted_mode and named_arg with a function_arg_info field.
>   (assign_parm_find_data_types): Remove local variables and
>   assign directly to "data".  Make data->passed_mode shadow
>   data->arg.mode until promotion, then assign the promoted
>   mode to data->arg.mode.
>   (assign_parms_setup_varargs, assign_parm_find_entry_rtl)
>   (assign_parm_find_stack_rtl, assign_parm_adjust_entry_rtl)
>   (assign_parm_remove_parallels, assign_parm_setup_block_p)
>   (assign_parm_setup_block, assign_parm_setup_reg)
>   (assign_parm_setup_stack, assign_parms, gimplify_parameters): Use
>   arg.mode instead of promoted_mode, arg.type instead of passed_type
>   and arg.named instead of named_arg.  Use data->arg for
>   function_arg_info structures that had the field values passed_type,
>   promoted_mode and named_arg.  Base other function_arg_infos on
>   data->arg, changing the necessary properties.
OK
jeff


Re: Fix up -fexcess-precision handling in LTO (was Re: [GCC][middle-end] Add rules to strip away unneeded type casts in expressions (2nd patch))

2019-08-19 Thread Joseph Myers
On Tue, 30 Jul 2019, Jakub Jelinek wrote:

> Furthermore, some comments claimed that the proper EXCESS_PRECISION_STANDARD
> handling requires FE support, but that also doesn't seem to be the case
> these days, some FEs even just use EXCESS_PRECISION_STANDARD by default
> (go, D).
> 
> So, the following patch gets rid of flag_excess_precision and renames
> flag_excess_precision_cmdline to flag_excess_precision, plus adds
> Optimization flag to that command line option, so that we remember it during
> compilation and e.g. during LTO can then have some functions with standard
> excess precision and others with fast excess precision.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK minus the removal of the comment in lhd_post_options.  Proper handling 
requires front-end support (to generate GIMPLE with the operations in the 
intended type).  Back-end support (to avoid having insn patterns claiming 
to operate on the types the processor in fact does not have direct support 
for arithmetic on), although not strictly required, is a very good idea, 
to make it more obvious if something is wrongly generating arithmetic on 
inappropriate types.  And then you need the middle-end support (to avoid 
transformations introducing operations in the types that aren't meant to 
have direct operations, even if in fact the semantics are equivalent) as 
well.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] PR libstdc++/91371 make std::is_function handle other calling conventions

2019-08-19 Thread Jonathan Wakely

On 16/08/19 16:35 +0100, Jonathan Wakely wrote:

The x86 attributes such as ms_abi, stdcall, fastcall etc. alter the
function type, which means that functions with one of those attributes
do not match any of the partial specializations of std::is_function.

Rather than duplicating the list for every calling convention, this
adds a fallback to the std::is_function primary template which
identifies other function types. The fallback works by assuming that
all function types fall into one of two categories: referenceable and
abominable. The former can be detected by testing for
function-to-pointer decay, and the latter are non-referenceable types
that are not cv void.

In order to detect referenceable types it's necessary to replace the
current definition of __is_referenceable with one that doesn't depend on
std::is_function, to avoid a cycle. The definition of std::decay can
also be modified to only act on referenceable function types, because
abominable function types do not decay.

PR libstdc++/91371
* include/std/type_traits (__declval, declval, __void_t): Declare
earlier in the file.
(__is_referenceable): Rewrite to not depend on is_function.
(__is_referenceable_function): New trait to identify non-abominable
function types.
(__is_qualified_function): New alias to identify abominable function
types.
(is_function): Make primary template use __is_referenceable_function
and __is_qualified_function to detect function types not covered by
the partial specializations.
(__decay_selector): Use __is_referenceable_function instead of
is_function.
(__decay_selector<_Up, false, true>): Do not use add_pointer.
* testsuite/20_util/bind/91371.cc: New test.
* testsuite/20_util/is_function/91371.cc: New test.
* testsuite/20_util/is_function/value.cc: Check more pointer types.
* testsuite/20_util/is_member_function_pointer/91371.cc: New test.

Tested x86_64-linux. Not committed yet.

I'd like to hear Daniel's thoughts on this approach, as he wrote the
original __is_referenceable trait, and much of .

This new __is_referenceable simply uses void_t to detect whether
forming T& is valid.

The detection for function-to-pointer decay works by checking whether
static_cast(declval()) is well-formed. If T is not a class
type (which could have a conversion operator) and is not nullptr or cv
void*cv (which can convert to nullptr* and cv void*cv* repectively)
then it must be a function.

The detection for abominable function types assumes that all types are
referenceable except functions with cv- or ref-qualifiers and cv void
types. So if it's not referenceable and not void, it's an abominable
function type.


Alisdair pointed out a much simpler implementation of is_function:

 /// is_function
 template
   struct is_function
   : public __bool_constant::value> { };

 template
   struct is_function<_Tp&>
   : public false_type { };

 template
   struct is_function<_Tp&&>
   : public false_type { };

I'm testing the attached patch which uses the above trick and keeps my
earlier simplification for __is_referenceable. I plan to commit this,
probably tomorrow.


commit 310eae1386a8410682b86aef3fa5391018583577
Author: Jonathan Wakely 
Date:   Mon Aug 19 22:04:58 2019 +0100

PR libstdc++/91371 make std::is_function handle other calling conventions

The x86 attributes such as ms_abi, stdcall, fastcall etc. alter the
function type, which means that functions with one of those attributes
do not match any of the partial specializations of std::is_function.

Rather than duplicating the list for every calling convention, use a
much simpler definition of std::is_function.

Also redefine __is_referenceable to not rely on partial specializations
for each type of referenceable function.

PR libstdc++/91371
* include/std/type_traits (is_function): Simplify definition. Remove
partial specializations for function types.
(__is_referenceable): Simplify definition.
* testsuite/20_util/bind/91371.cc: New test.
* testsuite/20_util/is_function/91371.cc: New test.
* testsuite/20_util/is_function/value.cc: Check more pointer types.
* testsuite/20_util/is_member_function_pointer/91371.cc: New test.
* testsuite/20_util/is_object/91371.cc: New test.

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 44db2cade5d..443208813b1 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -223,11 +223,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   struct __failure_type
   { };
 
-  // Primary type categories.
-
   template
 struct remove_cv;
 
+  template
+struct is_const;
+
+  // Primary type categories.
+
   template
 struct __is_void_helper
 : public false_type { };
@@ -481,105 

Go patch committed: New debugging functions

2019-08-19 Thread Ian Lance Taylor
This Go patch by Than McIntosh adds some new debugging output
methods/functions, to dump named objects, package bindings, and the
top level Gogo package list.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 274678)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-b0ba5daa8216a0424b24f74466cedab0b986f3b4
+a453eebae76296a39a1ded5bd2bffa78bedf40bd
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/gogo.cc
===
--- gcc/go/gofrontend/gogo.cc   (revision 274169)
+++ gcc/go/gofrontend/gogo.cc   (working copy)
@@ -5430,6 +5430,29 @@ Gogo::convert_named_types_in_bindings(Bi
 }
 }
 
+void
+debug_go_gogo(Gogo* gogo)
+{
+  if (gogo != NULL)
+gogo->debug_dump();
+}
+
+void
+Gogo::debug_dump()
+{
+  std::cerr << "Packages:\n";
+  for (Packages::const_iterator p = this->packages_.begin();
+   p != this->packages_.end();
+   ++p)
+{
+  const char *tag = "  ";
+  if (p->second == this->package_)
+tag = "* ";
+  std::cerr << tag << "'" << p->first << "' "
+<< p->second->pkgpath() << " " << ((void*)p->second) << "\n";
+}
+}
+
 // Class Function.
 
 Function::Function(Function_type* type, Named_object* enclosing, Block* block,
@@ -8593,6 +8616,61 @@ Named_object::get_id(Gogo* gogo)
   return decl_name;
 }
 
+void
+debug_go_named_object(Named_object* no)
+{
+  if (no == NULL)
+{
+  std::cerr << "";
+  return;
+}
+  std::cerr << "'" << no->name() << "': ";
+  const char *tag;
+  switch (no->classification())
+{
+  case Named_object::NAMED_OBJECT_UNINITIALIZED:
+tag = "uninitialized";
+break;
+  case Named_object::NAMED_OBJECT_ERRONEOUS:
+tag = "";
+break;
+  case Named_object::NAMED_OBJECT_UNKNOWN:
+tag = "";
+break;
+  case Named_object::NAMED_OBJECT_CONST:
+tag = "constant";
+break;
+  case Named_object::NAMED_OBJECT_TYPE:
+tag = "type";
+break;
+  case Named_object::NAMED_OBJECT_TYPE_DECLARATION:
+tag = "type_decl";
+break;
+  case Named_object::NAMED_OBJECT_VAR:
+tag = "var";
+break;
+  case Named_object::NAMED_OBJECT_RESULT_VAR:
+tag = "result_var";
+break;
+  case Named_object::NAMED_OBJECT_SINK:
+tag = "";
+break;
+  case Named_object::NAMED_OBJECT_FUNC:
+tag = "func";
+break;
+  case Named_object::NAMED_OBJECT_FUNC_DECLARATION:
+tag = "func_decl";
+break;
+  case Named_object::NAMED_OBJECT_PACKAGE:
+tag = "package";
+break;
+  default:
+tag = "";
+break;
+  };
+  std::cerr << tag << "\n";
+}
+
 // Get the backend representation for this named object.
 
 void
@@ -9140,6 +9218,31 @@ Bindings::traverse(Traverse* traverse, b
   return TRAVERSE_CONTINUE;
 }
 
+void
+Bindings::debug_dump()
+{
+  std::set defs;
+  for (size_t i = 0; i < this->named_objects_.size(); ++i)
+defs.insert(this->named_objects_[i]);
+  for (Contour::iterator p = this->bindings_.begin();
+   p != this->bindings_.end();
+   ++p)
+{
+  const char* tag = "  ";
+  if (defs.find(p->second) != defs.end())
+tag = "* ";
+  std::cerr << tag;
+  debug_go_named_object(p->second);
+}
+}
+
+void
+debug_go_bindings(Bindings* bindings)
+{
+  if (bindings != NULL)
+bindings->debug_dump();
+}
+
 // Class Label.
 
 // Clear any references to this label.
Index: gcc/go/gofrontend/gogo.h
===
--- gcc/go/gofrontend/gogo.h(revision 274169)
+++ gcc/go/gofrontend/gogo.h(working copy)
@@ -341,6 +341,9 @@ class Gogo
   set_debug_optimization(bool b)
   { this->debug_optimization_ = b; }
 
+  // Dump to stderr for debugging
+  void debug_dump();
+
   // Return the size threshold used to determine whether to issue
   // a nil-check for a given pointer dereference. A threshold of -1
   // implies that all potentially faulting dereference ops should
@@ -3068,6 +3071,9 @@ class Bindings
   first_declaration()
   { return this->bindings_.empty() ? NULL : this->bindings_.begin()->second; }
 
+  // Dump to stderr for debugging
+  void debug_dump();
+
  private:
   Named_object*
   add_named_object_to_contour(Contour*, Named_object*);
@@ -3746,4 +3752,10 @@ extern Gogo* go_get_gogo();
 // interface.
 extern bool saw_errors();
 
+// For use in the debugger
+extern void debug_go_gogo(Gogo*);
+extern void debug_go_named_object(Named_object*);
+extern void debug_go_bindings(Bindings*);
+
+
 #endif // !defined(GO_GOGO_H)


Re: [10/13] Add a apply_pass_by_reference_rules helper

2019-08-19 Thread Jeff Law
On 8/19/19 9:21 AM, Richard Sandiford wrote:
> This patch adds a helper routine that applies pass-by-reference
> semantics to an existing function_arg_info.
> 
> The c6x part means that c6x_function_arg and c6x_function_arg_advance
> see the same "named" value as pass_by_reference did, rather than
> pass_by_reference seeing "true" and the others seeing "false".
> This doesn't matter because the c6x port doesn't care about namedness.
> 
> The rs6000.c patch removes an assignment to "type", but the only
> later code to use it was the patched promote_mode line.
> 
> (The reason for patching these places despite the above is that
> often target code gets used as a basis for new targets or changes
> to existing ones.)
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * calls.h (apply_pass_by_reference_rules): Declare.
>   * calls.c (apply_pass_by_reference_rules): New function.
>   * config/c6x/c6x.c (c6x_call_saved_register_used): Use it.
>   * config/rs6000/rs6000-call.c (rs6000_parm_needs_stack): Likewise.
>   * config/s390/s390.c (s390_call_saved_register_used): Likewise.
>   * function.c (assign_parm_find_data_types): Likewise.
>   * var-tracking.c (prepare_call_arguments): Likewise.
> 
OK
jeff


Re: [09/13] Use function_arg_info for TARGET_MUST_PASS_IN_STACK

2019-08-19 Thread Jeff Law
On 8/19/19 9:20 AM, Richard Sandiford wrote:
> Use function_arg_info for TARGET_MUST_PASS_IN_STACK.
> 
> The hook is passed the promoted mode instead of the original type mode.
> 
> The expr.h reference in the documentation is no longer correct, but
> pointing to calls.h or calls.c doesn't help much either.  I just left
> this as-is since it's not related to the point of the series.
> 
> After previous changes, most places already pass arg.mode and arg.type.
> Only i386 and mcore needed to construct a new one out of nothing.
> rs6000 needs to construct one slightly earlier than before.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (must_pass_in_stack): Take a function_arg_info instead
>   of a mode and a type.
>   * doc/tm.texi: Regenerate.
>   * calls.h (must_pass_in_stack_var_size): Take a function_arg_info
>   instead of a mode and a type.
>   (must_pass_in_stack_var_size_or_pad): Likewise.
>   * calls.c (must_pass_in_stack_var_size): Likewise.
>   (must_pass_in_stack_var_size_or_pad): Likewise.
>   (initialize_argument_information): Update call to
>   targetm.calls.must_pass_in_stack.
>   (must_pass_va_arg_on_stack): Likewise.
>   * function.c (assign_parm_find_entry_rtl): Likewise.
>   * targhooks.c (hook_pass_by_reference_must_pass_in_stack): Likewise.
>   * config/alpha/alpha.c (alpha_function_arg): Likewise.
>   (alpha_function_arg_advance): Likewise.
>   * config/cr16/cr16.c (cr16_function_arg): Likewise.
>   (cr16_function_arg_advance): Likewise.
>   * config/cris/cris.c (cris_pass_by_reference): Likewise.
>   (cris_arg_partial_bytes): Likewise.
>   * config/iq2000/iq2000.c (iq2000_pass_by_reference): Likewise.
>   * config/lm32/lm32.c (lm32_function_arg): Likewise.
>   * config/mcore/mcore.c (mcore_num_arg_regs): Likewise.
>   (mcore_function_arg, mcore_arg_partial_bytes): Likewise.
>   * config/mips/mips.c (mips_pass_by_reference): Likewise.
>   * config/mmix/mmix.c (mmix_function_arg_advance): Likewise.
>   (mmix_function_arg_1, mmix_pass_by_reference): Likewise.
>   * config/sh/sh.c (sh_pass_by_reference): Likewise.
>   * config/stormy16/stormy16.c (xstormy16_function_arg): Likewise.
>   * config/xtensa/xtensa.c (xtensa_function_arg_advance): Likewise.
>   * config/arm/arm.c (arm_must_pass_in_stack): Take a function_arg_info
>   instead of a mode and a type.
>   * config/fr30/fr30.c (fr30_must_pass_in_stack): Likewise.
>   (fr30_num_arg_regs): Likewise.
>   (fr30_setup_incoming_varargs): Update calls accordingly.
>   (fr30_arg_partial_bytes, fr30_function_arg): Likewise.
>   (fr30_function_arg_advance): Likewise.
>   * config/frv/frv.c (frv_must_pass_in_stack): Take a function_arg_info
>   instead of a mode and a type.
>   * config/gcn/gcn.c (num_arg_regs): Likewise.
>   (gcn_function_arg, gcn_function_arg_advance): Update calls to
>   num_arg_regs and targetm.calls.must_pass_in_stack.
>   (gcn_arg_partial_bytes): Likewise.
>   * config/i386/i386.c (ix86_must_pass_in_stack): Take a
>   function_arg_info instead of a mode and a type.
>   (classify_argument): Update call accordingly.
>   * config/nds32/nds32.c (nds32_must_pass_in_stack): Take a
>   function_arg_info instead of a mode and a type.
>   * config/rs6000/rs6000-internal.h (rs6000_must_pass_in_stack):
>   Likewise.
>   * config/rs6000/rs6000-call.c (rs6000_must_pass_in_stack): Likewise.
>   (rs6000_parm_needs_stack): Update call accordingly.
>   (setup_incoming_varargs): Likewise.
> 
OK
jeff


Merge from trunk to gccgo branch

2019-08-19 Thread Ian Lance Taylor
I've merged trunk revision 274678 to the gccgo branch.

Ian


Re: [08/13] Use function_arg_info for TARGET_CALLEE_COPIES

2019-08-19 Thread Jeff Law
On 8/19/19 9:19 AM, Richard Sandiford wrote:
> Use function_arg_info for TARGET_CALLEE_COPIES.
> 
> The hook is passed the unpromoted type mode instead of the promoted mode.
> 
> The aarch64 definition is redundant, but worth keeping for emphasis.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (callee_copies): Take a function_arg_info instead
>   of a mode, type and named flag.
>   * doc/tm.texi: Regenerate.
>   * targhooks.h (hook_callee_copies_named): Take a function_arg_info
>   instead of a mode, type and named flag.
>   (hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false): Delete.
>   (hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true): Likewise.
>   (hook_bool_CUMULATIVE_ARGS_arg_info_true): New function.
>   * targhooks.c (hook_callee_copies_named): Take a function_arg_info
>   instead of a mode, type and named flag.
>   (hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false): Delete.
>   (hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true): Likewise.
>   (hook_bool_CUMULATIVE_ARGS_arg_info_true): New function.
>   * calls.h (reference_callee_copied): Take a function_arg_info
>   instead of a mode, type and named flag.
>   * calls.c (reference_callee_copied): Likewise.
>   (initialize_argument_information): Update call accordingly.
>   (emit_library_call_value_1): Likewise.
>   * function.c (gimplify_parameters): Likewise.
>   * config/aarch64/aarch64.c (TARGET_CALLEE_COPIES): Define to
>   hook_bool_CUMULATIVE_ARGS_arg_info_false instead of
>   hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false.
>   * config/c6x/c6x.c (c6x_callee_copies): Delete.
>   (TARGET_CALLEE_COPIES): Define to
>   hook_bool_CUMULATIVE_ARGS_arg_info_true instead.
>   * config/epiphany/epiphany.c (TARGET_CALLEE_COPIES): Define to
>   hook_bool_CUMULATIVE_ARGS_arg_info_true instead of
>   hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true.
>   * config/mips/mips.c (mips_callee_copies): Take a function_arg_info
>   instead of a mode, type and named flag.
>   * config/mmix/mmix.c (TARGET_CALLEE_COPIES): Define to
>   hook_bool_CUMULATIVE_ARGS_arg_info_true instead of
>   hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true.
>   * config/mn10300/mn10300.c (TARGET_CALLEE_COPIES): Likewise.
>   * config/msp430/msp430.c (msp430_callee_copies): Delete.
>   (TARGET_CALLEE_COPIES): Define to
>   hook_bool_CUMULATIVE_ARGS_arg_info_true instead.
>   * config/pa/pa.c (pa_callee_copies): Take a function_arg_info
>   instead of a mode, type and named flag.
>   * config/sh/sh.c (sh_callee_copies): Likewise.
>   * config/v850/v850.c (TARGET_CALLEE_COPIES): Define to
>   hook_bool_CUMULATIVE_ARGS_arg_info_true instead of
>   hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true.
> 
OK
jeff


Re: [07/13] Use function_arg_info for TARGET_FUNCTION_ARG_ADVANCE

2019-08-19 Thread Jeff Law
On 8/19/19 9:18 AM, Richard Sandiford wrote:
> Use function_arg_info for TARGET_FUNCTION_ARG_ADVANCE.
> 
> There seems to be a bit of confusion around this one.  Almost all
> callers pass the same arguments as TARGET_FUNCTION_ARG, meaning
> that the mode is the promoted mode rather than the type mode.
> But the calls.c handling for normal typed arguments instead passes
> the unpromoted TYPE_MODE (despite passing the promoted mode to
> TARGET_FUNCTION_ARG).  I've kept this behaviour with a ??? comment.
> 
> (The calls.c handling of libgcc functions does pass the promoted
> mode though, as does the function.c handling of incoming arguments.)
> 
> Also, a couple of the arm callers don't seem to be using the hook
> correctly.  Again I kept the current choices and added a ??? comment.
Keeping current behavior seems reasonable as does marking the
inconsistent bits.


> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (function_arg_advance): Take a function_arg_info instead
>   of a mode, type and named flag.
>   * doc/tm.texi: Regenerate.
>   * targhooks.h (default_function_arg_advance): Take a function_arg_info
>   instead of a mode, type and named flag.
>   * targhooks.c (default_function_arg_advance): Likewise.
>   * calls.c (initialize_argument_information): Update call to
>   targetm.calls.function_arg_advance.
>   (emit_library_call_value_1): Likewise.
>   * dse.c (get_call_args): Likewise.
>   * expr.c (block_move_libcall_safe_for_call_parm): Likewise.
>   * function.c (assign_parms, gimplify_parameters): Likewise.
>   * var-tracking.c (prepare_call_arguments): Likewise.
>   * config/aarch64/aarch64.c (aarch64_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (aarch64_setup_incoming_varargs): Update call accordingly.
>   * config/alpha/alpha.c (alpha_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (alpha_setup_incoming_varargs): Update call accordingly.
>   * config/arc/arc.c (arc_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (arc_setup_incoming_varargs): Update call accordingly.
>   * config/arm/arm.c (arm_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (cmse_func_args_or_return_in_stack): Update call accordingly.
>   (arm_function_ok_for_sibcall): Likewise.
>   (cmse_nonsecure_call_clear_caller_saved): Likewise.
>   * config/avr/avr.c (avr_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/bfin/bfin.c (bfin_function_arg_advance): Likewise.
>   * config/c6x/c6x.c (c6x_function_arg_advance): Likewise.
>   (c6x_call_saved_register_used): Update call accordingly.
>   * config/cr16/cr16.c (cr16_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/cris/cris.c (cris_function_arg_advance): Likewise.
>   * config/csky/csky.c (csky_function_arg_advance): Likewise.
>   (csky_setup_incoming_varargs): Update call accordingly.
>   * config/epiphany/epiphany.c (epiphany_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/fr30/fr30.c (fr30_function_arg_advance): Likewise.
>   * config/frv/frv.c (frv_function_arg_advance): Likewise.
>   * config/ft32/ft32.c (ft32_function_arg_advance): Likewise.
>   * config/gcn/gcn.c (gcn_function_arg_advance): Likewise.
>   * config/h8300/h8300.c (h8300_function_arg_advance): Likewise.
>   * config/i386/i386.c (ix86_function_arg_advance): Likewise.
>   (ix86_setup_incoming_varargs): Update call accordingly.
>   * config/ia64/ia64.c (ia64_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (ia64_setup_incoming_varargs): Update call accordingly.
>   * config/iq2000/iq2000.c (iq2000_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (iq2000_expand_prologue): Update call accordingly.
>   * config/lm32/lm32.c (lm32_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/m32c/m32c.c (m32c_function_arg_advance): Likewise.
>   * config/m32r/m32r.c (m32r_function_arg_advance): Likewise.
>   * config/m68k/m68k.c (m68k_function_arg_advance): Likewise.
>   * config/mcore/mcore.c (mcore_function_arg_advance): Likewise.
>   * config/microblaze/microblaze.c (microblaze_function_arg_advance):
>   Likewise.
>   (microblaze_expand_prologue): Update call accordingly.
>   * config/mips/mips.c (mips_function_arg_advance): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (mips_setup_incoming_varargs): Update call accordingly.
>   

Re: [06/13] Use function_arg_info for TARGET_FUNCTION_(INCOMING_)ARG

2019-08-19 Thread Jeff Law
On 8/19/19 9:16 AM, Richard Sandiford wrote:
> This patch makes both TARGET_FUNCTION_ARG and
> TARGET_FUNCTION_INCOMING_ARG take a function_arg_info.
> They have to be done together since many targets use the
> same function for both.
> 
> The hooks are passed the promoted mode instead of the original type mode.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (function_arg, function_incoming_arg): Take a
>   function_arg_info instead of a mode, tree and named flag.
>   * doc/tm.texi: Regenerate.
>   * targhooks.h (default_function_arg): Take a function_arg_info
>   instead of a mode, tree and named flag.
>   (default_function_incoming_arg): Likewise.
>   * targhooks.c (default_function_arg): Likewise.
>   (default_function_incoming_arg): Likewise.
>   * calls.h (function_arg_info::end_marker_p): New function.
>   (function_arg_info::end_marker): Likewise.
>   * calls.c (prepare_call_address, initialize_argument_information)
>   (expand_call, emit_library_call_value_1): Update calls to
>   targetm.calls.function_arg and targetm.calls.function_incoming_arg.
>   * dse.c: Include calls.h.
>   (get_call_args): Update call to targetm.calls.function_arg.
>   * expr.c (block_move_libcall_safe_for_call_parm): Likewise.
>   * var-tracking.c (prepare_call_arguments): Likewise.
>   * function.c (assign_parm_find_entry_rtl): Update call to
>   targetm.calls.function_incoming_arg.
>   * config/aarch64/aarch64.c (aarch64_function_arg): Take a
>   function_arg_info instead of a mode, tree and named flag.
>   * config/alpha/alpha.c (alpha_function_arg): Likewise.
>   * config/arc/arc.c (arc_function_arg): Likewise.
>   * config/arm/arm.c (arm_function_arg): Likewise.
>   (cmse_func_args_or_return_in_stack): Update call accordingly.
>   (arm_function_ok_for_sibcall): Likewise.
>   (cmse_nonsecure_call_clear_caller_saved): Likewise.
>   * config/avr/avr.c (avr_function_arg): Take a function_arg_info
>   instead of a mode, tree and named flag.
>   * config/bfin/bfin.c (bfin_function_arg): Likewise.
>   * config/c6x/c6x.c (c6x_function_arg): Likewise.
>   (c6x_call_saved_register_used): Update call accordingly.
>   * config/cr16/cr16.c (cr16_function_arg): Take a function_arg_info
>   instead of a mode, tree and named flag.
>   * config/cris/cris.c (cris_function_arg, cris_function_incoming_arg)
>   (cris_function_arg_1): Likewise.
>   * config/csky/csky.c (csky_function_arg): Likewise.
>   * config/epiphany/epiphany.c (epiphany_function_arg): Likewise.
>   * config/fr30/fr30.c (fr30_function_arg): Likewise.
>   * config/frv/frv.c (frv_function_arg, frv_function_incoming_arg)
>   (frv_function_arg_1): Likewise.
>   * config/ft32/ft32.c (ft32_function_arg): Likewise.
>   * config/gcn/gcn.c (gcn_function_arg): Likewise.
>   * config/h8300/h8300.c (h8300_function_arg): Likewise.
>   * config/i386/i386.c (ix86_function_arg): Likewise.
>   * config/ia64/ia64.c (ia64_function_arg, ia64_function_incoming_arg)
>   (ia64_function_arg_1): Likewise.
>   * config/iq2000/iq2000.c (iq2000_function_arg): Likewise.
>   (iq2000_expand_prologue, iq2000_pass_by_reference): Update call
>   accordingly.
>   * config/lm32/lm32.c (lm32_function_arg): Take a function_arg_info
>   instead of a mode, tree and named flag.
>   * config/m32c/m32c.c (m32c_function_arg): Likewise.
>   * config/m32r/m32r.c (m32r_function_arg): Likewise.
>   * config/m68k/m68k.c (m68k_function_arg): Likewise.
>   * config/mcore/mcore.c (mcore_function_arg): Likewise.
>   * config/microblaze/microblaze.c (microblaze_function_arg): Likewise.
>   (microblaze_expand_prologue): Update call accordingly.
>   * config/mips/mips.c (mips_function_arg): Take a function_arg_info
>   instead of a mode, tree and named flag.
>   * config/mmix/mmix.c (mmix_function_incoming_arg, mmix_function_arg)
>   (mmix_function_arg_1): Likewise.
>   * config/mn10300/mn10300.c (mn10300_function_arg): Likewise.
>   * config/moxie/moxie.c (moxie_function_arg): Likewise.
>   * config/msp430/msp430.c (msp430_function_arg): Likewise.
>   * config/nds32/nds32.c (nds32_function_arg): Likewise.
>   * config/nios2/nios2.c (nios2_function_arg): Likewise.
>   * config/nvptx/nvptx.c (nvptx_function_arg): Likewise.
>   (nvptx_function_incoming_arg): Likewise.
>   * config/or1k/or1k.c (or1k_function_arg): Likewise.
>   * config/pa/pa.c (pa_function_arg): Likewise.
>   * config/pdp11/pdp11.c (pdp11_function_arg): Likewise.
>   * config/pru/pru.c (pru_function_arg): Likewise.
>   * config/riscv/riscv.c (riscv_function_arg): Likewise.
>   * config/rl78/rl78.c (rl78_function_arg): Likewise.
>   * config/rs6000/rs6000-internal.h (rs6000_function_arg): Likewise.
>   * config/rs6000/rs6000-call.c 

Re: [05/13] Use function_arg_info for TARGET_SETUP_INCOMING_ARGS

2019-08-19 Thread Jeff Law
On 8/19/19 9:16 AM, Richard Sandiford wrote:
> Use function_arg_info for TARGET_SETUP_INCOMING_ARGS.
> 
> The hook is passed the promoted mode instead of the original type mode.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (setup_incoming_varargs): Take a function_arg_info
>   instead of a mode and tree.
>   * doc/tm.texi: Regenerate.
>   * targhooks.h (default_setup_incoming_varargs): Take a
>   function_arg_info instead of a mode and tree.
>   * targhooks.c (default_setup_incoming_varargs): Likewise.
>   * config/aarch64/aarch64.c (aarch64_setup_incoming_varargs): Likewise.
>   * config/alpha/alpha.c (alpha_setup_incoming_varargs): Likewise.
>   * config/arc/arc.c (arc_setup_incoming_varargs): Likewise.
>   * config/arm/arm.c (arm_setup_incoming_varargs): Likewise.
>   * config/bfin/bfin.c (setup_incoming_varargs): Likewise.
>   * config/cris/cris.c (cris_setup_incoming_varargs): Likewise.
>   * config/csky/csky.c (csky_setup_incoming_varargs): Likewise.
>   * config/epiphany/epiphany.c (epiphany_setup_incoming_varargs):
>   Likewise.
>   * config/fr30/fr30.c (fr30_setup_incoming_varargs): Likewise.
>   * config/frv/frv.c (frv_setup_incoming_varargs): Likewise.
>   * config/ft32/ft32.c (ft32_setup_incoming_varargs): Likewise.
>   * config/i386/i386.c (ix86_setup_incoming_varargs): Likewise.
>   * config/ia64/ia64.c (ia64_setup_incoming_varargs): Likewise.
>   * config/iq2000/iq2000.c (iq2000_setup_incoming_varargs): Likewise.
>   * config/lm32/lm32.c (lm32_setup_incoming_varargs): Likewise.
>   * config/m32r/m32r.c (m32r_setup_incoming_varargs): Likewise.
>   * config/mcore/mcore.c (mcore_setup_incoming_varargs): Likewise.
>   * config/mips/mips.c (mips_setup_incoming_varargs): Likewise.
>   * config/mmix/mmix.c (mmix_setup_incoming_varargs): Likewise.
>   * config/moxie/moxie.c (moxie_setup_incoming_varargs): Likewise.
>   * config/nds32/nds32.c (nds32_setup_incoming_varargs): Likewise.
>   * config/nios2/nios2.c (nios2_setup_incoming_varargs): Likewise.
>   * config/riscv/riscv.c (riscv_setup_incoming_varargs): Likewise.
>   * config/rs6000/rs6000-internal.h (setup_incoming_varargs): Likewise.
>   * config/rs6000/rs6000-call.c (setup_incoming_varargs): Likewise.
>   * config/sh/sh.c (sh_setup_incoming_varargs): Likewise.
>   * config/spu/spu.c (spu_setup_incoming_varargs): Likewise.
>   * config/tilegx/tilegx.c (tilegx_setup_incoming_varargs): Likewise.
>   * config/tilepro/tilepro.c (tilepro_setup_incoming_varargs): Likewise.
>   * config/visium/visium.c (visium_setup_incoming_varargs): Likewise.
>   * function.c (assign_parms_setup_varargs): Update call to
>   targetm.calls.setup_incoming_varargs.
OK
jeff


Re: [04/13] Use function_arg_info for TARGET_PASS_BY_REFERENCE

2019-08-19 Thread Jeff Law
On 8/19/19 9:15 AM, Richard Sandiford wrote:
> Use function_arg_info for TARGET_PASS_BY_REFERENCE.
> 
> The hook is passed the unpromoted type mode instead of the promoted mode.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (pass_by_reference): Take a function_arg_info instead
>   of a mode, type and named flag.
>   * doc/tm.texi: Regenerate.
>   * targhooks.h (hook_pass_by_reference_must_pass_in_stack): Update
>   accordingly.
>   (hook_bool_CUMULATIVE_ARGS_arg_info_false): Declare.
>   * targhooks.c (hook_pass_by_reference_must_pass_in_stack): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (hook_bool_CUMULATIVE_ARGS_arg_info_false): New function.
>   * calls.h (pass_by_reference): Take a function_arg_info instead of a
>   mode, type and named flag.
>   * calls.c (pass_by_reference): Likewise.
>   (pass_va_arg_by_reference): Update call accordingly.
>   (initialize_argument_information): Likewise.
>   (emit_library_call_value_1): Likewise.
>   * function.c (assign_parm_find_data_types): Likewise.
>   * var-tracking.c (prepare_call_arguments): Likewise.
>   * stor-layout.c: Include calls.h.
>   (compute_record_mode): Update call to targetm.calls.pass_by_reference.
>   * config/aarch64/aarch64.c (aarch64_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/alpha/alpha.c (alpha_pass_by_reference): Likewise.
>   * config/arc/arc.c (arc_pass_by_reference): Likewise.
>   * config/arm/arm.c (arm_pass_by_reference): Likewise.
>   * config/bfin/bfin.c (bfin_pass_by_reference): Likewise.
>   * config/c6x/c6x.c (c6x_pass_by_reference): Likewise.
>   (c6x_call_saved_register_used): Update call to pass_by_reference.
>   * config/cris/cris.c (cris_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/epiphany/epiphany.c (epiphany_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (epiphany_arg_partial_bytes): Update call accordingly.
>   * config/ft32/ft32.c (ft32_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (ft32_arg_partial_bytes): Update call accordingly.
>   * config/i386/i386.c (ix86_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/iq2000/iq2000.c (iq2000_pass_by_reference): Likewise.
>   * config/m32c/m32c.c (m32c_pass_by_reference): Likewise.
>   * config/m32r/m32r.c (m32r_pass_by_reference): Likewise.
>   (m32r_return_in_memory): Update call accordingly.
>   * config/mips/mips.c (mips_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/mmix/mmix.c (mmix_pass_by_reference): Likewise.
>   * config/mn10300/mn10300.c (mn10300_pass_by_reference): Likewise.
>   * config/moxie/moxie.c (moxie_pass_by_reference): Likewise.
>   (moxie_arg_partial_bytes): Update call accordingly.
>   * config/msp430/msp430.c (msp430_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/nvptx/nvptx.c (nvptx_pass_by_reference): Likewise.
>   * config/or1k/or1k.c (or1k_pass_by_reference): Likewise.
>   * config/pa/pa.c (pa_pass_by_reference): Likewise.
>   * config/riscv/riscv.c (riscv_pass_by_reference): Likewise.
>   (riscv_return_in_memory): Update call accordingly.
>   * config/rs6000/rs6000-internal.h (rs6000_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/rs6000/rs6000-call.c (rs6000_pass_by_reference): Likewise.
>   (rs6000_parm_needs_stack): Update call to pass_by_reference.
>   * config/s390/s390.c (s390_pass_by_reference): Take a
>   function_arg_info instead of a mode, type and named flag.
>   (s390_call_saved_register_used): Update call accordingly.
>   * config/sh/sh.c (sh_pass_by_reference): Take a function_arg_info
>   instead of a mode, type and named flag.
>   * config/sparc/sparc.c (sparc_pass_by_reference): Likewise.
>   * config/spu/spu.c (spu_pass_by_reference): Likewise.
>   * config/tilegx/tilegx.c (tilegx_pass_by_reference): Likewise.
>   * config/tilepro/tilepro.c (tilepro_pass_by_reference): Likewise.
>   * config/v850/v850.c (v850_pass_by_reference): Likewise.
>   * config/visium/visium.c (visium_pass_by_reference): Likewise.
> 
> gcc/ada/
>   * gcc-interface/misc.c (default_pass_by_ref): Update call to
>   pass_by_reference.
OK
jeff


Re: [03/13] Use function_arg_info for TARGET_ARG_PARTIAL_BYTES

2019-08-19 Thread Jeff Law
On 8/19/19 9:14 AM, Richard Sandiford wrote:
> This patch adds the function_arg_info class and uses it for
> TARGET_ARG_PARTIAL_BYTES.
> 
> The hook is passed the promoted mode instead of the original type mode.
> 
> The arguments aren't mentioned in the documentation, which is why the
> target.def change is so small.
> 
> The patch changes "true" to "arg.named" in:
> 
>   gcc_assert (!epiphany_pass_by_reference (cum, mode, type, /* named */ 
> true));
> 
> but epiphany_pass_by_reference doesn't care about the named flag.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * target.def (arg_partial_bytes): Take a function_arg_info instead
>   of a mode, type and named flag.
>   * doc/tm.texi: Regenerate.
>   * target.h (function_arg_info): Declare.
>   * calls.h (function_arg_info): New class.
>   * targhooks.h (hook_int_CUMULATIVE_ARGS_mode_tree_bool_0): Delete.
>   (hook_int_CUMULATIVE_ARGS_arg_info_0): Declare.
>   * targhooks.c (hook_int_CUMULATIVE_ARGS_mode_tree_bool_0): Delete.
>   (hook_int_CUMULATIVE_ARGS_arg_info_0): New function.
>   * calls.c (initialize_argument_information): Update call to
>   targetm.calls.partial_bytes.
>   (emit_library_call_value_1): Likewise.
>   * expr.c (block_move_libcall_safe_for_call_parm): Likewise.
>   * function.c (assign_parm_find_entry_rtl): Likewise.
>   * config/alpha/alpha.c (alpha_arg_partial_bytes): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/arc/arc.c (arc_arg_partial_bytes): Likewise.
>   * config/arm/arm.c (arm_arg_partial_bytes): Likewise.
>   (cmse_func_args_or_return_in_stack): Update accordingly.
>   * config/bfin/bfin.c (bfin_arg_partial_bytes): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/cris/cris.c (cris_arg_partial_bytes): Likewise.
>   * config/csky/csky.c (csky_arg_partial_bytes): Likewise.
>   * config/epiphany/epiphany.c (epiphany_arg_partial_bytes): Likewise.
>   * config/fr30/fr30.c: Include calls.h.
>   (fr30_arg_partial_bytes): Take a function_arg_info instead of a mode,
>   type and named flag.
>   * config/frv/frv.c: Include calls.h.
>   (frv_arg_partial_bytes): Take a function_arg_info instead of a mode,
>   type and named flag.
>   * config/ft32/ft32.c (ft32_arg_partial_bytes): Likewise.
>   * config/gcn/gcn.c (gcn_arg_partial_bytes): Likewise.
>   * config/ia64/ia64.c (ia64_arg_partial_bytes): Likewise.
>   * config/iq2000/iq2000.c (iq2000_arg_partial_bytes): Likewise.
>   * config/m32r/m32r.c (m32r_arg_partial_bytes): Likewise.
>   * config/mcore/mcore.c (mcore_arg_partial_bytes): Likewise.
>   * config/microblaze/microblaze.c (function_arg_partial_bytes):
>   Likewise.
>   * config/mips/mips.c (mips_arg_partial_bytes): Likewise.
>   * config/mn10300/mn10300.c (mn10300_arg_partial_bytes): Likewise.
>   * config/moxie/moxie.c (moxie_arg_partial_bytes): Likewise.
>   * config/msp430/msp430.c (msp430_arg_partial_bytes): Likewise.
>   * config/nds32/nds32.c (nds32_arg_partial_bytes): Likewise.
>   * config/nios2/nios2.c (nios2_arg_partial_bytes): Likewise.
>   * config/pa/pa.c (pa_arg_partial_bytes): Likewise.
>   * config/pru/pru.c (pru_arg_partial_bytes): Likewise.
>   * config/riscv/riscv.c (riscv_arg_partial_bytes): Likewise.
>   * config/rs6000/rs6000-internal.h (rs6000_arg_partial_bytes): Likewise.
>   * config/rs6000/rs6000-call.c (rs6000_arg_partial_bytes): Likewise.
>   (rs6000_parm_needs_stack): Update call accordingly.
>   * config/sh/sh.c (sh_arg_partial_bytes): Take a
>   function_arg_info instead of a mode, type and named flag.
>   * config/sparc/sparc.c (sparc_arg_partial_bytes): Likewise.
>   * config/v850/v850.c (v850_arg_partial_bytes): Likewise.
OK
jeff


Re: [PATCH V2 6/8] bpf: adjust GCC testsuite to eBPF limitations

2019-08-19 Thread jose . marchesi


> It also seems like rather than checking for ebpf on files with large
> stacks, we should be using the generic mechanisms to defined the 
allowed
> size of the stack (mentioned in prior review) & mark test which use 
too
> much space.  This would almost certainly help other embedded targets 
as
> well.
> 
> I first thought about doing that, but hesitated when I realized it would
> require to alter existing tests in no trivial ways: will the test still
> effectively test whatever it is supposed to test, after the size of an
> array is changed, for example?
I think you just add something like

/* dg-require-stack-size "" */

Assuming that's right you don't have to worry about changing the test
itself and potentially changing its meaning.

I wouldn't necessarily try to figure the exact size needed by each test.
 A reasonable guesstimation ought to be sufficient.

Oh nice, I didn't know about that directive.
Thanks!


Re: [PATCH V2 2/8] bpf: new GCC port

2019-08-19 Thread Richard Sandiford
In addition to Segher's comments:

jema...@gnu.org (Jose E. Marchesi) writes:
> [...]
> +/* This file contains the definition of the kernel helpers that are
> +   available to eBPF programs.
> +
> +   The primary source for information on kernel helpers is the
> +   linux/include/uapi/linux/bpf.h file in the Linux source tree.
> +   Please keep this database in sync.
> +
> +   The first column is the first kernel version featuring the helper
> +   function.  This should be an enumerate from bpf_kernel_version,
> +   defined in bpf-opts.h.  Note that the backend assumes that helpers
> +   never get deprecated in the kernel.  If that eventually happens,
> +   then we will need to use a bitmask here instead of an enumerate.
> +
> +   The second column is the constant-name for the helper.
> +   The third column is the program-name of the helper.
> +
> +   The fourth column is a list of names describing the types of the
> +   values returned and accepted by the helper, in one of these forms:
> +
> + TYPES (type1, type2, ..., 0)
> + VTYPES (type1, type2, ..., 0)
> +
> +   VTYPES should be used should the helper accept a variable number of
> +   arguments, TYPES otherwise.  The valid type names are:
> +
> + `vt' for void.
> + `it' for signed int.
> + `ut' for unsigned int.
> + `pt' for *void.
> + `cpt' for const *void.

"*" after "void" in both cases.

> + `st' for short int.
> + `ust' for unsigned short int.
> + `cst' for const char *.

Very minor, but it might be less confusing to pick something other than "s"
for "cst" given the above.

> [...]
> +/* Functions to emit BPF_LD_ABS and BPF_LD_IND instructions.  We
> +   provide the "standard" names as synonyms of the corresponding GCC
> +   builtins.  Note how the SKB argument is ignored.  */
> +
> +static inline long long
> +load_byte (void *skb, unsigned long long off)
> +{
> +  return __builtin_bpf_load_byte (off);
> +}
> [etc]

It might be worth adding __attribute__((unused)) to them, in case
anyone compiles with -Wsystem-headers.

> [...]
> +/* Supported versions of the Linux kernel.  */
> +enum bpf_kernel_version
> +{
> + /* Linux 4.x */
> + LINUX_V4_0,
> [etc.]

The contents should be indented by two spaces.

> [...]
> +enum bpf_builtins
> +{
> + BPF_BUILTIN_UNUSED = 0,
> + /* Built-ins for kernel helpers.  */
> +#define DEF_HELPER(V,D,N,T) BPF_BUILTIN_HELPER_##D,
> +#  include "bpf-helpers.def"
> +#undef DEF_HELPER
> + BPF_BUILTIN_HELPER_MAX,
> + /* Built-ins for non-generic loads and stores.  */
> + BPF_BUILTIN_LOAD_BYTE = BPF_BUILTIN_HELPER_MAX,
> + BPF_BUILTIN_LOAD_HALF,
> + BPF_BUILTIN_LOAD_WORD,
> + BPF_BUILTIN_MAX,
> +};
> +
> +/* This table is indexed by an enum bpf_builtin.  */
> +static const char *bpf_helper_names[] =
> +{
> + NULL,
> +#define DEF_HELPER(V,D,N,T) #N,
> +#  include "bpf-helpers.def"
> +#undef DEF_HELPER
> + NULL,
> + NULL,
> + NULL,
> + NULL
> +};

Same for these two.

> [...]
> +#define INCLUDE_STRING

You didn't seem to rely on this (i.e. std::string).

> [...]
> +/* Override options and do some other initialization.  */
> +
> +static void
> +bpf_option_override (void)
> +{
> +  /* Set the default target kernel if no -mkernel was specified.  */
> +  if (!global_options_set.x_bpf_kernel)
> +bpf_kernel = LINUX_LATEST;

LINUX_LATEST is the default in the .opt file, so when is this needed?

> [...]
> +  /* Define BPF_KERNEL_VERSION_CODE */
> +  {
> +const char *version_code;
> +char *kernel_version_code;
> +
> +switch (bpf_kernel)
> +  {
> +  case LINUX_V4_0: version_code = "0x4"; break;
> +  case LINUX_V4_1: version_code = "0x40100"; break;
> +  case LINUX_V4_2: version_code = "0x40200"; break;
> +  case LINUX_V4_3: version_code = "0x40300"; break;
> +  case LINUX_V4_4: version_code = "0x40400"; break;
> +  case LINUX_V4_5: version_code = "0x40500"; break;
> +  case LINUX_V4_6: version_code = "0x40600"; break;
> +  case LINUX_V4_7: version_code = "0x40700"; break;
> +  case LINUX_V4_8: version_code = "0x40800"; break;
> +  case LINUX_V4_9: version_code = "0x40900"; break;
> +  case LINUX_V4_10: version_code = "0x40a00"; break;
> +  case LINUX_V4_11: version_code = "0x40b00"; break;
> +  case LINUX_V4_12: version_code = "0x40c00"; break;
> +  case LINUX_V4_13: version_code = "0x40d00"; break;
> +  case LINUX_V4_14: version_code = "0x40e00"; break;
> +  case LINUX_V4_15: version_code = "0x40f00"; break;
> +  case LINUX_V4_16: version_code = "0x41000"; break;
> +  case LINUX_V4_17: version_code = "0x42000"; break;
> +  case LINUX_V4_18: version_code = "0x43000"; break;
> +  case LINUX_V4_19: version_code = "0x44000"; break;
> +  case LINUX_V4_20: version_code = "0x45000"; break;
> +  case LINUX_V5_0: version_code = "0x5"; break;
> +  case LINUX_V5_1: version_code = "0x50100"; break;
> +  case LINUX_V5_2: version_code = "0x50200"; break;
> +  default:
> + 

Re: [PATCH] Improve DSE to handle redundant zero initializations.

2019-08-19 Thread Matthew Beliveau
Hello,

This should have the changes you wanted!

Thank you,
Matthew Beliveau

On Fri, Aug 16, 2019 at 12:30 PM Jeff Law  wrote:
>
> On 8/13/19 9:09 AM, Matthew Beliveau wrote:
> > Hello,
> >
> > This should have the changes you all asked for! Let me know if I
> > missed anything!
> >
> > Thank you,
> > Matthew Beliveau
> >
> > On Tue, Aug 13, 2019 at 5:15 AM Richard Biener
> >  wrote:
> >> On Tue, Aug 13, 2019 at 10:18 AM Richard Sandiford
> >>  wrote:
> >>> Thanks for doing this.
> >>>
> >>> Matthew Beliveau  writes:
>  diff --git gcc/tree-ssa-dse.c gcc/tree-ssa-dse.c
>  index 5b7c4fc6d1a..dcaeb8edbfe 100644
>  --- gcc/tree-ssa-dse.c
>  +++ gcc/tree-ssa-dse.c
>  @@ -628,11 +628,8 @@ dse_optimize_redundant_stores (gimple *stmt)
> tree fndecl;
> if ((is_gimple_assign (use_stmt)
>   && gimple_vdef (use_stmt)
>  -&& ((gimple_assign_rhs_code (use_stmt) == CONSTRUCTOR
>  - && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (use_stmt)) == 0
>  - && !gimple_clobber_p (stmt))
>  -|| (gimple_assign_rhs_code (use_stmt) == INTEGER_CST
>  -&& integer_zerop (gimple_assign_rhs1 (use_stmt)
>  +&& initializer_zerop (gimple_op (use_stmt, 1), NULL)
>  +&& !gimple_clobber_p (stmt))
>  || (gimple_call_builtin_p (use_stmt, BUILT_IN_NORMAL)
>  && (fndecl = gimple_call_fndecl (use_stmt)) != NULL
>  && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMSET
>  @@ -1027,15 +1024,13 @@ dse_dom_walker::dse_optimize_stmt 
>  (gimple_stmt_iterator *gsi)
>   {
> bool by_clobber_p = false;
> 
>  -  /* First see if this store is a CONSTRUCTOR and if there
>  -  are subsequent CONSTRUCTOR stores which are totally
>  -  subsumed by this statement.  If so remove the subsequent
>  -  CONSTRUCTOR store.
>  +  /* Check if this store initalizes zero, or some aggregate of 
>  zeros,
>  +  and check if there are subsequent stores which are subsumed by 
>  this
>  +  statement.  If so, remove the subsequent store.
> 
> This will tend to make fewer calls into memset with longer
> arguments.  */
>  -  if (gimple_assign_rhs_code (stmt) == CONSTRUCTOR
>  -   && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt)) == 0
>  +  if (initializer_zerop (gimple_op (stmt, 1), NULL)
>  && !gimple_clobber_p (stmt))
>    dse_optimize_redundant_stores (stmt);
> 
> >>> In addition to Jeff's comment, the original choice of gimple_assign_rhs1
> >>> is the preferred way to write this (applies to both hunks).
> >> And the !gimple_clobber_p test is now redundant.
> >>
> >>> Richard
> >
> > DSE-2.patch
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > 2019-08-13  Matthew Beliveau  
> >
> >   * tree-ssa-dse.c (dse_optimize_redundant_stores): Improved check to
> >   catch more redundant zero initialization cases.
> >   (dse_dom_walker::dse_optimize_stmt): Likewise.
> >
> >   * gcc.dg/tree-ssa/redundant-assign-zero-1.c: New test.
> >   * gcc.dg/tree-ssa/redundant-assign-zero-2.c: New test.
> >
> > diff --git gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-1.c 
> > gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-1.c
> > new file mode 100644
> > index 000..b8d01d1644b
> > --- /dev/null
> > +++ gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-1.c
> > @@ -0,0 +1,13 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -fdump-tree-dse-details" } */
> > +
> > +void blah (char *);
> > +
> > +void bar ()
> > +{
> > +  char a[256] = "";
> > +  a[3] = 0;
> > +  blah (a);
> > +}
> > +
> > +/* { dg-final { scan-tree-dump-times "Deleted redundant store" 1 "dse1"} } 
> > */
> > diff --git gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-2.c 
> > gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-2.c
> > new file mode 100644
> > index 000..8cefa6f0cb7
> > --- /dev/null
> > +++ gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-2.c
> > @@ -0,0 +1,18 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -fdump-tree-dse-details" } */
> > +
> > +#include 
> > +
> > +void blahd (double *);
> > +
> > +void fubar ()
> > +{
> > +  double d;
> > +  double *x = 
> > +
> > +  memset (, 0 , sizeof d);
> > +  *x = 0.0;
> > +  blahd (x);
> > +}
> > +
> > +/* { dg-final { scan-tree-dump-times "Deleted redundant store" 1 "dse1"} } 
> > */
> > diff --git gcc/tree-ssa-dse.c gcc/tree-ssa-dse.c
> > index 5b7c4fc6d1a..14b66228e1e 100644
> > --- gcc/tree-ssa-dse.c
> > +++ gcc/tree-ssa-dse.c
> > @@ -628,11 +628,7 @@ dse_optimize_redundant_stores (gimple *stmt)
> >tree fndecl;
> >if ((is_gimple_assign (use_stmt)
> >  && gimple_vdef (use_stmt)
> > -&& ((gimple_assign_rhs_code (use_stmt) == CONSTRUCTOR
> > - && CONSTRUCTOR_NELTS 

Re: [02/13] Add must_pass_va_arg_in_stack

2019-08-19 Thread Jeff Law
On 8/19/19 9:12 AM, Richard Sandiford wrote:
> This patch splits out another idiom from the va_arg gimplification
> routines, so that there's only one place to update later.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * calls.h (must_pass_va_arg_in_stack): Declare.
>   * calls.c (must_pass_va_arg_in_stack): New function.
>   * config/alpha/alpha.c (alpha_gimplify_va_arg_1): Use it.
>   * config/sh/sh.c (sh_gimplify_va_arg_expr): Likewise.
>   * config/stormy16/stormy16.c (xstormy16_gimplify_va_arg_expr):
>   Likewise.
>   * config/xtensa/xtensa.c (xtensa_gimplify_va_arg_expr): Likewise.
OK.  Hopefully they're all this easy to review :-)

jeff


Re: [01/13] Add pass_va_arg_by_reference

2019-08-19 Thread Jeff Law
On 8/19/19 9:11 AM, Richard Sandiford wrote:
> This patch splits out a common idiom from the va_arg gimplification
> routines, so that there's only one place to update later.
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * calls.h (pass_va_arg_by_reference): Declare.
>   * calls.c (pass_va_arg_by_reference): New function.
>   * config/aarch64/aarch64.c (aarch64_gimplify_va_arg_expr): Use it.
>   * config/alpha/alpha.c (alpha_gimplify_va_arg): Likewise.
>   * config/gcn/gcn.c (gcn_gimplify_va_arg_expr): Likewise.
>   * config/i386/i386.c (ix86_gimplify_va_arg): Likewise.
>   * config/ia64/ia64.c (ia64_gimplify_va_arg): Likewise.
>   * config/mips/mips.c (mips_std_gimplify_va_arg_expr): Likewise.
>   (mips_gimplify_va_arg_expr): Likewise.
>   * config/msp430/msp430.c (msp430_gimplify_va_arg_expr): Likewise.
>   * config/pa/pa.c (hppa_gimplify_va_arg_expr): Likewise.
>   * config/rs6000/rs6000-call.c (rs6000_gimplify_va_arg): Likewise.
>   * config/s390/s390.c (s390_gimplify_va_arg): Likewise.
>   * config/sparc/sparc.c (sparc_gimplify_va_arg): Likewise.
>   * config/spu/spu.c (spu_gimplify_va_arg_expr): Likewise.
>   * config/tilegx/tilegx.c (tilegx_gimplify_va_arg_expr): Likewise.
>   * config/tilepro/tilepro.c (tilepro_gimplify_va_arg_expr): Likewise.
>   * config/visium/visium.c (visium_gimplify_va_arg): Likewise.
>   * config/xtensa/xtensa.c (xtensa_gimplify_va_arg_expr): Likewise.
>   * targhooks.c (std_gimplify_va_arg_expr): Likewise.
OK
jeff


Re: [PATCH V2 6/8] bpf: adjust GCC testsuite to eBPF limitations

2019-08-19 Thread Jeff Law
On 8/19/19 8:23 AM, Jose E. Marchesi wrote:
> 
> [...]
> > * gcc.dg/Wframe-larger-than-2.c: Likewise.
> > * gcc.dg/Wframe-larger-than.c: Likewise.
> > * gcc.dg/Wrestrict-11.c: Likewise.
> So I think we probably want an effective target check for indirect calls
> rather than checking explicitly for ebpf in all these files.
> 
> Ok, will introduce it.
> 
> It also seems like rather than checking for ebpf on files with large
> stacks, we should be using the generic mechanisms to defined the allowed
> size of the stack (mentioned in prior review) & mark test which use too
> much space.  This would almost certainly help other embedded targets as
> well.
> 
> I first thought about doing that, but hesitated when I realized it would
> require to alter existing tests in no trivial ways: will the test still
> effectively test whatever it is supposed to test, after the size of an
> array is changed, for example?
I think you just add something like

/* dg-require-stack-size "" */

Assuming that's right you don't have to worry about changing the test
itself and potentially changing its meaning.

I wouldn't necessarily try to figure the exact size needed by each test.
 A reasonable guesstimation ought to be sufficient.


> 
> Not sure the best way to deal with too many arguments.  I suspect we
> want an efffective target check for that.  Keeping this up-to-date will
> be painful as people write more tests.
> 
> Yeah, that won't be fun :(
> 
>   /* Copyright (C) 2000, 2003 Free Software Foundation */
> >  __complex__ long long f ()
> > diff --git a/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> > b/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> > index be0bdcf7631..9f6bd0af2e5 100644
> > --- a/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> > +++ b/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> > @@ -3,6 +3,7 @@
> >  /* { dg-skip-if "too much code for pdp11" { "pdp11-*-*" } } */
> >  /* { dg-xfail-if "PR36698" { spu-*-* } { "-O0" } { "" } } */
> >  /* { dg-skip-if "" { m32c-*-* } } */
> > +/* { dg-skip-if "jumps too far for eBPF" { bpf-*-* } } */
> >  /* { dg-timeout-factor 4.0 } */
> Jumps too far is probably an indication you need to fix something in
> your port.  Though I guess its OK if you're never going to support far
> away targets.
> 
> The reasons for this are that eBPF doesn't have indirect jump
> instructions, and the direct jump instruction's displacement is a signed
> PC-relative 16-bit offset, in 64-bit word units.
> 
> So, unless the compiler gets able to generate a "chain" of direct jumps
> to reach the destination (that would be a fun hack :D) the range for
> branches is severely limited.
OK.  Perhaps another effective target check.   Or leave this one with
the epf check.

jeff


Re: [PATCH 1/2] gcc/riscv: Include more registers in SIBCALL_REGS

2019-08-19 Thread Andrew Waterman
x5 is used as an alternate link register, so using it for sibcalls
will confuse hardware return-address stacks and reduce performance for
implementations that have one.

The reason I excluded a0-a7 is that those are used to pass arguments
to the sibcallee.  It's of course possible that's more restrictive
than necessary, but make sure to test before merging.


On Mon, Aug 19, 2019 at 12:16 PM Andrew Burgess
 wrote:
>
> The current SIBCALL_REGS are x6, x7, and x28 to x31.  These are all
> caller saved registers, however, they are not all of the caller saved
> registers.
>
> I don't see any reason why we couldn't add t1, and a0 to a7 into this
> set, and this is what this patch does.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv.h (REG_CLASS_CONTENTS): Update SIBCALL_REGS.
> ---
>  gcc/ChangeLog| 4 
>  gcc/config/riscv/riscv.h | 2 +-
>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
> index 5fc9be8edbf2..bb8240bb849a 100644
> --- a/gcc/config/riscv/riscv.h
> +++ b/gcc/config/riscv/riscv.h
> @@ -400,7 +400,7 @@ enum reg_class
>  #define REG_CLASS_CONTENTS \
>  {  \
>{ 0x, 0x, 0x },  /* NO_REGS */   \
> -  { 0xf0c0, 0x, 0x },  /* SIBCALL_REGS */  \
> +  { 0xf003fce0, 0x, 0x },  /* SIBCALL_REGS */  \
>{ 0xffc0, 0x, 0x },  /* JALR_REGS */ \
>{ 0x, 0x, 0x },  /* GR_REGS */   \
>{ 0x, 0x, 0x },  /* FP_REGS */   \
> --
> 2.14.5
>


New Chinese (simplified) PO file for 'gcc' (version 9.1.0)

2019-08-19 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'gcc' has been submitted
by the Chinese (simplified) team of translators.  The file is available at:

https://translationproject.org/latest/gcc/zh_CN.po

(This file, 'gcc-9.1.0.zh_CN.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

https://translationproject.org/latest/gcc/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

https://translationproject.org/domain/gcc.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




[PATCH 2/2] gcc/riscv: Add a mechanism to remove some calls to _riscv_save_0

2019-08-19 Thread Andrew Burgess
When using the -msave-restore flag we end up with calls to
_riscv_save_0 and _riscv_restore_0.  These functions adjust the stack
and save or restore the return address.  Due to grouping multiple
save/restore stub functions together the save/restore 0 calls actually
save s0, s1, s2, and the return address, but only the return address
actually matters.  Leaf functions don't call the save/restore stubs,
so whenever we do see a call to the save/restore stubs, the store of
the return address is required.

If we look in gcc/config/riscv/riscv.c at the function
riscv_expand_prologue and riscv_expand_epilogue we can see that it
would be reasonably easy to adjust these functions to avoid the calls
to the save/restore stubs for those cases where we are about to call
_riscv_save_0 and _riscv_restore_0, however, the actual code size
saving this would give is debatable, with linker relaxation, the calls
to save/restore are often just 4-bytes, and can sometimes even be
2-bytes, while leaving the stack adjust and return address save inline
is always going to be 4-bytes.

The interesting case is when we call _riscv_save_0 and
_riscv_restore_0, and also have a frame that would (without
save/restore) have resulted in a tail call.  In this case if we could
remove the save/restore calls, and restore the tail call then we would
get a real size saving.

The problem is that the choice of generating a tail call or not is
done during the gimple expand pass, at which point we don't know how
many registers we need to save (or restore).

The solution presented in this patch offers a partial solution to this
problem.  By using the TARGET_MACHINE_DEPENDENT_REORG pass to
implement a very limited pattern matching we identify functions that
call _riscv_save_0 and _riscv_restore_0, and which could be converted
to make use of a tail call.  These functions are then converted to the
non save/restore tail call form.

This should result in a code size reduction when compiling with -Os
and with the -msave-restore flag.

gcc/ChangeLog:

* config.gcc: Add riscv-sr.o to extra_objs for riscv.
* config/riscv/riscv-sr.c: New file.
* config/riscv/riscv.c (riscv_reorg): New function.
(TARGET_MACHINE_DEPENDENT_REORG): Define.
* config/riscv/riscv.h (SIBCALL_REG_P): Define.
(CALLEE_SAVED_REG_P): Define.
(riscv_remove_unneeded_save_restore_calls): Declare.
* config/riscv/t-riscv (riscv-sr.o): New build rule.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/save-restore-2.c: New file.
* gcc.target/riscv/save-restore-3.c: New file.
* gcc.target/riscv/save-restore-4.c: New file.
* gcc.target/riscv/save-restore-5.c: New file.
* gcc.target/riscv/save-restore-6.c: New file.
* gcc.target/riscv/save-restore-7.c: New file.
* gcc.target/riscv/save-restore-8.c: New file.
---
 gcc/ChangeLog   |  11 +
 gcc/config.gcc  |   2 +-
 gcc/config/riscv/riscv-sr.c | 375 
 gcc/config/riscv/riscv.c|  13 +
 gcc/config/riscv/riscv.h|  20 ++
 gcc/config/riscv/t-riscv|   5 +
 gcc/testsuite/ChangeLog |  10 +
 gcc/testsuite/gcc.target/riscv/save-restore-2.c |  22 ++
 gcc/testsuite/gcc.target/riscv/save-restore-3.c |  16 +
 gcc/testsuite/gcc.target/riscv/save-restore-4.c |  27 ++
 gcc/testsuite/gcc.target/riscv/save-restore-5.c |   9 +
 gcc/testsuite/gcc.target/riscv/save-restore-6.c |  16 +
 gcc/testsuite/gcc.target/riscv/save-restore-7.c |  30 ++
 gcc/testsuite/gcc.target/riscv/save-restore-8.c |  12 +
 14 files changed, 567 insertions(+), 1 deletion(-)
 create mode 100644 gcc/config/riscv/riscv-sr.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-5.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-8.c

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 40cbc52dc994..ac02d1835372 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -520,7 +520,7 @@ pru-*-*)
;;
 riscv*)
cpu_type=riscv
-   extra_objs="riscv-builtins.o riscv-c.o"
+   extra_objs="riscv-builtins.o riscv-c.o riscv-sr.o"
d_target_objs="riscv-d.o"
;;
 rs6000*-*-*)
diff --git a/gcc/config/riscv/riscv-sr.c b/gcc/config/riscv/riscv-sr.c
new file mode 100644
index ..7d12c0d82111
--- /dev/null
+++ b/gcc/config/riscv/riscv-sr.c
@@ -0,0 +1,375 @@
+/* This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as 

[PATCH 1/2] gcc/riscv: Include more registers in SIBCALL_REGS

2019-08-19 Thread Andrew Burgess
The current SIBCALL_REGS are x6, x7, and x28 to x31.  These are all
caller saved registers, however, they are not all of the caller saved
registers.

I don't see any reason why we couldn't add t1, and a0 to a7 into this
set, and this is what this patch does.

gcc/ChangeLog:

* config/riscv/riscv.h (REG_CLASS_CONTENTS): Update SIBCALL_REGS.
---
 gcc/ChangeLog| 4 
 gcc/config/riscv/riscv.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 5fc9be8edbf2..bb8240bb849a 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -400,7 +400,7 @@ enum reg_class
 #define REG_CLASS_CONTENTS \
 {  \
   { 0x, 0x, 0x },  /* NO_REGS */   \
-  { 0xf0c0, 0x, 0x },  /* SIBCALL_REGS */  \
+  { 0xf003fce0, 0x, 0x },  /* SIBCALL_REGS */  \
   { 0xffc0, 0x, 0x },  /* JALR_REGS */ \
   { 0x, 0x, 0x },  /* GR_REGS */   \
   { 0x, 0x, 0x },  /* FP_REGS */   \
-- 
2.14.5



[PATCH 0/2] RISCV: Reduce code size when compiling with -msave-restore

2019-08-19 Thread Andrew Burgess
The following two patches are an attempt at further reducing code size
when compiling with -msave-restore by attempting to claw back some of
the tail call cases where we currently include a call to
__riscv_save_0 and __riscv_restore_0.

Any feedback, or suggestions for improvements, or for better
approaches I could take are gratefully recieved.

Thanks,
Andrew

--

Andrew Burgess (2):
  gcc/riscv: Include more registers in SIBCALL_REGS
  gcc/riscv: Add a mechanism to remove some calls to _riscv_save_0

 gcc/ChangeLog   |  15 +
 gcc/config.gcc  |   2 +-
 gcc/config/riscv/riscv-sr.c | 375 
 gcc/config/riscv/riscv.c|  13 +
 gcc/config/riscv/riscv.h|  22 +-
 gcc/config/riscv/t-riscv|   5 +
 gcc/testsuite/ChangeLog |  10 +
 gcc/testsuite/gcc.target/riscv/save-restore-2.c |  22 ++
 gcc/testsuite/gcc.target/riscv/save-restore-3.c |  16 +
 gcc/testsuite/gcc.target/riscv/save-restore-4.c |  27 ++
 gcc/testsuite/gcc.target/riscv/save-restore-5.c |   9 +
 gcc/testsuite/gcc.target/riscv/save-restore-6.c |  16 +
 gcc/testsuite/gcc.target/riscv/save-restore-7.c |  30 ++
 gcc/testsuite/gcc.target/riscv/save-restore-8.c |  12 +
 14 files changed, 572 insertions(+), 2 deletions(-)
 create mode 100644 gcc/config/riscv/riscv-sr.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-5.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-8.c

-- 
2.14.5



libgo patch committed: Stricter GC checking

2019-08-19 Thread Ian Lance Taylor
This libgo patch by Cherry Zhang enables stricter GC checking in libgo.

With https://golang.org/cl/190599
(https://gcc.gnu.org/ml/gcc-patches/2019-08/msg01220.html), along with
what we do in greyobject, we ensure that we only mark allocated heap
objects.  As a result we can be more strict in GC:

- Enable "sweep increased allocation count" check, which checks that
the number of mark bits set are no more than the number of allocation
bits.

- Enable invalid pointer check on heap scan. We only trace allocated
heap objects, which should not contain invalid pointer.

This also makes the libgo runtime more convergent with the gc runtime.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 274614)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-85857977230437f2b3dcbeea009efbb8b2789039
+b0ba5daa8216a0424b24f74466cedab0b986f3b4
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/runtime/mcentral.go
===
--- libgo/go/runtime/mcentral.go(revision 274169)
+++ libgo/go/runtime/mcentral.go(working copy)
@@ -56,15 +56,6 @@ retry:
c.empty.insertBack(s)
unlock()
s.sweep(true)
-
-   // With gccgo's conservative GC, the returned span may
-   // now be full. See the comments in mspan.sweep.
-   if uintptr(s.allocCount) == s.nelems {
-   s.freeindex = s.nelems
-   lock()
-   goto retry
-   }
-
goto havespan
}
if s.sweepgen == sg-1 {
Index: libgo/go/runtime/mgcsweep.go
===
--- libgo/go/runtime/mgcsweep.go(revision 274169)
+++ libgo/go/runtime/mgcsweep.go(working copy)
@@ -326,39 +326,16 @@ func (s *mspan) sweep(preserve bool) boo
freeToHeap = true
}
nfreed := s.allocCount - nalloc
-
-   // This check is not reliable with gccgo, because of
-   // conservative stack scanning. The test boils down to
-   // checking that no new bits have been set in gcmarkBits since
-   // the span was added to the sweep count. New bits are set by
-   // greyobject. Seeing a new bit means that a live pointer has
-   // appeared that was not found during the mark phase. That can
-   // not happen when pointers are followed strictly. However,
-   // with conservative checking, it is possible for a pointer
-   // that will never be used to appear live and to cause a mark
-   // to be added. That is unfortunate in that it causes this
-   // check to be inaccurate, and it will keep an object live
-   // unnecessarily, but provided the pointer is not really live
-   // it is not otherwise a problem. So we disable the test for gccgo.
-   nfreedSigned := int(nfreed)
if nalloc > s.allocCount {
-   if usestackmaps {
-   print("runtime: nelems=", s.nelems, " nalloc=", nalloc, 
" previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n")
-   throw("sweep increased allocation count")
-   }
-
-   // For gccgo, adjust the freed count as a signed number.
-   nfreedSigned = int(s.allocCount) - int(nalloc)
-   if uintptr(nalloc) == s.nelems {
-   s.freeindex = s.nelems
-   }
+   print("runtime: nelems=", s.nelems, " nalloc=", nalloc, " 
previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n")
+   throw("sweep increased allocation count")
}
 
s.allocCount = nalloc
wasempty := s.nextFreeIndex() == s.nelems
s.freeindex = 0 // reset allocation index to start of span.
if trace.enabled {
-   getg().m.p.ptr().traceReclaimed += uintptr(nfreedSigned) * 
s.elemsize
+   getg().m.p.ptr().traceReclaimed += uintptr(nfreed) * s.elemsize
}
 
// gcmarkBits becomes the allocBits.
@@ -374,7 +351,7 @@ func (s *mspan) sweep(preserve bool) boo
// But we need to set it before we make the span available for 
allocation
// (return it to heap or mcentral), because allocation code assumes 
that a
// span is already swept if available for allocation.
-   if freeToHeap || nfreedSigned <= 0 {
+   if freeToHeap || nfreed == 0 {
// The span must be in our exclusive ownership until we update 
sweepgen,
// check for potential races.
if s.state != mSpanInUse || s.sweepgen 

Re: [PATCH 0/3] add support for POD struct convention (PR 61339)

2019-08-19 Thread Jason Merrill
On Wed, Aug 14, 2019, 11:44 AM Pedro Alves  wrote:

> On 7/12/19 9:24 AM, Jakub Jelinek wrote:
> > I'd just arrange that when being compiled with clang we compile with
> > -Wno-mismatched-tags to get rid of their misdesigned warning and not add
> > such misdesigned warning to GCC, that will just help people spread this
> > weirdo requirement further.
>
> FWIW and FYI, this is what GDB does (gdb/warning.m4).
>

As I understand it, the warning reflects a hard requirement for code that
wants to be portable to MSVC++, so I think it's useful to have for that
purpose.

Jason


Re: C++ PATCH for c++/81676 - bogus -Wunused warnings in constexpr if

2019-08-19 Thread Marek Polacek
On Fri, Aug 16, 2019 at 06:20:20PM -0700, Jason Merrill wrote:
> On 8/16/19 2:29 PM, Marek Polacek wrote:
> > This patch is an attempt to fix the annoying -Wunused-but-set-* warnings 
> > that
> > tend to occur with constexpr if.  When we have something like
> > 
> >template < typename T >
> >int f(T v){
> >if constexpr(sizeof(T) == sizeof(int)){
> >   return v;
> >}else{
> >   return 0;
> >}
> >}
> > 
> > and call f('a'), then the condition is false, meaning that we won't 
> > instantiate
> > the then-branch, as per tsubst_expr/IF_STMT:
> > 17284   if (IF_STMT_CONSTEXPR_P (t) && integer_zerop (tmp))
> > 17285 /* Don't instantiate the THEN_CLAUSE. */;
> > so we'll never get round to mark_exp_read-ing the decls used in the
> > then-branch, causing finish_function to emit "parameter set but not used"
> > warnings.
> > 
> > It's unclear how to best deal with this.  Marking the decls DECL_READ_P 
> > while
> > parsing doesn't seem like a viable approach
> 
> Why not?

Well, while parsing, we're in a template and so the condition won't be
evaluated until tsubst_expr.  So we can't tell which branch is dead.

I suppose we could still mark all the _DECLs in then/else branches as read,
in finish_if_stmt if IF_STMT_CONSTEXPR_P, but that seems really really ugly.

--
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA


Re: [PATCH], Patch #2 of 10, Add RTL prefixed attribute

2019-08-19 Thread Segher Boessenkool
Hi Mike,

Some comments on this patch:

On Wed, Aug 14, 2019 at 05:59:13PM -0400, Michael Meissner wrote:
> Due to some of the existing load and store insns not using the traditional
> operands[0] and operands[1], the functions that test whether an insn is
> prefixed only use the insn and not the operands directly.

Both the "update" and the "indexed" attributes have no problem with
this: the insns that have the problem set the attribute value directly.
This is mainly all the various update insns, but there are a bunch more,
and they all need different settings for their attributes.

>   * config/rs6000/rs6000.c (rs6000_emit_move): Add support for
>   loading up pc-relatve addresses.

(typo btw)

> +void
> +rs6000_final_prescan_insn (rtx_insn *insn)
> +{
> +  next_insn_prefixed_p = (get_attr_prefixed (insn) != PREFIXED_NO);
> +  return;
> +}

Don't say "return;" at the end of a function please.

> +void
> +rs6000_asm_output_opcode (FILE *stream, const char *)
> +{
> +  if (next_insn_prefixed_p)
> +{
> +  next_insn_prefixed_p = false;
> +  fprintf (stream, "p");
> +}

You don't need to clear the flag here; the next call to
rs6000_final_prescan_insn will.

> +#define FINAL_PRESCAN_INSN(INSN, OPERANDS, NOPERANDS)
> \
> +do   \
> +  {  \
> +if (TARGET_PREFIXED_ADDR)
> \
> +  rs6000_final_prescan_insn (INSN);  
> \
> +  }  \
> +while (0)

Either have the function only do what it needs to for prefixed, and call
it something with prefixed in the name, or put the TARGET_PREFIXED_ADDR
test in the function itself.

> +;; Load up a pc-relative address.  ASM_OUTPUT_OPCODE will emit the initial 
> "p".
> +(define_insn "*pcrel_addr"
> +  [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
> + (match_operand:DI 1 "pcrel_address"))]
> +  "TARGET_PCREL"
> +  "la %0,%a1"
> +  [(set_attr "prefixed" "yes")])

(use P for addresses please)

> +;; Load up a pc-relative address to an external symbol.  If the symbol and 
> the
> +;; program are both defined in the main program, the linker will optimize 
> this
> +;; to a PADDI.  Otherwise, it will create a GOT address that is relocated by
> +;; the dynamic linker and loaded up.
> +(define_insn "*pcrel_ext_addr"
> +  [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
> + (match_operand:DI 1 "pcrel_external_address"))]
> +  "TARGET_PCREL"
> +  "ld %0,%a1"
> +  [(set_attr "prefixed" "yes")])

pld does an indirection more than pla does, but this is not clear at all
from the RTL, from the predicate names.  All this is *before* the linker
has done its thing, so pcrel_external_address is really some GOT memory,
so it should have that in its name.


Segher


Re: [AArch64] Tweak handling of fp moves via int registers

2019-08-19 Thread James Greenhalgh
On Wed, Aug 07, 2019 at 07:12:19PM +0100, Richard Sandiford wrote:
> The AArch64 port uses define_splits to prefer moving certain float
> constants via integer registers over loading them from memory.  E.g.:
> 
> (set (reg:SF X) (const_double:SF C))
> 
> splits to:
> 
> (set (reg:SI tmp) (const_int C'))
> (set (reg:SF X) (subreg:SF (reg:SI tmp) 0))
> 
> The problem with using splits for this -- especially when the split
> instruction is a constant move -- is that the original form is still
> valid and can be recreated by later pre-RA passes.  (And I think that's
> a valid thing for them to do, since they're folding away what appears in
> rtl terms to be a redundant instruction.)
> 
> One pass that can do this is ira's combine_and_move_insns, which among
> other things looks for registers that are set once and used once.
> If the register is set to a rematerialisable value, the code tries
> to fold that value into the single use.
> 
> We don't normally see this effect at -O2 and above because
> combine_and_move_insns isn't run when -fsched-pressure is enabled
> (which it is by default on AArch64).  But arguably the combine part is
> useful independently of -fsched-pressure, and only the move part is
> suspect.  So I don't think we should rely on the combination not
> happening here.
> 
> The new tests demonstrate the problem by running the original tests
> at -O instead of -O2.
> 
> This patch does the optimisation by splitting the moves at generation
> time and rejecting the combined form while the split is still possible.
> REG_EQUAL notes on the second move still give the original floating-point
> value for passes that need it.
> 
> Tested on aarch64-linux-gnu (with and without SVE) and aarch64_be-elf.
> OK to install?

OK.

Thanks,
James

> Richard
> 
> 
> 2019-08-07  Richard Sandiford  
> 
> gcc/
>   * config/aarch64/aarch64-protos.h (aarch64_move_float_via_int_p):
>   Declare.
>   * config/aarch64/aarch64.c (aarch64_move_float_via_int_p): New
>   function, extracted from the GPF_HF move splitter.
>   * config/aarch64/aarch64.md: Remove GPF_HF move splitter.
>   (mov): Move via an integer register if
>   aarch64_move_float_via_int_p.
>   (*movhf_aarch64, *movsf_aarch64, *movdf_aarch64): Check
>   aarch64_move_float_via_int_p.
>   * config/aarch64/iterators.md (fcvt_target): Handle TI and TF.
>   (FCVT_TARGET): Likewise.
> 
> gcc/testsuite/
>   * gcc.target/aarch64/dbl_mov_immediate_2.c: New test.
>   * gcc.target/aarch64/f16_mov_immediate_5.c: Likewise.
>   * gcc.target/aarch64/flt_mov_immediate_2.c: Likewise.


Re: PR90724 - ICE with __sync_bool_compare_and_swap with -march=armv8.2-a

2019-08-19 Thread James Greenhalgh
On Thu, Aug 15, 2019 at 02:11:25PM +0100, Prathamesh Kulkarni wrote:
> On Thu, 8 Aug 2019 at 11:22, Prathamesh Kulkarni
>  wrote:
> >
> > On Thu, 1 Aug 2019 at 15:34, Prathamesh Kulkarni
> >  wrote:
> > >
> > > On Thu, 25 Jul 2019 at 11:56, Prathamesh Kulkarni
> > >  wrote:
> > > >
> > > > On Wed, 17 Jul 2019 at 18:15, Prathamesh Kulkarni
> > > >  wrote:
> > > > >
> > > > > On Wed, 17 Jul 2019 at 13:45, Kyrill Tkachov
> > > > >  wrote:
> > > > > >
> > > > > > Hi Prathamesh
> > > > > >
> > > > > > On 7/10/19 12:24 PM, Prathamesh Kulkarni wrote:
> > > > > > > Hi,
> > > > > > > For following test-case,
> > > > > > > static long long AL[24];
> > > > > > >
> > > > > > > int
> > > > > > > check_ok (void)
> > > > > > > {
> > > > > > >   return (__sync_bool_compare_and_swap (AL+1, 0x20003ll,
> > > > > > > 0x1234567890ll));
> > > > > > > }
> > > > > > >
> > > > > > > Compiling with -O2 -march=armv8.2-a results in:
> > > > > > > pr90724.c: In function ‘check_ok’:
> > > > > > > pr90724.c:7:1: error: unrecognizable insn:
> > > > > > > 7 | }
> > > > > > >   | ^
> > > > > > > (insn 11 10 12 2 (set (reg:CC 66 cc)
> > > > > > > (compare:CC (reg:DI 95)
> > > > > > > (const_int 8589934595 [0x20003]))) 
> > > > > > > "pr90724.c":6:11 -1
> > > > > > >  (nil))
> > > > > > >
> > > > > > > IIUC, the issue is that 0x20003 falls outside the range of
> > > > > > > allowable immediate in cmp ? If it's replaced by a small constant 
> > > > > > > then
> > > > > > > it works.
> > > > > > >
> > > > > > > The ICE results with -march=armv8.2-a because, we enter if
> > > > > > > (TARGET_LSE) { ... } condition
> > > > > > > in aarch64_expand_compare_and_swap, while with -march=armv8.a it 
> > > > > > > goes
> > > > > > > into else,
> > > > > > > which forces oldval into register if the predicate fails to match.
> > > > > > >
> > > > > > > The attached patch checks if y (oldval) satisfies 
> > > > > > > aarch64_plus_operand
> > > > > > > predicate and if not, forces it to be in register, which resolves 
> > > > > > > ICE.
> > > > > > > Does it look OK ?
> > > > > > >
> > > > > > > Bootstrap+testing in progress on aarch64-linux-gnu.
> > > > > > >
> > > > > > > PS: The issue has nothing to do with SVE, which I incorrectly
> > > > > > > mentioned in bug report.
> > > > > > >
> > > > > > This looks ok to me (but you'll need maintainer approval).
> > > > > >
> > > > > > Does this fail on the branches as well?
> > > > > Hi Kyrill,
> > > > > Thanks for the review. The test also fails on gcc-9-branch (but not 
> > > > > on gcc-8).
> > > > Hi James,
> > > > Is the patch OK to commit  ?
> > > > https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00793.html
> > > ping * 3: https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00793.html
> > ping * 4: https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00793.html
> ping * 5: https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00793.html

Hi,

Sorry, this missed my filters as it didn't mention AArch64 in the subject
line.

Thais is good for trunk, thanks for waiting.

James



Re: [PATCH 0/2] PR libstdc++/41861 Add full steady_clock support to condition_variable

2019-08-19 Thread Mike Crowe
On Monday 15 July 2019 at 17:47:47 +0100, Mike Crowe wrote:
> The pthread_cond_clockwait function was recently added[1] to glibc,
> and is due to be released in glibc 2.30. If this function is available
> in the C library it can be used it to fix
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41861 by supporting
> std::chrono::steady_clock properly with std::condition_variable.
> 
> Mike Crowe (2):
>   Add user-defined clock to libstdc++ condition_variable tests
>   PR libstdc++/41861 Add full steady_clock support to condition_variable
> 
>  libstdc++-v3/ChangeLog| 34 
> +-
>  libstdc++-v3/acinclude.m4 | 31 
> +++-
>  libstdc++-v3/config.h.in  |  3 
> +++-
>  libstdc++-v3/configure| 83 
> -
>  libstdc++-v3/configure.ac |  3 
> +++-
>  libstdc++-v3/include/std/condition_variable   | 52 
> +++--
>  libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc | 29 
> ++---
>  libstdc++-v3/testsuite/30_threads/condition_variable_any/members/2.cc | 29 
> ++---
>  8 files changed, 252 insertions(+), 12 deletions(-)
> 
> base-commit: 7b0d7c79224b412ea5073593943ab1525cbbda73
> -- 
> git-series 0.9.1

glibc 2.30 has now been released and contains pthread_cond_clockwait.

Mike.


Re: [PING][AArch64] Use scvtf fbits option where appropriate

2019-08-19 Thread James Greenhalgh
On Mon, Jul 08, 2019 at 04:41:06PM +0100, Joel Hutton wrote:
> On 01/07/2019 18:03, James Greenhalgh wrote:
> 
> >> gcc/testsuite/ChangeLog:
> >>
> >> 2019-06-12  Joel Hutton  
> >>
> >>   * gcc.target/aarch64/fmul_scvtf_1.c: New test.
> > This testcase will fail on ILP32 targets where unsigned long will still
> > live in a 'w' register.
> Updated to use long long and unsigned long long.

Sorry, this slipped through the cracks.

OK for trunk.

Thanks,
James


> 
> Joel
> 

> From e10d5fdb9430799cd2050b8a2f567d1b4e43cde1 Mon Sep 17 00:00:00 2001
> From: Joel Hutton 
> Date: Mon, 8 Jul 2019 11:59:50 +0100
> Subject: [PATCH] SCVTF
> 
> ---
>  gcc/config/aarch64/aarch64-protos.h   |   1 +
>  gcc/config/aarch64/aarch64.c  |  23 +++
>  gcc/config/aarch64/aarch64.md |  39 +
>  gcc/config/aarch64/constraints.md |   7 +
>  gcc/config/aarch64/predicates.md  |   4 +
>  .../gcc.target/aarch64/fmul_scvtf_1.c | 140 ++
>  6 files changed, 214 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/fmul_scvtf_1.c
> 


Re: [PATCH] Intrinsic documentation for DIM, MOD and MODULO.

2019-08-19 Thread Steve Kargl
On Mon, Aug 19, 2019 at 09:08:12AM -0600, Jeff Law wrote:
> On 8/19/19 3:11 AM, Mark Eggleston wrote:
> > The intrinsics DIM, MOD and MODULO can accept arguments of different
> > kinds and return values with the larger of the two kinds. Notes to this
> > effect have been added as they were missing from the documentation.
> > 
> > Please find attached the patch.
> > 
> > ChangeLog:
> > 
> > gcc/fortran/ChangeLog
> > 
> >     Mark Eggleston  
> > 
> >     PR fortran/89236
> >     * intrinsic.texi: Add GNU extension notes to DIM, MOD, MODULO.
> > 
> Do we want to be more specific about what types are accepted as a GNU
> extension for these operators?
> 

The current documentation already has that info.

_Arguments_:
 X   The type shall be 'INTEGER' or 'REAL'
 Y   The type shall be the same type and kind as X.

In Fortran standardese, INTEGER means any of the supported
integer kinds (e.g., INTEGER(2)).  X and Y must both be either
INTEGER or REAL, and X and Y must have the same kind type
paramter.  Mark's addition to the manual notes that the
GNU extension allows different kind type parameters, e.g.,

integer(1) i
integer(2) j
...
  k = dim(i,j) 

converts i to an integer(2) before executing the function.

Mark, BTW and IMHO, for minor changes/improvements to the gfortran
documentation, I consider these to be pre-approved.  For
large changes, or if you want someone to proofread a change,
then asking for commit approval is appropriate. 
-- 
Steve


Re: [patch][aarch64]: add intrinsics for vld1(q)_x4 and vst1(q)_x4

2019-08-19 Thread James Greenhalgh
On Thu, Aug 15, 2019 at 12:28:27PM +0100, Kyrill Tkachov wrote:
> Hi all,
> 
> On 8/6/19 10:51 AM, Richard Earnshaw (lists) wrote:
> On 18/07/2019 18:18, James Greenhalgh wrote:
> > On Mon, Jun 10, 2019 at 06:21:05PM +0100, Sylvia Taylor wrote:
> >> Greetings,
> >>
> >> This patch adds the intrinsic functions for:
> >> - vld1__x4
> >> - vst1__x4
> >> - vld1q__x4
> >> - vst1q__x4
> >>
> >> Bootstrapped and tested on aarch64-none-linux-gnu.
> >>
> >> Ok for trunk? If yes, I don't have any commit rights, so can someone
> >> please commit it on my behalf.
> >
> > Hi,
> >
> > I'm concerned by this strategy for implementing the arm_neon.h builtins:
> >
> >> +__extension__ extern __inline int8x8x4_t
> >> +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> >> +vld1_s8_x4 (const int8_t *__a)
> >> +{
> >> +  union { int8x8x4_t __i; __builtin_aarch64_simd_xi __o; } __au;
> >> +  __au.__o
> >> += __builtin_aarch64_ld1x4v8qi ((const __builtin_aarch64_simd_qi *) 
> >> __a);
> >> +  return __au.__i;
> >> +}
> >
> > As far as I know this is undefined behaviour in C++11. This was the best
> > resource I could find pointing to the relevant standards paragraphs.
> >
> >
> > https://stackoverflow.com/questions/11373203/accessing-inactive-union-member-and-undefined-behavior
> >
> > That said, GCC explicitly allows it, so maybe this is fine?
> >
> >
> > https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Optimize-Options.html#Type-punning
> >
> > Can anyone from the languages side chime in on whether we're exposing
> > undefined behaviour (in either C or C++) here?
> 
> Yes, this is a GNU extension.  My only question is whether or not this
> can be disabled within GCC if you're trying to check for strict
> standards conformance of your code?  And if so, is there a way of making
> sure that this header still works in that case?  A number of GNU
> extensions can be protected with __extension__ but it's not clear how
> that could be applied in this case.  Perhaps the outer __extension__ on
> the function will already do that.
> 
> 
> It should still work. The only relevant flag is -fstrict-aliasing and it is
> documented to preserve this case:
> 
> https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Optimize-Options.html#Optimize-Options
> 
> Note that we've already been using this idiom in arm_neon.h since 2014 [1]
> and it's worked fine.

Based on that input, this is OK for trunk.

Thanks,
James

> 
> Thanks,
> 
> Kyrill
> 
> [1] http://gcc.gnu.org/r209880
> 
> 
> 
> R.


Re: [aarch64] PR target/91386 Use copy_rtx to avoid modifying original insns in peep2 pattern

2019-08-19 Thread Richard Earnshaw (lists)

On 09/08/2019 17:15, Richard Earnshaw (lists) wrote:

PR target/91386 is a situation where a peephole2 pattern substitution
is discarded late because the selected instructions contain
frame-related notes that we cannot redistribute (because the pattern
has more than one insn in the output).  Unfortunately, the original
insns were being modified during the generation, so after the undo we
are left with corrupt RTL.

We avoid this by ensuring that the modifications are always made on a
copy, so that the original insns are never changed.

 PR target/91386
 * config/aarch64/aarch64.c (aarch64_gen_adjusted_ldpstp): Use copy_rtx
 to preserve the contents of the original insns.

Committed to trunk.


And now backported to gcc-9.

R.


[wwwdocs] Document C++ news in GCC 10 Release Notes

2019-08-19 Thread Marek Polacek
I'm of the mind that we should advertise some of the new cool
C++ changes going into GCC 10, esp. those that are user-visible.

Checking this in.

Index: changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-10/changes.html,v
retrieving revision 1.8
diff -u -r1.8 changes.html
--- changes.html19 Aug 2019 14:08:10 -  1.8
+++ changes.html19 Aug 2019 15:53:27 -
@@ -48,10 +48,46 @@
 
 C++
 
+  Several C++20 features have been implemented:
+  
+P1668R1, Permitting Unevaluated inline-assembly in constexpr 
Functions
+P1161R3, Deprecate a[b,c]
+P0848R3, Conditionally Trivial Special Member Functions
+P1091R3, Extending structured bindings
+
+  
+  Several C++ Defect Reports have been resolved, e.g.:
+  
+DR 1560 (lvalue-to-rvalue conversion in ?:),
+DR 1813 (__is_standard_layout for a class with repeated
+   bases),
+DR 2094 (volatile scalars are trivially copyable),
+DR 2096 (constraints on literal unions),
+DR 2413 (typename in  
conversion-function-ids).
+   
+
+  
   
 G++ can now detect modifying constant objects in constexpr evaluation
 (which is undefined behavior).
   
+  
+G++ no longer emits bogus -Wsign-conversion warnings with 
explicit
+casts.
+  
+  
+Narrowing is now detected in more contexts (e.g., case
+values).
+  
+  
+Memory consumption of the compiler has been reduced in constexpr 
evaluation.
+  
+  
+The noexcept-specifier is now properly treated as a
+complete-class context as per
+http://eel.is/c++draft/class.mem#def:complete-class_context;>
+[class.mem].
+  
 
 
 


Re: [PATCH][ARM] Remove remaining Neon DImode support

2019-08-19 Thread Wilco Dijkstra
   
 
ping
    
  
 Remove the remaining Neon adddi3, subdi3 and negdi2 patterns.  As a result
  adddi3, subdi3 and negdi2 can now always be expanded early irrespectively of
  whether Neon is available.  Also expand the extenddi patterns at the same
  time.  Several Neon arch attributes are no longer used and removed.
  
  Code generation is improved in all cases, saving another 400-500 instructions
  from the PR77308 testcase (total improvement is over 1700 instructions with
  -mcpu=cortex-a57 -O2).
  
  Bootstrap & regress OK on arm-none-linux-gnueabihf --with-cpu=cortex-a57
  
  ChangeLog:
  2019-07-19  Wilco Dijkstra  
  
  * config/arm/arm.md (neon_for_64bits): Remove.
  (avoid_neon_for_64bits): Remove.
  (arm_adddi3): Always split early.
  (arm_subdi3): Always split early.
  (negdi2): Remove Neon expansion.
  (split zero_extend): Split before reload.
  (split sign_extend): Split before reload.
  ---
  
  diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
  index 
10ed70dac4384354c0a2453c5e51a29108c6c062..6d8a5a54997caee0e6956f01018cb5300a9a07e1
 100644
  --- a/gcc/config/arm/arm.md
  +++ b/gcc/config/arm/arm.md
  @@ -125,7 +125,7 @@ (define_attr "length" ""
   ; arm_arch6.  "v6t2" for Thumb-2 with arm_arch6 and "v8mb" for ARMv8-M
   ; Baseline.  This attribute is used to compute attribute "enabled",
   ; use type "any" to enable an alternative in all cases.
  -(define_attr "arch" 
"any,a,t,32,t1,t2,v6,nov6,v6t2,v8mb,neon_for_64bits,avoid_neon_for_64bits,iwmmxt,iwmmxt2,armv6_or_vfpv3,neon"
  +(define_attr "arch" 
"any,a,t,32,t1,t2,v6,nov6,v6t2,v8mb,iwmmxt,iwmmxt2,armv6_or_vfpv3,neon"
     (const_string "any"))
   
   (define_attr "arch_enabled" "no,yes"
  @@ -168,16 +168,6 @@ (define_attr "arch_enabled" "no,yes"
     (match_test "TARGET_THUMB1 && arm_arch8"))
    (const_string "yes")
   
  -    (and (eq_attr "arch" "avoid_neon_for_64bits")
  - (match_test "TARGET_NEON")
  - (not (match_test "TARGET_PREFER_NEON_64BITS")))
  -    (const_string "yes")
  -
  -    (and (eq_attr "arch" "neon_for_64bits")
  - (match_test "TARGET_NEON")
  - (match_test "TARGET_PREFER_NEON_64BITS"))
  -    (const_string "yes")
  -
    (and (eq_attr "arch" "iwmmxt2")
     (match_test "TARGET_REALLY_IWMMXT2"))
    (const_string "yes")
  @@ -450,13 +440,8 @@ (define_expand "adddi3"
   (clobber (reg:CC CC_REGNUM))])]
     "TARGET_EITHER"
     "
  -  if (TARGET_THUMB1)
  -    {
  -  if (!REG_P (operands[1]))
  -    operands[1] = force_reg (DImode, operands[1]);
  -  if (!REG_P (operands[2]))
  -    operands[2] = force_reg (DImode, operands[2]);
  - }
  +  if (TARGET_THUMB1 && !REG_P (operands[2]))
  +    operands[2] = force_reg (DImode, operands[2]);
     "
   )
   
  @@ -465,9 +450,9 @@ (define_insn_and_split "*arm_adddi3"
   (plus:DI (match_operand:DI 1 "arm_general_register_operand" "%0, 0, 
r, 0, r")
    (match_operand:DI 2 "arm_general_adddi_operand"    "r,  0, 
r, Dd, Dd")))
  (clobber (reg:CC CC_REGNUM))]
  -  "TARGET_32BIT && !TARGET_NEON"
  +  "TARGET_32BIT"
     "#"
  -  "TARGET_32BIT && ((!TARGET_NEON && !TARGET_IWMMXT) || reload_completed)"
  +  "TARGET_32BIT"
     [(parallel [(set (reg:CC_C CC_REGNUM)
  (compare:CC_C (plus:SI (match_dup 1) (match_dup 2))
    (match_dup 1)))
  @@ -1290,24 +1275,16 @@ (define_expand "subdi3"
   (clobber (reg:CC CC_REGNUM))])]
     "TARGET_EITHER"
     "
  -  if (TARGET_THUMB1)
  -    {
  -  if (!REG_P (operands[1]))
  -    operands[1] = force_reg (DImode, operands[1]);
  -  if (!REG_P (operands[2]))
  -    operands[2] = force_reg (DImode, operands[2]);
  - } 
  -  "
  -)
  +")
   
   (define_insn_and_split "*arm_subdi3"
     [(set (match_operand:DI   0 "arm_general_register_operand" 
"=,,")
   (minus:DI (match_operand:DI 1 "arm_general_register_operand" "0,r,0")
     (match_operand:DI 2 "arm_general_register_operand" 
"r,0,0")))
  (clobber (reg:CC CC_REGNUM))]
  -  "TARGET_32BIT && !TARGET_NEON"
  +  "TARGET_32BIT"
     "#"  ; "subs\\t%Q0, %Q1, %Q2\;sbc\\t%R0, %R1, %R2"
  -  "&& (!TARGET_IWMMXT || reload_completed)"
  +  "TARGET_32BIT"
     [(parallel [(set (reg:CC CC_REGNUM)
  (compare:CC (match_dup 1) (match_dup 2)))
     (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))])
  @@ -4164,13 +4141,6 @@ (define_expand "negdi2"
    (neg:DI (match_operand:DI 1 "s_register_operand")))
   (clobber (reg:CC CC_REGNUM))])]
     "TARGET_EITHER"
  -  {
  -    if (TARGET_NEON)
  -  {
  -    emit_insn (gen_negdi2_neon (operands[0], operands[1]));
  -   DONE;
  -  }
  -  }
   )
   
   ;; The constraints here are to prevent a *partial* overlap (where %Q0 == 
%R1).
  @@ -4182,7 +4152,7 @@ 

Re: [PATCH][ARM] Cleanup DImode shifts

2019-08-19 Thread Wilco Dijkstra


   
 
ping
    
  
 Like the logical operations, expand all shifts early rather than only
  sometimes.  The Neon shift expansions are never emitted (not even with
  -fneon-for-64bits), so they are not useful.  So all the late expansions
  and Neon shift patterns can be removed, and shifts are more optimized
  as a result.  Since some extend patterns use Neon DImode shifts, remove
  the Neon extend variants and related splits.
  
  A simple example (relying on [1]) generates the same efficient code after
  this patch with -mfpu=neon and -mfpu=vfp (previously just the fact of
  having Neon enabled resulted inefficient code for no reason).
  
  unsigned long long f(unsigned long long x, unsigned long long y)
  { return x & (y >> 33); }
  
  Before:
  strd    r4, r5, [sp, #-8]!
  lsr r4, r3, #1
  mov r5, #0
  and r1, r1, r5
  and r0, r0, r4
  ldrd    r4, r5, [sp]
  add sp, sp, #8
  bx  lr
  
  After:
  and r0, r0, r3, lsr #1
  mov r1, #0
  bx  lr
  
  Bootstrap and regress OK on arm-none-linux-gnueabihf --with-cpu=cortex-a57
  
  [1] https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01301.html
  
  ChangeLog:
  2019-07-19  Wilco Dijkstra  
  
  * config/arm/iterators.md (qhs_extenddi_cstr): Update.
  (qhs_extenddi_cstr): Likewise.
  * config/arm/arm.md (ashldi3): Always expand early.
  (ashlsi3): Likewise.
  (ashrsi3): Likewise.
  (zero_extenddi2): Remove Neon variants.
  (extenddi2): Likewise.
  * config/arm/neon.md (ashldi3_neon_noclobber): Remove.
  (signed_shift_di3_neon): Likewise.
  (unsigned_shift_di3_neon): Likewise.
  (ashrdi3_neon_imm_noclobber): Likewise.
  (lshrdi3_neon_imm_noclobber): Likewise.
  (di3_neon): Likewise.
  (split extend): Remove DI extend split patterns.
  
  testsuite/
  * gcc.target/arm/neon-extend-1.c: Remove test.
  * gcc.target/arm/neon-extend-2.c: Remove test.
  ---
  
  diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
  index 
0dba97a4ebeed0c2133936ca662f1c9e86ffc6ba..10ed70dac4384354c0a2453c5e51a29108c6c062
 100644
  --- a/gcc/config/arm/arm.md
  +++ b/gcc/config/arm/arm.md
  @@ -3601,44 +3601,14 @@ (define_insn "*satsi__shift"
   (define_expand "ashldi3"
     [(set (match_operand:DI    0 "s_register_operand")
   (ashift:DI (match_operand:DI 1 "s_register_operand")
  -   (match_operand:SI 2 "general_operand")))]
  +   (match_operand:SI 2 "reg_or_int_operand")))]
     "TARGET_32BIT"
     "
  -  if (TARGET_NEON)
  -    {
  -  /* Delay the decision whether to use NEON or core-regs until
  -    register allocation.  */
  -  emit_insn (gen_ashldi3_neon (operands[0], operands[1], operands[2]));
  -  DONE;
  -    }
  -  else
  -    {
  -  /* Only the NEON case can handle in-memory shift counts.  */
  -  if (!reg_or_int_operand (operands[2], SImode))
  -    operands[2] = force_reg (SImode, operands[2]);
  -    }
  -
  -  if (!CONST_INT_P (operands[2]) && TARGET_REALLY_IWMMXT)
  -    ; /* No special preparation statements; expand pattern as above.  */
  -  else
  -    {
  -  rtx scratch1, scratch2;
  -
  -  /* Ideally we should use iwmmxt here if we could know that operands[1]
  - ends up already living in an iwmmxt register. Otherwise it's
  - cheaper to have the alternate code being generated than moving
  - values to iwmmxt regs and back.  */
  -
  -  /* Expand operation using core-registers.
  -    'FAIL' would achieve the same thing, but this is a bit smarter.  */
  -  scratch1 = gen_reg_rtx (SImode);
  -  scratch2 = gen_reg_rtx (SImode);
  -  arm_emit_coreregs_64bit_shift (ASHIFT, operands[0], operands[1],
  -    operands[2], scratch1, scratch2);
  -  DONE;
  -    }
  -  "
  -)
  +  arm_emit_coreregs_64bit_shift (ASHIFT, operands[0], operands[1],
  +    operands[2], gen_reg_rtx (SImode),
  +    gen_reg_rtx (SImode));
  +  DONE;
  +")
   
   (define_expand "ashlsi3"
     [(set (match_operand:SI    0 "s_register_operand")
  @@ -3661,35 +3631,11 @@ (define_expand "ashrdi3"
    (match_operand:SI 2 "reg_or_int_operand")))]
     "TARGET_32BIT"
     "
  -  if (TARGET_NEON)
  -    {
  -  /* Delay the decision whether to use NEON or core-regs until
  -    register allocation.  */
  -  emit_insn (gen_ashrdi3_neon (operands[0], operands[1], operands[2]));
  -  DONE;
  -    }
  -
  -  if (!CONST_INT_P (operands[2]) && TARGET_REALLY_IWMMXT)
  -    ; /* No special preparation statements; expand pattern as above.  */
  -  else
  -    {
  -  rtx scratch1, scratch2;
  -
  -  /* Ideally we should use iwmmxt here if we could know that operands[1]
  - ends up 

Re: [PATCH][ARM] Cleanup logical DImode operations

2019-08-19 Thread Wilco Dijkstra
   
 
ping
    
  
 
  Cleanup the logical DImode operations since the current implementation is way
  too complicated.  Thumb-1, Thumb-2, VFP/Neon and iwMMXt all work differently,
  resulting in a bewildering number of expansions, patterns and splits across
  several md files.  All this complexity is counterproductive and results in
  inefficient code.
  
  A much simpler approach is to split these operations early in the expander
  so that optimizations and register allocation are applied on the 32-bit 
halves.
  Code generation is unchanged on Thumb-1 and Arm/Thumb-2 without Neon or iwMMXt
  (which already expand these instructions early).  With Neon these changes save
  ~1000 instructions from the PR77308 testcase, mostly by significantly reducing
  register pressure and spilling.
  
  Bootstrap & regress OK on arm-none-linux-gnueabihf --with-cpu=cortex-a57
  
  OK for commit?
  
  ChangeLog:
  2019-07-18  Wilco Dijkstra  
  
  * config/arm/arm.md (split and/eor/ior): Remove Neon check.
  (split not): Add DImode not splitter.
  (anddi3): Remove pattern.
  (anddi3_insn): Likewise.
  (anddi_zesidi_di): Likewise.
  (anddi_sesdi_di): Likewise.
  (anddi_notdi_di): Likewise.
  (anddi_notzesidi_di): Likewise.
  (anddi_notsesidi_di): Likewise.
  (iordi3): Likewise.
  (iordi3_insn): Likewise.
  (iordi_zesidi_di): Likewise.
  (iordi_sesidi_di): Likewise.
  (xordi3): Likewise.
  (xordi3_insn): Likewise.
  (xordi_sesidi_di): Likewise.
  (xordi_zesidi_di): Likewise.
  (one_cmpldi2): Likewise.
  (one_cmpldi2_insn): Likewise.
  * config/arm/constraints.md: Remove De, Df, Dg constraints.
  * config/arm/iwmmxt.md (iwmmxt_iordi3): Remove general register
  alternative.
  (iwmmxt_xordi3): Likewise.
  (iwmmxt_anddi3): Likewise.
  * config/arm/neon.md (orndi3_neon): Remove pattern.
  (anddi_notdi_di): Likewise.
  * config/arm/predicates.md (arm_anddi_operand_neon): Remove.
  (arm_iordi_operand_neon): Likewise.
  (arm_xordi_operand_neon): Likewise.
  * config/arm/thumb2.md(iordi_notdi_di): Remove pattern.
  (iordi_notzesidi_di): Likewise.
  (iordi_notdi_zesidi): Likewise.
  (iordi_notsesidi_di): Likewise.
  
  
  ---
  diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
  index 
8f4a4c26ea849a023f2e63d2efbf327423512dfc..cab59c403b777c37c1e412ab9a69db2c2ec533a2
 100644
  --- a/gcc/config/arm/arm.md
  +++ b/gcc/config/arm/arm.md
  @@ -2183,19 +2183,16 @@ (define_expand "divdf3"
     "TARGET_32BIT && TARGET_HARD_FLOAT && TARGET_VFP_DOUBLE"
     "")
    
  -;; Boolean and,ior,xor insns
   
  -;; Split up double word logical operations
  -
  -;; Split up simple DImode logical operations.  Simply perform the logical
  +;; Split DImode and, ior, xor operations.  Simply perform the logical
   ;; operation on the upper and lower halves of the registers.
  +;; This is needed for atomic operations in arm_split_atomic_op.
   (define_split
     [(set (match_operand:DI 0 "s_register_operand" "")
   (match_operator:DI 6 "logical_binary_operator"
     [(match_operand:DI 1 "s_register_operand" "")
  (match_operand:DI 2 "s_register_operand" "")]))]
     "TARGET_32BIT && reload_completed
  -   && ! (TARGET_NEON && IS_VFP_REGNUM (REGNO (operands[0])))
  && ! IS_IWMMXT_REGNUM (REGNO (operands[0]))"
     [(set (match_dup 0) (match_op_dup:SI 6 [(match_dup 1) (match_dup 2)]))
  (set (match_dup 3) (match_op_dup:SI 6 [(match_dup 4) (match_dup 5)]))]
  @@ -2210,167 +2207,20 @@ (define_split
     }"
   )
   
  +;; Split DImode not (needed for atomic operations in arm_split_atomic_op).
   (define_split
  -  [(set (match_operand:DI 0 "s_register_operand" "")
  -   (match_operator:DI 6 "logical_binary_operator"
  - [(sign_extend:DI (match_operand:SI 2 "s_register_operand" ""))
  -  (match_operand:DI 1 "s_register_operand" "")]))]
  -  "TARGET_32BIT && reload_completed"
  -  [(set (match_dup 0) (match_op_dup:SI 6 [(match_dup 1) (match_dup 2)]))
  -   (set (match_dup 3) (match_op_dup:SI 6
  -   [(ashiftrt:SI (match_dup 2) (const_int 31))
  -    (match_dup 4)]))]
  -  "
  -  {
  -    operands[3] = gen_highpart (SImode, operands[0]);
  -    operands[0] = gen_lowpart (SImode, operands[0]);
  -    operands[4] = gen_highpart (SImode, operands[1]);
  -    operands[1] = gen_lowpart (SImode, operands[1]);
  -    operands[5] = gen_highpart (SImode, operands[2]);
  -    operands[2] = gen_lowpart (SImode, operands[2]);
  -  }"
  -)
  -
  -;; The zero extend of operand 2 means we can just copy the high part of
  -;; operand1 into operand0.
  -(define_split
  -  [(set (match_operand:DI 0 "s_register_operand" "")
  -   (ior:DI
  - (zero_extend:DI (match_operand:SI 2 "s_register_operand" ""))
  -   

Re: [PATCH][AArch64] Fix symbol offset limit

2019-08-19 Thread Wilco Dijkstra
   
 
ping
    
  
 In aarch64_classify_symbol symbols are allowed full-range offsets on 
relocations. 
  This means the offset can use all of the +/-4GB offset, leaving no offset 
available
  for the symbol itself.  This results in relocation overflow and link-time 
errors
  for simple expressions like _char + 0xff00.
  
  To avoid this, limit the offset to +/-1MB so that the symbol needs to be 
within a
  3.9GB offset from its references.  For the tiny code model use a 64KB offset, 
allowing
  most of the 1MB range for code/data between the symbol and its references.
  
  Bootstrapped on AArch64, passes regress, OK for commit?
  
  ChangeLog:
  2018-11-09  Wilco Dijkstra  
  
  gcc/
  * config/aarch64/aarch64.c (aarch64_classify_symbol):
  Apply reasonable limit to symbol offsets.
  
  testsuite/
  * gcc.target/aarch64/symbol-range.c (foo): Set new limit.
  * gcc.target/aarch64/symbol-range-tiny.c (foo): Likewise.
  
  --
  
  diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
  index 
83453d03095018eddd1801e71ef3836849267444..0023cb37bbae5afe9387840c1bb6b43586d4fac2
 100644
  --- a/gcc/config/aarch64/aarch64.c
  +++ b/gcc/config/aarch64/aarch64.c
  @@ -13047,26 +13047,26 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT 
offset)
    the offset does not cause overflow of the final address.  But
    we have no way of knowing the address of symbol at compile time
    so we can't accurately say if the distance between the PC and
  -    symbol + offset is outside the addressible range of +/-1M in the
  -    TINY code model.  So we rely on images not being greater than
  -    1M and cap the offset at 1M and anything beyond 1M will have to
  -    be loaded using an alternative mechanism.  Furthermore if the
  -    symbol is a weak reference to something that isn't known to
  -    resolve to a symbol in this module, then force to memory.  */
  +    symbol + offset is outside the addressible range of +/-1MB in the
  +    TINY code model.  So we limit the maximum offset to +/-64KB and
  +    assume the offset to the symbol is not larger than +/-(1MB - 
64KB).
  +    Furthermore force to memory if the symbol is a weak reference to
  +    something that doesn't resolve to a symbol in this module.  */
     if ((SYMBOL_REF_WEAK (x)
  && !aarch64_symbol_binds_local_p (x))
  - || !IN_RANGE (offset, -1048575, 1048575))
  + || !IN_RANGE (offset, -0x1, 0x1))
   return SYMBOL_FORCE_TO_MEM;
  +
     return SYMBOL_TINY_ABSOLUTE;
   
   case AARCH64_CMODEL_SMALL:
     /* Same reasoning as the tiny code model, but the offset cap here 
is
  -    4G.  */
  +    1MB, allowing +/-3.9GB for the offset to the symbol.  */
     if ((SYMBOL_REF_WEAK (x)
  && !aarch64_symbol_binds_local_p (x))
  - || !IN_RANGE (offset, HOST_WIDE_INT_C (-4294967263),
  -   HOST_WIDE_INT_C (4294967264)))
  + || !IN_RANGE (offset, -0x10, 0x10))
   return SYMBOL_FORCE_TO_MEM;
  +
     return SYMBOL_SMALL_ABSOLUTE;
   
   case AARCH64_CMODEL_TINY_PIC:
  diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c 
b/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c
  index 
d7e46b059e41f2672b3a1da5506fa8944e752e01..d49ff4dbe5786ef6d343d2b90052c09676dd7fe5
 100644
  --- a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c
  +++ b/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c
  @@ -1,12 +1,12 @@
  -/* { dg-do compile } */
  +/* { dg-do link } */
   /* { dg-options "-O3 -save-temps -mcmodel=tiny" } */
   
  -int fixed_regs[0x0020];
  +char fixed_regs[0x0020];
   
   int
  -foo()
  +main ()
   {
  -  return fixed_regs[0x0008];
  +  return fixed_regs[0x000ff000];
   }
   
   /* { dg-final { scan-assembler-not "adr\tx\[0-9\]+, fixed_regs\\\+" } } */
  diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range.c 
b/gcc/testsuite/gcc.target/aarch64/symbol-range.c
  index 
6574cf4310430b847e77ea56bf8f20ef312d53e4..75c87c12f08004c153efc5192e5cfab566c089db
 100644
  --- a/gcc/testsuite/gcc.target/aarch64/symbol-range.c
  +++ b/gcc/testsuite/gcc.target/aarch64/symbol-range.c
  @@ -1,12 +1,12 @@
  -/* { dg-do compile } */
  +/* { dg-do link } */
   /* { dg-options "-O3 -save-temps -mcmodel=small" } */
   
  -int fixed_regs[0x2ULL];
  +char fixed_regs[0x2ULL];
   
   int
  -foo()
  +main ()
   {
  -  return fixed_regs[0x1ULL];
  +  return fixed_regs[0xf000ULL];
   }
   
   /* { dg-final { scan-assembler-not "adrp\tx\[0-9\]+, fixed_regs\\\+" } } */
  
  

Re: [PATCH][ARM] Switch to default sched pressure algorithm

2019-08-19 Thread Wilco Dijkstra


ping


  
Currently the Arm backend selects the alternative sched pressure algorithm.
 The issue is that this doesn't take register pressure into account, and so
 it causes significant additional spilling on Arm where there are only 14
 allocatable registers.  SPEC2006 shows significant codesize reduction
 with the default pressure algorithm, so switch back to that.  PR77308 shows
 ~800 fewer instructions.
 
 SPECINT2006 is ~0.6% faster on Cortex-A57 together with the other DImode
 patches. Overall SPEC codesize is 1.1% smaller.
 
 Bootstrap & regress OK on arm-none-linux-gnueabihf --with-cpu=cortex-a57
 
 ChangeLog:
 2019-07-29  Wilco Dijkstra  
 
     * config/arm/arm.c (arm_option_override): Don't override sched
     pressure algorithm.
 
 --
 
 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
 index 
81286cadf32f908e045d704128c5e06842e0cc92..628cf02f23fb29392a63d87f561c3ee2fb73a515
 100644
 --- a/gcc/config/arm/arm.c
 +++ b/gcc/config/arm/arm.c
 @@ -3575,11 +3575,6 @@ arm_option_override (void)
    if (use_neon_for_64bits == 1)
   prefer_neon_for_64bits = true;
  
 -  /* Use the alternative scheduling-pressure algorithm by default.  */
 -  maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM, SCHED_PRESSURE_MODEL,
 -    global_options.x_param_values,
 -    global_options_set.x_param_values);
 -
    /* Look through ready list and all of queue for instructions
   relevant for L2 auto-prefetcher.  */
    int param_sched_autopref_queue_depth;
 
 

Re: [PATCH] Add --with-static-standard-libraries to the top level

2019-08-19 Thread Tom Tromey
> "Jonathan" == Jonathan Wakely  writes:

Jonathan> Given that the problem does exist, I think being able to disable the
Jonathan> GCC build flags for non-GCC components in the build tree makes sense.
Jonathan> I'm not sure if Jeff deferring to me means I can approve the patch
Jonathan> (normally I can't approve top-level config stuff) but for whatever
Jonathan> it's worth, I approve the patch.

Thanks.  I understood his message as deferring to your judgment, so I am
going to check it in.

Tom


[13/13] Add a pass_by_reference flag to function_arg_info

2019-08-19 Thread Richard Sandiford
This patch adds a flag that tells targets whether an argument
has been converted to pass-by-reference form.  This replaces
assign_parm_data_one::passed_pointer in function.c.

The flag is set automatically for places that call
apply_pass_by_reference_rules.  Places that apply
pass-by-reference manually need to set it themselves.

(After previous changes, no targets apply pass-by-reference
manually.  They all go through apply_pass_by_reference_rules.)


2019-08-19  Richard Sandiford  

gcc/
* calls.h (function_arg_info): Add a pass_by_reference field,
defaulting to false.
* calls.c (apply_pass_by_reference_rules): Set pass_by_reference
when applying pass-by-reference semantics.
(initialize_argument_information): Likewise.
(emit_library_call_value_1): Likewise.
* function.c (assign_parm_data_one): Remove passed_pointer field.
(assign_parm_find_data_types): Don't set it.
(assign_parm_find_stack_rtl, assign_parm_adjust_stack_rtl)
(assign_parm_setup_reg, assign_parms, gimplify_parameters): Use
arg.pass_by_reference instead of passed_pointer.

Index: gcc/calls.h
===
--- gcc/calls.h 2019-08-19 15:59:09.801778220 +0100
+++ gcc/calls.h 2019-08-19 15:59:21.817691272 +0100
@@ -34,21 +34,25 @@ #define GCC_CALLS_H
 class function_arg_info
 {
 public:
-  function_arg_info () : type (NULL_TREE), mode (VOIDmode), named (false) {}
+  function_arg_info ()
+: type (NULL_TREE), mode (VOIDmode), named (false),
+  pass_by_reference (false)
+  {}
 
   /* Initialize an argument of mode MODE, either before or after promotion.  */
   function_arg_info (machine_mode mode, bool named)
-: type (NULL_TREE), mode (mode), named (named)
+: type (NULL_TREE), mode (mode), named (named), pass_by_reference (false)
   {}
 
   /* Initialize an unpromoted argument of type TYPE.  */
   function_arg_info (tree type, bool named)
-: type (type), mode (TYPE_MODE (type)), named (named)
+: type (type), mode (TYPE_MODE (type)), named (named),
+  pass_by_reference (false)
   {}
 
   /* Initialize an argument with explicit properties.  */
   function_arg_info (tree type, machine_mode mode, bool named)
-: type (type), mode (mode), named (named)
+: type (type), mode (mode), named (named), pass_by_reference (false)
   {}
 
   /* Return true if the gimple-level type is an aggregate.  */
@@ -100,6 +104,10 @@ #define GCC_CALLS_H
  treated as an unnamed variadic argument (i.e. one passed through
  "...").  See also TARGET_STRICT_ARGUMENT_NAMING.  */
   unsigned int named : 1;
+
+  /* True if we have decided to pass the argument by reference, in which case
+ the function_arg_info describes a pointer to the original argument.  */
+  unsigned int pass_by_reference : 1;
 };
 
 extern int flags_from_decl_or_type (const_tree);
Index: gcc/calls.c
===
--- gcc/calls.c 2019-08-19 15:59:18.145717843 +0100
+++ gcc/calls.c 2019-08-19 15:59:21.817691272 +0100
@@ -946,6 +946,7 @@ apply_pass_by_reference_rules (CUMULATIV
 {
   arg.type = build_pointer_type (arg.type);
   arg.mode = TYPE_MODE (arg.type);
+  arg.pass_by_reference = true;
   return true;
 }
   return false;
@@ -2125,6 +2126,7 @@ initialize_argument_information (int num
  "argument must be passed"
  " by copying");
}
+ arg.pass_by_reference = true;
}
 
   unsignedp = TYPE_UNSIGNED (type);
@@ -4957,6 +4959,7 @@ emit_library_call_value_1 (int retval, r
 call_fusage);
 
  arg.mode = Pmode;
+ arg.pass_by_reference = true;
  val = force_operand (XEXP (slot, 0), NULL_RTX);
}
 
Index: gcc/function.c
===
--- gcc/function.c  2019-08-19 15:59:14.297745685 +0100
+++ gcc/function.c  2019-08-19 15:59:21.821691241 +0100
@@ -2271,7 +2271,6 @@ struct assign_parm_data_one
   machine_mode passed_mode;
   struct locate_and_pad_arg_data locate;
   int partial;
-  BOOL_BITFIELD passed_pointer : 1;
 };
 
 /* A subroutine of assign_parms.  Initialize ALL.  */
@@ -2453,7 +2452,6 @@ assign_parm_find_data_types (struct assi
   if (apply_pass_by_reference_rules (>args_so_far_v, data->arg))
 {
   data->nominal_type = data->arg.type;
-  data->passed_pointer = true;
   data->passed_mode = data->nominal_mode = data->arg.mode;
 }
 
@@ -2653,7 +2651,7 @@ assign_parm_find_stack_rtl (tree parm, s
 stack_parm = gen_rtx_PLUS (Pmode, stack_parm, offset_rtx);
   stack_parm = gen_rtx_MEM (data->arg.mode, stack_parm);
 
-  if (!data->passed_pointer)
+  if (!data->arg.pass_by_reference)
 {
   set_mem_attributes (stack_parm, parm, 1);
   /* set_mem_attributes could set 

[12/13] Make calls.c use function_arg_info internally

2019-08-19 Thread Richard Sandiford
This patch makes the two main calls.c argument-processing
routines track the state of the argument in a function_arg_info
instead of using separate mode variables.


2019-08-19  Richard Sandiford  

gcc/
* calls.c (emit_library_call_value_1): Merge arg and orig_arg
into a single function_arg_info, updating its fields when we
apply pass-by-reference and promotion semantics.  Use the
function_arg_info to track the mode rather than keeping it in
a separate local variable.
(initialize_argument_information): Likewise.  Base the final
arg_to_skip on this new function_arg_info rather than creating
a new one from scratch.

Index: gcc/calls.c
===
--- gcc/calls.c 2019-08-19 15:59:09.801778220 +0100
+++ gcc/calls.c 2019-08-19 15:59:18.145717843 +0100
@@ -1982,7 +1982,6 @@ initialize_argument_information (int num
 {
   tree type = TREE_TYPE (args[i].tree_value);
   int unsignedp;
-  machine_mode mode;
 
   /* Replace erroneous argument with constant zero.  */
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
@@ -2010,13 +2009,13 @@ initialize_argument_information (int num
 with those made by function.c.  */
 
   /* See if this argument should be passed by invisible reference.  */
-  function_arg_info orig_arg (type, argpos < n_named_args);
-  if (pass_by_reference (args_so_far_pnt, orig_arg))
+  function_arg_info arg (type, argpos < n_named_args);
+  if (pass_by_reference (args_so_far_pnt, arg))
{
  bool callee_copies;
  tree base = NULL_TREE;
 
- callee_copies = reference_callee_copied (args_so_far_pnt, orig_arg);
+ callee_copies = reference_callee_copied (args_so_far_pnt, arg);
 
  /* If we're compiling a thunk, pass through invisible references
 instead of making a copy.  */
@@ -2129,15 +2128,16 @@ initialize_argument_information (int num
}
 
   unsignedp = TYPE_UNSIGNED (type);
-  mode = promote_function_mode (type, TYPE_MODE (type), ,
-   fndecl ? TREE_TYPE (fndecl) : fntype, 0);
+  arg.type = type;
+  arg.mode
+   = promote_function_mode (type, TYPE_MODE (type), ,
+fndecl ? TREE_TYPE (fndecl) : fntype, 0);
 
   args[i].unsignedp = unsignedp;
-  args[i].mode = mode;
+  args[i].mode = arg.mode;
 
   targetm.calls.warn_parameter_passing_abi (args_so_far, type);
 
-  function_arg_info arg (type, mode, argpos < n_named_args);
   args[i].reg = targetm.calls.function_arg (args_so_far, arg);
 
   if (args[i].reg && CONST_INT_P (args[i].reg))
@@ -2177,7 +2177,7 @@ initialize_argument_information (int num
   if (args[i].reg == 0 || args[i].partial != 0
   || reg_parm_stack_space > 0
   || args[i].pass_on_stack)
-   locate_and_pad_parm (mode, type,
+   locate_and_pad_parm (arg.mode, type,
 #ifdef STACK_PARMS_IN_REG_PARM_AREA
 1,
 #else
@@ -2191,7 +2191,7 @@ initialize_argument_information (int num
/* The argument is passed entirely in registers.  See at which
   end it should be padded.  */
args[i].locate.where_pad =
- BLOCK_REG_PADDING (mode, type,
+ BLOCK_REG_PADDING (arg.mode, type,
 int_size_in_bytes (type) <= UNITS_PER_WORD);
 #endif
 
@@ -2208,9 +2208,8 @@ initialize_argument_information (int num
 promoted_mode used for function_arg above.  However, the
 corresponding handling of incoming arguments in function.c
 does pass the promoted mode.  */
-  function_arg_info arg_to_skip (type, TYPE_MODE (type),
-argpos < n_named_args);
-  targetm.calls.function_arg_advance (args_so_far, arg_to_skip);
+  arg.mode = TYPE_MODE (type);
+  targetm.calls.function_arg_advance (args_so_far, arg);
 
   /* Store argument values for functions decorated with attribute
 alloc_size.  */
@@ -4906,24 +4905,25 @@ emit_library_call_value_1 (int retval, r
   for (unsigned int i = 0; count < nargs; i++, count++)
 {
   rtx val = args[i].first;
-  machine_mode mode = args[i].second;
+  function_arg_info arg (args[i].second, /*named=*/true);
   int unsigned_p = 0;
 
   /* We cannot convert the arg value to the mode the library wants here;
 must do it earlier where we know the signedness of the arg.  */
-  gcc_assert (mode != BLKmode
- && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
+  gcc_assert (arg.mode != BLKmode
+ && (GET_MODE (val) == arg.mode
+ || GET_MODE (val) == VOIDmode));
 
   /* Make sure it is a reasonable operand for a move or push insn.  */
   if (!REG_P (val) && !MEM_P (val)
- && !(CONSTANT_P (val) && targetm.legitimate_constant_p 

[11/13] Make function.c use function_arg_info internally

2019-08-19 Thread Richard Sandiford
This patch adds a function_arg_info field to assign_parm_data_one,
so that:

  - passed_type -> arg.type
  - promoted_mode -> arg.mode
  - named_arg -> arg.named

We can then pass this function_arg_info directly to the converted
hooks.

Between the initialisation of the assign_parm_data_one and the
application of promotion rules (which is a state internal to
assign_parm_find_data_types), arg.mode is equivalent to passed_mode
(i.e. to TYPE_MODE).


2019-08-19  Richard Sandiford  

gcc/
* function.c (assign_parm_data_one): Replace passed_type,
promoted_mode and named_arg with a function_arg_info field.
(assign_parm_find_data_types): Remove local variables and
assign directly to "data".  Make data->passed_mode shadow
data->arg.mode until promotion, then assign the promoted
mode to data->arg.mode.
(assign_parms_setup_varargs, assign_parm_find_entry_rtl)
(assign_parm_find_stack_rtl, assign_parm_adjust_entry_rtl)
(assign_parm_remove_parallels, assign_parm_setup_block_p)
(assign_parm_setup_block, assign_parm_setup_reg)
(assign_parm_setup_stack, assign_parms, gimplify_parameters): Use
arg.mode instead of promoted_mode, arg.type instead of passed_type
and arg.named instead of named_arg.  Use data->arg for
function_arg_info structures that had the field values passed_type,
promoted_mode and named_arg.  Base other function_arg_infos on
data->arg, changing the necessary properties.

Index: gcc/function.c
===
--- gcc/function.c  2019-08-19 15:59:09.809778162 +0100
+++ gcc/function.c  2019-08-19 15:59:14.297745685 +0100
@@ -2264,15 +2264,13 @@ struct assign_parm_data_all
 struct assign_parm_data_one
 {
   tree nominal_type;
-  tree passed_type;
+  function_arg_info arg;
   rtx entry_parm;
   rtx stack_parm;
   machine_mode nominal_mode;
   machine_mode passed_mode;
-  machine_mode promoted_mode;
   struct locate_and_pad_arg_data locate;
   int partial;
-  BOOL_BITFIELD named_arg : 1;
   BOOL_BITFIELD passed_pointer : 1;
 };
 
@@ -2407,24 +2405,22 @@ assign_parms_augmented_arg_list (struct
 assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm,
 struct assign_parm_data_one *data)
 {
-  tree nominal_type, passed_type;
-  machine_mode nominal_mode, passed_mode, promoted_mode;
   int unsignedp;
 
-  memset (data, 0, sizeof (*data));
+  *data = assign_parm_data_one ();
 
   /* NAMED_ARG is a misnomer.  We really mean 'non-variadic'. */
   if (!cfun->stdarg)
-data->named_arg = 1;  /* No variadic parms.  */
+data->arg.named = 1;  /* No variadic parms.  */
   else if (DECL_CHAIN (parm))
-data->named_arg = 1;  /* Not the last non-variadic parm. */
+data->arg.named = 1;  /* Not the last non-variadic parm. */
   else if (targetm.calls.strict_argument_naming (all->args_so_far))
-data->named_arg = 1;  /* Only variadic ones are unnamed.  */
+data->arg.named = 1;  /* Only variadic ones are unnamed.  */
   else
-data->named_arg = 0;  /* Treat as variadic.  */
+data->arg.named = 0;  /* Treat as variadic.  */
 
-  nominal_type = TREE_TYPE (parm);
-  passed_type = DECL_ARG_TYPE (parm);
+  data->nominal_type = TREE_TYPE (parm);
+  data->arg.type = DECL_ARG_TYPE (parm);
 
   /* Look out for errors propagating this far.  Also, if the parameter's
  type is void then its value doesn't matter.  */
@@ -2432,49 +2428,40 @@ assign_parm_find_data_types (struct assi
   /* This can happen after weird syntax errors
 or if an enum type is defined among the parms.  */
   || TREE_CODE (parm) != PARM_DECL
-  || passed_type == NULL
-  || VOID_TYPE_P (nominal_type))
+  || data->arg.type == NULL
+  || VOID_TYPE_P (data->nominal_type))
 {
-  nominal_type = passed_type = void_type_node;
-  nominal_mode = passed_mode = promoted_mode = VOIDmode;
-  goto egress;
+  data->nominal_type = data->arg.type = void_type_node;
+  data->nominal_mode = data->passed_mode = data->arg.mode = VOIDmode;
+  return;
 }
 
   /* Find mode of arg as it is passed, and mode of arg as it should be
  during execution of this function.  */
-  passed_mode = TYPE_MODE (passed_type);
-  nominal_mode = TYPE_MODE (nominal_type);
+  data->passed_mode = data->arg.mode = TYPE_MODE (data->arg.type);
+  data->nominal_mode = TYPE_MODE (data->nominal_type);
 
   /* If the parm is to be passed as a transparent union or record, use the
  type of the first field for the tests below.  We have already verified
  that the modes are the same.  */
-  if ((TREE_CODE (passed_type) == UNION_TYPE
-   || TREE_CODE (passed_type) == RECORD_TYPE)
-  && TYPE_TRANSPARENT_AGGR (passed_type))
-passed_type = TREE_TYPE (first_field (passed_type));
+  if ((TREE_CODE (data->arg.type) == UNION_TYPE
+   || TREE_CODE (data->arg.type) == RECORD_TYPE)
+  

[10/13] Add a apply_pass_by_reference_rules helper

2019-08-19 Thread Richard Sandiford
This patch adds a helper routine that applies pass-by-reference
semantics to an existing function_arg_info.

The c6x part means that c6x_function_arg and c6x_function_arg_advance
see the same "named" value as pass_by_reference did, rather than
pass_by_reference seeing "true" and the others seeing "false".
This doesn't matter because the c6x port doesn't care about namedness.

The rs6000.c patch removes an assignment to "type", but the only
later code to use it was the patched promote_mode line.

(The reason for patching these places despite the above is that
often target code gets used as a basis for new targets or changes
to existing ones.)


2019-08-19  Richard Sandiford  

gcc/
* calls.h (apply_pass_by_reference_rules): Declare.
* calls.c (apply_pass_by_reference_rules): New function.
* config/c6x/c6x.c (c6x_call_saved_register_used): Use it.
* config/rs6000/rs6000-call.c (rs6000_parm_needs_stack): Likewise.
* config/s390/s390.c (s390_call_saved_register_used): Likewise.
* function.c (assign_parm_find_data_types): Likewise.
* var-tracking.c (prepare_call_arguments): Likewise.

Index: gcc/calls.h
===
--- gcc/calls.h 2019-08-19 15:59:04.261818304 +0100
+++ gcc/calls.h 2019-08-19 15:59:09.801778220 +0100
@@ -118,6 +118,8 @@ extern void fixup_tail_calls (void);
 
 extern bool pass_by_reference (CUMULATIVE_ARGS *, function_arg_info);
 extern bool pass_va_arg_by_reference (tree);
+extern bool apply_pass_by_reference_rules (CUMULATIVE_ARGS *,
+  function_arg_info &);
 extern bool reference_callee_copied (CUMULATIVE_ARGS *,
 const function_arg_info &);
 extern void maybe_warn_alloc_args_overflow (tree, tree, tree[2], int[2]);
Index: gcc/calls.c
===
--- gcc/calls.c 2019-08-19 15:59:04.261818304 +0100
+++ gcc/calls.c 2019-08-19 15:59:09.801778220 +0100
@@ -935,6 +935,22 @@ pass_va_arg_by_reference (tree type)
   return pass_by_reference (NULL, function_arg_info (type, /*named=*/false));
 }
 
+/* Decide whether ARG, which occurs in the state described by CA,
+   should be passed by reference.  Return true if so and update
+   ARG accordingly.  */
+
+bool
+apply_pass_by_reference_rules (CUMULATIVE_ARGS *ca, function_arg_info )
+{
+  if (pass_by_reference (ca, arg))
+{
+  arg.type = build_pointer_type (arg.type);
+  arg.mode = TYPE_MODE (arg.type);
+  return true;
+}
+  return false;
+}
+
 /* Return true if ARG, which is passed by reference, should be callee
copied instead of caller copied.  */
 
Index: gcc/config/c6x/c6x.c
===
--- gcc/config/c6x/c6x.c2019-08-19 15:58:58.001863604 +0100
+++ gcc/config/c6x/c6x.c2019-08-19 15:59:09.805778189 +0100
@@ -1088,8 +1088,6 @@ c6x_call_saved_register_used (tree call_
   cumulative_args_t cum;
   HARD_REG_SET call_saved_regset;
   tree parameter;
-  machine_mode mode;
-  tree type;
   rtx parm_rtx;
   int i;
 
@@ -1107,19 +1105,9 @@ c6x_call_saved_register_used (tree call_
   if (TREE_CODE (parameter) == ERROR_MARK)
return true;
 
-  type = TREE_TYPE (parameter);
-  gcc_assert (type);
+  function_arg_info arg (TREE_TYPE (parameter), /*named=*/true);
+  apply_pass_by_reference_rules (_v, arg);
 
-  mode = TYPE_MODE (type);
-  gcc_assert (mode);
-
-  if (pass_by_reference (_v, function_arg_info (type, /*named=*/true)))
-   {
- mode = Pmode;
- type = build_pointer_type (type);
-   }
-
-   function_arg_info arg (type, mode, /*named=*/false);
parm_rtx = c6x_function_arg (cum, arg);
 
c6x_function_arg_advance (cum, arg);
Index: gcc/config/rs6000/rs6000-call.c
===
--- gcc/config/rs6000/rs6000-call.c 2019-08-19 15:59:04.285818131 +0100
+++ gcc/config/rs6000/rs6000-call.c 2019-08-19 15:59:09.805778189 +0100
@@ -2170,7 +2170,6 @@ rs6000_pass_by_reference (cumulative_arg
 static bool
 rs6000_parm_needs_stack (cumulative_args_t args_so_far, tree type)
 {
-  machine_mode mode;
   int unsignedp;
   rtx entry_parm;
 
@@ -2193,16 +2192,14 @@ rs6000_parm_needs_stack (cumulative_args
 type = TREE_TYPE (first_field (type));
 
   /* See if this arg was passed by invisible reference.  */
-  if (pass_by_reference (get_cumulative_args (args_so_far),
-function_arg_info (type, /*named=*/true)))
-type = build_pointer_type (type);
+  function_arg_info arg (type, /*named=*/true);
+  apply_pass_by_reference_rules (get_cumulative_args (args_so_far), arg);
 
   /* Find mode as it is passed by the ABI.  */
   unsignedp = TYPE_UNSIGNED (type);
-  mode = promote_mode (type, TYPE_MODE (type), );
+  arg.mode = promote_mode (arg.type, arg.mode, );
 
   /* If we must pass 

[09/13] Use function_arg_info for TARGET_MUST_PASS_IN_STACK

2019-08-19 Thread Richard Sandiford
Use function_arg_info for TARGET_MUST_PASS_IN_STACK.

The hook is passed the promoted mode instead of the original type mode.

The expr.h reference in the documentation is no longer correct, but
pointing to calls.h or calls.c doesn't help much either.  I just left
this as-is since it's not related to the point of the series.

After previous changes, most places already pass arg.mode and arg.type.
Only i386 and mcore needed to construct a new one out of nothing.
rs6000 needs to construct one slightly earlier than before.


2019-08-19  Richard Sandiford  

gcc/
* target.def (must_pass_in_stack): Take a function_arg_info instead
of a mode and a type.
* doc/tm.texi: Regenerate.
* calls.h (must_pass_in_stack_var_size): Take a function_arg_info
instead of a mode and a type.
(must_pass_in_stack_var_size_or_pad): Likewise.
* calls.c (must_pass_in_stack_var_size): Likewise.
(must_pass_in_stack_var_size_or_pad): Likewise.
(initialize_argument_information): Update call to
targetm.calls.must_pass_in_stack.
(must_pass_va_arg_on_stack): Likewise.
* function.c (assign_parm_find_entry_rtl): Likewise.
* targhooks.c (hook_pass_by_reference_must_pass_in_stack): Likewise.
* config/alpha/alpha.c (alpha_function_arg): Likewise.
(alpha_function_arg_advance): Likewise.
* config/cr16/cr16.c (cr16_function_arg): Likewise.
(cr16_function_arg_advance): Likewise.
* config/cris/cris.c (cris_pass_by_reference): Likewise.
(cris_arg_partial_bytes): Likewise.
* config/iq2000/iq2000.c (iq2000_pass_by_reference): Likewise.
* config/lm32/lm32.c (lm32_function_arg): Likewise.
* config/mcore/mcore.c (mcore_num_arg_regs): Likewise.
(mcore_function_arg, mcore_arg_partial_bytes): Likewise.
* config/mips/mips.c (mips_pass_by_reference): Likewise.
* config/mmix/mmix.c (mmix_function_arg_advance): Likewise.
(mmix_function_arg_1, mmix_pass_by_reference): Likewise.
* config/sh/sh.c (sh_pass_by_reference): Likewise.
* config/stormy16/stormy16.c (xstormy16_function_arg): Likewise.
* config/xtensa/xtensa.c (xtensa_function_arg_advance): Likewise.
* config/arm/arm.c (arm_must_pass_in_stack): Take a function_arg_info
instead of a mode and a type.
* config/fr30/fr30.c (fr30_must_pass_in_stack): Likewise.
(fr30_num_arg_regs): Likewise.
(fr30_setup_incoming_varargs): Update calls accordingly.
(fr30_arg_partial_bytes, fr30_function_arg): Likewise.
(fr30_function_arg_advance): Likewise.
* config/frv/frv.c (frv_must_pass_in_stack): Take a function_arg_info
instead of a mode and a type.
* config/gcn/gcn.c (num_arg_regs): Likewise.
(gcn_function_arg, gcn_function_arg_advance): Update calls to
num_arg_regs and targetm.calls.must_pass_in_stack.
(gcn_arg_partial_bytes): Likewise.
* config/i386/i386.c (ix86_must_pass_in_stack): Take a
function_arg_info instead of a mode and a type.
(classify_argument): Update call accordingly.
* config/nds32/nds32.c (nds32_must_pass_in_stack): Take a
function_arg_info instead of a mode and a type.
* config/rs6000/rs6000-internal.h (rs6000_must_pass_in_stack):
Likewise.
* config/rs6000/rs6000-call.c (rs6000_must_pass_in_stack): Likewise.
(rs6000_parm_needs_stack): Update call accordingly.
(setup_incoming_varargs): Likewise.

Index: gcc/target.def
===
--- gcc/target.def  2019-08-19 15:58:58.017863486 +0100
+++ gcc/target.def  2019-08-19 15:59:04.289818104 +0100
@@ -4630,11 +4630,11 @@ false.",
Need audit to verify that this is the case.  */
 DEFHOOK
 (must_pass_in_stack,
- "This target hook should return @code{true} if we should not pass 
@var{type}\n\
+ "This target hook should return @code{true} if we should not pass @var{arg}\n\
 solely in registers.  The file @file{expr.h} defines a\n\
 definition that is usually appropriate, refer to @file{expr.h} for 
additional\n\
 documentation.",
- bool, (machine_mode mode, const_tree type),
+ bool, (const function_arg_info ),
  must_pass_in_stack_var_size_or_pad)
 
 /* Return true if type TYPE, mode MODE, which is passed by reference,
Index: gcc/doc/tm.texi
===
--- gcc/doc/tm.texi 2019-08-19 15:58:58.013863514 +0100
+++ gcc/doc/tm.texi 2019-08-19 15:59:04.289818104 +0100
@@ -4012,8 +4012,8 @@ defined, the argument will be computed i
 a register.
 @end deftypefn
 
-@deftypefn {Target Hook} bool TARGET_MUST_PASS_IN_STACK (machine_mode 
@var{mode}, const_tree @var{type})
-This target hook should return @code{true} if we should not pass @var{type}
+@deftypefn {Target Hook} bool TARGET_MUST_PASS_IN_STACK (const 
function_arg_info @var{})
+This 

[08/13] Use function_arg_info for TARGET_CALLEE_COPIES

2019-08-19 Thread Richard Sandiford
Use function_arg_info for TARGET_CALLEE_COPIES.

The hook is passed the unpromoted type mode instead of the promoted mode.

The aarch64 definition is redundant, but worth keeping for emphasis.


2019-08-19  Richard Sandiford  

gcc/
* target.def (callee_copies): Take a function_arg_info instead
of a mode, type and named flag.
* doc/tm.texi: Regenerate.
* targhooks.h (hook_callee_copies_named): Take a function_arg_info
instead of a mode, type and named flag.
(hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false): Delete.
(hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true): Likewise.
(hook_bool_CUMULATIVE_ARGS_arg_info_true): New function.
* targhooks.c (hook_callee_copies_named): Take a function_arg_info
instead of a mode, type and named flag.
(hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false): Delete.
(hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true): Likewise.
(hook_bool_CUMULATIVE_ARGS_arg_info_true): New function.
* calls.h (reference_callee_copied): Take a function_arg_info
instead of a mode, type and named flag.
* calls.c (reference_callee_copied): Likewise.
(initialize_argument_information): Update call accordingly.
(emit_library_call_value_1): Likewise.
* function.c (gimplify_parameters): Likewise.
* config/aarch64/aarch64.c (TARGET_CALLEE_COPIES): Define to
hook_bool_CUMULATIVE_ARGS_arg_info_false instead of
hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false.
* config/c6x/c6x.c (c6x_callee_copies): Delete.
(TARGET_CALLEE_COPIES): Define to
hook_bool_CUMULATIVE_ARGS_arg_info_true instead.
* config/epiphany/epiphany.c (TARGET_CALLEE_COPIES): Define to
hook_bool_CUMULATIVE_ARGS_arg_info_true instead of
hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true.
* config/mips/mips.c (mips_callee_copies): Take a function_arg_info
instead of a mode, type and named flag.
* config/mmix/mmix.c (TARGET_CALLEE_COPIES): Define to
hook_bool_CUMULATIVE_ARGS_arg_info_true instead of
hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true.
* config/mn10300/mn10300.c (TARGET_CALLEE_COPIES): Likewise.
* config/msp430/msp430.c (msp430_callee_copies): Delete.
(TARGET_CALLEE_COPIES): Define to
hook_bool_CUMULATIVE_ARGS_arg_info_true instead.
* config/pa/pa.c (pa_callee_copies): Take a function_arg_info
instead of a mode, type and named flag.
* config/sh/sh.c (sh_callee_copies): Likewise.
* config/v850/v850.c (TARGET_CALLEE_COPIES): Define to
hook_bool_CUMULATIVE_ARGS_arg_info_true instead of
hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true.

Index: gcc/target.def
===
--- gcc/target.def  2019-08-19 15:58:50.345918999 +0100
+++ gcc/target.def  2019-08-19 15:58:58.017863486 +0100
@@ -4653,8 +4653,8 @@ not be generated.\n\
 \n\
 The default version of this hook always returns false.",
  bool,
- (cumulative_args_t cum, machine_mode mode, const_tree type, bool named),
- hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false)
+ (cumulative_args_t cum, const function_arg_info ),
+ hook_bool_CUMULATIVE_ARGS_arg_info_false)
 
 /* Return zero for arguments passed entirely on the stack or entirely
in registers.  If passed in both, return the number of bytes passed
Index: gcc/doc/tm.texi
===
--- gcc/doc/tm.texi 2019-08-19 15:58:50.341919030 +0100
+++ gcc/doc/tm.texi 2019-08-19 15:58:58.013863514 +0100
@@ -4080,7 +4080,7 @@ The pointer is passed in whatever way is
 to that type.
 @end deftypefn
 
-@deftypefn {Target Hook} bool TARGET_CALLEE_COPIES (cumulative_args_t 
@var{cum}, machine_mode @var{mode}, const_tree @var{type}, bool @var{named})
+@deftypefn {Target Hook} bool TARGET_CALLEE_COPIES (cumulative_args_t 
@var{cum}, const function_arg_info @var{})
 The function argument described by the parameters to this hook is
 known to be passed by reference.  The hook should return true if the
 function argument should be copied by the callee instead of copied
Index: gcc/targhooks.h
===
--- gcc/targhooks.h 2019-08-19 15:58:50.345918999 +0100
+++ gcc/targhooks.h 2019-08-19 15:58:58.017863486 +0100
@@ -67,7 +67,7 @@ extern tree default_cxx_get_cookie_size
 extern bool hook_pass_by_reference_must_pass_in_stack
   (cumulative_args_t, const function_arg_info &);
 extern bool hook_callee_copies_named
-  (cumulative_args_t ca, machine_mode, const_tree, bool);
+  (cumulative_args_t ca, const function_arg_info &);
 
 extern void default_print_operand (FILE *, rtx, int);
 extern void default_print_operand_address (FILE *, machine_mode, rtx);
@@ -135,12 +135,10 @@ extern void default_goacc_reduction (gca
 extern bool 

[07/13] Use function_arg_info for TARGET_FUNCTION_ARG_ADVANCE

2019-08-19 Thread Richard Sandiford
Use function_arg_info for TARGET_FUNCTION_ARG_ADVANCE.

There seems to be a bit of confusion around this one.  Almost all
callers pass the same arguments as TARGET_FUNCTION_ARG, meaning
that the mode is the promoted mode rather than the type mode.
But the calls.c handling for normal typed arguments instead passes
the unpromoted TYPE_MODE (despite passing the promoted mode to
TARGET_FUNCTION_ARG).  I've kept this behaviour with a ??? comment.

(The calls.c handling of libgcc functions does pass the promoted
mode though, as does the function.c handling of incoming arguments.)

Also, a couple of the arm callers don't seem to be using the hook
correctly.  Again I kept the current choices and added a ??? comment.


2019-08-19  Richard Sandiford  

gcc/
* target.def (function_arg_advance): Take a function_arg_info instead
of a mode, type and named flag.
* doc/tm.texi: Regenerate.
* targhooks.h (default_function_arg_advance): Take a function_arg_info
instead of a mode, type and named flag.
* targhooks.c (default_function_arg_advance): Likewise.
* calls.c (initialize_argument_information): Update call to
targetm.calls.function_arg_advance.
(emit_library_call_value_1): Likewise.
* dse.c (get_call_args): Likewise.
* expr.c (block_move_libcall_safe_for_call_parm): Likewise.
* function.c (assign_parms, gimplify_parameters): Likewise.
* var-tracking.c (prepare_call_arguments): Likewise.
* config/aarch64/aarch64.c (aarch64_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(aarch64_setup_incoming_varargs): Update call accordingly.
* config/alpha/alpha.c (alpha_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(alpha_setup_incoming_varargs): Update call accordingly.
* config/arc/arc.c (arc_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(arc_setup_incoming_varargs): Update call accordingly.
* config/arm/arm.c (arm_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(cmse_func_args_or_return_in_stack): Update call accordingly.
(arm_function_ok_for_sibcall): Likewise.
(cmse_nonsecure_call_clear_caller_saved): Likewise.
* config/avr/avr.c (avr_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
* config/bfin/bfin.c (bfin_function_arg_advance): Likewise.
* config/c6x/c6x.c (c6x_function_arg_advance): Likewise.
(c6x_call_saved_register_used): Update call accordingly.
* config/cr16/cr16.c (cr16_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
* config/cris/cris.c (cris_function_arg_advance): Likewise.
* config/csky/csky.c (csky_function_arg_advance): Likewise.
(csky_setup_incoming_varargs): Update call accordingly.
* config/epiphany/epiphany.c (epiphany_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
* config/fr30/fr30.c (fr30_function_arg_advance): Likewise.
* config/frv/frv.c (frv_function_arg_advance): Likewise.
* config/ft32/ft32.c (ft32_function_arg_advance): Likewise.
* config/gcn/gcn.c (gcn_function_arg_advance): Likewise.
* config/h8300/h8300.c (h8300_function_arg_advance): Likewise.
* config/i386/i386.c (ix86_function_arg_advance): Likewise.
(ix86_setup_incoming_varargs): Update call accordingly.
* config/ia64/ia64.c (ia64_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(ia64_setup_incoming_varargs): Update call accordingly.
* config/iq2000/iq2000.c (iq2000_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(iq2000_expand_prologue): Update call accordingly.
* config/lm32/lm32.c (lm32_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
* config/m32c/m32c.c (m32c_function_arg_advance): Likewise.
* config/m32r/m32r.c (m32r_function_arg_advance): Likewise.
* config/m68k/m68k.c (m68k_function_arg_advance): Likewise.
* config/mcore/mcore.c (mcore_function_arg_advance): Likewise.
* config/microblaze/microblaze.c (microblaze_function_arg_advance):
Likewise.
(microblaze_expand_prologue): Update call accordingly.
* config/mips/mips.c (mips_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
(mips_setup_incoming_varargs): Update call accordingly.
(mips_output_args_xfer): Likewise.
* config/mmix/mmix.c (mmix_function_arg_advance): Take a
function_arg_info instead of a mode, type and named flag.
  

[06/13] Use function_arg_info for TARGET_FUNCTION_(INCOMING_)ARG

2019-08-19 Thread Richard Sandiford
This patch makes both TARGET_FUNCTION_ARG and
TARGET_FUNCTION_INCOMING_ARG take a function_arg_info.
They have to be done together since many targets use the
same function for both.

The hooks are passed the promoted mode instead of the original type mode.


2019-08-19  Richard Sandiford  

gcc/
* target.def (function_arg, function_incoming_arg): Take a
function_arg_info instead of a mode, tree and named flag.
* doc/tm.texi: Regenerate.
* targhooks.h (default_function_arg): Take a function_arg_info
instead of a mode, tree and named flag.
(default_function_incoming_arg): Likewise.
* targhooks.c (default_function_arg): Likewise.
(default_function_incoming_arg): Likewise.
* calls.h (function_arg_info::end_marker_p): New function.
(function_arg_info::end_marker): Likewise.
* calls.c (prepare_call_address, initialize_argument_information)
(expand_call, emit_library_call_value_1): Update calls to
targetm.calls.function_arg and targetm.calls.function_incoming_arg.
* dse.c: Include calls.h.
(get_call_args): Update call to targetm.calls.function_arg.
* expr.c (block_move_libcall_safe_for_call_parm): Likewise.
* var-tracking.c (prepare_call_arguments): Likewise.
* function.c (assign_parm_find_entry_rtl): Update call to
targetm.calls.function_incoming_arg.
* config/aarch64/aarch64.c (aarch64_function_arg): Take a
function_arg_info instead of a mode, tree and named flag.
* config/alpha/alpha.c (alpha_function_arg): Likewise.
* config/arc/arc.c (arc_function_arg): Likewise.
* config/arm/arm.c (arm_function_arg): Likewise.
(cmse_func_args_or_return_in_stack): Update call accordingly.
(arm_function_ok_for_sibcall): Likewise.
(cmse_nonsecure_call_clear_caller_saved): Likewise.
* config/avr/avr.c (avr_function_arg): Take a function_arg_info
instead of a mode, tree and named flag.
* config/bfin/bfin.c (bfin_function_arg): Likewise.
* config/c6x/c6x.c (c6x_function_arg): Likewise.
(c6x_call_saved_register_used): Update call accordingly.
* config/cr16/cr16.c (cr16_function_arg): Take a function_arg_info
instead of a mode, tree and named flag.
* config/cris/cris.c (cris_function_arg, cris_function_incoming_arg)
(cris_function_arg_1): Likewise.
* config/csky/csky.c (csky_function_arg): Likewise.
* config/epiphany/epiphany.c (epiphany_function_arg): Likewise.
* config/fr30/fr30.c (fr30_function_arg): Likewise.
* config/frv/frv.c (frv_function_arg, frv_function_incoming_arg)
(frv_function_arg_1): Likewise.
* config/ft32/ft32.c (ft32_function_arg): Likewise.
* config/gcn/gcn.c (gcn_function_arg): Likewise.
* config/h8300/h8300.c (h8300_function_arg): Likewise.
* config/i386/i386.c (ix86_function_arg): Likewise.
* config/ia64/ia64.c (ia64_function_arg, ia64_function_incoming_arg)
(ia64_function_arg_1): Likewise.
* config/iq2000/iq2000.c (iq2000_function_arg): Likewise.
(iq2000_expand_prologue, iq2000_pass_by_reference): Update call
accordingly.
* config/lm32/lm32.c (lm32_function_arg): Take a function_arg_info
instead of a mode, tree and named flag.
* config/m32c/m32c.c (m32c_function_arg): Likewise.
* config/m32r/m32r.c (m32r_function_arg): Likewise.
* config/m68k/m68k.c (m68k_function_arg): Likewise.
* config/mcore/mcore.c (mcore_function_arg): Likewise.
* config/microblaze/microblaze.c (microblaze_function_arg): Likewise.
(microblaze_expand_prologue): Update call accordingly.
* config/mips/mips.c (mips_function_arg): Take a function_arg_info
instead of a mode, tree and named flag.
* config/mmix/mmix.c (mmix_function_incoming_arg, mmix_function_arg)
(mmix_function_arg_1): Likewise.
* config/mn10300/mn10300.c (mn10300_function_arg): Likewise.
* config/moxie/moxie.c (moxie_function_arg): Likewise.
* config/msp430/msp430.c (msp430_function_arg): Likewise.
* config/nds32/nds32.c (nds32_function_arg): Likewise.
* config/nios2/nios2.c (nios2_function_arg): Likewise.
* config/nvptx/nvptx.c (nvptx_function_arg): Likewise.
(nvptx_function_incoming_arg): Likewise.
* config/or1k/or1k.c (or1k_function_arg): Likewise.
* config/pa/pa.c (pa_function_arg): Likewise.
* config/pdp11/pdp11.c (pdp11_function_arg): Likewise.
* config/pru/pru.c (pru_function_arg): Likewise.
* config/riscv/riscv.c (riscv_function_arg): Likewise.
* config/rl78/rl78.c (rl78_function_arg): Likewise.
* config/rs6000/rs6000-internal.h (rs6000_function_arg): Likewise.
* config/rs6000/rs6000-call.c (rs6000_function_arg): Likewise.
(rs6000_parm_needs_stack): 

[05/13] Use function_arg_info for TARGET_SETUP_INCOMING_ARGS

2019-08-19 Thread Richard Sandiford
Use function_arg_info for TARGET_SETUP_INCOMING_ARGS.

The hook is passed the promoted mode instead of the original type mode.


2019-08-19  Richard Sandiford  

gcc/
* target.def (setup_incoming_varargs): Take a function_arg_info
instead of a mode and tree.
* doc/tm.texi: Regenerate.
* targhooks.h (default_setup_incoming_varargs): Take a
function_arg_info instead of a mode and tree.
* targhooks.c (default_setup_incoming_varargs): Likewise.
* config/aarch64/aarch64.c (aarch64_setup_incoming_varargs): Likewise.
* config/alpha/alpha.c (alpha_setup_incoming_varargs): Likewise.
* config/arc/arc.c (arc_setup_incoming_varargs): Likewise.
* config/arm/arm.c (arm_setup_incoming_varargs): Likewise.
* config/bfin/bfin.c (setup_incoming_varargs): Likewise.
* config/cris/cris.c (cris_setup_incoming_varargs): Likewise.
* config/csky/csky.c (csky_setup_incoming_varargs): Likewise.
* config/epiphany/epiphany.c (epiphany_setup_incoming_varargs):
Likewise.
* config/fr30/fr30.c (fr30_setup_incoming_varargs): Likewise.
* config/frv/frv.c (frv_setup_incoming_varargs): Likewise.
* config/ft32/ft32.c (ft32_setup_incoming_varargs): Likewise.
* config/i386/i386.c (ix86_setup_incoming_varargs): Likewise.
* config/ia64/ia64.c (ia64_setup_incoming_varargs): Likewise.
* config/iq2000/iq2000.c (iq2000_setup_incoming_varargs): Likewise.
* config/lm32/lm32.c (lm32_setup_incoming_varargs): Likewise.
* config/m32r/m32r.c (m32r_setup_incoming_varargs): Likewise.
* config/mcore/mcore.c (mcore_setup_incoming_varargs): Likewise.
* config/mips/mips.c (mips_setup_incoming_varargs): Likewise.
* config/mmix/mmix.c (mmix_setup_incoming_varargs): Likewise.
* config/moxie/moxie.c (moxie_setup_incoming_varargs): Likewise.
* config/nds32/nds32.c (nds32_setup_incoming_varargs): Likewise.
* config/nios2/nios2.c (nios2_setup_incoming_varargs): Likewise.
* config/riscv/riscv.c (riscv_setup_incoming_varargs): Likewise.
* config/rs6000/rs6000-internal.h (setup_incoming_varargs): Likewise.
* config/rs6000/rs6000-call.c (setup_incoming_varargs): Likewise.
* config/sh/sh.c (sh_setup_incoming_varargs): Likewise.
* config/spu/spu.c (spu_setup_incoming_varargs): Likewise.
* config/tilegx/tilegx.c (tilegx_setup_incoming_varargs): Likewise.
* config/tilepro/tilepro.c (tilepro_setup_incoming_varargs): Likewise.
* config/visium/visium.c (visium_setup_incoming_varargs): Likewise.
* function.c (assign_parms_setup_varargs): Update call to
targetm.calls.setup_incoming_varargs.

Index: gcc/target.def
===
--- gcc/target.def  2019-08-19 15:58:28.450077433 +0100
+++ gcc/target.def  2019-08-19 15:58:34.850031127 +0100
@@ -4486,8 +4486,8 @@ pass all their arguments on the stack.\n
 \n\
 The argument @var{args_so_far} points to the @code{CUMULATIVE_ARGS} data\n\
 structure, containing the values that are obtained after processing the\n\
-named arguments.  The arguments @var{mode} and @var{type} describe the\n\
-last named argument---its machine mode and its data type as a tree node.\n\
+named arguments.  The argument @var{arg} describes the last of these named\n\
+arguments.\n\
 \n\
 The target hook should do two things: first, push onto the stack all the\n\
 argument registers @emph{not} used for the named arguments, and second,\n\
@@ -4507,7 +4507,7 @@ arguments of the function are being anal
 happens for an inline function, which is not actually compiled until the\n\
 end of the source file.  The hook @code{TARGET_SETUP_INCOMING_VARARGS} 
should\n\
 not generate any instructions in this case.",
- void, (cumulative_args_t args_so_far, machine_mode mode, tree type,
+ void, (cumulative_args_t args_so_far, const function_arg_info ,
int *pretend_args_size, int second_time),
  default_setup_incoming_varargs)
 
Index: gcc/doc/tm.texi
===
--- gcc/doc/tm.texi 2019-08-19 15:58:28.450077433 +0100
+++ gcc/doc/tm.texi 2019-08-19 15:58:34.850031127 +0100
@@ -5202,7 +5202,7 @@ return value of this function should be
 to use as the return of @code{__builtin_saveregs}.
 @end deftypefn
 
-@deftypefn {Target Hook} void TARGET_SETUP_INCOMING_VARARGS (cumulative_args_t 
@var{args_so_far}, machine_mode @var{mode}, tree @var{type}, int 
*@var{pretend_args_size}, int @var{second_time})
+@deftypefn {Target Hook} void TARGET_SETUP_INCOMING_VARARGS (cumulative_args_t 
@var{args_so_far}, const function_arg_info @var{}, int 
*@var{pretend_args_size}, int @var{second_time})
 This target hook offers an alternative to using
 @code{__builtin_saveregs} and defining the hook
 @code{TARGET_EXPAND_BUILTIN_SAVEREGS}.  Use it to store the anonymous
@@ 

[04/13] Use function_arg_info for TARGET_PASS_BY_REFERENCE

2019-08-19 Thread Richard Sandiford
Use function_arg_info for TARGET_PASS_BY_REFERENCE.

The hook is passed the unpromoted type mode instead of the promoted mode.


2019-08-19  Richard Sandiford  

gcc/
* target.def (pass_by_reference): Take a function_arg_info instead
of a mode, type and named flag.
* doc/tm.texi: Regenerate.
* targhooks.h (hook_pass_by_reference_must_pass_in_stack): Update
accordingly.
(hook_bool_CUMULATIVE_ARGS_arg_info_false): Declare.
* targhooks.c (hook_pass_by_reference_must_pass_in_stack): Take a
function_arg_info instead of a mode, type and named flag.
(hook_bool_CUMULATIVE_ARGS_arg_info_false): New function.
* calls.h (pass_by_reference): Take a function_arg_info instead of a
mode, type and named flag.
* calls.c (pass_by_reference): Likewise.
(pass_va_arg_by_reference): Update call accordingly.
(initialize_argument_information): Likewise.
(emit_library_call_value_1): Likewise.
* function.c (assign_parm_find_data_types): Likewise.
* var-tracking.c (prepare_call_arguments): Likewise.
* stor-layout.c: Include calls.h.
(compute_record_mode): Update call to targetm.calls.pass_by_reference.
* config/aarch64/aarch64.c (aarch64_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
* config/alpha/alpha.c (alpha_pass_by_reference): Likewise.
* config/arc/arc.c (arc_pass_by_reference): Likewise.
* config/arm/arm.c (arm_pass_by_reference): Likewise.
* config/bfin/bfin.c (bfin_pass_by_reference): Likewise.
* config/c6x/c6x.c (c6x_pass_by_reference): Likewise.
(c6x_call_saved_register_used): Update call to pass_by_reference.
* config/cris/cris.c (cris_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
* config/epiphany/epiphany.c (epiphany_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
(epiphany_arg_partial_bytes): Update call accordingly.
* config/ft32/ft32.c (ft32_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
(ft32_arg_partial_bytes): Update call accordingly.
* config/i386/i386.c (ix86_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
* config/iq2000/iq2000.c (iq2000_pass_by_reference): Likewise.
* config/m32c/m32c.c (m32c_pass_by_reference): Likewise.
* config/m32r/m32r.c (m32r_pass_by_reference): Likewise.
(m32r_return_in_memory): Update call accordingly.
* config/mips/mips.c (mips_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
* config/mmix/mmix.c (mmix_pass_by_reference): Likewise.
* config/mn10300/mn10300.c (mn10300_pass_by_reference): Likewise.
* config/moxie/moxie.c (moxie_pass_by_reference): Likewise.
(moxie_arg_partial_bytes): Update call accordingly.
* config/msp430/msp430.c (msp430_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
* config/nvptx/nvptx.c (nvptx_pass_by_reference): Likewise.
* config/or1k/or1k.c (or1k_pass_by_reference): Likewise.
* config/pa/pa.c (pa_pass_by_reference): Likewise.
* config/riscv/riscv.c (riscv_pass_by_reference): Likewise.
(riscv_return_in_memory): Update call accordingly.
* config/rs6000/rs6000-internal.h (rs6000_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
* config/rs6000/rs6000-call.c (rs6000_pass_by_reference): Likewise.
(rs6000_parm_needs_stack): Update call to pass_by_reference.
* config/s390/s390.c (s390_pass_by_reference): Take a
function_arg_info instead of a mode, type and named flag.
(s390_call_saved_register_used): Update call accordingly.
* config/sh/sh.c (sh_pass_by_reference): Take a function_arg_info
instead of a mode, type and named flag.
* config/sparc/sparc.c (sparc_pass_by_reference): Likewise.
* config/spu/spu.c (spu_pass_by_reference): Likewise.
* config/tilegx/tilegx.c (tilegx_pass_by_reference): Likewise.
* config/tilepro/tilepro.c (tilepro_pass_by_reference): Likewise.
* config/v850/v850.c (v850_pass_by_reference): Likewise.
* config/visium/visium.c (visium_pass_by_reference): Likewise.

gcc/ada/
* gcc-interface/misc.c (default_pass_by_ref): Update call to
pass_by_reference.

Index: gcc/target.def
===
--- gcc/target.def  2019-08-19 15:58:21.746125942 +0100
+++ gcc/target.def  2019-08-19 15:58:28.450077433 +0100
@@ -4450,18 +4450,18 @@ or 3-byte structure is returned at the m
from __builtin_va_arg.  */
 DEFHOOK
 (pass_by_reference,
- "This 

[03/13] Use function_arg_info for TARGET_ARG_PARTIAL_BYTES

2019-08-19 Thread Richard Sandiford
This patch adds the function_arg_info class and uses it for
TARGET_ARG_PARTIAL_BYTES.

The hook is passed the promoted mode instead of the original type mode.

The arguments aren't mentioned in the documentation, which is why the
target.def change is so small.

The patch changes "true" to "arg.named" in:

  gcc_assert (!epiphany_pass_by_reference (cum, mode, type, /* named */ true));

but epiphany_pass_by_reference doesn't care about the named flag.


2019-08-19  Richard Sandiford  

gcc/
* target.def (arg_partial_bytes): Take a function_arg_info instead
of a mode, type and named flag.
* doc/tm.texi: Regenerate.
* target.h (function_arg_info): Declare.
* calls.h (function_arg_info): New class.
* targhooks.h (hook_int_CUMULATIVE_ARGS_mode_tree_bool_0): Delete.
(hook_int_CUMULATIVE_ARGS_arg_info_0): Declare.
* targhooks.c (hook_int_CUMULATIVE_ARGS_mode_tree_bool_0): Delete.
(hook_int_CUMULATIVE_ARGS_arg_info_0): New function.
* calls.c (initialize_argument_information): Update call to
targetm.calls.partial_bytes.
(emit_library_call_value_1): Likewise.
* expr.c (block_move_libcall_safe_for_call_parm): Likewise.
* function.c (assign_parm_find_entry_rtl): Likewise.
* config/alpha/alpha.c (alpha_arg_partial_bytes): Take a
function_arg_info instead of a mode, type and named flag.
* config/arc/arc.c (arc_arg_partial_bytes): Likewise.
* config/arm/arm.c (arm_arg_partial_bytes): Likewise.
(cmse_func_args_or_return_in_stack): Update accordingly.
* config/bfin/bfin.c (bfin_arg_partial_bytes): Take a
function_arg_info instead of a mode, type and named flag.
* config/cris/cris.c (cris_arg_partial_bytes): Likewise.
* config/csky/csky.c (csky_arg_partial_bytes): Likewise.
* config/epiphany/epiphany.c (epiphany_arg_partial_bytes): Likewise.
* config/fr30/fr30.c: Include calls.h.
(fr30_arg_partial_bytes): Take a function_arg_info instead of a mode,
type and named flag.
* config/frv/frv.c: Include calls.h.
(frv_arg_partial_bytes): Take a function_arg_info instead of a mode,
type and named flag.
* config/ft32/ft32.c (ft32_arg_partial_bytes): Likewise.
* config/gcn/gcn.c (gcn_arg_partial_bytes): Likewise.
* config/ia64/ia64.c (ia64_arg_partial_bytes): Likewise.
* config/iq2000/iq2000.c (iq2000_arg_partial_bytes): Likewise.
* config/m32r/m32r.c (m32r_arg_partial_bytes): Likewise.
* config/mcore/mcore.c (mcore_arg_partial_bytes): Likewise.
* config/microblaze/microblaze.c (function_arg_partial_bytes):
Likewise.
* config/mips/mips.c (mips_arg_partial_bytes): Likewise.
* config/mn10300/mn10300.c (mn10300_arg_partial_bytes): Likewise.
* config/moxie/moxie.c (moxie_arg_partial_bytes): Likewise.
* config/msp430/msp430.c (msp430_arg_partial_bytes): Likewise.
* config/nds32/nds32.c (nds32_arg_partial_bytes): Likewise.
* config/nios2/nios2.c (nios2_arg_partial_bytes): Likewise.
* config/pa/pa.c (pa_arg_partial_bytes): Likewise.
* config/pru/pru.c (pru_arg_partial_bytes): Likewise.
* config/riscv/riscv.c (riscv_arg_partial_bytes): Likewise.
* config/rs6000/rs6000-internal.h (rs6000_arg_partial_bytes): Likewise.
* config/rs6000/rs6000-call.c (rs6000_arg_partial_bytes): Likewise.
(rs6000_parm_needs_stack): Update call accordingly.
* config/sh/sh.c (sh_arg_partial_bytes): Take a
function_arg_info instead of a mode, type and named flag.
* config/sparc/sparc.c (sparc_arg_partial_bytes): Likewise.
* config/v850/v850.c (v850_arg_partial_bytes): Likewise.

Index: gcc/target.def
===
--- gcc/target.def  2019-08-15 15:26:09.232205170 +0100
+++ gcc/target.def  2019-08-19 15:58:21.746125942 +0100
@@ -4677,8 +4677,8 @@ compiler when this occurs, and how many
 @code{TARGET_FUNCTION_ARG} for these arguments should return the first\n\
 register to be used by the caller for this argument; likewise\n\
 @code{TARGET_FUNCTION_INCOMING_ARG}, for the called function.",
- int, (cumulative_args_t cum, machine_mode mode, tree type, bool named),
- hook_int_CUMULATIVE_ARGS_mode_tree_bool_0)
+ int, (cumulative_args_t cum, const function_arg_info ),
+ hook_int_CUMULATIVE_ARGS_arg_info_0)
 
 /* Update the state in CA to advance past an argument in the
argument list.  The values MODE, TYPE, and NAMED describe that
Index: gcc/doc/tm.texi
===
--- gcc/doc/tm.texi 2019-08-15 15:26:09.228205200 +0100
+++ gcc/doc/tm.texi 2019-08-19 15:58:21.746125942 +0100
@@ -4057,7 +4057,7 @@ Perform a target dependent initializatio
 This hook is called at the start of register allocation.
 @end deftypefn
 
-@deftypefn 

[02/13] Add must_pass_va_arg_in_stack

2019-08-19 Thread Richard Sandiford
This patch splits out another idiom from the va_arg gimplification
routines, so that there's only one place to update later.


2019-08-19  Richard Sandiford  

gcc/
* calls.h (must_pass_va_arg_in_stack): Declare.
* calls.c (must_pass_va_arg_in_stack): New function.
* config/alpha/alpha.c (alpha_gimplify_va_arg_1): Use it.
* config/sh/sh.c (sh_gimplify_va_arg_expr): Likewise.
* config/stormy16/stormy16.c (xstormy16_gimplify_va_arg_expr):
Likewise.
* config/xtensa/xtensa.c (xtensa_gimplify_va_arg_expr): Likewise.

Index: gcc/calls.h
===
--- gcc/calls.h 2019-08-19 15:58:10.742205564 +0100
+++ gcc/calls.h 2019-08-19 15:58:16.094166837 +0100
@@ -28,6 +28,7 @@ extern bool gimple_alloca_call_p (const
 extern bool alloca_call_p (const_tree);
 extern bool must_pass_in_stack_var_size (machine_mode, const_tree);
 extern bool must_pass_in_stack_var_size_or_pad (machine_mode, const_tree);
+extern bool must_pass_va_arg_in_stack (tree);
 extern rtx prepare_call_address (tree, rtx, rtx, rtx *, int, int);
 extern bool shift_return_value (machine_mode, bool, rtx);
 extern rtx expand_call (tree, rtx, int);
Index: gcc/calls.c
===
--- gcc/calls.c 2019-08-19 15:58:10.742205564 +0100
+++ gcc/calls.c 2019-08-19 15:58:16.094166837 +0100
@@ -5900,5 +5900,14 @@ must_pass_in_stack_var_size_or_pad (mach
   return false;
 }
 
+/* Return true if TYPE must be passed on the stack when passed to
+   the "..." arguments of a function.  */
+
+bool
+must_pass_va_arg_in_stack (tree type)
+{
+  return targetm.calls.must_pass_in_stack (TYPE_MODE (type), type);
+}
+
 /* Tell the garbage collector about GTY markers in this source file.  */
 #include "gt-calls.h"
Index: gcc/config/alpha/alpha.c
===
--- gcc/config/alpha/alpha.c2019-08-19 15:58:10.750205506 +0100
+++ gcc/config/alpha/alpha.c2019-08-19 15:58:16.094166837 +0100
@@ -6243,7 +6243,7 @@ alpha_gimplify_va_arg_1 (tree type, tree
 
   /* If the type could not be passed in registers, skip the block
  reserved for the registers.  */
-  if (targetm.calls.must_pass_in_stack (TYPE_MODE (type), type))
+  if (must_pass_va_arg_in_stack (type))
 {
   t = build_int_cst (TREE_TYPE (offset), 6*8);
   gimplify_assign (offset,
Index: gcc/config/sh/sh.c
===
--- gcc/config/sh/sh.c  2019-08-13 22:35:11.793251783 +0100
+++ gcc/config/sh/sh.c  2019-08-19 15:58:16.098166809 +0100
@@ -7656,9 +7656,8 @@ sh_gimplify_va_arg_expr (tree valist, tr
   tree addr, lab_over = NULL, result = NULL;
   tree eff_type;
 
-  const bool pass_by_ref =
-!VOID_TYPE_P (type)
-&& targetm.calls.must_pass_in_stack (TYPE_MODE (type), type);
+  const bool pass_by_ref
+= !VOID_TYPE_P (type) && must_pass_va_arg_in_stack (type);
 
   if (pass_by_ref)
 type = build_pointer_type (type);
Index: gcc/config/stormy16/stormy16.c
===
--- gcc/config/stormy16/stormy16.c  2019-08-13 22:35:11.805251695 +0100
+++ gcc/config/stormy16/stormy16.c  2019-08-19 15:58:16.098166809 +0100
@@ -1342,7 +1342,7 @@ xstormy16_gimplify_va_arg_expr (tree val
   count = build3 (COMPONENT_REF, TREE_TYPE (f_count), valist, f_count,
  NULL_TREE);
 
-  must_stack = targetm.calls.must_pass_in_stack (TYPE_MODE (type), type);
+  must_stack = must_pass_va_arg_in_stack (type);
   size_tree = round_up (size_in_bytes (type), UNITS_PER_WORD);
   gimplify_expr (_tree, pre_p, NULL, is_gimple_val, fb_rvalue);
 
Index: gcc/config/xtensa/xtensa.c
===
--- gcc/config/xtensa/xtensa.c  2019-08-19 15:58:10.766205389 +0100
+++ gcc/config/xtensa/xtensa.c  2019-08-19 15:58:16.098166809 +0100
@@ -3328,7 +3328,7 @@ xtensa_gimplify_va_arg_expr (tree valist
   array = create_tmp_var (ptr_type_node);
 
   lab_over = NULL;
-  if (!targetm.calls.must_pass_in_stack (TYPE_MODE (type), type))
+  if (!must_pass_va_arg_in_stack (type))
 {
   lab_false = create_artificial_label (UNKNOWN_LOCATION);
   lab_over = create_artificial_label (UNKNOWN_LOCATION);


[01/13] Add pass_va_arg_by_reference

2019-08-19 Thread Richard Sandiford
This patch splits out a common idiom from the va_arg gimplification
routines, so that there's only one place to update later.


2019-08-19  Richard Sandiford  

gcc/
* calls.h (pass_va_arg_by_reference): Declare.
* calls.c (pass_va_arg_by_reference): New function.
* config/aarch64/aarch64.c (aarch64_gimplify_va_arg_expr): Use it.
* config/alpha/alpha.c (alpha_gimplify_va_arg): Likewise.
* config/gcn/gcn.c (gcn_gimplify_va_arg_expr): Likewise.
* config/i386/i386.c (ix86_gimplify_va_arg): Likewise.
* config/ia64/ia64.c (ia64_gimplify_va_arg): Likewise.
* config/mips/mips.c (mips_std_gimplify_va_arg_expr): Likewise.
(mips_gimplify_va_arg_expr): Likewise.
* config/msp430/msp430.c (msp430_gimplify_va_arg_expr): Likewise.
* config/pa/pa.c (hppa_gimplify_va_arg_expr): Likewise.
* config/rs6000/rs6000-call.c (rs6000_gimplify_va_arg): Likewise.
* config/s390/s390.c (s390_gimplify_va_arg): Likewise.
* config/sparc/sparc.c (sparc_gimplify_va_arg): Likewise.
* config/spu/spu.c (spu_gimplify_va_arg_expr): Likewise.
* config/tilegx/tilegx.c (tilegx_gimplify_va_arg_expr): Likewise.
* config/tilepro/tilepro.c (tilepro_gimplify_va_arg_expr): Likewise.
* config/visium/visium.c (visium_gimplify_va_arg): Likewise.
* config/xtensa/xtensa.c (xtensa_gimplify_va_arg_expr): Likewise.
* targhooks.c (std_gimplify_va_arg_expr): Likewise.

Index: gcc/calls.h
===
--- gcc/calls.h 2019-03-08 18:15:33.696751769 +
+++ gcc/calls.h 2019-08-19 15:58:10.742205564 +0100
@@ -35,6 +35,7 @@ extern void fixup_tail_calls (void);
 
 extern bool pass_by_reference (CUMULATIVE_ARGS *, machine_mode,
   tree, bool);
+extern bool pass_va_arg_by_reference (tree);
 extern bool reference_callee_copied (CUMULATIVE_ARGS *, machine_mode,
 tree, bool);
 extern void maybe_warn_alloc_args_overflow (tree, tree, tree[2], int[2]);
Index: gcc/calls.c
===
--- gcc/calls.c 2019-08-13 22:35:04.921302360 +0100
+++ gcc/calls.c 2019-08-19 15:58:10.742205564 +0100
@@ -927,6 +927,15 @@ pass_by_reference (CUMULATIVE_ARGS *ca,
  type, named_arg);
 }
 
+/* Return true if TYPE should be passed by reference when passed to
+   the "..." arguments of a function.  */
+
+bool
+pass_va_arg_by_reference (tree type)
+{
+  return pass_by_reference (NULL, TYPE_MODE (type), type, false);
+}
+
 /* Return true if TYPE, which is passed by reference, should be callee
copied instead of caller copied.  */
 
Index: gcc/config/aarch64/aarch64.c
===
--- gcc/config/aarch64/aarch64.c2019-08-15 10:00:02.366735649 +0100
+++ gcc/config/aarch64/aarch64.c2019-08-19 15:58:10.746205533 +0100
@@ -14271,7 +14271,7 @@ aarch64_gimplify_va_arg_expr (tree valis
   HOST_WIDE_INT size, rsize, adjust, align;
   tree t, u, cond1, cond2;
 
-  indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
+  indirect_p = pass_va_arg_by_reference (type);
   if (indirect_p)
 type = build_pointer_type (type);
 
Index: gcc/config/alpha/alpha.c
===
--- gcc/config/alpha/alpha.c2019-08-13 22:35:11.721252311 +0100
+++ gcc/config/alpha/alpha.c2019-08-19 15:58:10.750205506 +0100
@@ -6330,7 +6330,7 @@ alpha_gimplify_va_arg (tree valist, tree
   t = fold_convert (build_nonstandard_integer_type (64, 0), offset_field);
   offset = get_initialized_tmp_var (t, pre_p, NULL);
 
-  indirect = pass_by_reference (NULL, TYPE_MODE (type), type, false);
+  indirect = pass_va_arg_by_reference (type);
 
   if (indirect)
 {
Index: gcc/config/gcn/gcn.c
===
--- gcc/config/gcn/gcn.c2019-08-13 22:35:11.733252223 +0100
+++ gcc/config/gcn/gcn.c2019-08-19 15:58:10.750205506 +0100
@@ -2493,7 +2493,7 @@ gcn_gimplify_va_arg_expr (tree valist, t
   tree t, u;
   bool indirect;
 
-  indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
+  indirect = pass_va_arg_by_reference (type);
   if (indirect)
 {
   type = ptr;
Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c  2019-08-19 15:57:56.338309784 +0100
+++ gcc/config/i386/i386.c  2019-08-19 15:58:10.754205475 +0100
@@ -4307,7 +4307,7 @@ ix86_gimplify_va_arg (tree valist, tree
   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
 
-  indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
+  indirect_p = pass_va_arg_by_reference (type);
   if (indirect_p)
 

[00/13] Pass an argument descriptor to target hooks

2019-08-19 Thread Richard Sandiford
For the SVE calling conventions, function_arg and function_arg_advance
need to know whether an argument is being passed by reference or not.
The simplest way of providing that information would have been to add a
new parameter, or convert the "named" parameter into a bitmask.  But it
seemed cleaner to wrap the argument information in a struct/class instead.

The bulk of this series therefore adds a function_arg_info that
initially records the type, mode and named flag.  The final patch then
adds the pass-by-reference information as well, which becomes a small
change on its own.

The new struct/class inherits a couple of non-obvious points of the
current interface:

(a) For some hooks the mode is the mode of the type.  For others it's
the mode after promotion.  On targets that use argument promotion,
this affects the choice between the mode and the type when both
pieces of information are specified.

(a) Traditionally the type is null when calling libgcc support functions.
But I think the argument conceptually still has a type (most of the
functions are written in C after all).  It's just that the type is
inferred from the unpromoted mode rather than being specified directly.
So when we have access to the unpromoted mode, we can still query some
properties of the type even if we don't have access to the type itself.

(I remember it was said years ago that we should clean this up and
call libgcc functions like any other function.  But TBH I can't see
that ever happening.)

Of course, the ABI support is one of the most sensitive areas of the
compiler and it would be very easy to introduce a silent ABI break.
I've therefore tried to be conservative and stick to the following
changes:

(1) Replace uses of the old parameters with the corresponding fields
of the function_arg_info (which hold the same values as before).

(2) In cases where the mode is the unpromoted mode, replace the calculation:

  type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode)

with a new type_size_in_bytes (), which computes the same thing
in the same way.

[The name is based on (b) above -- every argument has a type,
even if we aren't given it explicitly.]

(3) In cases where the mode is the promoted mode, replace the calculation:

  mode == BLKmode ? int_size_in_bytes (type) : GET_MODE_SIZE (mode)

with a new promoted_size_in_bytes (), which computes the same thing
in the same way.

Not all the affected targets use argument promotion, but that's
what the calculation is logically providing in the affected contexts.

[The only case I found in which the calculation was used for an
unpromoted mode was aarch64_pass_by_reference.  Other targets use
the expression in (2) here, and the later:

  /* Aggregates are passed by reference based on their size.  */
  if (type && AGGREGATE_TYPE_P (type))
{
  size = int_size_in_bytes (type);
}

suggests that that might have been the intention for aarch64 too.
The series just leaves the aarch64 calculation as-is.]

(4) In cases where the mode is the promoted mode, replace the calculation:

  mode == BLKmode && type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode)

with promoted_size_in_bytes (), as for (3).  This means that the
compiler will now ICE (via a segfault) on the invalid combination:

  mode == BLKmode && !type

which I think is preferable to letting the error slip past.

(5) Replace the common test:

  type && AGGREGRATE_TYPE_P (type)

with a new aggregate_type_p (), which computes the same thing
in the same way.  This is again based on point (b) above.

(6) In function_arg only, replace:

  mode == VOIDmode

and

  type == void_type_node

(or both) with end_marker_p ().

Bootstrapped & regression-tested on aarch64-linux-gnu and x86_64-linux-gnu
(all languages for the latter).  I also tested each individual patch in
the series by compiling at least one target per CPU directory, checking
for no new warnings, and checking that there were no changes in assembly
output for gcc.c-torture, gcc.dg and g++.dg at -O0.

diffstat for series:

 66 files changed, 1676 insertions(+), 2246 deletions(-)

although admittedly a lot of that comes from culling out-of-date comments.

Richard


Re: [PATCH] Intrinsic documentation for DIM, MOD and MODULO.

2019-08-19 Thread Jeff Law
On 8/19/19 3:11 AM, Mark Eggleston wrote:
> The intrinsics DIM, MOD and MODULO can accept arguments of different
> kinds and return values with the larger of the two kinds. Notes to this
> effect have been added as they were missing from the documentation.
> 
> Please find attached the patch.
> 
> ChangeLog:
> 
> gcc/fortran/ChangeLog
> 
>     Mark Eggleston  
> 
>     PR fortran/89236
>     * intrinsic.texi: Add GNU extension notes to DIM, MOD, MODULO.
> 
Do we want to be more specific about what types are accepted as a GNU
extension for these operators?

jeff


[PATCH] Use tail-recursion in SCEV SCC finding where possible

2019-08-19 Thread Richard Biener


The following applies manual tail-recusion transform to add chains
SLP generates.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2019-08-19  Richard Biener  

PR tree-optimization/91403
* tree-scalar-evolution.c (follow_ssa_edge_binary): Inline
cases we can handle with tail-recursion...
(follow_ssa_edge_expr): ... here.  Do so.

Index: gcc/tree-scalar-evolution.c
===
--- gcc/tree-scalar-evolution.c (revision 274666)
+++ gcc/tree-scalar-evolution.c (working copy)
@@ -925,32 +925,11 @@ follow_ssa_edge_binary (class loop *loop
  res = follow_ssa_edge_expr
(loop, at_stmt, rhs1, halting_phi,
 evolution_of_loop, limit);
- if (res == t_true)
-   ;
- else if (res == t_dont_know)
-   *evolution_of_loop = chrec_dont_know;
}
-
- else if (res == t_dont_know)
-   *evolution_of_loop = chrec_dont_know;
}
 
  else
-   {
- /* Match an assignment under the form:
-"a = b + ...".  */
- *evolution_of_loop = add_to_evolution
- (loop->num, chrec_convert (type, *evolution_of_loop,
-at_stmt),
-  code, rhs1, at_stmt);
- res = follow_ssa_edge_expr
-   (loop, at_stmt, rhs0, halting_phi,
-evolution_of_loop, limit);
- if (res == t_true)
-   ;   
- else if (res == t_dont_know)
-   *evolution_of_loop = chrec_dont_know;
-   }
+   gcc_unreachable ();  /* Handled in caller.  */
}
 
   else if (TREE_CODE (rhs1) == SSA_NAME)
@@ -964,10 +943,6 @@ follow_ssa_edge_binary (class loop *loop
  res = follow_ssa_edge_expr
(loop, at_stmt, rhs1, halting_phi,
 evolution_of_loop, limit);
- if (res == t_true)
-   ;
- else if (res == t_dont_know)
-   *evolution_of_loop = chrec_dont_know;
}
 
   else
@@ -980,26 +955,7 @@ follow_ssa_edge_binary (class loop *loop
 case MINUS_EXPR:
   /* This case is under the form "opnd0 = rhs0 - rhs1".  */
   if (TREE_CODE (rhs0) == SSA_NAME)
-   {
- /* Match an assignment under the form:
-"a = b - ...".  */
-
- /* We want only assignments of form "name - name" contribute to
-LIMIT, as the other cases do not necessarily contribute to
-the complexity of the expression.  */
- if (TREE_CODE (rhs1) == SSA_NAME)
-   limit++;
-
- *evolution_of_loop = add_to_evolution
- (loop->num, chrec_convert (type, *evolution_of_loop, at_stmt),
-  MINUS_EXPR, rhs1, at_stmt);
- res = follow_ssa_edge_expr (loop, at_stmt, rhs0, halting_phi,
- evolution_of_loop, limit);
- if (res == t_true)
-   ;
- else if (res == t_dont_know)
-   *evolution_of_loop = chrec_dont_know;
-   }
+   gcc_unreachable (); /* Handled in caller.  */
   else
/* Otherwise, match an assignment under the form:
   "a = ... - ...".  */
@@ -1184,6 +1140,7 @@ follow_ssa_edge_expr (class loop *loop,
   /* For SSA_NAME look at the definition statement, handling
  PHI nodes and otherwise expand appropriately for the expression
  handling below.  */
+tail_recurse:
   if (TREE_CODE (expr) == SSA_NAME)
 {
   gimple *def = SSA_NAME_DEF_STMT (expr);
@@ -1193,7 +1150,10 @@ follow_ssa_edge_expr (class loop *loop,
 
   /* Give up if the path is longer than the MAX that we allow.  */
   if (limit > PARAM_VALUE (PARAM_SCEV_MAX_EXPR_COMPLEXITY))
-   return t_dont_know;
+   {
+ *evolution_of_loop = chrec_dont_know;
+ return t_dont_know;
+   }
 
   if (gphi *phi = dyn_cast (def))
{
@@ -1303,14 +1263,28 @@ follow_ssa_edge_expr (class loop *loop,
   /* This case is under the form "rhs0 +- rhs1".  */
   STRIP_USELESS_TYPE_CONVERSION (rhs0);
   STRIP_USELESS_TYPE_CONVERSION (rhs1);
+  if (TREE_CODE (rhs0) == SSA_NAME
+ && (TREE_CODE (rhs1) != SSA_NAME || code == MINUS_EXPR))
+   {
+ /* Match an assignment under the form:
+"a = b +- ...".
+Use tail-recursion for the simple case.  */
+ *evolution_of_loop = add_to_evolution
+ (loop->num, chrec_convert (type, *evolution_of_loop,
+at_stmt),
+  code, rhs1, at_stmt);
+ expr = rhs0;
+ goto tail_recurse;
+   }
+  /* Else search for the SCC in both rhs0 and rhs1.  */
   return follow_ssa_edge_binary (loop, at_stmt, type, rhs0, code, rhs1,
 halting_phi, 

Re: [PATCH 3/9] operand_equal_p: add support for OBJ_TYPE_REF.

2019-08-19 Thread Jan Hubicka
> On Fri, Aug 16, 2019 at 2:07 PM Jan Hubicka  wrote:
> >
> > >
> > > When we compare OBJ_TYPE_REF_TOKEN and OBJ_TYPE_REF_OBJECT
> > > and they are equal, are there cases where types_same_for_odr returns 
> > > false?
> >
> > OBJ_TYPE_REF_OBJECT is pointer to the instance, OBJ_TYPE_REF_TOKEN is
> > index in the vtable or the type given by obj_ref_type_class.  I guess
> > one can do something like
> >
> >  void *ptr;
> >  ...
> >  if (cond)
> >((class_a *)ptr)->firstvirtualmethod_of_class_a ();
> >  else
> >((class_b *)ptr)->firstvirtualmethod_of_class_b ();
> >
> > Here OBJECT will be always *ptr, TOKEN will be 0, but the actual virtual
> > method is different. So merging this may lead to invalid
> > devirtualization at least when the classes are anonymous namespace and
> > we work out late in compilation that they are not derived.
> 
> But we also compare OBJ_TYPE_REF_EXPR and later we expand to a call
> with exactly that address...

I think this is same as with memory references.  Just because the
addresses compare equal and read same type we still can not merge w/o
verifying that the alias oracle will not give different answers 
(so we need to compare cliques and access paths). operand_equal_p does
checking in this case though it is bit random on way it understands
access paths.

To get more agressive unification we can drop the optional metadata
(i.e. remove OBJ_TYPE_REF or drop to alias set zero) while merging but I
think this will need more care and decisions what to do for -Os only and
what to do for -O2/fast.  For this reason I would first handle this
conservatively (i.e. require match of metadata as well) and then improve
from that.

Honza


Re: [PATCH V2 6/8] bpf: adjust GCC testsuite to eBPF limitations

2019-08-19 Thread Jose E. Marchesi


[...]
>   * gcc.dg/Wframe-larger-than-2.c: Likewise.
>   * gcc.dg/Wframe-larger-than.c: Likewise.
>   * gcc.dg/Wrestrict-11.c: Likewise.
So I think we probably want an effective target check for indirect calls
rather than checking explicitly for ebpf in all these files.

Ok, will introduce it.

It also seems like rather than checking for ebpf on files with large
stacks, we should be using the generic mechanisms to defined the allowed
size of the stack (mentioned in prior review) & mark test which use too
much space.  This would almost certainly help other embedded targets as
well.

I first thought about doing that, but hesitated when I realized it would
require to alter existing tests in no trivial ways: will the test still
effectively test whatever it is supposed to test, after the size of an
array is changed, for example?

Not sure the best way to deal with too many arguments.  I suspect we
want an efffective target check for that.  Keeping this up-to-date will
be painful as people write more tests.

Yeah, that won't be fun :(

  /* Copyright (C) 2000, 2003 Free Software Foundation */
>  __complex__ long long f ()
> diff --git a/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> b/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> index be0bdcf7631..9f6bd0af2e5 100644
> --- a/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> +++ b/gcc/testsuite/gcc.c-torture/compile/20001226-1.c
> @@ -3,6 +3,7 @@
>  /* { dg-skip-if "too much code for pdp11" { "pdp11-*-*" } } */
>  /* { dg-xfail-if "PR36698" { spu-*-* } { "-O0" } { "" } } */
>  /* { dg-skip-if "" { m32c-*-* } } */
> +/* { dg-skip-if "jumps too far for eBPF" { bpf-*-* } } */
>  /* { dg-timeout-factor 4.0 } */
Jumps too far is probably an indication you need to fix something in
your port.  Though I guess its OK if you're never going to support far
away targets.

The reasons for this are that eBPF doesn't have indirect jump
instructions, and the direct jump instruction's displacement is a signed
PC-relative 16-bit offset, in 64-bit word units.

So, unless the compiler gets able to generate a "chain" of direct jumps
to reach the destination (that would be a fun hack :D) the range for
branches is severely limited.

> diff --git a/gcc/testsuite/gcc.c-torture/compile/20101217-1.c
> b/gcc/testsuite/gcc.c-torture/compile/20101217-1.c
> index c4eef0ed464..cd902afe709 100644
> --- a/gcc/testsuite/gcc.c-torture/compile/20101217-1.c
> +++ b/gcc/testsuite/gcc.c-torture/compile/20101217-1.c
> @@ -1,3 +1,5 @@
> +/* { dg-skip-if "no usable stdio.h for eBPF" { bpf-*-* } } */
I think this is only to get the printf prototype.  I suspect you could
just provide a suitable prototype and drop the #include .

Nice, will do just that.


Re: [PATCH] issue consistent warning for past-the-end array stores (PR 91457)

2019-08-19 Thread Richard Biener
On Sat, Aug 17, 2019 at 12:43 AM Martin Sebor  wrote:
>
> With the recent enhancement to the strlen handling of multibyte
> stores the g++.dg/warn/Warray-bounds-4.C for zero-length arrays
> started failing on hppa (and probably elsewhere as well).  This
> is partly the result of the added detection of past-the-end
> writes into the strlen pass which detects more instances of
> the problem than -Warray-bounds.  Since the IL each warning
> works with varies between targets, the same invalid code can
> be diagnosed by one warning one target and different warning
> on another.
>
> The attached patch does three things:
>
> 1) It enhances compute_objsize to also determine the size of
> a flexible array member (and its various variants), including
> from its initializer if necessary.  (This resolves 91457 but
> introduces another warning where was previously just one.)
> 2) It guards the new instance of -Wstringop-overflow with
> the no-warning bit on the assignment to avoid warning on code
> that's already been diagnosed.
> 3) It arranges for -Warray-bounds to set the no-warning bit on
> the enclosing expression to keep -Wstringop-overflow from issuing
> another warning for the same problem.
>
> Testing the compute_objsize enhancement to bring it up to par
> with -Warray-bounds in turn exposed a weakness in the latter
> warning for flexible array members.  Rather than snowballing
> additional improvements into this one I decided to put that
> off until later, so the new -Warray-bounds test has a bunch
> of XFAILs.  I'll see if I can find the time to deal with those
> either still in stage 1 or in stage 3 (one of them is actually
> an ancient regression).

+static tree
+get_initializer_for (tree init, tree decl)
+{

can't you use fold_ctor_reference here?

+/* Determine the size of the flexible array FLD from the initializer
+   expression for the struct object DECL in which the meber is declared
+   (possibly recursively).  Return the size or zero constant if it isn't
+   initialized.  */
+
+static tree
+get_flexarray_size (tree decl, tree fld)
+{
+  if (tree init = DECL_INITIAL (decl))
+{
+  init = get_initializer_for (init, fld);
+  if (init)
+   return TYPE_SIZE_UNIT (TREE_TYPE (init));
+}
+
+  return integer_zero_node;

so you're hoping that the (sub-)CONSTRUCTOR get_initializer_for
returns has a complete type but the initialized object didn't get it
completed.  Isnt that wishful thinking?  And why return integer_zero_node
rather than NULL_TREE here?

+  if (TREE_CODE (dest) == COMPONENT_REF)
+{
+  *pdecl = TREE_OPERAND (dest, 1);
+
+  /* If the member has a size return it.  Otherwise it's a flexible
+array member.  */
+  if (tree size = DECL_SIZE_UNIT (*pdecl))
+   return size;

because here you do.

Also once you have an underlying VAR_DECL you can compute
the flexarray size by DECL_SIZE (var) - offset-of flexarray member.
Isn't that way cheaper than walking the initializer (possibly many
times?)

Richard.

>
> Martin
>
> PS I imagine the new get_flexarray_size function will probably
> need to move somewhere more appropriate so that other warnings
> (like -Warray-bounds to remove the XFAILs) and optimizations
> can make use of it.


Re: [PATCH V2 5/8] bpf: make target-supports.exp aware of eBPF

2019-08-19 Thread Jose E. Marchesi


Hi Seguer!  Thanks for reviewing :)

> @@ -538,6 +539,9 @@ proc check_effective_target_stack_size { } {
>  if [target_info exists gcc,stack_size] {
>   return 1
>  }
> +if [istarget bpf-*-*] {
> + return 1
> +}

You should still set the proper stack size in your board file, so does
this help you at all?

> @@ -546,7 +550,11 @@ proc check_effective_target_stack_size { } {
>  proc dg-effective-target-value { effective_target } {
>  if { "$effective_target" == "stack_size" } {
>   if [check_effective_target_stack_size] {
> - return [target_info gcc,stack_size]
> + if [istarget bpf-*-*] {
> + return "512"
> + } else {
> + return [target_info gcc,stack_size]
> + }

Yeah okay...  Can't you directly override the gcc,stack_size setting,
instead of doing that in every(?) place it is checked?

Yes I agree these things belong to the board configuration files, so I
will remove that ad-hoc logic from the patch.



Re: [PATCH V2 5/8] bpf: make target-supports.exp aware of eBPF

2019-08-19 Thread Jose E. Marchesi


> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
>  
> @@ -546,7 +550,11 @@ proc check_effective_target_stack_size { } {
>  proc dg-effective-target-value { effective_target } {
>  if { "$effective_target" == "stack_size" } {
>   if [check_effective_target_stack_size] {
> - return [target_info gcc,stack_size]
> + if [istarget bpf-*-*] {
> + return "512"
> + } else {
> + return [target_info gcc,stack_size]
> + }
>   }
>  }
Shouldn't the BPF stack size be defined be in your target files?

Yes, definitely.  I am adding a board description to dejagnu.  Will
set_board_info gcc,stack_size 512 there and remove this nasty overwrite
in dg-effective-target-value.

The ChangeLog mentions check_effective_target_malloc, but I don't see it
in the patch itself.  Note that it needs to be documented in
gcc/doc/sourcebuild.texi as well if you are adding a new
check_effective_target_

Oh at some point I introduced a check_effective_target_malloc, then
removed it.  What you saw is a stale reference in the ChangeLog.  Will
get rid of it.

Thanks!


Re: [RFA] [tree-optimization/80576] Handle non-constant sizes in DSE

2019-08-19 Thread Richard Biener
On Fri, Aug 16, 2019 at 8:15 PM Jeff Law  wrote:
>
> On 8/16/19 12:09 PM, Marc Glisse wrote:
> > On Fri, 16 Aug 2019, Jeff Law wrote:
> >
> >> This patch improves our ability to detect dead stores by handling cases
> >> where the size memcpy, memset, strncpy, etc call is not constant.  This
> >> addresses some, but not all, of the issues in 80576.
> >>
> >> The key here is when the size is not constant we can make conservative
> >> decisions that still give us a chance to analyze the code for dead
> >> stores.
> >>
> >> Remember that for dead store elimination, we're trying to prove that
> >> given two stores, the second store overwrites (partially or fully) the
> >> same memory locations as the first store.  That makes the first store
> >> either partially or fully dead.
> >>
> >> When we encounter the first store, we set up a bitmap of bytes written
> >> by that store (live_bytes).  We then look at subsequent stores and clear
> >> the appropriate entries in the bitmap.
> >>
> >> If the first store has a nonconstant length argument we can use the
> >> range of the length argument (max) and the size of the destination
> >> object to make a conservative estimation of how many bytes are written.
> >>
> >> For the second store the conservative thing to do for a non-constant
> >> length is to use the minimum of the range of the length argument.
> >
> > So I guess it won't handle things like
> >
> > void f(char*p,int n){
> >   __builtin_memset(p,3,n);
> >   __builtin_memset(p,7,n);
> > }
> >
> > where we know nothing about the length, except that it is the same? Or
> > do you look at symbolic ranges?
> Nope.  I think ao_ref can represent that, so it'd just be a matter of
> recording "n" as the length, then verifying that the second call's
> length is "n" as well.  That makes the first call dead.  We'd have to
> bypass the byte tracking in that case, but I think that's trivial
> because we already have a means to do that when the sizes are too large.
>
> >
> >> This doesn't come up a lot in practice.  But it also happens to put some
> >> of the infrastructure in place to handle strcpy and strcpy_chk which are
> >> needed to fully resolve 80576.
> >>
> >> Bootstrapped and regression tested on x86, x86_64, ppc64le, ppc64,
> >> ppc32, aarch64, sparc, s390x and probably others.  Also verified that
> >> the tests work on the various *-elf targets in my tester.
> >>
> >> OK for the trunk?
> >
> > ENOPATCH
> Opps.Attached.

+static tree
+objsize_from_type (tree object)
+{
+  if (TREE_CODE (object) != ADDR_EXPR)
+return NULL_TREE;
+
+  tree type = TREE_TYPE (object);
+  if (POINTER_TYPE_P (type))

that if looks suspicious...  I'd say
  if (!POINTER_TYPE_P (type))
return NULL_TREE;

is better

+type = TREE_TYPE (type);

+  if (TREE_CODE (type) == ARRAY_TYPE && !array_at_struct_end_p (object))
+{

array_at_struct_end_p will never return true here since you pass it
an ADDR_EXPR...  you wanted to pass TREE_OPERAND (object, 0) here?

Also you seem to use this info to constrain optimization when you
might remember that types of addresses do not carry such information...
Thus it should be "trivially" possible to write a testcase that is miscompiled
after your patch.  I also don't see this really exercised in the
testcases you add?
All of them reference a static array a ...

+   if (TREE_CODE (size) != INTEGER_CST)

TREE_CODE (size) == SSA_NAME you want

+ {
+   wide_int minbound, maxbound;
+   value_range_kind rng = get_range_info (size,
, );
+   if (rng == VR_RANGE)

Richard.

>
> Jeff
>
>


Re: [PATCH 2/3] Add simplify rules for wrapped binary operations.

2019-08-19 Thread Richard Biener
On Fri, Aug 16, 2019 at 2:17 PM Robin Dapp  wrote:
>
> > So - what are you really after? (sorry if I don't remeber, testcase(s)
> > are missing
> > from this patch)
> >
> > To me it seems that 1) loses information if A + CST was done in a signed 
> > type
> > and we know that overflow doesn't happen because of that.  For the reverse
> > transformation we don't.  Btw, if you make A == A' + CST' then
> > you get (T)A + CST -> (T)(A' + CST' + CST) which is again trivially handled
> > so why do you need both transforms again?
>
> As far as I know the second transformation resulted from some suggestion
> to split what was the status back then.  Some things have changed in
> match.pd so I checked again:
>
> What I want to achieve in the end is getting rid of
>  add r1,-1
>  extend r1
>  add r1,1.
> emitted via doloop.
>
> We have
> (1)   (T)(A + CST1) + CST2 -> (T)(A) + (T)CST1 + CST2

Here + CST2 isn't part of the transform - is it just to restrict the
"first half" to a specific subset of cases?

> (2)   (T)(A) + (T)CST1 + CST2 -> (T)(A) + (T)(CST1 + CST2)

Likewise for (T)(A).

> (2better) (A +- CST1) +- CST2 -> A + CST3 (the one Marc mentioned)

But that's (1) with A == (T)(A' + CST1)

> (3)   (T)(A) + CST -> T(A + CST)
>
> Considering
>  unsigned long foo(unsigned int a)
>  {
>if (a > 3 && a < INT_MAX - 100)
>  return (unsigned long)(a - 1) + 1;

So you want to either compute everything
in unsigned long or everything in unsigned int.
IMHO unsigned int is preferable.  So that
asks for

 (T)A + 1 -> (T)(A + 1)

if T is wider.  We are already performing the reverse
of T is narrower, (T)(A + 1) -> (T)A + 1 (IIRC).

>  }.
>
> This results in s390 assembly
>  ahi%r2,-1
>  llgfr  %r2,%r2
>  aghi   %r2,1
>  br %r14.
>
> With the second transform it becomes just
>  br %r14
> due to
>
> (3) Applying pattern match.pd:2091, gimple-match.c:36515
> Matching expression match.pd:111, gimple-match.c:65
> (2better) Applying pattern match.pd:1980, gimple-match.c:1011
>
> in evrp.
>
> I believe when I last tried long time ago it would not work that way but
> now it does, so (3) is basically an enabler of (2better).  As far as I
> can tell (2better) does not make use of range information but I didn't
> really now why it works the way it does using (3).
>
>
> Now for
>
>  unsigned long bar(unsigned int a)
>  {
>if (a > 3 && a < INT_MAX - 100)
>  return (unsigned long)(a + 1) + ULONG_MAX;

Here we can't perform the add in the narrower type.  But
we do not want, generally, (T)(a + CST) -> (T)A + CST
when T is a widening conversion.  So for this case it makes
sense to restrict it to the case where we can combine the
constants (but I wonder if this needs to be done in a pass
like reassoc to be effective).

So - which case is it?  IIRC we want to handle small signed
constants but the code can end up unsigned.  For the
above we could write (unsigned long)((int)a + 1 - 1) and thus
sign-extend?  Or even avoid this if we know the range.
That is, it becomes the first case again (operation performed
in a smaller type).

>  }
>
> we have
>
> Folded into: _2 = a_7 + 1;
> Folding statement: _3 = (long unsigned int) _2;
> Folded into: _3 = (long unsigned int) _2;
> Folding statement: _6 = _3 + 18446744073709551615;
> (1) Applying pattern match.pd:2060, gimple-match.c:36437
>
> in vrp1.
>
> This is not being handled by (2alt) but by (1).  The same applies for
> long/int instead of ulong/uint except that we don't need range
> information there.
>
> Now, when removing (2) from my patch I run into nasty out-of-mem errors
> during bootstrap which I didn't find the reason for yet.  I thought of
> something like two match.md patterns that keep reverting the other's
> result but I think we have a recursion depth check in place there.
>
> > Also do
> >
> >   if ((did_replace || fold_all_stmts)
> >  && fold_stmt (...))
> >{
> >}
> >
> > to avoid extra work when folding does nothing.
>
> Does this work like this? We want to mark the statement as modified even
> if folding wasn't successful, I guess, and the gimple_set_modified ()
> call should not be that expensive? Could do a separate
>
>  if (fold_all_stmts && fold_stmt (...))

Sure, I was asking for a way to make fold_stmt conditional, it's of course
not 100% as simple as I quoted.

Richard.

> of course.
>
> Regards
>  Robin
>


Re: [PATCH V2 3/8] bpf: new libgcc port

2019-08-19 Thread Jose E. Marchesi


Hi Jeff.
First of all, thanks for reviewing the port.

> +++ b/libgcc/config/bpf/t-bpf
> @@ -0,0 +1,24 @@
> +HOST_LIBGCC2_CFLAGS += -O0
> +LIB2ADDEH = 
I'd like to understand the motivation behind the -O0, but otherwise I
don't see anything particularly concerning here.

Oh that's a reminiscency from earlier development stages when libgcc
wouldn't built with -O2.  I just removed it and everything builds ok.


Re: [PATCH 3/9] operand_equal_p: add support for OBJ_TYPE_REF.

2019-08-19 Thread Richard Biener
On Fri, Aug 16, 2019 at 2:07 PM Jan Hubicka  wrote:
>
> >
> > When we compare OBJ_TYPE_REF_TOKEN and OBJ_TYPE_REF_OBJECT
> > and they are equal, are there cases where types_same_for_odr returns false?
>
> OBJ_TYPE_REF_OBJECT is pointer to the instance, OBJ_TYPE_REF_TOKEN is
> index in the vtable or the type given by obj_ref_type_class.  I guess
> one can do something like
>
>  void *ptr;
>  ...
>  if (cond)
>((class_a *)ptr)->firstvirtualmethod_of_class_a ();
>  else
>((class_b *)ptr)->firstvirtualmethod_of_class_b ();
>
> Here OBJECT will be always *ptr, TOKEN will be 0, but the actual virtual
> method is different. So merging this may lead to invalid
> devirtualization at least when the classes are anonymous namespace and
> we work out late in compilation that they are not derived.

But we also compare OBJ_TYPE_REF_EXPR and later we expand to a call
with exactly that address...

> >
> > I guess we went over this some time ago when talking about value-numbering
> > of them.  I realize the devirt machinery use the class type to get at the
> > virtual table but since we later expand simply OBJ_TPE_REF_EXPR _that_
> > already has the result of the load from the vitual table.
> >
> > So - do we need to compare obj_type_ref_class at all?  The worst thing
> > that could happen is that devirt no longer can devirtualize after the 
> > merging
> > but it should never result in "wrong" devirtualization?  So, do we really
> > want to inhibit ICF of two equal functions that could be eventually
> > devirtualized both but into different direct calls?  Can't this sort of 
> > thing
>
> I think it is like with the TBAA info.  I would suggest first implement
> tests that preserve correctness of both TBAA and devirt annotations.
> Incrementally we can teach ICF to be agressive with -Os and merge anyway
> while dropping the metadata (removing OBJ_TYPE_REF or adjusting alias
> sets
> > happen anyway when you'd factor in IPA-CP and two identical functions
> > with indirect calls to a function argument but called with different 
> > constant
> > args?  And should IPA-CP then not consider cloning after ICF merging
> > (not sure how ordering works here).
>
> I am not sure how those are realated. For sure IPA-CP can clone when it
> works out that different types are passed to the function and
> devirtualize to different calls. But this is bit different - it is about
> the type annotation we
>
> Honza
> >
> > Richard.
> >
> > > Honza
> > > >
> > > > + }
> > > >
> > > >
> > > > > 2019-07-24  Martin Liska  
> > > > >
> > > > > * fold-const.c (operand_equal_p): Support OBJ_TYPE_REF.
> > > > > * tree.c (add_expr): Hash parts of OBJ_TYPE_REF.
> > > > > ---
> > > > >  gcc/fold-const.c | 21 +
> > > > >  gcc/tree.c   |  9 +
> > > > >  2 files changed, 30 insertions(+)
> > > > >


Re: [PATCH 10/N] Use const_tree more in IPA ICF.

2019-08-19 Thread Richard Biener
On Fri, Aug 16, 2019 at 1:06 PM Martin Liška  wrote:
>
> Hi.
>
> The patch is a mechanical clean up that changes some
> functions and data structures to use const_tree instead
> of tree.

I think this kind of changes are obvious.

Richard.

> Martin


Re: Canonicalization of compares performed as side-effect operations

2019-08-19 Thread Richard Earnshaw (lists)

On 14/08/2019 08:48, Eric Botcazou wrote:

[Sorry for the delay, I missed your question...]


Interesting.  Does it work for the general case of a reverse subtract,
which I need to handle as wel?


Not clear, Visium only uses it for SNE and combined NEG/SNE.



I worked through the logic.  I'm pretty sure it will work for any 
unsigned or equality comparison and for any constant.  The general 
transformation is


(cst uns/eq/op reg) == (~reg uns/eq/op ~cst)

R.


Re: PC-relative TLS support

2019-08-19 Thread Segher Boessenkool
On Fri, Aug 16, 2019 at 11:29:30AM +0930, Alan Modra wrote:
> On Thu, Aug 15, 2019 at 01:24:07PM -0500, Segher Boessenkool wrote:
> > On Thu, Aug 15, 2019 at 01:35:10PM +0930, Alan Modra wrote:
> > > Supporting TLS for -mpcrel turns out to be relatively simple, in part
> > > due to deciding that !TARGET_TLS_MARKERS with -mpcrel is silly.  No
> > > assembler that I know of supporting prefix insns lacks TLS marker
> > > support.
> > 
> > Will this stay that way?  (Or do we not care, not now anyway?)
> 
> I'd say we leave that problem to someone who wants pcrel without tls
> markers.  It's not hard to do, just extend rs6000_output_tlsargs and
> adjust IS_NOMARK_TLSGETADDR length attribute expressions.

Okay, so the latter option :-)

> > > Also, at some point powerpc gcc ought to remove
> > > !TARGET_TLS_MARKERS generally and simplify all the occurrences of
> > > IS_NOMARK_TLSGETADDR in rs6000.md rather than complicating them.
> > 
> > The last time this came up (a year ago) the conclusion was that we first
> > would have to remove AIX support.
> 
> Hmm, I wonder has that changed?  A quick look at the source says the
> AIX TLS support uses completely different patterns and shouldn't care.

https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02259.html

But if you think we can remove the !TARGET_TLS_MARKERS everywhere it
is relevant at all, now is the time, patches very welcome, it would be
a nice cleanup :-)  Needs testing everywhere of course, but now is
stage 1 :-)


Segher


Re: [PATCH] Fix 300.twolf regression caused by STV

2019-08-19 Thread Richard Biener
On Mon, 19 Aug 2019, Richard Biener wrote:

> 
> Uros noted that STV with !TImode isn't supposed to run before combine.
> The following adjusts things accordingly and now the pass runs twice
> for TARGET_64BIT.  I've also adjusted another gpr->xmm move to
> use (vec_merge (vec_duplicate..)) style rather than using a subreg.
> This isn't strictly neccesary to fix the bug though and my previous
> needs to do this might have been caused by the pass running too early.
> 
> So - with or without this consistency part?
> 
> Bootstrap / regtest running on x86_64-unknown-linux-gnu, OK?

It regresses

FAIL: gcc.target/i386/minmax-6.c scan-assembler-not rsp

Have to investigate that again then (it caused the change to
use (vec_merge (vec_duplicate..)) for conversion in the first place)

Richard.

> Thanks,
> Richard.
> 
> 2019-08-19  Richard Biener  
> 
>   PR target/91154
>   * config/i386/i386-features.c (general_scalar_chain::convert_op):
>   Use (vec_merge (vec_duplicate..)) style vector from scalar move.
>   (convert_scalars_to_vector): Add timode_p parameter and use it
>   to guard TImode-only operation.
>   (pass_stv::gate): Adjust so STV runs twice for TARGET_64BIT.
>   (pass_stv::execute): Pass down timode_p.
> 
>   * gcc.target/i386/minmax-7.c: New testcase.
> 
> Index: gcc/config/i386/i386-features.c
> ===
> --- gcc/config/i386/i386-features.c   (revision 274666)
> +++ gcc/config/i386/i386-features.c   (working copy)
> @@ -910,7 +910,9 @@ general_scalar_chain::convert_op (rtx *o
>  {
>rtx tmp = gen_reg_rtx (GET_MODE (*op));
>  
> -  emit_insn_before (gen_move_insn (tmp, *op), insn);
> +  emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0),
> +  gen_gpr_to_xmm_move_src (vmode, *op)),
> + insn);
>*op = gen_rtx_SUBREG (vmode, tmp, 0);
>  
>if (dump_file)
> @@ -1664,7 +1666,7 @@ timode_remove_non_convertible_regs (bitm
> instructions into vector mode when profitable.  */
>  
>  static unsigned int
> -convert_scalars_to_vector ()
> +convert_scalars_to_vector (bool timode_p)
>  {
>basic_block bb;
>int converted_insns = 0;
> @@ -1690,7 +1692,7 @@ convert_scalars_to_vector ()
>  {
>rtx_insn *insn;
>FOR_BB_INSNS (bb, insn)
> - if (TARGET_64BIT
> + if (timode_p
>   && timode_scalar_to_vector_candidate_p (insn))
> {
>   if (dump_file)
> @@ -1699,7 +1701,7 @@ convert_scalars_to_vector ()
>  
>   bitmap_set_bit ([2], INSN_UID (insn));
> }
> - else
> + else if (!timode_p)
> {
>   /* Check {SI,DI}mode.  */
>   for (unsigned i = 0; i <= 1; ++i)
> @@ -1715,7 +1717,7 @@ convert_scalars_to_vector ()
> }
>  }
>  
> -  if (TARGET_64BIT)
> +  if (timode_p)
>  timode_remove_non_convertible_regs ([2]);
>for (unsigned i = 0; i <= 1; ++i)
>  general_remove_non_convertible_regs ([i]);
> @@ -1875,13 +1877,13 @@ public:
>/* opt_pass methods: */
>virtual bool gate (function *)
>  {
> -  return (timode_p == !!TARGET_64BIT
> +  return ((!timode_p || TARGET_64BIT)
> && TARGET_STV && TARGET_SSE2 && optimize > 1);
>  }
>  
>virtual unsigned int execute (function *)
>  {
> -  return convert_scalars_to_vector ();
> +  return convert_scalars_to_vector (timode_p);
>  }
>  
>opt_pass *clone ()
> Index: gcc/testsuite/gcc.target/i386/minmax-7.c
> ===
> --- gcc/testsuite/gcc.target/i386/minmax-7.c  (nonexistent)
> +++ gcc/testsuite/gcc.target/i386/minmax-7.c  (working copy)
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=haswell" } */
> +
> +extern int numBins;
> +extern int binOffst;
> +extern int binWidth;
> +extern int Trybin;
> +void foo (int);
> +
> +void bar (int aleft, int axcenter)
> +{
> +  int a1LoBin = (((Trybin=((axcenter + aleft)-binOffst)/binWidth)<0)
> +  ? 0 : ((Trybin>numBins) ? numBins : Trybin));
> +  foo (a1LoBin);
> +}
> +
> +/* We do not want the RA to spill %esi for it's dual-use but using
> +   pminsd is OK.  */
> +/* { dg-final { scan-assembler-not "rsp" { target { ! { ia32 } } } } } */
> +/* { dg-final { scan-assembler "pminsd" } } */
> 

-- 
Richard Biener 
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany;
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah; HRB 21284 (AG Nürnberg)

[PATCH] Fix 300.twolf regression caused by STV

2019-08-19 Thread Richard Biener


Uros noted that STV with !TImode isn't supposed to run before combine.
The following adjusts things accordingly and now the pass runs twice
for TARGET_64BIT.  I've also adjusted another gpr->xmm move to
use (vec_merge (vec_duplicate..)) style rather than using a subreg.
This isn't strictly neccesary to fix the bug though and my previous
needs to do this might have been caused by the pass running too early.

So - with or without this consistency part?

Bootstrap / regtest running on x86_64-unknown-linux-gnu, OK?

Thanks,
Richard.

2019-08-19  Richard Biener  

PR target/91154
* config/i386/i386-features.c (general_scalar_chain::convert_op):
Use (vec_merge (vec_duplicate..)) style vector from scalar move.
(convert_scalars_to_vector): Add timode_p parameter and use it
to guard TImode-only operation.
(pass_stv::gate): Adjust so STV runs twice for TARGET_64BIT.
(pass_stv::execute): Pass down timode_p.

* gcc.target/i386/minmax-7.c: New testcase.

Index: gcc/config/i386/i386-features.c
===
--- gcc/config/i386/i386-features.c (revision 274666)
+++ gcc/config/i386/i386-features.c (working copy)
@@ -910,7 +910,9 @@ general_scalar_chain::convert_op (rtx *o
 {
   rtx tmp = gen_reg_rtx (GET_MODE (*op));
 
-  emit_insn_before (gen_move_insn (tmp, *op), insn);
+  emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0),
+gen_gpr_to_xmm_move_src (vmode, *op)),
+   insn);
   *op = gen_rtx_SUBREG (vmode, tmp, 0);
 
   if (dump_file)
@@ -1664,7 +1666,7 @@ timode_remove_non_convertible_regs (bitm
instructions into vector mode when profitable.  */
 
 static unsigned int
-convert_scalars_to_vector ()
+convert_scalars_to_vector (bool timode_p)
 {
   basic_block bb;
   int converted_insns = 0;
@@ -1690,7 +1692,7 @@ convert_scalars_to_vector ()
 {
   rtx_insn *insn;
   FOR_BB_INSNS (bb, insn)
-   if (TARGET_64BIT
+   if (timode_p
&& timode_scalar_to_vector_candidate_p (insn))
  {
if (dump_file)
@@ -1699,7 +1701,7 @@ convert_scalars_to_vector ()
 
bitmap_set_bit ([2], INSN_UID (insn));
  }
-   else
+   else if (!timode_p)
  {
/* Check {SI,DI}mode.  */
for (unsigned i = 0; i <= 1; ++i)
@@ -1715,7 +1717,7 @@ convert_scalars_to_vector ()
  }
 }
 
-  if (TARGET_64BIT)
+  if (timode_p)
 timode_remove_non_convertible_regs ([2]);
   for (unsigned i = 0; i <= 1; ++i)
 general_remove_non_convertible_regs ([i]);
@@ -1875,13 +1877,13 @@ public:
   /* opt_pass methods: */
   virtual bool gate (function *)
 {
-  return (timode_p == !!TARGET_64BIT
+  return ((!timode_p || TARGET_64BIT)
  && TARGET_STV && TARGET_SSE2 && optimize > 1);
 }
 
   virtual unsigned int execute (function *)
 {
-  return convert_scalars_to_vector ();
+  return convert_scalars_to_vector (timode_p);
 }
 
   opt_pass *clone ()
Index: gcc/testsuite/gcc.target/i386/minmax-7.c
===
--- gcc/testsuite/gcc.target/i386/minmax-7.c(nonexistent)
+++ gcc/testsuite/gcc.target/i386/minmax-7.c(working copy)
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=haswell" } */
+
+extern int numBins;
+extern int binOffst;
+extern int binWidth;
+extern int Trybin;
+void foo (int);
+
+void bar (int aleft, int axcenter)
+{
+  int a1LoBin = (((Trybin=((axcenter + aleft)-binOffst)/binWidth)<0)
+? 0 : ((Trybin>numBins) ? numBins : Trybin));
+  foo (a1LoBin);
+}
+
+/* We do not want the RA to spill %esi for it's dual-use but using
+   pminsd is OK.  */
+/* { dg-final { scan-assembler-not "rsp" { target { ! { ia32 } } } } } */
+/* { dg-final { scan-assembler "pminsd" } } */


Re: [PATCH 2/8] bpf: new GCC port

2019-08-19 Thread Segher Boessenkool
On Thu, Aug 15, 2019 at 12:22:46AM +0200, Jose E. Marchesi wrote:
> --- a/configure
> +++ b/configure
> @@ -754,6 +754,7 @@ infodir
>  docdir
>  oldincludedir
>  includedir
> +runstatedir
>  localstatedir
>  sharedstatedir
>  sysconfdir

(etc.)

You seem to have generated this with the wrong version of auto, or
the wrong options, or the previous version was.  Please check?  Or, what
else caused this change?

> --- a/contrib/config-list.mk
> +++ b/contrib/config-list.mk
> @@ -123,7 +123,7 @@ $(LIST): make-log-dir
>   TGT=`echo $@ | awk 'BEGIN { FS = "OPT" }; { print $$1 }'` &&
> \
>   TGT=`$(GCC_SRC_DIR)/config.sub $$TGT` &&
> \
>   case $$TGT in   
> \
> - *-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix*)  
> \
> + *-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix* | 
> bpf-*-* )   \

This line is too long now.  No space before ) btw.

> + gcc_unreachable ();  
> +  }
> +
> +#define KERNEL_VERSION_CODE "__BPF_KERNEL_VERSION_CODE__="

Trailing whitespace on the first and last of these lines.

> +void
> +bpf_expand_prologue (void)
> +{
> +  int regno, fp_offset;
> +  rtx insn;
> +  HOST_WIDE_INT size;
> +
> +  bpf_compute_frame ();
> +  size = (cfun->machine->local_vars_size
> +   + cfun->machine->callee_saved_reg_size);
> +  fp_offset = -cfun->machine->local_vars_size;
> +  

Trailing ws.

> +   if (!IN_RANGE (fp_offset, -1 - 0x7fff, 0x7fff))

You might want some constraint thing for this, or a helper function?

> + /* This has been already reported as an error in
> +bpf_compute_frame. */
> + break;
> +   else
> + {
> +   mem = gen_frame_mem (DImode,
> +plus_constant (DImode,
> +   gen_rtx_REG (DImode, 
> FRAME_POINTER_REGNUM),

This line is much too long.

> +/* Expand to the instructions in a function epilogue.  This function
> +   is called when expanding the 'prologue' pattern in bpf.md.  */

'epilogue' :-)

> +void
> +bpf_asm_function_prologue (FILE *file ATTRIBUTE_UNUSED)
> +{
> +}
> +
> +#undef TARGET_ASM_FUNCTION_PROLOGUE
> +#define TARGET_ASM_FUNCTION_PROLOGUE bpf_asm_function_prologue

You can just not define these at all, if you want them empty.

> +static unsigned int
> +bpf_hard_regno_nregs (unsigned int regno ATTRIBUTE_UNUSED,
> +   enum machine_mode mode)
> +{
> +  return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
> +}

return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);

(not that that is such an obvious name :-/ )

> +const char *
> +bpf_output_call (rtx target)
> +{
> +  static char *insn;
> +  rtx op;
> +
> +  op = XEXP (target, 0);
> +  switch (GET_CODE (op))
> +{
> +case CONST_INT:
> +  insn = (char *) xmalloc (5 + 6 + 1);
> +  sprintf (insn, "call\t%ld", INTVAL (op));

Will this never overflow?  An %ld can easily be more than 6 characters.
Add a check for it, a gcc_assert or similar?  (Similar for the other
calls).

> +(define_constraint "I"
> +  "A 32-bit signed immediate."
> +  (and (match_code "const_int")
> +   (match_test "IN_RANGE (ival, -1 - 0x7fff, 0x7fff)")))

So you can use  satisfies_constraint_I  instead of the other manual tests
for 32-bit signed.

> +(define_constraint "B"
> +  "A constant argument for LDDW."
> +  (ior (match_code "const,symbol_ref,label_ref,const_double")
> +   (and (match_code "const_int")
> +(match_test "IN_RANGE (ival, -1 - 0x7fff, 
> 0x7fff)"

Are 64-bit hex constants allowed with the minimum C++ version we support?
Also, this test is *always* true.  (And line too long :-) )


Segher


Re: [PATCH V2 8/8] bpf: add myself as the maintainer for the eBPF port

2019-08-19 Thread Segher Boessenkool
On Sat, Aug 17, 2019 at 02:50:56AM +0200, Jose E. Marchesi wrote:
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 5d8402949bc..bcf81e8f337 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -57,6 +57,7 @@ arm portRamana Radhakrishnan
> 
>  arm port Kyrylo Tkachov  
>  avr port Denis Chertykov 
>  bfin portJie Zhang   
> +bpf port Jose E. Marchesi
>  c6x port Bernd Schmidt   
>  cris portHans-Peter Nilsson  
>  c-sky port   Xianmiao Qu 

Don't forget to remove yourself from the Write After Approval section,
when you commit this.


Segher


Re: [PATCH V2 6/8] bpf: adjust GCC testsuite to eBPF limitations

2019-08-19 Thread Segher Boessenkool
On Sun, Aug 18, 2019 at 07:33:20PM -0600, Jeff Law wrote:
> On 8/16/19 6:50 PM, Jose E. Marchesi wrote:
> So I think we probably want an effective target check for indirect calls
> rather than checking explicitly for ebpf in all these files.

+1

> It also seems like rather than checking for ebpf on files with large
> stacks, we should be using the generic mechanisms to defined the allowed
> size of the stack (mentioned in prior review) & mark test which use too
> much space.  This would almost certainly help other embedded targets as
> well.

+2

> Not sure the best way to deal with too many arguments.  I suspect we
> want an efffective target check for that.  Keeping this up-to-date will
> be painful as people write more tests.

You could add a command line option to *allow* many args.  You wouldn't
use that in the kernel, but it helps (compiler) testing a lot.

You could do something similar for indirect jumps, and bigger stack size,
etc.


Segher


Re: [PATCH V2 5/8] bpf: make target-supports.exp aware of eBPF

2019-08-19 Thread Segher Boessenkool
Hi Jose,

On Sat, Aug 17, 2019 at 02:50:53AM +0200, Jose E. Marchesi wrote:
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -526,7 +526,8 @@ proc check_effective_target_trampolines { } {
>|| [istarget nvptx-*-*]
>|| [istarget hppa2.0w-hp-hpux11.23]
>|| [istarget hppa64-hp-hpux11.23]
> -  || [istarget pru-*-*] } {
> +  || [istarget pru-*-*]
> + || [istarget bpf-*-*] } {

There is some whitespace damage here.

> @@ -538,6 +539,9 @@ proc check_effective_target_stack_size { } {
>  if [target_info exists gcc,stack_size] {
>   return 1
>  }
> +if [istarget bpf-*-*] {
> + return 1
> +}

You should still set the proper stack size in your board file, so does
this help you at all?

> @@ -546,7 +550,11 @@ proc check_effective_target_stack_size { } {
>  proc dg-effective-target-value { effective_target } {
>  if { "$effective_target" == "stack_size" } {
>   if [check_effective_target_stack_size] {
> - return [target_info gcc,stack_size]
> + if [istarget bpf-*-*] {
> + return "512"
> + } else {
> + return [target_info gcc,stack_size]
> + }

Yeah okay...  Can't you directly override the gcc,stack_size setting,
instead of doing that in every(?) place it is checked?


Segher


Re: [PATCH] BOZ Documentation update

2019-08-19 Thread Mark Eggleston



On 16/08/2019 15:55, Steve Kargl wrote:

On Fri, Aug 16, 2019 at 03:25:03PM +0100, Mark Eggleston wrote:

In section 6.1.10 BOZ literal constants of the gfortran manual
(gfortran.pdf) the final paragraph refers to integer overflow error. As
a result of Steve Kargl's work on BOZ constants these errors no longer
occur.

This patch deletes the paragraph. I've checked info, pdf, dvi and HTML
documents.

OK to commit?


Yes.  Thanks for cleaning this up.  I've been off fixing
other issues and forgot about updating the docs.


Thanks, committed as revision 274667.

--
https://www.codethink.co.uk/privacy.html



[PATCH] Intrinsic documentation for DIM, MOD and MODULO.

2019-08-19 Thread Mark Eggleston
The intrinsics DIM, MOD and MODULO can accept arguments of different 
kinds and return values with the larger of the two kinds. Notes to this 
effect have been added as they were missing from the documentation.


Please find attached the patch.

ChangeLog:

gcc/fortran/ChangeLog

    Mark Eggleston  

    PR fortran/89236
    * intrinsic.texi: Add GNU extension notes to DIM, MOD, MODULO.

--
https://www.codethink.co.uk/privacy.html

>From 4e527390271f8002f37b33262bd4b4f90ad2062a Mon Sep 17 00:00:00 2001
From: Mark Eggleston 
Date: Tue, 5 Feb 2019 16:38:10 +
Subject: [PATCH] Intrinsic documentation.

---
 gcc/fortran/intrinsic.texi | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index 941c2e39374..4cb0ec8a4cd 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -4876,11 +4876,13 @@ Elemental function
 @item @emph{Arguments}:
 @multitable @columnfractions .15 .70
 @item @var{X} @tab The type shall be @code{INTEGER} or @code{REAL}
-@item @var{Y} @tab The type shall be the same type and kind as @var{X}.
+@item @var{Y} @tab The type shall be the same type and kind as @var{X}.  (As
+a GNU extension, arguments of different kinds are permitted.)
 @end multitable
 
 @item @emph{Return value}:
-The return value is of type @code{INTEGER} or @code{REAL}.
+The return value is of type @code{INTEGER} or @code{REAL}.  (As a GNU
+extension, kind is the largest kind of the actual arguments.)
 
 @item @emph{Example}:
 @smallexample
@@ -10603,14 +10605,16 @@ Elemental function
 @multitable @columnfractions .15 .70
 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}.
 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A} 
-and not equal to zero.
+and not equal to zero.  (As a GNU extension, arguments of different kinds are
+permitted.)
 @end multitable
 
 @item @emph{Return value}:
 The return value is the result of @code{A - (INT(A/P) * P)}. The type
 and kind of the return value is the same as that of the arguments. The
 returned value has the same sign as A and a magnitude less than the
-magnitude of P.
+magnitude of P.  (As a GNU extension, kind is the largest kind of the actual
+arguments.)
 
 @item @emph{Example}:
 @smallexample
@@ -10674,11 +10678,13 @@ Elemental function
 @multitable @columnfractions .15 .70
 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}.
 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}. 
-It shall not be zero.
+It shall not be zero.  (As a GNU extension, arguments of different kinds are
+permitted.)
 @end multitable
 
 @item @emph{Return value}:
-The type and kind of the result are those of the arguments.
+The type and kind of the result are those of the arguments.  (As a GNU
+extension, kind is the largest kind of the actual arguments.)
 @table @asis
 @item If @var{A} and @var{P} are of type @code{INTEGER}:
 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
@@ -12911,7 +12917,7 @@ Elemental function
 @item @emph{Arguments}:
 @multitable @columnfractions .15 .70
 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
-@item @var{B} @tab Shall be of the same type and kind as @var{A}
+@item @var{B} @tab Shall be of the same type and kind as @var{A}.
 @end multitable
 
 @item @emph{Return value}:
-- 
2.11.0



[Ada] Generate ada_target_properties

2019-08-19 Thread Pierre-Marie de Rodat
Generate target-dependent info into a file named ada_target_properties.
This information is used by tools for static analysis: they need to know
the size of standard types for a given run-time library. This metadata
is meant to be saved at the root of the run-time directory.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Jerome Guitton  

gcc/ada/

* Makefile.rtl (system.o): New target to add generation of
target properties.
* gcc-interface/Makefile.in (install-gnatlib): Install
ada_target_properties.--- gcc/ada/Makefile.rtl
+++ gcc/ada/Makefile.rtl
@@ -2696,6 +2696,18 @@ setup-rts: force
 # propagation of exceptions cannot itself be compiled with checks that
 # may give rise to exceptions, e.g. stack overflow checks.
 
+# Generate target-dependent info into a file named ada_target_properties.
+# This information is used by tools for static analysis: they need to know
+# the size of standard types for a given run-time library. This metadata
+# is meant to be saved at the root of the run-time directory.
+
+ADA_TARGET_PROPERTIES = -gnatet=ada_target_properties
+
+system.o  : system.ads
+	$(ADAC) -c $(ALL_ADAFLAGS) $(ADA_INCLUDES) $< \
+	  $(ADA_TARGET_PROPERTIES) \
+	  $(OUTPUT_OPTION)
+
 # Force no sibling call optimization on s-traceb.o so the number of stack
 # frames to be skipped when computing a call chain is not modified by
 # optimization. We don't want inlining, either.

--- gcc/ada/gcc-interface/Makefile.in
+++ gcc/ada/gcc-interface/Makefile.in
@@ -516,6 +516,8 @@ install-gnatlib: ../stamp-gnatlib-$(RTSDIR) install-gcc-specs
 	for file in $(RTSDIR)/*.ali; do \
 	$(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
 	done
+	$(INSTALL_DATA_DATE) $(RTSDIR)/ada_target_properties \
+	$(DESTDIR)$(ADA_RTL_OBJ_DIR)/../
 	-cd $(RTSDIR); for file in *$(arext);do \
 	$(INSTALL_DATA) $$file $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
 	$(RANLIB_FOR_TARGET) $(DESTDIR)$(ADA_RTL_OBJ_DIR)/$$file; \



[Ada] Process type extensions for -gnatw.h

2019-08-19 Thread Pierre-Marie de Rodat
This patch enables gap detection in type extensions.

With the -gnatw.h switch, on 64-bit machines,
the following test should get warnings:

gcc -c gaps.ads -gnatw.h
gaps.ads:16:07: warning: 48-bit gap before component "Comp2"
gaps.ads:17:07: warning: 8-bit gap before component "Comp3"

package Gaps is
   type Integer_16 is mod 2**16;

   type TestGap is tagged record
  Comp1 : Integer_16;
   end record;
   for TestGap use record
  Comp1 at 0 + 8 range 0..15;
   end record;

   type TestGap2 is new TestGap with record
  Comp2  : Integer_16;
  Comp3  : Integer_16;
   end record;
   for TestGap2 use record
  Comp2 at 08 + 8 range 0..15;
  Comp3 at 11 + 8 range 0..15;
   end record;

end Gaps;

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Bob Duff  

gcc/ada/

* sem_ch13.adb (Record_Hole_Check): Procedure to check for holes
that incudes processing type extensions. A type extension is
processed by first calling Record_Hole_Check recursively on the
parent type to compute the bit number after the last component
of the parent.--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -10122,6 +10122,14 @@ package body Sem_Ch13 is
   --  issued, since the message was already given. Comp is also set to
   --  Empty if the current "component clause" is in fact a pragma.
 
+  procedure Record_Hole_Check
+(Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean);
+  --  Checks for gaps in the given Rectype. Compute After_Last, the bit
+  --  number after the last component. Warn is True on the initial call,
+  --  and warnings are given for gaps. For a type extension, this is called
+  --  recursively to compute After_Last for the parent type; in this case
+  --  Warn is False and the warnings are suppressed.
+
   -
   -- Check_Component_Overlap --
   -
@@ -10233,6 +10241,225 @@ package body Sem_Ch13 is
  end if;
   end Find_Component;
 
+  ---
+  -- Record_Hole_Check --
+  ---
+
+  procedure Record_Hole_Check
+(Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean)
+  is
+ Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
+ --  Full declaration of record type
+
+ procedure Check_Component_List
+   (DS   : List_Id;
+CL   : Node_Id;
+Sbit : Uint;
+Abit : out Uint);
+ --  Check component list CL for holes. DS is a list of discriminant
+ --  specifications to be included in the consideration of components.
+ --  Sbit is the starting bit, which is zero if there are no preceding
+ --  components (before a variant part, or a parent type, or a tag
+ --  field). If there are preceding components, Sbit is the bit just
+ --  after the last such component. Abit is set to the bit just after
+ --  the last component of DS and CL.
+
+ --
+ -- Check_Component_List --
+ --
+
+ procedure Check_Component_List
+   (DS   : List_Id;
+CL   : Node_Id;
+Sbit : Uint;
+Abit : out Uint)
+ is
+Compl : Integer;
+
+ begin
+Compl := Integer (List_Length (Component_Items (CL)));
+
+if DS /= No_List then
+   Compl := Compl + Integer (List_Length (DS));
+end if;
+
+declare
+   Comps : array (Natural range 0 .. Compl) of Entity_Id;
+   --  Gather components (zero entry is for sort routine)
+
+   Ncomps : Natural := 0;
+   --  Number of entries stored in Comps (starting at Comps (1))
+
+   Citem : Node_Id;
+   --  One component item or discriminant specification
+
+   Nbit  : Uint;
+   --  Starting bit for next component
+
+   CEnt  : Entity_Id;
+   --  Component entity
+
+   Variant : Node_Id;
+   --  One variant
+
+   function Lt (Op1, Op2 : Natural) return Boolean;
+   --  Compare routine for Sort
+
+   procedure Move (From : Natural; To : Natural);
+   --  Move routine for Sort
+
+   package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
+
+   
+   -- Lt --
+   
+
+   function Lt (Op1, Op2 : Natural) return Boolean is
+   begin
+  return Component_Bit_Offset (Comps (Op1))
+   < Component_Bit_Offset (Comps (Op2));
+   end Lt;
+
+   --
+   -- Move --
+   --
+
+   procedure Move (From : Natural; To : Natural) is
+   begin
+  

[Ada] Add formal function parameter equality to SPARK containers

2019-08-19 Thread Pierre-Marie de Rodat
This patch adds a formal function parameter "=" (L, R : Element_Type) to
SPARK containers. The equality that is used by default for Element_Type
after this patch is the primitive equality and not the predefined any
more. It also allows to use any function with the appropriate signature
for the equality function.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Joffrey Huguet  

gcc/ada/

* libgnat/a-cfdlli.ads, libgnat/a-cfhama.ads,
libgnat/a-cfinve.ads, libgnat/a-cforma.ads,
libgnat/a-cofove.ads, libgnat/a-cofuma.ads,
libgnat/a-cofuve.ads: Add formal function parameter "=" (L, R :
Element_Type) to the generic packages.--- gcc/ada/libgnat/a-cfdlli.ads
+++ gcc/ada/libgnat/a-cfdlli.ads
@@ -34,6 +34,7 @@ with Ada.Containers.Functional_Maps;
 
 generic
type Element_Type is private;
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
 
 package Ada.Containers.Formal_Doubly_Linked_Lists with
   SPARK_Mode

--- gcc/ada/libgnat/a-cfhama.ads
+++ gcc/ada/libgnat/a-cfhama.ads
@@ -59,6 +59,7 @@ generic
with function Equivalent_Keys
  (Left  : Key_Type;
   Right : Key_Type) return Boolean is "=";
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
 
 package Ada.Containers.Formal_Hashed_Maps with
   SPARK_Mode

--- gcc/ada/libgnat/a-cfinve.ads
+++ gcc/ada/libgnat/a-cfinve.ads
@@ -38,6 +38,7 @@ with Ada.Containers.Functional_Vectors;
 generic
type Index_Type is range <>;
type Element_Type (<>) is private;
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
Max_Size_In_Storage_Elements : Natural;
--  Maximum size of Vector elements in bytes. This has the same meaning as
--  in Ada.Containers.Bounded_Holders, with the same restrictions. Note that

--- gcc/ada/libgnat/a-cforma.ads
+++ gcc/ada/libgnat/a-cforma.ads
@@ -58,6 +58,7 @@ generic
type Element_Type is private;
 
with function "<" (Left, Right : Key_Type) return Boolean is <>;
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
 
 package Ada.Containers.Formal_Ordered_Maps with
   SPARK_Mode

--- gcc/ada/libgnat/a-cofove.ads
+++ gcc/ada/libgnat/a-cofove.ads
@@ -40,6 +40,8 @@ with Ada.Containers.Functional_Vectors;
 generic
type Index_Type is range <>;
type Element_Type is private;
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
+
 package Ada.Containers.Formal_Vectors with
   SPARK_Mode
 is

--- gcc/ada/libgnat/a-cofuma.ads
+++ gcc/ada/libgnat/a-cofuma.ads
@@ -39,6 +39,7 @@ generic
with function Equivalent_Keys
  (Left  : Key_Type;
   Right : Key_Type) return Boolean is "=";
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
 
Enable_Handling_Of_Equivalence : Boolean := True;
--  This constant should only be set to False when no particular handling

--- gcc/ada/libgnat/a-cofuve.ads
+++ gcc/ada/libgnat/a-cofuve.ads
@@ -38,6 +38,7 @@ generic
--  should have at least one more element at the low end than Index_Type.
 
type Element_Type (<>) is private;
+   with function "=" (Left, Right : Element_Type) return Boolean is <>;
 
 package Ada.Containers.Functional_Vectors with SPARK_Mode is
 



[Ada] Incorrect code for -gnateV switch

2019-08-19 Thread Pierre-Marie de Rodat
This patch corrects the code generated by the -gnateV switch in the case
of a private type whose full type is a modular type, removing spurious
run-time failures.

In addition, this corrects the initialization of exception occurrences
in exception handlers to avoid leaving data uninitialized, which caused
-gnateV to raise spurious errors.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Bob Duff  

gcc/ada/

* exp_attr.adb (Attribute_Valid): Correct the handling of
private types where the full type is modular. System.Address is
an example. Otherwise, we convert uncheckedly to a signed type,
so we get an incorrect range 0 .. -1, for which all values will
fail.  The 'Valid attribute is illegal for such types, but we
generate such illegal attribute_references for 'Valid_Scalars,
and we generate 'Valid_Scalars when the -gnateV switch is used.
Rename Btyp --> PBtyp to avoid hiding the outer Btyp, which was
confusing.
* libgnat/a-except.adb: Set the Exception_Raised component.
Otherwise, we have incorrect reads of invalid data.

gcc/testsuite/

* gnat.dg/valid_scalars2.adb: New testcase.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -6545,7 +6545,7 @@ package body Exp_Attr is
   --  See separate sections below for the generated code in each case.
 
   when Attribute_Valid => Valid : declare
- Btyp : Entity_Id := Base_Type (Ptyp);
+ PBtyp : Entity_Id := Base_Type (Ptyp);
 
  Save_Validity_Checks_On : constant Boolean := Validity_Checks_On;
  --  Save the validity checking mode. We always turn off validity
@@ -6555,7 +6555,7 @@ package body Exp_Attr is
 
  function Make_Range_Test return Node_Id;
  --  Build the code for a range test of the form
- --Btyp!(Pref) in Btyp!(Ptyp'First) .. Btyp!(Ptyp'Last)
+ --PBtyp!(Pref) in PBtyp!(Ptyp'First) .. PBtyp!(Ptyp'Last)
 
  -
  -- Make_Range_Test --
@@ -6594,16 +6594,16 @@ package body Exp_Attr is
 
 return
   Make_In (Loc,
-Left_Opnd  => Unchecked_Convert_To (Btyp, Temp),
+Left_Opnd  => Unchecked_Convert_To (PBtyp, Temp),
 Right_Opnd =>
   Make_Range (Loc,
 Low_Bound  =>
-  Unchecked_Convert_To (Btyp,
+  Unchecked_Convert_To (PBtyp,
 Make_Attribute_Reference (Loc,
   Prefix => New_Occurrence_Of (Ptyp, Loc),
   Attribute_Name => Name_First)),
 High_Bound =>
-  Unchecked_Convert_To (Btyp,
+  Unchecked_Convert_To (PBtyp,
 Make_Attribute_Reference (Loc,
   Prefix => New_Occurrence_Of (Ptyp, Loc),
   Attribute_Name => Name_Last;
@@ -6631,8 +6631,8 @@ package body Exp_Attr is
  --  Retrieve the base type. Handle the case where the base type is a
  --  private enumeration type.
 
- if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
-Btyp := Full_View (Btyp);
+ if Is_Private_Type (PBtyp) and then Present (Full_View (PBtyp)) then
+PBtyp := Full_View (PBtyp);
  end if;
 
  --  Floating-point case. This case is handled by the Valid attribute
@@ -6665,7 +6665,7 @@ package body Exp_Attr is
 begin
--  The C and AAMP back-ends handle Valid for fpt types
 
-   if Modify_Tree_For_C or else Float_Rep (Btyp) = AAMP then
+   if Modify_Tree_For_C or else Float_Rep (PBtyp) = AAMP then
   Analyze_And_Resolve (Pref, Ptyp);
   Set_Etype (N, Standard_Boolean);
   Set_Analyzed (N);
@@ -6758,13 +6758,13 @@ package body Exp_Attr is
--  The way we do the range check is simply to create the
--  expression: Valid (N) and then Base_Type(Pref) in Typ.
 
-   if not Subtypes_Statically_Match (Ptyp, Btyp) then
+   if not Subtypes_Statically_Match (Ptyp, PBtyp) then
   Rewrite (N,
 Make_And_Then (Loc,
   Left_Opnd  => Relocate_Node (N),
   Right_Opnd =>
 Make_In (Loc,
-  Left_Opnd  => Convert_To (Btyp, Pref),
+  Left_Opnd  => Convert_To (PBtyp, Pref),
   Right_Opnd => New_Occurrence_Of (Ptyp, Loc;
end if;
 end Float_Valid;
@@ -6793,24 +6793,24 @@ package body Exp_Attr is
  --   (X >= type(X)'First and then type(X)'Last <= X)
 
  elsif Is_Enumeration_Type (Ptyp)
-   and then Present (Enum_Pos_To_Rep (Btyp))
+   and then Present 

[Ada] Suppress warnings on unreferenced parameters of dispatching ops

2019-08-19 Thread Pierre-Marie de Rodat
If the -gnatwf switch is used to activate warnings on unreferenced
formal parameters, the warning is no longer given if the subprogram is
dispatching, because such warnings tend to be noise. It is quite common
to have a parameter that is necessary just because the subprogram is
overriding, or just because we need a controlling parameter for the
dispatch.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Bob Duff  

gcc/ada/

* sem_warn.adb (Warn_On_Unreferenced_Entity): Suppress warning
on formal parameters of dispatching operations.

gcc/testsuite/

* gnat.dg/warn29.adb, gnat.dg/warn29.ads: New testcase.--- gcc/ada/sem_warn.adb
+++ gcc/ada/sem_warn.adb
@@ -4407,11 +4407,31 @@ package body Sem_Warn is
 E := Body_E;
  end if;
 
- if not Is_Trivial_Subprogram (Scope (E)) then
-Error_Msg_NE -- CODEFIX
-  ("?u?formal parameter & is not referenced!",
-   E, Spec_E);
- end if;
+ declare
+B : constant Node_Id := Parent (Parent (Scope (E)));
+S : Entity_Id := Empty;
+ begin
+if Nkind_In (B,
+ N_Expression_Function,
+ N_Subprogram_Body,
+ N_Subprogram_Renaming_Declaration)
+then
+   S := Corresponding_Spec (B);
+end if;
+
+--  Do not warn for dispatching operations, because
+--  that causes too much noise. Also do not warn for
+--  trivial subprograms.
+
+if (not Present (S)
+or else not Is_Dispatching_Operation (S))
+  and then not Is_Trivial_Subprogram (Scope (E))
+then
+   Error_Msg_NE -- CODEFIX
+ ("?u?formal parameter & is not referenced!",
+  E, Spec_E);
+end if;
+ end;
   end if;
end if;
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/warn29.adb
@@ -0,0 +1,11 @@
+--  { dg-do compile }
+--  { dg-options "-gnatwa" }
+
+with Text_IO; use Text_IO;
+
+package body Warn29 is
+   procedure P (X : T; Y : Integer) is
+   begin
+  Put_Line ("hello");
+   end P;
+end Warn29;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/warn29.ads
@@ -0,0 +1,4 @@
+package Warn29 is
+   type T is tagged null record;
+   procedure P (X : T; Y : Integer);
+end Warn29;



[Ada] Crash on object initialization that is call to expression function

2019-08-19 Thread Pierre-Marie de Rodat
This patch fixes a compiler abort on an object declaration for a
class-wide type whose expression is a call to an expression function
that returns type extension.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Ed Schonberg  

gcc/ada/

* sem_res.adb (Resolve_Call): A call to an expression function
freezes when expander is active, unless the call appears within
the body of another expression function,

gcc/testsuite/

* gnat.dg/expr_func9.adb: New testcase.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -6314,13 +6314,15 @@ package body Sem_Res is
   --  an expression function may appear when it is part of a default
   --  expression in a call to an initialization procedure, and must be
   --  frozen now, even if the body is inserted at a later point.
+  --  Otherwise, the call freezes the expression if expander is active,
+  --  for example as part of an object declaration.
 
   if Is_Entity_Name (Subp)
 and then not In_Spec_Expression
 and then not Is_Expression_Function_Or_Completion (Current_Scope)
 and then
   (not Is_Expression_Function_Or_Completion (Entity (Subp))
-or else Scope (Entity (Subp)) = Current_Scope)
+or else Expander_Active)
   then
  if Is_Expression_Function (Entity (Subp)) then
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/expr_func9.adb
@@ -0,0 +1,24 @@
+--  { dg-do compile }
+--  { dg-options "-gnatws" }
+
+procedure Expr_Func9 is
+
+   type Root is interface;
+
+   type Child1 is new Root with null record;
+
+   type Child2 is new Root with record
+  I2 : Integer;
+   end record;
+
+   function Create (I : Integer) return Child2 is (I2 => I);
+
+   I : Root'Class :=
+ (if False
+  then Child1'(null record)
+  else
+   Create (1));
+
+begin
+   null;
+end Expr_Func9;



[Ada] Fix incorrect stub generation for types in instances

2019-08-19 Thread Pierre-Marie de Rodat
This fixes a fallout of a recent change clearing the
Is_Generic_Actual_Type on the implicit full view of a private actual
type in an instance.  This flag is used to help disambiguating formal
types instantiated on the same actual type within an instance, but it
should be cleared outside the instance to let the usual disambiguation
rules apply again to these types outside the instance.

This in particular means that Exp_Dist cannot rely on it to detect
subtypes representing generic actual types, hence the need for the new
predicate.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Eric Botcazou  

gcc/ada/

* exp_dist.adb (Is_Generic_Actual_Subtype): New predicate.
(Build_From_Any_Call, Build_To_Any_Call, Build_TypeCode_Call):
Use it instead of Is_Generic_Actual_Type flag to detect subtypes
representing generic actual types.--- gcc/ada/exp_dist.adb
+++ gcc/ada/exp_dist.adb
@@ -8201,6 +8201,12 @@ package body Exp_Dist is
  --  type from Interfaces, or the smallest floating point type from
  --  Standard whose range encompasses that of Typ.
 
+ function Is_Generic_Actual_Subtype (Typ : Entity_Id) return Boolean;
+ --  Return true if Typ is a subtype representing a generic formal type
+ --  as a subtype of the actual type in an instance. This is needed to
+ --  recognize these subtypes because the Is_Generic_Actual_Type flag
+ --  can only be relied upon within the instance.
+
  function Make_Helper_Function_Name
(Loc : Source_Ptr;
 Typ : Entity_Id;
@@ -8453,7 +8459,7 @@ package body Exp_Dist is
 --  For the subtype representing a generic actual type, go to the
 --  actual type.
 
-if Is_Generic_Actual_Type (U_Type) then
+if Is_Generic_Actual_Subtype (U_Type) then
U_Type := Underlying_Type (Base_Type (U_Type));
 end if;
 
@@ -9262,7 +9268,7 @@ package body Exp_Dist is
 --  For the subtype representing a generic actual type, go to the
 --  actual type.
 
-if Is_Generic_Actual_Type (U_Type) then
+if Is_Generic_Actual_Subtype (U_Type) then
U_Type := Underlying_Type (Base_Type (U_Type));
 end if;
 
@@ -10116,7 +10122,7 @@ package body Exp_Dist is
 --  For the subtype representing a generic actual type, go to the
 --  actual type.
 
-if Is_Generic_Actual_Type (U_Type) then
+if Is_Generic_Actual_Subtype (U_Type) then
U_Type := Underlying_Type (Base_Type (U_Type));
 end if;
 
@@ -10901,6 +10907,30 @@ package body Exp_Dist is
 
  end Find_Numeric_Representation;
 
+ -
+ --  Is_Generic_Actual_Subtype  --
+ -
+
+ function Is_Generic_Actual_Subtype (Typ : Entity_Id) return Boolean is
+ begin
+if Is_Itype (Typ)
+  and then Present (Associated_Node_For_Itype (Typ))
+then
+   declare
+  N : constant Node_Id := Associated_Node_For_Itype (Typ);
+   begin
+  if Nkind (N) = N_Subtype_Declaration
+and then Nkind (Parent (N)) = N_Package_Specification
+and then Is_Generic_Instance (Scope_Of_Spec (Parent (N)))
+  then
+ return True;
+  end if;
+   end;
+end if;
+
+return False;
+ end Is_Generic_Actual_Subtype;
+
  ---
  -- Append_Array_Traversal --
  ---



[Ada] Conversion routines between GNAT.OS_Lib.OS_Time and long integer

2019-08-19 Thread Pierre-Marie de Rodat
The new routines convert back and forth between private type OS_Time and
a long integer which can be used in package Ada.Calendar.Conversions
routines to convert to Ada.Calendar.Time.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Dmitriy Anisimkov  

gcc/ada/

* libgnat/s-os_lib.ads, libgnat/s-os_lib.adb (To_Ada, To_C): New
routines.--- gcc/ada/libgnat/s-os_lib.adb
+++ gcc/ada/libgnat/s-os_lib.adb
@@ -2979,6 +2979,15 @@ package body System.OS_Lib is
   end loop;
end Spawn_Internal;
 
+   
+   -- To_Ada --
+   
+
+   function To_Ada (Time : time_t) return OS_Time is
+   begin
+  return OS_Time (Time);
+   end To_Ada;
+
---
-- To_Path_String_Access --
---
@@ -3008,6 +3017,15 @@ package body System.OS_Lib is
   return Return_Val;
end To_Path_String_Access;
 
+   --
+   -- To_C --
+   --
+
+   function To_C (Time : OS_Time) return time_t is
+   begin
+  return time_t (Time);
+   end To_C;
+
--
-- Wait_Process --
--

--- gcc/ada/libgnat/s-os_lib.ads
+++ gcc/ada/libgnat/s-os_lib.ads
@@ -164,6 +164,15 @@ package System.OS_Lib is
--  component parts to be interpreted in the local time zone, and returns
--  an OS_Time. Returns Invalid_Time if the creation fails.
 
+   subtype time_t is Long_Integer;
+   --  C time_t type of the time representation
+
+   function To_C (Time : OS_Time) return time_t;
+   --  Convert OS_Time to C time_t type
+
+   function To_Ada (Time : time_t) return OS_Time;
+   --  Convert C time_t type to OS_Time
+

-- File Stuff --

@@ -1107,6 +1116,8 @@ private
pragma Inline (">");
pragma Inline ("<=");
pragma Inline (">=");
+   pragma Inline (To_C);
+   pragma Inline (To_Ada);
 
type Process_Id is new Integer;
Invalid_Pid : constant Process_Id := -1;



[Ada] Lift restriction on instantiations that are compilation units

2019-08-19 Thread Pierre-Marie de Rodat
This change lifts the restriction that was still present in the new
on-demand instantiation scheme for the body of generics instantiated in
non-main units.

The instantiations that are compilation units were still dealt with in
the old-fashioned way, that is to say the decision of instantiating the
body was still made up front during the analysis of the instance
declaration, instead of being deferred until after a call to an inlined
subprogram is encountered.

This should save a few more cycles when full inlining across units is
enabled, but there should otherwise be no functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Eric Botcazou  

gcc/ada/

* inline.adb (Add_Inlined_Body): Do not special-case instances
that are compilation units.
(Add_Pending_Instantiation): Likewise.
(Instantiate_Body): Skip instantiations that are compilation
units and have already been performed.
* sem_ch12.adb (Needs_Body_Instantiated): Do not special-case
instances that are compilation units.
(Load_Parent_Of_Generic): Be prepared for parent that is a
compilation unit but whose instantiation node has not been
replaced.

gcc/testsuite/

* gnat.dg/generic_inst12.adb, gnat.dg/generic_inst12_pkg1.adb,
gnat.dg/generic_inst12_pkg1.ads,
gnat.dg/generic_inst12_pkg2.ads: New testcase.--- gcc/ada/inline.adb
+++ gcc/ada/inline.adb
@@ -611,12 +611,11 @@ package body Inline is
   Inst_Decl := Unit_Declaration_Node (Inst);
 
   --  Do not inline the instance if the body already exists,
-  --  or if the instance is a compilation unit, or else if
-  --  the instance node is simply missing.
+  --  or the instance node is simply missing.
 
   if Present (Corresponding_Body (Inst_Decl))
-or else Nkind (Parent (Inst_Decl)) = N_Compilation_Unit
-or else No (Next (Inst_Decl))
+or else (Nkind (Parent (Inst_Decl)) /= N_Compilation_Unit
+  and then No (Next (Inst_Decl)))
   then
  Set_Is_Called (Inst);
   else
@@ -797,13 +796,11 @@ package body Inline is
 
  To_Pending_Instantiations.Set (Act_Decl, Index);
 
- --  If an instantiation is either a compilation unit or is in the main
- --  unit or subunit or is a nested subprogram, then its body is needed
- --  as per the analysis already done in Analyze_Package_Instantiation
- --  and Analyze_Subprogram_Instantiation.
+ --  If an instantiation is in the main unit or subunit, or is a nested
+ --  subprogram, then its body is needed as per the analysis done in
+ --  Analyze_Package_Instantiation & Analyze_Subprogram_Instantiation.
 
- if Nkind (Parent (Inst)) = N_Compilation_Unit
-   or else In_Main_Unit_Or_Subunit (Act_Decl_Id)
+ if In_Main_Unit_Or_Subunit (Act_Decl_Id)
or else (Is_Subprogram (Act_Decl_Id)
  and then Is_Nested (Act_Decl_Id))
  then
@@ -4460,6 +4457,13 @@ package body Inline is
  if No (Info.Inst_Node) then
 null;
 
+ --  If the instantiation node is a package body, this means that the
+ --  instance is a compilation unit and the instantiation has already
+ --  been performed by Build_Instance_Compilation_Unit_Nodes.
+
+ elsif Nkind (Info.Inst_Node) = N_Package_Body then
+null;
+
  elsif Nkind (Info.Act_Decl) = N_Package_Declaration then
 Instantiate_Package_Body (Info);
 Add_Scope_To_Clean (Defining_Entity (Info.Act_Decl));

--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -3921,19 +3921,15 @@ package body Sem_Ch12 is
 return False;
  end if;
 
- --  Here we have a special handling for back-end inlining: if the
- --  instantiation is not a compilation unit, then we want to have
- --  its body instantiated. The reason is that Might_Inline_Subp
- --  does not catch all the cases (since it does not recurse into
- --  nested packages) so this avoids the need to patch things up
- --  at a later stage. Moreover the instantiations that are not
- --  compilation units are only performed on demand when back-end
+ --  Here we have a special handling for back-end inlining: if inline
+ --  processing is required, then we unconditionally want to have the
+ --  body instantiated. The reason is that Might_Inline_Subp does not
+ --  catch all the cases (as it does not recurse into nested packages)
+ --  so this avoids the need to patch things up afterwards. Moreover,
+ --  these instantiations are only performed on demand when back-end
  --  inlining is enabled, so this causes very 

[Ada] Fix bogus compilation error with Elaborate_Body and -gnatN

2019-08-19 Thread Pierre-Marie de Rodat
This fixes a bogus compilation error when a unit with SPARK_Mode
containing a pragma Elaborate_Body is with-ed by a generic unit
containing an inlined subprogram, and front-end inlining is enabled.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Eric Botcazou  

gcc/ada/

* sem_prag.adb (Is_Before_First_Decl): Deal with rewritten
pragmas.

gcc/testsuite/

* gnat.dg/elab8.adb, gnat.dg/elab8_gen.adb,
gnat.dg/elab8_gen.ads, gnat.dg/elab8_pkg.adb,
gnat.dg/elab8_pkg.ads: New testcase.--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -7146,10 +7146,11 @@ package body Sem_Prag is
  Item : Node_Id := First (Decls);
 
   begin
- --  Only other pragmas can come before this pragma
+ --  Only other pragmas can come before this pragma, but they might
+ --  have been rewritten so check the original node.
 
  loop
-if No (Item) or else Nkind (Item) /= N_Pragma then
+if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
return False;
 
 elsif Item = Pragma_Node then

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8.adb
@@ -0,0 +1,12 @@
+--  { dg-do compile }
+--  { dg-options "-gnatN" }
+
+with Elab8_Gen;
+
+procedure Elab8 is
+
+  package My_G is new Elab8_Gen  (Integer);
+
+begin
+  My_G.Compare (0, 1);
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_gen.adb
@@ -0,0 +1,12 @@
+with Elab8_Pkg;
+
+package body Elab8_Gen is
+
+  procedure Compare (Arg1, Arg2 : T) is
+  begin
+if Arg1 = Arg2 then
+  raise Program_Error;
+end if;
+  end;
+
+end Elab8_Gen;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_gen.ads
@@ -0,0 +1,8 @@
+generic
+  type T is private;
+package Elab8_Gen is
+
+  procedure Compare (Arg1, Arg2 : T);
+  pragma Inline (Compare);
+
+end Elab8_Gen;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_pkg.adb
@@ -0,0 +1,5 @@
+package body Elab8_Pkg is
+
+  procedure Dummy is null;
+
+end Elab8_Pkg;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_pkg.ads
@@ -0,0 +1,5 @@
+package Elab8_Pkg with SPARK_Mode is
+
+  pragma Elaborate_Body;
+
+end Elab8_Pkg;



[Ada] Fix internal error on subprogram instantiation with -gnatzc

2019-08-19 Thread Pierre-Marie de Rodat
This fixes a fallout of the recent change keeping the
Is_Generic_Instance flag on the wrapper package built for the
instantiation of a generic subprogram.

There is no need to visit the Instance_Spec of an
N_Subprogram_Instantiation node anymore because the regular processing
for an N_Package_Declaration node now does the job for instantiations of
generic subprograms.

The following subprogram must compile again quietly with -gnatzc:

with Gen_Proc;

package RCI is
   pragma Remote_Call_Interface;

   procedure Inst_Proc is new Gen_Proc;

   procedure P (S : String);
end RCI;

generic
procedure Gen_Proc (S : String);
pragma Remote_Call_Interface (Gen_Proc);

with Ada.Text_IO; use Ada.Text_IO;
procedure Gen_Proc (S : String) is
begin
   Put_Line ("Gen_Proc called: " & S);
end Gen_Proc;

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-19  Eric Botcazou  

gcc/ada/

* exp_dist.adb (Build_Package_Stubs): Do not specifically visit
the declarations of an N_Subprogram_Instantiation node.--- gcc/ada/exp_dist.adb
+++ gcc/ada/exp_dist.adb
@@ -963,10 +963,8 @@ package body Exp_Dist is
 when N_Package_Declaration =>
 
--  Case of a nested package or package instantiation coming
-   --  from source. Note that the anonymous wrapper package for
-   --  subprogram instances is not flagged Is_Generic_Instance at
-   --  this point, so there is a distinct circuit to handle them
-   --  (see case N_Subprogram_Instantiation below).
+   --  from source, including the wrapper package for an instance
+   --  of a generic subprogram.
 
declare
   Pkg_Ent : constant Entity_Id :=
@@ -982,16 +980,6 @@ package body Exp_Dist is
   end if;
end;
 
-when N_Subprogram_Instantiation =>
-
-   --  The subprogram declaration for an instance of a generic
-   --  subprogram is wrapped in a package that does not come from
-   --  source, so we need to explicitly traverse it here.
-
-   if Comes_From_Source (Decl) then
-  Visit_Nested_Pkg (Instance_Spec (Decl));
-   end if;
-
 when others =>
null;
  end case;



  1   2   >