Account for prologue spills in reg_pressure scheduling
[official-gcc.git] / gcc / java / builtins.c
blob12c427daedae46f91400ee9ad6018c016b132a0f
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_qualified_type
398 (value_type, TYPE_QUAL_VOLATILE)),
399 addr);
401 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
402 modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
403 build_java_indirect_ref (value_type, addr,
404 flag_check_references),
405 value_arg);
406 stmt = build2 (COMPOUND_EXPR, TREE_TYPE (modify_stmt),
407 stmt, modify_stmt);
409 return build_check_this (stmt, this_arg);
412 static tree
413 getVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
414 tree orig_call)
416 tree addr, stmt, modify_stmt, tmp;
417 UNMARSHAL3 (orig_call);
418 (void) this_arg; /* Avoid set but not used warning. */
420 addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
421 addr
422 = fold_convert (build_pointer_type (build_qualified_type
423 (method_return_type,
424 TYPE_QUAL_VOLATILE)), addr);
426 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
427 tmp = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL, method_return_type);
428 DECL_IGNORED_P (tmp) = 1;
429 DECL_ARTIFICIAL (tmp) = 1;
430 pushdecl (tmp);
432 modify_stmt = fold_build2 (MODIFY_EXPR, method_return_type,
433 tmp,
434 build_java_indirect_ref (method_return_type, addr,
435 flag_check_references));
437 stmt = build2 (COMPOUND_EXPR, void_type_node, modify_stmt, stmt);
438 stmt = build2 (COMPOUND_EXPR, method_return_type, stmt, tmp);
440 return stmt;
443 static tree
444 VMSupportsCS8_builtin (tree method_return_type,
445 tree orig_call ATTRIBUTE_UNUSED)
447 enum machine_mode mode = TYPE_MODE (long_type_node);
448 gcc_assert (method_return_type == boolean_type_node);
449 if (can_compare_and_swap_p (mode, false))
450 return boolean_true_node;
451 else
452 return boolean_false_node;
457 /* Define a single builtin. */
458 static void
459 define_builtin (enum built_in_function val,
460 const char *name,
461 tree type,
462 const char *libname,
463 int flags)
465 tree decl;
467 decl = build_decl (BUILTINS_LOCATION,
468 FUNCTION_DECL, get_identifier (name), type);
469 DECL_EXTERNAL (decl) = 1;
470 TREE_PUBLIC (decl) = 1;
471 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
472 pushdecl (decl);
473 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
474 DECL_FUNCTION_CODE (decl) = val;
475 set_call_expr_flags (decl, flags);
477 set_builtin_decl (val, decl, true);
482 /* Initialize the builtins. */
483 void
484 initialize_builtins (void)
486 tree double_ftype_double, double_ftype_double_double;
487 tree float_ftype_float_float;
488 tree boolean_ftype_boolean_boolean;
489 int i;
491 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
493 tree klass_id = get_identifier (java_builtins[i].class_name.s);
494 tree m = get_identifier (java_builtins[i].method_name.s);
496 java_builtins[i].class_name.t = klass_id;
497 java_builtins[i].method_name.t = m;
500 void_list_node = end_params_node;
502 float_ftype_float_float
503 = build_function_type_list (float_type_node,
504 float_type_node, float_type_node, NULL_TREE);
506 double_ftype_double
507 = build_function_type_list (double_type_node, double_type_node, NULL_TREE);
508 double_ftype_double_double
509 = build_function_type_list (double_type_node,
510 double_type_node, double_type_node, NULL_TREE);
512 define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
513 double_ftype_double_double, "fmod", ECF_CONST);
514 define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
515 float_ftype_float_float, "fmodf", ECF_CONST);
517 define_builtin (BUILT_IN_ACOS, "__builtin_acos",
518 double_ftype_double, "_ZN4java4lang4Math4acosEJdd",
519 ECF_CONST);
520 define_builtin (BUILT_IN_ASIN, "__builtin_asin",
521 double_ftype_double, "_ZN4java4lang4Math4asinEJdd",
522 ECF_CONST);
523 define_builtin (BUILT_IN_ATAN, "__builtin_atan",
524 double_ftype_double, "_ZN4java4lang4Math4atanEJdd",
525 ECF_CONST);
526 define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
527 double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd",
528 ECF_CONST);
529 define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
530 double_ftype_double, "_ZN4java4lang4Math4ceilEJdd",
531 ECF_CONST);
532 define_builtin (BUILT_IN_COS, "__builtin_cos",
533 double_ftype_double, "_ZN4java4lang4Math3cosEJdd",
534 ECF_CONST);
535 define_builtin (BUILT_IN_EXP, "__builtin_exp",
536 double_ftype_double, "_ZN4java4lang4Math3expEJdd",
537 ECF_CONST);
538 define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
539 double_ftype_double, "_ZN4java4lang4Math5floorEJdd",
540 ECF_CONST);
541 define_builtin (BUILT_IN_LOG, "__builtin_log",
542 double_ftype_double, "_ZN4java4lang4Math3logEJdd",
543 ECF_CONST);
544 define_builtin (BUILT_IN_POW, "__builtin_pow",
545 double_ftype_double_double, "_ZN4java4lang4Math3powEJddd",
546 ECF_CONST);
547 define_builtin (BUILT_IN_SIN, "__builtin_sin",
548 double_ftype_double, "_ZN4java4lang4Math3sinEJdd",
549 ECF_CONST);
550 define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
551 double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd",
552 ECF_CONST);
553 define_builtin (BUILT_IN_TAN, "__builtin_tan",
554 double_ftype_double, "_ZN4java4lang4Math3tanEJdd",
555 ECF_CONST);
557 boolean_ftype_boolean_boolean
558 = build_function_type_list (boolean_type_node,
559 boolean_type_node, boolean_type_node,
560 NULL_TREE);
561 define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
562 boolean_ftype_boolean_boolean,
563 "__builtin_expect",
564 ECF_CONST | ECF_NOTHROW);
565 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4,
566 "__sync_bool_compare_and_swap_4",
567 build_function_type_list (boolean_type_node,
568 int_type_node,
569 build_pointer_type (int_type_node),
570 int_type_node, NULL_TREE),
571 "__sync_bool_compare_and_swap_4", ECF_NOTHROW | ECF_LEAF);
572 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8,
573 "__sync_bool_compare_and_swap_8",
574 build_function_type_list (boolean_type_node,
575 long_type_node,
576 build_pointer_type (long_type_node),
577 int_type_node, NULL_TREE),
578 "__sync_bool_compare_and_swap_8", ECF_NOTHROW | ECF_LEAF);
579 define_builtin (BUILT_IN_SYNC_SYNCHRONIZE, "__sync_synchronize",
580 build_function_type_list (void_type_node, NULL_TREE),
581 "__sync_synchronize", ECF_NOTHROW | ECF_LEAF);
583 define_builtin (BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
584 build_function_type_list (ptr_type_node, int_type_node, NULL_TREE),
585 "__builtin_return_address", ECF_NOTHROW | ECF_LEAF);
586 define_builtin (BUILT_IN_TRAP, "__builtin_trap",
587 build_function_type_list (void_type_node, NULL_TREE),
588 "__builtin_trap", ECF_NOTHROW | ECF_LEAF | ECF_NORETURN);
589 build_common_builtin_nodes ();
592 /* If the call matches a builtin, return the
593 appropriate builtin expression instead. */
594 tree
595 check_for_builtin (tree method, tree call)
597 if (optimize && TREE_CODE (call) == CALL_EXPR)
599 int i;
600 tree method_class = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
601 tree method_name = DECL_NAME (method);
602 tree method_return_type = TREE_TYPE (TREE_TYPE (method));
604 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
606 if (method_class == java_builtins[i].class_name.t
607 && method_name == java_builtins[i].method_name.t)
609 tree fn;
611 if (java_builtins[i].creator != NULL)
613 tree result
614 = (*java_builtins[i].creator) (method_return_type, call);
615 return result == NULL_TREE ? call : result;
618 /* Builtin functions emit a direct call which is incompatible
619 with the BC-ABI. */
620 if (flag_indirect_dispatch)
621 return call;
622 fn = builtin_decl_explicit (java_builtins[i].builtin_code);
623 if (fn == NULL_TREE)
624 return call;
625 return java_build_function_call_expr (fn, call);
629 return call;
632 #include "gt-java-builtins.h"