This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gcjx] Patch: FYI: built-in functions


I'm checking this in on the gcjx branch.

This copies over most of the built-in function support from the
current gcj to gcjx.  We still don't try to recognize built-in
functions, though; I'll deal with that later.

This fixes a crash relating to lowering floating-point '%' operations.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* Make-lang.in (gt-java-decl.h): New target.
	* lower.cc (visit_bytecode_block): Use built_in_decls.
	* tree.cc (build_mod): Use built_in_decls to find fmod and fmodf.
	* hooks.hh (builtin_fmod): Removed.
	* decl.cc (builtin_creator_function, string_or_tree,
	builtin_record, java_builtins, max_builtin, min_builtin,
	abs_builtin, define_builtin, initialize_builtins): From gcj.
	(initialize_decls): Call initialize_builtins.
	(builtin_fmod): Removed.
	(initialize_builtin_functions): Removed old comment.
	Include gt-java-decl.h.

Index: Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Make-lang.in,v
retrieving revision 1.151.2.5
diff -u -r1.151.2.5 Make-lang.in
--- Make-lang.in 30 Jan 2005 03:18:35 -0000 1.151.2.5
+++ Make-lang.in 27 Mar 2005 02:59:04 -0000
@@ -74,7 +74,7 @@
 	-rm -f $(GCJ)-cross$(exeext)
 	cp $(GCJ)$(exeext) $(GCJ)-cross$(exeext)
 
-gt-java-hooks.h gt-java-langhooks.h : s-gtype ; @true
+gt-java-decl.h gt-java-hooks.h gt-java-langhooks.h : s-gtype ; @true
 
 # Executables built by this Makefile:
 JAVA_OBJS = java/abi.o java/builtins.o java/classobj.o java/decl.o \
Index: decl.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/decl.cc,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 decl.cc
--- decl.cc 24 Mar 2005 20:02:03 -0000 1.1.2.16
+++ decl.cc 27 Mar 2005 02:59:04 -0000
@@ -26,6 +26,58 @@
 // this explicitly.
 extern "C" rtx init_one_libfunc (const char *);
 
+static tree max_builtin (tree, tree);
+static tree min_builtin (tree, tree);
+static tree abs_builtin (tree, tree);
+
+
+
+/* Functions of this type are used to inline a given call.  Such a
+   function should either return an expression, if the call is to be
+   inlined, or NULL_TREE if a real call should be emitted.  Arguments
+   are method return type and arguments to call.  */
+typedef tree builtin_creator_function (tree, tree);
+
+/* Hold a char*, before initialization, or a tree, after
+   initialization.  */
+union string_or_tree GTY(())
+{
+  const char * GTY ((tag ("0"))) s;
+  tree GTY ((tag ("1"))) t;
+};
+
+/* Used to hold a single builtin record.  */
+struct builtin_record GTY(())
+{
+  union string_or_tree GTY ((desc ("1"))) class_name;
+  union string_or_tree GTY ((desc ("1"))) method_name;
+  builtin_creator_function * GTY((skip)) creator;
+  enum built_in_function builtin_code;
+};
+
+static GTY(()) struct builtin_record java_builtins[] =
+{
+  { { "java.lang.Math" }, { "min" }, min_builtin, (built_in_function) -1 },
+  { { "java.lang.Math" }, { "max" }, max_builtin, (built_in_function) -1 },
+  { { "java.lang.Math" }, { "abs" }, abs_builtin, (built_in_function) -1 },
+  { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
+  { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
+  { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
+  { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
+  { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
+  { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
+  { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
+  { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
+  { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
+  { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
+  { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
+  { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT },
+  { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN },
+  { { NULL }, { NULL }, NULL, END_BUILTINS }
+};
+
+
+
 // Used when computing the ABI version.
 #define GCJ_BINARYCOMPAT_ADDITION 5
 
@@ -117,7 +169,6 @@
 tree builtin_Jv_remI;
 tree builtin_Jv_divJ;
 tree builtin_Jv_remJ;
-tree builtin_fmod;
 
 // Vtables for primitive types.
 tree boolean_array_vtable;
@@ -742,8 +793,6 @@
 			      0, NOT_BUILT_IN, NULL, NULL_TREE);
   builtin_Jv_remJ
     = build_address_of (builtin_Jv_remJ);
-
-  // FIXME: initialize builtin_fmod.
 }
 
 static void
@@ -789,6 +838,127 @@
   gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
 }
 
+
+
+/* Internal functions which implement various builtin conversions.  */
+
+static tree
+max_builtin (tree method_return_type, tree method_arguments)
+{
+  return fold (build2 (MAX_EXPR, method_return_type,
+		       TREE_VALUE (method_arguments),
+		       TREE_VALUE (TREE_CHAIN (method_arguments))));
+}
+
+static tree
+min_builtin (tree method_return_type, tree method_arguments)
+{
+  return fold (build2 (MIN_EXPR, method_return_type,
+		       TREE_VALUE (method_arguments),
+		       TREE_VALUE (TREE_CHAIN (method_arguments))));
+}
+
+static tree
+abs_builtin (tree method_return_type, tree method_arguments)
+{
+  return fold (build1 (ABS_EXPR, method_return_type,
+		       TREE_VALUE (method_arguments)));
+}
+
+/* Define a single builtin.  */
+static void
+define_builtin (enum built_in_function val,
+		const char *name,
+		tree type,
+		const char *libname)
+{
+  tree decl;
+
+  decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
+  DECL_EXTERNAL (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
+  make_decl_rtl (decl);
+  pushdecl (decl);
+  DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
+  DECL_FUNCTION_CODE (decl) = val;
+
+  implicit_built_in_decls[val] = decl;
+  built_in_decls[val] = decl;
+}
+
+/* Initialize the builtins.  */
+static void
+initialize_builtins ()
+{
+  tree double_ftype_double, double_ftype_double_double;
+  tree float_ftype_float, float_ftype_float_float;
+  tree t;
+  int i;
+
+  for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
+    {
+      tree klass_id = get_identifier (java_builtins[i].class_name.s);
+      tree m = get_identifier (java_builtins[i].method_name.s);
+
+      java_builtins[i].class_name.t = klass_id;
+      java_builtins[i].method_name.t = m;
+    }
+
+  // Some possible confusion here, because we assume that
+  // float_type_node == type_jfloat, and likewise for double.
+  // Hopefully these assertions suffice.
+  assert (TYPE_PRECISION (float_type_node) == TYPE_PRECISION (type_jfloat));
+  assert (TYPE_PRECISION (double_type_node) == TYPE_PRECISION (type_jdouble));
+
+  t = tree_cons (NULL_TREE, float_type_node, void_list_node);
+  float_ftype_float = build_function_type (float_type_node, t);
+  t = tree_cons (NULL_TREE, float_type_node, t);
+  float_ftype_float_float = build_function_type (float_type_node, t);
+
+  t = tree_cons (NULL_TREE, double_type_node, void_list_node);
+  double_ftype_double = build_function_type (double_type_node, t);
+  t = tree_cons (NULL_TREE, double_type_node, t);
+  double_ftype_double_double = build_function_type (double_type_node, t);
+
+  define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
+		  double_ftype_double_double, "fmod");
+  define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
+		  float_ftype_float_float, "fmodf");
+
+  define_builtin (BUILT_IN_ACOS, "__builtin_acos",
+		  double_ftype_double, "_ZN4java4lang4Math4acosEd");
+  define_builtin (BUILT_IN_ASIN, "__builtin_asin",
+		  double_ftype_double, "_ZN4java4lang4Math4asinEd");
+  define_builtin (BUILT_IN_ATAN, "__builtin_atan",
+		  double_ftype_double, "_ZN4java4lang4Math4atanEd");
+  define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
+		  double_ftype_double_double, "_ZN4java4lang4Math5atan2Edd");
+  define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
+		  double_ftype_double, "_ZN4java4lang4Math4ceilEd");
+  define_builtin (BUILT_IN_COS, "__builtin_cos",
+		  double_ftype_double, "_ZN4java4lang4Math3cosEd");
+  define_builtin (BUILT_IN_EXP, "__builtin_exp",
+		  double_ftype_double, "_ZN4java4lang4Math3expEd");
+  define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
+		  double_ftype_double, "_ZN4java4lang4Math5floorEd");
+  define_builtin (BUILT_IN_LOG, "__builtin_log",
+		  double_ftype_double, "_ZN4java4lang4Math3logEd");
+  define_builtin (BUILT_IN_POW, "__builtin_pow",
+		  double_ftype_double_double, "_ZN4java4lang4Math3powEdd");
+  define_builtin (BUILT_IN_SIN, "__builtin_sin",
+		  double_ftype_double, "_ZN4java4lang4Math3sinEd");
+  define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
+		  double_ftype_double, "_ZN4java4lang4Math4sqrtEd");
+  define_builtin (BUILT_IN_TAN, "__builtin_tan",
+		  double_ftype_double, "_ZN4java4lang4Math3tanEd");
+
+  // Only on trunk for now.
+  // build_common_builtin_nodes ();
+}
+
+
+
 tree
 gcjx::builtin_function (const char *name,
 			tree type,
@@ -832,8 +1002,11 @@
   build_class_union ();
   initialize_builtin_functions ();
 
+  initialize_builtins ();
+
   initialize_version ();
 }
 
+#include "gt-java-decl.h"
 #include "gt-java-hooks.h"
 #include "gtype-java.h"
Index: hooks.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/hooks.hh,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 hooks.hh
--- hooks.hh 24 Mar 2005 20:02:03 -0000 1.1.2.8
+++ hooks.hh 27 Mar 2005 02:59:04 -0000
@@ -84,7 +84,6 @@
 extern GTY (()) tree builtin_Jv_remI;
 extern GTY (()) tree builtin_Jv_divJ;
 extern GTY (()) tree builtin_Jv_remJ;
-extern GTY (()) tree builtin_fmod;
 extern GTY (()) tree boolean_array_vtable;
 extern GTY (()) tree byte_array_vtable;
 extern GTY (()) tree char_array_vtable;
Index: lower.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/lower.cc,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 lower.cc
--- lower.cc 9 Mar 2005 02:19:09 -0000 1.1.2.7
+++ lower.cc 27 Mar 2005 02:59:05 -0000
@@ -717,10 +717,9 @@
 	  {
 	    tree val2 = pop (type_jfloat);
 	    tree val1 = pop (type_jfloat);
-	    // FIXME: convert to/from jfloat
 	    insn = push (build3 (CALL_EXPR,
 				 type_jfloat,
-				 builtin_fmod,
+				 build_address_of (built_in_decls[BUILT_IN_FMODF]),
 				 tree_cons (NULL_TREE, val1,
 					    build_tree_list (NULL_TREE,
 							     val2)),
@@ -734,7 +733,7 @@
 	    tree val1 = pop (type_jdouble);
 	    insn = push (build3 (CALL_EXPR,
 				 type_jdouble,
-				 builtin_fmod,
+				 build_address_of (built_in_decls[BUILT_IN_FMOD]),
 				 tree_cons (NULL_TREE, val1,
 					    build_tree_list (NULL_TREE,
 							     val2)),
Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.32
diff -u -r1.1.2.32 tree.cc
--- tree.cc 27 Mar 2005 02:58:22 -0000 1.1.2.32
+++ tree.cc 27 Mar 2005 02:59:05 -0000
@@ -2336,8 +2336,10 @@
 tree_generator::build_mod (tree result_type, tree lhs, tree rhs)
 {
   tree func;
-  if (result_type == type_jfloat || result_type == type_jdouble)
-    func = builtin_fmod;
+  if (result_type == type_jfloat)
+    func = build_address_of (built_in_decls[BUILT_IN_FMODF]);
+  else if (result_type == type_jdouble)
+    func = build_address_of (built_in_decls[BUILT_IN_FMOD]);
   else
     {
       if (! flag_use_divide_subroutine)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]