PR c/64768
[official-gcc.git] / gcc / java / builtins.c
blob067ce9fc5d0716a7de03fdb8b97c11b4f7f34e76
1 /* Built-in and inline functions for gcj
2 Copyright (C) 2001-2015 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 "hash-set.h"
34 #include "machmode.h"
35 #include "vec.h"
36 #include "double-int.h"
37 #include "input.h"
38 #include "alias.h"
39 #include "symtab.h"
40 #include "options.h"
41 #include "wide-int.h"
42 #include "inchash.h"
43 #include "tree.h"
44 #include "fold-const.h"
45 #include "stor-layout.h"
46 #include "stringpool.h"
47 #include "ggc.h"
48 #include "flags.h"
49 #include "langhooks.h"
50 #include "java-tree.h"
52 /* FIXME: All these headers are necessary for sync_compare_and_swap.
53 Front ends should never have to look at that. */
54 #include "rtl.h"
55 #include "insn-codes.h"
56 #include "hashtab.h"
57 #include "hard-reg-set.h"
58 #include "function.h"
59 #include "statistics.h"
60 #include "real.h"
61 #include "fixed-value.h"
62 #include "insn-config.h"
63 #include "expmed.h"
64 #include "dojump.h"
65 #include "explow.h"
66 #include "calls.h"
67 #include "emit-rtl.h"
68 #include "varasm.h"
69 #include "stmt.h"
70 #include "expr.h"
71 #include "optabs.h"
73 static tree max_builtin (tree, tree);
74 static tree min_builtin (tree, tree);
75 static tree abs_builtin (tree, tree);
76 static tree convert_real (tree, tree);
78 static tree java_build_function_call_expr (tree, tree);
80 static tree putObject_builtin (tree, tree);
81 static tree compareAndSwapInt_builtin (tree, tree);
82 static tree compareAndSwapLong_builtin (tree, tree);
83 static tree compareAndSwapObject_builtin (tree, tree);
84 static tree putVolatile_builtin (tree, tree);
85 static tree getVolatile_builtin (tree, tree);
86 static tree VMSupportsCS8_builtin (tree, tree);
89 /* Functions of this type are used to inline a given call. Such a
90 function should either return an expression, if the call is to be
91 inlined, or NULL_TREE if a real call should be emitted. Arguments
92 are method return type and the original CALL_EXPR containing the
93 arguments to the call. */
94 typedef tree builtin_creator_function (tree, tree);
96 /* Hold a char*, before initialization, or a tree, after
97 initialization. */
98 union GTY(()) string_or_tree {
99 const char * GTY ((tag ("0"))) s;
100 tree GTY ((tag ("1"))) t;
103 /* Used to hold a single builtin record. */
104 struct GTY(()) builtin_record {
105 union string_or_tree GTY ((desc ("1"))) class_name;
106 union string_or_tree GTY ((desc ("1"))) method_name;
107 builtin_creator_function * GTY((skip)) creator;
108 enum built_in_function builtin_code;
111 static GTY(()) struct builtin_record java_builtins[] =
113 { { "java.lang.Math" }, { "min" }, min_builtin, (enum built_in_function) 0 },
114 { { "java.lang.Math" }, { "max" }, max_builtin, (enum built_in_function) 0 },
115 { { "java.lang.Math" }, { "abs" }, abs_builtin, (enum built_in_function) 0 },
116 { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
117 { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
118 { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
119 { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
120 { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
121 { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
122 { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
123 { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
124 { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
125 { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
126 { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
127 { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT },
128 { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN },
129 { { "java.lang.Float" }, { "intBitsToFloat" }, convert_real,
130 (enum built_in_function) 0 },
131 { { "java.lang.Double" }, { "longBitsToDouble" }, convert_real,
132 (enum built_in_function) 0 },
133 { { "java.lang.Float" }, { "floatToRawIntBits" }, convert_real,
134 (enum built_in_function) 0 },
135 { { "java.lang.Double" }, { "doubleToRawLongBits" }, convert_real,
136 (enum built_in_function) 0 },
137 { { "sun.misc.Unsafe" }, { "putInt" }, putObject_builtin,
138 (enum built_in_function) 0},
139 { { "sun.misc.Unsafe" }, { "putLong" }, putObject_builtin,
140 (enum built_in_function) 0},
141 { { "sun.misc.Unsafe" }, { "putObject" }, putObject_builtin,
142 (enum built_in_function) 0},
143 { { "sun.misc.Unsafe" }, { "compareAndSwapInt" },
144 compareAndSwapInt_builtin, (enum built_in_function) 0},
145 { { "sun.misc.Unsafe" }, { "compareAndSwapLong" },
146 compareAndSwapLong_builtin, (enum built_in_function) 0},
147 { { "sun.misc.Unsafe" }, { "compareAndSwapObject" },
148 compareAndSwapObject_builtin, (enum built_in_function) 0},
149 { { "sun.misc.Unsafe" }, { "putOrderedInt" }, putVolatile_builtin,
150 (enum built_in_function) 0},
151 { { "sun.misc.Unsafe" }, { "putOrderedLong" }, putVolatile_builtin,
152 (enum built_in_function) 0},
153 { { "sun.misc.Unsafe" }, { "putOrderedObject" }, putVolatile_builtin,
154 (enum built_in_function) 0},
155 { { "sun.misc.Unsafe" }, { "putIntVolatile" }, putVolatile_builtin,
156 (enum built_in_function) 0},
157 { { "sun.misc.Unsafe" }, { "putLongVolatile" }, putVolatile_builtin,
158 (enum built_in_function) 0},
159 { { "sun.misc.Unsafe" }, { "putObjectVolatile" }, putVolatile_builtin,
160 (enum built_in_function) 0},
161 { { "sun.misc.Unsafe" }, { "getObjectVolatile" }, getVolatile_builtin,
162 (enum built_in_function) 0},
163 { { "sun.misc.Unsafe" }, { "getIntVolatile" }, getVolatile_builtin,
164 (enum built_in_function) 0},
165 { { "sun.misc.Unsafe" }, { "getLongVolatile" }, getVolatile_builtin, (enum built_in_function) 0},
166 { { "sun.misc.Unsafe" }, { "getLong" }, getVolatile_builtin,
167 (enum built_in_function) 0},
168 { { "java.util.concurrent.atomic.AtomicLong" }, { "VMSupportsCS8" },
169 VMSupportsCS8_builtin, (enum built_in_function) 0},
170 { { NULL }, { NULL }, NULL, END_BUILTINS }
174 /* Internal functions which implement various builtin conversions. */
176 static tree
177 max_builtin (tree method_return_type, tree orig_call)
179 /* MAX_EXPR does not handle -0.0 in the Java style. */
180 if (TREE_CODE (method_return_type) == REAL_TYPE)
181 return NULL_TREE;
182 return fold_build2 (MAX_EXPR, method_return_type,
183 CALL_EXPR_ARG (orig_call, 0),
184 CALL_EXPR_ARG (orig_call, 1));
187 static tree
188 min_builtin (tree method_return_type, tree orig_call)
190 /* MIN_EXPR does not handle -0.0 in the Java style. */
191 if (TREE_CODE (method_return_type) == REAL_TYPE)
192 return NULL_TREE;
193 return fold_build2 (MIN_EXPR, method_return_type,
194 CALL_EXPR_ARG (orig_call, 0),
195 CALL_EXPR_ARG (orig_call, 1));
198 static tree
199 abs_builtin (tree method_return_type, tree orig_call)
201 return fold_build1 (ABS_EXPR, method_return_type,
202 CALL_EXPR_ARG (orig_call, 0));
205 /* Construct a new call to FN using the arguments from ORIG_CALL. */
207 static tree
208 java_build_function_call_expr (tree fn, tree orig_call)
210 int nargs = call_expr_nargs (orig_call);
211 switch (nargs)
213 /* Although we could handle the 0-3 argument cases using the general
214 logic in the default case, splitting them out permits folding to
215 be performed without constructing a temporary CALL_EXPR. */
216 case 0:
217 return build_call_expr (fn, 0);
218 case 1:
219 return build_call_expr (fn, 1, CALL_EXPR_ARG (orig_call, 0));
220 case 2:
221 return build_call_expr (fn, 2,
222 CALL_EXPR_ARG (orig_call, 0),
223 CALL_EXPR_ARG (orig_call, 1));
224 case 3:
225 return build_call_expr (fn, 3,
226 CALL_EXPR_ARG (orig_call, 0),
227 CALL_EXPR_ARG (orig_call, 1),
228 CALL_EXPR_ARG (orig_call, 2));
229 default:
231 tree fntype = TREE_TYPE (fn);
232 fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn);
233 return fold (build_call_array (TREE_TYPE (fntype),
234 fn, nargs, CALL_EXPR_ARGP (orig_call)));
239 static tree
240 convert_real (tree method_return_type, tree orig_call)
242 return build1 (VIEW_CONVERT_EXPR, method_return_type,
243 CALL_EXPR_ARG (orig_call, 0));
248 /* Provide builtin support for atomic operations. These are
249 documented at length in libjava/sun/misc/Unsafe.java. */
251 /* FIXME. There are still a few things wrong with this logic. In
252 particular, atomic writes of multi-word integers are not truly
253 atomic: this requires more work.
255 In general, double-word compare-and-swap cannot portably be
256 implemented, so we need some kind of fallback for 32-bit machines.
261 /* Macros to unmarshal arguments from a CALL_EXPR into a few
262 variables. We also convert the offset arg from a long to an
263 integer that is the same size as a pointer. */
265 #define UNMARSHAL3(METHOD_CALL) \
266 tree this_arg, obj_arg, offset_arg; \
267 do \
269 tree orig_method_call = METHOD_CALL; \
270 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
271 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
272 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
273 CALL_EXPR_ARG (orig_method_call, 2)); \
275 while (0)
277 #define UNMARSHAL4(METHOD_CALL) \
278 tree value_type, this_arg, obj_arg, offset_arg, value_arg; \
279 do \
281 tree orig_method_call = METHOD_CALL; \
282 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
283 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
284 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
285 CALL_EXPR_ARG (orig_method_call, 2)); \
286 value_arg = CALL_EXPR_ARG (orig_method_call, 3); \
287 value_type = TREE_TYPE (value_arg); \
289 while (0)
291 #define UNMARSHAL5(METHOD_CALL) \
292 tree value_type, this_arg, obj_arg, offset_arg, expected_arg, value_arg; \
293 do \
295 tree orig_method_call = METHOD_CALL; \
296 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
297 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
298 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
299 CALL_EXPR_ARG (orig_method_call, 2)); \
300 expected_arg = CALL_EXPR_ARG (orig_method_call, 3); \
301 value_arg = CALL_EXPR_ARG (orig_method_call, 4); \
302 value_type = TREE_TYPE (value_arg); \
304 while (0)
306 /* Add an address to an offset, forming a sum. */
308 static tree
309 build_addr_sum (tree type, tree addr, tree offset)
311 tree ptr_type = build_pointer_type (type);
312 return fold_build_pointer_plus (fold_convert (ptr_type, addr), offset);
315 /* Make sure that this-arg is non-NULL. This is a security check. */
317 static tree
318 build_check_this (tree stmt, tree this_arg)
320 return build2 (COMPOUND_EXPR, TREE_TYPE (stmt),
321 java_check_reference (this_arg, 1), stmt);
324 /* Now the builtins. These correspond to the primitive functions in
325 libjava/sun/misc/natUnsafe.cc. */
327 static tree
328 putObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
329 tree orig_call)
331 tree addr, stmt;
332 UNMARSHAL4 (orig_call);
334 addr = build_addr_sum (value_type, obj_arg, offset_arg);
335 stmt = fold_build2 (MODIFY_EXPR, value_type,
336 build_java_indirect_ref (value_type, addr,
337 flag_check_references),
338 value_arg);
340 return build_check_this (stmt, this_arg);
343 static tree
344 compareAndSwapInt_builtin (tree method_return_type ATTRIBUTE_UNUSED,
345 tree orig_call)
347 machine_mode mode = TYPE_MODE (int_type_node);
348 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
350 tree addr, stmt;
351 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
352 UNMARSHAL5 (orig_call);
353 (void) value_type; /* Avoid set but not used warning. */
355 addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
356 stmt = build_call_expr (builtin_decl_explicit (fncode),
357 3, addr, expected_arg, value_arg);
359 return build_check_this (stmt, this_arg);
361 return NULL_TREE;
364 static tree
365 compareAndSwapLong_builtin (tree method_return_type ATTRIBUTE_UNUSED,
366 tree orig_call)
368 machine_mode mode = TYPE_MODE (long_type_node);
369 /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
370 Some machines such as ARM have atomic libfuncs but not the multi-word
371 versions. */
372 if (can_compare_and_swap_p (mode,
373 (flag_use_atomic_builtins
374 && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
376 tree addr, stmt;
377 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
378 UNMARSHAL5 (orig_call);
379 (void) value_type; /* Avoid set but not used warning. */
381 addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
382 stmt = build_call_expr (builtin_decl_explicit (fncode),
383 3, addr, expected_arg, value_arg);
385 return build_check_this (stmt, this_arg);
387 return NULL_TREE;
389 static tree
390 compareAndSwapObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
391 tree orig_call)
393 machine_mode mode = TYPE_MODE (ptr_type_node);
394 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
396 tree addr, stmt;
397 enum built_in_function builtin;
399 UNMARSHAL5 (orig_call);
400 builtin = (POINTER_SIZE == 32
401 ? BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4
402 : BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8);
404 addr = build_addr_sum (value_type, obj_arg, offset_arg);
405 stmt = build_call_expr (builtin_decl_explicit (builtin),
406 3, addr, expected_arg, value_arg);
408 return build_check_this (stmt, this_arg);
410 return NULL_TREE;
413 static tree
414 putVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
415 tree orig_call)
417 tree addr, stmt, modify_stmt;
418 UNMARSHAL4 (orig_call);
420 addr = build_addr_sum (value_type, obj_arg, offset_arg);
421 addr
422 = fold_convert (build_pointer_type (build_qualified_type
423 (value_type, TYPE_QUAL_VOLATILE)),
424 addr);
426 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
427 modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
428 build_java_indirect_ref (value_type, addr,
429 flag_check_references),
430 value_arg);
431 stmt = build2 (COMPOUND_EXPR, TREE_TYPE (modify_stmt),
432 stmt, modify_stmt);
434 return build_check_this (stmt, this_arg);
437 static tree
438 getVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
439 tree orig_call)
441 tree addr, stmt, modify_stmt, tmp;
442 UNMARSHAL3 (orig_call);
443 (void) this_arg; /* Avoid set but not used warning. */
445 addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
446 addr
447 = fold_convert (build_pointer_type (build_qualified_type
448 (method_return_type,
449 TYPE_QUAL_VOLATILE)), addr);
451 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
452 tmp = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL, method_return_type);
453 DECL_IGNORED_P (tmp) = 1;
454 DECL_ARTIFICIAL (tmp) = 1;
455 pushdecl (tmp);
457 modify_stmt = fold_build2 (MODIFY_EXPR, method_return_type,
458 tmp,
459 build_java_indirect_ref (method_return_type, addr,
460 flag_check_references));
462 stmt = build2 (COMPOUND_EXPR, void_type_node, modify_stmt, stmt);
463 stmt = build2 (COMPOUND_EXPR, method_return_type, stmt, tmp);
465 return stmt;
468 static tree
469 VMSupportsCS8_builtin (tree method_return_type,
470 tree orig_call ATTRIBUTE_UNUSED)
472 machine_mode mode = TYPE_MODE (long_type_node);
473 gcc_assert (method_return_type == boolean_type_node);
474 if (can_compare_and_swap_p (mode, false))
475 return boolean_true_node;
476 else
477 return boolean_false_node;
482 /* Define a single builtin. */
483 static void
484 define_builtin (enum built_in_function val,
485 const char *name,
486 tree type,
487 const char *libname,
488 int flags)
490 tree decl;
492 decl = build_decl (BUILTINS_LOCATION,
493 FUNCTION_DECL, get_identifier (name), type);
494 DECL_EXTERNAL (decl) = 1;
495 TREE_PUBLIC (decl) = 1;
496 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
497 pushdecl (decl);
498 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
499 DECL_FUNCTION_CODE (decl) = val;
500 set_call_expr_flags (decl, flags);
502 set_builtin_decl (val, decl, true);
507 /* Initialize the builtins. */
508 void
509 initialize_builtins (void)
511 tree double_ftype_double, double_ftype_double_double;
512 tree float_ftype_float_float;
513 tree boolean_ftype_boolean_boolean;
514 int i;
516 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
518 tree klass_id = get_identifier (java_builtins[i].class_name.s);
519 tree m = get_identifier (java_builtins[i].method_name.s);
521 java_builtins[i].class_name.t = klass_id;
522 java_builtins[i].method_name.t = m;
525 void_list_node = end_params_node;
527 float_ftype_float_float
528 = build_function_type_list (float_type_node,
529 float_type_node, float_type_node, NULL_TREE);
531 double_ftype_double
532 = build_function_type_list (double_type_node, double_type_node, NULL_TREE);
533 double_ftype_double_double
534 = build_function_type_list (double_type_node,
535 double_type_node, double_type_node, NULL_TREE);
537 define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
538 double_ftype_double_double, "fmod", ECF_CONST);
539 define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
540 float_ftype_float_float, "fmodf", ECF_CONST);
542 define_builtin (BUILT_IN_ACOS, "__builtin_acos",
543 double_ftype_double, "_ZN4java4lang4Math4acosEJdd",
544 ECF_CONST);
545 define_builtin (BUILT_IN_ASIN, "__builtin_asin",
546 double_ftype_double, "_ZN4java4lang4Math4asinEJdd",
547 ECF_CONST);
548 define_builtin (BUILT_IN_ATAN, "__builtin_atan",
549 double_ftype_double, "_ZN4java4lang4Math4atanEJdd",
550 ECF_CONST);
551 define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
552 double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd",
553 ECF_CONST);
554 define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
555 double_ftype_double, "_ZN4java4lang4Math4ceilEJdd",
556 ECF_CONST);
557 define_builtin (BUILT_IN_COS, "__builtin_cos",
558 double_ftype_double, "_ZN4java4lang4Math3cosEJdd",
559 ECF_CONST);
560 define_builtin (BUILT_IN_EXP, "__builtin_exp",
561 double_ftype_double, "_ZN4java4lang4Math3expEJdd",
562 ECF_CONST);
563 define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
564 double_ftype_double, "_ZN4java4lang4Math5floorEJdd",
565 ECF_CONST);
566 define_builtin (BUILT_IN_LOG, "__builtin_log",
567 double_ftype_double, "_ZN4java4lang4Math3logEJdd",
568 ECF_CONST);
569 define_builtin (BUILT_IN_POW, "__builtin_pow",
570 double_ftype_double_double, "_ZN4java4lang4Math3powEJddd",
571 ECF_CONST);
572 define_builtin (BUILT_IN_SIN, "__builtin_sin",
573 double_ftype_double, "_ZN4java4lang4Math3sinEJdd",
574 ECF_CONST);
575 define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
576 double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd",
577 ECF_CONST);
578 define_builtin (BUILT_IN_TAN, "__builtin_tan",
579 double_ftype_double, "_ZN4java4lang4Math3tanEJdd",
580 ECF_CONST);
582 boolean_ftype_boolean_boolean
583 = build_function_type_list (boolean_type_node,
584 boolean_type_node, boolean_type_node,
585 NULL_TREE);
586 define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
587 boolean_ftype_boolean_boolean,
588 "__builtin_expect",
589 ECF_CONST | ECF_NOTHROW);
590 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4,
591 "__sync_bool_compare_and_swap_4",
592 build_function_type_list (boolean_type_node,
593 int_type_node,
594 build_pointer_type (int_type_node),
595 int_type_node, NULL_TREE),
596 "__sync_bool_compare_and_swap_4", ECF_NOTHROW | ECF_LEAF);
597 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8,
598 "__sync_bool_compare_and_swap_8",
599 build_function_type_list (boolean_type_node,
600 long_type_node,
601 build_pointer_type (long_type_node),
602 int_type_node, NULL_TREE),
603 "__sync_bool_compare_and_swap_8", ECF_NOTHROW | ECF_LEAF);
604 define_builtin (BUILT_IN_SYNC_SYNCHRONIZE, "__sync_synchronize",
605 build_function_type_list (void_type_node, NULL_TREE),
606 "__sync_synchronize", ECF_NOTHROW | ECF_LEAF);
608 define_builtin (BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
609 build_function_type_list (ptr_type_node, int_type_node, NULL_TREE),
610 "__builtin_return_address", ECF_NOTHROW | ECF_LEAF);
611 define_builtin (BUILT_IN_TRAP, "__builtin_trap",
612 build_function_type_list (void_type_node, NULL_TREE),
613 "__builtin_trap", ECF_NOTHROW | ECF_LEAF | ECF_NORETURN);
614 build_common_builtin_nodes ();
617 /* If the call matches a builtin, return the
618 appropriate builtin expression instead. */
619 tree
620 check_for_builtin (tree method, tree call)
622 if (optimize && TREE_CODE (call) == CALL_EXPR)
624 int i;
625 tree method_class = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
626 tree method_name = DECL_NAME (method);
627 tree method_return_type = TREE_TYPE (TREE_TYPE (method));
629 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
631 if (method_class == java_builtins[i].class_name.t
632 && method_name == java_builtins[i].method_name.t)
634 tree fn;
636 if (java_builtins[i].creator != NULL)
638 tree result
639 = (*java_builtins[i].creator) (method_return_type, call);
640 return result == NULL_TREE ? call : result;
643 /* Builtin functions emit a direct call which is incompatible
644 with the BC-ABI. */
645 if (flag_indirect_dispatch)
646 return call;
647 fn = builtin_decl_explicit (java_builtins[i].builtin_code);
648 if (fn == NULL_TREE)
649 return call;
650 return java_build_function_call_expr (fn, call);
654 return call;
657 #include "gt-java-builtins.h"