[12/14] Write code to rs6000-bif.h.

Message ID f247fce8bdd255539c3c2b5cf047493937f07fcc.1580782131.git.wschmidt@linux.ibm.com
State New
Headers show
Series
  • rs6000: Begin replacing built-in support
Related show

Commit Message

Bill Schmidt Feb. 4, 2020, 2:26 a.m.
2020-02-03  Bill Schmidt  <wschmidt@linux.ibm.com>

        * config/rs6000/rs6000-genbif.c (write_autogenerated_header): New
        function.
        (write_bif_enum): New callback function.
        (write_ovld_enum): New callback	function.
        (write_decls): New function.
        (write_extern_fntype): New callback function.
        (write_header_file): Implement.
---
 gcc/config/rs6000/rs6000-genbif.c | 160 ++++++++++++++++++++++++++++++
 1 file changed, 160 insertions(+)

-- 
2.17.1

Patch

diff --git a/gcc/config/rs6000/rs6000-genbif.c b/gcc/config/rs6000/rs6000-genbif.c
index 0bcd035060d..c84df1aa30f 100644
--- a/gcc/config/rs6000/rs6000-genbif.c
+++ b/gcc/config/rs6000/rs6000-genbif.c
@@ -1617,10 +1617,170 @@  parse_ovld ()
   return result;
 }
 
+/* Write a comment at the top of FILE about how the code was generated.  */
+static void
+write_autogenerated_header (FILE *file)
+{
+  fprintf (file, "/* Automatically generated by the program '%s'\n",
+	   pgm_path);
+  fprintf (file, "   from the files '%s' and '%s'.  */\n\n",
+	   bif_path, ovld_path);
+}
+
+/* Callback functions used in creating enumerations.  */
+void write_bif_enum (char *str)
+{
+  fprintf (header_file, "  RS6000_BIF_%s,\n", str);
+}
+
+void write_ovld_enum (char *str)
+{
+  fprintf (header_file, "  RS6000_OVLD_%s,\n", str);
+}
+
+/* Write declarations into the header file.  */
+static void
+write_decls ()
+{
+  fprintf (header_file, "enum rs6000_gen_builtins\n{\n  RS6000_BIF_NONE,\n");
+  rbt_inorder_callback (&bif_rbt, bif_rbt.rbt_root, write_bif_enum);
+  fprintf (header_file, "  RS6000_BIF_MAX\n};\n\n");
+
+  fprintf (header_file, "enum restriction {\n");
+  fprintf (header_file, "  RES_NONE,\n");
+  fprintf (header_file, "  RES_BITS,\n");
+  fprintf (header_file, "  RES_RANGE,\n");
+  fprintf (header_file, "  RES_VALUES\n");
+  fprintf (header_file, "};\n\n");
+
+  fprintf (header_file, "struct bifdata\n");
+  fprintf (header_file, "{\n");
+  fprintf (header_file, "  const char *bifname;\n");
+  fprintf (header_file, "  tree fntype;\n");
+  fprintf (header_file, "  insn_code icode;\n");
+  fprintf (header_file, "  int  bifattrs;\n");
+  fprintf (header_file, "  int  restr_opnd;\n");
+  fprintf (header_file, "  restriction restr;\n");
+  fprintf (header_file, "  int  restr_val1;\n");
+  fprintf (header_file, "  int  restr_val2;\n");
+  fprintf (header_file, "};\n\n");
+
+  fprintf (header_file, "#define bif_const_bit\t(0x0000001)\n");
+  fprintf (header_file, "#define bif_pure_bit\t(0x0000002)\n");
+  fprintf (header_file, "#define bif_round_bit\t(0x0000004)\n");
+  fprintf (header_file, "#define bif_init_bit\t(0x0000008)\n");
+  fprintf (header_file, "#define bif_set_bit\t(0x0000010)\n");
+  fprintf (header_file, "#define bif_ext_bit\t(0x0000020)\n");
+  fprintf (header_file, "#define bif_nosoft_bit\t(0x0000040)\n");
+  fprintf (header_file, "#define bif_ldv_bit\t(0x0000080)\n");
+  fprintf (header_file, "#define bif_stv_bit\t(0x0000100)\n");
+  fprintf (header_file, "#define bif_reve_bit\t(0x0000200)\n");
+  fprintf (header_file, "#define bif_abs_bit\t(0x0000400)\n");
+  fprintf (header_file, "#define bif_pred_bit\t(0x0000800)\n");
+  fprintf (header_file, "#define bif_htm_bit\t(0x0001000)\n");
+  fprintf (header_file, "\n");
+  fprintf (header_file,
+	   "#define bif_is_const(x)\t\t((x).bifattrs & bif_const_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_pure(x)\t\t((x).bifattrs & bif_pure_bit)\n");
+  fprintf (header_file,
+	   "#define bif_has_rounding(x)\t((x).bifattrs & bif_round_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_init(x)\t\t((x).bifattrs & bif_init_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_extract(x)\t((x).bifattrs & bif_ext_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_nosoft(x)\t((x).bifattrs & bif_nosoft_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_ldv(x)\t\t((x).bifattrs & bif_ldv_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_stv(x)\t\t((x).bifattrs & bif_stv_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_reve(x)\t\t((x).bifattrs & bif_reve_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_abs(x)\t\t((x).bifattrs & bif_abs_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_predicate(x)\t((x).bifattrs & bif_pred_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_htm(x)\t\t((x).bifattrs & bif_htm_bit)\n");
+  fprintf (header_file, "\n");
+
+  /* #### Note that the _x is added for now to avoid conflict with
+     the existing rs6000_builtin_info[] file while testing.  It will
+     be removed as we progress.  */
+  fprintf (header_file, "extern bifdata rs6000_builtin_info_x[];\n\n");
+
+  fprintf (header_file,
+	   "struct rs6000_bif_hasher : nofree_ptr_hash<bifdata>\n");
+  fprintf (header_file, "{\n");
+  fprintf (header_file, "  typedef const char *compare_type;\n\n");
+  fprintf (header_file, "  static hashval_t hash (bifdata *);\n");
+  fprintf (header_file, "  static bool equal (bifdata *, const char *);\n");
+  fprintf (header_file, "};\n\n");
+
+  fprintf (header_file, "extern hash_table<rs6000_bif_hasher> bif_hash;\n\n");
+
+  /* Right now we use nonoverlapping numbers for rs6000_gen_builtins
+     and rs6000_gen_overloads.  In the old design, these were all in the
+     same enum, and I can't yet prove there isn't a dependency on these
+     numbers being distinct.  Once this is more clear, I may change
+     this to start at zero.  */
+  fprintf (header_file, "enum rs6000_gen_overloads\n{\n");
+  fprintf (header_file, "  RS6000_OVLD_NONE = RS6000_BIF_MAX + 1,\n");
+  rbt_inorder_callback (&ovld_rbt, ovld_rbt.rbt_root, write_ovld_enum);
+  fprintf (header_file, "  RS6000_OVLD_MAX\n};\n\n");
+
+  fprintf (header_file, "struct ovlddata\n");
+  fprintf (header_file, "{\n");
+  fprintf (header_file, "  const char *bifname;\n");
+  fprintf (header_file, "  rs6000_gen_builtins bifid;\n");
+  fprintf (header_file, "  tree fntype;\n");
+  fprintf (header_file, "  ovlddata *next;\n");
+  fprintf (header_file, "};\n\n");
+
+  fprintf (header_file, "extern ovlddata rs6000_overload_info[];\n\n");
+
+  fprintf (header_file,
+	   "struct rs6000_ovld_hasher : nofree_ptr_hash<ovlddata>\n");
+  fprintf (header_file, "{\n");
+  fprintf (header_file, "  typedef const char *compare_type;\n\n");
+  fprintf (header_file, "  static hashval_t hash (ovlddata *);\n");
+  fprintf (header_file, "  static bool equal (ovlddata *, const char *);\n");
+  fprintf (header_file, "};\n\n");
+
+  fprintf (header_file,
+	   "extern hash_table<rs6000_ovld_hasher> ovld_hash;\n\n");
+
+  fprintf (header_file, "extern void rs6000_autoinit_builtins ();\n\n");
+}
+
+/* Callback functions used for generating trees for function types.  */
+void
+write_extern_fntype (char *str)
+{
+  fprintf (header_file, "extern tree %s;\n", str);
+}
+
 /* Write everything to the header file (rs6000-bif.h).  */
 static int
 write_header_file ()
 {
+  write_autogenerated_header (header_file);
+  fprintf (header_file, "#include \"config.h\"\n");
+  fprintf (header_file, "#include \"system.h\"\n");
+  fprintf (header_file, "#include \"coretypes.h\"\n");
+  fprintf (header_file, "#include \"backend.h\"\n");
+  fprintf (header_file, "#include \"rtl.h\"\n");
+  fprintf (header_file, "#include \"tree.h\"\n");
+  fprintf (header_file, "\n");
+  fprintf (header_file, "#undef NEW_BUILTINS_ARE_LIVE\n\n");
+
+  write_decls ();
+
+  /* Write function type list declarators to the header file.  */
+  rbt_inorder_callback (&fntype_rbt, fntype_rbt.rbt_root, write_extern_fntype);
+  fprintf (header_file, "\n");
+
   return 1;
 }