public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers
@ 2021-06-15 17:17 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-06-15 17:17 UTC (permalink / raw)
  To: gcc-cvs

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

commit 9a90f4243c54c476d632caeebd08b9ca6de12266
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Mon Jun 7 14:17:21 2021 -0500

    rs6000: Build and store function type identifiers
    
    2021-06-07  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-gen-builtins.c (complete_vector_type): New
            function.
            (complete_base_type): Likewise.
            (construct_fntype_id): Likewise.
            (parse_bif_entry): Call contruct_fntype_id.
            (parse_ovld_entry): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 233 ++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index b38b7285acb..466fce1cdd2 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -1280,6 +1280,231 @@ endian = %d.\n",
   return PC_OK;
 }
 
+/* Convert a vector type into a mode string.  */
+static void
+complete_vector_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  if (typeptr->isbool)
+    buf[(*bufi)++] = 'b';
+  buf[(*bufi)++] = 'v';
+  if (typeptr->ispixel)
+    {
+      memcpy (&buf[*bufi], "p8hi", 4);
+      *bufi += 4;
+    }
+  else
+    {
+      switch (typeptr->base)
+	{
+	case BT_CHAR:
+	  memcpy (&buf[*bufi], "16qi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_SHORT:
+	  memcpy (&buf[*bufi], "8hi", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT:
+	  memcpy (&buf[*bufi], "4si", 3);
+	  *bufi += 3;
+	  break;
+	case BT_LONGLONG:
+	  memcpy (&buf[*bufi], "2di", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT:
+	  memcpy (&buf[*bufi], "4sf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_DOUBLE:
+	  memcpy (&buf[*bufi], "2df", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT128:
+	  memcpy (&buf[*bufi], "1ti", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT128:
+	  memcpy (&buf[*bufi], "1tf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_VPAIR:
+	  memcpy (&buf[*bufi], "1poi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_VQUAD:
+	  memcpy (&buf[*bufi], "1pxi", 4);
+	  *bufi += 4;
+	  break;
+	default:
+	  (*diag) ("unhandled basetype %d.\n", typeptr->base);
+	  exit (1);
+	}
+    }
+}
+
+/* Convert a base type into a mode string.  */
+static void
+complete_base_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  switch (typeptr->base)
+    {
+    case BT_CHAR:
+      memcpy (&buf[*bufi], "qi", 2);
+      break;
+    case BT_SHORT:
+      memcpy (&buf[*bufi], "hi", 2);
+      break;
+    case BT_INT:
+      memcpy (&buf[*bufi], "si", 2);
+      break;
+    case BT_LONG:
+      memcpy (&buf[*bufi], "lg", 2);
+      break;
+    case BT_LONGLONG:
+      memcpy (&buf[*bufi], "di", 2);
+      break;
+    case BT_FLOAT:
+      memcpy (&buf[*bufi], "sf", 2);
+      break;
+    case BT_DOUBLE:
+      memcpy (&buf[*bufi], "df", 2);
+      break;
+    case BT_LONGDOUBLE:
+      memcpy (&buf[*bufi], "ld", 2);
+      break;
+    case BT_INT128:
+      memcpy (&buf[*bufi], "ti", 2);
+      break;
+    case BT_FLOAT128:
+      memcpy (&buf[*bufi], "tf", 2);
+      break;
+    case BT_BOOL:
+      memcpy (&buf[*bufi], "bi", 2);
+      break;
+    case BT_STRING:
+      memcpy (&buf[*bufi], "st", 2);
+      break;
+    case BT_DECIMAL32:
+      memcpy (&buf[*bufi], "sd", 2);
+      break;
+    case BT_DECIMAL64:
+      memcpy (&buf[*bufi], "dd", 2);
+      break;
+    case BT_DECIMAL128:
+      memcpy (&buf[*bufi], "td", 2);
+      break;
+    case BT_IBM128:
+      memcpy (&buf[*bufi], "if", 2);
+      break;
+    default:
+      (*diag) ("unhandled basetype %d.\n", typeptr->base);
+      exit (1);
+    }
+
+  *bufi += 2;
+}
+
+/* Build a function type descriptor identifier from the return type
+   and argument types described by PROTOPTR, and store it if it does
+   not already exist.  Return the identifier.  */
+static char *
+construct_fntype_id (prototype *protoptr)
+{
+  /* Determine the maximum space for a function type descriptor id.
+     Each type requires at most 9 characters (6 for the mode*, 1 for
+     the optional 'u' preceding the mode, 1 for the optional 'p'
+     preceding the mode, and 1 for an underscore following the mode).
+     We also need 5 characters for the string "ftype" that separates
+     the return mode from the argument modes.  The last argument doesn't
+     need a trailing underscore, but we count that as the one trailing
+     "ftype" instead.  For the special case of zero arguments, we need 9
+     for the return type and 7 for "ftype_v".  Finally, we need one
+     character for the terminating null.  Thus for a function with N
+     arguments, we need at most 9N+15 characters for N>0, otherwise 17.
+     ----
+       *Worst case is bv16qi for "vector bool char".  */
+  int len = protoptr->nargs ? (protoptr->nargs + 1) * 9 + 6 : 17;
+  char *buf = (char *) malloc (len);
+  int bufi = 0;
+
+  if (protoptr->rettype.ispointer)
+    buf[bufi++] = 'p';
+
+  if (protoptr->rettype.isvoid)
+    buf[bufi++] = 'v';
+  else
+    {
+      if (protoptr->rettype.isunsigned)
+	buf[bufi++] = 'u';
+      if (protoptr->rettype.isvector)
+	complete_vector_type (&protoptr->rettype, buf, &bufi);
+      else
+	complete_base_type (&protoptr->rettype, buf, &bufi);
+    }
+
+  memcpy (&buf[bufi], "_ftype", 6);
+  bufi += 6;
+
+  if (!protoptr->nargs)
+    {
+      memcpy (&buf[bufi], "_v", 2);
+      bufi += 2;
+    }
+  else
+    {
+      typelist *argptr = protoptr->args;
+      for (int i = 0; i < protoptr->nargs; i++, argptr = argptr->next)
+	{
+	  assert (argptr);
+	  buf[bufi++] = '_';
+	  if (argptr->info.isconst
+	      && argptr->info.base == BT_INT
+	      && !argptr->info.ispointer)
+	    {
+	      buf[bufi++] = 'c';
+	      buf[bufi++] = 'i';
+	      continue;
+	    }
+	  if (argptr->info.ispointer)
+	    {
+	      if (argptr->info.isvoid)
+		{
+		  if (argptr->info.isconst)
+		    {
+		      memcpy (&buf[bufi], "pcvoid", 6);
+		      bufi += 6;
+		      continue;
+		    }
+		  else
+		    {
+		      buf[bufi++] = 'p';
+		      buf[bufi++] = 'v';
+		      continue;
+		    }
+		}
+	      else
+		buf[bufi++] = 'p';
+	    }
+
+	  if (argptr->info.isunsigned)
+	    buf[bufi++] = 'u';
+	  if (argptr->info.isvector)
+	    complete_vector_type (&argptr->info, buf, &bufi);
+	  else
+	    complete_base_type (&argptr->info, buf, &bufi);
+	}
+      assert (!argptr);
+      }
+
+  buf[bufi] = '\0';
+
+  /* Ignore return value, as duplicates are expected.  */
+  (void) rbt_insert (&fntype_rbt, buf);
+
+  return buf;
+}
+
 /* Parse a function prototype.  This code is shared by the bif and overload
    file processing.  */
 static parse_codes
@@ -1391,6 +1616,10 @@ parse_bif_entry (void)
   if (parse_prototype (&bifs[curr_bif].proto) == PC_PARSEFAIL)
     return PC_PARSEFAIL;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  bifs[curr_bif].fndecl = construct_fntype_id (&bifs[curr_bif].proto);
+
   /* Now process line 2.  First up is the builtin id.  */
   if (!advance_line (bif_file))
     {
@@ -1568,6 +1797,10 @@ parse_ovld_entry (void)
   if (ovlds[curr_ovld].proto.nargs > max_ovld_args)
     max_ovld_args = ovlds[curr_ovld].proto.nargs;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  ovlds[curr_ovld].fndecl = construct_fntype_id (&ovlds[curr_ovld].proto);
+
   /* Now process line 2, which just contains the builtin id and an
      optional overload id.  */
   if (!advance_line (ovld_file))


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers
@ 2021-06-25 16:16 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-06-25 16:16 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7931e390f98572d6c3512d9da8f1af1c1f74418e

commit 7931e390f98572d6c3512d9da8f1af1c1f74418e
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Mon Jun 7 14:17:21 2021 -0500

    rs6000: Build and store function type identifiers
    
    2021-06-07  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-gen-builtins.c (complete_vector_type): New
            function.
            (complete_base_type): Likewise.
            (construct_fntype_id): Likewise.
            (parse_bif_entry): Call contruct_fntype_id.
            (parse_ovld_entry): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 233 ++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index b38b7285acb..466fce1cdd2 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -1280,6 +1280,231 @@ endian = %d.\n",
   return PC_OK;
 }
 
+/* Convert a vector type into a mode string.  */
+static void
+complete_vector_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  if (typeptr->isbool)
+    buf[(*bufi)++] = 'b';
+  buf[(*bufi)++] = 'v';
+  if (typeptr->ispixel)
+    {
+      memcpy (&buf[*bufi], "p8hi", 4);
+      *bufi += 4;
+    }
+  else
+    {
+      switch (typeptr->base)
+	{
+	case BT_CHAR:
+	  memcpy (&buf[*bufi], "16qi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_SHORT:
+	  memcpy (&buf[*bufi], "8hi", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT:
+	  memcpy (&buf[*bufi], "4si", 3);
+	  *bufi += 3;
+	  break;
+	case BT_LONGLONG:
+	  memcpy (&buf[*bufi], "2di", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT:
+	  memcpy (&buf[*bufi], "4sf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_DOUBLE:
+	  memcpy (&buf[*bufi], "2df", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT128:
+	  memcpy (&buf[*bufi], "1ti", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT128:
+	  memcpy (&buf[*bufi], "1tf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_VPAIR:
+	  memcpy (&buf[*bufi], "1poi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_VQUAD:
+	  memcpy (&buf[*bufi], "1pxi", 4);
+	  *bufi += 4;
+	  break;
+	default:
+	  (*diag) ("unhandled basetype %d.\n", typeptr->base);
+	  exit (1);
+	}
+    }
+}
+
+/* Convert a base type into a mode string.  */
+static void
+complete_base_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  switch (typeptr->base)
+    {
+    case BT_CHAR:
+      memcpy (&buf[*bufi], "qi", 2);
+      break;
+    case BT_SHORT:
+      memcpy (&buf[*bufi], "hi", 2);
+      break;
+    case BT_INT:
+      memcpy (&buf[*bufi], "si", 2);
+      break;
+    case BT_LONG:
+      memcpy (&buf[*bufi], "lg", 2);
+      break;
+    case BT_LONGLONG:
+      memcpy (&buf[*bufi], "di", 2);
+      break;
+    case BT_FLOAT:
+      memcpy (&buf[*bufi], "sf", 2);
+      break;
+    case BT_DOUBLE:
+      memcpy (&buf[*bufi], "df", 2);
+      break;
+    case BT_LONGDOUBLE:
+      memcpy (&buf[*bufi], "ld", 2);
+      break;
+    case BT_INT128:
+      memcpy (&buf[*bufi], "ti", 2);
+      break;
+    case BT_FLOAT128:
+      memcpy (&buf[*bufi], "tf", 2);
+      break;
+    case BT_BOOL:
+      memcpy (&buf[*bufi], "bi", 2);
+      break;
+    case BT_STRING:
+      memcpy (&buf[*bufi], "st", 2);
+      break;
+    case BT_DECIMAL32:
+      memcpy (&buf[*bufi], "sd", 2);
+      break;
+    case BT_DECIMAL64:
+      memcpy (&buf[*bufi], "dd", 2);
+      break;
+    case BT_DECIMAL128:
+      memcpy (&buf[*bufi], "td", 2);
+      break;
+    case BT_IBM128:
+      memcpy (&buf[*bufi], "if", 2);
+      break;
+    default:
+      (*diag) ("unhandled basetype %d.\n", typeptr->base);
+      exit (1);
+    }
+
+  *bufi += 2;
+}
+
+/* Build a function type descriptor identifier from the return type
+   and argument types described by PROTOPTR, and store it if it does
+   not already exist.  Return the identifier.  */
+static char *
+construct_fntype_id (prototype *protoptr)
+{
+  /* Determine the maximum space for a function type descriptor id.
+     Each type requires at most 9 characters (6 for the mode*, 1 for
+     the optional 'u' preceding the mode, 1 for the optional 'p'
+     preceding the mode, and 1 for an underscore following the mode).
+     We also need 5 characters for the string "ftype" that separates
+     the return mode from the argument modes.  The last argument doesn't
+     need a trailing underscore, but we count that as the one trailing
+     "ftype" instead.  For the special case of zero arguments, we need 9
+     for the return type and 7 for "ftype_v".  Finally, we need one
+     character for the terminating null.  Thus for a function with N
+     arguments, we need at most 9N+15 characters for N>0, otherwise 17.
+     ----
+       *Worst case is bv16qi for "vector bool char".  */
+  int len = protoptr->nargs ? (protoptr->nargs + 1) * 9 + 6 : 17;
+  char *buf = (char *) malloc (len);
+  int bufi = 0;
+
+  if (protoptr->rettype.ispointer)
+    buf[bufi++] = 'p';
+
+  if (protoptr->rettype.isvoid)
+    buf[bufi++] = 'v';
+  else
+    {
+      if (protoptr->rettype.isunsigned)
+	buf[bufi++] = 'u';
+      if (protoptr->rettype.isvector)
+	complete_vector_type (&protoptr->rettype, buf, &bufi);
+      else
+	complete_base_type (&protoptr->rettype, buf, &bufi);
+    }
+
+  memcpy (&buf[bufi], "_ftype", 6);
+  bufi += 6;
+
+  if (!protoptr->nargs)
+    {
+      memcpy (&buf[bufi], "_v", 2);
+      bufi += 2;
+    }
+  else
+    {
+      typelist *argptr = protoptr->args;
+      for (int i = 0; i < protoptr->nargs; i++, argptr = argptr->next)
+	{
+	  assert (argptr);
+	  buf[bufi++] = '_';
+	  if (argptr->info.isconst
+	      && argptr->info.base == BT_INT
+	      && !argptr->info.ispointer)
+	    {
+	      buf[bufi++] = 'c';
+	      buf[bufi++] = 'i';
+	      continue;
+	    }
+	  if (argptr->info.ispointer)
+	    {
+	      if (argptr->info.isvoid)
+		{
+		  if (argptr->info.isconst)
+		    {
+		      memcpy (&buf[bufi], "pcvoid", 6);
+		      bufi += 6;
+		      continue;
+		    }
+		  else
+		    {
+		      buf[bufi++] = 'p';
+		      buf[bufi++] = 'v';
+		      continue;
+		    }
+		}
+	      else
+		buf[bufi++] = 'p';
+	    }
+
+	  if (argptr->info.isunsigned)
+	    buf[bufi++] = 'u';
+	  if (argptr->info.isvector)
+	    complete_vector_type (&argptr->info, buf, &bufi);
+	  else
+	    complete_base_type (&argptr->info, buf, &bufi);
+	}
+      assert (!argptr);
+      }
+
+  buf[bufi] = '\0';
+
+  /* Ignore return value, as duplicates are expected.  */
+  (void) rbt_insert (&fntype_rbt, buf);
+
+  return buf;
+}
+
 /* Parse a function prototype.  This code is shared by the bif and overload
    file processing.  */
 static parse_codes
@@ -1391,6 +1616,10 @@ parse_bif_entry (void)
   if (parse_prototype (&bifs[curr_bif].proto) == PC_PARSEFAIL)
     return PC_PARSEFAIL;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  bifs[curr_bif].fndecl = construct_fntype_id (&bifs[curr_bif].proto);
+
   /* Now process line 2.  First up is the builtin id.  */
   if (!advance_line (bif_file))
     {
@@ -1568,6 +1797,10 @@ parse_ovld_entry (void)
   if (ovlds[curr_ovld].proto.nargs > max_ovld_args)
     max_ovld_args = ovlds[curr_ovld].proto.nargs;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  ovlds[curr_ovld].fndecl = construct_fntype_id (&ovlds[curr_ovld].proto);
+
   /* Now process line 2, which just contains the builtin id and an
      optional overload id.  */
   if (!advance_line (ovld_file))


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers
@ 2021-04-26 20:49 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-26 20:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:900e1c2fc9be442198f2adb59a015606dbe333b7

commit 900e1c2fc9be442198f2adb59a015606dbe333b7
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Fri Apr 2 16:38:08 2021 -0500

    rs6000: Build and store function type identifiers
    
    2021-04-02  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-gen-builtins.c (complete_vector_type): New
            function.
            (complete_base_type): Likewise.
            (construct_fntype_id): Likewise.
            (parse_bif_entry): Call construct_fntype_id.
            (parse_ovld_entry): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 233 ++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index d5deefbfd3b..0358ff26414 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -1313,6 +1313,231 @@ endian = %d.\n",
   return PC_OK;
 }
 
+/* Convert a vector type into a mode string.  */
+static void
+complete_vector_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  if (typeptr->isbool)
+    buf[(*bufi)++] = 'b';
+  buf[(*bufi)++] = 'v';
+  if (typeptr->ispixel)
+    {
+      memcpy (&buf[*bufi], "p8hi", 4);
+      *bufi += 4;
+    }
+  else
+    {
+      switch (typeptr->base)
+	{
+	case BT_CHAR:
+	  memcpy (&buf[*bufi], "16qi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_SHORT:
+	  memcpy (&buf[*bufi], "8hi", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT:
+	  memcpy (&buf[*bufi], "4si", 3);
+	  *bufi += 3;
+	  break;
+	case BT_LONGLONG:
+	  memcpy (&buf[*bufi], "2di", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT:
+	  memcpy (&buf[*bufi], "4sf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_DOUBLE:
+	  memcpy (&buf[*bufi], "2df", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT128:
+	  memcpy (&buf[*bufi], "1ti", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT128:
+	  memcpy (&buf[*bufi], "1tf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_VPAIR:
+	  memcpy (&buf[*bufi], "1poi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_VQUAD:
+	  memcpy (&buf[*bufi], "1pxi", 4);
+	  *bufi += 4;
+	  break;
+	default:
+	  (*diag) ("unhandled basetype %d.\n", typeptr->base);
+	  exit (EC_INTERR);
+	}
+    }
+}
+
+/* Convert a base type into a mode string.  */
+static void
+complete_base_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  switch (typeptr->base)
+    {
+    case BT_CHAR:
+      memcpy (&buf[*bufi], "qi", 2);
+      break;
+    case BT_SHORT:
+      memcpy (&buf[*bufi], "hi", 2);
+      break;
+    case BT_INT:
+      memcpy (&buf[*bufi], "si", 2);
+      break;
+    case BT_LONG:
+      memcpy (&buf[*bufi], "lg", 2);
+      break;
+    case BT_LONGLONG:
+      memcpy (&buf[*bufi], "di", 2);
+      break;
+    case BT_FLOAT:
+      memcpy (&buf[*bufi], "sf", 2);
+      break;
+    case BT_DOUBLE:
+      memcpy (&buf[*bufi], "df", 2);
+      break;
+    case BT_LONGDOUBLE:
+      memcpy (&buf[*bufi], "ld", 2);
+      break;
+    case BT_INT128:
+      memcpy (&buf[*bufi], "ti", 2);
+      break;
+    case BT_FLOAT128:
+      memcpy (&buf[*bufi], "tf", 2);
+      break;
+    case BT_BOOL:
+      memcpy (&buf[*bufi], "bi", 2);
+      break;
+    case BT_STRING:
+      memcpy (&buf[*bufi], "st", 2);
+      break;
+    case BT_DECIMAL32:
+      memcpy (&buf[*bufi], "sd", 2);
+      break;
+    case BT_DECIMAL64:
+      memcpy (&buf[*bufi], "dd", 2);
+      break;
+    case BT_DECIMAL128:
+      memcpy (&buf[*bufi], "td", 2);
+      break;
+    case BT_IBM128:
+      memcpy (&buf[*bufi], "if", 2);
+      break;
+    default:
+      (*diag) ("unhandled basetype %d.\n", typeptr->base);
+      exit (EC_INTERR);
+    }
+
+  *bufi += 2;
+}
+
+/* Build a function type descriptor identifier from the return type
+   and argument types described by PROTOPTR, and store it if it does
+   not already exist.  Return the identifier.  */
+static char *
+construct_fntype_id (prototype *protoptr)
+{
+  /* Determine the maximum space for a function type descriptor id.
+     Each type requires at most 9 characters (6 for the mode*, 1 for
+     the optional 'u' preceding the mode, 1 for the optional 'p'
+     preceding the mode, and 1 for an underscore following the mode).
+     We also need 5 characters for the string "ftype" that separates
+     the return mode from the argument modes.  The last argument doesn't
+     need a trailing underscore, but we count that as the one trailing
+     "ftype" instead.  For the special case of zero arguments, we need 9
+     for the return type and 7 for "ftype_v".  Finally, we need one
+     character for the terminating null.  Thus for a function with N
+     arguments, we need at most 9N+15 characters for N>0, otherwise 17.
+     ----
+       *Worst case is bv16qi for "vector bool char".  */
+  int len = protoptr->nargs ? (protoptr->nargs + 1) * 9 + 6 : 17;
+  char *buf = (char *) malloc (len);
+  int bufi = 0;
+
+  if (protoptr->rettype.ispointer)
+    buf[bufi++] = 'p';
+
+  if (protoptr->rettype.isvoid)
+    buf[bufi++] = 'v';
+  else
+    {
+      if (protoptr->rettype.isunsigned)
+	buf[bufi++] = 'u';
+      if (protoptr->rettype.isvector)
+	complete_vector_type (&protoptr->rettype, buf, &bufi);
+      else
+	complete_base_type (&protoptr->rettype, buf, &bufi);
+    }
+
+  memcpy (&buf[bufi], "_ftype", 6);
+  bufi += 6;
+
+  if (!protoptr->nargs)
+    {
+      memcpy (&buf[bufi], "_v", 2);
+      bufi += 2;
+    }
+  else
+    {
+      typelist *argptr = protoptr->args;
+      for (int i = 0; i < protoptr->nargs; i++, argptr = argptr->next)
+	{
+	  assert (argptr);
+	  buf[bufi++] = '_';
+	  if (argptr->info.isconst
+	      && argptr->info.base == BT_INT
+	      && !argptr->info.ispointer)
+	    {
+	      buf[bufi++] = 'c';
+	      buf[bufi++] = 'i';
+	      continue;
+	    }
+	  if (argptr->info.ispointer)
+	    {
+	      if (argptr->info.isvoid)
+		{
+		  if (argptr->info.isconst)
+		    {
+		      memcpy (&buf[bufi], "pcvoid", 6);
+		      bufi += 6;
+		      continue;
+		    }
+		  else
+		    {
+		      buf[bufi++] = 'p';
+		      buf[bufi++] = 'v';
+		      continue;
+		    }
+		}
+	      else
+		buf[bufi++] = 'p';
+	    }
+
+	  if (argptr->info.isunsigned)
+	    buf[bufi++] = 'u';
+	  if (argptr->info.isvector)
+	    complete_vector_type (&argptr->info, buf, &bufi);
+	  else
+	    complete_base_type (&argptr->info, buf, &bufi);
+	}
+      assert (!argptr);
+      }
+
+  buf[bufi] = '\0';
+
+  /* Ignore return value, as duplicates are expected.  */
+  (void) rbt_insert (&fntype_rbt, buf);
+
+  return buf;
+}
+
 /* Parse a function prototype.  This code is shared by the bif and overload
    file processing.  */
 static parse_codes
@@ -1425,6 +1650,10 @@ parse_bif_entry ()
   if (parse_prototype (&bifs[curr_bif].proto) == PC_PARSEFAIL)
     return PC_PARSEFAIL;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  bifs[curr_bif].fndecl = construct_fntype_id (&bifs[curr_bif].proto);
+
   /* Now process line 2.  First up is the builtin id.  */
   if (!advance_line (bif_file))
     {
@@ -1602,6 +1831,10 @@ parse_ovld_entry ()
   if (ovlds[curr_ovld].proto.nargs > max_ovld_args)
     max_ovld_args = ovlds[curr_ovld].proto.nargs;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  ovlds[curr_ovld].fndecl = construct_fntype_id (&ovlds[curr_ovld].proto);
+
   /* Now process line 2, which just contains the builtin id and an
      optional overload id.  */
   if (!advance_line (ovld_file))


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers
@ 2021-04-02 22:09 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-02 22:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c1bbfd479c886e9b1a168aa832bdd7067763a73a

commit c1bbfd479c886e9b1a168aa832bdd7067763a73a
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Fri Apr 2 16:38:08 2021 -0500

    rs6000: Build and store function type identifiers
    
    2021-04-02  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-gen-builtins.c (complete_vector_type): New
            function.
            (complete_base_type): Likewise.
            (construct_fntype_id): Likewise.
            (parse_bif_entry): Call construct_fntype_id.
            (parse_ovld_entry): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 233 ++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index d5deefbfd3b..0358ff26414 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -1313,6 +1313,231 @@ endian = %d.\n",
   return PC_OK;
 }
 
+/* Convert a vector type into a mode string.  */
+static void
+complete_vector_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  if (typeptr->isbool)
+    buf[(*bufi)++] = 'b';
+  buf[(*bufi)++] = 'v';
+  if (typeptr->ispixel)
+    {
+      memcpy (&buf[*bufi], "p8hi", 4);
+      *bufi += 4;
+    }
+  else
+    {
+      switch (typeptr->base)
+	{
+	case BT_CHAR:
+	  memcpy (&buf[*bufi], "16qi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_SHORT:
+	  memcpy (&buf[*bufi], "8hi", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT:
+	  memcpy (&buf[*bufi], "4si", 3);
+	  *bufi += 3;
+	  break;
+	case BT_LONGLONG:
+	  memcpy (&buf[*bufi], "2di", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT:
+	  memcpy (&buf[*bufi], "4sf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_DOUBLE:
+	  memcpy (&buf[*bufi], "2df", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT128:
+	  memcpy (&buf[*bufi], "1ti", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT128:
+	  memcpy (&buf[*bufi], "1tf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_VPAIR:
+	  memcpy (&buf[*bufi], "1poi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_VQUAD:
+	  memcpy (&buf[*bufi], "1pxi", 4);
+	  *bufi += 4;
+	  break;
+	default:
+	  (*diag) ("unhandled basetype %d.\n", typeptr->base);
+	  exit (EC_INTERR);
+	}
+    }
+}
+
+/* Convert a base type into a mode string.  */
+static void
+complete_base_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  switch (typeptr->base)
+    {
+    case BT_CHAR:
+      memcpy (&buf[*bufi], "qi", 2);
+      break;
+    case BT_SHORT:
+      memcpy (&buf[*bufi], "hi", 2);
+      break;
+    case BT_INT:
+      memcpy (&buf[*bufi], "si", 2);
+      break;
+    case BT_LONG:
+      memcpy (&buf[*bufi], "lg", 2);
+      break;
+    case BT_LONGLONG:
+      memcpy (&buf[*bufi], "di", 2);
+      break;
+    case BT_FLOAT:
+      memcpy (&buf[*bufi], "sf", 2);
+      break;
+    case BT_DOUBLE:
+      memcpy (&buf[*bufi], "df", 2);
+      break;
+    case BT_LONGDOUBLE:
+      memcpy (&buf[*bufi], "ld", 2);
+      break;
+    case BT_INT128:
+      memcpy (&buf[*bufi], "ti", 2);
+      break;
+    case BT_FLOAT128:
+      memcpy (&buf[*bufi], "tf", 2);
+      break;
+    case BT_BOOL:
+      memcpy (&buf[*bufi], "bi", 2);
+      break;
+    case BT_STRING:
+      memcpy (&buf[*bufi], "st", 2);
+      break;
+    case BT_DECIMAL32:
+      memcpy (&buf[*bufi], "sd", 2);
+      break;
+    case BT_DECIMAL64:
+      memcpy (&buf[*bufi], "dd", 2);
+      break;
+    case BT_DECIMAL128:
+      memcpy (&buf[*bufi], "td", 2);
+      break;
+    case BT_IBM128:
+      memcpy (&buf[*bufi], "if", 2);
+      break;
+    default:
+      (*diag) ("unhandled basetype %d.\n", typeptr->base);
+      exit (EC_INTERR);
+    }
+
+  *bufi += 2;
+}
+
+/* Build a function type descriptor identifier from the return type
+   and argument types described by PROTOPTR, and store it if it does
+   not already exist.  Return the identifier.  */
+static char *
+construct_fntype_id (prototype *protoptr)
+{
+  /* Determine the maximum space for a function type descriptor id.
+     Each type requires at most 9 characters (6 for the mode*, 1 for
+     the optional 'u' preceding the mode, 1 for the optional 'p'
+     preceding the mode, and 1 for an underscore following the mode).
+     We also need 5 characters for the string "ftype" that separates
+     the return mode from the argument modes.  The last argument doesn't
+     need a trailing underscore, but we count that as the one trailing
+     "ftype" instead.  For the special case of zero arguments, we need 9
+     for the return type and 7 for "ftype_v".  Finally, we need one
+     character for the terminating null.  Thus for a function with N
+     arguments, we need at most 9N+15 characters for N>0, otherwise 17.
+     ----
+       *Worst case is bv16qi for "vector bool char".  */
+  int len = protoptr->nargs ? (protoptr->nargs + 1) * 9 + 6 : 17;
+  char *buf = (char *) malloc (len);
+  int bufi = 0;
+
+  if (protoptr->rettype.ispointer)
+    buf[bufi++] = 'p';
+
+  if (protoptr->rettype.isvoid)
+    buf[bufi++] = 'v';
+  else
+    {
+      if (protoptr->rettype.isunsigned)
+	buf[bufi++] = 'u';
+      if (protoptr->rettype.isvector)
+	complete_vector_type (&protoptr->rettype, buf, &bufi);
+      else
+	complete_base_type (&protoptr->rettype, buf, &bufi);
+    }
+
+  memcpy (&buf[bufi], "_ftype", 6);
+  bufi += 6;
+
+  if (!protoptr->nargs)
+    {
+      memcpy (&buf[bufi], "_v", 2);
+      bufi += 2;
+    }
+  else
+    {
+      typelist *argptr = protoptr->args;
+      for (int i = 0; i < protoptr->nargs; i++, argptr = argptr->next)
+	{
+	  assert (argptr);
+	  buf[bufi++] = '_';
+	  if (argptr->info.isconst
+	      && argptr->info.base == BT_INT
+	      && !argptr->info.ispointer)
+	    {
+	      buf[bufi++] = 'c';
+	      buf[bufi++] = 'i';
+	      continue;
+	    }
+	  if (argptr->info.ispointer)
+	    {
+	      if (argptr->info.isvoid)
+		{
+		  if (argptr->info.isconst)
+		    {
+		      memcpy (&buf[bufi], "pcvoid", 6);
+		      bufi += 6;
+		      continue;
+		    }
+		  else
+		    {
+		      buf[bufi++] = 'p';
+		      buf[bufi++] = 'v';
+		      continue;
+		    }
+		}
+	      else
+		buf[bufi++] = 'p';
+	    }
+
+	  if (argptr->info.isunsigned)
+	    buf[bufi++] = 'u';
+	  if (argptr->info.isvector)
+	    complete_vector_type (&argptr->info, buf, &bufi);
+	  else
+	    complete_base_type (&argptr->info, buf, &bufi);
+	}
+      assert (!argptr);
+      }
+
+  buf[bufi] = '\0';
+
+  /* Ignore return value, as duplicates are expected.  */
+  (void) rbt_insert (&fntype_rbt, buf);
+
+  return buf;
+}
+
 /* Parse a function prototype.  This code is shared by the bif and overload
    file processing.  */
 static parse_codes
@@ -1425,6 +1650,10 @@ parse_bif_entry ()
   if (parse_prototype (&bifs[curr_bif].proto) == PC_PARSEFAIL)
     return PC_PARSEFAIL;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  bifs[curr_bif].fndecl = construct_fntype_id (&bifs[curr_bif].proto);
+
   /* Now process line 2.  First up is the builtin id.  */
   if (!advance_line (bif_file))
     {
@@ -1602,6 +1831,10 @@ parse_ovld_entry ()
   if (ovlds[curr_ovld].proto.nargs > max_ovld_args)
     max_ovld_args = ovlds[curr_ovld].proto.nargs;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  ovlds[curr_ovld].fndecl = construct_fntype_id (&ovlds[curr_ovld].proto);
+
   /* Now process line 2, which just contains the builtin id and an
      optional overload id.  */
   if (!advance_line (ovld_file))


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers
@ 2021-04-01 19:48 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-01 19:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3dbe297666ec661bb5b2f328e4205b2bbae50d21

commit 3dbe297666ec661bb5b2f328e4205b2bbae50d21
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Wed Mar 3 16:24:25 2021 -0600

    rs6000: Build and store function type identifiers
    
    2021-03-03  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-gen-builtins.c (complete_vector_type): New
            function.
            (complete_base_type): Likewise.
            (construct_fntype_id): Likewise.
            (parse_bif_entry): Call construct_fntype_id.
            (parse_ovld_entry): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 233 ++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index 36a2f3b9991..b085ceb7ae3 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -1312,6 +1312,231 @@ endian = %d.\n",
   return PC_OK;
 }
 
+/* Convert a vector type into a mode string.  */
+static void
+complete_vector_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  if (typeptr->isbool)
+    buf[(*bufi)++] = 'b';
+  buf[(*bufi)++] = 'v';
+  if (typeptr->ispixel)
+    {
+      memcpy (&buf[*bufi], "p8hi", 4);
+      *bufi += 4;
+    }
+  else
+    {
+      switch (typeptr->base)
+	{
+	case BT_CHAR:
+	  memcpy (&buf[*bufi], "16qi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_SHORT:
+	  memcpy (&buf[*bufi], "8hi", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT:
+	  memcpy (&buf[*bufi], "4si", 3);
+	  *bufi += 3;
+	  break;
+	case BT_LONGLONG:
+	  memcpy (&buf[*bufi], "2di", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT:
+	  memcpy (&buf[*bufi], "4sf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_DOUBLE:
+	  memcpy (&buf[*bufi], "2df", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT128:
+	  memcpy (&buf[*bufi], "1ti", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT128:
+	  memcpy (&buf[*bufi], "1tf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_VPAIR:
+	  memcpy (&buf[*bufi], "1poi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_VQUAD:
+	  memcpy (&buf[*bufi], "1pxi", 4);
+	  *bufi += 4;
+	  break;
+	default:
+	  (*diag) ("unhandled basetype %d.\n", typeptr->base);
+	  exit (EC_INTERR);
+	}
+    }
+}
+
+/* Convert a base type into a mode string.  */
+static void
+complete_base_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  switch (typeptr->base)
+    {
+    case BT_CHAR:
+      memcpy (&buf[*bufi], "qi", 2);
+      break;
+    case BT_SHORT:
+      memcpy (&buf[*bufi], "hi", 2);
+      break;
+    case BT_INT:
+      memcpy (&buf[*bufi], "si", 2);
+      break;
+    case BT_LONG:
+      memcpy (&buf[*bufi], "lg", 2);
+      break;
+    case BT_LONGLONG:
+      memcpy (&buf[*bufi], "di", 2);
+      break;
+    case BT_FLOAT:
+      memcpy (&buf[*bufi], "sf", 2);
+      break;
+    case BT_DOUBLE:
+      memcpy (&buf[*bufi], "df", 2);
+      break;
+    case BT_LONGDOUBLE:
+      memcpy (&buf[*bufi], "ld", 2);
+      break;
+    case BT_INT128:
+      memcpy (&buf[*bufi], "ti", 2);
+      break;
+    case BT_FLOAT128:
+      memcpy (&buf[*bufi], "tf", 2);
+      break;
+    case BT_BOOL:
+      memcpy (&buf[*bufi], "bi", 2);
+      break;
+    case BT_STRING:
+      memcpy (&buf[*bufi], "st", 2);
+      break;
+    case BT_DECIMAL32:
+      memcpy (&buf[*bufi], "sd", 2);
+      break;
+    case BT_DECIMAL64:
+      memcpy (&buf[*bufi], "dd", 2);
+      break;
+    case BT_DECIMAL128:
+      memcpy (&buf[*bufi], "td", 2);
+      break;
+    case BT_IBM128:
+      memcpy (&buf[*bufi], "if", 2);
+      break;
+    default:
+      (*diag) ("unhandled basetype %d.\n", typeptr->base);
+      exit (EC_INTERR);
+    }
+
+  *bufi += 2;
+}
+
+/* Build a function type descriptor identifier from the return type
+   and argument types described by PROTOPTR, and store it if it does
+   not already exist.  Return the identifier.  */
+static char *
+construct_fntype_id (prototype *protoptr)
+{
+  /* Determine the maximum space for a function type descriptor id.
+     Each type requires at most 9 characters (6 for the mode*, 1 for
+     the optional 'u' preceding the mode, 1 for the optional 'p'
+     preceding the mode, and 1 for an underscore following the mode).
+     We also need 5 characters for the string "ftype" that separates
+     the return mode from the argument modes.  The last argument doesn't
+     need a trailing underscore, but we count that as the one trailing
+     "ftype" instead.  For the special case of zero arguments, we need 9
+     for the return type and 7 for "ftype_v".  Finally, we need one
+     character for the terminating null.  Thus for a function with N
+     arguments, we need at most 9N+14 characters for N>0, otherwise 17.
+     ----
+       *Worst case is bv16qi for "vector bool char".  */
+  int len = protoptr->nargs ? (protoptr->nargs + 1) * 9 + 6 : 17;
+  char *buf = (char *) malloc (len);
+  int bufi = 0;
+
+  if (protoptr->rettype.ispointer)
+    buf[bufi++] = 'p';
+
+  if (protoptr->rettype.isvoid)
+    buf[bufi++] = 'v';
+  else
+    {
+      if (protoptr->rettype.isunsigned)
+	buf[bufi++] = 'u';
+      if (protoptr->rettype.isvector)
+	complete_vector_type (&protoptr->rettype, buf, &bufi);
+      else
+	complete_base_type (&protoptr->rettype, buf, &bufi);
+    }
+
+  memcpy (&buf[bufi], "_ftype", 6);
+  bufi += 6;
+
+  if (!protoptr->nargs)
+    {
+      memcpy (&buf[bufi], "_v", 2);
+      bufi += 2;
+    }
+  else
+    {
+      typelist *argptr = protoptr->args;
+      for (int i = 0; i < protoptr->nargs; i++, argptr = argptr->next)
+	{
+	  assert (argptr);
+	  buf[bufi++] = '_';
+	  if (argptr->info.isconst
+	      && argptr->info.base == BT_INT
+	      && !argptr->info.ispointer)
+	    {
+	      buf[bufi++] = 'c';
+	      buf[bufi++] = 'i';
+	      continue;
+	    }
+	  if (argptr->info.ispointer)
+	    {
+	      if (argptr->info.isvoid)
+		{
+		  if (argptr->info.isconst)
+		    {
+		      memcpy (&buf[bufi], "pcvoid", 6);
+		      bufi += 6;
+		      continue;
+		    }
+		  else
+		    {
+		      buf[bufi++] = 'p';
+		      buf[bufi++] = 'v';
+		      continue;
+		    }
+		}
+	      else
+		buf[bufi++] = 'p';
+	    }
+
+	  if (argptr->info.isunsigned)
+	    buf[bufi++] = 'u';
+	  if (argptr->info.isvector)
+	    complete_vector_type (&argptr->info, buf, &bufi);
+	  else
+	    complete_base_type (&argptr->info, buf, &bufi);
+	}
+      assert (!argptr);
+      }
+
+  buf[bufi] = '\0';
+
+  /* Ignore return value, as duplicates are expected.  */
+  (void) rbt_insert (&fntype_rbt, buf);
+
+  return buf;
+}
+
 /* Parse a function prototype.  This code is shared by the bif and overload
    file processing.  */
 static parse_codes
@@ -1424,6 +1649,10 @@ parse_bif_entry ()
   if (parse_prototype (&bifs[curr_bif].proto) == PC_PARSEFAIL)
     return PC_PARSEFAIL;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  bifs[curr_bif].fndecl = construct_fntype_id (&bifs[curr_bif].proto);
+
   /* Now process line 2.  First up is the builtin id.  */
   if (!advance_line (bif_file))
     {
@@ -1601,6 +1830,10 @@ parse_ovld_entry ()
   if (ovlds[curr_ovld].proto.nargs > max_ovld_args)
     max_ovld_args = ovlds[curr_ovld].proto.nargs;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  ovlds[curr_ovld].fndecl = construct_fntype_id (&ovlds[curr_ovld].proto);
+
   /* Now process line 2, which just contains the builtin id and an
      optional overload id.  */
   if (!advance_line (ovld_file))


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers
@ 2021-03-25 15:45 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-03-25 15:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b1861ece501259df43e58b9b22261aef13dc4fc2

commit b1861ece501259df43e58b9b22261aef13dc4fc2
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Wed Mar 3 16:24:25 2021 -0600

    rs6000: Build and store function type identifiers
    
    2021-03-03  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-gen-builtins.c (complete_vector_type): New
            function.
            (complete_base_type): Likewise.
            (construct_fntype_id): Likewise.
            (parse_bif_entry): Call construct_fntype_id.
            (parse_ovld_entry): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 233 ++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index 36a2f3b9991..b085ceb7ae3 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -1312,6 +1312,231 @@ endian = %d.\n",
   return PC_OK;
 }
 
+/* Convert a vector type into a mode string.  */
+static void
+complete_vector_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  if (typeptr->isbool)
+    buf[(*bufi)++] = 'b';
+  buf[(*bufi)++] = 'v';
+  if (typeptr->ispixel)
+    {
+      memcpy (&buf[*bufi], "p8hi", 4);
+      *bufi += 4;
+    }
+  else
+    {
+      switch (typeptr->base)
+	{
+	case BT_CHAR:
+	  memcpy (&buf[*bufi], "16qi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_SHORT:
+	  memcpy (&buf[*bufi], "8hi", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT:
+	  memcpy (&buf[*bufi], "4si", 3);
+	  *bufi += 3;
+	  break;
+	case BT_LONGLONG:
+	  memcpy (&buf[*bufi], "2di", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT:
+	  memcpy (&buf[*bufi], "4sf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_DOUBLE:
+	  memcpy (&buf[*bufi], "2df", 3);
+	  *bufi += 3;
+	  break;
+	case BT_INT128:
+	  memcpy (&buf[*bufi], "1ti", 3);
+	  *bufi += 3;
+	  break;
+	case BT_FLOAT128:
+	  memcpy (&buf[*bufi], "1tf", 3);
+	  *bufi += 3;
+	  break;
+	case BT_VPAIR:
+	  memcpy (&buf[*bufi], "1poi", 4);
+	  *bufi += 4;
+	  break;
+	case BT_VQUAD:
+	  memcpy (&buf[*bufi], "1pxi", 4);
+	  *bufi += 4;
+	  break;
+	default:
+	  (*diag) ("unhandled basetype %d.\n", typeptr->base);
+	  exit (EC_INTERR);
+	}
+    }
+}
+
+/* Convert a base type into a mode string.  */
+static void
+complete_base_type (typeinfo *typeptr, char *buf, int *bufi)
+{
+  switch (typeptr->base)
+    {
+    case BT_CHAR:
+      memcpy (&buf[*bufi], "qi", 2);
+      break;
+    case BT_SHORT:
+      memcpy (&buf[*bufi], "hi", 2);
+      break;
+    case BT_INT:
+      memcpy (&buf[*bufi], "si", 2);
+      break;
+    case BT_LONG:
+      memcpy (&buf[*bufi], "lg", 2);
+      break;
+    case BT_LONGLONG:
+      memcpy (&buf[*bufi], "di", 2);
+      break;
+    case BT_FLOAT:
+      memcpy (&buf[*bufi], "sf", 2);
+      break;
+    case BT_DOUBLE:
+      memcpy (&buf[*bufi], "df", 2);
+      break;
+    case BT_LONGDOUBLE:
+      memcpy (&buf[*bufi], "ld", 2);
+      break;
+    case BT_INT128:
+      memcpy (&buf[*bufi], "ti", 2);
+      break;
+    case BT_FLOAT128:
+      memcpy (&buf[*bufi], "tf", 2);
+      break;
+    case BT_BOOL:
+      memcpy (&buf[*bufi], "bi", 2);
+      break;
+    case BT_STRING:
+      memcpy (&buf[*bufi], "st", 2);
+      break;
+    case BT_DECIMAL32:
+      memcpy (&buf[*bufi], "sd", 2);
+      break;
+    case BT_DECIMAL64:
+      memcpy (&buf[*bufi], "dd", 2);
+      break;
+    case BT_DECIMAL128:
+      memcpy (&buf[*bufi], "td", 2);
+      break;
+    case BT_IBM128:
+      memcpy (&buf[*bufi], "if", 2);
+      break;
+    default:
+      (*diag) ("unhandled basetype %d.\n", typeptr->base);
+      exit (EC_INTERR);
+    }
+
+  *bufi += 2;
+}
+
+/* Build a function type descriptor identifier from the return type
+   and argument types described by PROTOPTR, and store it if it does
+   not already exist.  Return the identifier.  */
+static char *
+construct_fntype_id (prototype *protoptr)
+{
+  /* Determine the maximum space for a function type descriptor id.
+     Each type requires at most 9 characters (6 for the mode*, 1 for
+     the optional 'u' preceding the mode, 1 for the optional 'p'
+     preceding the mode, and 1 for an underscore following the mode).
+     We also need 5 characters for the string "ftype" that separates
+     the return mode from the argument modes.  The last argument doesn't
+     need a trailing underscore, but we count that as the one trailing
+     "ftype" instead.  For the special case of zero arguments, we need 9
+     for the return type and 7 for "ftype_v".  Finally, we need one
+     character for the terminating null.  Thus for a function with N
+     arguments, we need at most 9N+14 characters for N>0, otherwise 17.
+     ----
+       *Worst case is bv16qi for "vector bool char".  */
+  int len = protoptr->nargs ? (protoptr->nargs + 1) * 9 + 6 : 17;
+  char *buf = (char *) malloc (len);
+  int bufi = 0;
+
+  if (protoptr->rettype.ispointer)
+    buf[bufi++] = 'p';
+
+  if (protoptr->rettype.isvoid)
+    buf[bufi++] = 'v';
+  else
+    {
+      if (protoptr->rettype.isunsigned)
+	buf[bufi++] = 'u';
+      if (protoptr->rettype.isvector)
+	complete_vector_type (&protoptr->rettype, buf, &bufi);
+      else
+	complete_base_type (&protoptr->rettype, buf, &bufi);
+    }
+
+  memcpy (&buf[bufi], "_ftype", 6);
+  bufi += 6;
+
+  if (!protoptr->nargs)
+    {
+      memcpy (&buf[bufi], "_v", 2);
+      bufi += 2;
+    }
+  else
+    {
+      typelist *argptr = protoptr->args;
+      for (int i = 0; i < protoptr->nargs; i++, argptr = argptr->next)
+	{
+	  assert (argptr);
+	  buf[bufi++] = '_';
+	  if (argptr->info.isconst
+	      && argptr->info.base == BT_INT
+	      && !argptr->info.ispointer)
+	    {
+	      buf[bufi++] = 'c';
+	      buf[bufi++] = 'i';
+	      continue;
+	    }
+	  if (argptr->info.ispointer)
+	    {
+	      if (argptr->info.isvoid)
+		{
+		  if (argptr->info.isconst)
+		    {
+		      memcpy (&buf[bufi], "pcvoid", 6);
+		      bufi += 6;
+		      continue;
+		    }
+		  else
+		    {
+		      buf[bufi++] = 'p';
+		      buf[bufi++] = 'v';
+		      continue;
+		    }
+		}
+	      else
+		buf[bufi++] = 'p';
+	    }
+
+	  if (argptr->info.isunsigned)
+	    buf[bufi++] = 'u';
+	  if (argptr->info.isvector)
+	    complete_vector_type (&argptr->info, buf, &bufi);
+	  else
+	    complete_base_type (&argptr->info, buf, &bufi);
+	}
+      assert (!argptr);
+      }
+
+  buf[bufi] = '\0';
+
+  /* Ignore return value, as duplicates are expected.  */
+  (void) rbt_insert (&fntype_rbt, buf);
+
+  return buf;
+}
+
 /* Parse a function prototype.  This code is shared by the bif and overload
    file processing.  */
 static parse_codes
@@ -1424,6 +1649,10 @@ parse_bif_entry ()
   if (parse_prototype (&bifs[curr_bif].proto) == PC_PARSEFAIL)
     return PC_PARSEFAIL;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  bifs[curr_bif].fndecl = construct_fntype_id (&bifs[curr_bif].proto);
+
   /* Now process line 2.  First up is the builtin id.  */
   if (!advance_line (bif_file))
     {
@@ -1601,6 +1830,10 @@ parse_ovld_entry ()
   if (ovlds[curr_ovld].proto.nargs > max_ovld_args)
     max_ovld_args = ovlds[curr_ovld].proto.nargs;
 
+  /* Build a function type descriptor identifier from the return type
+     and argument types, and store it if it does not already exist.  */
+  ovlds[curr_ovld].fndecl = construct_fntype_id (&ovlds[curr_ovld].proto);
+
   /* Now process line 2, which just contains the builtin id and an
      optional overload id.  */
   if (!advance_line (ovld_file))


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-25 16:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 17:17 [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Build and store function type identifiers William Schmidt
  -- strict thread matches above, loose matches on Subject: below --
2021-06-25 16:16 William Schmidt
2021-04-26 20:49 William Schmidt
2021-04-02 22:09 William Schmidt
2021-04-01 19:48 William Schmidt
2021-03-25 15:45 William Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).