Re: [PATCH v1 1/2] LoongArch: Switch loongarch-def from C to C++ to make it possible.

2023-12-04 Thread chenglulu



在 2023/12/2 下午9:41, Xi Ruoyao 写道:

On Sat, 2023-12-02 at 20:44 +0800, chenglulu wrote:

@@ -657,12 +658,18 @@ abi_str (struct loongarch_abi abi)
     strlen (loongarch_abi_base_strings[abi.base]));
      else
    {
+  /* This situation has not yet occurred, so in order to avoid
the
+-Warray-bounds warning during C++ syntax checking, this part
+of the code is commented first.*/
+  /*

Just put a "gcc_unreachable ();" here?

Um, I just thought that the code can't go here, I will add a prompt
message here.:-(

If I read the code correctly, this is indeed unreachable so we can just
put gcc_unreachable() here.  But maybe I'm wrong.


I agree that if it runs this far, it's a problem with the code design.

In addition,I've sorted out the patches to remove the unnecessary guards.,

and I will send the v2 version of the patch immediately.



Re: [PATCH v1 1/2] LoongArch: Switch loongarch-def from C to C++ to make it possible.

2023-12-02 Thread Xi Ruoyao
On Sat, 2023-12-02 at 20:44 +0800, chenglulu wrote:
> > > @@ -657,12 +658,18 @@ abi_str (struct loongarch_abi abi)
> > >        strlen (loongarch_abi_base_strings[abi.base]));
> > >      else
> > >    {
> > > +  /* This situation has not yet occurred, so in order to avoid
> > > the
> > > +  -Warray-bounds warning during C++ syntax checking, this part
> > > +  of the code is commented first.*/
> > > +  /*
> > Just put a "gcc_unreachable ();" here?
> Um, I just thought that the code can't go here, I will add a prompt 
> message here.:-(

If I read the code correctly, this is indeed unreachable so we can just
put gcc_unreachable() here.  But maybe I'm wrong.

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [PATCH v1 1/2] LoongArch: Switch loongarch-def from C to C++ to make it possible.

2023-12-02 Thread chenglulu



在 2023/12/2 下午6:15, Xi Ruoyao 写道:

On Sat, 2023-12-02 at 16:14 +0800, Lulu Cheng wrote:

/* snip */


diff --git a/gcc/config/loongarch/loongarch-opts.cc
b/gcc/config/loongarch/loongarch-opts.cc
index b5836f198c0..6861642a98d 100644
--- a/gcc/config/loongarch/loongarch-opts.cc
+++ b/gcc/config/loongarch/loongarch-opts.cc
@@ -163,6 +163,7 @@ loongarch_config_target (struct loongarch_target
*target,
     int follow_multilib_list_p)
  {
    struct loongarch_target t;
+
    if (!target)
  return;
  
@@ -657,12 +658,18 @@ abi_str (struct loongarch_abi abi)

     strlen (loongarch_abi_base_strings[abi.base]));
    else
  {
+  /* This situation has not yet occurred, so in order to avoid
the
+-Warray-bounds warning during C++ syntax checking, this part
+of the code is commented first.*/
+  /*

Just put a "gcc_unreachable ();" here?
Um, I just thought that the code can't go here, I will add a prompt 
message here.:-(





    APPEND_STRING (loongarch_abi_base_strings[abi.base])
    APPEND1 ('/')
    APPEND_STRING (loongarch_abi_ext_strings[abi.ext])
    APPEND1 ('\0')
  
    return XOBFINISH (_obstack, const char *);

+  */
+  gcc_unreachable ();
  }
  }
  
diff --git a/gcc/config/loongarch/loongarch-opts.h

b/gcc/config/loongarch/loongarch-opts.h
index fa3773223bc..7a644c86d48 100644
--- a/gcc/config/loongarch/loongarch-opts.h
+++ b/gcc/config/loongarch/loongarch-opts.h
@@ -21,7 +21,10 @@ along with GCC; see the file COPYING3.  If not see
  #ifndef LOONGARCH_OPTS_H
  #define LOONGARCH_OPTS_H
  
+/* This is a C++ header and it shouldn't be used by target libraries.  */

+#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)
  #include "loongarch-def.h"
+#endif

With this change we can revert r14-5634 (remove the #if
!defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)
guards in loongarch-def.h as they'll be unneeded).



Ok!

Thanks!



Re: [PATCH v1 1/2] LoongArch: Switch loongarch-def from C to C++ to make it possible.

2023-12-02 Thread Xi Ruoyao
On Sat, 2023-12-02 at 16:14 +0800, Lulu Cheng wrote:

/* snip */

> diff --git a/gcc/config/loongarch/loongarch-opts.cc
> b/gcc/config/loongarch/loongarch-opts.cc
> index b5836f198c0..6861642a98d 100644
> --- a/gcc/config/loongarch/loongarch-opts.cc
> +++ b/gcc/config/loongarch/loongarch-opts.cc
> @@ -163,6 +163,7 @@ loongarch_config_target (struct loongarch_target
> *target,
>    int follow_multilib_list_p)
>  {
>    struct loongarch_target t;
> +
>    if (!target)
>  return;
>  
> @@ -657,12 +658,18 @@ abi_str (struct loongarch_abi abi)
>    strlen (loongarch_abi_base_strings[abi.base]));
>    else
>  {
> +  /* This situation has not yet occurred, so in order to avoid
> the
> +  -Warray-bounds warning during C++ syntax checking, this part
> +  of the code is commented first.*/
> +  /*

Just put a "gcc_unreachable ();" here?

>    APPEND_STRING (loongarch_abi_base_strings[abi.base])
>    APPEND1 ('/')
>    APPEND_STRING (loongarch_abi_ext_strings[abi.ext])
>    APPEND1 ('\0')
>  
>    return XOBFINISH (_obstack, const char *);
> +  */
> +  gcc_unreachable ();
>  }
>  }
>  
> diff --git a/gcc/config/loongarch/loongarch-opts.h
> b/gcc/config/loongarch/loongarch-opts.h
> index fa3773223bc..7a644c86d48 100644
> --- a/gcc/config/loongarch/loongarch-opts.h
> +++ b/gcc/config/loongarch/loongarch-opts.h
> @@ -21,7 +21,10 @@ along with GCC; see the file COPYING3.  If not see
>  #ifndef LOONGARCH_OPTS_H
>  #define LOONGARCH_OPTS_H
>  
> +/* This is a C++ header and it shouldn't be used by target libraries.  */
> +#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)
>  #include "loongarch-def.h"
> +#endif

With this change we can revert r14-5634 (remove the #if
!defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)
guards in loongarch-def.h as they'll be unneeded).


-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


[PATCH v1 1/2] LoongArch: Switch loongarch-def from C to C++ to make it possible.

2023-12-02 Thread Lulu Cheng
From: Xi Ruoyao 

We'll use HOST_WIDE_INT in LoongArch static properties in following patches.
Switch loongarch-def from C to C++ to make it possible.

To keep the same readability as C99 designated initializers, create a
std::array like data structure with position setter function, and add
field setter functions for structs used in loongarch-def.cc.

gcc/ChangeLog:

* config/loongarch/loongarch-def.h: Remove extern "C".
(loongarch_isa_base_strings): Declare as loongarch_def_array
instead of plain array.
(loongarch_isa_ext_strings): Likewise.
(loongarch_abi_base_strings): Likewise.
(loongarch_abi_ext_strings): Likewise.
(loongarch_cmodel_strings): Likewise.
(loongarch_cpu_strings): Likewise.
(loongarch_cpu_default_isa): Likewise.
(loongarch_cpu_issue_rate): Likewise.
(loongarch_cpu_multipass_dfa_lookahead): Likewise.
(loongarch_cpu_cache): Likewise.
(loongarch_cpu_align): Likewise.
(loongarch_cpu_rtx_cost_data): Likewise.
(loongarch_isa): Add a constructor and field setter functions.
* config/loongarch/loongarch-opts.h (loongarch-defs.h): Do not
include for target libraries.
* config/loongarch/loongarch-tune.h (LOONGARCH_TUNE_H): Likewise.
(struct loongarch_rtx_cost_data): Likewise.
(struct loongarch_cache): Likewise.
(struct loongarch_align): Likewise.
* config/loongarch/t-loongarch: Compile loongarch-def.cc with the
C++ compiler.
* config/loongarch/loongarch-def-array.h: New file for a
std:array like data structure with position setter function.
* config/loongarch/loongarch-def.c: Rename to ...
* config/loongarch/loongarch-def.cc: ... here.
(loongarch_cpu_strings): Define as loongarch_def_array instead
of plain array.
(loongarch_cpu_default_isa): Likewise.
(loongarch_cpu_cache): Likewise.
(loongarch_cpu_align): Likewise.
(loongarch_cpu_rtx_cost_data): Likewise.
(loongarch_cpu_issue_rate): Likewise.
(loongarch_cpu_multipass_dfa_lookahead): Likewise.
(loongarch_isa_base_strings): Likewise.
(loongarch_isa_ext_strings): Likewise.
(loongarch_abi_base_strings): Likewise.
(loongarch_abi_ext_strings): Likewise.
(loongarch_cmodel_strings): Likewise.
(abi_minimal_isa): Likewise.
(loongarch_rtx_cost_optimize_size): Use field setter functions
instead of designated initializers.
(loongarch_rtx_cost_data): Implement default constructor.
---
 gcc/config/loongarch/loongarch-def-array.h |  40 
 gcc/config/loongarch/loongarch-def.c   | 227 -
 gcc/config/loongarch/loongarch-def.cc  | 187 +
 gcc/config/loongarch/loongarch-def.h   |  51 +++--
 gcc/config/loongarch/loongarch-opts.cc |   7 +
 gcc/config/loongarch/loongarch-opts.h  |   3 +
 gcc/config/loongarch/loongarch-tune.h  | 123 ++-
 gcc/config/loongarch/t-loongarch   |   4 +-
 8 files changed, 389 insertions(+), 253 deletions(-)
 create mode 100644 gcc/config/loongarch/loongarch-def-array.h
 delete mode 100644 gcc/config/loongarch/loongarch-def.c
 create mode 100644 gcc/config/loongarch/loongarch-def.cc

diff --git a/gcc/config/loongarch/loongarch-def-array.h 
b/gcc/config/loongarch/loongarch-def-array.h
new file mode 100644
index 000..bdb3e9c6a2b
--- /dev/null
+++ b/gcc/config/loongarch/loongarch-def-array.h
@@ -0,0 +1,40 @@
+/* A std::array like data structure for LoongArch static properties.
+   Copyright (C) 2023 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
+.  */
+
+#ifndef _LOONGARCH_DEF_ARRAY_H
+#define _LOONGARCH_DEF_ARRAY_H 1
+
+template 
+class loongarch_def_array {
+private:
+  T arr[N];
+public:
+  loongarch_def_array () : arr{} {}
+
+  T [] (int n) { return arr[n]; }
+  const T [] (int n) const { return arr[n]; }
+
+  loongarch_def_array set (int idx, T &)
+  {
+(*this)[idx] = value;
+return *this;
+  }
+};
+
+#endif
diff --git a/gcc/config/loongarch/loongarch-def.c 
b/gcc/config/loongarch/loongarch-def.c
deleted file mode 100644
index f22d488acb2..000
--- a/gcc/config/loongarch/loongarch-def.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/* LoongArch static properties.
-   Copyright (C) 2021-2023 Free Software