Fix type in the changelog entry,
[official-gcc.git] / gcc / java / builtins.c
blobf10227f19e15db59c7dad98a6c049dc846bcd03b
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 "alias.h"
34 #include "tree.h"
35 #include "options.h"
36 #include "fold-const.h"
37 #include "stor-layout.h"
38 #include "stringpool.h"
39 #include "flags.h"
40 #include "langhooks.h"
41 #include "java-tree.h"
43 /* FIXME: All these headers are necessary for sync_compare_and_swap.
44 Front ends should never have to look at that. */
45 #include "rtl.h"
46 #include "insn-codes.h"
47 #include "function.h"
48 #include "insn-config.h"
49 #include "expmed.h"
50 #include "dojump.h"
51 #include "explow.h"
52 #include "calls.h"
53 #include "emit-rtl.h"
54 #include "varasm.h"
55 #include "stmt.h"
56 #include "expr.h"
57 #include "optabs.h"
59 static tree max_builtin (tree, tree);
60 static tree min_builtin (tree, tree);
61 static tree abs_builtin (tree, tree);
62 static tree convert_real (tree, tree);
64 static tree java_build_function_call_expr (tree, tree);
66 static tree putObject_builtin (tree, tree);
67 static tree compareAndSwapInt_builtin (tree, tree);
68 static tree compareAndSwapLong_builtin (tree, tree);
69 static tree compareAndSwapObject_builtin (tree, tree);
70 static tree putVolatile_builtin (tree, tree);
71 static tree getVolatile_builtin (tree, tree);
72 static tree VMSupportsCS8_builtin (tree, tree);
75 /* Functions of this type are used to inline a given call. Such a
76 function should either return an expression, if the call is to be
77 inlined, or NULL_TREE if a real call should be emitted. Arguments
78 are method return type and the original CALL_EXPR containing the
79 arguments to the call. */
80 typedef tree builtin_creator_function (tree, tree);
82 /* Hold a char*, before initialization, or a tree, after
83 initialization. */
84 union GTY(()) string_or_tree {
85 const char * GTY ((tag ("0"))) s;
86 tree GTY ((tag ("1"))) t;
89 /* Used to hold a single builtin record. */
90 struct GTY(()) builtin_record {
91 union string_or_tree GTY ((desc ("1"))) class_name;
92 union string_or_tree GTY ((desc ("1"))) method_name;
93 builtin_creator_function * GTY((skip)) creator;
94 enum built_in_function builtin_code;
97 static GTY(()) struct builtin_record java_builtins[] =
99 { { "java.lang.Math" }, { "min" }, min_builtin, (enum built_in_function) 0 },
100 { { "java.lang.Math" }, { "max" }, max_builtin, (enum built_in_function) 0 },
101 { { "java.lang.Math" }, { "abs" }, abs_builtin, (enum built_in_function) 0 },
102 { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
103 { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
104 { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
105 { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
106 { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
107 { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
108 { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
109 { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
110 { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
111 { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
112 { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
113 { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT },
114 { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN },
115 { { "java.lang.Float" }, { "intBitsToFloat" }, convert_real,
116 (enum built_in_function) 0 },
117 { { "java.lang.Double" }, { "longBitsToDouble" }, convert_real,
118 (enum built_in_function) 0 },
119 { { "java.lang.Float" }, { "floatToRawIntBits" }, convert_real,
120 (enum built_in_function) 0 },
121 { { "java.lang.Double" }, { "doubleToRawLongBits" }, convert_real,
122 (enum built_in_function) 0 },
123 { { "sun.misc.Unsafe" }, { "putInt" }, putObject_builtin,
124 (enum built_in_function) 0},
125 { { "sun.misc.Unsafe" }, { "putLong" }, putObject_builtin,
126 (enum built_in_function) 0},
127 { { "sun.misc.Unsafe" }, { "putObject" }, putObject_builtin,
128 (enum built_in_function) 0},
129 { { "sun.misc.Unsafe" }, { "compareAndSwapInt" },
130 compareAndSwapInt_builtin, (enum built_in_function) 0},
131 { { "sun.misc.Unsafe" }, { "compareAndSwapLong" },
132 compareAndSwapLong_builtin, (enum built_in_function) 0},
133 { { "sun.misc.Unsafe" }, { "compareAndSwapObject" },
134 compareAndSwapObject_builtin, (enum built_in_function) 0},
135 { { "sun.misc.Unsafe" }, { "putOrderedInt" }, putVolatile_builtin,
136 (enum built_in_function) 0},
137 { { "sun.misc.Unsafe" }, { "putOrderedLong" }, putVolatile_builtin,
138 (enum built_in_function) 0},
139 { { "sun.misc.Unsafe" }, { "putOrderedObject" }, putVolatile_builtin,
140 (enum built_in_function) 0},
141 { { "sun.misc.Unsafe" }, { "putIntVolatile" }, putVolatile_builtin,
142 (enum built_in_function) 0},
143 { { "sun.misc.Unsafe" }, { "putLongVolatile" }, putVolatile_builtin,
144 (enum built_in_function) 0},
145 { { "sun.misc.Unsafe" }, { "putObjectVolatile" }, putVolatile_builtin,
146 (enum built_in_function) 0},
147 { { "sun.misc.Unsafe" }, { "getObjectVolatile" }, getVolatile_builtin,
148 (enum built_in_function) 0},
149 { { "sun.misc.Unsafe" }, { "getIntVolatile" }, getVolatile_builtin,
150 (enum built_in_function) 0},
151 { { "sun.misc.Unsafe" }, { "getLongVolatile" }, getVolatile_builtin, (enum built_in_function) 0},
152 { { "sun.misc.Unsafe" }, { "getLong" }, getVolatile_builtin,
153 (enum built_in_function) 0},
154 { { "java.util.concurrent.atomic.AtomicLong" }, { "VMSupportsCS8" },
155 VMSupportsCS8_builtin, (enum built_in_function) 0},
156 { { NULL }, { NULL }, NULL, END_BUILTINS }
160 /* Internal functions which implement various builtin conversions. */
162 static tree
163 max_builtin (tree method_return_type, tree orig_call)
165 /* MAX_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 (MAX_EXPR, method_return_type,
169 CALL_EXPR_ARG (orig_call, 0),
170 CALL_EXPR_ARG (orig_call, 1));
173 static tree
174 min_builtin (tree method_return_type, tree orig_call)
176 /* MIN_EXPR does not handle -0.0 in the Java style. */
177 if (TREE_CODE (method_return_type) == REAL_TYPE)
178 return NULL_TREE;
179 return fold_build2 (MIN_EXPR, method_return_type,
180 CALL_EXPR_ARG (orig_call, 0),
181 CALL_EXPR_ARG (orig_call, 1));
184 static tree
185 abs_builtin (tree method_return_type, tree orig_call)
187 return fold_build1 (ABS_EXPR, method_return_type,
188 CALL_EXPR_ARG (orig_call, 0));
191 /* Construct a new call to FN using the arguments from ORIG_CALL. */
193 static tree
194 java_build_function_call_expr (tree fn, tree orig_call)
196 int nargs = call_expr_nargs (orig_call);
197 switch (nargs)
199 /* Although we could handle the 0-3 argument cases using the general
200 logic in the default case, splitting them out permits folding to
201 be performed without constructing a temporary CALL_EXPR. */
202 case 0:
203 return build_call_expr (fn, 0);
204 case 1:
205 return build_call_expr (fn, 1, CALL_EXPR_ARG (orig_call, 0));
206 case 2:
207 return build_call_expr (fn, 2,
208 CALL_EXPR_ARG (orig_call, 0),
209 CALL_EXPR_ARG (orig_call, 1));
210 case 3:
211 return build_call_expr (fn, 3,
212 CALL_EXPR_ARG (orig_call, 0),
213 CALL_EXPR_ARG (orig_call, 1),
214 CALL_EXPR_ARG (orig_call, 2));
215 default:
217 tree fntype = TREE_TYPE (fn);
218 fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn);
219 return fold (build_call_array (TREE_TYPE (fntype),
220 fn, nargs, CALL_EXPR_ARGP (orig_call)));
225 static tree
226 convert_real (tree method_return_type, tree orig_call)
228 return build1 (VIEW_CONVERT_EXPR, method_return_type,
229 CALL_EXPR_ARG (orig_call, 0));
234 /* Provide builtin support for atomic operations. These are
235 documented at length in libjava/sun/misc/Unsafe.java. */
237 /* FIXME. There are still a few things wrong with this logic. In
238 particular, atomic writes of multi-word integers are not truly
239 atomic: this requires more work.
241 In general, double-word compare-and-swap cannot portably be
242 implemented, so we need some kind of fallback for 32-bit machines.
247 /* Macros to unmarshal arguments from a CALL_EXPR into a few
248 variables. We also convert the offset arg from a long to an
249 integer that is the same size as a pointer. */
251 #define UNMARSHAL3(METHOD_CALL) \
252 tree this_arg, obj_arg, offset_arg; \
253 do \
255 tree orig_method_call = METHOD_CALL; \
256 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
257 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
258 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
259 CALL_EXPR_ARG (orig_method_call, 2)); \
261 while (0)
263 #define UNMARSHAL4(METHOD_CALL) \
264 tree value_type, this_arg, obj_arg, offset_arg, value_arg; \
265 do \
267 tree orig_method_call = METHOD_CALL; \
268 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
269 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
270 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
271 CALL_EXPR_ARG (orig_method_call, 2)); \
272 value_arg = CALL_EXPR_ARG (orig_method_call, 3); \
273 value_type = TREE_TYPE (value_arg); \
275 while (0)
277 #define UNMARSHAL5(METHOD_CALL) \
278 tree value_type, this_arg, obj_arg, offset_arg, expected_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 expected_arg = CALL_EXPR_ARG (orig_method_call, 3); \
287 value_arg = CALL_EXPR_ARG (orig_method_call, 4); \
288 value_type = TREE_TYPE (value_arg); \
290 while (0)
292 /* Add an address to an offset, forming a sum. */
294 static tree
295 build_addr_sum (tree type, tree addr, tree offset)
297 tree ptr_type = build_pointer_type (type);
298 return fold_build_pointer_plus (fold_convert (ptr_type, addr), offset);
301 /* Make sure that this-arg is non-NULL. This is a security check. */
303 static tree
304 build_check_this (tree stmt, tree this_arg)
306 return build2 (COMPOUND_EXPR, TREE_TYPE (stmt),
307 java_check_reference (this_arg, 1), stmt);
310 /* Now the builtins. These correspond to the primitive functions in
311 libjava/sun/misc/natUnsafe.cc. */
313 static tree
314 putObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
315 tree orig_call)
317 tree addr, stmt;
318 UNMARSHAL4 (orig_call);
320 addr = build_addr_sum (value_type, obj_arg, offset_arg);
321 stmt = fold_build2 (MODIFY_EXPR, value_type,
322 build_java_indirect_ref (value_type, addr,
323 flag_check_references),
324 value_arg);
326 return build_check_this (stmt, this_arg);
329 static tree
330 compareAndSwapInt_builtin (tree method_return_type ATTRIBUTE_UNUSED,
331 tree orig_call)
333 machine_mode mode = TYPE_MODE (int_type_node);
334 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
336 tree addr, stmt;
337 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
338 UNMARSHAL5 (orig_call);
339 (void) value_type; /* Avoid set but not used warning. */
341 addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
342 stmt = build_call_expr (builtin_decl_explicit (fncode),
343 3, addr, expected_arg, value_arg);
345 return build_check_this (stmt, this_arg);
347 return NULL_TREE;
350 static tree
351 compareAndSwapLong_builtin (tree method_return_type ATTRIBUTE_UNUSED,
352 tree orig_call)
354 machine_mode mode = TYPE_MODE (long_type_node);
355 /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
356 Some machines such as ARM have atomic libfuncs but not the multi-word
357 versions. */
358 if (can_compare_and_swap_p (mode,
359 (flag_use_atomic_builtins
360 && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
362 tree addr, stmt;
363 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
364 UNMARSHAL5 (orig_call);
365 (void) value_type; /* Avoid set but not used warning. */
367 addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
368 stmt = build_call_expr (builtin_decl_explicit (fncode),
369 3, addr, expected_arg, value_arg);
371 return build_check_this (stmt, this_arg);
373 return NULL_TREE;
375 static tree
376 compareAndSwapObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
377 tree orig_call)
379 machine_mode mode = TYPE_MODE (ptr_type_node);
380 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
382 tree addr, stmt;
383 enum built_in_function builtin;
385 UNMARSHAL5 (orig_call);
386 builtin = (POINTER_SIZE == 32
387 ? BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4
388 : BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8);
390 addr = build_addr_sum (value_type, obj_arg, offset_arg);
391 stmt = build_call_expr (builtin_decl_explicit (builtin),
392 3, addr, expected_arg, value_arg);
394 return build_check_this (stmt, this_arg);
396 return NULL_TREE;
399 static tree
400 putVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
401 tree orig_call)
403 tree addr, stmt, modify_stmt;
404 UNMARSHAL4 (orig_call);
406 addr = build_addr_sum (value_type, obj_arg, offset_arg);
407 addr
408 = fold_convert (build_pointer_type (build_qualified_type
409 (value_type, TYPE_QUAL_VOLATILE)),
410 addr);
412 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
413 modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
414 build_java_indirect_ref (value_type, addr,
415 flag_check_references),
416 value_arg);
417 stmt = build2 (COMPOUND_EXPR, TREE_TYPE (modify_stmt),
418 stmt, modify_stmt);
420 return build_check_this (stmt, this_arg);
423 static tree
424 getVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
425 tree orig_call)
427 tree addr, stmt, modify_stmt, tmp;
428 UNMARSHAL3 (orig_call);
429 (void) this_arg; /* Avoid set but not used warning. */
431 addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
432 addr
433 = fold_convert (build_pointer_type (build_qualified_type
434 (method_return_type,
435 TYPE_QUAL_VOLATILE)), addr);
437 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
438 tmp = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL, method_return_type);
439 DECL_IGNORED_P (tmp) = 1;
440 DECL_ARTIFICIAL (tmp) = 1;
441 pushdecl (tmp);
443 modify_stmt = fold_build2 (MODIFY_EXPR, method_return_type,
444 tmp,
445 build_java_indirect_ref (method_return_type, addr,
446 flag_check_references));
448 stmt = build2 (COMPOUND_EXPR, void_type_node, modify_stmt, stmt);
449 stmt = build2 (COMPOUND_EXPR, method_return_type, stmt, tmp);
451 return stmt;
454 static tree
455 VMSupportsCS8_builtin (tree method_return_type,
456 tree orig_call ATTRIBUTE_UNUSED)
458 machine_mode mode = TYPE_MODE (long_type_node);
459 gcc_assert (method_return_type == boolean_type_node);
460 if (can_compare_and_swap_p (mode, false))
461 return boolean_true_node;
462 else
463 return boolean_false_node;
468 /* Define a single builtin. */
469 static void
470 define_builtin (enum built_in_function val,
471 const char *name,
472 tree type,
473 const char *libname,
474 int flags)
476 tree decl;
478 decl = build_decl (BUILTINS_LOCATION,
479 FUNCTION_DECL, get_identifier (name), type);
480 DECL_EXTERNAL (decl) = 1;
481 TREE_PUBLIC (decl) = 1;
482 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
483 pushdecl (decl);
484 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
485 DECL_FUNCTION_CODE (decl) = val;
486 set_call_expr_flags (decl, flags);
488 set_builtin_decl (val, decl, true);
493 /* Initialize the builtins. */
494 void
495 initialize_builtins (void)
497 tree double_ftype_double, double_ftype_double_double;
498 tree float_ftype_float_float;
499 tree boolean_ftype_boolean_boolean;
500 int i;
502 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
504 tree klass_id = get_identifier (java_builtins[i].class_name.s);
505 tree m = get_identifier (java_builtins[i].method_name.s);
507 java_builtins[i].class_name.t = klass_id;
508 java_builtins[i].method_name.t = m;
511 void_list_node = end_params_node;
513 float_ftype_float_float
514 = build_function_type_list (float_type_node,
515 float_type_node, float_type_node, NULL_TREE);
517 double_ftype_double
518 = build_function_type_list (double_type_node, double_type_node, NULL_TREE);
519 double_ftype_double_double
520 = build_function_type_list (double_type_node,
521 double_type_node, double_type_node, NULL_TREE);
523 define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
524 double_ftype_double_double, "fmod", ECF_CONST);
525 define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
526 float_ftype_float_float, "fmodf", ECF_CONST);
528 define_builtin (BUILT_IN_ACOS, "__builtin_acos",
529 double_ftype_double, "_ZN4java4lang4Math4acosEJdd",
530 ECF_CONST);
531 define_builtin (BUILT_IN_ASIN, "__builtin_asin",
532 double_ftype_double, "_ZN4java4lang4Math4asinEJdd",
533 ECF_CONST);
534 define_builtin (BUILT_IN_ATAN, "__builtin_atan",
535 double_ftype_double, "_ZN4java4lang4Math4atanEJdd",
536 ECF_CONST);
537 define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
538 double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd",
539 ECF_CONST);
540 define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
541 double_ftype_double, "_ZN4java4lang4Math4ceilEJdd",
542 ECF_CONST);
543 define_builtin (BUILT_IN_COS, "__builtin_cos",
544 double_ftype_double, "_ZN4java4lang4Math3cosEJdd",
545 ECF_CONST);
546 define_builtin (BUILT_IN_EXP, "__builtin_exp",
547 double_ftype_double, "_ZN4java4lang4Math3expEJdd",
548 ECF_CONST);
549 define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
550 double_ftype_double, "_ZN4java4lang4Math5floorEJdd",
551 ECF_CONST);
552 define_builtin (BUILT_IN_LOG, "__builtin_log",
553 double_ftype_double, "_ZN4java4lang4Math3logEJdd",
554 ECF_CONST);
555 define_builtin (BUILT_IN_POW, "__builtin_pow",
556 double_ftype_double_double, "_ZN4java4lang4Math3powEJddd",
557 ECF_CONST);
558 define_builtin (BUILT_IN_SIN, "__builtin_sin",
559 double_ftype_double, "_ZN4java4lang4Math3sinEJdd",
560 ECF_CONST);
561 define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
562 double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd",
563 ECF_CONST);
564 define_builtin (BUILT_IN_TAN, "__builtin_tan",
565 double_ftype_double, "_ZN4java4lang4Math3tanEJdd",
566 ECF_CONST);
568 boolean_ftype_boolean_boolean
569 = build_function_type_list (boolean_type_node,
570 boolean_type_node, boolean_type_node,
571 NULL_TREE);
572 define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
573 boolean_ftype_boolean_boolean,
574 "__builtin_expect",
575 ECF_CONST | ECF_NOTHROW);
576 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4,
577 "__sync_bool_compare_and_swap_4",
578 build_function_type_list (boolean_type_node,
579 int_type_node,
580 build_pointer_type (int_type_node),
581 int_type_node, NULL_TREE),
582 "__sync_bool_compare_and_swap_4", ECF_NOTHROW | ECF_LEAF);
583 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8,
584 "__sync_bool_compare_and_swap_8",
585 build_function_type_list (boolean_type_node,
586 long_type_node,
587 build_pointer_type (long_type_node),
588 int_type_node, NULL_TREE),
589 "__sync_bool_compare_and_swap_8", ECF_NOTHROW | ECF_LEAF);
590 define_builtin (BUILT_IN_SYNC_SYNCHRONIZE, "__sync_synchronize",
591 build_function_type_list (void_type_node, NULL_TREE),
592 "__sync_synchronize", ECF_NOTHROW | ECF_LEAF);
594 define_builtin (BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
595 build_function_type_list (ptr_type_node, int_type_node, NULL_TREE),
596 "__builtin_return_address", ECF_NOTHROW | ECF_LEAF);
597 define_builtin (BUILT_IN_TRAP, "__builtin_trap",
598 build_function_type_list (void_type_node, NULL_TREE),
599 "__builtin_trap", ECF_NOTHROW | ECF_LEAF | ECF_NORETURN);
600 build_common_builtin_nodes ();
603 /* If the call matches a builtin, return the
604 appropriate builtin expression instead. */
605 tree
606 check_for_builtin (tree method, tree call)
608 if (optimize && TREE_CODE (call) == CALL_EXPR)
610 int i;
611 tree method_class = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
612 tree method_name = DECL_NAME (method);
613 tree method_return_type = TREE_TYPE (TREE_TYPE (method));
615 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
617 if (method_class == java_builtins[i].class_name.t
618 && method_name == java_builtins[i].method_name.t)
620 tree fn;
622 if (java_builtins[i].creator != NULL)
624 tree result
625 = (*java_builtins[i].creator) (method_return_type, call);
626 return result == NULL_TREE ? call : result;
629 /* Builtin functions emit a direct call which is incompatible
630 with the BC-ABI. */
631 if (flag_indirect_dispatch)
632 return call;
633 fn = builtin_decl_explicit (java_builtins[i].builtin_code);
634 if (fn == NULL_TREE)
635 return call;
636 return java_build_function_call_expr (fn, call);
640 return call;
643 #include "gt-java-builtins.h"