https://gcc.gnu.org/g:9bf4cad4e4e1ec92c320a619c9bad35535596ced

commit r15-5931-g9bf4cad4e4e1ec92c320a619c9bad35535596ced
Author: Kito Cheng <kito.ch...@sifive.com>
Date:   Tue Dec 3 00:44:09 2024 -0800

    RISC-V: Add const to function_shape::get_name [NFC]
    
    function_shape::get_name is the funciton for building intrinsic function 
name,
    the result should not be changed by others once it built.
    
    So add const to the return type to make sure no one change that by
    accident.
    
    gcc/ChangeLog:
            * config/riscv/riscv-vector-builtins-shapes.cc
            (vsetvl_def::get_name): Adjust return type.
            (loadstore_def::get_name): Ditto.
            (indexed_loadstore_def::get_name): Ditto.
            (th_loadstore_width_def::get_name): Ditto.
            (th_indexed_loadstore_width_def::get_name): Ditto.
            (alu_def::get_name): Ditto.
            (alu_frm_def::get_name): Ditto.
            (widen_alu_frm_def::get_name): Ditto.
            (narrow_alu_frm_def::get_name): Ditto.
            (reduc_alu_frm_def::get_name): Ditto.
            (widen_alu_def::get_name): Ditto.
            (no_mask_policy_def::get_name): Ditto.
            (return_mask_def::get_name): Ditto.
            (narrow_alu_def::get_name): Ditto.
            (move_def::get_name): Ditto.
            (mask_alu_def::get_name): Ditto.
            (reduc_alu_def::get_name): Ditto.
            (th_extract_def::get_name): Ditto.
            (scalar_move_def::get_name): Ditto.
            (vundefined_def::get_name): Ditto.
            (misc_def::get_name): Ditto.
            (vset_def::get_name): Ditto.
            (vcreate_def: Ditto.::get_name): Ditto.
            (read_vl_def::get_name): Ditto.
            (fault_load_def::get_name): Ditto.
            (vlenb_def::get_name): Ditto.
            (seg_loadstore_def::get_name): Ditto.
            (seg_indexed_loadstore_def::get_name): Ditto.
            (seg_fault_load_def::get_name): Ditto.
            (crypto_vv_def::get_name): Ditto.
            (crypto_vi_def::get_name): Ditto.
            (crypto_vv_no_op_type_def::get_name): Ditto.
            (sf_vqmacc_def::get_name): Ditto.
            (sf_vqmacc_def::get_name): Ditto.
            (sf_vfnrclip_def::get_name): Ditto.
            * config/riscv/riscv-vector-builtins.cc
            (function_builder::add_unique_function): Adjust the type for the
            function name holder.
            (function_builder::add_overloaded_function): Ditto.
            * config/riscv/riscv-vector-builtins.h (function_shape::get_name): 
Add
            const to the return type.

Diff:
---
 gcc/config/riscv/riscv-vector-builtins-shapes.cc | 136 +++++++++++------------
 gcc/config/riscv/riscv-vector-builtins.cc        |   6 +-
 gcc/config/riscv/riscv-vector-builtins.h         |   4 +-
 3 files changed, 73 insertions(+), 73 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins-shapes.cc 
b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
index 0999a6443881..9dadaf969548 100644
--- a/gcc/config/riscv/riscv-vector-builtins-shapes.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
@@ -142,8 +142,8 @@ struct build_base : public function_shape
 /* vsetvl_def class.  */
 struct vsetvl_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* vsetvl* instruction doesn't have C++ overloaded functions.  */
     if (overloaded_p)
@@ -157,8 +157,8 @@ struct vsetvl_def : public build_base
 /* loadstore_def class.  */
 struct loadstore_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -213,8 +213,8 @@ struct indexed_loadstore_def : public function_shape
       }
   }
 
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -301,8 +301,8 @@ struct th_loadstore_width_def : public build_base
       }
   }
 
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -352,8 +352,8 @@ struct th_indexed_loadstore_width_def : public 
function_shape
       }
   }
 
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
 
     /* Return nullptr if it can not be overloaded.  */
@@ -383,8 +383,8 @@ struct th_indexed_loadstore_width_def : public 
function_shape
 /* alu_def class.  */
 struct alu_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -461,8 +461,8 @@ struct build_frm_base : public build_base
 /* alu_frm_def class.  */
 struct alu_frm_def : public build_frm_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     char base_name[BASE_NAME_MAX_LEN] = {};
 
@@ -500,8 +500,8 @@ struct alu_frm_def : public build_frm_base
 /* widen_alu_frm_def class.  */
 struct widen_alu_frm_def : public build_frm_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     char base_name[BASE_NAME_MAX_LEN] = {};
 
@@ -535,8 +535,8 @@ struct widen_alu_frm_def : public build_frm_base
 /* narrow_alu_frm_def class.  */
 struct narrow_alu_frm_def : public build_frm_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     char base_name[BASE_NAME_MAX_LEN] = {};
 
@@ -573,8 +573,8 @@ struct narrow_alu_frm_def : public build_frm_base
 /* reduc_alu_frm_def class.  */
 struct reduc_alu_frm_def : public build_frm_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     char base_name[BASE_NAME_MAX_LEN] = {};
 
@@ -613,8 +613,8 @@ struct reduc_alu_frm_def : public build_frm_base
    'OP' suffix in overloaded API.  */
 struct widen_alu_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -638,8 +638,8 @@ struct widen_alu_def : public build_base
    doesn't need mask policy.  */
 struct no_mask_policy_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -659,8 +659,8 @@ struct no_mask_policy_def : public build_base
    is returning mask value.  */
 struct return_mask_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -686,8 +686,8 @@ struct return_mask_def : public build_base
 /* narrow_alu_def class. Handle narrowing instructions like vnsrl.wv.  */
 struct narrow_alu_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -729,8 +729,8 @@ struct narrow_alu_def : public build_base
 /* move_def class. Handle vmv.v.v/vmv.v.x.  */
 struct move_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* vmv.v.x/vfmv.v.f (PRED_none) can not be overloaded.  */
     if ((instance.op_info->op == OP_TYPE_x || instance.op_info->op == 
OP_TYPE_f)
@@ -757,8 +757,8 @@ struct move_def : public build_base
 /* mask_alu_def class.  */
 struct mask_alu_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -786,8 +786,8 @@ struct mask_alu_def : public build_base
 /* reduc_alu_def class.  */
 struct reduc_alu_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -813,8 +813,8 @@ struct reduc_alu_def : public build_base
 /* th_extract_def class.  */
 struct th_extract_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-      bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_name ("__riscv_th_");
     b.append_name (instance.base_name);
@@ -830,8 +830,8 @@ struct th_extract_def : public build_base
 /* scalar_move_def class.  */
 struct scalar_move_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
     if (overloaded_p)
@@ -846,8 +846,8 @@ struct scalar_move_def : public build_base
 /* vundefined_def class.  */
 struct vundefined_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     if (overloaded_p)
       return nullptr;
@@ -860,8 +860,8 @@ struct vundefined_def : public build_base
 /* misc_def class.  */
 struct misc_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -884,8 +884,8 @@ struct misc_def : public build_base
 /* vset_def class.  */
 struct vset_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -964,8 +964,8 @@ struct vcreate_def : public build_base
      }
   }
 
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     if (overloaded_p)
       return nullptr;
@@ -999,8 +999,8 @@ struct read_vl_def : public function_shape
                           group.required_extensions);
   }
 
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     if (overloaded_p)
       return nullptr;
@@ -1012,8 +1012,8 @@ struct read_vl_def : public function_shape
 /* fault_load_def class.  */
 struct fault_load_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
       return nullptr;
@@ -1058,8 +1058,8 @@ struct vlenb_def : public function_shape
                           group.required_extensions);
   }
 
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     if (overloaded_p)
       return nullptr;
@@ -1071,8 +1071,8 @@ struct vlenb_def : public function_shape
 /* seg_loadstore_def class.  */
 struct seg_loadstore_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -1114,8 +1114,8 @@ struct seg_loadstore_def : public build_base
 /* seg_indexed_loadstore_def class.  */
 struct seg_indexed_loadstore_def : public indexed_loadstore_def
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -1161,8 +1161,8 @@ struct seg_indexed_loadstore_def : public 
indexed_loadstore_def
 /* seg_fault_load_def class.  */
 struct seg_fault_load_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -1207,8 +1207,8 @@ struct seg_fault_load_def : public build_base
 /* vsm4r/vaes* class.  */
 struct crypto_vv_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                  bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -1241,8 +1241,8 @@ struct crypto_vv_def : public build_base
 /* vaeskf1/vaeskf2/vsm4k/vsm3c class.  */
 struct crypto_vi_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                  bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -1261,8 +1261,8 @@ struct crypto_vi_def : public build_base
 /* vaesz class.  */
 struct crypto_vv_no_op_type_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                  bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     /* Return nullptr if it can not be overloaded.  */
     if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
@@ -1290,8 +1290,8 @@ struct crypto_vv_no_op_type_def : public build_base
 /* sf_vqmacc_def class.  */
 struct sf_vqmacc_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
@@ -1319,8 +1319,8 @@ struct sf_vqmacc_def : public build_base
 /* sf_vfnrclip_def class. Handle instructions like vfnrclip.  */
 struct sf_vfnrclip_def : public build_base
 {
-  char *get_name (function_builder &b, const function_instance &instance,
-                 bool overloaded_p) const override
+  const char *get_name (function_builder &b, const function_instance &instance,
+                       bool overloaded_p) const override
   {
     b.append_base_name (instance.base_name);
 
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index b9b9d33adab6..7d92ab7b0cad 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -3974,10 +3974,10 @@ function_builder::add_unique_function (const 
function_instance &instance,
 
   /* Also add the function under its overloaded alias, if we want
      a separate decl for each instance of an overloaded function.  */
-  char *overload_name = shape->get_name (*this, instance, true);
+  const char *overload_name = shape->get_name (*this, instance, true);
 
   /* Add the function under its full (unique) name.  */
-  char *name = shape->get_name (*this, instance, false);
+  const char *name = shape->get_name (*this, instance, false);
   tree fntype
     = build_function_type_array (return_type, argument_types.length (),
                                 argument_types.address ());
@@ -4020,7 +4020,7 @@ function_builder::add_overloaded_function (const 
function_instance &instance,
   if (!check_required_extensions (instance))
     return;
 
-  char *name = shape->get_name (*this, instance, true);
+  const char *name = shape->get_name (*this, instance, true);
 
   if (name)
     {
diff --git a/gcc/config/riscv/riscv-vector-builtins.h 
b/gcc/config/riscv/riscv-vector-builtins.h
index 2602f6c2aa16..1e308412b446 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -638,8 +638,8 @@ class function_shape
 {
 public:
   /* Shape the function name according to function_instance.  */
-  virtual char *get_name (function_builder &, const function_instance &,
-                         bool) const
+  virtual const char *get_name (function_builder &, const function_instance &,
+                               bool) const
     = 0;
 
   /* Define all functions associated with the given group.  */

Reply via email to