Re: [PATCH] [ARC] Add support for HS4x cpus.

2018-07-06 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-06-13 12:09:18 +0300]:

> From: Claudiu Zissulescu 
> 
> This patch adds support for two ARCHS variations.
> 
> Ok to apply?
> Claudiu

Sorry for the delay, this looks fine.

Thanks,
Andrew



> 
> gcc/
> 2017-03-10  Claudiu Zissulescu  
> 
>   * config/arc/arc-arch.h (arc_tune_attr): Add new tune parameters
>   for ARCHS4x.
>   * config/arc/arc-cpus.def (hs4x): New cpu.
>   (hs4xd): Likewise.
>   * config/arc/arc-tables.opt: Regenerate.
>   * config/arc/arc.c (arc_sched_issue_rate): New function.
>   (TARGET_SCHED_ISSUE_RATE): Define.
>   (TARGET_SCHED_EXPOSED_PIPELINE): Likewise.
>   * config/arc/arc.md (attr type): Add fpu_fuse, fpu_sdiv, fpu_ddiv,
>   fpu_cvt.
>   (attr tune): Add ARCHS4x tune values.
>   (attr tune_dspmpy): Define.
>   (*tst): Correct instruction type.
>   * config/arc/arcHS.md: Don't use this automaton for ARCHS4x cpus.
>   * config/arc/arcHS4x.md: New file.
>   * config/arc/fpu.md: Update instruction type attributes.
>   * config/arc/t-multilib: Regenerate.
> ---
>  gcc/config/arc/arc-arch.h |   5 +-
>  gcc/config/arc/arc-cpus.def   |   8 +-
>  gcc/config/arc/arc-tables.opt |   6 +
>  gcc/config/arc/arc.c  |  19 +++
>  gcc/config/arc/arc.md |  24 +++-
>  gcc/config/arc/arcHS.md   |   6 +
>  gcc/config/arc/arcHS4x.md | 221 ++
>  gcc/config/arc/fpu.md |  16 +--
>  8 files changed, 289 insertions(+), 16 deletions(-)
>  create mode 100644 gcc/config/arc/arcHS4x.md
> 
> diff --git a/gcc/config/arc/arc-arch.h b/gcc/config/arc/arc-arch.h
> index 64866dd529b..01f95946623 100644
> --- a/gcc/config/arc/arc-arch.h
> +++ b/gcc/config/arc/arc-arch.h
> @@ -73,7 +73,10 @@ enum arc_tune_attr
>  ARC_TUNE_ARC600,
>  ARC_TUNE_ARC700_4_2_STD,
>  ARC_TUNE_ARC700_4_2_XMAC,
> -ARC_TUNE_CORE_3
> +ARC_TUNE_CORE_3,
> +ARC_TUNE_ARCHS4X,
> +ARC_TUNE_ARCHS4XD,
> +ARC_TUNE_ARCHS4XD_SLOW
>};
>  
>  /* CPU specific properties.  */
> diff --git a/gcc/config/arc/arc-cpus.def b/gcc/config/arc/arc-cpus.def
> index 1fce81f6933..4aa422f1a39 100644
> --- a/gcc/config/arc/arc-cpus.def
> +++ b/gcc/config/arc/arc-cpus.def
> @@ -59,10 +59,12 @@ ARC_CPU (archs,hs, FL_MPYOPT_2|FL_DIVREM|FL_LL64, 
> NONE)
>  ARC_CPU (hs34,hs, FL_MPYOPT_2, NONE)
>  ARC_CPU (hs38,hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64, NONE)
>  ARC_CPU (hs38_linux, hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64|FL_FPU_FPUD_ALL, NONE)
> +ARC_CPU (hs4x,  hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64, ARCHS4X)
> +ARC_CPU (hs4xd, hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64, ARCHS4XD)
>  
> -ARC_CPU (arc600,   6xx, FL_BS, ARC600)
> -ARC_CPU (arc600_norm,  6xx, FL_BS|FL_NORM, ARC600)
> -ARC_CPU (arc600_mul64, 6xx, FL_BS|FL_NORM|FL_MUL64, ARC600)
> +ARC_CPU (arc600,  6xx, FL_BS, ARC600)
> +ARC_CPU (arc600_norm, 6xx, FL_BS|FL_NORM, ARC600)
> +ARC_CPU (arc600_mul64,6xx, FL_BS|FL_NORM|FL_MUL64, ARC600)
>  ARC_CPU (arc600_mul32x16, 6xx, FL_BS|FL_NORM|FL_MUL32x16, ARC600)
>  ARC_CPU (arc601,   6xx, 0, ARC600)
>  ARC_CPU (arc601_norm,  6xx, FL_NORM, ARC600)
> diff --git a/gcc/config/arc/arc-tables.opt b/gcc/config/arc/arc-tables.opt
> index 3b17b3de7d5..2afaf5bd83c 100644
> --- a/gcc/config/arc/arc-tables.opt
> +++ b/gcc/config/arc/arc-tables.opt
> @@ -63,6 +63,12 @@ Enum(processor_type) String(hs38) Value(PROCESSOR_hs38)
>  EnumValue
>  Enum(processor_type) String(hs38_linux) Value(PROCESSOR_hs38_linux)
>  
> +EnumValue
> +Enum(processor_type) String(hs4x) Value(PROCESSOR_hs4x)
> +
> +EnumValue
> +Enum(processor_type) String(hs4xd) Value(PROCESSOR_hs4xd)
> +
>  EnumValue
>  Enum(processor_type) String(arc600) Value(PROCESSOR_arc600)
>  
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 2bedc9af37e..03a2f4223c0 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -483,6 +483,22 @@ arc_autovectorize_vector_sizes (vector_sizes *sizes)
>  }
>  }
>  
> +
> +/* Implements target hook TARGET_SCHED_ISSUE_RATE.  */
> +static int
> +arc_sched_issue_rate (void)
> +{
> +  switch (arc_tune)
> +{
> +case TUNE_ARCHS4X:
> +case TUNE_ARCHS4XD:
> +  return 3;
> +default:
> +  break;
> +}
> +  return 1;
> +}
> +
>  /* TARGET_PRESERVE_RELOAD_P is still awaiting patch re-evaluation / review.  
> */
>  static bool arc_preserve_reload_p (rtx in) ATTRIBUTE_UNUSED;
>  static rtx arc_delegitimize_address (rtx);
> @@ -565,6 +581,9 @@ static rtx arc_legitimize_address_0 (rtx, rtx, 
> machine_mode mode);
>  #undef  TARGET_SCHED_ADJUST_PRIORITY
>  #define TARGET_SCHED_ADJUST_PRIORITY arc_sched_adjust_priority
>  
> +#undef TARGET_SCHED_ISSUE_RATE
> +#define TARGET_SCHED_ISSUE_RATE arc_sched_issue_rate
> +
>  #undef TARGET_VECTOR_MODE_SUPPORTED_P
>  #define TARGET_VECTOR_MODE_SUPPORTED_P arc_vector_mode_supported_p
>  
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 091f1092bed..5610b

Re: [PATCH 1/4] [ARC] Add more additional register names

2018-07-25 Thread Andrew Burgess
All the patches in this series look fine.

Thanks,
Andrew


* Claudiu Zissulescu  [2018-07-16 15:29:42 +0300]:

> From: claziss 
> 
> gcc/
> 2017-06-14  Claudiu Zissulescu  
> 
>   * config/arc/arc.h (ADDITIONAL_REGISTER_NAMES): Add additional
>   register names.
> ---
>  gcc/config/arc/arc.h | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index 1780034aabe..3648314eaca 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -1215,7 +1215,15 @@ extern char rname56[], rname57[], rname58[], rname59[];
>  {\
>{"ilink",  29},\
>{"r29",29},\
> -  {"r30",30} \
> +  {"r30",30},\
> +  {"r40",40},\
> +  {"r41",41},\
> +  {"r42",42},\
> +  {"r43",43},\
> +  {"r56",56},\
> +  {"r57",57},\
> +  {"r58",58},\
> +  {"r59",59} \
>  }
>  
>  /* Entry to the insn conditionalizer.  */
> -- 
> 2.17.1
> 


[PATCH] gdb: Add a dependency between gdb and libbacktrace

2021-08-30 Thread Andrew Burgess
I plan to make use of libbacktrace within GDB.  I believe that the
patch below needs to be merged into GCCs toplevel directory and then
back-ported to the binutils-gdb repository.

Is this OK to merge?

Thanks,
Andrew

---

GDB is going to start using libbacktrace, so add a build dependency
between the two projects.  This change needs to be added into the GCC
toplevel files, and then back-ported to the binutils-gdb repository.

ChangeLog:

* Makefile.def: Add all-gdb dependency on all-libbacktrace.
* Makefile.in: Regenerate.
---
 ChangeLog| 5 +
 Makefile.def | 1 +
 Makefile.in  | 1 +
 3 files changed, 7 insertions(+)

diff --git a/Makefile.def b/Makefile.def
index fbfdb6fee08..de3e0052106 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -423,6 +423,7 @@ dependencies = { module=all-gdb; on=all-sim; };
 dependencies = { module=all-gdb; on=all-libdecnumber; };
 dependencies = { module=all-gdb; on=all-libtermcap; };
 dependencies = { module=all-gdb; on=all-libctf; };
+dependencies = { module=all-gdb; on=all-libbacktrace; };
 
 // Host modules specific to gdbserver.
 dependencies = { module=configure-gdbserver; on=all-gnulib; };
diff --git a/Makefile.in b/Makefile.in
index 5c85fcc5dd0..61af99dc75a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -61237,6 +61237,7 @@ all-gdb: maybe-all-libiconv
 all-gdb: maybe-all-opcodes
 all-gdb: maybe-all-libdecnumber
 all-gdb: maybe-all-libctf
+all-gdb: maybe-all-libbacktrace
 all-gdbserver: maybe-all-libiberty
 configure-gdbsupport: maybe-configure-intl
 all-gdbsupport: maybe-all-intl
-- 
2.25.4



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

2019-10-28 Thread Andrew Burgess
* Jim Wilson  [2019-10-22 16:34:53 -0700]:

> On Mon, Oct 21, 2019 at 5:26 AM Andrew Burgess
>  wrote:
> > Below is a new versions of this patch, I believe that this addresses
> > the review comments from the earlier version.  In addition this has
> > been tested using Jim's idea of forcing -msave-restore (if the flag is
> > not otherwise given) and I now see no test failures for newlib and
> > linux toolchains.
> >
> > One thing that has been mentioned briefly was adding a flag to control
> > just this optimisation, I haven't done that yet, but can if that is
> > required - obviously this optimisation doesn't do anything if
> > -msave-restore is turned off, so that is always an option.  With no
> > test failures I don't know if a separate flag is required.
> 
> I can live without the flag to control it, since as you mention
> -msave-restore will turn it off.
> 
> I'm seeing failures with the new save-restore-4.c testcase for 32-bit
> targets.  It works for 64-bit but not for 32-bit, because the
> sign-extension it is checking for only happens for 64-bit targets.
> The testcase should check for a target of riscv64*-*-* or else hard
> code -march=rv64gc etc options.  Either fix seems reasonable.
> 
> You fixed some British spellings of optimise to optimize, but there
> are two new comments that add two more uses of optimise which is
> inconsistent.
> 
> I also noticed a "useage" that should be "usage".
> 
> Otherwise this looks good to me.  It is OK to check in with the above
> minor issues fixed.

Jim,

Thanks for all your help reviewing this patch.

I've now merged this with fixes for the issues you identified above.
Let me know if you run into any problems.

Thanks,
Andrew


[PATCH] gcc: Add new configure options to allow static libraries to be selected

2020-01-22 Thread Andrew Burgess
The motivation behind this change is to make it easier for a user to
link against static libraries on a target where dynamic libraries are
the default library type (for example GNU/Linux).

Further, my motivation is really for linking libraries into GDB,
however, the binutils-gdb/config/ directory is a copy of gcc/config/
so changes for GDB need to be approved by the GCC project first.

After making this change in the gcc/config/ directory I've run
autoreconf on all of the configure scripts in the GCC tree and a
couple have been updated, so I'll use one of these to describe what my
change does.

Consider libcpp, this library links against libiconv.  Currently if
the user builds on a system with both static and dynamic libiconv
installed then autotools will pick up the dynamic libiconv by
default.  This is almost certainly the right thing to do.

However, if the user wants to link against static libiconv then things
are a little harder, they could remove the dynamic libiconv from their
system, but this is probably a bad idea (other things might depend on
that library), or the user can build their own version of libiconv,
install it into a unique prefix, and then configure gcc using the
--with-libiconv-prefix=DIR flag.  This works fine, but is somewhat
annoying, the static library available, I just can't get autotools to
use it.

My change then adds a new flag --with-libiconv-type=TYPE, where type
is either auto, static, or shared.  The default auto, ensures we keep
the existing behaviour unchanged.

If the user configures with --with-libiconv-type=static then the
configure script will ignore any dynamic libiconv it finds, and will
only look for a static libiconv, if no static libiconv is found then
the configure will continue as though there is no libiconv at all
available.

Similarly a user can specify --with-libiconv-type=shared and force the
use of shared libiconv, any static libiconv will be ignored.

As I've implemented this change within the AC_LIB_LINKFLAGS_BODY macro
then only libraries configured using the AC_LIB_LINKFLAGS or
AC_LIB_HAVE_LINKFLAGS macros will gain the new configure flag.

If this is accepted into GCC then there will be follow on patches for
binutils and GDB to regenerate some configure scripts in those
projects.

For GCC only two configure scripts needed updated after this commit,
libcpp and libstdc++-v3, both of which link against libiconv.

config/ChangeLog:

* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
--with-libXXX-type=... option.  Use this to guide the selection of
either a shared library or a static library.

libcpp/ChangeLog:

* configure: Regnerate.

libstdc++-v3/ChangeLog:

* configure: Regnerate.
---
 config/ChangeLog   |  6 ++
 config/lib-link.m4 | 22 --
 libcpp/ChangeLog   |  4 
 libcpp/configure   | 29 +++--
 libstdc++-v3/ChangeLog |  4 
 libstdc++-v3/configure | 47 ---
 6 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/config/lib-link.m4 b/config/lib-link.m4
index eeb200d266d..662192e0a07 100644
--- a/config/lib-link.m4
+++ b/config/lib-link.m4
@@ -150,6 +150,11 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
   fi
 fi
 ])
+  AC_LIB_ARG_WITH([lib$1-type],
+[  --with-lib$1-type=TYPE type of library to search for 
(auto/static/shared) ],
+  [ with_lib$1_type=$withval ], [ with_lib$1_type=auto ])
+  lib_type=`eval echo \$with_lib$1_type`
+
   dnl Search the library and its dependencies in $additional_libdir and
   dnl $LDFLAGS. Using breadth-first-seach.
   LIB[]NAME=
@@ -195,13 +200,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
   found_so=
   found_a=
   if test $use_additional = yes; then
-if test -n "$shlibext" && test -f 
"$additional_libdir/lib$name.$shlibext"; then
+if test -n "$shlibext" && test -f 
"$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
   found_dir="$additional_libdir"
   found_so="$additional_libdir/lib$name.$shlibext"
   if test -f "$additional_libdir/lib$name.la"; then
 found_la="$additional_libdir/lib$name.la"
   fi
-else
+elif test x$lib_type != xshared; then
   if test -f "$additional_libdir/lib$name.$libext"; then
 found_dir="$additional_libdir"
 found_a="$additional_libdir/lib$name.$libext"
@@ -217,13 +222,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
   case "$x" in
 -L*)
   dir=`echo "X$x" | sed -e 's/^X-L//'`
-  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; 
then
+  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" 
&& test x$lib_type != xstatic; then
 found_dir="$dir"
 found_so="$dir/lib$name.$shlibext"
 if test -f "$d

Re: [PATCH] gcc: Add new configure options to allow static libraries to be selected

2020-01-27 Thread Andrew Burgess
* Jeff Law  [2020-01-22 13:52:27 -0700]:

> On Wed, 2020-01-22 at 15:39 +0000, Andrew Burgess wrote:
> > The motivation behind this change is to make it easier for a user to
> > link against static libraries on a target where dynamic libraries are
> > the default library type (for example GNU/Linux).
> > 
> > Further, my motivation is really for linking libraries into GDB,
> > however, the binutils-gdb/config/ directory is a copy of gcc/config/
> > so changes for GDB need to be approved by the GCC project first.
> > 
> > After making this change in the gcc/config/ directory I've run
> > autoreconf on all of the configure scripts in the GCC tree and a
> > couple have been updated, so I'll use one of these to describe what my
> > change does.
> > 
> > Consider libcpp, this library links against libiconv.  Currently if
> > the user builds on a system with both static and dynamic libiconv
> > installed then autotools will pick up the dynamic libiconv by
> > default.  This is almost certainly the right thing to do.
> > 
> > However, if the user wants to link against static libiconv then things
> > are a little harder, they could remove the dynamic libiconv from their
> > system, but this is probably a bad idea (other things might depend on
> > that library), or the user can build their own version of libiconv,
> > install it into a unique prefix, and then configure gcc using the
> > --with-libiconv-prefix=DIR flag.  This works fine, but is somewhat
> > annoying, the static library available, I just can't get autotools to
> > use it.
> > 
> > My change then adds a new flag --with-libiconv-type=TYPE, where type
> > is either auto, static, or shared.  The default auto, ensures we keep
> > the existing behaviour unchanged.
> > 
> > If the user configures with --with-libiconv-type=static then the
> > configure script will ignore any dynamic libiconv it finds, and will
> > only look for a static libiconv, if no static libiconv is found then
> > the configure will continue as though there is no libiconv at all
> > available.
> > 
> > Similarly a user can specify --with-libiconv-type=shared and force the
> > use of shared libiconv, any static libiconv will be ignored.
> > 
> > As I've implemented this change within the AC_LIB_LINKFLAGS_BODY macro
> > then only libraries configured using the AC_LIB_LINKFLAGS or
> > AC_LIB_HAVE_LINKFLAGS macros will gain the new configure flag.
> > 
> > If this is accepted into GCC then there will be follow on patches for
> > binutils and GDB to regenerate some configure scripts in those
> > projects.
> > 
> > For GCC only two configure scripts needed updated after this commit,
> > libcpp and libstdc++-v3, both of which link against libiconv.
> > 
> > config/ChangeLog:
> > 
> > * lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
> > --with-libXXX-type=... option.  Use this to guide the selection of
> > either a shared library or a static library.
> > 
> > libcpp/ChangeLog:
> > 
> > * configure: Regnerate.
> > 
> > libstdc++-v3/ChangeLog:
> > 
> > * configure: Regnerate.
> s/Regnerate/Regenerate/
> 
> This isn't strictly a regression bugfix.  But given the nature of these
> files I think we probably need to be a bit more lax and allow safe
> changes so that downstream uses can move forward independent of the gcc
> development and release schedule.
> 
> So, OK.

Thanks for the flexibility.  Now pushed.

Thanks,
Andrew


[PATCH] libiberty/hashtab: More const parameters

2020-01-27 Thread Andrew Burgess
I know that the tree's currently closed to non-bugfix changes, but I
was hoping this might be accpeted anyway so it can be backported to
binutils-gdb.

---

Makes some parameters const in libiberty's hashtab library.

include/ChangeLog:

* hashtab.h (htab_remove_elt): Make a parameter const.
(htab_remove_elt_with_hash): Likewise.

libiberty/ChangeLog:

* hashtab.c (htab_remove_elt): Make a parameter const.
(htab_remove_elt_with_hash): Likewise.
---
 include/ChangeLog   | 5 +
 include/hashtab.h   | 4 ++--
 libiberty/ChangeLog | 5 +
 libiberty/hashtab.c | 4 ++--
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/hashtab.h b/include/hashtab.h
index d94b54c3c41..6cca342b989 100644
--- a/include/hashtab.h
+++ b/include/hashtab.h
@@ -173,8 +173,8 @@ extern void *   htab_find_with_hash (htab_t, const void 
*, hashval_t);
 extern void ** htab_find_slot_with_hash (htab_t, const void *,
  hashval_t, enum insert_option);
 extern voidhtab_clear_slot (htab_t, void **);
-extern voidhtab_remove_elt (htab_t, void *);
-extern voidhtab_remove_elt_with_hash (htab_t, void *, hashval_t);
+extern voidhtab_remove_elt (htab_t, const void *);
+extern voidhtab_remove_elt_with_hash (htab_t, const void *, hashval_t);
 
 extern voidhtab_traverse (htab_t, htab_trav, void *);
 extern voidhtab_traverse_noresize (htab_t, htab_trav, void *);
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index 26c98ce2d68..225e9e540a7 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -709,7 +709,7 @@ htab_find_slot (htab_t htab, const PTR element, enum 
insert_option insert)
element in the hash table, this function does nothing.  */
 
 void
-htab_remove_elt (htab_t htab, PTR element)
+htab_remove_elt (htab_t htab, const PTR element)
 {
   htab_remove_elt_with_hash (htab, element, (*htab->hash_f) (element));
 }
@@ -720,7 +720,7 @@ htab_remove_elt (htab_t htab, PTR element)
function does nothing.  */
 
 void
-htab_remove_elt_with_hash (htab_t htab, PTR element, hashval_t hash)
+htab_remove_elt_with_hash (htab_t htab, const PTR element, hashval_t hash)
 {
   PTR *slot;
 
-- 
2.14.5



Re: [PATCH] gcc: Add new configure options to allow static libraries to be selected

2020-01-30 Thread Andrew Burgess
* Iain Sandoe  [2020-01-28 10:34:52 +]:

> Hi Andrew,
> 
> Andrew Burgess  wrote:
> 
> > * Jeff Law  [2020-01-22 13:52:27 -0700]:
> > 
> > > On Wed, 2020-01-22 at 15:39 +, Andrew Burgess wrote:
> > > > The motivation behind this change is to make it easier for a user to
> > > > link against static libraries on a target where dynamic libraries are
> > > > the default library type (for example GNU/Linux).
> > > > 
> > > > Further, my motivation is really for linking libraries into GDB,
> > > > however, the binutils-gdb/config/ directory is a copy of gcc/config/
> > > > so changes for GDB need to be approved by the GCC project first.
> > > > 
> > > > After making this change in the gcc/config/ directory I've run
> > > > autoreconf on all of the configure scripts in the GCC tree and a
> > > > couple have been updated, so I'll use one of these to describe what my
> > > > change does.
> > > > 
> > > > Consider libcpp, this library links against libiconv.  Currently if
> > > > the user builds on a system with both static and dynamic libiconv
> > > > installed then autotools will pick up the dynamic libiconv by
> > > > default.  This is almost certainly the right thing to do.
> > > > 
> > > > However, if the user wants to link against static libiconv then things
> > > > are a little harder, they could remove the dynamic libiconv from their
> > > > system, but this is probably a bad idea (other things might depend on
> > > > that library), or the user can build their own version of libiconv,
> > > > install it into a unique prefix, and then configure gcc using the
> > > > --with-libiconv-prefix=DIR flag.  This works fine, but is somewhat
> > > > annoying, the static library available, I just can't get autotools to
> > > > use it.
> > > > 
> > > > My change then adds a new flag --with-libiconv-type=TYPE, where type
> > > > is either auto, static, or shared.  The default auto, ensures we keep
> > > > the existing behaviour unchanged.
> > > > 
> > > > If the user configures with --with-libiconv-type=static then the
> > > > configure script will ignore any dynamic libiconv it finds, and will
> > > > only look for a static libiconv, if no static libiconv is found then
> > > > the configure will continue as though there is no libiconv at all
> > > > available.
> > > > 
> > > > Similarly a user can specify --with-libiconv-type=shared and force the
> > > > use of shared libiconv, any static libiconv will be ignored.
> > > > 
> > > > As I've implemented this change within the AC_LIB_LINKFLAGS_BODY macro
> > > > then only libraries configured using the AC_LIB_LINKFLAGS or
> > > > AC_LIB_HAVE_LINKFLAGS macros will gain the new configure flag.
> > > > 
> > > > If this is accepted into GCC then there will be follow on patches for
> > > > binutils and GDB to regenerate some configure scripts in those
> > > > projects.
> > > > 
> > > > For GCC only two configure scripts needed updated after this commit,
> > > > libcpp and libstdc++-v3, both of which link against libiconv.
> 
> This kinda surprises me, gcc/ also configures for iconv
> 
> > > > config/ChangeLog:
> > > > 
> > > > * lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
> > > > --with-libXXX-type=... option.  Use this to guide the selection 
> > > > of
> > > > either a shared library or a static library.
> > > > 
> > > > libcpp/ChangeLog:
> > > > 
> > > > * configure: Regnerate.
> > > > 
> > > > libstdc++-v3/ChangeLog:
> > > > 
> > > > * configure: Regnerate.
> > > s/Regnerate/Regenerate/
> > > 
> > > This isn't strictly a regression bugfix.  But given the nature of these
> > > files I think we probably need to be a bit more lax and allow safe
> > > changes so that downstream uses can move forward independent of the gcc
> > > development and release schedule.
> > > 
> > > So, OK.
> > 
> > Thanks for the flexibility.  Now pushed.
> 
> this (r10-6269,
> https://gcc.gnu.org/g:e7c26e04b2dd6266d62d5a5825ff7eb44d1cf14e) causes or
> exposes a problem which breaks bootstrap on all Darwin platforms I tried.
> 
> Bo

Re: [PATCH] gcc: Add new configure options to allow static libraries to be selected

2020-01-30 Thread Andrew Burgess
* Iain Sandoe  [2020-01-30 15:21:08 +]:

> >> Can you clarify why there’s no need to match the configury changes in 
> >> libcpp
> >> / gcc / libstdc++ ?
> > 
> > This is the same issue that Tobias pointed out, and was a result of me
> > incorrectly trying to regenerate the configure files.
> 
> .. but it seems that the combination of the two things produced the 
> configuration
> mismatch ..
> 
> > Let me know if this resolves the problems you're seeing and if it does
> > I'll prepare it for submission.
> 
> I did a smoke test on Darwin19 and the amended patch allowed bootstrap to
>  complete. ICONV is seen in both libcpp and gcc (that’s not an exhaustive 
> check
> and the testsuite is still running).
> 
> I’ll add this to my overnight runs - “overnight” means results later tomorrow 
> for the
> slower targets - but it looks encouraging.

Thanks, for checking this so quickly.

I'll prepare this as a proper patch and post this again later tonight
for review, but if your results are good tomorrow then I'll go ahead
and push this.

Thanks,
Andrew


Re: [PATCH] gcc: Add new configure options to allow static libraries to be selected

2020-01-30 Thread Andrew Burgess
Here's a cleaned up version of the previous patch I posted.  If Iain
reports this fixes the regressions he saw then I will push this.

All feedback welcome.

Thanks,
Andrew

---

>From 876996580d64d31407357787fc5df7bd5699b2c0 Mon Sep 17 00:00:00 2001
From: Andrew Burgess 
Date: Thu, 30 Jan 2020 12:18:13 +
Subject: [PATCH] Fixes after recent configure changes relating to static
 libraries

This commit:

  commit e7c26e04b2dd6266d62d5a5825ff7eb44d1cf14e (tjteru/master)
  Date:   Wed Jan 22 14:54:26 2020 +

  gcc: Add new configure options to allow static libraries to be selected

contains a couple of issues.  First I failed to correctly regenerate
all of the configure files it should have done.  Second, there was a
mistake in lib-link.m4, one of the conditions didn't use pure sh
syntax, I wrote this:

  if x$lib_type = xauto || x$lib_type = xshared; then

When I should have written this:

  if test "x$lib_type" = "xauto" || test "x$lib_type" = "xshared"; then

These issues were raised on the mailing list in these messages:

  https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01827.html
  https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01921.html

config/ChangeLog:

* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Update shell syntax.

gcc/ChangeLog:

* configure: Regenerate.

intl/ChangeLog:

* configure: Regenerate.

libcpp/ChangeLog:

* configure: Regenerate.

libstdc++-v3/ChangeLog:

* configure: Regenerate.
---
 config/ChangeLog   |  4 
 config/lib-link.m4 |  2 +-
 gcc/ChangeLog  |  4 
 gcc/configure  | 29 +++--
 intl/ChangeLog |  4 
 intl/configure | 58 +++---
 libcpp/ChangeLog   |  4 
 libcpp/configure   |  2 +-
 libstdc++-v3/ChangeLog |  4 
 libstdc++-v3/configure |  2 +-
 10 files changed, 92 insertions(+), 21 deletions(-)

diff --git a/config/lib-link.m4 b/config/lib-link.m4
index 662192e0a07..20e281fd323 100644
--- a/config/lib-link.m4
+++ b/config/lib-link.m4
@@ -492,7 +492,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
 dnl known to the linker and runtime loader. (All the system
 dnl directories known to the linker should also be known to the
 dnl runtime loader, otherwise the system is severely 
misconfigured.)
-if x$lib_type = xauto || x$lib_type = xshared; then
+if test "x$lib_type" = "xauto" || test "x$lib_type" = "xshared"; 
then
   LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
   LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
 else
diff --git a/gcc/configure b/gcc/configure
index e2c8fc71772..4c2c5991c0e 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -974,6 +974,7 @@ with_zstd_include
 with_zstd_lib
 enable_rpath
 with_libiconv_prefix
+with_libiconv_type
 enable_sjlj_exceptions
 with_gcc_major_version_only
 enable_secureplt
@@ -1811,6 +1812,7 @@ Optional Packages:
   --with-gnu-ld   assume the C compiler uses GNU ld default=no
   --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
   --without-libiconv-prefix don't search for libiconv in includedir and 
libdir
+  --with-libiconv-type=TYPE type of library to search for 
(auto/static/shared)
   --with-gcc-major-version-only
   use only GCC major number in filesystem paths
   --with-pic  try to use only PIC/non-PIC objects [default=use
@@ -10730,6 +10732,16 @@ if test "${with_libiconv_prefix+set}" = set; then :
 
 fi
 
+
+# Check whether --with-libiconv-type was given.
+if test "${with_libiconv_type+set}" = set; then :
+  withval=$with_libiconv_type;  with_libiconv_type=$withval
+else
+   with_libiconv_type=auto
+fi
+
+  lib_type=`eval echo \$with_libiconv_type`
+
   LIBICONV=
   LTLIBICONV=
   INCICONV=
@@ -10767,13 +10779,13 @@ fi
   found_so=
   found_a=
   if test $use_additional = yes; then
-if test -n "$shlibext" && test -f 
"$additional_libdir/lib$name.$shlibext"; then
+if test -n "$shlibext" && test -f 
"$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
   found_dir="$additional_libdir"
   found_so="$additional_libdir/lib$name.$shlibext"
   if test -f "$additional_libdir/lib$name.la"; then
 found_la="$additional_libdir/lib$name.la"
   fi
-else
+elif test x$lib_type != xshared; then
   if test -f "$additional_libdir/lib$name.$libext"; then
 found_dir="$additional_libdir"
 found_a="$additional_libdir/lib$name.$libext"
@@ -107

Re: [PATCH] gcc: Add new configure options to allow static libraries to be selected

2020-01-31 Thread Andrew Burgess
* Iain Sandoe  [2020-01-31 20:18:58 +]:

> Hello Andrew,
> 
> Andrew Burgess  wrote:
> 
> > Here's a cleaned up version of the previous patch I posted.  If Iain
> > reports this fixes the regressions he saw then I will push this.
> 
> I applied this to r10-6364 and tested on a bunch of Darwin platforms.
> 
> AFAICT, the configuration now reports consistent values between
> libcpp, gcc, intl, and libstdc++-v3.
> 
> Bootstrap succeeded with my “normal” defaults, and testing appears
> nominal.
> 
> Notes:
> 
> * I have only tested on Darwin, I’m assuming you have tested on other
>  platforms.
> 
> * there are now a number of interacting ICONV options, I made no
>  attempt to test multiple permutations.

Thanks, I've gone ahead and pushed this fix.  I tested this on my
local machine with no issues, and with your positive results I think I
should get this in sooner rather than later.

Once again, sorry for the breakage.

Thanks,
Andrew


[PATCH] top-level configure: setup target_configdirs based on repository

2021-09-22 Thread Andrew Burgess
The top-level configure script is shared between the gcc repository
and the binutils-gdb repository.

The target_configdirs variable in the configure.ac script, defines
sub-directories that contain components that should be built for the
target using the target tools.

Some components, e.g. zlib, are built as both host and target
libraries.

This causes problems for binutils-gdb.  If we run 'make all' in the
binutils-gdb repository we end up trying to build a target version of
the zlib library, which requires the target compiler be available.
Often the target compiler isn't immediately available, and so the
build fails.

The problem with zlib impacted a previous attempt to synchronise the
top-level configure scripts from gcc to binutils-gdb, see this thread:

  https://sourceware.org/pipermail/binutils/2019-May/107094.html

And I'm in the process of importing libbacktrace in to binutils-gdb,
which is also a host and target library, and triggers the same issues.

I believe that for binutils-gdb, at least at the moment, there are no
target libraries that we need to build.

My proposal then is to make the value of target_libraries change based
on which repository we are building in.  Specifically, if the source
tree has a gcc/ directory then we should set the target_libraries
variable, otherwise this variable is left entry.

I think that if someone tries to create a single unified tree (gcc +
binutils-gdb in a single source tree) and then build, this change will
not have a negative impact, the tree still has gcc/ so we'd expect the
target compiler to be built, which means building the target_libraries
should work just fine.

However, if the source tree lacks gcc/ then we assume the target
compiler isn't built/available, and so target_libraries shouldn't be
built.

There is already precedent within configure.ac for check on the
existence of gcc/ in the source tree, see the handling of
-enable-werror around line 3658.

I've tested a build of gcc on x86-64, and the same set of target
libraries still seem to get built.  On binutils-gdb this change
resolves the issues with 'make all'.

Any thoughts?

ChangeLog:

* configure: Regenerate.
* configure.ac (target_configdirs): Only set this when building
within the gcc repository.
---
 ChangeLog|  6 ++
 configure| 12 ++--
 configure.ac | 12 ++--
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 85ab9915402..3ef5c2b553f 100755
--- a/configure
+++ b/configure
@@ -2849,9 +2849,17 @@ target_tools="target-rda"
 ## We assign ${configdirs} this way to remove all embedded newlines.  This
 ## is important because configure will choke if they ever get through.
 ## ${configdirs} is directories we build using the host tools.
-## ${target_configdirs} is directories we build using the target tools.
+##
+## ${target_configdirs} is directories we build using the target
+## tools, these are only needed when working in the gcc tree.  This
+## file is also reused in the binutils-gdb tree, where building any
+## target stuff doesn't make sense.
 configdirs=`echo ${host_libs} ${host_tools}`
-target_configdirs=`echo ${target_libraries} ${target_tools}`
+if test -d ${srcdir}/gcc; then
+  target_configdirs=`echo ${target_libraries} ${target_tools}`
+else
+  target_configdirs=""
+fi
 build_configdirs=`echo ${build_libs} ${build_tools}`
 
 
diff --git a/configure.ac b/configure.ac
index 1df038b04f3..d1217e3f886 100644
--- a/configure.ac
+++ b/configure.ac
@@ -180,9 +180,17 @@ target_tools="target-rda"
 ## We assign ${configdirs} this way to remove all embedded newlines.  This
 ## is important because configure will choke if they ever get through.
 ## ${configdirs} is directories we build using the host tools.
-## ${target_configdirs} is directories we build using the target tools.
+##
+## ${target_configdirs} is directories we build using the target
+## tools, these are only needed when working in the gcc tree.  This
+## file is also reused in the binutils-gdb tree, where building any
+## target stuff doesn't make sense.
 configdirs=`echo ${host_libs} ${host_tools}`
-target_configdirs=`echo ${target_libraries} ${target_tools}`
+if test -d ${srcdir}/gcc; then
+  target_configdirs=`echo ${target_libraries} ${target_tools}`
+else
+  target_configdirs=""
+fi
 build_configdirs=`echo ${build_libs} ${build_tools}`
 
 m4_divert_text([PARSE_ARGS],
-- 
2.25.4



Re: [PATCH] top-level configure: setup target_configdirs based on repository

2021-09-24 Thread Andrew Burgess
* Richard Biener  [2021-09-23 10:53:16 +0200]:

> On Wed, Sep 22, 2021 at 5:47 PM Andrew Burgess
>  wrote:
> >
> > The top-level configure script is shared between the gcc repository
> > and the binutils-gdb repository.
> >
> > The target_configdirs variable in the configure.ac script, defines
> > sub-directories that contain components that should be built for the
> > target using the target tools.
> >
> > Some components, e.g. zlib, are built as both host and target
> > libraries.
> >
> > This causes problems for binutils-gdb.  If we run 'make all' in the
> > binutils-gdb repository we end up trying to build a target version of
> > the zlib library, which requires the target compiler be available.
> > Often the target compiler isn't immediately available, and so the
> > build fails.
> >
> > The problem with zlib impacted a previous attempt to synchronise the
> > top-level configure scripts from gcc to binutils-gdb, see this thread:
> >
> >   https://sourceware.org/pipermail/binutils/2019-May/107094.html
> >
> > And I'm in the process of importing libbacktrace in to binutils-gdb,
> > which is also a host and target library, and triggers the same issues.
> >
> > I believe that for binutils-gdb, at least at the moment, there are no
> > target libraries that we need to build.
> >
> > My proposal then is to make the value of target_libraries change based
> > on which repository we are building in.  Specifically, if the source
> > tree has a gcc/ directory then we should set the target_libraries
> > variable, otherwise this variable is left entry.
> >
> > I think that if someone tries to create a single unified tree (gcc +
> > binutils-gdb in a single source tree) and then build, this change will
> > not have a negative impact, the tree still has gcc/ so we'd expect the
> > target compiler to be built, which means building the target_libraries
> > should work just fine.
> >
> > However, if the source tree lacks gcc/ then we assume the target
> > compiler isn't built/available, and so target_libraries shouldn't be
> > built.
> >
> > There is already precedent within configure.ac for check on the
> > existence of gcc/ in the source tree, see the handling of
> > -enable-werror around line 3658.
> >
> > I've tested a build of gcc on x86-64, and the same set of target
> > libraries still seem to get built.  On binutils-gdb this change
> > resolves the issues with 'make all'.
> >
> > Any thoughts?
> 
> Hmm, why not use make all-binutils instead?

That absolutely would work, but sucks when I have to say 'make
all-binutils all-gas all-ld all-gdb' when 'make all' used to work.

>  Otherwise this does
> look like a reasonable thing to do.

Thanks.  I'm reworking things anyway based on Thomas's feedback.

Andrew


> 
> Richard.
> 
> > ChangeLog:
> >
> > * configure: Regenerate.
> > * configure.ac (target_configdirs): Only set this when building
> > within the gcc repository.
> > ---
> >  ChangeLog|  6 ++
> >  configure| 12 ++--
> >  configure.ac | 12 ++--
> >  3 files changed, 26 insertions(+), 4 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 85ab9915402..3ef5c2b553f 100755
> > --- a/configure
> > +++ b/configure
> > @@ -2849,9 +2849,17 @@ target_tools="target-rda"
> >  ## We assign ${configdirs} this way to remove all embedded newlines.  This
> >  ## is important because configure will choke if they ever get through.
> >  ## ${configdirs} is directories we build using the host tools.
> > -## ${target_configdirs} is directories we build using the target tools.
> > +##
> > +## ${target_configdirs} is directories we build using the target
> > +## tools, these are only needed when working in the gcc tree.  This
> > +## file is also reused in the binutils-gdb tree, where building any
> > +## target stuff doesn't make sense.
> >  configdirs=`echo ${host_libs} ${host_tools}`
> > -target_configdirs=`echo ${target_libraries} ${target_tools}`
> > +if test -d ${srcdir}/gcc; then
> > +  target_configdirs=`echo ${target_libraries} ${target_tools}`
> > +else
> > +  target_configdirs=""
> > +fi
> >  build_configdirs=`echo ${build_libs} ${build_tools}`
> >
> >
> > diff --git a/configure.ac b/configure.ac
> > index 1df038b04f3..d1217e3f886 100644
> > --- a/co

[PATCHv2] top-level configure: setup target_configdirs based on repository

2021-09-24 Thread Andrew Burgess
* Thomas Schwinge  [2021-09-23 11:29:05 +0200]:

> Hi!
> 
> I only had a curious look here; hope that's still useful.
> 
> On 2021-09-22T16:30:42+0100, Andrew Burgess  
> wrote:
> > The top-level configure script is shared between the gcc repository
> > and the binutils-gdb repository.
> >
> > The target_configdirs variable in the configure.ac script, defines
> > sub-directories that contain components that should be built for the
> > target using the target tools.
> >
> > Some components, e.g. zlib, are built as both host and target
> > libraries.
> >
> > This causes problems for binutils-gdb.  If we run 'make all' in the
> > binutils-gdb repository we end up trying to build a target version of
> > the zlib library, which requires the target compiler be available.
> > Often the target compiler isn't immediately available, and so the
> > build fails.
> 
> I did wonder: shouldn't normally these target libraries be masked out via
> 'noconfigdirs' (see 'Handle --disable- generically' section),
> via 'enable_[...]' being set to 'no'?  But I think I now see the problem
> here: the 'enable_[...]' variables guard both the host and target library
> build!  (... if I'm quickly understanding that correctly...)
> 
> ... and you do need the host zlib, thus '$enable_zlib != no'.
> 
> > The problem with zlib impacted a previous attempt to synchronise the
> > top-level configure scripts from gcc to binutils-gdb, see this thread:
> >
> >   https://sourceware.org/pipermail/binutils/2019-May/107094.html
> >
> > And I'm in the process of importing libbacktrace in to binutils-gdb,
> > which is also a host and target library, and triggers the same issues.
> >
> > I believe that for binutils-gdb, at least at the moment, there are no
> > target libraries that we need to build.
> >
> > My proposal then is to make the value of target_libraries change based
> > on which repository we are building in.  Specifically, if the source
> > tree has a gcc/ directory then we should set the target_libraries
> > variable, otherwise this variable is left entry.
> >
> > I think that if someone tries to create a single unified tree (gcc +
> > binutils-gdb in a single source tree) and then build, this change will
> > not have a negative impact, the tree still has gcc/ so we'd expect the
> > target compiler to be built, which means building the target_libraries
> > should work just fine.
> >
> > However, if the source tree lacks gcc/ then we assume the target
> > compiler isn't built/available, and so target_libraries shouldn't be
> > built.
> >
> > There is already precedent within configure.ac for check on the
> > existence of gcc/ in the source tree, see the handling of
> > -enable-werror around line 3658.
> 
> (I understand that one to just guard the 'cat $srcdir/gcc/DEV-PHASE',
> tough.)
> 
> > I've tested a build of gcc on x86-64, and the same set of target
> > libraries still seem to get built.  On binutils-gdb this change
> > resolves the issues with 'make all'.
> >
> > Any thoughts?
> 
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -180,9 +180,17 @@ target_tools="target-rda"
> >  ## We assign ${configdirs} this way to remove all embedded newlines.  This
> >  ## is important because configure will choke if they ever get through.
> >  ## ${configdirs} is directories we build using the host tools.
> > -## ${target_configdirs} is directories we build using the target tools.
> > +##
> > +## ${target_configdirs} is directories we build using the target
> > +## tools, these are only needed when working in the gcc tree.  This
> > +## file is also reused in the binutils-gdb tree, where building any
> > +## target stuff doesn't make sense.
> >  configdirs=`echo ${host_libs} ${host_tools}`
> > -target_configdirs=`echo ${target_libraries} ${target_tools}`
> > +if test -d ${srcdir}/gcc; then
> > +  target_configdirs=`echo ${target_libraries} ${target_tools}`
> > +else
> > +  target_configdirs=""
> > +fi
> >  build_configdirs=`echo ${build_libs} ${build_tools}`
> 
> What I see is that after this, there are still occasions where inside
> 'case "${target}"', 'target_configdirs' gets amended, so those won't be
> caught by your approach?

Good point, I'd failed to spot these.

> 
> Instead of erasing 'target_configdirs' as you've posted, and
> understan

[PATCH] top-level: merge Makefile.def patches from binutils-gdb repository

2021-09-24 Thread Andrew Burgess
This commit back-ports two patches to Makefile.def from the
binutils-gdb repository, these patches were committed over there
without first being merged in to the gcc repository.

These commits all relate to dependencies for binutils-gdb modules, so
should have no impact on gcc, I tested a gcc build/install on x86-64
GNU/Linux, and everything looked OK.

The two patches being backported are binutils-gdb commits:

  commit ba4d88ad892fe29c6ca7938c8861f8edef5f7a3f (gdb-gnulib-issues)
  Date:   Mon Oct 12 16:04:32 2020 +0100

  gdb/gdbserver: add dependencies for distclean-gnulib

And

  commit 755ba58ebef02e1be9fc6770d00243ba6ed0223c
  Date:   Thu Mar 18 12:37:52 2021 +

  Add install dependencies for ld -> bfd and libctf -> bfd

OK to merge?

2021-09-07  Andrew Burgess  

Merge from binutils-gdb:
2021-09-08  Nick Alcock  

PR libctf/27482
* Makefile.def: Add install-bfd dependencies for install-libctf and
install-ld, and install-strip-bfd dependencies for
install-strip-libctf and install-strip-ld; move the install-ld
dependency on install-libctf to join it.
* Makefile.in: Regenerated.

And:
2020-10-14  Andrew Burgess  

* Makefile.in: Rebuild.
* Makefile.def: Make distclean-gnulib depend on distclean-gdb and
distclean-gdbserver.
---
 ChangeLog| 19 +++
 Makefile.def | 14 ++
 Makefile.in  |  8 
 3 files changed, 41 insertions(+)

diff --git a/Makefile.def b/Makefile.def
index de3e0052106..143a6b469b2 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -471,6 +471,14 @@ dependencies = { module=all-ld; on=all-libctf; };
 dependencies = { module=install-binutils; on=install-opcodes; };
 dependencies = { module=install-strip-binutils; on=install-strip-opcodes; };
 
+// Likewise for ld, libctf, and bfd.
+dependencies = { module=install-libctf; on=install-bfd; };
+dependencies = { module=install-ld; on=install-bfd; };
+dependencies = { module=install-ld; on=install-libctf; };
+dependencies = { module=install-strip-libctf; on=install-strip-bfd; };
+dependencies = { module=install-strip-ld; on=install-strip-bfd; };
+dependencies = { module=install-strip-ld; on=install-strip-libctf; };
+
 // libopcodes depends on libbfd
 dependencies = { module=install-opcodes; on=install-bfd; };
 dependencies = { module=install-strip-opcodes; on=install-strip-bfd; };
@@ -564,6 +572,12 @@ dependencies = { module=configure-libctf; on=all-zlib; };
 dependencies = { module=configure-libctf; on=all-libiconv; };
 dependencies = { module=check-libctf; on=all-ld; };
 
+// The Makefiles in gdb and gdbserver pull in a file that configure
+// generates in the gnulib directory, so distclean gnulib only after
+// gdb and gdbserver.
+dependencies = { module=distclean-gnulib; on=distclean-gdb; };
+dependencies = { module=distclean-gnulib; on=distclean-gdbserver; };
+
 // Warning, these are not well tested.
 dependencies = { module=all-bison; on=all-intl; };
 dependencies = { module=all-bison; on=all-build-texinfo; };
diff --git a/Makefile.in b/Makefile.in
index 61af99dc75a..7613da5a378 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -60763,6 +60763,12 @@ all-stageautoprofile-ld: 
maybe-all-stageautoprofile-libctf
 all-stageautofeedback-ld: maybe-all-stageautofeedback-libctf
 install-binutils: maybe-install-opcodes
 install-strip-binutils: maybe-install-strip-opcodes
+install-libctf: maybe-install-bfd
+install-ld: maybe-install-bfd
+install-ld: maybe-install-libctf
+install-strip-libctf: maybe-install-strip-bfd
+install-strip-ld: maybe-install-strip-bfd
+install-strip-ld: maybe-install-strip-libctf
 install-opcodes: maybe-install-bfd
 install-strip-opcodes: maybe-install-strip-bfd
 configure-gas: maybe-configure-intl
@@ -61131,6 +61137,8 @@ check-stagetrain-libctf: maybe-all-stagetrain-ld
 check-stagefeedback-libctf: maybe-all-stagefeedback-ld
 check-stageautoprofile-libctf: maybe-all-stageautoprofile-ld
 check-stageautofeedback-libctf: maybe-all-stageautofeedback-ld
+distclean-gnulib: maybe-distclean-gdb
+distclean-gnulib: maybe-distclean-gdbserver
 all-bison: maybe-all-build-texinfo
 all-flex: maybe-all-build-bison
 all-flex: maybe-all-m4
-- 
2.25.4



Re: [PATCH] top-level: merge Makefile.def patches from binutils-gdb repository

2021-09-24 Thread Andrew Burgess
* Richard Biener  [2021-09-24 13:58:20 +0200]:

> On Fri, Sep 24, 2021 at 12:49 PM Andrew Burgess
>  wrote:
> >
> > This commit back-ports two patches to Makefile.def from the
> > binutils-gdb repository, these patches were committed over there
> > without first being merged in to the gcc repository.
> >
> > These commits all relate to dependencies for binutils-gdb modules, so
> > should have no impact on gcc, I tested a gcc build/install on x86-64
> > GNU/Linux, and everything looked OK.
> >
> > The two patches being backported are binutils-gdb commits:
> >
> >   commit ba4d88ad892fe29c6ca7938c8861f8edef5f7a3f (gdb-gnulib-issues)
> >   Date:   Mon Oct 12 16:04:32 2020 +0100
> >
> >   gdb/gdbserver: add dependencies for distclean-gnulib
> >
> > And
> >
> >   commit 755ba58ebef02e1be9fc6770d00243ba6ed0223c
> >   Date:   Thu Mar 18 12:37:52 2021 +
> >
> >   Add install dependencies for ld -> bfd and libctf -> bfd
> >
> > OK to merge?
> 
> OK.

Thanks, I pushed this patch.

Andrew


Re: [PATCHv2] top-level configure: setup target_configdirs based on repository

2021-09-28 Thread Andrew Burgess
* Richard Biener  [2021-09-27 10:23:50 +0200]:

> On Fri, Sep 24, 2021 at 12:34 PM Andrew Burgess
>  wrote:
> >
> > * Thomas Schwinge  [2021-09-23 11:29:05 +0200]:
> >
> > > Hi!
> > >
> > > I only had a curious look here; hope that's still useful.
> > >
> > > On 2021-09-22T16:30:42+0100, Andrew Burgess  
> > > wrote:
> > > > The top-level configure script is shared between the gcc repository
> > > > and the binutils-gdb repository.
> > > >
> > > > The target_configdirs variable in the configure.ac script, defines
> > > > sub-directories that contain components that should be built for the
> > > > target using the target tools.
> > > >
> > > > Some components, e.g. zlib, are built as both host and target
> > > > libraries.
> > > >
> > > > This causes problems for binutils-gdb.  If we run 'make all' in the
> > > > binutils-gdb repository we end up trying to build a target version of
> > > > the zlib library, which requires the target compiler be available.
> > > > Often the target compiler isn't immediately available, and so the
> > > > build fails.
> > >
> > > I did wonder: shouldn't normally these target libraries be masked out via
> > > 'noconfigdirs' (see 'Handle --disable- generically' section),
> > > via 'enable_[...]' being set to 'no'?  But I think I now see the problem
> > > here: the 'enable_[...]' variables guard both the host and target library
> > > build!  (... if I'm quickly understanding that correctly...)
> > >
> > > ... and you do need the host zlib, thus '$enable_zlib != no'.
> > >
> > > > The problem with zlib impacted a previous attempt to synchronise the
> > > > top-level configure scripts from gcc to binutils-gdb, see this thread:
> > > >
> > > >   https://sourceware.org/pipermail/binutils/2019-May/107094.html
> > > >
> > > > And I'm in the process of importing libbacktrace in to binutils-gdb,
> > > > which is also a host and target library, and triggers the same issues.
> > > >
> > > > I believe that for binutils-gdb, at least at the moment, there are no
> > > > target libraries that we need to build.
> > > >
> > > > My proposal then is to make the value of target_libraries change based
> > > > on which repository we are building in.  Specifically, if the source
> > > > tree has a gcc/ directory then we should set the target_libraries
> > > > variable, otherwise this variable is left entry.
> > > >
> > > > I think that if someone tries to create a single unified tree (gcc +
> > > > binutils-gdb in a single source tree) and then build, this change will
> > > > not have a negative impact, the tree still has gcc/ so we'd expect the
> > > > target compiler to be built, which means building the target_libraries
> > > > should work just fine.
> > > >
> > > > However, if the source tree lacks gcc/ then we assume the target
> > > > compiler isn't built/available, and so target_libraries shouldn't be
> > > > built.
> > > >
> > > > There is already precedent within configure.ac for check on the
> > > > existence of gcc/ in the source tree, see the handling of
> > > > -enable-werror around line 3658.
> > >
> > > (I understand that one to just guard the 'cat $srcdir/gcc/DEV-PHASE',
> > > tough.)
> > >
> > > > I've tested a build of gcc on x86-64, and the same set of target
> > > > libraries still seem to get built.  On binutils-gdb this change
> > > > resolves the issues with 'make all'.
> > > >
> > > > Any thoughts?
> > >
> > > > --- a/configure.ac
> > > > +++ b/configure.ac
> > > > @@ -180,9 +180,17 @@ target_tools="target-rda"
> > > >  ## We assign ${configdirs} this way to remove all embedded newlines.  
> > > > This
> > > >  ## is important because configure will choke if they ever get through.
> > > >  ## ${configdirs} is directories we build using the host tools.
> > > > -## ${target_configdirs} is directories we build using the target tools.
> > > > +##
> > > > +## ${target_configdirs} is directories we build using the target
> > > > +#

Re: [PATCH 0/13] v2 warning control by group and location (PR 74765)

2021-07-28 Thread Andrew Burgess
* Martin Sebor via Gcc-patches  [2021-07-19 09:08:35 
-0600]:

> On 7/17/21 2:36 PM, Jan-Benedict Glaw wrote:
> > Hi Martin!
> > 
> > On Fri, 2021-06-04 15:27:04 -0600, Martin Sebor  wrote:
> > > This is a revised patch series to add warning control by group and
> > > location, updated based on feedback on the initial series.
> > [...]
> > 
> > My automated checking (in this case: Using Debian's "gcc-snapshot"
> > package) indicates that between versions 1:20210527-1 and
> > 1:20210630-1, building GDB breaks. Your patch is a likely candidate.
> > It's a case where a method asks for a nonnull argument and later on
> > checks for NULLness again. The build log is currently available at
> > (http://wolf.lug-owl.de:8080/jobs/gdb-vax-linux/5), though obviously
> > breaks for any target:
> > 
> > configure --target=vax-linux --prefix=/tmp/gdb-vax-linux
> > make all-gdb
> > 
> > [...]
> > [all 2021-07-16 19:19:25]   CXXcompile/compile.o
> > [all 2021-07-16 19:19:30] In file included from 
> > ./../gdbsupport/common-defs.h:126,
> > [all 2021-07-16 19:19:30]  from ./defs.h:28,
> > [all 2021-07-16 19:19:30]  from compile/compile.c:20:
> > [all 2021-07-16 19:19:30] ./../gdbsupport/gdb_unlinker.h: In constructor 
> > 'gdb::unlinker::unlinker(const char*)':
> > [all 2021-07-16 19:19:30] ./../gdbsupport/gdb_assert.h:35:4: error: 
> > 'nonnull' argument 'filename' compared to NULL [-Werror=nonnull-compare]
> > [all 2021-07-16 19:19:30]35 |   ((void) ((expr) ? 0 :   
> > \
> > [all 2021-07-16 19:19:30]   |   
> > ~^~~~
> > [all 2021-07-16 19:19:30]36 |(gdb_assert_fail (#expr, 
> > __FILE__, __LINE__, FUNCTION_NAME), 0)))
> > [all 2021-07-16 19:19:30]   |
> > ~
> > [all 2021-07-16 19:19:30] ./../gdbsupport/gdb_unlinker.h:38:5: note: in 
> > expansion of macro 'gdb_assert'
> > [all 2021-07-16 19:19:30]38 | gdb_assert (filename != NULL);
> > [all 2021-07-16 19:19:30]   | ^~
> > [all 2021-07-16 19:19:31] cc1plus: all warnings being treated as errors
> > [all 2021-07-16 19:19:31] make[1]: *** [Makefile:1641: compile/compile.o] 
> > Error 1
> > [all 2021-07-16 19:19:31] make[1]: Leaving directory 
> > '/var/lib/laminar/run/gdb-vax-linux/5/binutils-gdb/gdb'
> > [all 2021-07-16 19:19:31] make: *** [Makefile:11410: all-gdb] Error 2
> > 
> > 
> > Code is this:
> > 
> >   31 class unlinker
> >   32 {
> >   33  public:
> >   34
> >   35   unlinker (const char *filename) ATTRIBUTE_NONNULL (2)
> >   36 : m_filename (filename)
> >   37   {
> >   38 gdb_assert (filename != NULL);
> >   39   }
> > 
> > I'm quite undecided whether this is bad behavior of GCC or bad coding
> > style in Binutils/GDB, or both.
> 
> A warning should be expected in this case.  Before the recent GCC
> change it was inadvertently suppressed in gdb_assert macros by its
> operand being enclosed in parentheses.

This issue was just posted to the GDB list, and I wanted to clarify my
understanding a bit.

I believe that (at least by default) adding the nonnull attribute
allows GCC to assume (in the above case) that filename will not be
NULL and generate code accordingly.

Additionally, passing an explicit NULL (i.e. 'unlinker obj (NULL)')
would cause a compile time error.

But, there's nothing to actually stop a NULL being passed due to, say,
a logic bug in the program.  So, something like this would compile
fine:

  extern const char *ptr;
  unlinker obj (ptr);

And in a separate compilation unit:

  const char *ptr = NULL;

Obviously, the run time behaviour of such a program would be
undefined.

Given the above then, it doesn't seem crazy to want to do something
like the above, that is, add an assert to catch a logic bug in the
program.

Is there an approved mechanism through which I can tell GCC that I
really do want to do a comparison to NULL, without any warning, and
without the check being optimised out?

Thanks,
Andrew


Re: [PATCH 0/13] v2 warning control by group and location (PR 74765)

2021-07-29 Thread Andrew Burgess
* Martin Sebor  [2021-07-28 10:16:59 -0600]:

> On 7/28/21 5:14 AM, Andrew Burgess wrote:
> > * Martin Sebor via Gcc-patches  [2021-07-19 
> > 09:08:35 -0600]:
> > 
> > > On 7/17/21 2:36 PM, Jan-Benedict Glaw wrote:
> > > > Hi Martin!
> > > > 
> > > > On Fri, 2021-06-04 15:27:04 -0600, Martin Sebor  
> > > > wrote:
> > > > > This is a revised patch series to add warning control by group and
> > > > > location, updated based on feedback on the initial series.
> > > > [...]
> > > > 
> > > > My automated checking (in this case: Using Debian's "gcc-snapshot"
> > > > package) indicates that between versions 1:20210527-1 and
> > > > 1:20210630-1, building GDB breaks. Your patch is a likely candidate.
> > > > It's a case where a method asks for a nonnull argument and later on
> > > > checks for NULLness again. The build log is currently available at
> > > > (http://wolf.lug-owl.de:8080/jobs/gdb-vax-linux/5), though obviously
> > > > breaks for any target:
> > > > 
> > > > configure --target=vax-linux --prefix=/tmp/gdb-vax-linux
> > > > make all-gdb
> > > > 
> > > > [...]
> > > > [all 2021-07-16 19:19:25]   CXXcompile/compile.o
> > > > [all 2021-07-16 19:19:30] In file included from 
> > > > ./../gdbsupport/common-defs.h:126,
> > > > [all 2021-07-16 19:19:30]  from ./defs.h:28,
> > > > [all 2021-07-16 19:19:30]  from compile/compile.c:20:
> > > > [all 2021-07-16 19:19:30] ./../gdbsupport/gdb_unlinker.h: In 
> > > > constructor 'gdb::unlinker::unlinker(const char*)':
> > > > [all 2021-07-16 19:19:30] ./../gdbsupport/gdb_assert.h:35:4: error: 
> > > > 'nonnull' argument 'filename' compared to NULL [-Werror=nonnull-compare]
> > > > [all 2021-07-16 19:19:30]35 |   ((void) ((expr) ? 0 :   
> > > > \
> > > > [all 2021-07-16 19:19:30]   |   
> > > > ~^~~~
> > > > [all 2021-07-16 19:19:30]36 |(gdb_assert_fail (#expr, 
> > > > __FILE__, __LINE__, FUNCTION_NAME), 0)))
> > > > [all 2021-07-16 19:19:30]   |
> > > > ~
> > > > [all 2021-07-16 19:19:30] ./../gdbsupport/gdb_unlinker.h:38:5: note: in 
> > > > expansion of macro 'gdb_assert'
> > > > [all 2021-07-16 19:19:30]38 | gdb_assert (filename != NULL);
> > > > [all 2021-07-16 19:19:30]   | ^~
> > > > [all 2021-07-16 19:19:31] cc1plus: all warnings being treated as errors
> > > > [all 2021-07-16 19:19:31] make[1]: *** [Makefile:1641: 
> > > > compile/compile.o] Error 1
> > > > [all 2021-07-16 19:19:31] make[1]: Leaving directory 
> > > > '/var/lib/laminar/run/gdb-vax-linux/5/binutils-gdb/gdb'
> > > > [all 2021-07-16 19:19:31] make: *** [Makefile:11410: all-gdb] Error 2
> > > > 
> > > > 
> > > > Code is this:
> > > > 
> > > >31 class unlinker
> > > >32 {
> > > >33  public:
> > > >34
> > > >35   unlinker (const char *filename) ATTRIBUTE_NONNULL (2)
> > > >36 : m_filename (filename)
> > > >37   {
> > > >38 gdb_assert (filename != NULL);
> > > >39   }
> > > > 
> > > > I'm quite undecided whether this is bad behavior of GCC or bad coding
> > > > style in Binutils/GDB, or both.
> > > 
> > > A warning should be expected in this case.  Before the recent GCC
> > > change it was inadvertently suppressed in gdb_assert macros by its
> > > operand being enclosed in parentheses.
> > 
> > This issue was just posted to the GDB list, and I wanted to clarify my
> > understanding a bit.
> > 
> > I believe that (at least by default) adding the nonnull attribute
> > allows GCC to assume (in the above case) that filename will not be
> > NULL and generate code accordingly.
> > 
> > Additionally, passing an explicit NULL (i.e. 'unlinker obj (NULL)')
> > would cause a compile time error.
> > 
> > But, there's nothing to actually stop a NULL being passed due to, say,
> > a logic bug in the 

Re: [PATCH] Revert "Pass GUILE down to subdirectories"

2024-03-06 Thread Andrew Burgess


Tom Tromey  writes:

> This reverts commit b7e5a29602143b53267efcd9c8d5ecc78cd5a62f.
>
> This patch caused problems for some users when building gdb, because
> it would cause 'guild' to be invoked with the wrong versin of guile.
> On the whole it seems simpler to just back this out.

Tom,

After once again forgetting to add GUILE=guile2.2 to my GDB build I was
thinking about this issue again.

Given that GDB has a --with-guile=... configure option, and that our
configure scripts try to identify a matching version of guild and a
shared library to link GDB against, I wondered why we don't just force
the use of a matching version of guile.

I guess I'm suggesting that for building GDB's guile components we
should respect either the --with-guile=... configure option, or what the
configure script auto-detected, and should not be picking up any build
time GUILE=... flag -- setting GUILE=... isn't going to change the
version of guild used, nor is it going to change the shared library that
GDB links against, so just changing the guile version seems like a
recipe for incompatibility problems.

Below is a patch that forces GDB to compile our guile scripts using a
suitable version of guile.  This could be applied irrespective of
whether you revert b7e5a29602143b53267efcd9c8d5ecc78cd5a62f or not.

What do you think?

Thanks,
Andrew

---

commit 6d326010217a2c94ad27d4063f90f689f7c11615
Author: Andrew Burgess 
Date:   Tue Mar 5 12:35:05 2024 +

gdb/data-directory: set GUILE for compiling GDB's guile scripts

After this commit:

  commit d006ec41c448d9f4a84df50391e87cbf0aa8c152
  Date:   Thu Dec 28 14:08:39 2023 -0700

  Pass GUILE down to subdirectories

I have had issues with GDB's guile support.  Commit d006ec41c448 sets
the GUILE variable in the top-level Makefile to the default value
'guile'.

The problem this causes for me is that 'guile' on my system is
2.0.14.  I also have guile2.2 available on my system, and this is
version 2.2.6.

When GDB configures it selects looks for a suitable guile version to
use, and it looks in the order:

  guile-3.0
  guile-2.2
  guile-2.0

This means that on my system GDB chooses to use the guile2.2 library
to link against, and uses guild2.2 as the compiler to pre-compile
GDB's guile scripts.

However, guild (and guile2.2) check for the GUILE environment
variable, and use the value of this variable as the version of guile
interpreter which is used when compiling things.

What this means is that after commit d006ec41c448, I am now using the
guild2.2 binary (version 2.2.6), but this is then invoking the guile
binary (version 2.0.14).  The compiled scripts are then loaded by GDB,
which is linking against libguile-2.2.so.1, this results in the
following error:

  $ ./gdb/gdb --data-directory ./gdb/data-directory
  Exception caught while booting Guile.
  Error in function "load-thunk-from-memory":
  not an ELF file
  ./gdb/gdb: warning: Could not complete Guile gdb module initialization 
from:
  /tmp/binutils-gdb/build/gdb/data-directory/guile/gdb/boot.scm.
  Limited Guile support is available.
  Suggest passing --data-directory=/path/to/gdb/data-directory.
  GDB Version: 15.1

  (gdb)

We could fix this by reverting some parts of d006ec41c448,
specifically, the part which sets 'guile' as the default value of
GUILE in the top-level Makefile.  However, I wonder if there's a
better solution.

GDB already has a configure flag `--with-guile=...` if this isn't
provided then GDB looks for a sensible default.

I think that when compiling GDB's guile files we should use a
consistent set of tools, i.e. a matching version of guild and guile,
both of which correspond to the shared library GDB will link against.

I propose that this should be done by setting the GUILE environment
variable in gdb/data-directory/Makefile.in based on the version of
guile that GDB's configure script selected.

This does mean that doing:

  make all-gdb GUILE=

will no longer work, GDB will ignore this setting, however, if we
really want to compile GDB's guile scripts using a different guile
version then surely we should also be linking to a corresponding
shared library, and (maybe) using the corresponding guild version too?
This can be achieved by configuring GDB using `--with-guile=`.

After this commit I no longer have issues compiling GDB with guile
support.

diff --git a/gdb/acinclude.m4 b/gdb/acinclude.m4
index 915082056dd..6e4b96f0acf 100644
--- a/gdb/acinclude.m4
+++ b/gdb/acinclude.m4
@@ -284,7 +284,29 @@ AC_DEFUN([GDB_GUILE_PROGRAM_NAMES], [
   fi
 
   GUILD="

Re: [PATCH] Revert "Pass GUILE down to subdirectories"

2024-03-11 Thread Andrew Burgess
Tom Tromey  writes:

>>>>>> "Andrew" == Andrew Burgess  writes:
>
> Andrew> Tom Tromey  writes:
>>> This reverts commit b7e5a29602143b53267efcd9c8d5ecc78cd5a62f.
>>> 
>>> This patch caused problems for some users when building gdb, because
>>> it would cause 'guild' to be invoked with the wrong versin of guile.
>>> On the whole it seems simpler to just back this out.
>>> 
>>> * Makefile.in: Rebuild.
>>> * Makefile.tpl (BASE_EXPORTS): Remove GUILE.
>>> (GUILE): Remove.
>>> * Makefile.def (flags_to_pass): Remove GUILE.
>
> Andrew> Is it going to be possible to merge this with GCC in stage 4?  Would 
> be
> Andrew> super useful if we could as this is still causing problems.
>
> We can always check it in to gdb now and then to gcc at some later date.
> If that sounds ok to you, I'll go ahead & do it.

Thanks, that would be great, and would certainly fix the build problems
I see.

Sorry for the late reply.

Thanks,
Andrew



Re: [PATCH] Revert "Pass GUILE down to subdirectories"

2024-02-07 Thread Andrew Burgess
Tom Tromey  writes:

> This reverts commit b7e5a29602143b53267efcd9c8d5ecc78cd5a62f.
>
> This patch caused problems for some users when building gdb, because
> it would cause 'guild' to be invoked with the wrong versin of guile.
> On the whole it seems simpler to just back this out.
>
>   * Makefile.in: Rebuild.
>   * Makefile.tpl (BASE_EXPORTS): Remove GUILE.
>   (GUILE): Remove.
>   * Makefile.def (flags_to_pass): Remove GUILE.

Is it going to be possible to merge this with GCC in stage 4?  Would be
super useful if we could as this is still causing problems.

Thanks,
Andrew



> ---
>  Makefile.def | 1 -
>  Makefile.in  | 8 ++--
>  Makefile.tpl | 7 ++-
>  3 files changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/Makefile.def b/Makefile.def
> index 19954e7d731..c8c80af3657 100644
> --- a/Makefile.def
> +++ b/Makefile.def
> @@ -312,7 +312,6 @@ flags_to_pass = { flag= GNATBIND ; };
>  flags_to_pass = { flag= GNATMAKE ; };
>  flags_to_pass = { flag= GDC ; };
>  flags_to_pass = { flag= GDCFLAGS ; };
> -flags_to_pass = { flag= GUILE ; };
>  
>  // Target tools
>  flags_to_pass = { flag= AR_FOR_TARGET ; };
> diff --git a/Makefile.in b/Makefile.in
> index edb0c8a9a42..245dd610b53 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -3,7 +3,7 @@
>  #
>  # Makefile for directory with subdirs to build.
>  #   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
> -#   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
> 2011, 2023
> +#   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
> 2011
>  #   Free Software Foundation
>  #
>  # This file is free software; you can redistribute it and/or modify
> @@ -143,8 +143,7 @@ BASE_EXPORTS = \
>   M4="$(M4)"; export M4; \
>   SED="$(SED)"; export SED; \
>   AWK="$(AWK)"; export AWK; \
> - MAKEINFO="$(MAKEINFO)"; export MAKEINFO; \
> - GUILE="$(GUILE)"; export GUILE;
> + MAKEINFO="$(MAKEINFO)"; export MAKEINFO;
>  
>  # This is the list of variables to export in the environment when
>  # configuring subdirectories for the build system.
> @@ -452,8 +451,6 @@ GM2FLAGS = $(CFLAGS)
>  
>  PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
>  
> -GUILE = guile
> -
>  # Pass additional PGO and LTO compiler options to the PGO build.
>  BUILD_CFLAGS = $(PGO_BUILD_CFLAGS) $(PGO_BUILD_LTO_CFLAGS)
>  override CFLAGS += $(BUILD_CFLAGS)
> @@ -886,7 +883,6 @@ BASE_FLAGS_TO_PASS = \
>   "GNATMAKE=$(GNATMAKE)" \
>   "GDC=$(GDC)" \
>   "GDCFLAGS=$(GDCFLAGS)" \
> - "GUILE=$(GUILE)" \
>   "AR_FOR_TARGET=$(AR_FOR_TARGET)" \
>   "AS_FOR_TARGET=$(AS_FOR_TARGET)" \
>   "CC_FOR_TARGET=$(CC_FOR_TARGET)" \
> diff --git a/Makefile.tpl b/Makefile.tpl
> index adbcbdd1d57..6e22adecd2f 100644
> --- a/Makefile.tpl
> +++ b/Makefile.tpl
> @@ -6,7 +6,7 @@ in
>  #
>  # Makefile for directory with subdirs to build.
>  #   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
> -#   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
> 2011, 2023
> +#   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
> 2011
>  #   Free Software Foundation
>  #
>  # This file is free software; you can redistribute it and/or modify
> @@ -146,8 +146,7 @@ BASE_EXPORTS = \
>   M4="$(M4)"; export M4; \
>   SED="$(SED)"; export SED; \
>   AWK="$(AWK)"; export AWK; \
> - MAKEINFO="$(MAKEINFO)"; export MAKEINFO; \
> - GUILE="$(GUILE)"; export GUILE;
> + MAKEINFO="$(MAKEINFO)"; export MAKEINFO;
>  
>  # This is the list of variables to export in the environment when
>  # configuring subdirectories for the build system.
> @@ -455,8 +454,6 @@ GM2FLAGS = $(CFLAGS)
>  
>  PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
>  
> -GUILE = guile
> -
>  # Pass additional PGO and LTO compiler options to the PGO build.
>  BUILD_CFLAGS = $(PGO_BUILD_CFLAGS) $(PGO_BUILD_LTO_CFLAGS)
>  override CFLAGS += $(BUILD_CFLAGS)
> -- 
> 2.43.0



Re: [PATCH] Revert "Pass GUILE down to subdirectories"

2024-02-08 Thread Andrew Burgess
Christian Biesinger  writes:

> On Mon, Jan 22, 2024 at 7:21 PM Tom Tromey  wrote:
>
>> This reverts commit b7e5a29602143b53267efcd9c8d5ecc78cd5a62f.
>>
>> This patch caused problems for some users when building gdb, because
>> it would cause 'guild' to be invoked with the wrong versin of guile.
>>
>
> Is "guild" here a typo? (I don't see a "guild" binary when installing
> guile-3.0)

guild is the guile compiler.  There's certainly a guild binary with
3.02 and 3.0.9, as well as every 2.x I've checked.  What version exactly
are you using?

Thanks,
Andrew



[PATCHv2 0/2] Changes to libiberty buildargv

2024-02-10 Thread Andrew Burgess
I realise that these patches are not going to get merged until GCC is
back in stage 1, but thought I'd post my latest set of changes for the
libiberty buildargv function.

Patch #1 is unchanged from V1.

Patch #2 is new in V2.

Thanks,
Andrew

---

Andrew Burgess (2):
  libiberty/buildargv: POSIX behaviour for backslash handling
  libiberty/buildargv: handle input consisting of only white space

 libiberty/argv.c  | 104 
 libiberty/testsuite/test-expandargv.c | 170 ++
 2 files changed, 200 insertions(+), 74 deletions(-)


base-commit: cff174fabd6c980c09aee95db1d9d5c22421761f
-- 
2.25.4



[PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-02-10 Thread Andrew Burgess
GDB makes use of the libiberty function buildargv for splitting the
inferior (program being debugged) argument string in the case where
the inferior is not being started under a shell.

I have recently been working to improve this area of GDB, and noticed
some unexpected behaviour to the libiberty function buildargv, when
the input is a string consisting only of white space.

What I observe is that if the input to buildargv is a string
containing only white space, then buildargv will return an argv list
containing a single empty argument, e.g.:

  char **argv = buildargv (" ");
  assert (*argv[0] == '\0');
  assert (argv[1] == NULL);

We get the same output from buildargv if the input is a single space,
or multiple spaces.  Other white space characters give the same
results.

This doesn't seem right to me, and in fact, there appears to be a work
around for this issue in expandargv where we have this code:

  /* If the file is empty or contains only whitespace, buildargv would
 return a single empty argument.  In this context we want no arguments,
 instead.  */
  if (only_whitespace (buffer))
{
  file_argv = (char **) xmalloc (sizeof (char *));
  file_argv[0] = NULL;
}
  else
/* Parse the string.  */
file_argv = buildargv (buffer);

I think that the correct behaviour in this situation is to return an
empty argv array, e.g.:

  char **argv = buildargv (" ");
  assert (argv[0] == NULL);

And it turns out that this is a trivial change to buildargv.  The diff
does look big, but this is because I've re-indented a block.  Check
with 'git diff -b' to see the minimal changes.  I've also removed the
work around from expandargv.

When testing this sort of thing I normally write the tests first, and
then fix the code.  In this case test-expandargv.c has sort-of been
used as a mechanism for testing the buildargv function (expandargv
does call buildargv most of the time), however, for this particular
issue the work around in expandargv (mentioned above) masked the
buildargv bug.

I did consider adding a new test-buildargv.c file, however, this would
have basically been a copy & paste of test-expandargv.c (with some
minor changes to call buildargv).  This would be fine now, but feels
like we would eventually end up with one file not being updated as
much as the other, and so test coverage would suffer.

Instead, I have added some explicit buildargv testing to the
test-expandargv.c file, this reuses the test input that is already
defined for expandargv.

Of course, once I removed the work around from expandargv then we now
do always call buildargv from expandargv, and so the bug I'm fixing
would impact both expandargv and buildargv, so maybe the new testing
is redundant?  I tend to think more testing is always better, so I've
left it in for now.
---
 libiberty/argv.c  | 108 ++--
 libiberty/testsuite/test-expandargv.c | 136 ++
 2 files changed, 166 insertions(+), 78 deletions(-)

diff --git a/libiberty/argv.c b/libiberty/argv.c
index d9d32e59e72..675336273f3 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -212,71 +212,74 @@ char **buildargv (const char *input)
  argv[argc] = NULL;
}
  /* Begin scanning arg */
- arg = copybuf;
- while (*input != EOS)
+ if (*input != EOS)
{
- if (ISSPACE (*input) && !squote && !dquote && !bsquote)
+ arg = copybuf;
+ while (*input != EOS)
{
- break;
-   }
- else
-   {
- if (bsquote)
-   {
- bsquote = 0;
- if (*input != '\n')
-   *arg++ = *input;
-   }
- else if (*input == '\\'
-  && !squote
-  && (!dquote
-  || strchr ("$`\"\\\n", *(input + 1)) != NULL))
+ if (ISSPACE (*input) && !squote && !dquote && !bsquote)
{
- bsquote = 1;
-   }
- else if (squote)
-   {
- if (*input == '\'')
-   {
- squote = 0;
-   }
- else
-   {
- *arg++ = *input;
-   }
+ break;
}
- else if (dquote)
+ else
{
- if (*input == '"')
+ if (bsquote)
{
- dquote = 0;
+ bsquote = 0;
+ if (*input != '\n')
+   *arg++ = *input;
}
- else
+ else if (*input == '\\'
+ 

[PATCHv2 1/2] libiberty/buildargv: POSIX behaviour for backslash handling

2024-02-10 Thread Andrew Burgess
GDB makes use of the libiberty function buildargv for splitting the
inferior (program being debugged) argument string in the case where
the inferior is not being started under a shell.

I have recently been working to improve this area of GDB, and have
tracked done some of the unexpected behaviour to the libiberty
function buildargv, and how it handles backslash escapes.

For reference, I've been mostly reading:

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

The issues that I would like to fix are:

  1. Backslashes within single quotes should not be treated as an
  escape, thus: '\a' should split to \a, retaining the backslash.

  2. Backslashes within double quotes should only act as an escape if
  they are immediately before one of the characters $ (dollar),
  ` (backtick), " (double quote), ` (backslash), or \n (newline).  In
  all other cases a backslash should not be treated as an escape
  character.  Thus: "\a" should split to \a, but "\$" should split to
  $.

  3. A backslash-newline sequence should be treated as a line
  continuation, both the backslash and the newline should be removed.

I've updated libiberty and also added some tests.  All the existing
libiberty tests continue to pass, but I'm not sure if there is more
testing that should be done, buildargv is used within lto-wraper.cc,
so maybe there's some testing folk can suggest that I run?
---
 libiberty/argv.c  |  8 +--
 libiberty/testsuite/test-expandargv.c | 34 +++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/libiberty/argv.c b/libiberty/argv.c
index 45f16854603..d9d32e59e72 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -224,9 +224,13 @@ char **buildargv (const char *input)
  if (bsquote)
{
  bsquote = 0;
- *arg++ = *input;
+ if (*input != '\n')
+   *arg++ = *input;
}
- else if (*input == '\\')
+ else if (*input == '\\'
+  && !squote
+  && (!dquote
+  || strchr ("$`\"\\\n", *(input + 1)) != NULL))
{
  bsquote = 1;
}
diff --git a/libiberty/testsuite/test-expandargv.c 
b/libiberty/testsuite/test-expandargv.c
index 1e9cb0a0d5a..ea1aeb0eda2 100644
--- a/libiberty/testsuite/test-expandargv.c
+++ b/libiberty/testsuite/test-expandargv.c
@@ -142,6 +142,40 @@ const char *test_data[] = {
   "b",
   0,
 
+  /* Test 7 - No backslash removal within single quotes.  */
+  "'a\\$VAR' '\\\"'",/* Test 7 data */
+  ARGV0,
+  "@test-expandargv-7.lst",
+  0,
+  ARGV0,
+  "a\\$VAR",
+  "\\\"",
+  0,
+
+  /* Test 8 - Remove backslash / newline pairs.  */
+  "\"ab\\\ncd\" ef\\\ngh",/* Test 8 data */
+  ARGV0,
+  "@test-expandargv-8.lst",
+  0,
+  ARGV0,
+  "abcd",
+  "efgh",
+  0,
+
+  /* Test 9 - Backslash within double quotes.  */
+  "\"\\$VAR\" \"\\`\" \"\\\"\" \"\" \"\\n\" \"\\t\"",/* Test 9 data */
+  ARGV0,
+  "@test-expandargv-9.lst",
+  0,
+  ARGV0,
+  "$VAR",
+  "`",
+  "\"",
+  "\\",
+  "\\n",
+  "\\t",
+  0,
+
   0 /* Test done marker, don't remove. */
 };
 
-- 
2.25.4



Re: [PATCH] Pass GUILE down to subdirectories

2024-01-13 Thread Andrew Burgess
Tom Tromey  writes:

> When I enable cgen rebuilding in the binutils-gdb tree, the default is
> to run cgen using 'guile'.  However, on my host, guile is guile 2.2,
> which doesn't work for me -- I have to use guile3.0.
>
> This patch arranges to pass "GUILE" down to subdirectories, so I can
> use 'make GUILE=guile3.0'.
>
> ChangeLog
> 2023-12-30  Tom Tromey  
>
>   * Makefile.in: Rebuild.
>   * Makefile.tpl (BASE_EXPORTS): Add GUILE.
>   (GUILE): New variable.
>   * Makefile.def (flags_to_pass): Add GUILE.
> ---
>  ChangeLog| 7 +++
>  Makefile.def | 1 +
>  Makefile.in  | 8 ++--
>  Makefile.tpl | 7 +--
>  4 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/Makefile.def b/Makefile.def
> index 662e50fdc18..792919e561c 100644
> --- a/Makefile.def
> +++ b/Makefile.def
> @@ -310,6 +310,7 @@ flags_to_pass = { flag= GNATBIND ; };
>  flags_to_pass = { flag= GNATMAKE ; };
>  flags_to_pass = { flag= GDC ; };
>  flags_to_pass = { flag= GDCFLAGS ; };
> +flags_to_pass = { flag= GUILE ; };
>  
>  // Target tools
>  flags_to_pass = { flag= AR_FOR_TARGET ; };
> diff --git a/Makefile.in b/Makefile.in
> index 48320bb549e..9a58d5a4f20 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -3,7 +3,7 @@
>  #
>  # Makefile for directory with subdirs to build.
>  #   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
> -#   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
> 2011
> +#   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
> 2011, 2023
>  #   Free Software Foundation
>  #
>  # This file is free software; you can redistribute it and/or modify
> @@ -143,7 +143,8 @@ BASE_EXPORTS = \
>   M4="$(M4)"; export M4; \
>   SED="$(SED)"; export SED; \
>   AWK="$(AWK)"; export AWK; \
> - MAKEINFO="$(MAKEINFO)"; export MAKEINFO;
> + MAKEINFO="$(MAKEINFO)"; export MAKEINFO; \
> + GUILE="$(GUILE)"; export GUILE;
>  
>  # This is the list of variables to export in the environment when
>  # configuring subdirectories for the build system.
> @@ -450,6 +451,8 @@ GM2FLAGS = $(CFLAGS)
>  
>  PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
>  
> +GUILE = guile

Hi Tom,

This change is causing some problems for me.

One of my build machines has 2 versions of guile installed.  One is
guile 2.0.14 and the other is guile 2.2.21.

When GDB configures itself the configure script figures out that it
should use 2.2.21 to compile the guile libraries that GDB uses.

However, when we actually build the guile libraries we do use guild2.2,
but due to this 'GUILE = guile' line, guild2.2 uses guile 2.0.14 in
order to perform the compile (I guess, I don't know the details of how
guile compilation works).

Unfortunately guile 2.0.14 compiles in a way which is not compatible
with how GDB then tries to load the guile library.

Maybe better to show you what's going on:

  $ pwd
  /tmp/binutils-gdb/build/gdb/data-directory/guile
  $ GUILE=guile /usr/bin/guild2.2 compile -Warity-mismatch -Wformat 
-Wunused-toplevel -L . -o ./gdb.go ./gdb.scm
  wrote `./gdb.go'
  $ file gdb.go
  gdb.go: Guile Object, little endian, 64bit, bytecode v2.0
  $ GUILE=guile2.2 /usr/bin/guild2.2 compile -Warity-mismatch -Wformat 
-Wunused-toplevel -L . -o ./gdb.go ./gdb.scm
  wrote `./gdb.go'
  $ file gdb.go
  gdb.go: ELF 64-bit LSB shared object, no machine, version 1 (embedded), 
dynamically linked, with debug_info, not stripped

The first compile uses GUILE=guile, so I use guile 2.0.14, which results
in a non-ELF being generated.  When I start GDB with this non-ELF in
place, I see this:

  $ ./gdb/gdb --data-directory ./gdb/data-directory/
  Exception caught while booting Guile.
  Error in function "load-thunk-from-memory":
  not an ELF file
  ./gdb/gdb: warning: Could not complete Guile gdb module initialization from:
  /tmp/binutils-gdb/build/gdb/data-directory/guile/gdb/boot.scm.
  Limited Guile support is available.
  Suggest passing --data-directory=/path/to/gdb/data-directory.
  GDB Version: 15.1
  
  (gdb) 

The second compile, with GUILE=guile2.2 results in an ELF being
generated, and with this in place GDB starts just fine.

Now, clearly the obvious answer is: don't have such an old, out of date
version of guile installed.  But I think there's a bigger issue here.
As guild version X will by default pick up the corresponding version of
guile, shouldn't that be the default behaviour?

My proposal would be that we change the line 'GUILE = guile' to instead
be just 'GUILE ='.

With this in place I can still override the choice of guile executable
with:

  make GUILE=guile

but, if I don't do this t

Ping: Re: [PATCH] libiberty/buildargv: POSIX behaviour for backslash handling

2024-01-02 Thread Andrew Burgess


Ping!

Thanks,
Andrew

Andrew Burgess  writes:

> GDB makes use of the libiberty function buildargv for splitting the
> inferior (program being debugged) argument string in the case where
> the inferior is not being started under a shell.
>
> I have recently been working to improve this area of GDB, and have
> tracked done some of the unexpected behaviour to the libiberty
> function buildargv, and how it handles backslash escapes.
>
> For reference, I've been mostly reading:
>
>   https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
>
> The issues that I would like to fix are:
>
>   1. Backslashes within single quotes should not be treated as an
>   escape, thus: '\a' should split to \a, retaining the backslash.
>
>   2. Backslashes within double quotes should only act as an escape if
>   they are immediately before one of the characters $ (dollar),
>   ` (backtick), " (double quote), ` (backslash), or \n (newline).  In
>   all other cases a backslash should not be treated as an escape
>   character.  Thus: "\a" should split to \a, but "\$" should split to
>   $.
>
>   3. A backslash-newline sequence should be treated as a line
>   continuation, both the backslash and the newline should be removed.
>
> I've updated libiberty and also added some tests.  All the existing
> libiberty tests continue to pass, but I'm not sure if there is more
> testing that should be done, buildargv is used within lto-wraper.cc,
> so maybe there's some testing folk can suggest that I run?
> ---
>  libiberty/argv.c  |  8 +--
>  libiberty/testsuite/test-expandargv.c | 34 +++
>  2 files changed, 40 insertions(+), 2 deletions(-)
>
> diff --git a/libiberty/argv.c b/libiberty/argv.c
> index c2823d3e4ba..6bae4ca2ee9 100644
> --- a/libiberty/argv.c
> +++ b/libiberty/argv.c
> @@ -224,9 +224,13 @@ char **buildargv (const char *input)
> if (bsquote)
>   {
> bsquote = 0;
> -   *arg++ = *input;
> +   if (*input != '\n')
> + *arg++ = *input;
>   }
> -   else if (*input == '\\')
> +   else if (*input == '\\'
> +&& !squote
> +&& (!dquote
> +|| strchr ("$`\"\\\n", *(input + 1)) != NULL))
>   {
> bsquote = 1;
>   }
> diff --git a/libiberty/testsuite/test-expandargv.c 
> b/libiberty/testsuite/test-expandargv.c
> index 30f2337ef77..b8dcc6a269a 100644
> --- a/libiberty/testsuite/test-expandargv.c
> +++ b/libiberty/testsuite/test-expandargv.c
> @@ -142,6 +142,40 @@ const char *test_data[] = {
>"b",
>0,
>  
> +  /* Test 7 - No backslash removal within single quotes.  */
> +  "'a\\$VAR' '\\\"'",/* Test 7 data */
> +  ARGV0,
> +  "@test-expandargv-7.lst",
> +  0,
> +  ARGV0,
> +  "a\\$VAR",
> +  "\\\"",
> +  0,
> +
> +  /* Test 8 - Remove backslash / newline pairs.  */
> +  "\"ab\\\ncd\" ef\\\ngh",/* Test 8 data */
> +  ARGV0,
> +  "@test-expandargv-8.lst",
> +  0,
> +  ARGV0,
> +  "abcd",
> +  "efgh",
> +  0,
> +
> +  /* Test 9 - Backslash within double quotes.  */
> +  "\"\\$VAR\" \"\\`\" \"\\\"\" \"\" \"\\n\" \"\\t\"",/* Test 9 data 
> */
> +  ARGV0,
> +  "@test-expandargv-9.lst",
> +  0,
> +  ARGV0,
> +  "$VAR",
> +  "`",
> +  "\"",
> +  "\\",
> +  "\\n",
> +  "\\t",
> +  0,
> +
>0 /* Test done marker, don't remove. */
>  };
>  
>
> base-commit: 458e7c937924bbcef80eb006af0b61420dbfc1c1
> -- 
> 2.25.4



[PATCH] libiberty/buildargv: POSIX behaviour for backslash handling

2023-12-06 Thread Andrew Burgess
GDB makes use of the libiberty function buildargv for splitting the
inferior (program being debugged) argument string in the case where
the inferior is not being started under a shell.

I have recently been working to improve this area of GDB, and have
tracked done some of the unexpected behaviour to the libiberty
function buildargv, and how it handles backslash escapes.

For reference, I've been mostly reading:

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

The issues that I would like to fix are:

  1. Backslashes within single quotes should not be treated as an
  escape, thus: '\a' should split to \a, retaining the backslash.

  2. Backslashes within double quotes should only act as an escape if
  they are immediately before one of the characters $ (dollar),
  ` (backtick), " (double quote), ` (backslash), or \n (newline).  In
  all other cases a backslash should not be treated as an escape
  character.  Thus: "\a" should split to \a, but "\$" should split to
  $.

  3. A backslash-newline sequence should be treated as a line
  continuation, both the backslash and the newline should be removed.

I've updated libiberty and also added some tests.  All the existing
libiberty tests continue to pass, but I'm not sure if there is more
testing that should be done, buildargv is used within lto-wraper.cc,
so maybe there's some testing folk can suggest that I run?
---
 libiberty/argv.c  |  8 +--
 libiberty/testsuite/test-expandargv.c | 34 +++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/libiberty/argv.c b/libiberty/argv.c
index c2823d3e4ba..6bae4ca2ee9 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -224,9 +224,13 @@ char **buildargv (const char *input)
  if (bsquote)
{
  bsquote = 0;
- *arg++ = *input;
+ if (*input != '\n')
+   *arg++ = *input;
}
- else if (*input == '\\')
+ else if (*input == '\\'
+  && !squote
+  && (!dquote
+  || strchr ("$`\"\\\n", *(input + 1)) != NULL))
{
  bsquote = 1;
}
diff --git a/libiberty/testsuite/test-expandargv.c 
b/libiberty/testsuite/test-expandargv.c
index 30f2337ef77..b8dcc6a269a 100644
--- a/libiberty/testsuite/test-expandargv.c
+++ b/libiberty/testsuite/test-expandargv.c
@@ -142,6 +142,40 @@ const char *test_data[] = {
   "b",
   0,
 
+  /* Test 7 - No backslash removal within single quotes.  */
+  "'a\\$VAR' '\\\"'",/* Test 7 data */
+  ARGV0,
+  "@test-expandargv-7.lst",
+  0,
+  ARGV0,
+  "a\\$VAR",
+  "\\\"",
+  0,
+
+  /* Test 8 - Remove backslash / newline pairs.  */
+  "\"ab\\\ncd\" ef\\\ngh",/* Test 8 data */
+  ARGV0,
+  "@test-expandargv-8.lst",
+  0,
+  ARGV0,
+  "abcd",
+  "efgh",
+  0,
+
+  /* Test 9 - Backslash within double quotes.  */
+  "\"\\$VAR\" \"\\`\" \"\\\"\" \"\" \"\\n\" \"\\t\"",/* Test 9 data */
+  ARGV0,
+  "@test-expandargv-9.lst",
+  0,
+  ARGV0,
+  "$VAR",
+  "`",
+  "\"",
+  "\\",
+  "\\n",
+  "\\t",
+  0,
+
   0 /* Test done marker, don't remove. */
 };
 

base-commit: 458e7c937924bbcef80eb006af0b61420dbfc1c1
-- 
2.25.4



Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-06-28 Thread Andrew Burgess


Hi,

Am I OK to push these patches given the testing went OK?  I'm thinking
probably, but I don't want to overstep.

Thanks,
Andrew


Andrew Burgess  writes:

> Jeff Law  writes:
>
>> On 2/10/24 10:26 AM, Andrew Burgess wrote:
>>> GDB makes use of the libiberty function buildargv for splitting the
>>> inferior (program being debugged) argument string in the case where
>>> the inferior is not being started under a shell.
>>> 
>>> I have recently been working to improve this area of GDB, and noticed
>>> some unexpected behaviour to the libiberty function buildargv, when
>>> the input is a string consisting only of white space.
>>> 
>>> What I observe is that if the input to buildargv is a string
>>> containing only white space, then buildargv will return an argv list
>>> containing a single empty argument, e.g.:
>>> 
>>>char **argv = buildargv (" ");
>>>assert (*argv[0] == '\0');
>>>assert (argv[1] == NULL);
>>> 
>>> We get the same output from buildargv if the input is a single space,
>>> or multiple spaces.  Other white space characters give the same
>>> results.
>>> 
>>> This doesn't seem right to me, and in fact, there appears to be a work
>>> around for this issue in expandargv where we have this code:
>>> 
>>>/* If the file is empty or contains only whitespace, buildargv would
>>>   return a single empty argument.  In this context we want no arguments,
>>>   instead.  */
>>>if (only_whitespace (buffer))
>>>  {
>>>file_argv = (char **) xmalloc (sizeof (char *));
>>>file_argv[0] = NULL;
>>>  }
>>>else
>>>  /* Parse the string.  */
>>>  file_argv = buildargv (buffer);
>>> 
>>> I think that the correct behaviour in this situation is to return an
>>> empty argv array, e.g.:
>>> 
>>>char **argv = buildargv (" ");
>>>assert (argv[0] == NULL);
>>> 
>>> And it turns out that this is a trivial change to buildargv.  The diff
>>> does look big, but this is because I've re-indented a block.  Check
>>> with 'git diff -b' to see the minimal changes.  I've also removed the
>>> work around from expandargv.
>>> 
>>> When testing this sort of thing I normally write the tests first, and
>>> then fix the code.  In this case test-expandargv.c has sort-of been
>>> used as a mechanism for testing the buildargv function (expandargv
>>> does call buildargv most of the time), however, for this particular
>>> issue the work around in expandargv (mentioned above) masked the
>>> buildargv bug.
>>> 
>>> I did consider adding a new test-buildargv.c file, however, this would
>>> have basically been a copy & paste of test-expandargv.c (with some
>>> minor changes to call buildargv).  This would be fine now, but feels
>>> like we would eventually end up with one file not being updated as
>>> much as the other, and so test coverage would suffer.
>>> 
>>> Instead, I have added some explicit buildargv testing to the
>>> test-expandargv.c file, this reuses the test input that is already
>>> defined for expandargv.
>>> 
>>> Of course, once I removed the work around from expandargv then we now
>>> do always call buildargv from expandargv, and so the bug I'm fixing
>>> would impact both expandargv and buildargv, so maybe the new testing
>>> is redundant?  I tend to think more testing is always better, so I've
>>> left it in for now.
>> So just an FYI.  Sometimes folks include the -b diffs as well for these 
>> scenarios.  THe problem with doing so (as I recently stumbled over 
>> myself) is the bots which monitor the list and apply patches get quite 
>> confused by that practice.  Anyway, just something to be aware of.
>>
>> As for testing, I tend to agree, more is better unless we're highly 
>> confident its redundant.  So I'll go with your judgment on 
>> redundant-ness of the test.
>>
>> As with the prior patch, you'll need to run it through the usual 
>> bootstrap/regression cycle and cobble together a ChangeLog.
>>
>> OK once those things are taken care of.
>
> Jeff,
>
> Thanks for looking these patches over.
>
> For testing, using current(ish) gcc HEAD, on x86-64 GNU/Linux, I:
>
>   ../src/configure --prefix=$(cd .. && pwd)/install
>   make
>   make check
>
> I did this with / without my patch and then:
>
>   find . -name "*.sum"
>   ... compare all .sum files ...
>
> There was no change in any of the .sum files.
>
>   1. Am I correct that this will have run the bootstrap test by default?
>
>   2. Is there any other testing I should be doing?
>
>   3. If not, am I OK to apply both patches in this series?
>
> Thanks,
> Andrew



Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-07-16 Thread Andrew Burgess
Jeff Law  writes:

> On 6/11/24 4:39 AM, Andrew Burgess wrote:
>
>> 
>> Jeff,
>> 
>> Thanks for looking these patches over.
>> 
>> For testing, using current(ish) gcc HEAD, on x86-64 GNU/Linux, I:
>> 
>>../src/configure --prefix=$(cd .. && pwd)/install
>>make
>>make check
>> 
>> I did this with / without my patch and then:
>> 
>>find . -name "*.sum"
>>... compare all .sum files ...
>> 
>> There was no change in any of the .sum files.
>> 
>>1. Am I correct that this will have run the bootstrap test by default?
>> 
>>2. Is there any other testing I should be doing?
>> 
>>3. If not, am I OK to apply both patches in this series?
> Sorry, as always June is a rough month with the trunk opening for 
> development.

Not a problem.

>
> Your testing of the .sum files is reasonable, assuming you used -k on 
> the make-check step.  GCC's testsuite is never really clean.
>
> And the default target for "make" these days does a bootstrap, so you 
> also took care of that.
>
> So, yes, you can go ahead and commit the change.

I've gone ahead and pushed these patches.

Thanks,
Andrew



Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-06-11 Thread Andrew Burgess
Jeff Law  writes:

> On 2/10/24 10:26 AM, Andrew Burgess wrote:
>> GDB makes use of the libiberty function buildargv for splitting the
>> inferior (program being debugged) argument string in the case where
>> the inferior is not being started under a shell.
>> 
>> I have recently been working to improve this area of GDB, and noticed
>> some unexpected behaviour to the libiberty function buildargv, when
>> the input is a string consisting only of white space.
>> 
>> What I observe is that if the input to buildargv is a string
>> containing only white space, then buildargv will return an argv list
>> containing a single empty argument, e.g.:
>> 
>>char **argv = buildargv (" ");
>>assert (*argv[0] == '\0');
>>assert (argv[1] == NULL);
>> 
>> We get the same output from buildargv if the input is a single space,
>> or multiple spaces.  Other white space characters give the same
>> results.
>> 
>> This doesn't seem right to me, and in fact, there appears to be a work
>> around for this issue in expandargv where we have this code:
>> 
>>/* If the file is empty or contains only whitespace, buildargv would
>>   return a single empty argument.  In this context we want no arguments,
>>   instead.  */
>>if (only_whitespace (buffer))
>>  {
>>file_argv = (char **) xmalloc (sizeof (char *));
>>file_argv[0] = NULL;
>>  }
>>else
>>  /* Parse the string.  */
>>  file_argv = buildargv (buffer);
>> 
>> I think that the correct behaviour in this situation is to return an
>> empty argv array, e.g.:
>> 
>>char **argv = buildargv (" ");
>>assert (argv[0] == NULL);
>> 
>> And it turns out that this is a trivial change to buildargv.  The diff
>> does look big, but this is because I've re-indented a block.  Check
>> with 'git diff -b' to see the minimal changes.  I've also removed the
>> work around from expandargv.
>> 
>> When testing this sort of thing I normally write the tests first, and
>> then fix the code.  In this case test-expandargv.c has sort-of been
>> used as a mechanism for testing the buildargv function (expandargv
>> does call buildargv most of the time), however, for this particular
>> issue the work around in expandargv (mentioned above) masked the
>> buildargv bug.
>> 
>> I did consider adding a new test-buildargv.c file, however, this would
>> have basically been a copy & paste of test-expandargv.c (with some
>> minor changes to call buildargv).  This would be fine now, but feels
>> like we would eventually end up with one file not being updated as
>> much as the other, and so test coverage would suffer.
>> 
>> Instead, I have added some explicit buildargv testing to the
>> test-expandargv.c file, this reuses the test input that is already
>> defined for expandargv.
>> 
>> Of course, once I removed the work around from expandargv then we now
>> do always call buildargv from expandargv, and so the bug I'm fixing
>> would impact both expandargv and buildargv, so maybe the new testing
>> is redundant?  I tend to think more testing is always better, so I've
>> left it in for now.
> So just an FYI.  Sometimes folks include the -b diffs as well for these 
> scenarios.  THe problem with doing so (as I recently stumbled over 
> myself) is the bots which monitor the list and apply patches get quite 
> confused by that practice.  Anyway, just something to be aware of.
>
> As for testing, I tend to agree, more is better unless we're highly 
> confident its redundant.  So I'll go with your judgment on 
> redundant-ness of the test.
>
> As with the prior patch, you'll need to run it through the usual 
> bootstrap/regression cycle and cobble together a ChangeLog.
>
> OK once those things are taken care of.

Jeff,

Thanks for looking these patches over.

For testing, using current(ish) gcc HEAD, on x86-64 GNU/Linux, I:

  ../src/configure --prefix=$(cd .. && pwd)/install
  make
  make check

I did this with / without my patch and then:

  find . -name "*.sum"
  ... compare all .sum files ...

There was no change in any of the .sum files.

  1. Am I correct that this will have run the bootstrap test by default?

  2. Is there any other testing I should be doing?

  3. If not, am I OK to apply both patches in this series?

Thanks,
Andrew




Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-06-11 Thread Andrew Burgess
Jeff Law  writes:

> On 2/10/24 10:26 AM, Andrew Burgess wrote:
>> GDB makes use of the libiberty function buildargv for splitting the
>> inferior (program being debugged) argument string in the case where
>> the inferior is not being started under a shell.
>> 
>> I have recently been working to improve this area of GDB, and noticed
>> some unexpected behaviour to the libiberty function buildargv, when
>> the input is a string consisting only of white space.
>> 
>> What I observe is that if the input to buildargv is a string
>> containing only white space, then buildargv will return an argv list
>> containing a single empty argument, e.g.:
>> 
>>char **argv = buildargv (" ");
>>assert (*argv[0] == '\0');
>>assert (argv[1] == NULL);
>> 
>> We get the same output from buildargv if the input is a single space,
>> or multiple spaces.  Other white space characters give the same
>> results.
>> 
>> This doesn't seem right to me, and in fact, there appears to be a work
>> around for this issue in expandargv where we have this code:
>> 
>>/* If the file is empty or contains only whitespace, buildargv would
>>   return a single empty argument.  In this context we want no arguments,
>>   instead.  */
>>if (only_whitespace (buffer))
>>  {
>>file_argv = (char **) xmalloc (sizeof (char *));
>>file_argv[0] = NULL;
>>  }
>>else
>>  /* Parse the string.  */
>>  file_argv = buildargv (buffer);
>> 
>> I think that the correct behaviour in this situation is to return an
>> empty argv array, e.g.:
>> 
>>char **argv = buildargv (" ");
>>assert (argv[0] == NULL);
>> 
>> And it turns out that this is a trivial change to buildargv.  The diff
>> does look big, but this is because I've re-indented a block.  Check
>> with 'git diff -b' to see the minimal changes.  I've also removed the
>> work around from expandargv.
>> 
>> When testing this sort of thing I normally write the tests first, and
>> then fix the code.  In this case test-expandargv.c has sort-of been
>> used as a mechanism for testing the buildargv function (expandargv
>> does call buildargv most of the time), however, for this particular
>> issue the work around in expandargv (mentioned above) masked the
>> buildargv bug.
>> 
>> I did consider adding a new test-buildargv.c file, however, this would
>> have basically been a copy & paste of test-expandargv.c (with some
>> minor changes to call buildargv).  This would be fine now, but feels
>> like we would eventually end up with one file not being updated as
>> much as the other, and so test coverage would suffer.
>> 
>> Instead, I have added some explicit buildargv testing to the
>> test-expandargv.c file, this reuses the test input that is already
>> defined for expandargv.
>> 
>> Of course, once I removed the work around from expandargv then we now
>> do always call buildargv from expandargv, and so the bug I'm fixing
>> would impact both expandargv and buildargv, so maybe the new testing
>> is redundant?  I tend to think more testing is always better, so I've
>> left it in for now.
> So just an FYI.  Sometimes folks include the -b diffs as well for these 
> scenarios.  THe problem with doing so (as I recently stumbled over 
> myself) is the bots which monitor the list and apply patches get quite 
> confused by that practice.  Anyway, just something to be aware of.

I meant to say: I used to do this (diff -b), but I stopped as it was
causing more problems.  Not just bots trying to apply patches, but
reviewers who want to download and apply patches to test.

I'm happy to send the reduced diff if it helps though.

Thanks,
Andrew



Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-07-29 Thread Andrew Burgess
Thomas Schwinge  writes:

> Hi!
>
> On 2024-02-10T17:26:01+0000, Andrew Burgess  wrote:
>> --- a/libiberty/argv.c
>> +++ b/libiberty/argv.c
>
>> @@ -439,17 +442,8 @@ expandargv (int *argcp, char ***argvp)
>>  }
>>/* Add a NUL terminator.  */
>>buffer[len] = '\0';
>> -  /* If the file is empty or contains only whitespace, buildargv would
>> - return a single empty argument.  In this context we want no arguments,
>> - instead.  */
>> -  if (only_whitespace (buffer))
>> -{
>> -  file_argv = (char **) xmalloc (sizeof (char *));
>> -  file_argv[0] = NULL;
>> -}
>> -  else
>> -/* Parse the string.  */
>> -file_argv = buildargv (buffer);
>> +  /* Parse the string.  */
>> +  file_argv = buildargv (buffer);
>>/* If *ARGVP is not already dynamically allocated, copy it.  */
>>if (*argvp == original_argv)
>>  *argvp = dupargv (*argvp);
>
> With that (single) use of 'only_whitespace' now gone:
>
> [...]/source-gcc/libiberty/argv.c:128:1: warning: ‘only_whitespace’ 
> defined but not used [-Wunused-function]
>   128 | only_whitespace (const char* input)
>       | ^~~
>

Sorry about that.

The patch below is the obvious fix.  OK to apply?

Thanks,
Andrew

---

commit c4533957b8424a3780180b47834350897674c776
Author: Andrew Burgess 
Date:   Mon Jul 29 13:47:32 2024 +0100

libiberty/argv.c: remove only_whitespace

After the commit:

  commit 5e1d530da87a6d2aa7e719744cb278e7e54a6623 (gcc-buildargv)
  Date:   Sat Feb 10 11:22:13 2024 +

  libiberty/buildargv: handle input consisting of only white space

    The function only_whitespace (in argv.c) was no longer being called.
Lets delete it.

There should be no user visible changes after this commit.

2024-07-29  Andrew Burgess  

libiberty/

* argv.c (only_whitespace): Delete.

diff --git a/libiberty/argv.c b/libiberty/argv.c
index 675336273f3..f889432a868 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -124,15 +124,6 @@ consume_whitespace (const char **input)
 }
 }
 
-static int
-only_whitespace (const char* input)
-{
-  while (*input != EOS && ISSPACE (*input))
-input++;
-
-  return (*input == EOS);
-}
-
 /*
 
 @deftypefn Extension char** buildargv (char *@var{sp})




Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space

2024-08-05 Thread Andrew Burgess
Jeff Law  writes:

> On 7/29/24 6:51 AM, Andrew Burgess wrote:
>> Thomas Schwinge  writes:
>> 
>>> Hi!
>>>
>>> On 2024-02-10T17:26:01+, Andrew Burgess  wrote:
>>>> --- a/libiberty/argv.c
>>>> +++ b/libiberty/argv.c
>>>
>>>> @@ -439,17 +442,8 @@ expandargv (int *argcp, char ***argvp)
>>>>}
>>>> /* Add a NUL terminator.  */
>>>> buffer[len] = '\0';
>>>> -  /* If the file is empty or contains only whitespace, buildargv would
>>>> -   return a single empty argument.  In this context we want no arguments,
>>>> -   instead.  */
>>>> -  if (only_whitespace (buffer))
>>>> -  {
>>>> -file_argv = (char **) xmalloc (sizeof (char *));
>>>> -file_argv[0] = NULL;
>>>> -  }
>>>> -  else
>>>> -  /* Parse the string.  */
>>>> -  file_argv = buildargv (buffer);
>>>> +  /* Parse the string.  */
>>>> +  file_argv = buildargv (buffer);
>>>> /* If *ARGVP is not already dynamically allocated, copy it.  */
>>>> if (*argvp == original_argv)
>>>>*argvp = dupargv (*argvp);
>>>
>>> With that (single) use of 'only_whitespace' now gone:
>>>
>>>  [...]/source-gcc/libiberty/argv.c:128:1: warning: ‘only_whitespace’ 
>>> defined but not used [-Wunused-function]
>>>128 | only_whitespace (const char* input)
>>>| ^~~
>>>
>> 
>> Sorry about that.
>> 
>> The patch below is the obvious fix.  OK to apply?
> Of course.
> jeff

Pushed.

Thanks,
Andrew



Re: [PATCHv2 0/2] Changes to libiberty buildargv

2024-04-27 Thread Andrew Burgess


Ping!

Any thoughts on these patches?

Thanks,
Andrew


Andrew Burgess  writes:

> I realise that these patches are not going to get merged until GCC is
> back in stage 1, but thought I'd post my latest set of changes for the
> libiberty buildargv function.
>
> Patch #1 is unchanged from V1.
>
> Patch #2 is new in V2.
>
> Thanks,
> Andrew
>
> ---
>
> Andrew Burgess (2):
>   libiberty/buildargv: POSIX behaviour for backslash handling
>   libiberty/buildargv: handle input consisting of only white space
>
>  libiberty/argv.c  | 104 
>  libiberty/testsuite/test-expandargv.c | 170 ++
>  2 files changed, 200 insertions(+), 74 deletions(-)
>
>
> base-commit: cff174fabd6c980c09aee95db1d9d5c22421761f
> -- 
> 2.25.4



[PATCH 03/10] gcc/arc: generate jump tables in code section for nps400

2016-03-04 Thread Andrew Burgess
When code runs from section loaded into fast memory we do not want it to
use rodata section from a slow memory for any jump tables.  This commit
turns on CASE_VECTOR_PC_RELATIVE by default for NPS400 targets, which in
turn turns on JUMP_TABLES_IN_TEXT_SECTION, which will place the jump
tables into the code section.

As a later optimisation we could be smarter about this, only turning on
inline jump tables when the code section is not the default code
section (.text), which we assume is not loaded into fast memory.

gcc/ChangeLog:

* config/arc/arc.opt (TARGET_CASE_VECTOR_PC_RELATIVE): Default on
for NPS400.
---
 gcc/ChangeLog.NPS400   | 7 +++
 gcc/config/arc/arc.opt | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 0281640..716e413 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,10 @@
+2015-09-08  Andrew Burgess  
+   Joern Rennecke  
+   Noam Camus  
+
+   * config/arc/arc.opt (TARGET_CASE_VECTOR_PC_RELATIVE): Default on
+   for NPS400.
+
 2016-02-02  Joern Rennecke  
Andrew Burgess  
 
diff --git a/gcc/config/arc/arc.opt b/gcc/config/arc/arc.opt
index f8e062c..55a5b32 100644
--- a/gcc/config/arc/arc.opt
+++ b/gcc/config/arc/arc.opt
@@ -283,7 +283,7 @@ Target Var(TARGET_BBIT_PEEPHOLE)
 Enable bbit peephole2.
 
 mcase-vector-pcrel
-Target Var(TARGET_CASE_VECTOR_PC_RELATIVE)
+Target Var(TARGET_CASE_VECTOR_PC_RELATIVE) Init(ARC_NPS400 != 0)
 Use pc-relative switch case tables - this enables case table shortening.
 
 mcompact-casesi
-- 
2.6.4



[PATCH 01/10] gcc: Add support for mellanox nps400 arc variant

2016-03-04 Thread Andrew Burgess
This commit adds support for the mellanox nps400 arc variant.  Nothing
much actually changes with this commit other than adding support for
'arc*-mellanox-*' targets at configuration time.

I've added a new makefile fragment for the mellanox variant, right now
there's not much in here, I'll be adding some content in a later commit,
but adding the file now lets me get all of the build
infrastructure (config.gcc) changes done in a single commit.

gcc/ChangeLog:

* config.gcc: Add support for arc*-mellanox-* nps400 targets.
* config/arc/t-nps400: New file.
---
 gcc/ChangeLog.NPS400|  5 +
 gcc/config.gcc  | 10 ++
 gcc/config/arc/t-nps400 | 21 +
 3 files changed, 36 insertions(+)
 create mode 100644 gcc/config/arc/t-nps400

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 4e68491..286f2dd 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,8 @@
+2016-02-01  Andrew Burgess  
+
+   * config.gcc: Add support for arc*-mellanox-* nps400 targets.
+   * config/arc/t-nps400: New file.
+
 2016-02-02  Andrew Burgess  
 
* common.opt (ffat-lto-objects): Make this flag default on.
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6722260..9a48dca 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1015,6 +1015,11 @@ arc*-*-elf*)
case ${with_endian} in
big*)   
tm_defines="DRIVER_ENDIAN_SELF_SPECS=\\\"%{!EL:%{!mlittle-endian:-mbig-endian}}\\\"
 ${tm_defines}"
esac
+   case ${target} in
+   arc*-mellanox-*)
+   tm_defines="${tm_defines} ARC_NPS400=1"
+   tmake_file="${tmake_file} arc/t-nps400";;
+   esac
;;
 arc*-*-linux-uclibc*)
extra_headers="arc-simd.h"
@@ -1040,6 +1045,11 @@ arc*-*-linux-uclibc*)
case ${with_endian} in
big*)   
tm_defines="DRIVER_ENDIAN_SELF_SPECS=\\\"%{!EL:%{!mlittle-endian:-mbig-endian}}\\\"
 ${tm_defines}"
esac
+   case ${target} in
+   arc*-mellanox-*)
+   tm_defines="${tm_defines} ARC_NPS400=1"
+   tmake_file="${tmake_file} arc/t-nps400";;
+   esac
 ;;
 arm-wrs-vxworks)
tm_file="elfos.h arm/elf.h arm/aout.h ${tm_file} vx-common.h vxworks.h 
arm/vxworks.h"
diff --git a/gcc/config/arc/t-nps400 b/gcc/config/arc/t-nps400
new file mode 100644
index 000..e332e24
--- /dev/null
+++ b/gcc/config/arc/t-nps400
@@ -0,0 +1,21 @@
+# GCC Makefile fragment for Mellanox NPS400 variant of Synopsys
+# DesignWare ARC
+
+# Copyright (C) 2016 Free Software Foundation, Inc.
+
+# 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 published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+
+# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along
+# with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+MULTILIB_OPTIONS=
-- 
2.6.4



[PATCH 04/10] gcc/arc: Replace rI constraint with r & Cm2 for ld and update insns

2016-03-04 Thread Andrew Burgess
In the load*_update instructions the constraint 'rI' was being used,
which would accept either a register or a signed 12 bit constant.  The
problem is that the 32-bit form of ld with update only takes a signed
9-bit immediate.  As such, some ld instructions could be generated that
would, when assembled be 64-bit long, however, GCC believed them to be
32-bit long.  This error in the length would cause problems during
branch shortening.

The store*_update have the same restrictions on immediate size, however,
the patterns for these instructions already only accept 9-bit
immediates, and so should be safe.

gcc/ChangeLog:

* config/arc/arc.md (*loadqi_update): Replace use of 'rI'
constraint with separate 'r' and 'Cm2' constraints.
(*load_zeroextendqisi_update): Likewise.
(*load_signextendqisi_update): Likewise.
(*loadhi_update): Likewise.
(*load_zeroextendhisi_update): Likewise.
(*load_signextendhisi_update): Likewise.
(*loadsi_update): Likewise.
(*loadsf_update): Likewise.
---
 gcc/ChangeLog.NPS400  | 12 +++
 gcc/config/arc/arc.md | 96 +--
 2 files changed, 60 insertions(+), 48 deletions(-)

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 716e413..71463df 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,15 @@
+2016-02-01  Andrew Burgess  
+
+   * config/arc/arc.md (*loadqi_update): Replace use of 'rI'
+   constraint with separate 'r' and 'Cm2' constraints.
+   (*load_zeroextendqisi_update): Likewise.
+   (*load_signextendqisi_update): Likewise.
+   (*loadhi_update): Likewise.
+   (*load_zeroextendhisi_update): Likewise.
+   (*load_signextendhisi_update): Likewise.
+   (*loadsi_update): Likewise.
+   (*loadsf_update): Likewise.
+
 2015-09-08  Andrew Burgess  
Joern Rennecke  
Noam Camus  
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 4193d26..99e8e30 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -1151,40 +1151,40 @@
 
 ;; Note: loadqi_update has no 16-bit variant
 (define_insn "*loadqi_update"
-  [(set (match_operand:QI 3 "dest_reg_operand" "=r,r")
+  [(set (match_operand:QI 3 "dest_reg_operand" "=r,r,r")
 (match_operator:QI 4 "any_mem_operand"
- [(plus:SI (match_operand:SI 1 "register_operand" "0,0")
-   (match_operand:SI 2 "nonmemory_operand" "rI,Cal"))]))
-   (set (match_operand:SI 0 "dest_reg_operand" "=r,r")
+ [(plus:SI (match_operand:SI 1 "register_operand" "0,0,0")
+   (match_operand:SI 2 "nonmemory_operand" "r,Cm2,Cal"))]))
+   (set (match_operand:SI 0 "dest_reg_operand" "=r,r,r")
(plus:SI (match_dup 1) (match_dup 2)))]
   ""
   "ldb.a%V4 %3,[%0,%S2]"
-  [(set_attr "type" "load,load")
-   (set_attr "length" "4,8")])
+  [(set_attr "type" "load,load,load")
+   (set_attr "length" "4,4,8")])
 
 (define_insn "*load_zeroextendqisi_update"
-  [(set (match_operand:SI 3 "dest_reg_operand" "=r,r")
+  [(set (match_operand:SI 3 "dest_reg_operand" "=r,r,r")
(zero_extend:SI (match_operator:QI 4 "any_mem_operand"
-[(plus:SI (match_operand:SI 1 "register_operand" "0,0")
-  (match_operand:SI 2 "nonmemory_operand" 
"rI,Cal"))])))
-   (set (match_operand:SI 0 "dest_reg_operand" "=r,r")
+[(plus:SI (match_operand:SI 1 "register_operand" 
"0,0,0")
+  (match_operand:SI 2 "nonmemory_operand" 
"r,Cm2,Cal"))])))
+   (set (match_operand:SI 0 "dest_reg_operand" "=r,r,r")
(plus:SI (match_dup 1) (match_dup 2)))]
   ""
   "ldb.a%V4 %3,[%0,%S2]"
-  [(set_attr "type" "load,load")
-   (set_attr "length" "4,8")])
+  [(set_attr "type" "load,load,load")
+   (set_attr "length" "4,4,8")])
 
 (define_insn "*load_signextendqisi_update"
-  [(set (match_operand:SI 3 "dest_reg_operand" "=r,r")
+  [(set (match_operand:SI 3 "dest_reg_operand" "=r,r,r")
(sign_extend:SI (match_operator:QI 4 "any_mem_operand"
-[(plus:SI (match_operand:SI 1 "register_operand" "0,0")
-  (match_operand:SI 2 "nonmemory_operand" 
"rI,Cal&q

[PATCH 00/10] ARC: Add support for NPS400 variant

2016-03-04 Thread Andrew Burgess
The NPS400 is an ARC700 variant from Mellanox (formally EZChip).

This patch series adds a new GCC build target with the mellanox vendor
string, that configures the ARC backend to support NPS400.

This patch series is intended for GCC 7, Stage 1, once it reopens.  I
am posting early in the hope that I could get an early review,
especially on patch #1, the build infrastructure, then if I need to
rework anything I can get started on it sooner.

I've run regression tests against a standard arc-elf target, and the
results look good.

All feedback appreciated.

Thanks,
Andrew

---

Andrew Burgess (10):
  gcc: Add support for mellanox nps400 arc variant
  gcc/arc: Add -munaligned-access option for nps400
  gcc/arc: generate jump tables in code section for nps400
  gcc/arc: Replace rI constraint with r & Cm2 for ld and update insns
  gcc/arc: convert some constraints to define_constraint
  gcc/arc: Add support for nps400 cmem xld/xst instructions
  gcc/arc: Add nps400 bitops support
  gcc/arc: Mask integer 'L' operands to 32-bit
  gcc/arc: Add an nps400 specific testcase
  gcc/arc: Add __NPS400__ define for nps400 targets

 gcc/ChangeLog.NPS400  | 122 +++
 gcc/config.gcc|  10 +
 gcc/config/arc/arc.c  |  67 +++-
 gcc/config/arc/arc.h  |  35 +-
 gcc/config/arc/arc.md | 567 +++---
 gcc/config/arc/arc.opt|  14 +-
 gcc/config/arc/constraints.md |  86 -
 gcc/config/arc/predicates.md  |  19 +
 gcc/config/arc/t-nps400   |  21 ++
 gcc/testsuite/ChangeLog.NPS400|  44 +++
 gcc/testsuite/gcc.target/arc/cmem-1.c |  10 +
 gcc/testsuite/gcc.target/arc/cmem-2.c |  10 +
 gcc/testsuite/gcc.target/arc/cmem-3.c |  10 +
 gcc/testsuite/gcc.target/arc/cmem-4.c |  10 +
 gcc/testsuite/gcc.target/arc/cmem-5.c |  10 +
 gcc/testsuite/gcc.target/arc/cmem-6.c |  10 +
 gcc/testsuite/gcc.target/arc/cmem-7.c |  26 ++
 gcc/testsuite/gcc.target/arc/cmem-ld.inc  |  16 +
 gcc/testsuite/gcc.target/arc/cmem-st.inc  |  18 +
 gcc/testsuite/gcc.target/arc/extzv-1.c|  11 +
 gcc/testsuite/gcc.target/arc/insv-1.c |  21 ++
 gcc/testsuite/gcc.target/arc/insv-2.c |  18 +
 gcc/testsuite/gcc.target/arc/movb-1.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-2.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-3.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-4.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-5.c |  13 +
 gcc/testsuite/gcc.target/arc/movb_cl-1.c  |   9 +
 gcc/testsuite/gcc.target/arc/movb_cl-2.c  |  11 +
 gcc/testsuite/gcc.target/arc/movbi_cl-1.c |   9 +
 gcc/testsuite/gcc.target/arc/movh_cl-1.c  |  27 ++
 gcc/testsuite/gcc.target/arc/movl-1.c |  17 +
 gcc/testsuite/gcc.target/arc/mrgb-1.c |  14 +
 gcc/testsuite/gcc.target/arc/nps400-1.c   |  23 ++
 gcc/testsuite/gcc.target/arc/setmem-1.c   |  13 +
 gcc/testsuite/gcc.target/arc/setmem-2.c   |  18 +
 gcc/testsuite/gcc.target/arc/setmem-3.c   |  13 +
 gcc/testsuite/gcc.target/arc/setmem-4.c   |  18 +
 38 files changed, 1231 insertions(+), 161 deletions(-)
 create mode 100644 gcc/config/arc/t-nps400
 create mode 100644 gcc/testsuite/ChangeLog.NPS400
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-3.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-4.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-5.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-6.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-7.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-ld.inc
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-st.inc
 create mode 100644 gcc/testsuite/gcc.target/arc/extzv-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/insv-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/insv-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-3.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-4.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-5.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb_cl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb_cl-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movbi_cl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movh_cl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/mrgb-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/nps400-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-3.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-4.c

-- 
2.6.4



[PATCH 05/10] gcc/arc: convert some constraints to define_constraint

2016-03-04 Thread Andrew Burgess
The define_memory_constraint allows for the address operand to be
reloaded into a base register.  However, for the constraints 'Us<' and
'Us>', which are used for matching 'push' and 'pop' instructions moving
the address into a base register is not helpful.  The constraints then
should be define_constraint, not define_memory_constraint.

Similarly the Usd constraint, used for generating small data area memory
accesses, can't have its operand loaded into a register as the
relocation for small data area symbols only works within ld/st
instructions.

gcc/ChangeLog:

* config/arc/constraints.md (Usd): Convert to define_constraint.
(Us<): Likewise.
(Us>): Likewise.
---
 gcc/ChangeLog.NPS400  |  7 +++
 gcc/config/arc/constraints.md | 18 +++---
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 71463df..5d1533c 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,10 @@
+2016-03-01  Joern Rennecke  
+   Andrew Burgess  
+
+   * config/arc/constraints.md (Usd): Convert to define_constraint.
+   (Us<): Likewise.
+   (Us>): Likewise.
+
 2016-02-01  Andrew Burgess  
 
* config/arc/arc.md (*loadqi_update): Replace use of 'rI'
diff --git a/gcc/config/arc/constraints.md b/gcc/config/arc/constraints.md
index 668b60a..b6954ad 100644
--- a/gcc/config/arc/constraints.md
+++ b/gcc/config/arc/constraints.md
@@ -269,11 +269,15 @@
   (and (match_code "mem")
(match_test "compact_store_memory_operand (op, VOIDmode)")))
 
-(define_memory_constraint "Usd"
-  "@internal
-   A valid _small-data_ memory operand for ARCompact instructions"
-  (and (match_code "mem")
-   (match_test "compact_sda_memory_operand (op, VOIDmode)")))
+; Don't use define_memory_constraint here as the relocation patching
+; for small data symbols only works within a ld/st instruction and
+; define_memory_constraint may result in the address being calculated
+; into a register first.
+(define_constraint "Usd"
+   "@internal
+A valid _small-data_ memory operand for ARCompact instructions"
+   (and (match_code "mem")
+(match_test "compact_sda_memory_operand (op, VOIDmode)")))
 
 (define_memory_constraint "Usc"
   "@internal
@@ -283,7 +287,7 @@
 ;; ??? the assembler rejects stores of immediates to small data.
(match_test "!compact_sda_memory_operand (op, VOIDmode)")))
 
-(define_memory_constraint "Us<"
+(define_constraint "Us<"
   "@internal
Stack pre-decrement"
   (and (match_code "mem")
@@ -291,7 +295,7 @@
(match_test "REG_P (XEXP (XEXP (op, 0), 0))")
(match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG")))
 
-(define_memory_constraint "Us>"
+(define_constraint "Us>"
   "@internal
Stack post-increment"
   (and (match_code "mem")
-- 
2.6.4



[PATCH 02/10] gcc/arc: Add -munaligned-access option for nps400

2016-03-04 Thread Andrew Burgess
New option for nps400 arc (-munaligned-access) that allows GCC to
generate unaligned accesses, the option is off by default.  Turning this
option on will update the value for STRICT_ALIGNMENT.

gcc/ChangeLog:

* config/arc/arc.h (ARC_NPS400): Define if not already defined.
(UNALIGNED_ACCESS_DEFAULT): Define, if not already defined.
(STRICT_ALIGNMENT): Make use of unaligned_access var.
* config/arc/arc.c (arc_expand_movmem): Take STRICT_ALIGNMENT into
account.
* config/arc/arc.opt: (munaligned-access): New option.
* config/arc/t-nps400: Add munaligned-access to the multilib list.

gcc/testsuite/ChangeLog:

* gcc.target/arc/setmem-1.c: New file.
* gcc.target/arc/setmem-2.c: New file.
* gcc.target/arc/setmem-3.c: New file.
* gcc.target/arc/setmem-4.c: New file.
---
 gcc/ChangeLog.NPS400| 11 +++
 gcc/config/arc/arc.c|  4 ++--
 gcc/config/arc/arc.h| 19 +++
 gcc/config/arc/arc.opt  |  4 
 gcc/config/arc/t-nps400 |  2 +-
 gcc/testsuite/ChangeLog.NPS400  |  6 ++
 gcc/testsuite/gcc.target/arc/setmem-1.c | 13 +
 gcc/testsuite/gcc.target/arc/setmem-2.c | 18 ++
 gcc/testsuite/gcc.target/arc/setmem-3.c | 13 +
 gcc/testsuite/gcc.target/arc/setmem-4.c | 18 ++
 10 files changed, 101 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/ChangeLog.NPS400
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-3.c
 create mode 100644 gcc/testsuite/gcc.target/arc/setmem-4.c

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 286f2dd..0281640 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,14 @@
+2016-02-02  Joern Rennecke  
+   Andrew Burgess  
+
+   * config/arc/arc.h (ARC_NPS400): Define if not already defined.
+   (UNALIGNED_ACCESS_DEFAULT): Define, if not already defined.
+   (STRICT_ALIGNMENT): Make use of unaligned_access var.
+   * config/arc/arc.c (arc_expand_movmem): Take STRICT_ALIGNMENT into
+   account.
+   * config/arc/arc.opt: (munaligned-access): New option.
+   * config/arc/t-nps400: Add munaligned-access to the multilib list.
+
 2016-02-01  Andrew Burgess  
 
* config.gcc: Add support for arc*-mellanox-* nps400 targets.
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index d60db50..35bb44a 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -7137,7 +7137,7 @@ arc_expand_movmem (rtx *operands)
   HOST_WIDE_INT size;
   int align = INTVAL (operands[3]);
   unsigned n_pieces;
-  int piece = align;
+  int piece = STRICT_ALIGNMENT ? align : 4;
   rtx store[2];
   rtx tmpx[2];
   int i;
@@ -7146,7 +7146,7 @@ arc_expand_movmem (rtx *operands)
 return false;
   size = INTVAL (operands[2]);
   /* move_by_pieces_ninsns is static, so we can't use it.  */
-  if (align >= 4)
+  if (align >= 4 || !STRICT_ALIGNMENT)
 {
   if (TARGET_LL64)
n_pieces = (size + 4) / 8U + ((size >> 1) & 1) + (size & 1);
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index 21c049f..1cb59ec 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -62,6 +62,10 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_APP_OFF
 #undef CC1_SPEC
 
+#ifndef ARC_NPS400
+#define ARC_NPS400 0
+#endif
+
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_CPU_CPP_BUILTINS()  \
  do {  \
@@ -309,6 +313,10 @@ along with GCC; see the file COPYING3.  If not see
 #define MULTILIB_DEFAULTS { "mARC700" }
 #endif
 
+#ifndef UNALIGNED_ACCESS_DEFAULT
+#define UNALIGNED_ACCESS_DEFAULT 0
+#endif
+
 /* Target machine storage layout.  */
 
 /* We want zero_extract to mean the same
@@ -416,10 +424,13 @@ if (GET_MODE_CLASS (MODE) == MODE_INT \
 
 /* Set this nonzero if move instructions will actually fail to work
when given unaligned data.  */
-/* On the ARC the lower address bits are masked to 0 as necessary.  The chip
-   won't croak when given an unaligned address, but the insn will still fail
-   to produce the correct result.  */
-#define STRICT_ALIGNMENT 1
+/* On most ARC cores the lower address bits are masked to 0 as necessary,
+   the chip won't croak when given an unaligned address, but the insn will
+   still fail to produce the correct result.  */
+/* The NPS400 ARC variant supports unaligned access.  Although not without
+   cost, this is still fast enough that we can justify keeping
+   SLOW_UNALIGNED_ACCESS off.  */
+#define STRICT_ALIGNMENT (!unaligned_access)
 
 /* Layout of source language data types.  */
 
diff --git a/gcc/config/arc/arc.opt b/gcc/config/arc/arc.opt
index 2227b75

[PATCH 09/10] gcc/arc: Add an nps400 specific testcase

2016-03-04 Thread Andrew Burgess
This test case triggered a bug caused by VOIDmode not being handled in
proper_comparison_operator, this problem was fixed with a commit on
2016-01-27 by Claudiu Zissulescu, adding this test case for coverage.

gcc/testsuite/ChangeLog:

* gcc.target/arc/nps400-1.c: New file.
---
 gcc/testsuite/ChangeLog.NPS400  |  4 
 gcc/testsuite/gcc.target/arc/nps400-1.c | 23 +++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/arc/nps400-1.c

diff --git a/gcc/testsuite/ChangeLog.NPS400 b/gcc/testsuite/ChangeLog.NPS400
index d658bd9..20f88d0 100644
--- a/gcc/testsuite/ChangeLog.NPS400
+++ b/gcc/testsuite/ChangeLog.NPS400
@@ -1,3 +1,7 @@
+2016-02-06  Andrew Burgess  
+
+   * gcc.target/arc/nps400-1.c: New file.
+
 2016-01-19  Andrew Burgess  
 
* gcc.target/arc/movh_cl-1.c: New file.
diff --git a/gcc/testsuite/gcc.target/arc/nps400-1.c 
b/gcc/testsuite/gcc.target/arc/nps400-1.c
new file mode 100644
index 000..57d6800
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/nps400-1.c
@@ -0,0 +1,23 @@
+/* { dg-do compile { target arc*-mellanox-* } } */
+/* { dg-options "-mq-class -mbitops -munaligned-access -mcmem -O2 
-fno-strict-aliasing" } */
+
+enum npsdp_mem_space_type {
+  NPSDP_EXTERNAL_MS = 1
+};
+struct npsdp_ext_addr {
+  struct {
+struct {
+  enum npsdp_mem_space_type mem_type : 1;
+  unsigned msid : 5;
+};
+  };
+  char user_space[];
+} a;
+char b;
+void fn1() {
+  ((struct npsdp_ext_addr *)a.user_space)->mem_type = NPSDP_EXTERNAL_MS;
+  ((struct npsdp_ext_addr *)a.user_space)->msid =
+  ((struct npsdp_ext_addr *)a.user_space)->mem_type ? 1 : 10;
+  while (b)
+;
+}
-- 
2.6.4



[PATCH 08/10] gcc/arc: Mask integer 'L' operands to 32-bit

2016-03-04 Thread Andrew Burgess
When formatting 'L' operands (least significant word) only print
32-bits, don't sign extend to 64-bits.

This commit could really be applied directly to the current GCC trunk,
however, the only test I have for this issue right now relies on the
nps400 bitops support.

gcc/ChangeLog:

* config/arc/arc.c (arc_print_operand): Print integer 'L' operands
as 32-bits.

gcc/testsuite/ChangeLog:

* gcc.target/arc/movh_cl-1.c: New file.
---
 gcc/ChangeLog.NPS400 |  6 ++
 gcc/config/arc/arc.c | 10 --
 gcc/testsuite/ChangeLog.NPS400   |  4 
 gcc/testsuite/gcc.target/arc/movh_cl-1.c | 27 +++
 4 files changed, 41 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/movh_cl-1.c

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 8229d67..146370c 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,9 @@
+2016-01-19  Joern Rennecke  
+   Andrew Burgess  
+
+   * config/arc/arc.c (arc_print_operand): Print integer 'L' operands
+   as 32-bits.
+
 2013-02-19  Joern Rennecke  
Andrew Burgess  
 
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index a75f200..dc885d3 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -3176,18 +3176,16 @@ arc_print_operand (FILE *file, rtx x, int code)
   else if (GET_CODE (x) == CONST_INT
   || GET_CODE (x) == CONST_DOUBLE)
{
- rtx first, second;
+ rtx first, second, word;
 
  split_double (x, &first, &second);
 
  if((WORDS_BIG_ENDIAN) == 0)
- fprintf (file, "0x%08" PRIx64,
-  code == 'L' ? INTVAL (first) : INTVAL (second));
+   word = (code == 'L' ? first : second);
  else
- fprintf (file, "0x%08" PRIx64,
-  code == 'L' ? INTVAL (second) : INTVAL (first));
-
+   word = (code == 'L' ? second : first);
 
+ fprintf (file, "0x%08" PRIx32, ((uint32_t) INTVAL (word)));
  }
   else
output_operand_lossage ("invalid operand to %%H/%%L code");
diff --git a/gcc/testsuite/ChangeLog.NPS400 b/gcc/testsuite/ChangeLog.NPS400
index 22dec32..d658bd9 100644
--- a/gcc/testsuite/ChangeLog.NPS400
+++ b/gcc/testsuite/ChangeLog.NPS400
@@ -1,3 +1,7 @@
+2016-01-19  Andrew Burgess  
+
+   * gcc.target/arc/movh_cl-1.c: New file.
+
 2013-02-19  Joern Rennecke  
Andrew Burgess  
 
diff --git a/gcc/testsuite/gcc.target/arc/movh_cl-1.c 
b/gcc/testsuite/gcc.target/arc/movh_cl-1.c
new file mode 100644
index 000..8fbea7e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/movh_cl-1.c
@@ -0,0 +1,27 @@
+/* { dg-do compile { target arc*-mellanox-* } } */
+/* { dg-options "-O2 -mbitops" } */
+
+struct thing
+{
+  union
+  {
+int raw;
+struct
+{
+  unsigned a : 1;
+  unsigned b : 1;
+};
+  };
+};
+
+extern void func (int);
+
+void
+blah ()
+{
+  struct thing xx;
+  xx.a = xx.b = 1;
+  func (xx.raw);
+}
+
+/* { dg-final { scan-assembler "movh\.cl r\[0-9\]+,0xc000>>16" } } */
-- 
2.6.4



[PATCH 06/10] gcc/arc: Add support for nps400 cmem xld/xst instructions

2016-03-04 Thread Andrew Burgess
This commit adds support for NPS400 cmem memory sections.  Data to be
placed into cmem memory is placed into a section ".cmem",
".cmem_shared", or ".cmem_private".

There are restrictions on how instructions can be used to operate on
data held in cmem memory, this is reflected by the introduction of new
operand constraints (Uex/Ucm), and modifications to some instructions to
make use of these constraints.

gcc/ChangeLog:

* config/arc/arc.h (SYMBOL_FLAG_CMEM): Define.
(TARGET_NPS400_CMEM_DEFAULT): Provide default definition.
* config/arc/arc.c (arc_address_cost): Return 0 for cmem_address.
(arc_encode_section_info): Set SYMBOL_FLAG_CMEM where indicated.
* config/arc/arc.opt (mcmem): New option.
* config/arc/arc.md (*extendqihi2_i): Add r/Uex alternative,
supply length for r/m alternative.
(*extendqisi2_ac): Likewise.
(*extendhisi2_i): Add r/Uex alternative, supply length for r/m and
r/Uex alternative.
(movqi_insn): Add r/Ucm and Ucm/?Rac alternatives.
(movhi_insn): Likewise.
(movsi_insn): Add r/Ucm,Ucm/w alternatives.
(*zero_extendqihi2_i): Add r/Ucm alternative.
(*zero_extendqisi2_ac): Likewise.
(*zero_extendhisi2_i): Likewise.
* config/arc/constraints.md (Uex): New memory constraint.
(Ucm): New define_constraint.
* config/arc/predicates.md (long_immediate_loadstore_operand):
Return 0 for MEM with cmem_address address.
(cmem_address_0): New predicates.
(cmem_address_1): Likewise.
(cmem_address_2): Likewise.
(cmem_address): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/arc/cmem-1.c: New file.
* gcc.target/arc/cmem-2.c: New file.
* gcc.target/arc/cmem-3.c: New file.
* gcc.target/arc/cmem-4.c: New file.
* gcc.target/arc/cmem-5.c: New file.
* gcc.target/arc/cmem-6.c: New file.
* gcc.target/arc/cmem-7.c: New file.
* gcc.target/arc/cmem-ld.inc: New file.
* gcc.target/arc/cmem-st.inc: New file.
---
 gcc/ChangeLog.NPS400 |  28 
 gcc/config/arc/arc.c |  20 ++
 gcc/config/arc/arc.h |   5 ++
 gcc/config/arc/arc.md| 115 +--
 gcc/config/arc/arc.opt   |   4 ++
 gcc/config/arc/constraints.md|  14 +++-
 gcc/config/arc/predicates.md |  19 +
 gcc/testsuite/ChangeLog.NPS400   |  13 
 gcc/testsuite/gcc.target/arc/cmem-1.c|  10 +++
 gcc/testsuite/gcc.target/arc/cmem-2.c|  10 +++
 gcc/testsuite/gcc.target/arc/cmem-3.c|  10 +++
 gcc/testsuite/gcc.target/arc/cmem-4.c|  10 +++
 gcc/testsuite/gcc.target/arc/cmem-5.c|  10 +++
 gcc/testsuite/gcc.target/arc/cmem-6.c|  10 +++
 gcc/testsuite/gcc.target/arc/cmem-7.c|  26 +++
 gcc/testsuite/gcc.target/arc/cmem-ld.inc |  16 +
 gcc/testsuite/gcc.target/arc/cmem-st.inc |  18 +
 17 files changed, 287 insertions(+), 51 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-3.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-4.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-5.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-6.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-7.c
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-ld.inc
 create mode 100644 gcc/testsuite/gcc.target/arc/cmem-st.inc

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 5d1533c..2a0f820 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,31 @@
+2013-08-31  Joern Rennecke  
+   Andrew Burgess  
+
+   * config/arc/arc.h (SYMBOL_FLAG_CMEM): Define.
+   (TARGET_NPS400_CMEM_DEFAULT): Provide default definition.
+   * config/arc/arc.c (arc_address_cost): Return 0 for cmem_address.
+   (arc_encode_section_info): Set SYMBOL_FLAG_CMEM where indicated.
+   * config/arc/arc.opt (mcmem): New option.
+   * config/arc/arc.md (*extendqihi2_i): Add r/Uex alternative,
+   supply length for r/m alternative.
+   (*extendqisi2_ac): Likewise.
+   (*extendhisi2_i): Add r/Uex alternative, supply length for r/m and
+   r/Uex alternative.
+   (movqi_insn): Add r/Ucm and Ucm/?Rac alternatives.
+   (movhi_insn): Likewise.
+   (movsi_insn): Add r/Ucm,Ucm/w alternatives.
+   (*zero_extendqihi2_i): Add r/Ucm alternative.
+   (*zero_extendqisi2_ac): Likewise.
+   (*zero_extendhisi2_i): Likewise.
+   * config/arc/constraints.md (Uex): New memory constraint.
+   (Ucm): New define_constraint.
+   * config/arc/predicates.md (long_immediate_loadstore_operand):
+   Return 0 for MEM with cmem_address address.
+   (cmem_address_0): New predicates.
+   

[PATCH 10/10] gcc/arc: Add __NPS400__ define for nps400 targets

2016-03-04 Thread Andrew Burgess
Arrange to have the define __NPS400__ defined when compiling code for
Mellanox NPS400 ARC variant.

gcc/ChangeLog:

* conig/arc/arc.h (TARGET_CPU_CPP_BUILTINS): Add __NPS400__.
---
 gcc/ChangeLog.NPS400 | 4 
 gcc/config/arc/arc.h | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 146370c..e1889b9 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,7 @@
+2016-02-08  Andrew Burgess  
+
+   * conig/arc/arc.h (TARGET_CPU_CPP_BUILTINS): Add __NPS400__.
+
 2016-01-19  Joern Rennecke  
Andrew Burgess  
 
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index f278bf5..0330ab4 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -120,6 +120,8 @@ along with GCC; see the file COPYING3.  If not see
? "__BIG_ENDIAN__" : "__LITTLE_ENDIAN__"); \
 if (TARGET_BIG_ENDIAN) \
   builtin_define ("__big_endian__"); \
+if (ARC_NPS400)\
+  builtin_define ("__NPS400__");   \
 } while(0)
 
 #if DEFAULT_LIBC == LIBC_UCLIBC
-- 
2.6.4



[PATCH 07/10] gcc/arc: Add nps400 bitops support

2016-03-04 Thread Andrew Burgess
Add support for nps400 bit operation instructions.  There's a new flag
-mbitops that turns this feature on.  There are new instructions, some
changes to existing instructions, a new register class to support the
new instructions, and some new expand and peephole optimisations.

gcc/ChangeLog:

* config/arc/arc.c (arc_conditional_register_usage): Take
TARGET_RRQ_CLASS into account.
(arc_print_operand): Support printing 'p' and 's' operands.
* config/arc/arc.h (TARGET_NPS400_BITOPS_DEFAULT): Provide default
as 0.
(TARGET_RRQ_CLASS): Define.
(IS_POWEROF2_OR_0_P): Define.
* config/arc/arc.md (*movsi_insn): Add w/Clo, w/Chi, and w/Cbi
alternatives.
(*tst_movb): New define_insn.
(*tst): Avoid recognition if it could prevent '*tst_movb'
combination; replace c/CnL with c/Chs alternative.
(*tst_bitfield_tst): New define_insn.
(*tst_bitfield_asr): New define_insn.
(*tst_bitfield): New define_insn.
(andsi3_i): Add Rrq variant.
(extzv): New define_expand.
(insv): New define_expand.
(*insv_i): New define_insn.
(*movb): New define_insn.
(*movb_signed): New define_insn.
(*movb_high): New define_insn.
(*movb_high_signed): New define_insn.
(*movb_high_signed + 1): New define_split pattern.
(*mrgb): New define_insn.
(*mrgb + 1): New define_peephole2 pattern.
(*mrgb + 2): New define_peephole2 pattern.
* config/arc/arc.opt (mbitops): New option for nps400, uses
TARGET_NPS400_BITOPS_DEFAULT.
* config/arc/constraints.md (q): Make register class conditional.
(Rrq): New register constraint.
(Chs): New constraint.
(Clo): New constraint.
(Chi): New constraint.
(Cbf): New constraint.
(Cbn): New constraint.
(C18): New constraint.
(Cbi): New constraint.

gcc/testsuite/ChangeLog:

* gcc.target/arc/extzv-1.c: New file.
* gcc.target/arc/insv-1.c: New file.
* gcc.target/arc/insv-2.c: New file.
* gcc.target/arc/movb-1.c: New file.
* gcc.target/arc/movb-2.c: New file.
* gcc.target/arc/movb-3.c: New file.
* gcc.target/arc/movb-4.c: New file.
* gcc.target/arc/movb-5.c: New file.
* gcc.target/arc/movb_cl-1.c: New file.
* gcc.target/arc/movb_cl-2.c: New file.
* gcc.target/arc/movbi_cl-1.c: New file.
* gcc.target/arc/movl-1.c: New file.
* gcc.target/arc/mrgb-1.c: New file.
---
 gcc/ChangeLog.NPS400  |  42 
 gcc/config/arc/arc.c  |  33 ++-
 gcc/config/arc/arc.h  |   9 +
 gcc/config/arc/arc.md | 382 ++
 gcc/config/arc/arc.opt|   4 +
 gcc/config/arc/constraints.md |  58 -
 gcc/testsuite/ChangeLog.NPS400|  17 ++
 gcc/testsuite/gcc.target/arc/extzv-1.c|  11 +
 gcc/testsuite/gcc.target/arc/insv-1.c |  21 ++
 gcc/testsuite/gcc.target/arc/insv-2.c |  18 ++
 gcc/testsuite/gcc.target/arc/movb-1.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-2.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-3.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-4.c |  13 +
 gcc/testsuite/gcc.target/arc/movb-5.c |  13 +
 gcc/testsuite/gcc.target/arc/movb_cl-1.c  |   9 +
 gcc/testsuite/gcc.target/arc/movb_cl-2.c  |  11 +
 gcc/testsuite/gcc.target/arc/movbi_cl-1.c |   9 +
 gcc/testsuite/gcc.target/arc/movl-1.c |  17 ++
 gcc/testsuite/gcc.target/arc/mrgb-1.c |  14 ++
 20 files changed, 663 insertions(+), 57 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/extzv-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/insv-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/insv-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-3.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-4.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb-5.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb_cl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movb_cl-2.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movbi_cl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/movl-1.c
 create mode 100644 gcc/testsuite/gcc.target/arc/mrgb-1.c

diff --git a/gcc/ChangeLog.NPS400 b/gcc/ChangeLog.NPS400
index 2a0f820..8229d67 100644
--- a/gcc/ChangeLog.NPS400
+++ b/gcc/ChangeLog.NPS400
@@ -1,3 +1,45 @@
+2013-02-19  Joern Rennecke  
+   Andrew Burgess  
+
+   * config/arc/arc.c (arc_conditional_register_usage): Take
+   TARGET_RRQ_CLASS into account.
+   (arc_print_operand): Support printing 'p' and 's' operands.
+   * config/arc/arc.h (TARGET_NPS400_BITOPS_DEFAULT): Provide d

[PATCH] contrib: Add KPASS support to dg-extract-results.{sh,py}

2019-10-03 Thread Andrew Burgess
My motivation for the patch below comes from GDB.  The binutils-gdb
project maintains a copy of the contrib directory that it keeps in
sync with upstream GCC, and patches to contrib/ are ideally first
applied to GCC then backported to binutils-gdb.

This patch extends the dg-extract-results.* scripts to support KPASS
results.  These results are a part of standard dejagnu.

I haven't checked if this is going to impact GCC, but if it does, it
should only be a good impact - adding previously missing results into
the final .sum file.  I tested on GDB and we now pick up some
previously missing results.

Will this be OK to apply?

Thanks,
Andrew

---

Extend dg-extract-results.sh and dg-extract-results.py to support the
KPASS test result status.  This is required by GDB which uses a copy
of the dg-extract-results.{sh,py} scripts that it tries to keep in
sync with GCC.

ChangeLog:

* contrib/dg-extract-results.sh: Add support for KPASS.
* contrib/dg-extract-results.py: Likewise.
---
 ChangeLog | 5 +
 contrib/dg-extract-results.py | 2 +-
 contrib/dg-extract-results.sh | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/contrib/dg-extract-results.py b/contrib/dg-extract-results.py
index 4e113a8dd6b..7100794d42a 100644
--- a/contrib/dg-extract-results.py
+++ b/contrib/dg-extract-results.py
@@ -117,7 +117,7 @@ class Prog:
 self.tool_re = re.compile (r'^\t\t=== (.*) tests ===$')
 self.result_re = re.compile (r'^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED'
  r'|WARNING|ERROR|UNSUPPORTED|UNTESTED'
- r'|KFAIL):\s*(.+)')
+ r'|KFAIL|KPASS):\s*(.+)')
 self.completed_re = re.compile (r'.* completed at (.*)')
 # Pieces of text to write at the head of the output.
 # start_line is a pair in which the first element is a datetime
diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
index 97ac222b54a..f948088370e 100755
--- a/contrib/dg-extract-results.sh
+++ b/contrib/dg-extract-results.sh
@@ -326,7 +326,7 @@ BEGIN {
   }
 }
 /^\t\t=== .* ===$/ { curvar = ""; next }
-/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/
 {
+/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL|KPASS):/
 {
   testname=\$2
   # Ugly hack for gfortran.dg/dg.exp
   if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
-- 
2.14.5



Re: [PATCH] RISC-V: Include more registers in SIBCALL_REGS.

2019-10-17 Thread Andrew Burgess
* Jim Wilson  [2019-10-16 14:04:45 -0700]:

> This finishes the part 1 of 2 patch submitted by Andrew Burgess on Aug 19.
> This adds the argument registers but not t0 (aka x5) to SIBCALL_REGS.  It
> also adds the missing riscv_regno_to_class change.
> 
> Tested with cross riscv32-elf and riscv64-linux toolchain build and check.
> There were no regressions.  I see about a 0.01% code size reduction for the
> C and libstdc++ libraries.
> 
> Committed.

Thanks for doing this Jim.

I'm still working on part 2, I'm hoping to have a revised patch posted
by Monday next week.

Thanks again,
Andrew



> 
> Jim
> 
>   gcc/
>   * config/riscv/riscv.h (REG_CLASS_CONTENTS): Add argument passing
>   regs to SIBCALL_REGS.
>   * config/riscv/riscv.c (riscv_regno_to_class): Change argument
>   passing regs to SIBCALL_REGS.
> ---
>  gcc/config/riscv/riscv.c | 6 +++---
>  gcc/config/riscv/riscv.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
> index b8a8778b92c..77a3ad94aa8 100644
> --- a/gcc/config/riscv/riscv.c
> +++ b/gcc/config/riscv/riscv.c
> @@ -256,9 +256,9 @@ enum riscv_microarchitecture_type riscv_microarchitecture;
>  const enum reg_class riscv_regno_to_class[FIRST_PSEUDO_REGISTER] = {
>GR_REGS,   GR_REGS,GR_REGS,GR_REGS,
>GR_REGS,   GR_REGS,SIBCALL_REGS,   SIBCALL_REGS,
> -  JALR_REGS, JALR_REGS,  JALR_REGS,  JALR_REGS,
> -  JALR_REGS, JALR_REGS,  JALR_REGS,  JALR_REGS,
> -  JALR_REGS, JALR_REGS,  JALR_REGS,  JALR_REGS,
> +  JALR_REGS, JALR_REGS,  SIBCALL_REGS,   SIBCALL_REGS,
> +  SIBCALL_REGS,  SIBCALL_REGS,   SIBCALL_REGS,   SIBCALL_REGS,
> +  SIBCALL_REGS,  SIBCALL_REGS,   JALR_REGS,  JALR_REGS,
>JALR_REGS, JALR_REGS,  JALR_REGS,  JALR_REGS,
>JALR_REGS, JALR_REGS,  JALR_REGS,  JALR_REGS,
>SIBCALL_REGS,  SIBCALL_REGS,   SIBCALL_REGS,   SIBCALL_REGS,
> diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
> index 5fc9be8edbf..246494663f6 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 */  \
> +  { 0xf003fcc0, 0x, 0x },/* SIBCALL_REGS */  \
>{ 0xffc0, 0x, 0x },/* JALR_REGS */ \
>{ 0x, 0x, 0x },/* GR_REGS */   \
>{ 0x, 0x, 0x },/* FP_REGS */   \
> -- 
> 2.17.1
> 


Re: [PATCH] RISC-V: Include more registers in SIBCALL_REGS.

2019-10-17 Thread Andrew Burgess
* Jim Wilson  [2019-10-17 14:55:34 -0700]:

> On Thu, Oct 17, 2019 at 7:09 AM Andrew Burgess
>  wrote:
> > I'm still working on part 2, I'm hoping to have a revised patch posted
> > by Monday next week.
> 
> I started looking at the part 2 patch also.  I noticed a problem where
> the NOTE_INSN_EPILOGUE_BEGIN can occur before the
> NOTE_INSN_PROLOGUE_END due to branch and basic block optimizations, I
> get an ICE in this case due to deref of a null pointer.  This is
> pretty easy to fix, I just added a check to
> riscv_remove_unneeded_save_restore_calls in the loop that searches for
> NOTE_INSN_PROLOGUE_END, and if I find NOTE_INSN_EPILOGUE_BEGIN first I
> exit without doing anything.  A more complex fix would be to try to
> follow the CFG instead of scanning forward from the prologue end note
> to find the epilogue begin note.  I also noticed a case where the
> __riscv_save_0 call was optimized away but the __riscv_restore_0 call
> was not.  In this case the function has two epilogues, and only one of
> the two epilogues was optimized.  We could just check for more than
> one epilogue and return without doing any work as the simple fix.  Or
> a more complex fix is to try to handle more than one epilogue.
> 
> Given the kinds of problems I'm seeing, I think there should be an
> option to control this optimization, so people can turn it off is
> necessary.  I think it is OK if this is on by default if it passes the
> gcc testsuite.
> 
> Since you are looking at this, I can look at something else for a few
> days.  I was just trying to get this off of my backlog.

It's entirely up to you.  I believe I have a version testing now that
addresses all of the issues you mentioned above.  I haven't added a
switch for it, but can do if you want.

My expectation was that I would post a version on Monday that had zero
regressions when run with -msave-restore forced on (as you described
in a previous mail).

I'll continue to work on this and post on Monday unless you drop a
revision earlier.

Thanks,

Andrew


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

2019-10-21 Thread Andrew Burgess
Below is a new versions of this patch, I believe that this addresses
the review comments from the earlier version.  In addition this has
been tested using Jim's idea of forcing -msave-restore (if the flag is
not otherwise given) and I now see no test failures for newlib and
linux toolchains.

One thing that has been mentioned briefly was adding a flag to control
just this optimisation, I haven't done that yet, but can if that is
required - obviously this optimisation doesn't do anything if
-msave-restore is turned off, so that is always an option.  With no
test failures I don't know if a separate flag is required.

Thanks,
Andrew

---

commit f1b824e94f3ea396bd0ef46692d5211f855d4b4c
Author: Andrew Burgess 
Date:   Thu Jul 18 16:03:10 2019 +0100

gcc/riscv: Add a mechanism to remove some calls to _riscv_save_0

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

diff --git a/gcc/config.gcc b/gcc/config.gcc
index bdc2253f8ef..b4440877e99 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -523,7 +523,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 000..977f21b3e37
--- /dev/null
+++ b/gcc/config/riscv/riscv-sr.c
@@ -0,0 +1,465 @@
+/* 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 published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.

[PATCH] contrib: Handle GDB specific test result types

2020-05-11 Thread Andrew Burgess
This commit is for the benefit of GDB, but as the binutils-gdb
repository shares the contrib/ directory with gcc, this commit must
first be applied to gcc then copied back to binutils-gdb.

This commit extends the two scripts contrib/dg-extract-results.{py,sh}
to handle some new, GDB specific test result types.  These test
results types should never appear in GCC, or any other tool that
shares the contrib/ directly, so this change should be harmless.

In this patch series:
  https://sourceware.org/pipermail/gdb-patches/2020-April/167847.html
changes were made in GDB's use of Dejagnu so that two additional
conditions could be detected, these are:

  1. Test names that contain either the build or source paths.  Such
  test names make it difficult to compare the results of two test runs
  of GDB from two different directories, and

  2. Duplicate test names.  Duplicates make it difficult to track down
  exactly which test has failed.

When running Dejagnu on GDB we can now (sometimes) see two additional
test result types matching the above conditions, these are '# of paths
in test names' and '# of duplicate test names'.

If the test is run in parallel mode (make -j...) then these extra test
results will appear in the individual test summary files, but are not
merged into the final summary file.

Additionally, within the summary file there are now two new types of
test summary line, these are 'PATH: ...' and 'DUPLICATE: ...', these
allow users to quickly search the test summary to track down where the
offending test names are.  These lines are similarly not merged into
the unified gdb.sum file after a parallel test run.

This commit extends the dg-extract-results.* scripts to calculate the
totals for the two new result types, and to copy the new test summary
lines into the unified summary file.

contrib/ChangeLog:

* dg-extract-results.py: Handle GDB specific test types.
* dg-extract-results.sh: Likewise.
---
 contrib/ChangeLog |  5 +
 contrib/dg-extract-results.py |  6 --
 contrib/dg-extract-results.sh | 12 +++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/contrib/dg-extract-results.py b/contrib/dg-extract-results.py
index 7100794d42a..30aa68771d4 100644
--- a/contrib/dg-extract-results.py
+++ b/contrib/dg-extract-results.py
@@ -117,7 +117,7 @@ class Prog:
 self.tool_re = re.compile (r'^\t\t=== (.*) tests ===$')
 self.result_re = re.compile (r'^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED'
  r'|WARNING|ERROR|UNSUPPORTED|UNTESTED'
- r'|KFAIL|KPASS):\s*(.+)')
+ r'|KFAIL|KPASS|PATH|DUPLICATE):\s*(.+)')
 self.completed_re = re.compile (r'.* completed at (.*)')
 # Pieces of text to write at the head of the output.
 # start_line is a pair in which the first element is a datetime
@@ -143,7 +143,9 @@ class Prog:
 '# of known failures\t\t',
 '# of untested testcases\t\t',
 '# of unresolved testcases\t',
-'# of unsupported tests\t\t'
+'# of unsupported tests\t\t',
+'# of paths in test names\t',
+'# of duplicate test names\t'
 ]
 self.runs = dict()
 
diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
index f948088370e..ff6c50d029c 100755
--- a/contrib/dg-extract-results.sh
+++ b/contrib/dg-extract-results.sh
@@ -326,7 +326,7 @@ BEGIN {
   }
 }
 /^\t\t=== .* ===$/ { curvar = ""; next }
-/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL|KPASS):/
 {
+/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL|KPASS|PATH|DUPLICATE):/
 {
   testname=\$2
   # Ugly hack for gfortran.dg/dg.exp
   if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
@@ -400,6 +400,7 @@ BEGIN {
   variant="$VAR"
   tool="$TOOL"
   passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; 
kfailcnt=0; unsupcnt=0; unrescnt=0; dgerrorcnt=0;
+  pathcnt=0; dupcnt=0
   curvar=""; insummary=0
 }
 /^Running target / { curvar = \$3; next }
@@ -414,6 +415,8 @@ BEGIN {
 /^# of untested testcases/ { if (insummary == 1) untstcnt += \$5; next; }
 /^# of unresolved testcases/   { if (insummary == 1) unrescnt += \$5; next; }
 /^# of unsupported tests/  { if (insummary == 1) unsupcnt += \$5; next; }
+/^# of paths in test names/{ if (insummary == 1) pathcnt += \$7; next; }
+/^# of duplicate test names/   { if (insummary == 1) dupcnt += \$6; next; }
 /^$/   { if (insummary == 1)
{ insummary = 0; curvar = "" }
  next
@@ -431,6 +434,8 @@ END {
   if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
   if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
   if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
+  if 

Re: [PATCH 1/7] [ARC] Add support for naked functions.

2017-06-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-06-01 15:34:51 
+0200]:

> gcc/
> 2016-12-13  Claudiu Zissulescu  
>       Andrew Burgess  
> 
>   * config/arc/arc-protos.h (arc_compute_function_type): Change prototype.
>   (arc_return_address_register): New function.
>   * config/arc/arc.c (arc_handle_fndecl_attribute): New function.
>   (arc_handle_fndecl_attribute): Add naked attribute.
>   (TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS): Define.
>   (TARGET_WARN_FUNC_RETURN): Likewise.
>   (arc_allocate_stack_slots_for_args): New function.
>   (arc_warn_func_return): Likewise.
>   (machine_function): Change type fn_type.
>   (arc_compute_function_type): Consider new naked function type,
>   change function return type.
>   (arc_must_save_register): Adapt to handle new
>   arc_compute_function_type's return type.
>   (arc_expand_prologue): Likewise.
>   (arc_expand_epilogue): Likewise.
>   (arc_return_address_regs): Delete.
>   (arc_return_address_register): New function.
>   (arc_epilogue_uses): Use above function.
>   * config/arc/arc.h (arc_return_address_regs): Delete prototype.
>   (arc_function_type): Change encoding, add naked type.
>   (ARC_INTERRUPT_P): Change to handle the new encoding.
>   (ARC_FAST_INTERRUPT_P): Likewise.
>   (ARC_NORMAL_P): Define.
>   (ARC_NAKED_P): Likewise.
>   (arc_compute_function_type): Delete prototype.
>   * config/arc/arc.md (in_ret_delay_slot): Use
>   arc_return_address_register function.
>   (simple_return): Likewise.
>   (p_return_i): Likewise.
> 
> gcc/testsuite
> 2016-12-13  Claudiu Zissulescu  
>   Andrew Burgess  
> 
>   * gcc.target/arc/naked-1.c: New file.
>   * gcc.target/arc/naked-2.c: Likewise.

Claudiu,

Sorry it's taken me a while to look at these patches.

I tried to apply this to the current GCC head, and it looks for me
like this doesn't apply.  Specifically `arc_expand_epilogue` does not
appear (in the current head) to have the code expected in this patch.

I have double checked at my end, but could you confirm that the patch
does apply cleanly for you please, then I'll spend some additional
time trying to figure out what I've done wrong :)

Thanks,
Andrew





> ---
>  gcc/config/arc/arc-protos.h|   6 +-
>  gcc/config/arc/arc.c   | 165 
> -
>  gcc/config/arc/arc.h   |  40 +---
>  gcc/config/arc/arc.md  |  10 +-
>  gcc/testsuite/gcc.target/arc/naked-1.c |  18 
>  gcc/testsuite/gcc.target/arc/naked-2.c |  26 ++
>  6 files changed, 197 insertions(+), 68 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/naked-1.c
>  create mode 100644 gcc/testsuite/gcc.target/arc/naked-2.c
> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index 4ff8e9b..b436dbe 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -45,12 +45,10 @@ extern void arc_expand_atomic_op (enum rtx_code, rtx, 
> rtx, rtx, rtx, rtx);
>  extern void arc_split_compare_and_swap (rtx *);
>  extern void arc_expand_compare_and_swap (rtx *);
>  extern bool compact_memory_operand_p (rtx, machine_mode, bool, bool);
> +extern int arc_return_address_register (unsigned int);
> +extern unsigned int arc_compute_function_type (struct function *);
>  #endif /* RTX_CODE */
>  
> -#ifdef TREE_CODE
> -extern enum arc_function_type arc_compute_function_type (struct function *);
> -#endif /* TREE_CODE */
> -
>  extern bool arc_ccfsm_branch_deleted_p (void);
>  extern void arc_ccfsm_record_branch_deleted (void);
>  
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index a65fc3a..7dfc68e 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -211,6 +211,7 @@ static int rgf_banked_register_count;
>  static int get_arc_condition_code (rtx);
>  
>  static tree arc_handle_interrupt_attribute (tree *, tree, tree, int, bool *);
> +static tree arc_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
>  
>  /* Initialized arc_attribute_table to NULL since arc doesnot have any
> machine specific supported attributes.  */
> @@ -229,6 +230,9 @@ const struct attribute_spec arc_attribute_table[] =
>/* And these functions are always known to reside within the 21 bit
>   addressing range of blcc.  */
>{ "short_call",   0, 0, false, true,  true,  NULL, false },
> +  /* Function which are not having the prologue and epilogue generated
> + by the compiler.  */
> +  { "naked", 0, 0, true, false, false, arc_handle_fndecl_attribute, false },
>{ NULL, 0, 0, false, false, false,

Re: [PATCH 2/7] [ARC] Define ADDITIONAL_REGISTER_NAMES.

2017-06-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-06-01 15:34:52 
+0200]:

> This macro is needed to be used with -ffixed- option, and inline asm.
> 
> gcc/
> 2017-01-09  Claudiu Zissulescu  
> 
>   * config/arc/arc.h (ADDITIONAL_REGISTER_NAMES): Define.

This looks fine and could be applied straight away I think.

Thanks,
Andrew

> ---
>  gcc/config/arc/arc.h | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index 16d5319..585e98c 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -1262,6 +1262,13 @@ extern char rname56[], rname57[], rname58[], rname59[];
>"lp_start", "lp_end" \
>  }
>  
> +#define ADDITIONAL_REGISTER_NAMES\
> +{\
> +  {"ilink",  29},\
> +  {"r29",29},\
> +  {"r30",30} \
> +}
> +
>  /* Entry to the insn conditionalizer.  */
>  #define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS) \
>arc_final_prescan_insn (INSN, OPVEC, NOPERANDS)
> -- 
> 1.9.1
> 


Re: [PATCH 3/7] [ARC] [LRA] Fix tests asm constraints.

2017-06-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-06-01 15:34:53 
+0200]:

> LRA doesn't like the 'X' constraint as used in our tests, remove it.
> 
> gcc/testsuite
> 2017-01-09  Claudiu Zissulescu  
> 
>   * gcc.target/arc/mulsi3_highpart-1.c: Remove 'X' constraint.
>   * gcc.target/arc/mulsi3_highpart-2.c: Likewise.

This looks fine and could be applied straight away I think.

Thanks,
Andrew



> ---
>  gcc/testsuite/gcc.target/arc/mulsi3_highpart-1.c | 2 +-
>  gcc/testsuite/gcc.target/arc/mulsi3_highpart-2.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/testsuite/gcc.target/arc/mulsi3_highpart-1.c 
> b/gcc/testsuite/gcc.target/arc/mulsi3_highpart-1.c
> index 57cb95b..5fd6c36 100644
> --- a/gcc/testsuite/gcc.target/arc/mulsi3_highpart-1.c
> +++ b/gcc/testsuite/gcc.target/arc/mulsi3_highpart-1.c
> @@ -7,7 +7,7 @@
>  static int
>  id (int i)
>  {
> -  asm ("": "+Xr" (i));
> +  asm ("": "+r" (i));
>return i;
>  }
>  
> diff --git a/gcc/testsuite/gcc.target/arc/mulsi3_highpart-2.c 
> b/gcc/testsuite/gcc.target/arc/mulsi3_highpart-2.c
> index 287d96d..6ec4bc5 100644
> --- a/gcc/testsuite/gcc.target/arc/mulsi3_highpart-2.c
> +++ b/gcc/testsuite/gcc.target/arc/mulsi3_highpart-2.c
> @@ -9,7 +9,7 @@
>  static int
>  id (int i)
>  {
> -  asm ("": "+Xr" (i));
> +  asm ("": "+r" (i));
>return i;
>  }
>  
> -- 
> 1.9.1
> 


Re: [PATCH] [ARC] Reimplement exception handling support.

2017-11-07 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:00:09 
+0100]:

> This is patch which solves the ARC issues with exception handling support.
> 
> Ok to apply?

Mostly OK, my only comment is about the comments!  There's a couple of
places where the comments are phrased in terms of "this commit" and
"see changes".  Comments in the code should (I think) be phrased in
terms of how the code is right now (or at least after the changes is
merged), so:

(see changes to arc_frame_pointer_required)

becomes

(see arc_frame_pointer_required)

while:

This issue is fixed in this commit too.

can probably be deleted completely.

Otherwise, I'm happy.

Thanks,
Andrew




> Claudiu
> 
> 2016-06-09  Claudiu Zissulescu  
>   Andrew Burgess  
> 
>   * config/arc/arc-protos.h (arc_compute_frame_size): Delete
>   declaration.
>   (arc_return_slot_offset): Likewise.
>   (arc_eh_return_address_location): New declaration.
>   * config/arc/arc.c (TARGET_BUILTIN_SETJMP_FRAME_VALUE): Define.
>   (MUST_SAVE_REGISTER): Add exception handler case.
>   (MUST_SAVE_RETURN_ADDR): Likewise.
>   (arc_frame_pointer_required): Likewise.
>   (arc_frame_pointer_needed): New function.
>   (arc_compute_frame_size): Changed.
>   (arc_expand_prologue): Likewise.
>   (arc_expand_epilogue): Likewise.
>   (arc_initial_elimination_offset): Likewise.
>   (arc_return_slot_offset): Delete.
>   (arc_eh_return_address_location): New function.
>   (arc_builtin_setjmp_frame_value): Likewise.
>   * config/arc/arc.h (EH_RETURN_DATA_REGNO): Use 2 registers.
>   (EH_RETURN_STACKADJ_RTX): Define.
>   (EH_RETURN_HANDLER_RTX): Likewise.
>   * config/arc/arc.md (eh_return): Delete.
> ---
>  gcc/config/arc/arc-protos.h |   2 +-
>  gcc/config/arc/arc.c| 202 
> +++-
>  gcc/config/arc/arc.h|   7 +-
>  gcc/config/arc/arc.md   |  33 
>  4 files changed, 166 insertions(+), 78 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index 1c7031c..6e7239f 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -111,8 +111,8 @@ extern bool arc_epilogue_uses (int regno);
>  extern bool arc_eh_uses (int regno);
>  /* insn-attrtab.c doesn't include reload.h, which declares 
> regno_clobbered_p. */
>  extern int regno_clobbered_p (unsigned int, rtx_insn *, machine_mode, int);
> -extern int arc_return_slot_offset (void);
>  extern bool arc_legitimize_reload_address (rtx *, machine_mode, int, int);
>  extern void arc_secondary_reload_conv (rtx, rtx, rtx, bool);
>  extern void arc_cpu_cpp_builtins (cpp_reader *);
>  extern bool arc_store_addr_hazard_p (rtx_insn *, rtx_insn *);
> +extern rtx arc_eh_return_address_location (void);
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index a0b66758..75d35cd 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -597,6 +597,8 @@ static void arc_finalize_pic (void);
>  
>  #undef TARGET_MODES_TIEABLE_P
>  #define TARGET_MODES_TIEABLE_P arc_modes_tieable_p
> +#undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
> +#define TARGET_BUILTIN_SETJMP_FRAME_VALUE arc_builtin_setjmp_frame_value
>  
>  /* Try to keep the (mov:DF _, reg) as early as possible so
> that the dh-lr insns appear together and can
> @@ -2556,8 +2558,7 @@ arc_compute_function_type (struct function *fun)
> Addition for pic: The gp register needs to be saved if the current
> function changes it to access gotoff variables.
> FIXME: This will not be needed if we used some arbitrary register
> -   instead of r26.
> -*/
> +   instead of r26.  */
>  
>  static bool
>  arc_must_save_register (int regno, struct function *func)
> @@ -2620,14 +2621,51 @@ arc_must_save_return_addr (struct function *func)
>  /* Helper function to wrap FRAME_POINTER_NEEDED.  We do this as
> FRAME_POINTER_NEEDED will not be true until the IRA (Integrated
> Register Allocator) pass, while we want to get the frame size
> -   correct earlier than the IRA pass.  */
> +   correct earlier than the IRA pass.
> +
> +   When a function uses eh_return we must ensure that the fp register
> +   is saved and then restored so that the unwinder can restore the
> +   correct value for the frame we are going to jump to.
> +
> +   To do this we force all frames that call eh_return to require a
> +   frame pointer (see changes to arc_frame_pointer_required), this
> +   will ensure that the previous frame pointer is stored on entry to
> +   the function, and will then be reloaded at function exit.
> +
> +   As the frame pointer is handled as a special case in our prologue

Re: [PATCH 01/10] [ARC][LRA] Use TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV.

2017-11-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:50 
+0100]:

> From: Claudiu Zissulescu 
> 
> Sometimes the memory equivalent is not valid due to a large offset.
> For example replacing the ap register with its fp/sp-equivalent during
> LRA step. To solve this we introduced TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV.
> 
> gcc/
> 2017-08-08  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_cannot_substitute_mem_equiv_p): New function.
>   (TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV_P): Define.
> 
> gcc/testsuite
> 2017-08-08  Claudiu Zissulescu  
> 
>   * gcc.target/arc/lra-1.c: New test.

Looks good.

Thanks,
Andrew


> ---
>  gcc/config/arc/arc.c | 12 
>  gcc/testsuite/gcc.target/arc/lra-1.c | 17 +
>  2 files changed, 29 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/arc/lra-1.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index dd922a6..25f123c 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -11352,12 +11352,24 @@ arc_use_anchors_for_symbol_p (const_rtx symbol)
>return default_use_anchors_for_symbol_p (symbol);
>  }
>  
> +/* Return true if SUBST can't safely replace its equivalent during RA.  */
> +static bool
> +arc_cannot_substitute_mem_equiv_p (rtx)
> +{
> +  /* If SUBST is mem[base+index], the address may not fit iSA, 
> + thus return true. */
> +  return true;
> +}
> +
>  #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
>  #define TARGET_USE_ANCHORS_FOR_SYMBOL_P arc_use_anchors_for_symbol_p
>  
>  #undef TARGET_CONSTANT_ALIGNMENT
>  #define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings
>  
> +#undef TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV_P
> +#define TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV_P 
> arc_cannot_substitute_mem_equiv_p
> +
>  struct gcc_target targetm = TARGET_INITIALIZER;
>  
>  #include "gt-arc.h"
> diff --git a/gcc/testsuite/gcc.target/arc/lra-1.c 
> b/gcc/testsuite/gcc.target/arc/lra-1.c
> new file mode 100644
> index 000..27336d1
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/lra-1.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-Os -w -mlra" } */
> +
> +/* ap is replaced with an address like base+offset by lra,
> +   where offset is larger than s9, resulting into an ICE.  */
> +
> +typedef struct { char a[500] } b;
> +c;
> +struct d {
> +  short e;
> +  b f
> +} g(int h, int i, int j, int k, char l, int m, int n, char *p) {
> +again:;
> +  struct d o;
> +  *p = c = ({ q(o); });
> +  goto again;
> +}
> -- 
> 1.9.1
> 


Re: [PATCH 02/10] [ARC][ZOL] Update uses for hw-loop labels.

2017-11-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:51 
+0100]:

> From: claziss 
> 
> Make sure we mark the hw-loop labels as beeing used.
> 
> gcc/
> 2017-09-19  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (hwloop_optimize): Update hw-loop's end/start
>   labels number of usages.
> 
> gcc/testsuite
> 2017-09-19  Claudiu Zissulescu  
> 
>   * gcc.target/arc/loop-2.cpp: New test.

Looks good.

Thanks,
Andrew

> ---
>  gcc/config/arc/arc.c|  3 +++
>  gcc/testsuite/gcc.target/arc/loop-2.cpp | 18 ++
>  2 files changed, 21 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/arc/loop-2.cpp
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 25f123c..964815a 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -7702,6 +7702,9 @@ hwloop_optimize (hwloop_info loop)
>/* Insert the loop end label before the last instruction of the
>   loop.  */
>emit_label_after (end_label, loop->last_insn);
> +  /* Make sure we mark the begining and end label as used.  */
> +  LABEL_NUSES (loop->end_label)++;
> +  LABEL_NUSES (loop->start_label)++;
>  
>return true;
>  }
> diff --git a/gcc/testsuite/gcc.target/arc/loop-2.cpp 
> b/gcc/testsuite/gcc.target/arc/loop-2.cpp
> new file mode 100644
> index 000..d1dc917
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/loop-2.cpp
> @@ -0,0 +1,18 @@
> +/* { dg-options "-O2" } *
> +/* { dg-do assemble } */
> +
> +/* This file fails to assemble if we forgot to increase the number of
> +   uses for loop's start and end labels.  */
> +int a, c, d;
> +int *b;
> +void fn1(int p1) {
> +  if (d == 5)
> +for (int i; i < p1; ++i)
> +  if (c)
> +b[i] = c;
> +  else
> +int t = a = t;
> +  else
> +for (int i; i < p1; ++i)
> +  b[i] = 0;
> +}
> -- 
> 1.9.1
> 


Re: [PATCH 03/10] [ARC] Don't allow the last ZOL insn to be in a delay slot.

2017-11-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:52 
+0100]:

> From: Claudiu Zissulescu 
> 
> The ARC ZOL implementation doesn't allow the last instruction to be a
> control instruction or part of a delay slot.  Thus, we add a note to
> the last ZOL instruction which will prevent it to finish into a delay
> slot.
> 
> 2017-10-20  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (hwloop_optimize): Prevent the last
> ZOL instruction to end into a delay slot.
>   * config/arc/arc.md (cond_delay_insn): Check if the instruction
>   can be placed into a delay slot against reg_note.
>   (in_delay_slot): Likewise.
> 
> testsuite/
> 2017-10-20  Claudiu Zissulescu  
> 
>   * gcc.target/arc/loop-3.c: New test.
>   * gcc.target/arc/loop-4.c: Likewise.

OK.

Thanks,
Andrew



> 
> [FIX][ZOL] fix checking for jumps
> ---
>  gcc/config/arc/arc.c  |  6 ++
>  gcc/config/arc/arc.md |  4 
>  gcc/testsuite/gcc.target/arc/loop-3.c | 27 +++
>  gcc/testsuite/gcc.target/arc/loop-4.c | 14 ++
>  4 files changed, 51 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/arc/loop-3.c
>  create mode 100644 gcc/testsuite/gcc.target/arc/loop-4.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 964815a..1479a8d 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -7609,6 +7609,12 @@ hwloop_optimize (hwloop_info loop)
>loop->loop_no);
>last_insn = emit_insn_after (gen_nopv (), last_insn);
>  }
> +
> +  /* SAVE_NOTE is used by haifa scheduler.  However, we are after it
> + and we can use it to indicate the last ZOL instruction cannot be
> + part of a delay slot.  */
> +  add_reg_note (last_insn, REG_SAVE_NOTE, GEN_INT (2));
> +
>loop->last_insn = last_insn;
>  
>/* Get the loop iteration register.  */
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 2e0ac52..6239483 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -472,6 +472,8 @@
>(symbol_ref "(arc_hazard (prev_active_insn (insn), insn)
>  + arc_hazard (insn, next_active_insn (insn)))"))
>(const_string "false")
> +  (match_test "find_reg_note (insn, REG_SAVE_NOTE, GEN_INT (2))")
> +  (const_string "false")
>(eq_attr "iscompact" "maybe") (const_string "true")
>]
>  
> @@ -499,6 +501,8 @@
>(cond [(eq_attr "cond" "!canuse") (const_string "no")
>(eq_attr "type" "call,branch,uncond_branch,jump,brcc")
>(const_string "no")
> +  (match_test "find_reg_note (insn, REG_SAVE_NOTE, GEN_INT (2))")
> +  (const_string "no")
>(eq_attr "length" "2,4") (const_string "yes")]
>   (const_string "no")))
>  
> diff --git a/gcc/testsuite/gcc.target/arc/loop-3.c 
> b/gcc/testsuite/gcc.target/arc/loop-3.c
> new file mode 100644
> index 000..bf7aec9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/loop-3.c
> @@ -0,0 +1,27 @@
> +/* { dg-do assemble } */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mno-sdata" } *
> +
> +/* This example will fail to assemble if the last instruction is a
> +   branch with delay slot.  */
> +int d;
> +extern char * fn2 (void);
> +
> +void fn1(void)
> +{
> +  char *a = fn2();
> +  for (;;) {
> +long long b;
> +int e = 8;
> +for (; e <= 63; e += 7) {
> +  long c = *a++;
> +  b += c & e;
> +  if (c & 28)
> +break;
> +}
> +d = b;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler "bne_s @.L2" } } */
> +/* { dg-final { scan-assembler-not "add.eq" } } */
> diff --git a/gcc/testsuite/gcc.target/arc/loop-4.c 
> b/gcc/testsuite/gcc.target/arc/loop-4.c
> new file mode 100644
> index 000..99a93a7
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/loop-4.c
> @@ -0,0 +1,14 @@
> +/* { dg-do assemble } */
> +/* { dg-do compile } */
> +/* { dg-options "-Os" } */
> +
> +
> +void fn1(void *p1, int p2, int p3)
> +{
> +  char *d = p1;
> +  do
> +*d++ = p2;
> +  while (--p3);
> +}
> +
> +/* { dg-final { scan-assembler "lp_count" } } */
> -- 
> 1.9.1
> 


Re: [PATCH 04/10] [ARC] Add ARCv2 core3 tune option.

2017-11-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:53 
+0100]:

> From: claziss 
> 
> ARCv2 Core3 cpus are comming with dbnz support. Add this feature on
> the tune option.
> 
> gcc/
> 2017-09-14  Claudiu Zissulescu  
> 
>   * config/arc/arc-arch.h (arc_tune_attr): Add ARC_TUNE_CORE_3.
>   * config/arc/arc.c (arc_sched_issue_rate): Use ARC_TUNE_... .
>   (arc_init): Likewise.
>   (arc_override_options): Likewise.
>   (arc_file_start): Choose Tag_ARC_CPU_variation based on arc_tune
>   value.
>   (hwloop_fail): Use TARGET_DBNZ when we want to check for dbnz insn
>   support.
>   * config/arc/arc.h (TARGET_DBNZ): Define.
>   * config/arc/arc.md (attr tune): Add core_3, use ARC_TUNE_... to
>   properly set the tune attribute.
>   (dbnz): Use TARGET_DBNZ guard.
>   * config/arc/arc.opt (mtune): Add core3 option.

OK.

Thanks,
Andrew


> ---
>  gcc/config/arc/arc-arch.h |  3 ++-
>  gcc/config/arc/arc.c  | 21 -
>  gcc/config/arc/arc.h  |  2 ++
>  gcc/config/arc/arc.md | 22 --
>  gcc/config/arc/arc.opt| 40 ++--
>  5 files changed, 50 insertions(+), 38 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-arch.h b/gcc/config/arc/arc-arch.h
> index 7c3f47c..38d2bcb 100644
> --- a/gcc/config/arc/arc-arch.h
> +++ b/gcc/config/arc/arc-arch.h
> @@ -75,7 +75,8 @@ enum arc_tune_attr
>  ARC_TUNE_ARC700_4_2_XMAC,
>  ARC_TUNE_ARCHS4X,
>  ARC_TUNE_ARCHS4XD,
> -ARC_TUNE_ARCHS4XD_SLOW
> +ARC_TUNE_ARCHS4XD_SLOW,
> +ARC_TUNE_CORE_3
>};
>  
>  /* CPU specific properties.  */
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 1479a8d..4d7a282 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -442,8 +442,8 @@ arc_sched_issue_rate (void)
>  {
>switch (arc_tune)
>  {
> -case TUNE_ARCHS4X:
> -case TUNE_ARCHS4XD:
> +case ARC_TUNE_ARCHS4X:
> +case ARC_TUNE_ARCHS4XD:
>return 3;
>  default:
>break;
> @@ -866,21 +866,21 @@ arc_init (void)
>if (arc_multcost < 0)
>  switch (arc_tune)
>{
> -  case TUNE_ARC700_4_2_STD:
> +  case ARC_TUNE_ARC700_4_2_STD:
>   /* latency 7;
>  max throughput (1 multiply + 4 other insns) / 5 cycles.  */
>   arc_multcost = COSTS_N_INSNS (4);
>   if (TARGET_NOMPY_SET)
> arc_multcost = COSTS_N_INSNS (30);
>   break;
> -  case TUNE_ARC700_4_2_XMAC:
> +  case ARC_TUNE_ARC700_4_2_XMAC:
>   /* latency 5;
>  max throughput (1 multiply + 2 other insns) / 3 cycles.  */
>   arc_multcost = COSTS_N_INSNS (3);
>   if (TARGET_NOMPY_SET)
> arc_multcost = COSTS_N_INSNS (30);
>   break;
> -  case TUNE_ARC600:
> +  case ARC_TUNE_ARC600:
>   if (TARGET_MUL64_SET)
> {
>   arc_multcost = COSTS_N_INSNS (4);
> @@ -1196,8 +1196,8 @@ arc_override_options (void)
>  #undef ARC_OPT
>  
>/* Set Tune option.  */
> -  if (arc_tune == TUNE_NONE)
> -arc_tune = (enum attr_tune) arc_selected_cpu->tune;
> +  if (arc_tune == ARC_TUNE_NONE)
> +arc_tune = (enum arc_tune_attr) arc_selected_cpu->tune;
>  
>if (arc_size_opt_level == 3)
>  optimize_size = 1;
> @@ -5205,6 +5205,9 @@ static void arc_file_start (void)
>  TARGET_NO_SDATA_SET ? 0 : 2);
>asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_ABI_exceptions, %d\n",
>  TARGET_OPTFPE ? 1 : 0);
> +  if (TARGET_V2)
> +asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_CPU_variation, 
> %d\n",
> +  arc_tune == ARC_TUNE_CORE_3 ? 3 : 2);
>  }
>  
>  /* Implement `TARGET_ASM_FILE_END'.  */
> @@ -7389,11 +7392,11 @@ hwloop_fail (hwloop_info loop)
>rtx test;
>rtx insn = loop->loop_end;
>  
> -  if (TARGET_V2
> +  if (TARGET_DBNZ
>&& (loop->length && (loop->length <= ARC_MAX_LOOP_LENGTH))
>&& REG_P (loop->iter_reg))
>  {
> -  /* TARGET_V2 has dbnz instructions.  */
> +  /* TARGET_V2 core3 has dbnz instructions.  */
>test = gen_dbnz (loop->iter_reg, loop->start_label);
>insn = emit_jump_insn_before (test, loop->loop_end);
>  }
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index b5a8f84..8d90975 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -1628,5 +1628,7 @@ enum
>  /* Custom FP instructions used by QuarkSE EM cpu.  */
>  #define TARGET_FPX_QUARK(TARGET_EM && TARGET_SPFP\
>&& (arc_fpu_build == FPX_QK))
> +/* DBNZ support is available for ARCv2 core3 cpus.  */
> +#define TARGET_DBNZ (TARGET_V2 && (arc_tune == ARC_TUNE_CORE_3))
>  
>  #endif /* GCC_ARC_H */
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 6239483..b8fa44e 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -597,19 +597,21 @@
>  ;;   is made that makes conditional execution required.
>  
>  (define_attr "tune" "none, arc600, arc700_4_2_std, arc700_4

Re: [PATCH 05/10] [ARC] Add trap instruction.

2017-11-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:54 
+0100]:

> From: Claudiu Zissulescu 
> 
> 2017-11-07  Claudiu Zissulescu  
> 
>   * config/arc/arc.md (trap): New pattern.

Looks good.

Thanks,
Andrew

> ---
>  gcc/config/arc/arc.md | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index b8fa44e..42c6a23 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -4321,6 +4321,13 @@ archs4xd, archs4xd_slow, core_3"
>  ; use it for lack of inter-procedural branch shortening.
>  ; Link-time relaxation would help...
>  
> +(define_insn "trap"
> +  [(trap_if (const_int 1) (const_int 0))]
> +  "!TARGET_ARC600_FAMILY"
> +  "trap_s\\t5"
> +  [(set_attr "type" "misc")
> +   (set_attr "length" "2")])
> +
>  (define_insn "nop"
>[(const_int 0)]
>""
> -- 
> 1.9.1
> 


Re: [PATCH 06/10] [ARC] Update legitimate constant hook.

2017-12-07 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:55 
+0100]:

> From: Claudiu Zissulescu 
> 
> Make sure we check the constants in all cases.
> 
> gcc/
> 2017-10-14  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_legitimate_constant_p): Always check all
>   constants.
> 
> testsuite/
> 2017-10-14  Claudiu Zissulescu  
> 
>   * gcc.target/arc/tls-1.c: New test.

Looks good.

Thanks,
Andrew


> ---
>  gcc/config/arc/arc.c |  6 --
>  gcc/testsuite/gcc.target/arc/tls-1.c | 26 ++
>  2 files changed, 26 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/tls-1.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 4d7a282..42ea921 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -6185,12 +6185,6 @@ arc_return_addr_rtx (int count, ATTRIBUTE_UNUSED rtx 
> frame)
>  bool
>  arc_legitimate_constant_p (machine_mode mode, rtx x)
>  {
> -  if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x))
> -return false;
> -
> -  if (!flag_pic && mode != Pmode)
> -return true;
> -
>switch (GET_CODE (x))
>  {
>  case CONST:
> diff --git a/gcc/testsuite/gcc.target/arc/tls-1.c 
> b/gcc/testsuite/gcc.target/arc/tls-1.c
> new file mode 100644
> index 000..3f7a6d4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/tls-1.c
> @@ -0,0 +1,26 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target tls } */
> +/* { dg-options "-O3 -std=gnu99" } */
> +
> +/* Check if addressing the `pos` member of struct is done via tls
> +   mechanism.  */
> +
> +struct callchain_cursor {
> +  int last;
> +  long long pos;
> +} __thread a;
> +void fn1(struct callchain_cursor *p1)
> +{
> +  p1->pos++;
> +}
> +
> +extern void fn3 (void);
> +
> +void fn2(void) {
> +  struct callchain_cursor *b = &a;
> +  while (1) {
> +fn3();
> +fn1(b);
> +  }
> +}
> +/* { dg-final { scan-assembler "r25,@a@tpoff" } } */
> -- 
> 1.9.1
> 


Re: [PATCH 07/10] [ARC][FIX] Consider command line ffixed- option.

2017-12-07 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:56 
+0100]:

> From: claziss 
> 
> Track which regs are set fixed/call saved/call used from commnad line.
> Do not try to override their properties if user says otherwise.
> 
> gcc/
> 2017-06-08  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (overrideregs): New variable.
>   (arc_override_options): Track fixed/call saved/call options.
>   (arc_conditional_register_usage): Check against overrideregs
>   variable whenever we change register properties.

Looks good.

Thanks,
Andrew


> ---
>  gcc/config/arc/arc.c | 60 
> +---
>  1 file changed, 48 insertions(+), 12 deletions(-)
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 42ea921..0eeeb42 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -79,6 +79,9 @@ typedef struct GTY (()) _arc_jli_section
>  
>  static arc_jli_section *arc_jli_sections = NULL;
>  
> +/* Track which regs are set fixed/call saved/call used from commnad line.  */
> +HARD_REG_SET overrideregs;
> +
>  /* Maximum size of a loop.  */
>  #define ARC_MAX_LOOP_LENGTH 4095
>  
> @@ -1144,6 +1147,30 @@ arc_override_options (void)
> }
>}
>  
> +  CLEAR_HARD_REG_SET (overrideregs);
> +  if (common_deferred_options)
> +{
> +  vec v =
> + *((vec *) common_deferred_options);
> +  int reg, nregs, j;
> +
> +  FOR_EACH_VEC_ELT (v, i, opt)
> + {
> +   switch (opt->opt_index)
> + {
> + case OPT_ffixed_:
> + case OPT_fcall_used_:
> + case OPT_fcall_saved_:
> +   if ((reg = decode_reg_name_and_count (opt->arg, &nregs)) >= 0)
> + for (j = reg;  j < reg + nregs; j++)
> +   SET_HARD_REG_BIT (overrideregs, j);
> +   break;
> + default:
> +   break;
> + }
> + }
> +}
> +
>/* Set cpu flags accordingly to architecture/selected cpu.  The cpu
>   specific flags are set in arc-common.c.  The architecture forces
>   the default hardware configurations in, regardless what command
> @@ -1673,14 +1700,20 @@ arc_conditional_register_usage (void)
>/* For ARCv2 the core register set is changed.  */
>strcpy (rname29, "ilink");
>strcpy (rname30, "r30");
> -  call_used_regs[30] = 1;
> -  fixed_regs[30] = 0;
> -
> -  arc_regno_reg_class[30] = WRITABLE_CORE_REGS;
> -  SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], 30);
> -  SET_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], 30);
> -  SET_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], 30);
> -  SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], 30);
> +
> +  if (!TEST_HARD_REG_BIT (overrideregs, 30))
> + {
> +   /* No user interference.  Set the r30 to be used by the
> +  compiler.  */
> +   call_used_regs[30] = 1;
> +   fixed_regs[30] = 0;
> +
> +   arc_regno_reg_class[30] = WRITABLE_CORE_REGS;
> +   SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], 30);
> +   SET_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], 30);
> +   SET_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], 30);
> +   SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], 30);
> + }
> }
>  
>if (TARGET_MUL64_SET)
> @@ -1935,11 +1968,14 @@ arc_conditional_register_usage (void)
>  SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], 
> ACCL_REGNO);
>  SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], 
> ACCH_REGNO);
>  
> - /* Allow the compiler to freely use them.  */
> -fixed_regs[ACCL_REGNO] = 0;
> -fixed_regs[ACCH_REGNO] = 0;
> +/* Allow the compiler to freely use them.  */
> +if (!TEST_HARD_REG_BIT (overrideregs, ACCL_REGNO))
> +  fixed_regs[ACCL_REGNO] = 0;
> +if (!TEST_HARD_REG_BIT (overrideregs, ACCH_REGNO))
> +  fixed_regs[ACCH_REGNO] = 0;
>  
> -arc_hard_regno_modes[ACC_REG_FIRST] = D_MODES;
> +if (!fixed_regs[ACCH_REGNO] && !fixed_regs[ACCL_REGNO])
> +  arc_hard_regno_modes[ACC_REG_FIRST] = D_MODES;
>}
>  }
>  
> -- 
> 1.9.1
> 


Re: [PATCH 09/10] [ARC] Update (u)maddsidi patterns.

2017-12-07 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:58 
+0100]:

> From: claziss 
> 
> The accumulator registers are freely used by the compiler. However,
> there are a number of instructions which are having an intrinsic use
> of these registers. Update patterns to inform the compiler which ones.
> 
> gcc/
> 2017-09-19  Claudiu Zissulescu  
> 
>   * config/arc/arc.md (maddsidi4, maddsidi4_split): Update pattern.
>   (umaddsidi4,umaddsidi4): Likewise.
> 
> gcc/testsuite
> 2017-09-19  Claudiu Zissulescu  
> 
>   * gcc.target/arc/tumaddsidi4.c: New test.

Looks good.

Thanks,
Andrew


> ---
>  gcc/config/arc/arc.md  | 32 
> ++
>  gcc/testsuite/gcc.target/arc/tumaddsidi4.c | 14 +
>  2 files changed, 42 insertions(+), 4 deletions(-)
>  create mode 100755 gcc/testsuite/gcc.target/arc/tumaddsidi4.c
> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 42c6a23..155ee6c 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -6175,13 +6175,25 @@ archs4xd, archs4xd_slow, core_3"
>[(set_attr "length" "0")])
>  
>  ;; MAC and DMPY instructions
> -(define_insn_and_split "maddsidi4"
> +(define_expand "maddsidi4"
> +  [(match_operand:DI 0 "register_operand" "")
> +   (match_operand:SI 1 "register_operand" "")
> +   (match_operand:SI 2 "extend_operand"   "")
> +   (match_operand:DI 3 "register_operand" "")]
> +  "TARGET_PLUS_DMPY"
> +  "{
> +   emit_insn (gen_maddsidi4_split (operands[0], operands[1], operands[2], 
> operands[3]));
> +   DONE;
> +  }")
> +
> +(define_insn_and_split "maddsidi4_split"
>[(set (match_operand:DI 0 "register_operand" "=r")
>   (plus:DI
>(mult:DI
> (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
> (sign_extend:DI (match_operand:SI 2 "extend_operand" "ri")))
> -  (match_operand:DI 3 "register_operand" "r")))]
> +  (match_operand:DI 3 "register_operand" "r")))
> +   (clobber (reg:DI ARCV2_ACC))]
>"TARGET_PLUS_DMPY"
>"#"
>"TARGET_PLUS_DMPY && reload_completed"
> @@ -6263,13 +6275,25 @@ archs4xd, archs4xd_slow, core_3"
> (set_attr "predicable" "no")
> (set_attr "cond" "nocond")])
>  
> -(define_insn_and_split "umaddsidi4"
> +(define_expand "umaddsidi4"
> +  [(match_operand:DI 0 "register_operand" "")
> +   (match_operand:SI 1 "register_operand" "")
> +   (match_operand:SI 2 "extend_operand"   "")
> +   (match_operand:DI 3 "register_operand" "")]
> +  "TARGET_PLUS_DMPY"
> +  "{
> +   emit_insn (gen_umaddsidi4_split (operands[0], operands[1], operands[2], 
> operands[3]));
> +   DONE;
> +  }")
> +
> +(define_insn_and_split "umaddsidi4_split"
>[(set (match_operand:DI 0 "register_operand" "=r")
>   (plus:DI
>(mult:DI
> (zero_extend:DI (match_operand:SI 1 "register_operand" "%r"))
> (zero_extend:DI (match_operand:SI 2 "extend_operand" "ri")))
> -  (match_operand:DI 3 "register_operand" "r")))]
> +  (match_operand:DI 3 "register_operand" "r")))
> +   (clobber (reg:DI ARCV2_ACC))]
>"TARGET_PLUS_DMPY"
>"#"
>"TARGET_PLUS_DMPY && reload_completed"
> diff --git a/gcc/testsuite/gcc.target/arc/tumaddsidi4.c 
> b/gcc/testsuite/gcc.target/arc/tumaddsidi4.c
> new file mode 100755
> index 000..40d2b33
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/tumaddsidi4.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-mcpu=archs -O1 -mmpy-option=plus_dmpy" } */
> +
> +/* Check how we generate umaddsidi4 patterns.  */
> +long a;
> +long long b;
> +unsigned c, d;
> +
> +void fn1(void)
> +{
> +  b = d * (long long)c + a;
> +}
> +
> +/* { dg-final { scan-assembler "macu 0,r" } } */
> -- 
> 1.9.1
> 


Re: [PATCH 08/10] [ARC] Enable unaligned access.

2018-01-02 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:57 
+0100]:

> From: Claudiu Zissulescu 
> 
> Use munaligned-access to control if we can have unaligned accesses.  For ARC
> HS family unaligned access is always on.
> 
> 2017-10-19  Claudiu Zissulescu  
> 
>   * config/arc/arc-c.def (__ARC_UNALIGNED__): New define.
>   * config/arc/arc.h (STRICT_ALIGNMENT): Control this macro using
>   munaligned-access.

This looks fine,

Thanks,
Andrew


> ---
>  gcc/config/arc/arc-c.def | 1 +
>  gcc/config/arc/arc.h | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/config/arc/arc-c.def b/gcc/config/arc/arc-c.def
> index c9443c9..86eab4e 100644
> --- a/gcc/config/arc/arc-c.def
> +++ b/gcc/config/arc/arc-c.def
> @@ -29,6 +29,7 @@ ARC_C_DEF ("__ARC_MUL64__", TARGET_MUL64_SET)
>  ARC_C_DEF ("__ARC_MUL32BY16__", TARGET_MULMAC_32BY16_SET)
>  ARC_C_DEF ("__ARC_SIMD__",   TARGET_SIMD_SET)
>  ARC_C_DEF ("__ARC_RF16__",   TARGET_RF16)
> +ARC_C_DEF ("__ARC_UNALIGNED__",  !STRICT_ALIGNMENT)
>  
>  ARC_C_DEF ("__ARC_BARREL_SHIFTER__", TARGET_BARREL_SHIFTER)
>  
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index 8d90975..8c31fb2 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -288,7 +288,7 @@ if (GET_MODE_CLASS (MODE) == MODE_INT \
>  /* On the ARC the lower address bits are masked to 0 as necessary.  The chip
> won't croak when given an unaligned address, but the insn will still fail
> to produce the correct result.  */
> -#define STRICT_ALIGNMENT 1
> +#define STRICT_ALIGNMENT (!unaligned_access && !TARGET_HS)
>  
>  /* Layout of source language data types.  */
>  
> -- 
> 1.9.1
> 


Re: [PATCH 10/10] [ARC] Revamp trampoline implementation.

2018-01-02 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-27 12:09:59 
+0100]:

> From: Claudiu Zissulescu 
> 
> The new implementation attempts to clean up the existing trampoline
> implementation for ARC making it to work for linux type of systems.
> 
> gcc/
> 2017-11-10  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (TARGET_TRAMPOLINE_ADJUST_ADDRESS): Delete.
>   (emit_store_direct): Likewise.
>   (arc_trampoline_adjust_address): Likewise.
>   (arc_asm_trampoline_template): New function.
>   (arc_initialize_trampoline): Use asm_trampoline_template.
>   (TARGET_ASM_TRAMPOLINE_TEMPLATE): Define.
>   * config/arc/arc.h (TRAMPOLINE_SIZE): Adjust to 16.
>   *config/arc/arc.md (flush_icache): Delete pattern.

 ^-- Missing space here.

Otherwise, looks fine.

Thanks,
Andrew



> ---
>  gcc/config/arc/arc.c  | 89 
> +--
>  gcc/config/arc/arc.h  |  2 +-
>  gcc/config/arc/arc.md |  9 --
>  3 files changed, 44 insertions(+), 56 deletions(-)
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 0eeeb42..053f3c2 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -588,8 +588,6 @@ static void arc_finalize_pic (void);
>  
>  #define TARGET_TRAMPOLINE_INIT arc_initialize_trampoline
>  
> -#define TARGET_TRAMPOLINE_ADJUST_ADDRESS arc_trampoline_adjust_address
> -
>  #define TARGET_CAN_ELIMINATE arc_can_eliminate
>  
>  #define TARGET_FRAME_POINTER_REQUIRED arc_frame_pointer_required
> @@ -3727,69 +3725,65 @@ output_shift (rtx *operands)
>  
>  /* Nested function support.  */
>  
> -/* Directly store VALUE into memory object BLOCK at OFFSET.  */
> -
> -static void
> -emit_store_direct (rtx block, int offset, int value)
> -{
> -  emit_insn (gen_store_direct (adjust_address (block, SImode, offset),
> -force_reg (SImode,
> -   gen_int_mode (value, SImode;
> -}
> +/* Output assembler code for a block containing the constant parts of
> +   a trampoline, leaving space for variable parts.
>  
> -/* Emit RTL insns to initialize the variable parts of a trampoline.
> -   FNADDR is an RTX for the address of the function's pure code.
> -   CXT is an RTX for the static chain value for the function.  */
> -/* With potentially multiple shared objects loaded, and multiple stacks
> -   present for multiple thereds where trampolines might reside, a simple
> -   range check will likely not suffice for the profiler to tell if a callee
> -   is a trampoline.  We a speedier check by making the trampoline start at
> -   an address that is not 4-byte aligned.
> A trampoline looks like this:
>  
> -   nop_s  0x78e0
> -entry:
> ld_s r12,[pcl,12] 0xd403
> ld   r11,[pcl,12] 0x170c 700b
> j_s [r12] 0x7c00
> -   nop_s  0x78e0
> +   .word function's address
> +   .word static chain value
> +
> +*/
> +
> +static void
> +arc_asm_trampoline_template (FILE *f)
> +{
> +  asm_fprintf (f, "\tld_s\t%s,[pcl,8]\n", ARC_TEMP_SCRATCH_REG);
> +  asm_fprintf (f, "\tld\t%s,[pcl,12]\n", reg_names[STATIC_CHAIN_REGNUM]);
> +  asm_fprintf (f, "\tj_s\t[%s]\n", ARC_TEMP_SCRATCH_REG);
> +  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
> +  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
> +}
> +
> +/* Emit RTL insns to initialize the variable parts of a trampoline.
> +   FNADDR is an RTX for the address of the function's pure code.  CXT
> +   is an RTX for the static chain value for the function.
>  
> The fastest trampoline to execute for trampolines within +-8KB of CTX
> would be:
> +
> add2 r11,pcl,s12
> j [limm]   0x20200f80 limm
> -   and that would also be faster to write to the stack by computing the 
> offset
> -   from CTX to TRAMP at compile time.  However, it would really be better to
> -   get rid of the high cost of cache invalidation when generating 
> trampolines,
> -   which requires that the code part of trampolines stays constant, and
> -   additionally either
> -   - making sure that no executable code but trampolines is on the stack,
> - no icache entries linger for the area of the stack from when before the
> - stack was allocated, and allocating trampolines in trampoline-only
> - cache lines
> -  or
> -   - allocate trampolines fram a special pool of pre-allocated trampolines.  
> */
> +
> +   and that would also be faster to write to the stack by computing
> +   the offset from CTX to TRAMP at compile time.  However, it would
> +   really be better to get rid of the high cost of cache invalidation
> +   when generating trampolines, which requires that the code part of
> +   trampolines stays constant, and additionally either making sure
> +   that no executable code but trampolines is on the stack, no icache
> +   entries linger for the area of the stack from when before the stack
> +   was allocated, and allocating trampolines in trampoline-only cache
> +   lines or allocate trampolines fram a

Re: [PATCH 1/2] [ARC][QuarkSE] Update

2018-06-04 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:20:28 +0300]:

> From: claziss 
> 
> QuarkSE has lp_count width set to 16 bits. Update the compiler to
> consider it.
> 
> Ok to apply?
> Claudiu
> 
> gcc/
> 2017-07-11  Claudiu Zissulescu  
> 
>   * config/arc/arc-arch.h (arc_extras): New enum.
>   (arc_cpu_t): Add field extra.
>   (arc_cpu_types): Consider the extras.
>   * config/arc/arc-cpus.def: Add extras info.
>   * config/arc/arc-opts.h (processor_type): Consider extra field.
>   * config/arc/arc.c (arc_override_options): Handle extra field.

The field name 'extra' seems a little vague.  Can this field ever be
used for more than just lp_count size?  Would a name related more to
lp_count be better?  Or if the intention is that other flags might get
added, maybe there's a name that could suggest that usage?

As a minimum maybe the comment on the new field could describe what
the field is for?

Thanks,
Andrew


> ---
>  gcc/config/arc/arc-arch.h   | 19 ---
>  gcc/config/arc/arc-cpus.def | 59 
> -
>  gcc/config/arc/arc-opts.h   |  2 +-
>  gcc/config/arc/arc.c| 10 
>  4 files changed, 57 insertions(+), 33 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-arch.h b/gcc/config/arc/arc-arch.h
> index 01f95946623..f90be66e200 100644
> --- a/gcc/config/arc/arc-arch.h
> +++ b/gcc/config/arc/arc-arch.h
> @@ -79,6 +79,14 @@ enum arc_tune_attr
>  ARC_TUNE_ARCHS4XD_SLOW
>};
>  
> +/* Extra options for a processor.  */
> +
> +enum arc_extras
> +{
> +  HAS_NONE,
> +  HAS_LPCOUNT_16
> +};
> +
>  /* CPU specific properties.  */
>  
>  typedef struct
> @@ -95,6 +103,9 @@ typedef struct
>/* Specific flags.  */
>const unsigned long long flags;
>  
> +  /* Extra value.  */
> +  enum arc_extras extra;
> +
>/* Tune value.  */
>enum arc_tune_attr tune;
>  
> @@ -112,12 +123,12 @@ const arc_arch_t arc_arch_types[] =
>  
>  const arc_cpu_t arc_cpu_types[] =
>{
> -{"none", NULL, PROCESSOR_NONE, 0, ARC_TUNE_NONE},
> -#define ARC_CPU(NAME, ARCH, FLAGS, TUNE) \
> -{#NAME, &arc_arch_types [BASE_ARCH_##ARCH], PROCESSOR_##NAME, FLAGS, 
> ARC_TUNE_##TUNE },
> +{"none", NULL, PROCESSOR_NONE, 0, HAS_NONE, ARC_TUNE_NONE},
> +#define ARC_CPU(NAME, ARCH, FLAGS, EXTRA, TUNE)  
> \
> +{#NAME, &arc_arch_types [BASE_ARCH_##ARCH], PROCESSOR_##NAME, FLAGS, 
> HAS_##EXTRA, ARC_TUNE_##TUNE },
>  #include "arc-cpus.def"
>  #undef ARC_CPU
> -{NULL, NULL, PROCESSOR_NONE, 0, ARC_TUNE_NONE}
> +{NULL, NULL, PROCESSOR_NONE, 0, HAS_NONE, ARC_TUNE_NONE}
>};
>  
>  /* Currently selected cpu type.  */
> diff --git a/gcc/config/arc/arc-cpus.def b/gcc/config/arc/arc-cpus.def
> index 4aa422f1a39..eea83917b42 100644
> --- a/gcc/config/arc/arc-cpus.def
> +++ b/gcc/config/arc/arc-cpus.def
> @@ -43,36 +43,39 @@
> as defined in arc-options.def file, and allowed by arc-arches.def
> file.  The specific hardware flags are enumerated without using
> spaces between the '|' character and consequtive flags.
> +   EXTRA  Extra hardware flags, different than the ones in
> +   arc-arches.def.  Here we can specify the width of lp_count,
> +   for example.
> TUNETune value for the given configuration, otherwise NONE.  */
>  
> -ARC_CPU (em, em, 0, NONE)
> -ARC_CPU (em_mini,   em, FL_RF16, NONE)
> -ARC_CPU (arcem,  em, FL_MPYOPT_2|FL_CD|FL_BS, NONE)
> -ARC_CPU (em4,em, FL_CD, NONE)
> -ARC_CPU (em4_dmips, em, FL_MPYOPT_2|FL_CD|FL_DIVREM|FL_NORM|FL_SWAP|FL_BS, 
> NONE)
> -ARC_CPU (em4_fpus,  em, 
> FL_MPYOPT_2|FL_CD|FL_DIVREM|FL_NORM|FL_SWAP|FL_BS|FL_FPU_FPUS, NONE)
> -ARC_CPU (em4_fpuda, em, 
> FL_MPYOPT_2|FL_CD|FL_DIVREM|FL_NORM|FL_SWAP|FL_BS|FL_FPU_FPUDA, NONE)
> -ARC_CPU (quarkse_em, em, 
> FL_MPYOPT_3|FL_CD|FL_DIVREM|FL_NORM|FL_SWAP|FL_BS|FL_FPX_QUARK|FL_SPFP|FL_DPFP,
>  NONE)
> -
> -ARC_CPU (hs,  hs, 0, NONE)
> -ARC_CPU (archs,   hs, FL_MPYOPT_2|FL_DIVREM|FL_LL64, NONE)
> -ARC_CPU (hs34,hs, FL_MPYOPT_2, NONE)
> -ARC_CPU (hs38,hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64, NONE)
> -ARC_CPU (hs38_linux, hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64|FL_FPU_FPUD_ALL, NONE)
> -ARC_CPU (hs4x,  hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64, ARCHS4X)
> -ARC_CPU (hs4xd, hs, FL_MPYOPT_9|FL_DIVREM|FL_LL64, ARCHS4XD)
> -
> -ARC_CPU (arc600,  6xx, FL_BS, ARC600)
> -ARC_CPU (arc600_norm, 6xx, FL_BS|FL_NORM, ARC600)
> -ARC_CPU (arc600_mul64,6xx, FL_BS|FL_NORM|FL_MUL64, ARC600)
> -ARC_CPU (arc600_mul32x16, 6xx, FL_BS|FL_NORM|FL_MUL32x16, ARC600)
> -ARC_CPU (arc601,   6xx, 0, ARC600)
> -ARC_CPU (arc601_norm,  6xx, FL_NORM, ARC600)
> -ARC_CPU (arc601_mul64, 6xx, FL_NORM|FL_MUL64, ARC600)
> -ARC_CPU (arc601_mul32x16, 6xx, FL_NORM|FL_MUL32x16, ARC600)
> -
> -ARC_CPU (arc700, 700, 0, ARC700_4_2_STD)
> -ARC_CPU (nps400, 700, 0, ARC700_4_2_STD)
> +ARC_CPU (em, em, 0, NONE, NONE)
> +ARC_CPU (em_mini,   em, FL_RF16, NONE, NONE

Re: [PATCH 2/2] [ARC] Update warning messges.

2018-06-04 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:20:29 +0300]:

> From: claziss 
> 
> When we pass an mcpu to the compiler we have two types of (hardware
> configuration) flags that are set:
> 
> 1. Architecture specific, for example code-density is always enabled
> for ARCHS architectures. These options are overwriting whatever the
> corresponding user options with the preset ones.
> 
> 2. CPU specific, for example archs is using LL64 option by
> default. These options can be freely enabled or disabled.
> 
> Because of the above complexity, we need to throw some errors for the
> user to know when he/she does something which goes against the above
> rules. Thus, I came up with the following set of rules:
> 
> 1. Overwriting default architecture specific hardware option: it is
> ignored, a warning is thrown;
> 
> 2. Overwriting default CPU specific hardware option: it is taken into
> account, a warning is thrown.
> 
> Ok to apply?
> Claudiu

This seems fine.

Thanks,
Andrew

> 
> gcc/
> 2017-09-26  Claudiu Zissulescu  
> 
>   * config/arc/arc-arch.h: Update ARC_OPTX macro.
>   * config/arc/arc-options.def (ARC_OPTX): Introduce a new doc
>   field.
>   * config/arc/arc.c (arc_init): Update pic warning.
>   (irq_range): Update irq range parsing warnings.
>   (arc_override_options): Update various warning messages.
>   (arc_handle_aux_attribute): Likewise.
> 
> gcc/testsuite
> 2017-09-26  Claudiu Zissulescu  
> 
>   * gcc.target/arc/builtin_simdarc.c: Update test.
>   * gcc.target/arc/mulsi3_highpart-2.c: Likewise.
>   * gcc.target/arc/tumaddsidi4.c: Likewise.
> ---
>  gcc/config/arc/arc-arch.h|  2 +-
>  gcc/config/arc/arc-options.def   | 44 ++--
>  gcc/config/arc/arc.c | 90 
> ++--
>  gcc/testsuite/gcc.target/arc/builtin_simdarc.c   |  2 +-
>  gcc/testsuite/gcc.target/arc/mulsi3_highpart-2.c |  2 +-
>  gcc/testsuite/gcc.target/arc/tumaddsidi4.c   |  2 +-
>  6 files changed, 80 insertions(+), 62 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-arch.h b/gcc/config/arc/arc-arch.h
> index f90be66e200..a3b7dc87be4 100644
> --- a/gcc/config/arc/arc-arch.h
> +++ b/gcc/config/arc/arc-arch.h
> @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3.  If not see
>  enum cpu_flags
>{
>  #define ARC_OPT(NAME, CODE, MASK, DOC)   NAME = CODE,
> -#define ARC_OPTX(NAME, CODE, VAR, VAL, DOC) NAME = CODE,
> +#define ARC_OPTX(NAME, CODE, VAR, VAL, DOC0, DOC1) NAME = CODE,
>  #include "arc-options.def"
>  #undef ARC_OPT
>  #undef ARC_OPTX
> diff --git a/gcc/config/arc/arc-options.def b/gcc/config/arc/arc-options.def
> index 61ecd1de150..fefb3081c81 100644
> --- a/gcc/config/arc/arc-options.def
> +++ b/gcc/config/arc/arc-options.def
> @@ -74,32 +74,32 @@ ARC_OPT (FL_DPFP, (1ULL << 13), 
> MASK_DPFP_COMPACT_SET, "double precission FP
>  ARC_OPT (FL_ARGONAUT, (1ULL << 14), MASK_ARGONAUT_SET,  "argonaut")
>  ARC_OPT (FL_SIMD, (1ULL << 15), MASK_SIMD_SET,  "simd")
>  
> -ARC_OPTX (FL_MPYOPT_1, (1ULL << 17), arc_mpy_option, 1, "mpy option w")
> -ARC_OPTX (FL_MPYOPT_2, (1ULL << 18), arc_mpy_option, 2, "mpy option wlh1")
> -ARC_OPTX (FL_MPYOPT_3, (1ULL << 19), arc_mpy_option, 3, "mpy option wlh2")
> -ARC_OPTX (FL_MPYOPT_4, (1ULL << 20), arc_mpy_option, 4, "mpy option wlh3")
> -ARC_OPTX (FL_MPYOPT_5, (1ULL << 21), arc_mpy_option, 5, "mpy option wlh4")
> -ARC_OPTX (FL_MPYOPT_6, (1ULL << 22), arc_mpy_option, 6, "mpy option wlh5")
> -ARC_OPTX (FL_MPYOPT_7, (1ULL << 23), arc_mpy_option, 7, "mpy option 
> plus_dmpy")
> -ARC_OPTX (FL_MPYOPT_8, (1ULL << 24), arc_mpy_option, 8, "mpy option 
> plus_macd")
> -ARC_OPTX (FL_MPYOPT_9, (1ULL << 25), arc_mpy_option, 9, "mpy option 
> plus_qmacw")
> +ARC_OPTX (FL_MPYOPT_1, (1ULL << 17), arc_mpy_option, 1, "mpy-option", "w")
> +ARC_OPTX (FL_MPYOPT_2, (1ULL << 18), arc_mpy_option, 2, "mpy-option", "wlh1")
> +ARC_OPTX (FL_MPYOPT_3, (1ULL << 19), arc_mpy_option, 3, "mpy-option", "wlh2")
> +ARC_OPTX (FL_MPYOPT_4, (1ULL << 20), arc_mpy_option, 4, "mpy-option", "wlh3")
> +ARC_OPTX (FL_MPYOPT_5, (1ULL << 21), arc_mpy_option, 5, "mpy-option", "wlh4")
> +ARC_OPTX (FL_MPYOPT_6, (1ULL << 22), arc_mpy_option, 6, "mpy-option", "wlh5")
> +ARC_OPTX (FL_MPYOPT_7, (1ULL << 23), arc_mpy_option, 7, "mpy-option", 
> "plus_dmpy")
> +ARC_OPTX (FL_MPYOPT_8, (1ULL << 24), arc_mpy_option, 8, "mpy-option", 
> "plus_macd")
> +ARC_OPTX (FL_MPYOPT_9, (1ULL << 25), arc_mpy_option, 9, "mpy-option", 
> "plus_qmacw")
>  
>  ARC_OPT (FL_MPYOPT_7_9, (0x01c2ULL << 17), 0, "mpy option")
>  ARC_OPT (FL_MPYOPT_1_6, (0x003fULL << 17), 0, "mpy option")
>  
> -ARC_OPTX (FL_FPU_FPUS,   (1ULL << 26), arc_fpu_build, FPU_FPUS,  
> "mfpu=fpus")
> -ARC_OPTX (FL_FPU_FPUS_DIV,  (1ULL << 27), arc_fpu_build, FPU_FPUS_DIV,   
> "mfpu=fpus_div")
> -ARC_OPTX (FL_FPU_FPUS_FMA,  (1ULL << 28), arc_fpu_build, FPU_FPUS_FMA,   
> "mfpu=fpus_fma")
> -ARC_OPTX (FL_FPU_FPUS_ALL,  (1ULL << 

Re: [PATCH 4/6] [ARC] Define LINK_GCC_C_SEQUENCE_SPEC.

2018-06-12 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:18:37 +0300]:

> From: claziss 
> 
> If no specs file is provided, default to nosys library.
> 
> Ok to apply?

Looks good.

Thanks,
Andrew


> Claudiu
> 
> gcc/
> 2017-05-03  Claudiu Zissulescu  
> 
>   * config/arc/elf.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
> ---
>  gcc/config/arc/elf.h | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/gcc/config/arc/elf.h b/gcc/config/arc/elf.h
> index 43ced3b720f..66ee5b698ea 100644
> --- a/gcc/config/arc/elf.h
> +++ b/gcc/config/arc/elf.h
> @@ -73,3 +73,8 @@ along with GCC; see the file COPYING3.  If not see
>  
>  #undef TARGET_ASM_FILE_END
>  #define TARGET_ASM_FILE_END arc_file_end
> +
> +/* If no specs file is enforced, default to nosys libarary.  */
> +#undef LINK_GCC_C_SEQUENCE_SPEC
> +#define LINK_GCC_C_SEQUENCE_SPEC \
> +  "--start-group %G %{!specs=*:-lc -lnosys} --end-group"
> -- 
> 2.14.3
> 


Re: [PATCH 3/6] [ARC] SYNC instruction is valid on all ARC cores.

2018-06-12 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:18:36 +0300]:

> From: claziss 
> 
> The sync instruction is part of all ARC architectures. Fix this in the 
> compiler.
> 
> Ok to apply?

Looks good.

Thanks,
Andrew


> Claudiu
> 
> gcc/
> 2017-05-03  Claudiu Zissulescu  
> 
>   * config/arc/builtins.def (SYNC): SYNC instruction is valid on all
>   ARC cores.
> ---
>  gcc/config/arc/builtins.def | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/config/arc/builtins.def b/gcc/config/arc/builtins.def
> index 349f39fab23..5171ab40842 100644
> --- a/gcc/config/arc/builtins.def
> +++ b/gcc/config/arc/builtins.def
> @@ -34,7 +34,7 @@
>  /* Special builtins.  */
>  DEF_BUILTIN (NOP,0, void_ftype_void,nothing, 1)
>  DEF_BUILTIN (RTIE,   0, void_ftype_void,rtie,1)
> -DEF_BUILTIN (SYNC,   0, void_ftype_void,sync,
> TARGET_ARC700)
> +DEF_BUILTIN (SYNC,   0, void_ftype_void,sync,1)
>  DEF_BUILTIN (BRK,0, void_ftype_void,brk, 1)
>  DEF_BUILTIN (SWI,0, void_ftype_void,swi, 1)
>  DEF_BUILTIN (UNIMP_S,0, void_ftype_void,unimp_s, 
> !TARGET_ARC600_FAMILY)
> -- 
> 2.14.3
> 


Re: [PATCH 1/6] [ARC] Add modes scheduler HS

2018-06-12 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:18:34 +0300]:

> From: Claudiu Zissulescu 
> 
> An update on how the instructions are scheduled for HS processor.
> 
> Ok to apply?

Looks good.

Thanks,
Andrew


> Claudiu
> 
> ---
>  gcc/config/arc/arcHS.md | 21 +++--
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/gcc/config/arc/arcHS.md b/gcc/config/arc/arcHS.md
> index d49b90c4970..5c1ab5413ab 100644
> --- a/gcc/config/arc/arcHS.md
> +++ b/gcc/config/arc/arcHS.md
> @@ -35,12 +35,14 @@
> (eq_attr "type" "store"))
>"hs_issue+hs_ld_st")
>  
> -(define_insn_reservation "hs_alu0" 2
> +;; Advanced ALU
> +(define_insn_reservation "hs_alu0" 4
>(and (match_test "TARGET_HS")
> (eq_attr "tune" "none")
> (eq_attr "type" "cc_arith, two_cycle_core, shift, lr, sr"))
> -  "hs_issue+x1,x2")
> +  "hs_issue+x1,x2, nothing*2")
>  
> +;; Basic ALU
>  (define_insn_reservation "hs_alu1" 4
>(and (match_test "TARGET_HS")
> (eq_attr "tune" "none")
> @@ -54,19 +56,26 @@
> (eq_attr "type" "div_rem"))
>"hs_issue+divrem_hs, (divrem_hs)*12")
>  
> -(define_insn_reservation "hs_mul" 3
> +(define_insn_reservation "hs_mul" 4
>(and (match_test "TARGET_HS")
> (eq_attr "tune" "none")
> (eq_attr "type" "mul16_em, multi, umulti"))
>"hs_issue+mul_hs, nothing*3")
>  
> -;; BYPASS EALU ->
> +;; BYPASS Advanced ALU ->
>  (define_bypass 1 "hs_alu0" "hs_divrem")
>  (define_bypass 1 "hs_alu0" "hs_mul")
> +(define_bypass 2 "hs_alu0" "hs_alu0")
> +(define_bypass 1 "hs_alu0" "hs_alu1")
> +(define_bypass 1 "hs_alu0" "hs_data_load")
> +(define_bypass 1 "hs_alu0" "hs_data_store" "store_data_bypass_p")
> +(define_bypass 2 "hs_alu0" "hs_data_store")
>  
> -;; BYPASS BALU ->
> +;; BYPASS Basic ALU ->
>  (define_bypass 1 "hs_alu1" "hs_alu1")
>  (define_bypass 1 "hs_alu1" "hs_data_store" "store_data_bypass_p")
> +(define_bypass 3 "hs_alu1" "hs_mul")
> +(define_bypass 3 "hs_alu1" "hs_divrem")
>  
>  ;; BYPASS LD ->
>  (define_bypass 1 "hs_data_load" "hs_alu1")
> @@ -76,7 +85,7 @@
>  (define_bypass 1 "hs_data_load" "hs_data_store" "store_data_bypass_p")
>  
>  ;; BYPASS MPY ->
> -;;(define_bypass 3 "hs_mul" "hs_mul")
> +(define_bypass 3 "hs_mul" "hs_mul")
>  (define_bypass 1 "hs_mul" "hs_alu1")
>  (define_bypass 3 "hs_mul" "hs_divrem")
>  (define_bypass 1 "hs_mul" "hs_data_store" "store_data_bypass_p")
> -- 
> 2.14.3
> 


Re: [PATCH 2/6] [ARC] Allow EX instruction for ARC700 and ARCv2.

2018-06-12 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:18:35 +0300]:

> From: claziss 
> 
> The EX instruction is base line for both architectures. Reflect this in the 
> compiler.
> 
> OK to apply?

Looks good.

Thanks,
Andrew


> Claudiu
> 
> gcc/
> 2017-05-02  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (atomic_exchangesi): EX instruction is default
>   for ARC700 and ARCv2.
> ---
>  gcc/config/arc/atomic.md | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/config/arc/atomic.md b/gcc/config/arc/atomic.md
> index 13a2e34549c..4a56ca229cc 100644
> --- a/gcc/config/arc/atomic.md
> +++ b/gcc/config/arc/atomic.md
> @@ -120,7 +120,7 @@
> (match_operand:SI 1 "mem_noofs_operand" "")
> (match_operand:SI 2 "register_operand" "")
> (match_operand:SI 3 "const_int_operand" "")]
> -  "TARGET_ATOMIC"
> +  "TARGET_ARC700 || TARGET_V2"
>  {
>enum memmodel model = (enum memmodel) INTVAL (operands[3]);
>  
> -- 
> 2.14.3
> 


Re: [PATCH 5/6] [ARC] Update fma expansions.

2018-06-12 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:18:38 +0300]:

> Make sure only one operand has an immediate.
> 
> OK to apply?

Looks good.

Thanks,
Andrew

> Claudiu
> 
> gcc/
> 2018-03-21  Claudiu Zissulescu  
> 
>   * config/arc/fpu.md (fmasf4): Force operand to register.
>   (fnmasf4): Likewise.
> 
> gcc/testsuite
> 2018-03-21  Claudiu Zissulescu  
> 
>   * gcc.target/arc/fma-1.c: New test.
> ---
>  gcc/config/arc/fpu.md|  6 ++
>  gcc/testsuite/gcc.target/arc/fma-1.c | 13 +
>  2 files changed, 19 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/arc/fma-1.c
> 
> diff --git a/gcc/config/arc/fpu.md b/gcc/config/arc/fpu.md
> index de876cac0c1..9457922667e 100644
> --- a/gcc/config/arc/fpu.md
> +++ b/gcc/config/arc/fpu.md
> @@ -64,6 +64,9 @@
> tmp = gen_rtx_REG (SFmode, ACCL_REGNO);
> emit_move_insn (tmp, operands[3]);
> operands[3] = tmp;
> +   if (!register_operand (operands[1], SFmode)
> +&& !register_operand (operands[2], SFmode))
> + operands[2] = force_reg (SFmode, operands[2]);
> }")
>  
>  (define_expand "fnmasf4"
> @@ -77,6 +80,9 @@
> tmp = gen_rtx_REG (SFmode, ACCL_REGNO);
> emit_move_insn (tmp, operands[3]);
> operands[3] = tmp;
> +   if (!register_operand (operands[1], SFmode)
> +&& !register_operand (operands[2], SFmode))
> + operands[2] = force_reg (SFmode, operands[2]);
>  }")
>  
>  (define_insn "fmasf4_fpu"
> diff --git a/gcc/testsuite/gcc.target/arc/fma-1.c 
> b/gcc/testsuite/gcc.target/arc/fma-1.c
> new file mode 100644
> index 000..c195ad98127
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/fma-1.c
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-skip-if "FPU not available" { arc700 || arc6xx } } */
> +/* { dg-options "-s -std=gnu11  -O2 -frounding-math -mfpu=fpus_all" } */
> +
> +const float a, b = 7.8539818525e01;
> +
> +/* Check if the fma operation is generated correctly.  */
> +
> +int foo (void)
> +{
> +  return (float)3.0 * b + a;
> +}
> +/* { dg-final { scan-assembler "fsmadd" } } */
> -- 
> 2.14.3
> 


Re: [PATCH 6/6] [ARC] Reimplement return padding operation for ARC700.

2018-06-12 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-05-21 13:18:39 +0300]:

> From: Claudiu Zissulescu 
> 
> For ARC700, adding padding if necessary to avoid a mispredict.  A
> return could happen immediately after the function start.  A
> call/return and return/return must be 6 bytes apart to avoid
> mispredict.
> 
> The old implementation was doing this operation very late in the
> compilation process, and the additional nop instructions and/or
> forcing some other instruction to take their long form was not taken
> into account when generating brcc instructions. Thus, wrong code could
> be generated.
> 
> Ok to apply?

This looks fine with a couple of small adjustments, inline below...

> Claudiu
> 
> gcc/
> 2017-03-24  Claudiu Zissulescu  
> 
>   * config/arc/arc-protos.h (arc_pad_return): Remove.
>   * config/arc/arc.c (machine_function): Remove force_short_suffix
>   and size_reason.
>   (arc_print_operand): Adjust printing of '&'.
>   (arc_verify_short): Remove conditional printing of short suffix.
>   (arc_final_prescan_insn): Remove reference to size_reason.
>   (pad_return): New function.
>   (arc_reorg): Call pad_return.
>   (arc_pad_return): Remove.
>   (arc_init_machine_status): Remove reference to force_short_suffix.
>   * config/arc/arc.md (vunspec): Add VUNSPEC_ARC_BLOCKAGE.
>   (attr length): When attribute iscompact is true force to 2
>   regardless; in the case of maybe check if we want to force the
>   instruction to have 4 bytes length.
>   (nopv): Change it to generate 4 byte long nop as well.
>   (blockage): New pattern.
>   (simple_return): Remove call to arc_pad_return.
>   (p_return_i): Likewise.
> 
> gcc/testsuite/
> 2017-03-24  Claudiu Zissulescu  
> 
>   * gcc.target/arc/pr9001107555.c: New file.
> ---
>  gcc/config/arc/arc-protos.h |   1 -
>  gcc/config/arc/arc.c| 156 
> +---
>  gcc/config/arc/arc.md   |  26 +++--
>  gcc/testsuite/gcc.target/arc/pr9001107555.c |  38 +++
>  4 files changed, 128 insertions(+), 93 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/pr9001107555.c
> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index 67f3b4e3226..ce4b6f84749 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -89,7 +89,6 @@ extern void arc_clear_unalign (void);
>  extern void arc_toggle_unalign (void);
>  extern void split_addsi (rtx *);
>  extern void split_subsi (rtx *);
> -extern void arc_pad_return (void);
>  extern void arc_split_move (rtx *);
>  extern const char *arc_short_long (rtx_insn *insn, const char *, const char 
> *);
>  extern rtx arc_regno_use_in (unsigned int, rtx);
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index b1a09d82b72..22f1442a027 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -2648,8 +2648,6 @@ typedef struct GTY (()) machine_function
>struct arc_frame_info frame_info;
>/* To keep track of unalignment caused by short insns.  */
>int unalign;
> -  int force_short_suffix; /* Used when disgorging return delay slot insns.  
> */
> -  const char *size_reason;
>struct arc_ccfsm ccfsm_current;
>/* Map from uid to ccfsm state during branch shortening.  */
>rtx ccfsm_current_insn;
> @@ -4307,7 +4305,7 @@ arc_print_operand (FILE *file, rtx x, int code)
>   }
>break;
>  case '&':
> -  if (TARGET_ANNOTATE_ALIGN && cfun->machine->size_reason)
> +  if (TARGET_ANNOTATE_ALIGN)
>   fprintf (file, "; unalign: %d", cfun->machine->unalign);
>return;
>  case '+':
> @@ -4980,7 +4978,6 @@ static int
>  arc_verify_short (rtx_insn *insn, int, int check_attr)
>  {
>enum attr_iscompact iscompact;
> -  struct machine_function *machine;
>  
>if (check_attr > 0)
>  {
> @@ -4988,10 +4985,6 @@ arc_verify_short (rtx_insn *insn, int, int check_attr)
>if (iscompact == ISCOMPACT_FALSE)
>   return 0;
>  }
> -  machine = cfun->machine;
> -
> -  if (machine->force_short_suffix >= 0)
> -return machine->force_short_suffix;
>  
>return (get_attr_length (insn) & 2) != 0;
>  }
> @@ -5030,8 +5023,6 @@ arc_final_prescan_insn (rtx_insn *insn, rtx *opvec 
> ATTRIBUTE_UNUSED,
>cfun->machine->prescan_initialized = 1;
>  }
>arc_ccfsm_advance (insn, &arc_ccfsm_current);
> -
> -  cfun->machine->size_reason = 0;
>  }
>  
>  /* Given FROM and TO register numbers, say whether this elimination is 
> allowed.
> @@ -7673,6 +7664,76 @@ jli_call_scan (void)
>  }
>  }
>  
> +/* Add padding if necessary to avoid a mispredict.  A return could
> +   happen immediately after the function start.  A call/return and
> +   return/return must be 6 bytes apart to avoid mispredict.  */
> +
> +static void
> +pad_return (void)
> +{
> +  rtx_insn *insn;
> +  long offset;
> +
> +  if (!TARGET_PAD_RETURN)
> +return;
> +
> +  for (insn = get_insns (); insn; in

Re: [PATCH 00/10][ARC] Critical fixes

2018-01-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-01-08 15:18:30 
+]:

> >   [ARC][LRA] Use TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV.
> >   [ARC] Don't allow the last ZOL insn to be in a delay slot.
> >   [ARC] Add trap instruction.
> >   [ARC] Update legitimate constant hook.
> >   [ARC] Enable unaligned access.
> >   [ARC] Revamp trampoline implementation.
> >   [ARC][ZOL] Update uses for hw-loop labels.
> >   [ARC] Add ARCv2 core3 tune option.
> >   [ARC][FIX] Consider command line ffixed- option.
> >   [ARC] Update (u)maddsidi patterns.
> 
> Hi Andrew,
> 
> Thank you for reviewing this batch of fixes. Any chance to check also these 
> ones, they are hanging there for a long time now:
> 
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00078.html
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00081.html
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00080.html
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00079.html
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00084.html
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00083.html
> https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00082.html

Sorry for missing these, they somehow didn't make it onto my todo
list.

I'll review these over the next couple of days.

Thanks,
Andrew


Re: [PATCH 1/6] [ARC] Add JLI support.

2018-01-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:30:30 
+0100]:

> The ARCv2 ISA provides the JLI instruction, which is two-byte instructions
> that can be used to reduce code size in an application. To make use of it,
> we provide two new function attributes 'jli_always' and 'jli_fixed' which
> will force the compiler to call the indicated function using a jli_s
> instruction. The compiler also generates the entries in the JLI table for
> the case when we use 'jli_always' attribute. In the case of 'jli_fixed'
> the compiler assumes a fixed position of the function into JLI
> table. Thus, the user needs to provide an assembly file with the JLI table
> for the final link. This is usefully when we want to have a table in ROM
> and a second table in the RAM memory.
> 
> The jli instruction usage can be also forced without the need to annotate
> the source code via '-mjli-always' command.
> 
> gcc/
> 2017-02-10  Claudiu Zissulescu  
>   John Eric Martin 
> 
>   * config/arc/arc-protos.h: Add arc_is_jli_call_p proto.
>   * config/arc/arc.c (_arc_jli_section): New struct.
>   (arc_jli_section): New type.
>   (rc_jli_sections): New static variable.
>   (arc_handle_jli_attribute): New function.
>   (arc_attribute_table): Add jli_always and jli_fixed attribute.
>   (arc_file_end): New function.
>   (TARGET_ASM_FILE_END): Define.
>   (arc_print_operand): Reuse 'S' letter for JLI output instruction.
>   (arc_add_jli_section): New function.
>   (jli_call_scan): Likewise.
>   (arc_reorg): Call jli_call_scan.
>   (arc_output_addsi): Remove 'S' from printing asm operand.
>   (arc_is_jli_call_p): New function.
>   * config/arc/arc.md (movqi_insn): Remove 'S' from printing asm
>   operand.
>   (movhi_insn): Likewise.
>   (movsi_insn): Likewise.
>   (movsi_set_cc_insn): Likewise.
>   (loadqi_update): Likewise.
>   (load_zeroextendqisi_update): Likewise.
>   (load_signextendqisi_update): Likewise.
>   (loadhi_update): Likewise.
>   (load_zeroextendhisi_update): Likewise.
>   (load_signextendhisi_update): Likewise.
>   (loadsi_update): Likewise.
>   (loadsf_update): Likewise.
>   (movsicc_insn): Likewise.
>   (bset_insn): Likewise.
>   (bxor_insn): Likewise.
>   (bclr_insn): Likewise.
>   (bmsk_insn): Likewise.
>   (bicsi3_insn): Likewise.
>   (cmpsi_cc_c_insn): Likewise.
>   (movsi_ne): Likewise.
>   (movsi_cond_exec): Likewise.
>   (clrsbsi2): Likewise.
>   (norm_f): Likewise.
>   (normw): Likewise.
>   (swap): Likewise.
>   (divaw): Likewise.
>   (flag): Likewise.
>   (sr): Likewise.
>   (kflag): Likewise.
>   (ffs): Likewise.
>   (ffs_f): Likewise.
>   (fls): Likewise.
>   (call_i): Remove 'S' asm letter, add jli instruction.
>   (call_value_i): Likewise.
>   * config/arc/arc.op (mjli-always): New option.
>   * config/arc/constraints.md (Cji): New constraint.
>   * config/arc/fpx.md (addsf3_fpx): Remove 'S' from printing asm
>   operand.
>   (subsf3_fpx): Likewise.
>   (mulsf3_fpx): Likewise.
>   * config/arc/simdext.md (vendrec_insn): Remove 'S' from printing
>   asm operand.
>   * doc/extend.texi (ARC): Document 'jli-always' and 'jli-fixed'
>   function attrbutes.
>   * doc/invoke.texi (ARC): Document mjli-always option.
> 
> gcc/testsuite
> 2017-02-10  Claudiu Zissulescu  
> 
>   * gcc.target/arc/jli-1.c: New file.
>   * gcc.target/arc/jli-2.c: Likewise.

This looks fine, but I wonder if there should be some documentation
that mentions the new .jlitab section added?

There's one whitespace issue I also spotted...

> @@ -5026,6 +5062,36 @@ static void arc_file_start (void)
>fprintf (asm_out_file, "\t.cpu %s\n", arc_cpu_string);
>  }
>  
> +/* Implement `TARGET_ASM_FILE_END'.  */
> +/* Outputs to the stdio stream FILE jli related text.  */
> +
> +void arc_file_end (void)
> +{
> +  arc_jli_section *sec = arc_jli_sections;
> +
> +  while (sec != NULL)
> +  {

I think the '{' is not indented correctly.

Thanks,
Andrew


Re: [PATCH 2/6] [ARC] Add SJLI support.

2018-01-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:30:31 
+0100]:

> gcc/
> 2017-02-20  Claudiu Zissulescu  
> 
>   * config/arc/arc-protos.h: Add arc_is_secure_call_p proto.
>   * config/arc/arc.c (arc_handle_secure_attribute): New function.
>   (arc_attribute_table): Add 'secure_call' attribute.
>   (arc_print_operand): Print secure call operand.
>   (arc_function_ok_for_sibcall): Don't optimize tail calls when
>   secure.
>   (arc_is_secure_call_p): New function.
>   * config/arc/arc.md (call_i): Add support for sjli instruction.
>   (call_value_i): Likewise.
>   * config/arc/constraints.md (Csc): New constraint.
> ---
>  gcc/config/arc/arc-protos.h   |   1 +
>  gcc/config/arc/arc.c  | 164 
> +++---
>  gcc/config/arc/arc.md |  32 +
>  gcc/config/arc/constraints.md |   7 ++
>  gcc/doc/extend.texi   |   6 ++
>  5 files changed, 155 insertions(+), 55 deletions(-)

Looks fine, few comments inline below.

Thanks
Andrew

> 
> @@ -3939,6 +3985,9 @@ arc_print_operand (FILE *file, rtx x, int code)
>   : NULL_TREE);
> if (lookup_attribute ("jli_fixed", attrs))
>   {
> +   /* No special treatment for jli_fixed functions.  */
> +   if (code == 'j' )

Extra space before ')'.

> + break;
> fprintf (file, "%ld\t; @",
>  TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attrs;
> assemble_name (file, XSTR (x, 0));
> @@ -3947,6 +3996,22 @@ arc_print_operand (FILE *file, rtx x, int code)
>   }
> fprintf (file, "@__jli.");
> assemble_name (file, XSTR (x, 0));
> +   if (code == 'j')
> + arc_add_jli_section (x);
> +   return;
> + }
> +  if (GET_CODE (x) == SYMBOL_REF
> +   && arc_is_secure_call_p (x))
> + {
> +   /* No special treatment for secure functions.  */
> +   if (code == 'j' )
> + break;
> +   tree attrs = (TREE_TYPE (SYMBOL_REF_DECL (x)) != error_mark_node
> + ? TYPE_ATTRIBUTES (TREE_TYPE (SYMBOL_REF_DECL (x)))
> + : NULL_TREE);
> +   fprintf (file, "%ld\t; @",
> +TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attrs;
> +   assemble_name (file, XSTR (x, 0));
> return;
>   }
>break;
> @@ -6897,6 +6962,8 @@ arc_function_ok_for_sibcall (tree decl,
>   return false;
>if (lookup_attribute ("jli_fixed", attrs))
>   return false;
> +  if (lookup_attribute ("secure_call", attrs))
> + return false;
>  }
>  
>/* Everything else is ok.  */
> @@ -7594,46 +7661,6 @@ arc_reorg_loops (void)
>reorg_loops (true, &arc_doloop_hooks);
>  }
>  
> -/* Add the given function declaration to emit code in JLI section.  */
> -
> -static void
> -arc_add_jli_section (rtx pat)
> -{
> -  const char *name;
> -  tree attrs;
> -  arc_jli_section *sec = arc_jli_sections, *new_section;
> -  tree decl = SYMBOL_REF_DECL (pat);
> -
> -  if (!pat)
> -return;
> -
> -  if (decl)
> -{
> -  /* For fixed locations do not generate the jli table entry.  It
> -  should be provided by the user as an asm file.  */
> -  attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl));
> -  if (lookup_attribute ("jli_fixed", attrs))
> - return;
> -}
> -
> -  name = XSTR (pat, 0);
> -
> -  /* Don't insert the same symbol twice.  */
> -  while (sec != NULL)
> -{
> -  if(strcmp (name, sec->name) == 0)
> - return;
> -  sec = sec->next;
> -}
> -
> -  /* New name, insert it.  */
> -  new_section = (arc_jli_section *) xmalloc (sizeof (arc_jli_section));
> -  gcc_assert (new_section != NULL);
> -  new_section->name = name;
> -  new_section->next = arc_jli_sections;
> -  arc_jli_sections = new_section;
> -}
> -
>  /* Scan all calls and add symbols to be emitted in the jli section if
> needed.  */
>  
> @@ -10968,6 +10995,63 @@ arc_handle_jli_attribute (tree *node 
> ATTRIBUTE_UNUSED,
> return NULL_TREE;
>  }
>  
> +/* Handle and "scure" attribute; arguments as in struct
> +   attribute_spec.handler.  */
> +
> +static tree
> +arc_handle_secure_attribute (tree *node ATTRIBUTE_UNUSED,
> +   tree name, tree args, int,
> +   bool *no_add_attrs)
> +{
> +  if (!TARGET_EM)
> +{
> +  warning (OPT_Wattributes,
> +"%qE attribute only valid for ARC EM architecture",
> +name);
> +  *no_add_attrs = true;
> +}
> +
> +  if (args == NULL_TREE)
> +{
> +  warning (OPT_Wattributes,
> +"argument of %qE attribute is missing",
> +name);
> +  *no_add_attrs = true;
> +}
> +  else
> +{
> +  if (TREE_CODE (TREE_VALUE (args)) == NON_LVALUE_EXPR)
> + TREE_VALUE (args) = TREE_OPERAND (TREE_VALUE (args), 0);
> +  tree arg = TREE_VALUE (args);
> +  if (TREE_CODE (arg) != INTEGER_CST)
> + {
> +   warning 

Re: [PATCH 3/6] [ARC] Add support for "register file 16" reduced register set

2018-01-16 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:30:32 
+0100]:

> gcc/
> 2017-03-20  Claudiu Zissulescu  
> 
>   * config/arc/arc-arches.def: Option mrf16 valid for all
>   architectures.
>   * config/arc/arc-c.def (__ARC_RF16__): New predefined macro.
>   * config/arc/arc-cpus.def (em_mini): New cpu with rf16 on.
>   * config/arc/arc-options.def (FL_RF16): Add mrf16 option.
>   * config/arc/arc-tables.opt: Regenerate.
>   * config/arc/arc.c (arc_conditional_register_usage): Handle
>   reduced register file case.
>   (arc_file_start): Set must have build attributes.
>   * config/arc/arc.h (MAX_ARC_PARM_REGS): Conditional define using
>   mrf16 option value.
>   * config/arc/arc.opt (mrf16): Add new option.
>   * config/arc/elf.h (ATTRIBUTE_PCS): Define.
>   * config/arc/genmultilib.awk: Handle new mrf16 option.
>   * config/arc/linux.h (ATTRIBUTE_PCS): Define.
>   * config/arc/t-multilib: Regenerate.
>   * doc/invoke.texi (ARC Options): Document mrf16 option.
> 
> gcc/testsuite/
> 2017-03-20  Claudiu Zissulescu  
> 
>   * gcc.dg/builtin-apply2.c: Change for the ARC's reduced register
>   set file case.
> 
> libgcc/
> 2017-09-18  Claudiu Zissulescu  
> 
>   * config/arc/lib1funcs.S (__udivmodsi4): Use safe version for RF16
>   option.
>   (__divsi3): Use RF16 safe registers.
>   (__modsi3): Likewise.

Looks fine, except I think that the new 'em_mini' cpu needs to be
added to the -mcpu= description in doc/invoke.texi.

Thanks,
Andrew




> ---
>  gcc/config/arc/arc-arches.def |  8 
>  gcc/config/arc/arc-c.def  |  1 +
>  gcc/config/arc/arc-cpus.def   |  1 +
>  gcc/config/arc/arc-options.def|  2 +-
>  gcc/config/arc/arc-tables.opt |  3 +++
>  gcc/config/arc/arc.c  | 27 +++
>  gcc/config/arc/arc.h  |  2 +-
>  gcc/config/arc/arc.opt|  4 
>  gcc/config/arc/elf.h  |  4 
>  gcc/config/arc/genmultilib.awk|  2 ++
>  gcc/config/arc/linux.h|  9 +
>  gcc/config/arc/t-multilib |  4 ++--
>  gcc/doc/invoke.texi   |  8 +++-
>  gcc/testsuite/gcc.dg/builtin-apply2.c |  8 +++-
>  libgcc/config/arc/lib1funcs.S | 22 +++---
>  15 files changed, 84 insertions(+), 21 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-arches.def b/gcc/config/arc/arc-arches.def
> index 29cb9c4..a0d585b 100644
> --- a/gcc/config/arc/arc-arches.def
> +++ b/gcc/config/arc/arc-arches.def
> @@ -40,15 +40,15 @@
>  
>  ARC_ARCH ("arcem", em, FL_MPYOPT_1_6 | FL_DIVREM | FL_CD | FL_NORM   \
> | FL_BS | FL_SWAP | FL_FPUS | FL_SPFP | FL_DPFP   \
> -   | FL_SIMD | FL_FPUDA | FL_QUARK, 0)
> +   | FL_SIMD | FL_FPUDA | FL_QUARK | FL_RF16, 0)
>  ARC_ARCH ("archs", hs, FL_MPYOPT_7_9 | FL_DIVREM | FL_NORM | FL_CD   \
> | FL_ATOMIC | FL_LL64 | FL_BS | FL_SWAP   \
> -   | FL_FPUS | FL_FPUD,  \
> +   | FL_FPUS | FL_FPUD | FL_RF16,\
> FL_CD | FL_ATOMIC | FL_BS | FL_NORM | FL_SWAP)
>  ARC_ARCH ("arc6xx", 6xx, FL_BS | FL_NORM | FL_SWAP | FL_MUL64 | FL_MUL32x16 \
> -   | FL_SPFP | FL_ARGONAUT | FL_DPFP, 0)
> +   | FL_SPFP | FL_ARGONAUT | FL_DPFP | FL_RF16, 0)
>  ARC_ARCH ("arc700", 700, FL_ATOMIC | FL_BS | FL_NORM | FL_SWAP | FL_EA \
> -   | FL_SIMD | FL_SPFP | FL_ARGONAUT | FL_DPFP, \
> +   | FL_SIMD | FL_SPFP | FL_ARGONAUT | FL_DPFP | FL_RF16,   \
> FL_BS | FL_NORM | FL_SWAP)
>  
>  /* Local Variables: */
> diff --git a/gcc/config/arc/arc-c.def b/gcc/config/arc/arc-c.def
> index 8c5097e..c9443c9 100644
> --- a/gcc/config/arc/arc-c.def
> +++ b/gcc/config/arc/arc-c.def
> @@ -28,6 +28,7 @@ ARC_C_DEF ("__ARC_NORM__",  TARGET_NORM)
>  ARC_C_DEF ("__ARC_MUL64__",  TARGET_MUL64_SET)
>  ARC_C_DEF ("__ARC_MUL32BY16__", TARGET_MULMAC_32BY16_SET)
>  ARC_C_DEF ("__ARC_SIMD__",   TARGET_SIMD_SET)
> +ARC_C_DEF ("__ARC_RF16__",   TARGET_RF16)
>  
>  ARC_C_DEF ("__ARC_BARREL_SHIFTER__", TARGET_BARREL_SHIFTER)
>  
> diff --git a/gcc/config/arc/arc-cpus.def b/gcc/config/arc/arc-cpus.def
> index 60b4045..c2b0062 100644
> --- a/gcc/config/arc/arc-cpus.def
> +++ b/gcc/config/arc/arc-cpus.def
> @@ -46,6 +46,7 @@
> TUNETune value for the given configuration, otherwise NONE.  */
>  
>  ARC_CPU (em, em, 0, NONE)
> +ARC_CPU (em_mini,   em, FL_RF16, NONE)
>  ARC_CPU (arcem,  em, FL_MPYOPT_2|FL_CD|FL_BS, NONE)
>  ARC_CPU (em4,em, FL_CD, NONE)
>  ARC_CPU (em4_dmips, em, FL_MPYOPT_2|FL_CD|FL_DIVREM|FL_NORM|FL_SWAP|FL_BS, 
> NONE)
> diff --git a/gcc/config/arc/arc-options.def b/gcc/config/arc/arc-options.def
> index be51614..8fc7b50 100644
> --- a/gcc/config/arc/arc-options.def
> +++ b/gcc/config/arc/arc-options.def
> @@ -60,7 +60,7 @@
>  ARC_OPT (FL_CD,(1UL

Re: [PATCH 4/6] [ARC] Rework delegitimate_address hook

2018-01-23 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:30:33 
+0100]:

> From: claziss 
> 
> Delegitimize address is used to undo the obfuscating effect of PIC
> addresses, returning the address in a way which is understood by the
> compiler.
> 
> gcc/
> 2017-04-25  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_delegitimize_address_0): Refactored to
>   recognize new pic like addresses.
>   (arc_delegitimize_address): Clean up.
> 
> testsuite/
> 2017-08-31  Claudiu Zissulescu  
> 
>   * testsuite/gcc.target/arc/tdelegitimize_addr.c: New test.

Assuming this has passed all of the tests, then this change is fine
with me.

The commit message you propose above describes what delegitimize does
in general, but it doesn't really explain why _this_ change is
needed.  You remove a lot of code, it would be nice if the commit
message explained why we're able to drop all of this complexity.

Thanks,
Andrew



> ---
>  gcc/config/arc/arc.c  | 91 
> ++-
>  gcc/testsuite/gcc.target/arc/tdelegitimize_addr.c | 23 ++
>  2 files changed, 62 insertions(+), 52 deletions(-)
>  create mode 100755 gcc/testsuite/gcc.target/arc/tdelegitimize_addr.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index e7194a2..07dd072 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -9506,68 +9506,55 @@ arc_legitimize_address (rtx orig_x, rtx oldx, 
> machine_mode mode)
>  }
>  
>  static rtx
> -arc_delegitimize_address_0 (rtx x)
> +arc_delegitimize_address_0 (rtx op)
>  {
> -  rtx u, gp, p;
> -
> -  if (GET_CODE (x) == CONST && GET_CODE (u = XEXP (x, 0)) == UNSPEC)
> +  switch (GET_CODE (op))
>  {
> -  if (XINT (u, 1) == ARC_UNSPEC_GOT
> -   || XINT (u, 1) == ARC_UNSPEC_GOTOFFPC)
> - return XVECEXP (u, 0, 0);
> +case CONST:
> +  return arc_delegitimize_address_0 (XEXP (op, 0));
> +
> +case UNSPEC:
> +  switch (XINT (op, 1))
> + {
> + case ARC_UNSPEC_GOT:
> + case ARC_UNSPEC_GOTOFFPC:
> +   return XVECEXP (op, 0, 0);
> + default:
> +   break;
> + }
> +  break;
> +
> +case PLUS:
> +  {
> + rtx t1 = arc_delegitimize_address_0 (XEXP (op, 0));
> + rtx t2 = XEXP (op, 1);
> +
> + if (t1 && t2)
> +   return gen_rtx_PLUS (GET_MODE (op), t1, t2);
> + break;
> +  }
> +
> +default:
> +  break;
>  }
> -  else if (GET_CODE (x) == CONST && GET_CODE (p = XEXP (x, 0)) == PLUS
> -&& GET_CODE (u = XEXP (p, 0)) == UNSPEC
> -&& (XINT (u, 1) == ARC_UNSPEC_GOT
> -|| XINT (u, 1) == ARC_UNSPEC_GOTOFFPC))
> -return gen_rtx_CONST
> - (GET_MODE (x),
> -  gen_rtx_PLUS (GET_MODE (p), XVECEXP (u, 0, 0), XEXP (p, 1)));
> -  else if (GET_CODE (x) == PLUS
> -&& ((REG_P (gp = XEXP (x, 0))
> - && REGNO (gp) == PIC_OFFSET_TABLE_REGNUM)
> -|| (GET_CODE (gp) == CONST
> -&& GET_CODE (u = XEXP (gp, 0)) == UNSPEC
> -&& XINT (u, 1) == ARC_UNSPEC_GOT
> -&& GET_CODE (XVECEXP (u, 0, 0)) == SYMBOL_REF
> -&& !strcmp (XSTR (XVECEXP (u, 0, 0), 0), "_DYNAMIC")))
> -&& GET_CODE (XEXP (x, 1)) == CONST
> -&& GET_CODE (u = XEXP (XEXP (x, 1), 0)) == UNSPEC
> -&& XINT (u, 1) == ARC_UNSPEC_GOTOFF)
> -return XVECEXP (u, 0, 0);
> -  else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
> -&& ((REG_P (gp = XEXP (XEXP (x, 0), 1))
> - && REGNO (gp) == PIC_OFFSET_TABLE_REGNUM)
> -|| (GET_CODE (gp) == CONST
> -&& GET_CODE (u = XEXP (gp, 0)) == UNSPEC
> -&& XINT (u, 1) == ARC_UNSPEC_GOT
> -&& GET_CODE (XVECEXP (u, 0, 0)) == SYMBOL_REF
> -&& !strcmp (XSTR (XVECEXP (u, 0, 0), 0), "_DYNAMIC")))
> -&& GET_CODE (XEXP (x, 1)) == CONST
> -&& GET_CODE (u = XEXP (XEXP (x, 1), 0)) == UNSPEC
> -&& XINT (u, 1) == ARC_UNSPEC_GOTOFF)
> -return gen_rtx_PLUS (GET_MODE (x), XEXP (XEXP (x, 0), 0),
> -  XVECEXP (u, 0, 0));
> -  else if (GET_CODE (x) == PLUS
> -&& (u = arc_delegitimize_address_0 (XEXP (x, 1
> -return gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), u);
>return NULL_RTX;
>  }
>  
>  static rtx
> -arc_delegitimize_address (rtx x)
> +arc_delegitimize_address (rtx orig_x)
>  {
> -  rtx orig_x = x = delegitimize_mem_from_attrs (x);
> -  if (GET_CODE (x) == MEM)
> +  rtx x = orig_x;
> +
> +  if (MEM_P (x))
>  x = XEXP (x, 0);
> +
>x = arc_delegitimize_address_0 (x);
> -  if (x)
> -{
> -  if (MEM_P (orig_x))
> - x = replace_equiv_address_nv (orig_x, x);
> -  return x;
> -}
> -  return orig_x;
> +  if (!x)
> +return orig_x;
> +
> +  if (MEM_P (orig_x))
> +x = replace_equiv_address_nv (orig_x, x);
> +  return x;
>  }
>  
>  /* Return a REG rtx for acc1.  N.B. the gcc-internal representation may
> diff --git a/gcc/testsuite/gcc.target/arc/tdelegitimize_addr.c 

Re: [PATCH 5/6] [ARC] Add 'uncached' attribute.

2018-01-29 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:30:34 
+0100]:

> From: claziss 
> 
> The _Uncached type qualifier can be used to bypass the cache without
> resorting to declaring variables as volatile.
> 
> gcc/
> 2017-07-12  Claudiu Zissulescu  
> 
>   * config/arc/arc-protos.h (arc_is_uncached_mem_p): Function proto.
>   * config/arc/arc.c (arc_handle_uncached_attribute): New function.
>   (arc_attribute_table): Add 'uncached' attribute.
>   (arc_print_operand): Print '.di' flag for uncached memory
>   accesses.
>   (arc_in_small_data_p): Do not consider for small data the uncached
>   types.
>   (arc_is_uncached_mem_p): New function.
>   * config/arc/predicates.md (compact_store_memory_operand): Check
>   for uncached memory accesses.
>   (nonvol_nonimm_operand): Likewise.
> 
> gcc/testsuite
> 2017-07-12  Claudiu Zissulescu  

Looks good, with the updated documentation.

Thanks,
Andrew


> 
>   * gcc.target/arc/uncached.c: New test.
> ---
>  gcc/config/arc/arc-protos.h |  1 +
>  gcc/config/arc/arc.c| 65 
> -
>  gcc/config/arc/predicates.md|  7 +++-
>  gcc/testsuite/gcc.target/arc/uncached.c | 18 +
>  4 files changed, 88 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/uncached.c
> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index f8e7937..cc00730 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -47,6 +47,7 @@ extern void arc_expand_compare_and_swap (rtx *);
>  extern bool compact_memory_operand_p (rtx, machine_mode, bool, bool);
>  extern int arc_return_address_register (unsigned int);
>  extern unsigned int arc_compute_function_type (struct function *);
> +extern bool arc_is_uncached_mem_p (rtx);
>  #endif /* RTX_CODE */
>  
>  extern unsigned int arc_compute_frame_size (int);
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 07dd072..a397cbd 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -222,7 +222,7 @@ static tree arc_handle_interrupt_attribute (tree *, tree, 
> tree, int, bool *);
>  static tree arc_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
>  static tree arc_handle_jli_attribute (tree *, tree, tree, int, bool *);
>  static tree arc_handle_secure_attribute (tree *, tree, tree, int, bool *);
> -
> +static tree arc_handle_uncached_attribute (tree *, tree, tree, int, bool *);
>  
>  /* Initialized arc_attribute_table to NULL since arc doesnot have any
> machine specific supported attributes.  */
> @@ -254,6 +254,9 @@ const struct attribute_spec arc_attribute_table[] =
>/* Call a function using secure-mode.  */
>{ "secure_call",  1, 1, false, true, true, arc_handle_secure_attribute,
>  false },
> +  /* Bypass caches using .di flag.  */
> +  { "uncached", 0, 0, false, true, false, arc_handle_uncached_attribute,
> +false },
>{ NULL, 0, 0, false, false, false, NULL, false }
>  };
>  static int arc_comp_type_attributes (const_tree, const_tree);
> @@ -4135,7 +4138,8 @@ arc_print_operand (FILE *file, rtx x, int code)
>refs are defined to use the cache bypass mechanism.  */
>if (GET_CODE (x) == MEM)
>   {
> -   if (MEM_VOLATILE_P (x) && !TARGET_VOLATILE_CACHE_SET )
> +   if ((MEM_VOLATILE_P (x) && !TARGET_VOLATILE_CACHE_SET)
> +   || arc_is_uncached_mem_p (x))
>   fputs (".di", file);
>   }
>else
> @@ -8038,6 +8042,7 @@ static bool
>  arc_in_small_data_p (const_tree decl)
>  {
>HOST_WIDE_INT size;
> +  tree attr;
>  
>/* Only variables are going into small data area.  */
>if (TREE_CODE (decl) != VAR_DECL)
> @@ -8061,6 +8066,11 @@ arc_in_small_data_p (const_tree decl)
>&& TREE_THIS_VOLATILE (decl))
>  return false;
>  
> +  /* Likewise for uncached data.  */
> +  attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
> +  if (lookup_attribute ("uncached", attr))
> +return false;
> +
>if (DECL_SECTION_NAME (decl) != 0)
>  {
>const char *name = DECL_SECTION_NAME (decl);
> @@ -11066,6 +11076,57 @@ arc_is_secure_call_p (rtx pat)
>return false;
>  }
>  
> +/* Handle "uncached" qualifier.  */
> +
> +static tree
> +arc_handle_uncached_attribute (tree *node,
> +tree name, tree args,
> +int flags ATTRIBUTE_UNUSED,
> +bool *no_add_attrs)
> +{
> +  if (DECL_P (*node) && TREE_CODE (*node) != TYPE_DECL)
> +{
> +  error ("%qE attribute only applies to types",
> +  name);
> +  *no_add_attrs = true;
> +}
> +  else if (args)
> +{
> +  warning (OPT_Wattributes, "argument of %qE attribute ignored", name);
> +}
> +  return NULL_TREE;
> +}
> +
> +/* Return TRUE if PAT is a memory addressing an uncached data.  */
> +
> +bool
> +arc_is_uncached_mem_p (rtx pat)
> +{
> +  tree attrs;
> +  tree ttype;
> +  struct mem_attrs *refattr

Re: [PATCH 6/6] [ARC] Add 'aux' variable attribute.

2018-01-29 Thread Andrew Burgess
* Claudiu Zissulescu  [2017-11-02 13:30:35 
+0100]:

> From: claziss 
> 
> The 'aux' variable attribute is used to directly access the auxiliary
> register space from C.
> 
> gcc/
> 2017-07-25  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_handle_aux_attribute): New function.
>   (arc_attribute_table): Add 'aux' attribute.
>   (arc_in_small_data_p): Consider aux like variables.
>   (arc_is_aux_reg_p): New function.
>   (arc_asm_output_aligned_decl_local): Ignore 'aux' like variables.
>   (arc_get_aux_arg): New function.
>   (prepare_move_operands): Handle aux-register access.
>   (arc_handle_aux_attribute): New function.
>   * doc/extend.texi (ARC Variable attributes): Add subsection.
> 
> testsuite/
> 2017-07-25  Claudiu Zissulescu  
> 
>   * gcc.target/arc/taux-1.c: New test.
>   * gcc.target/arc/taux-2.c: Likewise.

Looks good.

Sorry for the time taken to review this series.

Thanks,
Andrew


> ---
>  gcc/config/arc/arc.c  | 160 
> +-
>  gcc/doc/extend.texi   |  13 +++
>  gcc/testsuite/gcc.target/arc/taux-1.c |  38 
>  gcc/testsuite/gcc.target/arc/taux-2.c |  15 
>  4 files changed, 225 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/taux-1.c
>  create mode 100644 gcc/testsuite/gcc.target/arc/taux-2.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index a397cbd..33f68ef 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -223,6 +223,7 @@ static tree arc_handle_fndecl_attribute (tree *, tree, 
> tree, int, bool *);
>  static tree arc_handle_jli_attribute (tree *, tree, tree, int, bool *);
>  static tree arc_handle_secure_attribute (tree *, tree, tree, int, bool *);
>  static tree arc_handle_uncached_attribute (tree *, tree, tree, int, bool *);
> +static tree arc_handle_aux_attribute (tree *, tree, tree, int, bool *);
>  
>  /* Initialized arc_attribute_table to NULL since arc doesnot have any
> machine specific supported attributes.  */
> @@ -257,6 +258,8 @@ const struct attribute_spec arc_attribute_table[] =
>/* Bypass caches using .di flag.  */
>{ "uncached", 0, 0, false, true, false, arc_handle_uncached_attribute,
>  false },
> +  /* Declare a variable as aux.  */
> +  { "aux", 0, 1, true, false, false, arc_handle_aux_attribute, false },
>{ NULL, 0, 0, false, false, false, NULL, false }
>  };
>  static int arc_comp_type_attributes (const_tree, const_tree);
> @@ -8071,6 +8074,11 @@ arc_in_small_data_p (const_tree decl)
>if (lookup_attribute ("uncached", attr))
>  return false;
>  
> +  /* and for aux regs.  */
> +  attr = DECL_ATTRIBUTES (decl);
> +  if (lookup_attribute ("aux", attr))
> +return false;
> +
>if (DECL_SECTION_NAME (decl) != 0)
>  {
>const char *name = DECL_SECTION_NAME (decl);
> @@ -8238,6 +8246,35 @@ compact_sda_memory_operand (rtx op, machine_mode mode, 
> bool short_p)
>return false;
>  }
>  
> +/* Return TRUE if PAT is accessing an aux-reg.  */
> +
> +static bool
> +arc_is_aux_reg_p (rtx pat)
> +{
> +  tree attrs = NULL_TREE;
> +  tree addr;
> +
> +  if (!MEM_P (pat))
> +return false;
> +
> +  /* Get the memory attributes.  */
> +  addr = MEM_EXPR (pat);
> +  if (!addr)
> +return false;
> +
> +  /* Get the attributes.  */
> +  if (TREE_CODE (addr) == VAR_DECL)
> +attrs = DECL_ATTRIBUTES (addr);
> +  else if (TREE_CODE (addr) == MEM_REF)
> +attrs = TYPE_ATTRIBUTES (TREE_TYPE (TREE_OPERAND (addr, 0)));
> +  else
> +return false;
> +
> +  if (lookup_attribute ("aux", attrs))
> +return true;
> +  return false;
> +}
> +
>  /* Implement ASM_OUTPUT_ALIGNED_DECL_LOCAL.  */
>  
>  void
> @@ -8246,7 +8283,14 @@ arc_asm_output_aligned_decl_local (FILE * stream, tree 
> decl, const char * name,
>  unsigned HOST_WIDE_INT align,
>  unsigned HOST_WIDE_INT globalize_p)
>  {
> -  int in_small_data =   arc_in_small_data_p (decl);
> +  int in_small_data = arc_in_small_data_p (decl);
> +  rtx mem = decl == NULL_TREE ? NULL_RTX : DECL_RTL (decl);
> +
> +  /* Don't output aux-reg symbols.  */
> +  if (mem != NULL_RTX && MEM_P (mem)
> +  && SYMBOL_REF_P (XEXP (mem, 0))
> +  && arc_is_aux_reg_p (mem))
> +return;
>  
>if (in_small_data)
>  switch_to_section (get_named_section (NULL, ".sbss", 0));
> @@ -8586,12 +8630,80 @@ arc_expand_movmem (rtx *operands)
>return true;
>  }
>  
> +static bool
> +arc_get_aux_arg (rtx pat, int *auxr)
> +{
> +  tree attr, addr = MEM_EXPR (pat);
> +  if (TREE_CODE (addr) != VAR_DECL)
> +return false;
> +
> +  attr = DECL_ATTRIBUTES (addr);
> +  if (lookup_attribute ("aux", attr))
> +{
> +  tree arg = TREE_VALUE (attr);
> +  if (arg)
> + {
> +   *auxr = TREE_INT_CST_LOW (TREE_VALUE (arg));
> +   return true;
> + }
> +}
> +
> +  return false;
> +}
> +
>  /* Prepare operands for move in MODE.  R

Re: [PATCH] [ARC] Cleanup unused functions.

2018-03-05 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-02-20 15:38:32 +0200]:

> From: Claudiu Zissulescu 
> 
> Cleanup unsed functions and macros.
> 
> OK to apply?
> Claudiu

Looks good.  Nice cleanup.

Thanks,
Andrew


> 
> gcc/
> 2018-01-26  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_finalize_pic): Remove function.
>   (arc_must_save_register): We use single base PIC register, remove
>   checks to save/restore the PIC register.
>   (arc_expand_prologue): Likewise.
>   * config/arc/arc-protos.h (arc_set_default_type_attributes):
>   Remove.
>   (arc_verify_short): Likewise.
>   (arc_attr_type): Likewise.
>   * config/arc/arc.c (arc_set_default_type_attributes): Remove.
>   (walk_stores): Likewise.
>   (arc_address_cost): Make it static.
>   (arc_verify_short): Likewise.
>   (branch_dest): Likewise.
>   (arc_attr_type): Likewise.
>   * config/arc/arc.c (TARGET_ADJUST_INSN_LENGTH): Remove.
>   (TARGET_INSN_LENGTH_PARAMETERS): Likewise.
>   (arc_final_prescan_insn): Remove inserting the nops due to
>   hardware hazards.  It is done in reorg step.
>   (insn_length_variant_t): Remove.
>   (insn_length_parameters_t): Likewise.
>   (arc_insn_length_parameters): Likewise.
>   (arc_get_insn_variants): Likewise.
>   * config/arc/arc.h (TARGET_UPSIZE_DBR): Remove.
> ---
>  gcc/config/arc/arc-protos.h |   3 -
>  gcc/config/arc/arc.c| 471 
> +---
>  gcc/config/arc/arc.h|   3 -
>  3 files changed, 4 insertions(+), 473 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index b469cfc4c2c..75cfedab7f1 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -32,7 +32,6 @@ extern bool arc_double_limm_p (rtx);
>  extern void arc_print_operand (FILE *, rtx, int);
>  extern void arc_print_operand_address (FILE *, rtx);
>  extern void arc_final_prescan_insn (rtx_insn *, rtx *, int);
> -extern void arc_set_default_type_attributes(tree type);
>  extern const char *arc_output_libcall (const char *);
>  extern bool prepare_extend_operands (rtx *operands, enum rtx_code code,
>machine_mode omode);
> @@ -97,10 +96,8 @@ extern void split_addsi (rtx *);
>  extern void split_subsi (rtx *);
>  extern void arc_pad_return (void);
>  extern void arc_split_move (rtx *);
> -extern int arc_verify_short (rtx_insn *insn, int unalign, int);
>  extern const char *arc_short_long (rtx_insn *insn, const char *, const char 
> *);
>  extern rtx arc_regno_use_in (unsigned int, rtx);
> -extern int arc_attr_type (rtx_insn *);
>  extern bool arc_scheduling_not_expected (void);
>  extern bool arc_sets_cc_p (rtx_insn *insn);
>  extern int arc_label_align (rtx_insn *label);
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index f572d6f4883..74007d8aba3 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -473,8 +473,6 @@ static void arc_function_arg_advance (cumulative_args_t, 
> machine_mode,
> const_tree, bool);
>  static rtx arc_legitimize_address_0 (rtx, rtx, machine_mode mode);
>  
> -static void arc_finalize_pic (void);
> -
>  /* initialize the GCC target structure.  */
>  #undef  TARGET_COMP_TYPE_ATTRIBUTES
>  #define TARGET_COMP_TYPE_ATTRIBUTES arc_comp_type_attributes
> @@ -612,10 +610,6 @@ static void arc_finalize_pic (void);
>  
>  #define TARGET_LEGITIMIZE_ADDRESS arc_legitimize_address
>  
> -#define TARGET_ADJUST_INSN_LENGTH arc_adjust_insn_length
> -
> -#define TARGET_INSN_LENGTH_PARAMETERS arc_insn_length_parameters
> -
>  #undef TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P
>  #define TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P   \
>arc_no_speculation_in_delay_slots_p
> @@ -2131,14 +2125,6 @@ arc_comp_type_attributes (const_tree type1,
>return 1;
>  }
>  
> -/* Set the default attributes for TYPE.  */
> -
> -void
> -arc_set_default_type_attributes (tree type ATTRIBUTE_UNUSED)
> -{
> -  gcc_unreachable();
> -}
> -
>  /* Misc. utilities.  */
>  
>  /* X and Y are two things to compare using CODE.  Emit the compare insn and
> @@ -2368,7 +2354,7 @@ arc_setup_incoming_varargs (cumulative_args_t 
> args_so_far,
>  /* Provide the costs of an addressing mode that contains ADDR.
> If ADDR is not a valid address, its cost is irrelevant.  */
>  
> -int
> +static int
>  arc_address_cost (rtx addr, machine_mode, addr_space_t, bool speed)
>  {
>switch (GET_CODE (addr))
> @@ -2703,10 +2689,6 @@ arc_must_save_register (int regno, struct function 
> *func)
>&& !firq_auto_save_p)
>  return true;
>  
> -  if (flag_pic && crtl->uses_pic_offset_table
> -  && regno == PIC_OFFSET_TABLE_REGNUM)
> -return true;
> -
>return false;
>  }
>  
> @@ -3296,10 +3278,6 @@ arc_expand_prologue (void)
>   emit_insn (gen_stack_tie (stack_pointer_rtx,
> hard_frame_pointer_rtx));
>  }
> -
> -  /* Setup the gp registe

Re: [PATCH] [ARC] Add/update combiner patterns.

2018-04-07 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-03-07 13:59:03 +0200]:

> From: claziss 
> 
> Hi Andrew,
> 
> Please find the following patch which improves generating more instructions 
> with .f flag (i.e., compare with zero).
> 
> Ok to apply?

Looks good.

Thanks.
Andrew


> Claudiu
> 
> gcc/
> 2018-01-26  Claudiu Zissulescu  
> 
>   * config/arc/arc.md (add_shift): New pattern.
>   (add_shift2): Likewise.
>   (sub_shift): Likewise.
>   (sub_shift_cmp0_noout): Likewise.
>   (compare_si_ashiftsi): Likewise.
>   (xbfu_cmp0_noout): New combine pattern.
>   (xbfu_cmp0"): Likewise.
>   (movsi_set_cc_insn): Place the predicable variant first.
>   (commutative_binary_cmp0_noout): Remove clobber.
>   (commutative_binary_cmp0): New pattern.
>   (noncommutative_binary_cmp0): Likewise.
>   (noncommutative_binary_cmp0_noout): Likewise.
>   (noncommutative_binary_comparison_result_used): Removed.
>   (rsub_cmp0): New pattern.
>   (rsub_cmp0_noout): Likewise.
>   (extzvsi): Changed, keep only meaningful variants.
>   (SQH, SEZ): New iterators.
>   (SQH_postfix): New mode attribute.
>   (SEZ_prefix): New code attribute.
>   (xt_cmp0_noout): New instruction pattern.
>   (xt_cmp0): Likewise.
>   * config/arc/predicates.md (cc_set_register): Use CC_REG instead
>   of numerical value.
>   (noncommutative_operator): Check the availability of barrel
>   shifter option.
> ---
>  gcc/config/arc/arc.md| 274 
> ---
>  gcc/config/arc/predicates.md |   6 +-
>  2 files changed, 233 insertions(+), 47 deletions(-)
> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 7633d36b5a6..fb3432964ac 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -810,20 +810,90 @@ archs4x, archs4xd, archs4xd_slow"
>"st%U0 %1,%0\;st%U0.di %1,%0"
>[(set_attr "type" "store")])
>  
> +;; Combiner patterns for compare with zero
> +(define_mode_iterator SQH [QI HI])
> +(define_mode_attr SQH_postfix [(QI "b") (HI "%_")])
> +
> +(define_code_iterator SEZ [sign_extend zero_extend])
> +(define_code_attr SEZ_prefix [(sign_extend "sex") (zero_extend "ext")])
> +
> +(define_insn "*xt_cmp0_noout"
> +  [(set (match_operand 0 "cc_set_register" "")
> + (compare:CC_ZN (SEZ:SI (match_operand:SQH 1 "register_operand" "r"))
> +(const_int 0)))]
> +  ""
> +  ".f\\t0,%1"
> +  [(set_attr "type" "compare")
> +   (set_attr "cond" "set_zn")])
> +
> +(define_insn "*xt_cmp0"
> +  [(set (match_operand 0 "cc_set_register" "")
> + (compare:CC_ZN (SEZ:SI (match_operand:SQH 1 "register_operand" "r"))
> +(const_int 0)))
> +   (set (match_operand:SI 2 "register_operand" "=r")
> + (SEZ:SI (match_dup 1)))]
> +  ""
> +  ".f\\t%2,%1"
> +  [(set_attr "type" "compare")
> +   (set_attr "cond" "set_zn")])
> +
> +(define_insn "*xbfu_cmp0_noout"
> +  [(set (match_operand 0 "cc_set_register" "")
> + (compare:CC_Z
> +  (zero_extract:SI
> +   (match_operand:SI 1 "register_operand"  "  r,r")
> +   (match_operand:SI 2 "const_int_operand" "C3p,n")
> +   (match_operand:SI 3 "const_int_operand" "  n,n"))
> +  (const_int 0)))]
> +  "TARGET_HS && TARGET_BARREL_SHIFTER"
> +  {
> +   int assemble_op2 = (((INTVAL (operands[2]) - 1) & 0x1f) << 5) | (INTVAL 
> (operands[3]) & 0x1f);
> +   operands[2] = GEN_INT (assemble_op2);
> +   return "xbfu%?.f\\t0,%1,%2";
> +  }
> +  [(set_attr "type"   "shift")
> +   (set_attr "iscompact"  "false")
> +   (set_attr "length" "4,8")
> +   (set_attr "predicable" "no")
> +   (set_attr "cond"   "set_zn")])
> +
> +(define_insn "*xbfu_cmp0"
> +  [(set (match_operand 4 "cc_set_register" "")
> + (compare:CC_Z
> +  (zero_extract:SI
> +   (match_operand:SI 1 "register_operand"  "0  ,r,0")
> +   (match_operand:SI 2 "const_int_operand" "C3p,n,n")
> +   (match_operand:SI 3 "const_int_operand" "n  ,n,n"))
> +  (const_int 0)))
> +   (set (match_operand:SI 0 "register_operand"  "=r,r,r")
> + (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
> +  "TARGET_HS && TARGET_BARREL_SHIFTER"
> +  {
> +   int assemble_op2 = (((INTVAL (operands[2]) - 1) & 0x1f) << 5) | (INTVAL 
> (operands[3]) & 0x1f);
> +   operands[2] = GEN_INT (assemble_op2);
> +   return "xbfu%?.f\\t%0,%1,%2";
> +  }
> +  [(set_attr "type"   "shift")
> +   (set_attr "iscompact"  "false")
> +   (set_attr "length" "4,8,8")
> +   (set_attr "predicable" "yes,no,yes")
> +   (set_attr "cond"   "set_zn")])
> +
> +; splitting to 'tst' allows short insns and combination into brcc.
>  (define_insn_and_split "*movsi_set_cc_insn"
> -  [(set (match_operand:CC_ZN 2 "cc_set_register" "")
> - (match_operator:CC_ZN 3 "zn_compare_operator"
> -   [(match_operand:SI 1 "nonmemory_operand" "cI,cL,Cal") (const_int 0)]))
> -   (set (match_operand:SI 0 "register_operand" "=w,w,w")
> +  [(set (match_operand 2 "cc_set_register" "")
> + (m

Re: [PATCH] [ARC]: core3 features are default for core4

2018-09-11 Thread Andrew Burgess
* Vineet Gupta  [2018-09-10 11:26:35 -0700]:

>* config/arc/arc.c: object attributes for core4 not reflected correctly
>* config/arc/arc.h: Don't restrict DBNZ to core3 (core4 includes core3)
> 
> Signed-off-by: Vineet Gupta 
> ---
>  gcc/ChangeLog| 7 +++
>  gcc/config/arc/arc.c | 2 +-
>  gcc/config/arc/arc.h | 2 +-
>  3 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index 6dbe8147b3ec..3a022d156445 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,10 @@
> +2018-09-10  Vineet Gupta 
> +
> + * config/arc/arc.c: object attributes for core4 not reflected
> + correctly
> + * config/arc/arc.h: Don't restrict DBNZ to core3 (core4 includes
> + core3)

These entries should be formatted as sentences with capital letter and
full stop.

> +
>  2018-09-09  Uros Bizjak  
>  
>   * config/i386/i386.md (float partial SSE register stall splitter): Move
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index c186e02e0f18..0171e8a7c615 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -5181,7 +5181,7 @@ static void arc_file_start (void)
>  TARGET_OPTFPE ? 1 : 0);
>if (TARGET_V2)
>  asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_CPU_variation, 
> %d\n",
> -  arc_tune == ARC_TUNE_CORE_3 ? 3 : 2);
> +  arc_tune < ARC_TUNE_CORE_3 ? 2 : (arc_tune == ARC_TUNE_CORE_3 
> ? 3 : 4) );
>  }
>  
>  /* Implement `TARGET_ASM_FILE_END'.  */
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index de09b6b2f09e..4d38f9ec174f 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -1636,6 +1636,6 @@ enum
>  #define TARGET_FPX_QUARK(TARGET_EM && TARGET_SPFP\
>&& (arc_fpu_build == FPX_QK))
>  /* DBNZ support is available for ARCv2 core3 cpus.  */
> -#define TARGET_DBNZ (TARGET_V2 && (arc_tune == ARC_TUNE_CORE_3))
> +#define TARGET_DBNZ (TARGET_V2 && (arc_tune >= ARC_TUNE_CORE_3))

Could you update the comment too please.

Otherwise, looks fine.

Thanks,
Andrew

>  
>  #endif /* GCC_ARC_H */
> -- 
> 2.7.4
> 


Re: [PATCH 1/2] [ARC] Check for odd-even register when emitting double mac ops.

2018-09-20 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-09-17 15:50:26 +0300]:

> Avoid generate dmac instructions when the register is not odd-even,
> use instead the equivalent mac instruction.
> 
> gcc/
>   Claudiu Zissulescu  
> 
>   * config/arc/arc.md (maddsidi4_split): Don't use dmac if the
>   destination register is not odd-even.
>   (umaddsidi4_split): Likewise.
> 
> gcc/testsuite/
>   Claudiu Zissulescu  
> 
>   * gcc.target/arc/tmac-3.c: New file.

Looks good thanks, with one minor nit below...

> ---
>  gcc/config/arc/arc.md |  4 ++--
>  gcc/testsuite/gcc.target/arc/tmac-3.c | 17 +
>  2 files changed, 19 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/tmac-3.c
> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index dbcd7098bec..2d108ef166d 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -6078,7 +6078,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
>"{
> rtx acc_reg = gen_rtx_REG (DImode, ACC_REG_FIRST);
> emit_move_insn (acc_reg, operands[3]);
> -   if (TARGET_PLUS_MACD)
> +   if (TARGET_PLUS_MACD && even_register_operand (operands[0], DImode))
>   emit_insn (gen_macd (operands[0], operands[1], operands[2]));
> else
>   {
> @@ -6178,7 +6178,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
>"{
> rtx acc_reg = gen_rtx_REG (DImode, ACC_REG_FIRST);
> emit_move_insn (acc_reg, operands[3]);
> -   if (TARGET_PLUS_MACD)
> +   if (TARGET_PLUS_MACD && even_register_operand (operands[0], DImode))
>   emit_insn (gen_macdu (operands[0], operands[1], operands[2]));
> else
>   {
> diff --git a/gcc/testsuite/gcc.target/arc/tmac-3.c 
> b/gcc/testsuite/gcc.target/arc/tmac-3.c
> new file mode 100644
> index 000..3c8c1201f83
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/tmac-3.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-skip-if "" { ! { clmcpu } } } */
> +/* { dg-options "-mcpu=hs38 -Os" } */
> +
> +/* The compiler will assign r1r2 as a DI register, but it doesn't fit
> +   the macd operation, hence we need to fall back on the mac
> +   instruction.  */
> +typedef long long myint64_t;
> +
> +extern int d (int, myint64_t);
> +int b (int c)
> +{
> +  int x = (int) d;
> +  d(c, (myint64_t)x * 2 + 1);

Could you apply GNU coding standard whitespace on this line please.

Thanks,
Andrew

> +}
> +
> +/* { dg-final { scan-assembler "mac\\\s+r1" } } */
> -- 
> 2.17.1
> 


Re: [PATCH 2/2] [ARC] Avoid specific constants to end in limm field.

2018-09-20 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-09-17 15:50:27 +0300]:

> The 3-operand instructions accepts to place an immediate into the
> second operand. However, this immediate will end up in the long
> immediate field. This patch avoids constants to end up in the limm
> field for particular instructions when compiling for size.
> 
> gcc/
> -xx-xx  Claudiu Zissulescu  
> 
>   * config/arc/arc.md (*add_n): Clean up pattern, update instruction
>   constraints.
>   (ashlsi3_insn): Update instruction constraints.
>   (ashrsi3_insn): Likewise.
>   (rotrsi3): Likewise.
>   (add_shift): Likewise.
>   * config/arc/constraints.md (Csz): New 32 bit constraint. It
>   avoids placing in the limm field small constants which, otherwise,
>   could end into a small instruction.
> ---
>  gcc/config/arc/arc.md   | 51 +---
>  gcc/config/arc/constraints.md   |  6 +++
>  gcc/testsuite/gcc.target/arc/tph_addx.c | 53 +
>  3 files changed, 78 insertions(+), 32 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/tph_addx.c

Looks good.

Thanks,
Andrew


> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 2d108ef166d..c28a87cd3b0 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -3056,30 +3056,17 @@ core_3, archs4x, archs4xd, archs4xd_slow"
> (set (match_dup 3) (match_dup 4))])
>  
>  (define_insn "*add_n"
> -  [(set (match_operand:SI 0 "dest_reg_operand" "=Rcqq,Rcw,W,W,w,w")
> - (plus:SI (ashift:SI (match_operand:SI 1 "register_operand" 
> "Rcqq,c,c,c,c,c")
> - (match_operand:SI 2 "_1_2_3_operand" ""))
> -  (match_operand:SI 3 "nonmemory_operand" 
> "0,0,c,?Cal,?c,??Cal")))]
> +  [(set (match_operand:SI 0 "dest_reg_operand" "=q,r,r")
> + (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "q,r,r")
> +   (match_operand:SI 2 "_2_4_8_operand" ""))
> +  (match_operand:SI 3 "nonmemory_operand" "0,r,Csz")))]
>""
> -  "add%c2%? %0,%3,%1%&"
> +  "add%z2%?\\t%0,%3,%1%&"
>[(set_attr "type" "shift")
> -   (set_attr "length" "*,4,4,8,4,8")
> -   (set_attr "predicable" "yes,yes,no,no,no,no")
> -   (set_attr "cond" "canuse,canuse,nocond,nocond,nocond,nocond")
> -   (set_attr "iscompact" "maybe,false,false,false,false,false")])
> -
> -(define_insn "*add_n"
> -  [(set (match_operand:SI 0 "dest_reg_operand"  
> "=Rcqq,Rcw,W,  W,w,w")
> - (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "Rcqq,  c,c,  
> c,c,c")
> -   (match_operand:SI 2 "_2_4_8_operand"   ""))
> -  (match_operand:SI 3 "nonmemory_operand""0,  
> 0,c,Cal,c,Cal")))]
> -  ""
> -  "add%z2%? %0,%3,%1%&"
> -  [(set_attr "type" "shift")
> -   (set_attr "length" "*,4,4,8,4,8")
> -   (set_attr "predicable" "yes,yes,no,no,no,no")
> -   (set_attr "cond" "canuse,canuse,nocond,nocond,nocond,nocond")
> -   (set_attr "iscompact" "maybe,false,false,false,false,false")])
> +   (set_attr "length" "*,4,8")
> +   (set_attr "predicable" "yes,no,no")
> +   (set_attr "cond" "canuse,nocond,nocond")
> +   (set_attr "iscompact" "maybe,false,false")])
>  
>  ;; N.B. sub[123] has the operands of the MINUS in the opposite order from
>  ;; what synth_mult likes.
> @@ -3496,7 +3483,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
>  ; provide one alternatice for this, without condexec support.
>  (define_insn "*ashlsi3_insn"
>[(set (match_operand:SI 0 "dest_reg_operand"   
> "=Rcq,Rcqq,Rcqq,Rcw, w,   w")
> - (ashift:SI (match_operand:SI 1 "nonmemory_operand" "!0,Rcqq,   0,  0, 
> c,cCal")
> + (ashift:SI (match_operand:SI 1 "nonmemory_operand" "!0,Rcqq,   0,  0, 
> c,cCsz")
>  (match_operand:SI 2 "nonmemory_operand"  "K,  K,RcqqM, 
> cL,cL,cCal")))]
>"TARGET_BARREL_SHIFTER
> && (register_operand (operands[1], SImode)
> @@ -3509,7 +3496,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
>  
>  (define_insn "*ashrsi3_insn"
>[(set (match_operand:SI 0 "dest_reg_operand" 
> "=Rcq,Rcqq,Rcqq,Rcw, w,   w")
> - (ashiftrt:SI (match_operand:SI 1 "nonmemory_operand" "!0,Rcqq,   0,  0, 
> c,cCal")
> + (ashiftrt:SI (match_operand:SI 1 "nonmemory_operand" "!0,Rcqq,   0,  0, 
> c,cCsz")
>(match_operand:SI 2 "nonmemory_operand"  "K,  K,RcqqM, 
> cL,cL,cCal")))]
>"TARGET_BARREL_SHIFTER
> && (register_operand (operands[1], SImode)
> @@ -3536,7 +3523,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
>  
>  (define_insn "rotrsi3"
>[(set (match_operand:SI 0 "dest_reg_operand" "=Rcw, w,   w")
> - (rotatert:SI (match_operand:SI 1 "register_operand"  " 0,cL,cCal")
> + (rotatert:SI (match_operand:SI 1 "register_operand"  " 0,cL,cCsz")
>(match_operand:SI 2 "nonmemory_operand" "cL,cL,cCal")))]
>"TARGET_BARREL_SHIFTER"
>"ror%? %0,%1,%2"
> @@ -4284,16 +4271,16 @@ core_3, archs4x, archs4xd, archs4xd_sl

Re: [PATCH 2/6] [ARC] Cleanup TLS implementation.

2018-10-11 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-10-10 11:00:12 +0300]:

> Cleanup TLS implementation and add a number of tests.
> 
> gcc/
> 2018-07-25  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_get_tp): Remove function.
>   (arc_emit_call_tls_get_addr): Likewise.
>   (arc_call_tls_get_addr): New function.
>   (arc_legitimize_tls_address): Make use of arc_call_tls_get_addr.
>   * config/arc/arc.md (tls_load_tp_soft): Remove.
>   (tls_gd_get_addr): Likewise.
> 
> testsuite/
> 2018-07-25  Claudiu Zissulescu  
> 
>   * gcc.target/arc/tls-gd.c: New file.
>   * gcc.target/arc/tls-ie.c: Likewise.
>   * gcc.target/arc/tls-ld.c: Likewise.
>   * gcc.target/arc/tls-le.c: Likewise.
> ---
>  gcc/config/arc/arc.c  | 95 +++
>  gcc/config/arc/arc.md | 21 --
>  gcc/testsuite/gcc.target/arc/tls-1.c  |  2 +-
>  gcc/testsuite/gcc.target/arc/tls-gd.c | 17 +
>  gcc/testsuite/gcc.target/arc/tls-ie.c | 17 +
>  gcc/testsuite/gcc.target/arc/tls-ld.c | 18 +
>  gcc/testsuite/gcc.target/arc/tls-le.c | 16 +
>  7 files changed, 106 insertions(+), 80 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/tls-gd.c
>  create mode 100644 gcc/testsuite/gcc.target/arc/tls-ie.c
>  create mode 100644 gcc/testsuite/gcc.target/arc/tls-ld.c
>  create mode 100644 gcc/testsuite/gcc.target/arc/tls-le.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index de4c7433c1b..56f566795ff 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -5559,51 +5559,30 @@ arc_raw_symbolic_reference_mentioned_p (rtx op, bool 
> skip_local)
>return false;
>  }
>  
> -/* Get the thread pointer.  */
> +/* Emit a call to __tls_get_addr.  TI is the argument to this function.
> +   RET is an RTX for the return value location.  The entire insn sequence
> +   is returned.  */

This comment should be moved down to arc_call_tls_get_addr, and a new
comment should be added explaining what arc_tls_symbol is used for.

Otherwise, this seems fine.

Thanks,
Andrew

> +static GTY(()) rtx arc_tls_symbol;
>  
>  static rtx
> -arc_get_tp (void)
> +arc_call_tls_get_addr (rtx ti)
>  {
> -   /* If arc_tp_regno has been set, we can use that hard register
> -  directly as a base register.  */
> -  if (arc_tp_regno != -1)
> -return gen_rtx_REG (Pmode, arc_tp_regno);
> -
> -  /* Otherwise, call __read_tp.  Copy the result to a pseudo to avoid
> - conflicts with function arguments / results.  */
> -  rtx reg = gen_reg_rtx (Pmode);
> -  emit_insn (gen_tls_load_tp_soft ());
> -  emit_move_insn (reg, gen_rtx_REG (Pmode, R0_REG));
> -  return reg;
> -}
> -
> -/* Helper to be used by TLS Global dynamic model.  */
> -
> -static rtx
> -arc_emit_call_tls_get_addr (rtx sym, int reloc, rtx eqv)
> -{
> -  rtx r0 = gen_rtx_REG (Pmode, R0_REG);
> -  rtx call_fusage = NULL_RTX;
> -
> -  start_sequence ();
> -
> -  rtx x = arc_unspec_offset (sym, reloc);
> -  emit_move_insn (r0, x);
> -  use_reg (&call_fusage, r0);
> +  rtx arg = gen_rtx_REG (Pmode, R0_REG);
> +  rtx ret = gen_rtx_REG (Pmode, R0_REG);
> +  rtx fn;
> +  rtx_insn *insn;
>  
> -  gcc_assert (reloc == UNSPEC_TLS_GD);
> -  rtx call_insn = emit_call_insn (gen_tls_gd_get_addr (sym));
> -  /* Should we set RTL_CONST_CALL_P?  We read memory, but not in a
> - way that the application should care.  */
> -  RTL_PURE_CALL_P (call_insn) = 1;
> -  add_function_usage_to (call_insn, call_fusage);
> +  if (!arc_tls_symbol)
> +arc_tls_symbol = init_one_libfunc ("__tls_get_addr");
>  
> -  rtx_insn *insns = get_insns ();
> -  end_sequence ();
> +  emit_move_insn (arg, ti);
> +  fn = gen_rtx_MEM (SImode, arc_tls_symbol);
> +  insn = emit_call_insn (gen_call_value (ret, fn, const0_rtx));
> +  RTL_CONST_CALL_P (insn) = 1;
> +  use_reg (&CALL_INSN_FUNCTION_USAGE (insn), ret);
> +  use_reg (&CALL_INSN_FUNCTION_USAGE (insn), arg);
>  
> -  rtx dest = gen_reg_rtx (Pmode);
> -  emit_libcall_block (insns, dest, r0, eqv);
> -  return dest;
> +  return ret;
>  }
>  
>  #define DTPOFF_ZERO_SYM ".tdata"
> @@ -5614,16 +5593,26 @@ arc_emit_call_tls_get_addr (rtx sym, int reloc, rtx 
> eqv)
>  static rtx
>  arc_legitimize_tls_address (rtx addr, enum tls_model model)
>  {
> +  rtx tmp;
> +
>if (!flag_pic && model == TLS_MODEL_LOCAL_DYNAMIC)
>  model = TLS_MODEL_LOCAL_EXEC;
>  
> +
> +  /* The TP pointer needs to be set.  */
> +  gcc_assert (arc_tp_regno != -1);
> +
>switch (model)
>  {
> +case TLS_MODEL_GLOBAL_DYNAMIC:
> +  tmp = gen_reg_rtx (Pmode);
> +  emit_move_insn (tmp, arc_unspec_offset (addr, UNSPEC_TLS_GD));
> +  return arc_call_tls_get_addr (tmp);
> +
>  case TLS_MODEL_LOCAL_DYNAMIC:
>rtx base;
>tree decl;
>const char *base_name;
> -  rtvec v;
>  
>decl = SYMBOL_REF_DECL (addr);
>base_name = DTPOFF_ZERO_SYM;
> @@ -5631,31 +5620,21 @@ arc_legitimize_tls_address (rtx addr, enum tls_model 
> model)
>   base_name = ".tbss";
>

Re: [PATCH 1/6] [ARC] Remove non standard funcions calls.

2018-10-11 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-10-10 11:00:11 +0300]:

> Replace all custom "library" calls with compiler known patterns.
> 
> gcc/
> -xx-xx  Claudiu Zissulescu  
> 
>   * config/arc/arc.md (mulsi3): Remove call to mulsi_600_lib.
>   (mulsi3_600_lib): Remove pattern.
>   (umulsi3_highpart_600_lib_le): Likewise.
>   (umulsi3_highpart): Remove call to umulsi3_highpart_600_lib_le.
>   (umulsidi3): Remove call to umulsidi3_600_lib.
>   (umulsidi3_600_lib): Remove pattern.
>   (peephole2): Remove peephole using the above deprecated patterns.
> 
> testsuite/
> -xx-xx  Claudiu Zissulescu  
> 
>   * gcc.target/arc/mulsi3_highpart-2.c: Update test.
> 
> libgcc/
> -xx-xx  Claudiu Zissulescu  
> 
>   * config/arc/lib1funcs.S (_muldi3): New function.
>   * config/arc/t-arc (LIB1ASMFUNCS): Add _muldi3.

This seems fine.

Thanks,
Andrew

> ---
>  gcc/config/arc/arc.md | 158 ++
>  .../gcc.target/arc/mulsi3_highpart-2.c|   5 +-
>  libgcc/config/arc/lib1funcs.S |  54 ++
>  libgcc/config/arc/t-arc   |   2 +-
>  4 files changed, 67 insertions(+), 152 deletions(-)
> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 42ca820b91d..d73289a20c4 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -2076,44 +2076,21 @@ archs4x, archs4xd, archs4xd_slow"
>  ;; SI <- SI * SI
>  
>  (define_expand "mulsi3"
> - [(set (match_operand:SI 0 "nonimmediate_operand""")
> + [(set (match_operand:SI 0 "register_operand""")
>   (mult:SI (match_operand:SI 1 "register_operand"  "")
>(match_operand:SI 2 "nonmemory_operand" "")))]
> -  ""
> +  "TARGET_ANY_MPY"
>  {
> -  if (TARGET_MPY)
> -{
> -  if (!register_operand (operands[0], SImode))
> - {
> -   rtx result = gen_reg_rtx (SImode);
> -
> -   emit_insn (gen_mulsi3 (result, operands[1], operands[2]));
> -   emit_move_insn (operands[0], result);
> -   DONE;
> - }
> -}
> -  else if (TARGET_MUL64_SET)
> +  if (TARGET_MUL64_SET)
>  {
> - rtx tmp = gen_reg_rtx (SImode);
> - emit_insn (gen_mulsi64 (tmp, operands[1], operands[2]));
> - emit_move_insn (operands[0], tmp);
> + emit_insn (gen_mulsi64 (operands[0], operands[1], operands[2]));
>   DONE;
>  }
>else if (TARGET_MULMAC_32BY16_SET)
>  {
> - rtx tmp = gen_reg_rtx (SImode);
> - emit_insn (gen_mulsi32x16 (tmp, operands[1], operands[2]));
> - emit_move_insn (operands[0], tmp);
> + emit_insn (gen_mulsi32x16 (operands[0], operands[1], operands[2]));
>   DONE;
>  }
> -  else
> -{
> -  emit_move_insn (gen_rtx_REG (SImode, R0_REG), operands[1]);
> -  emit_move_insn (gen_rtx_REG (SImode, R1_REG), operands[2]);
> -  emit_insn (gen_mulsi3_600_lib ());
> -  emit_move_insn (operands[0], gen_rtx_REG (SImode, R0_REG));
> -  DONE;
> -}
>  })
>  
>  (define_insn_and_split "mulsi32x16"
> @@ -2229,27 +2206,6 @@ archs4x, archs4xd, archs4xd_slow"
> (set_attr "predicable" "yes,yes,no,yes")
> (set_attr "cond" "canuse,canuse,canuse_limm,canuse")])
>  
> -; If we compile without an mul option enabled, but link with libraries
> -; for a mul option, we'll see clobbers of multiplier output registers.
> -; There is also an implementation using norm that clobbers the loop 
> registers.
> -(define_insn "mulsi3_600_lib"
> -  [(set (reg:SI R0_REG)
> - (mult:SI (reg:SI R0_REG) (reg:SI R1_REG)))
> -   (clobber (reg:SI RETURN_ADDR_REGNUM))
> -   (clobber (reg:SI R1_REG))
> -   (clobber (reg:SI R2_REG))
> -   (clobber (reg:SI R3_REG))
> -   (clobber (reg:DI MUL64_OUT_REG))
> -   (clobber (reg:SI LP_COUNT))
> -   (clobber (reg:SI LP_START))
> -   (clobber (reg:SI LP_END))
> -   (clobber (reg:CC CC_REG))]
> -  "!TARGET_ANY_MPY
> -   && SFUNC_CHECK_PREDICABLE"
> -  "*return arc_output_libcall (\"__mulsi3\");"
> -  [(set_attr "is_sfunc" "yes")
> -   (set_attr "predicable" "yes")])
> -
>  (define_insn_and_split "mulsidi_600"
>[(set (match_operand:DI 0 "register_operand"   
> "=c, c,c,  c")
>   (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand"  
> "%Rcq#q, c,c,  c"))
> @@ -2504,48 +2460,6 @@ archs4x, archs4xd, archs4xd_slow"
> (set_attr "predicable" "yes,no,yes,no")
> (set_attr "cond" "canuse,nocond,canuse,nocond")])
>  
> -; Implementations include additional labels for umulsidi3, so we got all
> -; the same clobbers - plus one for the result low part.  */
> -(define_insn "umulsi3_highpart_600_lib_le"
> -  [(set (reg:SI R1_REG)
> - (truncate:SI
> -  (lshiftrt:DI
> -   (mult:DI (zero_extend:DI (reg:SI R0_REG))
> -(zero_extend:DI (reg:SI R1_REG)))
> -   (const_int 32
> -   (clobber (reg:SI RETURN_ADDR_REGNUM))
> -   (clobber (reg:SI R0_REG))
> -   (clobber (reg:DI R2_REG))
> -   (clobber (reg:SI R12_REG))
> -   (clobber (reg:DI MUL64_OUT_REG))
> -   (clo

Re: [PATCH 1/5] [ARC] Update sleep builtin.

2018-04-18 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-04-06 11:00:10 
+0200]:

> From: claziss 
> 
> gcc/
> 2017-05-09  Claudiu Zissulescu  
> 
>   * config/arc/arc-protos.h (check_if_valid_sleep_operand): Remove.
>   * config/arc/arc.c (arc_expand_builtin): Sleep accepts registers
>   and short u6 immediate.
>   (check_if_valid_sleep_operand): Remove.
>   * config/arc/arc.md (Sleep): Accepts registers and u6 immediates.
> ---
>  gcc/config/arc/arc-protos.h |  1 -
>  gcc/config/arc/arc.c| 26 --
>  gcc/config/arc/arc.md   |  4 ++--
>  3 files changed, 2 insertions(+), 29 deletions(-)

Looks good.

Thanks,
Andrew

> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index 75cfeda..0ba6871 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -59,7 +59,6 @@ void arc_asm_output_aligned_decl_local (FILE *, tree, const 
> char *,
>   unsigned HOST_WIDE_INT);
>  extern rtx arc_return_addr_rtx (int , rtx);
>  extern bool check_if_valid_regno_const (rtx *, int);
> -extern bool check_if_valid_sleep_operand (rtx *, int);
>  extern bool arc_legitimate_constant_p (machine_mode, rtx);
>  extern bool arc_legitimate_pic_addr_p (rtx);
>  extern bool arc_raw_symbolic_reference_mentioned_p (rtx, bool);
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 3564696..47d3ba4 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -6573,11 +6573,6 @@ arc_expand_builtin (tree exp,
>fold (arg0);
>op0 = expand_expr (arg0, NULL_RTX, VOIDmode, EXPAND_NORMAL);
>  
> -  if  (!CONST_INT_P (op0) || !satisfies_constraint_L (op0))
> - {
> -   error ("builtin operand should be an unsigned 6-bit value");
> -   return NULL_RTX;
> - }
>gcc_assert (icode != 0);
>emit_insn (GEN_FCN (icode) (op0));
>return NULL_RTX;
> @@ -6925,27 +6920,6 @@ check_if_valid_regno_const (rtx *operands, int opno)
>return false;
>  }
>  
> -/* Check that after all the constant folding, whether the operand to
> -   __builtin_arc_sleep is an unsigned int of 6 bits.  If not, flag an error. 
>  */
> -
> -bool
> -check_if_valid_sleep_operand (rtx *operands, int opno)
> -{
> -  switch (GET_CODE (operands[opno]))
> -{
> -case CONST :
> -case CONST_INT :
> - if( UNSIGNED_INT6 (INTVAL (operands[opno])))
> - return true;
> -/* FALLTHRU */
> -default:
> - fatal_error (input_location,
> -  "operand for sleep instruction must be an unsigned 6 bit 
> compile-time constant");
> - break;
> -}
> -  return false;
> -}
> -
>  /* Return true if it is ok to make a tail-call to DECL.  */
>  
>  static bool
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index fb34329..2ec2b48 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -4794,9 +4794,9 @@ archs4x, archs4xd, archs4xd_slow"
>  
>  
>  (define_insn "sleep"
> -  [(unspec_volatile [(match_operand:SI 0 "immediate_operand" "L")]
> +  [(unspec_volatile [(match_operand:SI 0 "nonmemory_operand" "Lr")]
>  VUNSPEC_ARC_SLEEP)]
> -  "check_if_valid_sleep_operand(operands,0)"
> +  ""
>"sleep %0"
>[(set_attr "length" "4")
>(set_attr "type" "misc")])
> -- 
> 1.9.1
> 


Re: [PATCH 2/5] [ARC] Fix FLS, SETI patterns.

2018-04-18 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-04-06 11:00:11 
+0200]:

> From: claziss 
> 
> Claudiu Zissulescu  
> 
>   * config/arc/arc.md ("vunspec"): Delete it, unify all the unspec
>   enums into a single definition.
>   (fls): Fix predicates and printing.
>   (seti): Likewise.

Looks good,

Thanks,
Andrew

> ---
>  gcc/config/arc/arc.md | 14 +-
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index 2ec2b48..ffd9d5b 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -137,9 +137,7 @@
>UNSPEC_ARC_VMPY2H
>UNSPEC_ARC_VMPY2HU
>UNSPEC_ARC_STKTIE
> -  ])
>  
> -(define_c_enum "vunspec" [
>VUNSPEC_ARC_RTIE
>VUNSPEC_ARC_SYNC
>VUNSPEC_ARC_BRK
> @@ -5818,21 +5816,19 @@ archs4x, archs4xd, archs4xd_slow"
> })
>  
>  (define_insn "fls"
> -  [(set (match_operand:SI  0 "dest_reg_operand" "=w,w")
> - (unspec:SI [(match_operand:SI 1 "general_operand" "cL,Cal")]
> +  [(set (match_operand:SI  0 "register_operand" "=r,r")
> + (unspec:SI [(match_operand:SI 1 "nonmemory_operand" "rL,Cal")]
>   UNSPEC_ARC_FLS))]
>"TARGET_NORM && TARGET_V2"
> -  "@
> -   fls \t%0, %1
> -   fls \t%0, %1"
> +  "fls\\t%0,%1"
>[(set_attr "length" "4,8")
> (set_attr "type" "two_cycle_core,two_cycle_core")])
>  
>  (define_insn "seti"
> -  [(unspec_volatile:SI [(match_operand:SI 0 "general_operand" "rL")]
> +  [(unspec_volatile:SI [(match_operand:SI 0 "nonmemory_operand" "rL")]
>  VUNSPEC_ARC_SETI)]
>"TARGET_V2"
> -  "seti  %0"
> +  "seti\\t%0"
>[(set_attr "length" "4")
> (set_attr "type" "misc")])
>  
> -- 
> 1.9.1
> 


Re: [PATCH 3/5] [ARC] Update movhi and movdi patterns.

2018-04-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-04-06 11:00:12 
+0200]:

> From: Claudiu Zissulescu 
> 
> Allow signed 6-bit short immediates into st[d] instructions.
> 
> 2017-10-19  Claudiu Zissulescu  
> 
>   * config/arc/arc.c (arc_split_move): Allow signed 6-bit constants
>   as source of std instructions.
>   * config/arc/arc.md (movsi_insn): Update pattern predicate to
>   allow 6-bit constants as source for store instructions.
>   (movdi_insn): Update instruction pattern to allow 6-bit constants
>   as source for store instructions.
> 
> testsuite/
> 2017-10-19  Claudiu Zissulescu  
> 
>   * gcc.target/arc/store-merge-1.c: New test.
>   * gcc.target/arc/add_n-combine.c: Update test.

Looks good thanks,

Andrew


> ---
>  gcc/config/arc/arc.c |  3 ++-
>  gcc/config/arc/arc.md| 25 +
>  gcc/testsuite/gcc.target/arc/add_n-combine.c |  2 +-
>  gcc/testsuite/gcc.target/arc/store-merge-1.c | 17 +
>  4 files changed, 33 insertions(+), 14 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/store-merge-1.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 47d3ba4..2ccdce8 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -9669,7 +9669,8 @@ arc_split_move (rtx *operands)
>  
>if (TARGET_LL64
>&& ((memory_operand (operands[0], mode)
> -&& even_register_operand (operands[1], mode))
> +&& (even_register_operand (operands[1], mode)
> +|| satisfies_constraint_Cm3 (operands[1])))
> || (memory_operand (operands[1], mode)
> && even_register_operand (operands[0], mode
>  {
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index ffd9d5b..0fc7aba 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -740,7 +740,9 @@ archs4x, archs4xd, archs4xd_slow"
> /* Don't use a LIMM that we could load with a single insn - we loose
> delay-slot filling opportunities.  */
> && !satisfies_constraint_I (operands[1])
> -   && satisfies_constraint_Usc (operands[0]))"
> +   && satisfies_constraint_Usc (operands[0]))
> +   || (satisfies_constraint_Cm3 (operands[1])
> +  && memory_operand (operands[0], SImode))"
>"@
> mov%? %0,%1%& ;0
> mov%? %0,%1%& ;1
> @@ -1237,10 +1239,12 @@ archs4x, archs4xd, archs4xd_slow"
>")
>  
>  (define_insn_and_split "*movdi_insn"
> -  [(set (match_operand:DI 0 "move_dest_operand"  "=w, w,r,m")
> - (match_operand:DI 1 "move_double_src_operand" "c,Hi,m,c"))]
> +  [(set (match_operand:DI 0 "move_dest_operand"  "=w, w,r,   m")
> + (match_operand:DI 1 "move_double_src_operand" "c,Hi,m,cCm3"))]
>"register_operand (operands[0], DImode)
> -   || register_operand (operands[1], DImode)"
> +   || register_operand (operands[1], DImode)
> +   || (satisfies_constraint_Cm3 (operands[1])
> +  && memory_operand (operands[0], DImode))"
>"*
>  {
>switch (which_alternative)
> @@ -1250,19 +1254,16 @@ archs4x, archs4xd, archs4xd_slow"
>  
>  case 2:
>  if (TARGET_LL64
> - && ((even_register_operand (operands[0], DImode)
> -  && memory_operand (operands[1], DImode))
> - || (memory_operand (operands[0], DImode)
> - && even_register_operand (operands[1], DImode
> +&& memory_operand (operands[1], DImode)
> + && even_register_operand (operands[0], DImode))
>return \"ldd%U1%V1 %0,%1%&\";
>  return \"#\";
>  
>  case 3:
>  if (TARGET_LL64
> - && ((even_register_operand (operands[0], DImode)
> -  && memory_operand (operands[1], DImode))
> - || (memory_operand (operands[0], DImode)
> - && even_register_operand (operands[1], DImode
> + && memory_operand (operands[0], DImode)
> + && (even_register_operand (operands[1], DImode)
> + || satisfies_constraint_Cm3 (operands[1])))
>   return \"std%U0%V0 %1,%0\";
>  return \"#\";
>  }
> diff --git a/gcc/testsuite/gcc.target/arc/add_n-combine.c 
> b/gcc/testsuite/gcc.target/arc/add_n-combine.c
> index db6454f..cd32ed3 100644
> --- a/gcc/testsuite/gcc.target/arc/add_n-combine.c
> +++ b/gcc/testsuite/gcc.target/arc/add_n-combine.c
> @@ -45,4 +45,4 @@ void f() {
>a(at3.bn[bu]);
>  }
>  
> -/* { dg-final { scan-rtl-dump-times "\\*add_n" 3 "combine" } } */
> +/* { dg-final { scan-rtl-dump-times "\\*add_n" 2 "combine" } } */
> diff --git a/gcc/testsuite/gcc.target/arc/store-merge-1.c 
> b/gcc/testsuite/gcc.target/arc/store-merge-1.c
> new file mode 100644
> index 000..4bb8dcb
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/store-merge-1.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3" } */
> +
> +/* This tests checks if we use st w6,[reg] format.  */
> +
> +typedef struct {
> +  unsigned long __val[2];
> +} sigset_t;
> +
> +int sigemptyset2 (sigset_t *set)
> +{
> +  set->__val[0] = 0;
> +  set->__v

Re: [PATCH 4/5] [ARC] Cleanup sdata handling.

2018-04-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-04-06 11:00:13 
+0200]:

> From: Claudiu Zissulescu 
> 
> Clean up how we handle small data load/store operations. This patch clears 
> -flto-fat-lto-object LTO related errors.
> 
> gcc/
> 2018-01-18  Claudiu Zissulescu  
> 
>   * config/arc/arc-protos.h (prepare_extend_operands): Remove.
>   (small_data_pattern): Likewise.
>   (arc_rewrite_small_data): Likewise.
>   * config/arc/arc.c (LEGITIMATE_SMALL_DATA_OFFSET_P): Remove.
>   (LEGITIMATE_SMALL_DATA_ADDRESS_P): Likewise.
>   (get_symbol_alignment): New function.
>   (legitimate_small_data_address_p): Likewise.
>   (legitimate_scaled_address): Update, call
>   legitimate_small_data_address_p.
>   (output_sdata): New static variable.
>   (arc_print_operand): Update how we handle small data operands.
>   (arc_print_operand_address): Likewise.
>   (arc_legitimate_address_p): Update, use
>   legitimate_small_data_address_p.
>   (arc_rewrite_small_data_p): Remove.
>   (arc_rewrite_small_data_1): Likewise.
>   (arc_rewrite_small_data): Likewise.
>   (small_data_pattern): Likewise.
>   (compact_sda_memory_operand): Update to use
>   legitimate_small_data_address_p and get_symbol_alignment.
>   (prepare_move_operands): Don't rewite sdata pattern.
>   (prepare_extend_operands): Remove.
>   * config/arc/arc.md (zero_extendqihi2): Don't rewrite sdata
>   pattern.
>   (zero_extendqisi2): Likewise.
>   (zero_extendhisi2): Likewise.
>   (extendqihi2): Likewise.
>   (extendqisi2): Likewise.
>   (extendhisi2): Likewise.
>   (addsi3): Likewise.
>   (subsi3): Likewise.
>   (andsi3): Likewise.
>   * config/arc/constraints.md (Usd): Change it to memory constraint.
> 
> gcc/testsuite
> 2018-01-18  Claudiu Zissulescu  
> 
>   * gcc.target/arc/interrupt-8.c: Update test.
>   * gcc.target/arc/loop-4.c: Likewise.
>   * gcc.target/arc/loop-hazard-1.c: Likewise.
>   * gcc.target/arc/sdata-3.c: Likewise.

Looks like a good clean up.

Thanks,
Andrew

> ---
>  gcc/config/arc/arc-protos.h  |   4 -
>  gcc/config/arc/arc.c | 309 
> ---
>  gcc/config/arc/arc.md|  22 +-
>  gcc/config/arc/constraints.md|   6 +-
>  gcc/testsuite/gcc.target/arc/interrupt-8.c   |   5 +-
>  gcc/testsuite/gcc.target/arc/loop-4.c|   2 +-
>  gcc/testsuite/gcc.target/arc/loop-hazard-1.c |   2 +-
>  gcc/testsuite/gcc.target/arc/sdata-3.c   |   8 +-
>  8 files changed, 110 insertions(+), 248 deletions(-)
> 
> diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
> index 0ba6871..67f3b4e 100644
> --- a/gcc/config/arc/arc-protos.h
> +++ b/gcc/config/arc/arc-protos.h
> @@ -33,8 +33,6 @@ extern void arc_print_operand (FILE *, rtx, int);
>  extern void arc_print_operand_address (FILE *, rtx);
>  extern void arc_final_prescan_insn (rtx_insn *, rtx *, int);
>  extern const char *arc_output_libcall (const char *);
> -extern bool prepare_extend_operands (rtx *operands, enum rtx_code code,
> -  machine_mode omode);
>  extern int arc_output_addsi (rtx *operands, bool, bool);
>  extern int arc_output_commutative_cond_exec (rtx *operands, bool);
>  extern bool arc_expand_movmem (rtx *operands);
> @@ -65,8 +63,6 @@ extern bool arc_raw_symbolic_reference_mentioned_p (rtx, 
> bool);
>  extern bool arc_is_longcall_p (rtx);
>  extern bool arc_is_shortcall_p (rtx);
>  extern bool valid_brcc_with_delay_p (rtx *);
> -extern bool small_data_pattern (rtx , machine_mode);
> -extern rtx arc_rewrite_small_data (rtx);
>  extern bool arc_ccfsm_cond_exec_p (void);
>  struct secondary_reload_info;
>  extern int arc_register_move_cost (machine_mode, enum reg_class,
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 2ccdce8..2ce1744 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -96,22 +96,6 @@ HARD_REG_SET overrideregs;
> ? 0 \
> : -(-GET_MODE_SIZE (MODE) | -4) >> 1)))
>  
> -#define LEGITIMATE_SMALL_DATA_OFFSET_P(X)\
> -  (GET_CODE (X) == CONST \
> -   && GET_CODE (XEXP ((X), 0)) == PLUS   
> \
> -   && GET_CODE (XEXP (XEXP ((X), 0), 0)) == SYMBOL_REF   
> \
> -   && SYMBOL_REF_SMALL_P (XEXP (XEXP ((X), 0), 0))   \
> -   && GET_CODE (XEXP(XEXP ((X), 0), 1)) == CONST_INT \
> -   && INTVAL (XEXP (XEXP ((X), 0), 1)) <= g_switch_value)
> -
> -#define LEGITIMATE_SMALL_DATA_ADDRESS_P(X)   \
> -  (GET_CODE (X) == PLUS  
> \
> - && REG_P (XEXP ((X), 0))
> \
> - && REGNO (XEXP ((X), 0)) == SDATA_BASE_REGNUM   \
> - && ((GET_CODE (XEXP 

Re: [PATCH 5/5] [ARC] Clear the instruction cache using syscalls.

2018-04-27 Thread Andrew Burgess
* Claudiu Zissulescu  [2018-04-06 11:00:14 
+0200]:

> Clear the instruction cache from `beg' to `end'.  This makes an inline
> system call to SYS_cacheflush.
> 
> gcc/
> 2017-03-28  Claudiu Zissulescu  
> 
>   * config/arc/linux.h (CLEAR_INSN_CACHE): Define.


Looks good.

Thanks,
Andrew

> ---
>  gcc/config/arc/linux.h | 14 ++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/gcc/config/arc/linux.h b/gcc/config/arc/linux.h
> index 4e87dfe..96d548e 100644
> --- a/gcc/config/arc/linux.h
> +++ b/gcc/config/arc/linux.h
> @@ -109,3 +109,17 @@ along with GCC; see the file COPYING3.  If not see
>  /* Build attribute: procedure call standard.  */
>  #undef ATTRIBUTE_PCS
>  #define ATTRIBUTE_PCS 3
> +
> +/* Clear the instruction cache from `beg' to `end'.  This makes an
> +   inline system call to SYS_cacheflush.  */
> +#undef CLEAR_INSN_CACHE
> +#define CLEAR_INSN_CACHE(beg, end)   \
> +{\
> +  register unsigned long _beg __asm ("r0") = (unsigned long) (beg);  \
> +  register unsigned long _end __asm ("r1") = (unsigned long) (end);  \
> +  register unsigned long _xtr __asm ("r2") = 0;  
> \
> +  register unsigned long _scno __asm ("r8") = 244;   \
> +  __asm __volatile ("trap_s 0; sys_cache_sync"   
> \
> + : "=r" (_beg)   \
> + : "0" (_beg), "r" (_end), "r" (_xtr), "r" (_scno)); \
> +}
> -- 
> 1.9.1
> 


Re: [PATCH] ARC: Add multilib support for linux targets

2018-05-16 Thread Andrew Burgess
* Alexey Brodkin  [2018-05-16 22:42:36 +0300]:

> We used to build baremetal (AKA Elf32) multilibbed toolchains for years
> now but never made that for Linux targets since there were problems with
> uClibc n multilib setup. Now with help of Crosstool-NG it is finally
> possible to create uClibc-based multilibbed toolchains and so we add
> relevant CPUs for multilib in case of configuration for "arc*-*-linux*".
> 
> This will be essentially useful for glibc-based multilibbbed toolchains
> in the future.
> 
> gcc/
> 2018-05-16  Alexey Brodkin 
> 
> * config.gcc: Add arc/t-multilib-linux to tmake_file for
> arc*-*-linux*.
> * config/arc/t-multilib-linux: Specify MULTILIB_OPTIONS and
> MULTILIB_DIRNAMES

Looks good.

Thanks,
Andrew

> ---
>  gcc/config.gcc  |  2 +-
>  gcc/config/arc/t-multilib-linux | 25 +
>  2 files changed, 26 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/config/arc/t-multilib-linux
> 
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index a5defb0f0058..8e038a72f613 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -1059,7 +1059,7 @@ arc*-*-elf*)
>   ;;
>  arc*-*-linux*)
>   tm_file="arc/arc-arch.h dbxelf.h elfos.h gnu-user.h linux.h 
> linux-android.h glibc-stdint.h arc/linux.h ${tm_file}"
> - tmake_file="${tmake_file} arc/t-arc"
> + tmake_file="${tmake_file} arc/t-multilib-linux arc/t-arc"
>   extra_gcc_objs="driver-arc.o"
>   if test "x$with_cpu" != x; then
>   tm_defines="${tm_defines} TARGET_CPU_BUILD=PROCESSOR_$with_cpu"
> diff --git a/gcc/config/arc/t-multilib-linux b/gcc/config/arc/t-multilib-linux
> new file mode 100644
> index ..f357cfc3f926
> --- /dev/null
> +++ b/gcc/config/arc/t-multilib-linux
> @@ -0,0 +1,25 @@
> +# Copyright (C) 2018 Free Software Foundation, Inc.
> +#
> +# 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 published by the Free
> +# Software Foundation; either version 3, or (at your option) any later
> +# version.
> +#
> +# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +# WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +# for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with GCC; see the file COPYING3.  If not see
> +# .
> +
> +MULTILIB_OPTIONS = 
> mcpu=hs/mcpu=archs/mcpu=hs38/mcpu=hs38_linux/mcpu=arc700/mcpu=nps400
> +
> +MULTILIB_DIRNAMES = hs archs hs38 hs38_linux arc700 nps400
> +
> +# Aliases:
> +MULTILIB_MATCHES += mcpu?arc700=mA7
> +MULTILIB_MATCHES += mcpu?arc700=mARC700
> -- 
> 2.17.0
> 


Re: [PATCH] Delete temporary string within demangler even in failure cases.

2014-06-10 Thread Andrew Burgess
On 27/05/2014 2:47 PM, Ian Lance Taylor wrote:
> On Tue, May 27, 2014 at 3:57 AM, Andrew Burgess  wrote:
>>
>> libiberty/ChangeLog
>>
>> * cplus-dem.c (do_type): Call string_delete even if the call to
>> demangle_template fails.
> 
> This is OK.
> 
> Thanks.
> 
> I have to ask: you know this code is not used, right?  You're looking
> at the old demangler, for symbols generated by versions of g++ before
> GCC 3.4 (released 2004).  The demangler for current versions of g++ is
> in cp-demangle.c.

Sorry for the delay.  Yes, I know it's not very old code, but it is
still shipped, and consumers such as gdb can still trigger this code
path.

Thanks for taking a look at this patch for me.

I don't have gcc write permissions, would you (or any other interested
maintainer) mind committing this for me please.

Thanks,
Andrew



PING: Re: [PATCH] demangler, only access valid fields for DEMANGLE_COMPONENT_FIXED_TYPE.

2014-06-10 Thread Andrew Burgess
Ping!

Thanks for your time,
Andrew

On 29/05/2014 1:02 AM, Andrew Burgess wrote:
> On 28/05/2014 11:56 PM, Pedro Alves wrote:
>> On 05/28/2014 09:38 PM, Andrew Burgess wrote:
>>>
>>> diff --git a/libiberty/testsuite/demangle-expected 
>>> b/libiberty/testsuite/demangle-expected
>>> index 453f9a3..0e2bb12 100644
>>> --- a/libiberty/testsuite/demangle-expected
>>> +++ b/libiberty/testsuite/demangle-expected
>>> @@ -4343,3 +4343,9 @@ 
>>> cereal::detail::InputBindingMap::Serializers 
>>> cereal::p
>>>  --format=gnu-v3
>>>  _ZNSt9_Any_data9_M_accessIPZ4postISt8functionIFvvEEEvOT_EUlvE_EERS5_v
>>>  void post >(std::function>> ()>&&)::{lambda()#1}*& std::_Any_data::_M_access>> post >(void post 
>>> >(std::function&&)::{lambda()#1}*&&)::{lambda()#1}*>()
>>> +# The following input symbol was found during random, it caused a fault
>>
>> Could you add a single empty # above, to separate the tests?
>> I find that that makes it much easier to follow the file.
> 
> Done.
> 
>>> +# The following input symbol was found during random, it caused a fault
>>
>> "during random testing?"
>>
>>> +# within the demangler, it's not a symbol we'd expect in the real world.
>>
>> Why not?
> 
> Good point(s), that comment was out of date,  I've removed it.  The
> symbol is a perfectly good symbol which we could find in the real world,
> and should be able to handle.
> 
> Patch below only has changes to the tests.
> 
> Thanks,
> Andrew
> 
> libiberty/ChangeLog:
> 
>   * cp-demangle.c (d_dump): Only access field from s_fixed part of
>   the union for DEMANGLE_COMPONENT_FIXED_TYPE.
>   (d_count_templates_scopes): Likewise.
>   * testsuite/demangle-expected: New test case.
> 
> diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
> index 68d8ee1..a31dad4 100644
> --- a/libiberty/cp-demangle.c
> +++ b/libiberty/cp-demangle.c
> @@ -710,7 +710,9 @@ d_dump (struct demangle_component *dc, int indent)
>printf ("pointer to member type\n");
>break;
>  case DEMANGLE_COMPONENT_FIXED_TYPE:
> -  printf ("fixed-point type\n");
> +  printf ("fixed-point type, accum? %d, sat? %d\n",
> +  dc->u.s_fixed.accum, dc->u.s_fixed.sat);
> +  d_dump (dc->u.s_fixed.length, indent + 2)
>break;
>  case DEMANGLE_COMPONENT_ARGLIST:
>printf ("argument list\n");
> @@ -3869,7 +3871,13 @@ d_count_templates_scopes (int *num_templates, int 
> *num_scopes,
>  case DEMANGLE_COMPONENT_FUNCTION_TYPE:
>  case DEMANGLE_COMPONENT_ARRAY_TYPE:
>  case DEMANGLE_COMPONENT_PTRMEM_TYPE:
> +  goto recurse_left_right;
> +
>  case DEMANGLE_COMPONENT_FIXED_TYPE:
> +  d_count_templates_scopes (num_templates, num_scopes,
> +dc->u.s_fixed.length);
> +  break;
> +
>  case DEMANGLE_COMPONENT_VECTOR_TYPE:
>  case DEMANGLE_COMPONENT_ARGLIST:
>  case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
> diff --git a/libiberty/testsuite/demangle-expected 
> b/libiberty/testsuite/demangle-expected
> index 453f9a3..63f6821 100644
> --- a/libiberty/testsuite/demangle-expected
> +++ b/libiberty/testsuite/demangle-expected
> @@ -4343,3 +4343,8 @@ 
> cereal::detail::InputBindingMap::Serializers 
> cereal::p
>  --format=gnu-v3
>  _ZNSt9_Any_data9_M_accessIPZ4postISt8functionIFvvEEEvOT_EUlvE_EERS5_v
>  void post >(std::function&&)::{lambda()#1}*& 
> std::_Any_data::_M_access >(void 
> post >(std::function ()>&&)::{lambda()#1}*&&)::{lambda()#1}*>()
> +#
> +--format=auto --no-params
> +_Z3xxxDFyuVb
> +xxx(unsigned long long _Fract, bool volatile)
> +xxx
> 
> 
> 



[PATCH] DW_AT_APPLE_* DWARF extensions.

2014-11-13 Thread Andrew Burgess
Some time ago there was an attempt to add the DWARF DW_AT_APPLE_*
extensions to the file include/dwarf2.def.

The original patch email is here:
  https://sourceware.org/ml/binutils/2012-09/msg00282.html
the "patch committed" mail is here:
  https://sourceware.org/ml/binutils/2012-10/msg00424.html
which corresponds to binutils commit:
  10fca301c7ea8362c086647ee8b4b6aa64ad3e67

However, the patch was reverted in binutils commit:
  1f3de044c6f615326d31ba878dfcd7fdeee7765f
which was an auto-merge from GCC to binutils.

Am I correct to think that the include/* files are owned by GCC, and
so the mistake here was not propagating the change to the GCC
repository?

I had a look on the mailing lists and couldn't find any mail
suggesting this code was deliberately removed, please correct me if
I'm wrong.

I'd like to propose that we try again with this patch, unless there's
any objection.  If I'm right about the ownership then we first need
the patch applied to GCC, after that I can apply it to binutils-gdb.

I've included the patch I'm proposing we apply below.

Any objections?

Thanks,
Andrew

--

include/ChangeLog:

2014-11-13  Shinichiro Hamaji  

* dwarf2.h (DW_AT_APPLE_optimized, DW_AT_APPLE_flags)
(DW_AT_APPLE_isa, DW_AT_APPLE_block)
(DW_AT_APPLE_major_runtime_vers, DW_AT_APPLE_runtime_class)
(DW_AT_APPLE_omit_frame_ptr, DW_AT_APPLE_property_name)
(DW_AT_APPLE_property_getter, DW_AT_APPLE_property_setter)
(DW_AT_APPLE_property_attribute, DW_AT_APPLE_objc_complete_type)
(DW_AT_APPLE_property, DW_OP_GNU_entry_value): New macros.

diff --git a/include/dwarf2.def b/include/dwarf2.def
index 7fe2df1..fd2d080 100644
--- a/include/dwarf2.def
+++ b/include/dwarf2.def
@@ -403,6 +403,20 @@ DW_AT (DW_AT_upc_threads_scaled, 0x3210)
 DW_AT (DW_AT_PGI_lbase, 0x3a00)
 DW_AT (DW_AT_PGI_soffset, 0x3a01)
 DW_AT (DW_AT_PGI_lstride, 0x3a02)
+/* Apple extensions.  */
+DW_AT (DW_AT_APPLE_optimized, 0x3fe1)
+DW_AT (DW_AT_APPLE_flags, 0x3fe2)
+DW_AT (DW_AT_APPLE_isa, 0x3fe3)
+DW_AT (DW_AT_APPLE_block, 0x3fe4)
+DW_AT (DW_AT_APPLE_major_runtime_vers, 0x3fe5)
+DW_AT (DW_AT_APPLE_runtime_class, 0x3fe6)
+DW_AT (DW_AT_APPLE_omit_frame_ptr, 0x3fe7)
+DW_AT (DW_AT_APPLE_property_name, 0x3fe8)
+DW_AT (DW_AT_APPLE_property_getter, 0x3fe9)
+DW_AT (DW_AT_APPLE_property_setter, 0x3fea)
+DW_AT (DW_AT_APPLE_property_attribute, 0x3feb)
+DW_AT (DW_AT_APPLE_objc_complete_type, 0x3fec)
+DW_AT (DW_AT_APPLE_property, 0x3fed)
 DW_END_AT
 
 DW_FIRST_OP (DW_OP_addr, 0x03)


Re: [PATCH] DW_AT_APPLE_* DWARF extensions.

2014-11-13 Thread Andrew Burgess
* Jakub Jelinek  [2014-11-13 10:55:34 +0100]:

> On Thu, Nov 13, 2014 at 10:35:28AM +0100, Andrew Burgess wrote:
> > Am I correct to think that the include/* files are owned by GCC, and
> > so the mistake here was not propagating the change to the GCC
> > repository?
>
> Yes.
>
> > 2014-11-13  Shinichiro Hamaji  
> >
> > * dwarf2.h (DW_AT_APPLE_optimized, DW_AT_APPLE_flags)
> > (DW_AT_APPLE_isa, DW_AT_APPLE_block)
> > (DW_AT_APPLE_major_runtime_vers, DW_AT_APPLE_runtime_class)
> > (DW_AT_APPLE_omit_frame_ptr, DW_AT_APPLE_property_name)
> > (DW_AT_APPLE_property_getter, DW_AT_APPLE_property_setter)
> > (DW_AT_APPLE_property_attribute, DW_AT_APPLE_objc_complete_type)
> > (DW_AT_APPLE_property, DW_OP_GNU_entry_value): New macros.
>
> You aren't adding DW_OP_GNU_entry_value, that is already there.

That will teach me for just using the previous commit message, without
checking it.

> Perhaps a comment with a link to documentation of those would
> be helpful here.

I had a look around and couldn't find anything helpful.  The best I
can offer would be the current path within the llvm source code where
these are defined.  Would that be sufficient?

Updated patch below.  If this is acceptable could someone commit to
GCC please.

Thanks,
Andrew

---

2014-11-13  Shinichiro Hamaji  

* dwarf2.def (DW_AT_APPLE_optimized, DW_AT_APPLE_flags)
(DW_AT_APPLE_isa, DW_AT_APPLE_block)
(DW_AT_APPLE_major_runtime_vers, DW_AT_APPLE_runtime_class)
(DW_AT_APPLE_omit_frame_ptr, DW_AT_APPLE_property_name)
(DW_AT_APPLE_property_getter, DW_AT_APPLE_property_setter)
(DW_AT_APPLE_property_attribute, DW_AT_APPLE_objc_complete_type)
(DW_AT_APPLE_property): New macros.


diff --git a/include/dwarf2.def b/include/dwarf2.def
index 71a37b3..35d01b8 100644
--- a/include/dwarf2.def
+++ b/include/dwarf2.def
@@ -406,6 +406,21 @@ DW_AT (DW_AT_upc_threads_scaled, 0x3210)
 DW_AT (DW_AT_PGI_lbase, 0x3a00)
 DW_AT (DW_AT_PGI_soffset, 0x3a01)
 DW_AT (DW_AT_PGI_lstride, 0x3a02)
+/* Apple extensions.  These are defined within the LLVM source code in the
+   file llvm/include/llvm/Support/Dwarf.h.  */
+DW_AT (DW_AT_APPLE_optimized, 0x3fe1)
+DW_AT (DW_AT_APPLE_flags, 0x3fe2)
+DW_AT (DW_AT_APPLE_isa, 0x3fe3)
+DW_AT (DW_AT_APPLE_block, 0x3fe4)
+DW_AT (DW_AT_APPLE_major_runtime_vers, 0x3fe5)
+DW_AT (DW_AT_APPLE_runtime_class, 0x3fe6)
+DW_AT (DW_AT_APPLE_omit_frame_ptr, 0x3fe7)
+DW_AT (DW_AT_APPLE_property_name, 0x3fe8)
+DW_AT (DW_AT_APPLE_property_getter, 0x3fe9)
+DW_AT (DW_AT_APPLE_property_setter, 0x3fea)
+DW_AT (DW_AT_APPLE_property_attribute, 0x3feb)
+DW_AT (DW_AT_APPLE_objc_complete_type, 0x3fec)
+DW_AT (DW_AT_APPLE_property, 0x3fed)
 DW_END_AT
 
 DW_FIRST_OP (DW_OP_addr, 0x03)


Re: [PATCH] DW_AT_APPLE_* DWARF extensions.

2014-11-14 Thread Andrew Burgess
* Jakub Jelinek  [2014-11-13 14:13:42 +0100]:

> On Thu, Nov 13, 2014 at 01:21:21PM +0100, Andrew Burgess wrote:
> > I had a look around and couldn't find anything helpful.  The best I
> > can offer would be the current path within the llvm source code where
> > these are defined.  Would that be sufficient?
>
> That is not useful.  The point is not to suggest where those constants come
> from but what they mean, see e.g. the
> http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open
> http://gcc.gnu.org/wiki/TemplateParmsDwarf
> etc. links that describe what the extensions do.
> If LLVM doesn't have any documentation of their extensions, then just
> /* Apple extensions.  */
> is good enough.

I agree, hence my comment about not finding anything useful :)

I've look again, and still can't find anything suitable, so could we
go with just "/* Apple extensions.  */" then?

Patch & Changelog below.

Thanks,
Andrew

2014-11-14  Shinichiro Hamaji  

* dwarf2.def (DW_AT_APPLE_optimized, DW_AT_APPLE_flags)
(DW_AT_APPLE_isa, DW_AT_APPLE_block)
(DW_AT_APPLE_major_runtime_vers, DW_AT_APPLE_runtime_class)
(DW_AT_APPLE_omit_frame_ptr, DW_AT_APPLE_property_name)
(DW_AT_APPLE_property_getter, DW_AT_APPLE_property_setter)
(DW_AT_APPLE_property_attribute, DW_AT_APPLE_objc_complete_type)
(DW_AT_APPLE_property): New macros.


diff --git a/include/dwarf2.def b/include/dwarf2.def
index 71a37b3..878c5c6 100644
--- a/include/dwarf2.def
+++ b/include/dwarf2.def
@@ -406,6 +406,20 @@ DW_AT (DW_AT_upc_threads_scaled, 0x3210)
 DW_AT (DW_AT_PGI_lbase, 0x3a00)
 DW_AT (DW_AT_PGI_soffset, 0x3a01)
 DW_AT (DW_AT_PGI_lstride, 0x3a02)
+/* Apple extensions.  */
+DW_AT (DW_AT_APPLE_optimized, 0x3fe1)
+DW_AT (DW_AT_APPLE_flags, 0x3fe2)
+DW_AT (DW_AT_APPLE_isa, 0x3fe3)
+DW_AT (DW_AT_APPLE_block, 0x3fe4)
+DW_AT (DW_AT_APPLE_major_runtime_vers, 0x3fe5)
+DW_AT (DW_AT_APPLE_runtime_class, 0x3fe6)
+DW_AT (DW_AT_APPLE_omit_frame_ptr, 0x3fe7)
+DW_AT (DW_AT_APPLE_property_name, 0x3fe8)
+DW_AT (DW_AT_APPLE_property_getter, 0x3fe9)
+DW_AT (DW_AT_APPLE_property_setter, 0x3fea)
+DW_AT (DW_AT_APPLE_property_attribute, 0x3feb)
+DW_AT (DW_AT_APPLE_objc_complete_type, 0x3fec)
+DW_AT (DW_AT_APPLE_property, 0x3fed)
 DW_END_AT
 
 DW_FIRST_OP (DW_OP_addr, 0x03)


Re: [PATCH] libiberty/argv.c: Use freeargv() instead of free() to avoid memory leak.

2015-01-28 Thread Andrew Burgess
* Chen Gang S  [2015-01-28 19:34:38 +0800]:

>  libiberty/argv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libiberty/argv.c b/libiberty/argv.c
> index f2727e8..9fdd55b 100644
> --- a/libiberty/argv.c
> +++ b/libiberty/argv.c
> @@ -454,7 +454,7 @@ expandargv (int *argcp, char ***argvp)
>/* Free up memory allocated to process the response file.  We do
>not use freeargv because the individual options in FILE_ARGV
>are now in the main ARGV.  */
> -  free (file_argv);
> +  freeargv (file_argv);

I'm not commenting on the correctness of the patch, however, you will
need to update the comment just above this change.

Personally, I'd also hope that the commit message explains why the
comment is no longer correct, rather than just stating that the change
has been made.

Thanks,
Andrew


  1   2   3   >