2014-04-14 Martin Jambor <mjambor@suse.cz>
[official-gcc.git] / gcc / java / builtins.c
blob1ce9ce5c564a4f8c6a8a1239d5127b09eeb6ca44
1 /* Built-in and inline functions for gcj
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 /* Written by Tom Tromey <tromey@redhat.com>. */
26 /* FIXME: Still need to include rtl.h here (see below). */
27 #undef IN_GCC_FRONTEND
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "tree.h"
34 #include "stor-layout.h"
35 #include "stringpool.h"
36 #include "ggc.h"
37 #include "flags.h"
38 #include "langhooks.h"
39 #include "java-tree.h"
41 /* FIXME: All these headers are necessary for sync_compare_and_swap.
42 Front ends should never have to look at that. */
43 #include "rtl.h"
44 #include "insn-codes.h"
45 #include "expr.h"
46 #include "optabs.h"
48 static tree max_builtin (tree, tree);
49 static tree min_builtin (tree, tree);
50 static tree abs_builtin (tree, tree);
51 static tree convert_real (tree, tree);
53 static tree java_build_function_call_expr (tree, tree);
55 static tree putObject_builtin (tree, tree);
56 static tree compareAndSwapInt_builtin (tree, tree);
57 static tree compareAndSwapLong_builtin (tree, tree);
58 static tree compareAndSwapObject_builtin (tree, tree);
59 static tree putVolatile_builtin (tree, tree);
60 static tree getVolatile_builtin (tree, tree);
61 static tree VMSupportsCS8_builtin (tree, tree);
64 /* Functions of this type are used to inline a given call. Such a
65 function should either return an expression, if the call is to be
66 inlined, or NULL_TREE if a real call should be emitted. Arguments
67 are method return type and the original CALL_EXPR containing the
68 arguments to the call. */
69 typedef tree builtin_creator_function (tree, tree);
71 /* Hold a char*, before initialization, or a tree, after
72 initialization. */
73 union GTY(()) string_or_tree {
74 const char * GTY ((tag ("0"))) s;
75 tree GTY ((tag ("1"))) t;
78 /* Used to hold a single builtin record. */
79 struct GTY(()) builtin_record {
80 union string_or_tree GTY ((desc ("1"))) class_name;
81 union string_or_tree GTY ((desc ("1"))) method_name;
82 builtin_creator_function * GTY((skip)) creator;
83 enum built_in_function builtin_code;
86 static GTY(()) struct builtin_record java_builtins[] =
88 { { "java.lang.Math" }, { "min" }, min_builtin, (enum built_in_function) 0 },
89 { { "java.lang.Math" }, { "max" }, max_builtin, (enum built_in_function) 0 },
90 { { "java.lang.Math" }, { "abs" }, abs_builtin, (enum built_in_function) 0 },
91 { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
92 { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
93 { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
94 { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
95 { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
96 { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
97 { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
98 { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
99 { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
100 { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
101 { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
102 { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT },
103 { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN },
104 { { "java.lang.Float" }, { "intBitsToFloat" }, convert_real,
105 (enum built_in_function) 0 },
106 { { "java.lang.Double" }, { "longBitsToDouble" }, convert_real,
107 (enum built_in_function) 0 },
108 { { "java.lang.Float" }, { "floatToRawIntBits" }, convert_real,
109 (enum built_in_function) 0 },
110 { { "java.lang.Double" }, { "doubleToRawLongBits" }, convert_real,
111 (enum built_in_function) 0 },
112 { { "sun.misc.Unsafe" }, { "putInt" }, putObject_builtin,
113 (enum built_in_function) 0},
114 { { "sun.misc.Unsafe" }, { "putLong" }, putObject_builtin,
115 (enum built_in_function) 0},
116 { { "sun.misc.Unsafe" }, { "putObject" }, putObject_builtin,
117 (enum built_in_function) 0},
118 { { "sun.misc.Unsafe" }, { "compareAndSwapInt" },
119 compareAndSwapInt_builtin, (enum built_in_function) 0},
120 { { "sun.misc.Unsafe" }, { "compareAndSwapLong" },
121 compareAndSwapLong_builtin, (enum built_in_function) 0},
122 { { "sun.misc.Unsafe" }, { "compareAndSwapObject" },
123 compareAndSwapObject_builtin, (enum built_in_function) 0},
124 { { "sun.misc.Unsafe" }, { "putOrderedInt" }, putVolatile_builtin,
125 (enum built_in_function) 0},
126 { { "sun.misc.Unsafe" }, { "putOrderedLong" }, putVolatile_builtin,
127 (enum built_in_function) 0},
128 { { "sun.misc.Unsafe" }, { "putOrderedObject" }, putVolatile_builtin,
129 (enum built_in_function) 0},
130 { { "sun.misc.Unsafe" }, { "putIntVolatile" }, putVolatile_builtin,
131 (enum built_in_function) 0},
132 { { "sun.misc.Unsafe" }, { "putLongVolatile" }, putVolatile_builtin,
133 (enum built_in_function) 0},
134 { { "sun.misc.Unsafe" }, { "putObjectVolatile" }, putVolatile_builtin,
135 (enum built_in_function) 0},
136 { { "sun.misc.Unsafe" }, { "getObjectVolatile" }, getVolatile_builtin,
137 (enum built_in_function) 0},
138 { { "sun.misc.Unsafe" }, { "getIntVolatile" }, getVolatile_builtin,
139 (enum built_in_function) 0},
140 { { "sun.misc.Unsafe" }, { "getLongVolatile" }, getVolatile_builtin, (enum built_in_function) 0},
141 { { "sun.misc.Unsafe" }, { "getLong" }, getVolatile_builtin,
142 (enum built_in_function) 0},
143 { { "java.util.concurrent.atomic.AtomicLong" }, { "VMSupportsCS8" },
144 VMSupportsCS8_builtin, (enum built_in_function) 0},
145 { { NULL }, { NULL }, NULL, END_BUILTINS }
149 /* Internal functions which implement various builtin conversions. */
151 static tree
152 max_builtin (tree method_return_type, tree orig_call)
154 /* MAX_EXPR does not handle -0.0 in the Java style. */
155 if (TREE_CODE (method_return_type) == REAL_TYPE)
156 return NULL_TREE;
157 return fold_build2 (MAX_EXPR, method_return_type,
158 CALL_EXPR_ARG (orig_call, 0),
159 CALL_EXPR_ARG (orig_call, 1));
162 static tree
163 min_builtin (tree method_return_type, tree orig_call)
165 /* MIN_EXPR does not handle -0.0 in the Java style. */
166 if (TREE_CODE (method_return_type) == REAL_TYPE)
167 return NULL_TREE;
168 return fold_build2 (MIN_EXPR, method_return_type,
169 CALL_EXPR_ARG (orig_call, 0),
170 CALL_EXPR_ARG (orig_call, 1));
173 static tree
174 abs_builtin (tree method_return_type, tree orig_call)
176 return fold_build1 (ABS_EXPR, method_return_type,
177 CALL_EXPR_ARG (orig_call, 0));
180 /* Construct a new call to FN using the arguments from ORIG_CALL. */
182 static tree
183 java_build_function_call_expr (tree fn, tree orig_call)
185 int nargs = call_expr_nargs (orig_call);
186 switch (nargs)
188 /* Although we could handle the 0-3 argument cases using the general
189 logic in the default case, splitting them out permits folding to
190 be performed without constructing a temporary CALL_EXPR. */
191 case 0:
192 return build_call_expr (fn, 0);
193 case 1:
194 return build_call_expr (fn, 1, CALL_EXPR_ARG (orig_call, 0));
195 case 2:
196 return build_call_expr (fn, 2,
197 CALL_EXPR_ARG (orig_call, 0),
198 CALL_EXPR_ARG (orig_call, 1));
199 case 3:
200 return build_call_expr (fn, 3,
201 CALL_EXPR_ARG (orig_call, 0),
202 CALL_EXPR_ARG (orig_call, 1),
203 CALL_EXPR_ARG (orig_call, 2));
204 default:
206 tree fntype = TREE_TYPE (fn);
207 fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn);
208 return fold (build_call_array (TREE_TYPE (fntype),
209 fn, nargs, CALL_EXPR_ARGP (orig_call)));
214 static tree
215 convert_real (tree method_return_type, tree orig_call)
217 return build1 (VIEW_CONVERT_EXPR, method_return_type,
218 CALL_EXPR_ARG (orig_call, 0));
223 /* Provide builtin support for atomic operations. These are
224 documented at length in libjava/sun/misc/Unsafe.java. */
226 /* FIXME. There are still a few things wrong with this logic. In
227 particular, atomic writes of multi-word integers are not truly
228 atomic: this requires more work.
230 In general, double-word compare-and-swap cannot portably be
231 implemented, so we need some kind of fallback for 32-bit machines.
236 /* Macros to unmarshal arguments from a CALL_EXPR into a few
237 variables. We also convert the offset arg from a long to an
238 integer that is the same size as a pointer. */
240 #define UNMARSHAL3(METHOD_CALL) \
241 tree this_arg, obj_arg, offset_arg; \
242 do \
244 tree orig_method_call = METHOD_CALL; \
245 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
246 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
247 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
248 CALL_EXPR_ARG (orig_method_call, 2)); \
250 while (0)
252 #define UNMARSHAL4(METHOD_CALL) \
253 tree value_type, this_arg, obj_arg, offset_arg, value_arg; \
254 do \
256 tree orig_method_call = METHOD_CALL; \
257 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
258 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
259 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
260 CALL_EXPR_ARG (orig_method_call, 2)); \
261 value_arg = CALL_EXPR_ARG (orig_method_call, 3); \
262 value_type = TREE_TYPE (value_arg); \
264 while (0)
266 #define UNMARSHAL5(METHOD_CALL) \
267 tree value_type, this_arg, obj_arg, offset_arg, expected_arg, value_arg; \
268 do \
270 tree orig_method_call = METHOD_CALL; \
271 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
272 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
273 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
274 CALL_EXPR_ARG (orig_method_call, 2)); \
275 expected_arg = CALL_EXPR_ARG (orig_method_call, 3); \
276 value_arg = CALL_EXPR_ARG (orig_method_call, 4); \
277 value_type = TREE_TYPE (value_arg); \
279 while (0)
281 /* Add an address to an offset, forming a sum. */
283 static tree
284 build_addr_sum (tree type, tree addr, tree offset)
286 tree ptr_type = build_pointer_type (type);
287 return fold_build_pointer_plus (fold_convert (ptr_type, addr), offset);
290 /* Make sure that this-arg is non-NULL. This is a security check. */
292 static tree
293 build_check_this (tree stmt, tree this_arg)
295 return build2 (COMPOUND_EXPR, TREE_TYPE (stmt),
296 java_check_reference (this_arg, 1), stmt);
299 /* Now the builtins. These correspond to the primitive functions in
300 libjava/sun/misc/natUnsafe.cc. */
302 static tree
303 putObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
304 tree orig_call)
306 tree addr, stmt;
307 UNMARSHAL4 (orig_call);
309 addr = build_addr_sum (value_type, obj_arg, offset_arg);
310 stmt = fold_build2 (MODIFY_EXPR, value_type,
311 build_java_indirect_ref (value_type, addr,
312 flag_check_references),
313 value_arg);
315 return build_check_this (stmt, this_arg);
318 static tree
319 compareAndSwapInt_builtin (tree method_return_type ATTRIBUTE_UNUSED,
320 tree orig_call)
322 enum machine_mode mode = TYPE_MODE (int_type_node);
323 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
325 tree addr, stmt;
326 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
327 UNMARSHAL5 (orig_call);
328 (void) value_type; /* Avoid set but not used warning. */
330 addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
331 stmt = build_call_expr (builtin_decl_explicit (fncode),
332 3, addr, expected_arg, value_arg);
334 return build_check_this (stmt, this_arg);
336 return NULL_TREE;
339 static tree
340 compareAndSwapLong_builtin (tree method_return_type ATTRIBUTE_UNUSED,
341 tree orig_call)
343 enum machine_mode mode = TYPE_MODE (long_type_node);
344 /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
345 Some machines such as ARM have atomic libfuncs but not the multi-word
346 versions. */
347 if (can_compare_and_swap_p (mode,
348 (flag_use_atomic_builtins
349 && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
351 tree addr, stmt;
352 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
353 UNMARSHAL5 (orig_call);
354 (void) value_type; /* Avoid set but not used warning. */
356 addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
357 stmt = build_call_expr (builtin_decl_explicit (fncode),
358 3, addr, expected_arg, value_arg);
360 return build_check_this (stmt, this_arg);
362 return NULL_TREE;
364 static tree
365 compareAndSwapObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
366 tree orig_call)
368 enum machine_mode mode = TYPE_MODE (ptr_type_node);
369 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
371 tree addr, stmt;
372 enum built_in_function builtin;
374 UNMARSHAL5 (orig_call);
375 builtin = (POINTER_SIZE == 32
376 ? BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4
377 : BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8);
379 addr = build_addr_sum (value_type, obj_arg, offset_arg);
380 stmt = build_call_expr (builtin_decl_explicit (builtin),
381 3, addr, expected_arg, value_arg);
383 return build_check_this (stmt, this_arg);
385 return NULL_TREE;
388 static tree
389 putVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
390 tree orig_call)
392 tree addr, stmt, modify_stmt;
393 UNMARSHAL4 (orig_call);
395 addr = build_addr_sum (value_type, obj_arg, offset_arg);
396 addr
397 = fold_convert (build_pointer_type (build_type_variant (value_type, 0, 1)),
398 addr);
400 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
401 modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
402 build_java_indirect_ref (value_type, addr,
403 flag_check_references),
404 value_arg);
405 stmt = build2 (COMPOUND_EXPR, TREE_TYPE (modify_stmt),
406 stmt, modify_stmt);
408 return build_check_this (stmt, this_arg);
411 static tree
412 getVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
413 tree orig_call)
415 tree addr, stmt, modify_stmt, tmp;
416 UNMARSHAL3 (orig_call);
417 (void) this_arg; /* Avoid set but not used warning. */
419 addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
420 addr
421 = fold_convert (build_pointer_type (build_type_variant
422 (method_return_type, 0, 1)), addr);
424 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
425 tmp = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL, method_return_type);
426 DECL_IGNORED_P (tmp) = 1;
427 DECL_ARTIFICIAL (tmp) = 1;
428 pushdecl (tmp);
430 modify_stmt = fold_build2 (MODIFY_EXPR, method_return_type,
431 tmp,
432 build_java_indirect_ref (method_return_type, addr,
433 flag_check_references));
435 stmt = build2 (COMPOUND_EXPR, void_type_node, modify_stmt, stmt);
436 stmt = build2 (COMPOUND_EXPR, method_return_type, stmt, tmp);
438 return stmt;
441 static tree
442 VMSupportsCS8_builtin (tree method_return_type,
443 tree orig_call ATTRIBUTE_UNUSED)
445 enum machine_mode mode = TYPE_MODE (long_type_node);
446 gcc_assert (method_return_type == boolean_type_node);
447 if (can_compare_and_swap_p (mode, false))
448 return boolean_true_node;
449 else
450 return boolean_false_node;
455 /* Define a single builtin. */
456 static void
457 define_builtin (enum built_in_function val,
458 const char *name,
459 tree type,
460 const char *libname,
461 int flags)
463 tree decl;
465 decl = build_decl (BUILTINS_LOCATION,
466 FUNCTION_DECL, get_identifier (name), type);
467 DECL_EXTERNAL (decl) = 1;
468 TREE_PUBLIC (decl) = 1;
469 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
470 pushdecl (decl);
471 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
472 DECL_FUNCTION_CODE (decl) = val;
473 set_call_expr_flags (decl, flags);
475 set_builtin_decl (val, decl, true);
480 /* Initialize the builtins. */
481 void
482 initialize_builtins (void)
484 tree double_ftype_double, double_ftype_double_double;
485 tree float_ftype_float_float;
486 tree boolean_ftype_boolean_boolean;
487 int i;
489 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
491 tree klass_id = get_identifier (java_builtins[i].class_name.s);
492 tree m = get_identifier (java_builtins[i].method_name.s);
494 java_builtins[i].class_name.t = klass_id;
495 java_builtins[i].method_name.t = m;
498 void_list_node = end_params_node;
500 float_ftype_float_float
501 = build_function_type_list (float_type_node,
502 float_type_node, float_type_node, NULL_TREE);
504 double_ftype_double
505 = build_function_type_list (double_type_node, double_type_node, NULL_TREE);
506 double_ftype_double_double
507 = build_function_type_list (double_type_node,
508 double_type_node, double_type_node, NULL_TREE);
510 define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
511 double_ftype_double_double, "fmod", ECF_CONST);
512 define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
513 float_ftype_float_float, "fmodf", ECF_CONST);
515 define_builtin (BUILT_IN_ACOS, "__builtin_acos",
516 double_ftype_double, "_ZN4java4lang4Math4acosEJdd",
517 ECF_CONST);
518 define_builtin (BUILT_IN_ASIN, "__builtin_asin",
519 double_ftype_double, "_ZN4java4lang4Math4asinEJdd",
520 ECF_CONST);
521 define_builtin (BUILT_IN_ATAN, "__builtin_atan",
522 double_ftype_double, "_ZN4java4lang4Math4atanEJdd",
523 ECF_CONST);
524 define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
525 double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd",
526 ECF_CONST);
527 define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
528 double_ftype_double, "_ZN4java4lang4Math4ceilEJdd",
529 ECF_CONST);
530 define_builtin (BUILT_IN_COS, "__builtin_cos",
531 double_ftype_double, "_ZN4java4lang4Math3cosEJdd",
532 ECF_CONST);
533 define_builtin (BUILT_IN_EXP, "__builtin_exp",
534 double_ftype_double, "_ZN4java4lang4Math3expEJdd",
535 ECF_CONST);
536 define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
537 double_ftype_double, "_ZN4java4lang4Math5floorEJdd",
538 ECF_CONST);
539 define_builtin (BUILT_IN_LOG, "__builtin_log",
540 double_ftype_double, "_ZN4java4lang4Math3logEJdd",
541 ECF_CONST);
542 define_builtin (BUILT_IN_POW, "__builtin_pow",
543 double_ftype_double_double, "_ZN4java4lang4Math3powEJddd",
544 ECF_CONST);
545 define_builtin (BUILT_IN_SIN, "__builtin_sin",
546 double_ftype_double, "_ZN4java4lang4Math3sinEJdd",
547 ECF_CONST);
548 define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
549 double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd",
550 ECF_CONST);
551 define_builtin (BUILT_IN_TAN, "__builtin_tan",
552 double_ftype_double, "_ZN4java4lang4Math3tanEJdd",
553 ECF_CONST);
555 boolean_ftype_boolean_boolean
556 = build_function_type_list (boolean_type_node,
557 boolean_type_node, boolean_type_node,
558 NULL_TREE);
559 define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
560 boolean_ftype_boolean_boolean,
561 "__builtin_expect",
562 ECF_CONST | ECF_NOTHROW);
563 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4,
564 "__sync_bool_compare_and_swap_4",
565 build_function_type_list (boolean_type_node,
566 int_type_node,
567 build_pointer_type (int_type_node),
568 int_type_node, NULL_TREE),
569 "__sync_bool_compare_and_swap_4", ECF_NOTHROW | ECF_LEAF);
570 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8,
571 "__sync_bool_compare_and_swap_8",
572 build_function_type_list (boolean_type_node,
573 long_type_node,
574 build_pointer_type (long_type_node),
575 int_type_node, NULL_TREE),
576 "__sync_bool_compare_and_swap_8", ECF_NOTHROW | ECF_LEAF);
577 define_builtin (BUILT_IN_SYNC_SYNCHRONIZE, "__sync_synchronize",
578 build_function_type_list (void_type_node, NULL_TREE),
579 "__sync_synchronize", ECF_NOTHROW | ECF_LEAF);
581 define_builtin (BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
582 build_function_type_list (ptr_type_node, int_type_node, NULL_TREE),
583 "__builtin_return_address", ECF_NOTHROW | ECF_LEAF);
584 define_builtin (BUILT_IN_TRAP, "__builtin_trap",
585 build_function_type_list (void_type_node, NULL_TREE),
586 "__builtin_trap", ECF_NOTHROW | ECF_LEAF | ECF_NORETURN);
587 build_common_builtin_nodes ();
590 /* If the call matches a builtin, return the
591 appropriate builtin expression instead. */
592 tree
593 check_for_builtin (tree method, tree call)
595 if (optimize && TREE_CODE (call) == CALL_EXPR)
597 int i;
598 tree method_class = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
599 tree method_name = DECL_NAME (method);
600 tree method_return_type = TREE_TYPE (TREE_TYPE (method));
602 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
604 if (method_class == java_builtins[i].class_name.t
605 && method_name == java_builtins[i].method_name.t)
607 tree fn;
609 if (java_builtins[i].creator != NULL)
611 tree result
612 = (*java_builtins[i].creator) (method_return_type, call);
613 return result == NULL_TREE ? call : result;
616 /* Builtin functions emit a direct call which is incompatible
617 with the BC-ABI. */
618 if (flag_indirect_dispatch)
619 return call;
620 fn = builtin_decl_explicit (java_builtins[i].builtin_code);
621 if (fn == NULL_TREE)
622 return call;
623 return java_build_function_call_expr (fn, call);
627 return call;
630 #include "gt-java-builtins.h"