[18/29] rs6000: Write output to the builtins init file, part 2 of 3

Message ID 30eb5357ac2cae6fedfae962a35bf63a58d96b9d.1595809584.git.wschmidt@linux.ibm.com
State New
Headers show
Series
  • rs6000: Auto-generate builtins from descriptions [V2]
Related show

Commit Message

Bill Schmidt July 27, 2020, 2:14 p.m.
From: Bill Schmidt <wschmidt@linux.ibm.com>


2020-07-26  Bill Schmidt  <wschmidt@linux.ibm.com>

	* config/rs6000/rs6000-gen-builtins.c (write_init_bif_table):
	Implement.
---
 gcc/config/rs6000/rs6000-gen-builtins.c | 153 ++++++++++++++++++++++++
 1 file changed, 153 insertions(+)

-- 
2.17.1

Patch

diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index 3ac199ff2e5..43d13b46a43 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -2094,6 +2094,159 @@  write_header_file ()
 static void
 write_init_bif_table ()
 {
+  const char *attr_string;
+
+  for (int i = 0; i <= curr_bif; i++)
+    {
+      fprintf (init_file,
+	       "  rs6000_builtin_info_x[RS6000_BIF_%s].bifname"
+	       "\n    = \"%s\";\n",
+	       bifs[i].idname, bifs[i].proto.bifname);
+      fprintf (init_file,
+	       "  rs6000_builtin_info_x[RS6000_BIF_%s].enable"
+	       "\n    = %s;\n",
+	       bifs[i].idname, enable_string[bifs[i].stanza]);
+      fprintf (init_file,
+	       "  rs6000_builtin_info_x[RS6000_BIF_%s].fntype"
+	       "\n    = %s;\n",
+	       bifs[i].idname, bifs[i].fndecl);
+      fprintf (init_file,
+	       "  rs6000_builtin_info_x[RS6000_BIF_%s].nargs"
+	       "\n    = %d;\n",
+	       bifs[i].idname, bifs[i].proto.nargs);
+      fprintf (init_file,
+	       "  rs6000_builtin_info_x[RS6000_BIF_%s].icode"
+	       "\n    = CODE_FOR_%s;\n",
+	       bifs[i].idname, bifs[i].patname);
+      fprintf (init_file,
+	       "  rs6000_builtin_info_x[RS6000_BIF_%s].bifattrs"
+	       "\n    = 0",
+	       bifs[i].idname);
+      if (bifs[i].attrs.isinit)
+	fprintf (init_file, " | bif_init_bit");
+      if (bifs[i].attrs.isset)
+	fprintf (init_file, " | bif_set_bit");
+      if (bifs[i].attrs.isextract)
+	fprintf (init_file, " | bif_extract_bit");
+      if (bifs[i].attrs.isnosoft)
+	fprintf (init_file, " | bif_nosoft_bit");
+      if (bifs[i].attrs.isldvec)
+	fprintf (init_file, " | bif_ldvec_bit");
+      if (bifs[i].attrs.isstvec)
+	fprintf (init_file, " | bif_stvec_bit");
+      if (bifs[i].attrs.isreve)
+	fprintf (init_file, " | bif_reve_bit");
+      if (bifs[i].attrs.ispred)
+	fprintf (init_file, " | bif_pred_bit");
+      if (bifs[i].attrs.ishtm)
+	fprintf (init_file, " | bif_htm_bit");
+      if (bifs[i].attrs.ishtmspr)
+	fprintf (init_file, " | bif_htmspr_bit");
+      if (bifs[i].attrs.ishtmcr)
+	fprintf (init_file, " | bif_htmcr_bit");
+      if (bifs[i].attrs.ismma)
+	fprintf (init_file, " | bif_mma_bit");
+      if (bifs[i].attrs.isno32bit)
+	fprintf (init_file, " | bif_no32bit_bit");
+      if (bifs[i].attrs.iscpu)
+	fprintf (init_file, " | bif_cpu_bit");
+      if (bifs[i].attrs.isldstmask)
+	fprintf (init_file, " | bif_ldstmask_bit");
+      fprintf (init_file, ";\n");
+      for (int j = 0; j < 1; j++)
+	{
+	  fprintf (init_file,
+		   "  rs6000_builtin_info_x[RS6000_BIF_%s].restr_opnd[%d]"
+		   "\n    = %d;\n",
+		   bifs[i].idname, j, bifs[i].proto.restr_opnd[j]);
+	  if (bifs[i].proto.restr_opnd[j])
+	    {
+	      const char *res
+		= (bifs[i].proto.restr[j] == RES_BITS ? "RES_BITS"
+		   : (bifs[i].proto.restr[j] == RES_RANGE ? "RES_RANGE"
+		      : (bifs[i].proto.restr[j] == RES_VALUES ? "RES_VALUES"
+			 : (bifs[i].proto.restr[j] == RES_VAR_RANGE
+			    ? "RES_VAR_RANGE" : "ERROR"))));
+	      fprintf (init_file,
+		       "  rs6000_builtin_info_x[RS6000_BIF_%s].restr[%d]"
+		       "\n    = %s;\n",
+		       bifs[i].idname, j, res);
+	      fprintf (init_file,
+		       "  rs6000_builtin_info_x[RS6000_BIF_%s].restr_val1[%d]"
+		       "\n    = %d;\n",
+		       bifs[i].idname, j, bifs[i].proto.restr_val1[j]);
+	      fprintf (init_file,
+		       "  rs6000_builtin_info_x[RS6000_BIF_%s].restr_val2[%d]"
+		       "\n    = %d;\n",
+		       bifs[i].idname, j, bifs[i].proto.restr_val2[j]);
+	    }
+	  fprintf (init_file, "\n");
+	}
+
+      fprintf (init_file,
+	       "  bifaddr = &rs6000_builtin_info_x[RS6000_BIF_%s];\n",
+	       bifs[i].idname);
+      fprintf (init_file,
+	       "  hash = rs6000_bif_hasher::hash (bifaddr);\n");
+      fprintf (init_file,
+	       "  slot = bif_hash.find_slot_with_hash (\n");
+      fprintf (init_file,
+	       "           \"%s\", hash, INSERT\n",
+	       bifs[i].proto.bifname);
+      fprintf (init_file,
+	       "         );\n");
+      fprintf (init_file,
+	       "  *slot = bifaddr;\n\n");
+
+      fprintf (init_file,
+	       "  if (new_builtins_are_live)\n");
+      fprintf (init_file, "    {\n");
+      fprintf (init_file,
+	       "      rs6000_builtin_decls[(int)RS6000_BIF_%s] = t\n",
+	       bifs[i].idname);
+      fprintf (init_file,
+	       "        = add_builtin_function (\"%s\",\n",
+	       bifs[i].proto.bifname);
+      fprintf (init_file,
+	       "                                %s,\n",
+	       bifs[i].fndecl);
+      fprintf (init_file,
+	       "                                (int)RS6000_BIF_%s,"
+	       " BUILT_IN_MD,\n",
+	       bifs[i].idname);
+      fprintf (init_file,
+	       "                                NULL, NULL_TREE);\n");
+      if (bifs[i].kind == FNK_CONST)
+	{
+	  fprintf (init_file, "      TREE_READONLY (t) = 1;\n");
+	  fprintf (init_file, "      TREE_NOTHROW (t) = 1;\n");
+	  attr_string = ", const";
+	}
+      else if (bifs[i].kind == FNK_PURE)
+	{
+	  fprintf (init_file, "      DECL_PURE_P (t) = 1;\n");
+	  fprintf (init_file, "      TREE_NOTHROW (t) = 1;\n");
+	  attr_string = ", pure";
+	}
+      else if (bifs[i].kind == FNK_FPMATH)
+	{
+	  fprintf (init_file, "      TREE_NOTHROW (t) = 1;\n");
+	  fprintf (init_file, "      if (flag_rounding_math)\n");
+	  fprintf (init_file, "        {\n");
+	  fprintf (init_file, "          DECL_PURE_P (t) = 1;\n");
+	  fprintf (init_file, "          DECL_IS_NOVOPS (t) = 1;\n");
+	  fprintf (init_file, "        }\n");
+	  attr_string = ", fp, const";
+	}
+      else
+	attr_string = "";
+
+      fprintf (init_file, "      if (TARGET_DEBUG_BUILTIN)\n");
+      fprintf (init_file, "        fprintf (stderr, \"rs6000_builtin"
+	       ", code = %4d, \"\n                  \"%s%s\\n\");\n",
+	       i, bifs[i].proto.bifname, attr_string);
+      fprintf (init_file, "    }\n\n");
+    }
 }
 
 /* Write code to initialize the overload table.  */