gcc/
[official-gcc.git] / gcc / java / builtins.c
blob6c7545b9ada28abd239e17b676dd33634ef3d803
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 "symtab.h"
35 #include "options.h"
36 #include "tree.h"
37 #include "fold-const.h"
38 #include "stor-layout.h"
39 #include "stringpool.h"
40 #include "flags.h"
41 #include "langhooks.h"
42 #include "java-tree.h"
44 /* FIXME: All these headers are necessary for sync_compare_and_swap.
45 Front ends should never have to look at that. */
46 #include "rtl.h"
47 #include "insn-codes.h"
48 #include "hard-reg-set.h"
49 #include "function.h"
50 #include "insn-config.h"
51 #include "expmed.h"
52 #include "dojump.h"
53 #include "explow.h"
54 #include "calls.h"
55 #include "emit-rtl.h"
56 #include "varasm.h"
57 #include "stmt.h"
58 #include "expr.h"
59 #include "optabs.h"
61 static tree max_builtin (tree, tree);
62 static tree min_builtin (tree, tree);
63 static tree abs_builtin (tree, tree);
64 static tree convert_real (tree, tree);
66 static tree java_build_function_call_expr (tree, tree);
68 static tree putObject_builtin (tree, tree);
69 static tree compareAndSwapInt_builtin (tree, tree);
70 static tree compareAndSwapLong_builtin (tree, tree);
71 static tree compareAndSwapObject_builtin (tree, tree);
72 static tree putVolatile_builtin (tree, tree);
73 static tree getVolatile_builtin (tree, tree);
74 static tree VMSupportsCS8_builtin (tree, tree);
77 /* Functions of this type are used to inline a given call. Such a
78 function should either return an expression, if the call is to be
79 inlined, or NULL_TREE if a real call should be emitted. Arguments
80 are method return type and the original CALL_EXPR containing the
81 arguments to the call. */
82 typedef tree builtin_creator_function (tree, tree);
84 /* Hold a char*, before initialization, or a tree, after
85 initialization. */
86 union GTY(()) string_or_tree {
87 const char * GTY ((tag ("0"))) s;
88 tree GTY ((tag ("1"))) t;
91 /* Used to hold a single builtin record. */
92 struct GTY(()) builtin_record {
93 union string_or_tree GTY ((desc ("1"))) class_name;
94 union string_or_tree GTY ((desc ("1"))) method_name;
95 builtin_creator_function * GTY((skip)) creator;
96 enum built_in_function builtin_code;
99 static GTY(()) struct builtin_record java_builtins[] =
101 { { "java.lang.Math" }, { "min" }, min_builtin, (enum built_in_function) 0 },
102 { { "java.lang.Math" }, { "max" }, max_builtin, (enum built_in_function) 0 },
103 { { "java.lang.Math" }, { "abs" }, abs_builtin, (enum built_in_function) 0 },
104 { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
105 { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
106 { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
107 { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
108 { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
109 { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
110 { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
111 { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
112 { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
113 { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
114 { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
115 { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT },
116 { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN },
117 { { "java.lang.Float" }, { "intBitsToFloat" }, convert_real,
118 (enum built_in_function) 0 },
119 { { "java.lang.Double" }, { "longBitsToDouble" }, convert_real,
120 (enum built_in_function) 0 },
121 { { "java.lang.Float" }, { "floatToRawIntBits" }, convert_real,
122 (enum built_in_function) 0 },
123 { { "java.lang.Double" }, { "doubleToRawLongBits" }, convert_real,
124 (enum built_in_function) 0 },
125 { { "sun.misc.Unsafe" }, { "putInt" }, putObject_builtin,
126 (enum built_in_function) 0},
127 { { "sun.misc.Unsafe" }, { "putLong" }, putObject_builtin,
128 (enum built_in_function) 0},
129 { { "sun.misc.Unsafe" }, { "putObject" }, putObject_builtin,
130 (enum built_in_function) 0},
131 { { "sun.misc.Unsafe" }, { "compareAndSwapInt" },
132 compareAndSwapInt_builtin, (enum built_in_function) 0},
133 { { "sun.misc.Unsafe" }, { "compareAndSwapLong" },
134 compareAndSwapLong_builtin, (enum built_in_function) 0},
135 { { "sun.misc.Unsafe" }, { "compareAndSwapObject" },
136 compareAndSwapObject_builtin, (enum built_in_function) 0},
137 { { "sun.misc.Unsafe" }, { "putOrderedInt" }, putVolatile_builtin,
138 (enum built_in_function) 0},
139 { { "sun.misc.Unsafe" }, { "putOrderedLong" }, putVolatile_builtin,
140 (enum built_in_function) 0},
141 { { "sun.misc.Unsafe" }, { "putOrderedObject" }, putVolatile_builtin,
142 (enum built_in_function) 0},
143 { { "sun.misc.Unsafe" }, { "putIntVolatile" }, putVolatile_builtin,
144 (enum built_in_function) 0},
145 { { "sun.misc.Unsafe" }, { "putLongVolatile" }, putVolatile_builtin,
146 (enum built_in_function) 0},
147 { { "sun.misc.Unsafe" }, { "putObjectVolatile" }, putVolatile_builtin,
148 (enum built_in_function) 0},
149 { { "sun.misc.Unsafe" }, { "getObjectVolatile" }, getVolatile_builtin,
150 (enum built_in_function) 0},
151 { { "sun.misc.Unsafe" }, { "getIntVolatile" }, getVolatile_builtin,
152 (enum built_in_function) 0},
153 { { "sun.misc.Unsafe" }, { "getLongVolatile" }, getVolatile_builtin, (enum built_in_function) 0},
154 { { "sun.misc.Unsafe" }, { "getLong" }, getVolatile_builtin,
155 (enum built_in_function) 0},
156 { { "java.util.concurrent.atomic.AtomicLong" }, { "VMSupportsCS8" },
157 VMSupportsCS8_builtin, (enum built_in_function) 0},
158 { { NULL }, { NULL }, NULL, END_BUILTINS }
162 /* Internal functions which implement various builtin conversions. */
164 static tree
165 max_builtin (tree method_return_type, tree orig_call)
167 /* MAX_EXPR does not handle -0.0 in the Java style. */
168 if (TREE_CODE (method_return_type) == REAL_TYPE)
169 return NULL_TREE;
170 return fold_build2 (MAX_EXPR, method_return_type,
171 CALL_EXPR_ARG (orig_call, 0),
172 CALL_EXPR_ARG (orig_call, 1));
175 static tree
176 min_builtin (tree method_return_type, tree orig_call)
178 /* MIN_EXPR does not handle -0.0 in the Java style. */
179 if (TREE_CODE (method_return_type) == REAL_TYPE)
180 return NULL_TREE;
181 return fold_build2 (MIN_EXPR, method_return_type,
182 CALL_EXPR_ARG (orig_call, 0),
183 CALL_EXPR_ARG (orig_call, 1));
186 static tree
187 abs_builtin (tree method_return_type, tree orig_call)
189 return fold_build1 (ABS_EXPR, method_return_type,
190 CALL_EXPR_ARG (orig_call, 0));
193 /* Construct a new call to FN using the arguments from ORIG_CALL. */
195 static tree
196 java_build_function_call_expr (tree fn, tree orig_call)
198 int nargs = call_expr_nargs (orig_call);
199 switch (nargs)
201 /* Although we could handle the 0-3 argument cases using the general
202 logic in the default case, splitting them out permits folding to
203 be performed without constructing a temporary CALL_EXPR. */
204 case 0:
205 return build_call_expr (fn, 0);
206 case 1:
207 return build_call_expr (fn, 1, CALL_EXPR_ARG (orig_call, 0));
208 case 2:
209 return build_call_expr (fn, 2,
210 CALL_EXPR_ARG (orig_call, 0),
211 CALL_EXPR_ARG (orig_call, 1));
212 case 3:
213 return build_call_expr (fn, 3,
214 CALL_EXPR_ARG (orig_call, 0),
215 CALL_EXPR_ARG (orig_call, 1),
216 CALL_EXPR_ARG (orig_call, 2));
217 default:
219 tree fntype = TREE_TYPE (fn);
220 fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn);
221 return fold (build_call_array (TREE_TYPE (fntype),
222 fn, nargs, CALL_EXPR_ARGP (orig_call)));
227 static tree
228 convert_real (tree method_return_type, tree orig_call)
230 return build1 (VIEW_CONVERT_EXPR, method_return_type,
231 CALL_EXPR_ARG (orig_call, 0));
236 /* Provide builtin support for atomic operations. These are
237 documented at length in libjava/sun/misc/Unsafe.java. */
239 /* FIXME. There are still a few things wrong with this logic. In
240 particular, atomic writes of multi-word integers are not truly
241 atomic: this requires more work.
243 In general, double-word compare-and-swap cannot portably be
244 implemented, so we need some kind of fallback for 32-bit machines.
249 /* Macros to unmarshal arguments from a CALL_EXPR into a few
250 variables. We also convert the offset arg from a long to an
251 integer that is the same size as a pointer. */
253 #define UNMARSHAL3(METHOD_CALL) \
254 tree this_arg, obj_arg, offset_arg; \
255 do \
257 tree orig_method_call = METHOD_CALL; \
258 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
259 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
260 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
261 CALL_EXPR_ARG (orig_method_call, 2)); \
263 while (0)
265 #define UNMARSHAL4(METHOD_CALL) \
266 tree value_type, this_arg, obj_arg, offset_arg, value_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)); \
274 value_arg = CALL_EXPR_ARG (orig_method_call, 3); \
275 value_type = TREE_TYPE (value_arg); \
277 while (0)
279 #define UNMARSHAL5(METHOD_CALL) \
280 tree value_type, this_arg, obj_arg, offset_arg, expected_arg, value_arg; \
281 do \
283 tree orig_method_call = METHOD_CALL; \
284 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
285 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
286 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
287 CALL_EXPR_ARG (orig_method_call, 2)); \
288 expected_arg = CALL_EXPR_ARG (orig_method_call, 3); \
289 value_arg = CALL_EXPR_ARG (orig_method_call, 4); \
290 value_type = TREE_TYPE (value_arg); \
292 while (0)
294 /* Add an address to an offset, forming a sum. */
296 static tree
297 build_addr_sum (tree type, tree addr, tree offset)
299 tree ptr_type = build_pointer_type (type);
300 return fold_build_pointer_plus (fold_convert (ptr_type, addr), offset);
303 /* Make sure that this-arg is non-NULL. This is a security check. */
305 static tree
306 build_check_this (tree stmt, tree this_arg)
308 return build2 (COMPOUND_EXPR, TREE_TYPE (stmt),
309 java_check_reference (this_arg, 1), stmt);
312 /* Now the builtins. These correspond to the primitive functions in
313 libjava/sun/misc/natUnsafe.cc. */
315 static tree
316 putObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
317 tree orig_call)
319 tree addr, stmt;
320 UNMARSHAL4 (orig_call);
322 addr = build_addr_sum (value_type, obj_arg, offset_arg);
323 stmt = fold_build2 (MODIFY_EXPR, value_type,
324 build_java_indirect_ref (value_type, addr,
325 flag_check_references),
326 value_arg);
328 return build_check_this (stmt, this_arg);
331 static tree
332 compareAndSwapInt_builtin (tree method_return_type ATTRIBUTE_UNUSED,
333 tree orig_call)
335 machine_mode mode = TYPE_MODE (int_type_node);
336 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
338 tree addr, stmt;
339 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
340 UNMARSHAL5 (orig_call);
341 (void) value_type; /* Avoid set but not used warning. */
343 addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
344 stmt = build_call_expr (builtin_decl_explicit (fncode),
345 3, addr, expected_arg, value_arg);
347 return build_check_this (stmt, this_arg);
349 return NULL_TREE;
352 static tree
353 compareAndSwapLong_builtin (tree method_return_type ATTRIBUTE_UNUSED,
354 tree orig_call)
356 machine_mode mode = TYPE_MODE (long_type_node);
357 /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
358 Some machines such as ARM have atomic libfuncs but not the multi-word
359 versions. */
360 if (can_compare_and_swap_p (mode,
361 (flag_use_atomic_builtins
362 && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
364 tree addr, stmt;
365 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
366 UNMARSHAL5 (orig_call);
367 (void) value_type; /* Avoid set but not used warning. */
369 addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
370 stmt = build_call_expr (builtin_decl_explicit (fncode),
371 3, addr, expected_arg, value_arg);
373 return build_check_this (stmt, this_arg);
375 return NULL_TREE;
377 static tree
378 compareAndSwapObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
379 tree orig_call)
381 machine_mode mode = TYPE_MODE (ptr_type_node);
382 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
384 tree addr, stmt;
385 enum built_in_function builtin;
387 UNMARSHAL5 (orig_call);
388 builtin = (POINTER_SIZE == 32
389 ? BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4
390 : BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8);
392 addr = build_addr_sum (value_type, obj_arg, offset_arg);
393 stmt = build_call_expr (builtin_decl_explicit (builtin),
394 3, addr, expected_arg, value_arg);
396 return build_check_this (stmt, this_arg);
398 return NULL_TREE;
401 static tree
402 putVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
403 tree orig_call)
405 tree addr, stmt, modify_stmt;
406 UNMARSHAL4 (orig_call);
408 addr = build_addr_sum (value_type, obj_arg, offset_arg);
409 addr
410 = fold_convert (build_pointer_type (build_qualified_type
411 (value_type, TYPE_QUAL_VOLATILE)),
412 addr);
414 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
415 modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
416 build_java_indirect_ref (value_type, addr,
417 flag_check_references),
418 value_arg);
419 stmt = build2 (COMPOUND_EXPR, TREE_TYPE (modify_stmt),
420 stmt, modify_stmt);
422 return build_check_this (stmt, this_arg);
425 static tree
426 getVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
427 tree orig_call)
429 tree addr, stmt, modify_stmt, tmp;
430 UNMARSHAL3 (orig_call);
431 (void) this_arg; /* Avoid set but not used warning. */
433 addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
434 addr
435 = fold_convert (build_pointer_type (build_qualified_type
436 (method_return_type,
437 TYPE_QUAL_VOLATILE)), addr);
439 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
440 tmp = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL, method_return_type);
441 DECL_IGNORED_P (tmp) = 1;
442 DECL_ARTIFICIAL (tmp) = 1;
443 pushdecl (tmp);
445 modify_stmt = fold_build2 (MODIFY_EXPR, method_return_type,
446 tmp,
447 build_java_indirect_ref (method_return_type, addr,
448 flag_check_references));
450 stmt = build2 (COMPOUND_EXPR, void_type_node, modify_stmt, stmt);
451 stmt = build2 (COMPOUND_EXPR, method_return_type, stmt, tmp);
453 return stmt;
456 static tree
457 VMSupportsCS8_builtin (tree method_return_type,
458 tree orig_call ATTRIBUTE_UNUSED)
460 machine_mode mode = TYPE_MODE (long_type_node);
461 gcc_assert (method_return_type == boolean_type_node);
462 if (can_compare_and_swap_p (mode, false))
463 return boolean_true_node;
464 else
465 return boolean_false_node;
470 /* Define a single builtin. */
471 static void
472 define_builtin (enum built_in_function val,
473 const char *name,
474 tree type,
475 const char *libname,
476 int flags)
478 tree decl;
480 decl = build_decl (BUILTINS_LOCATION,
481 FUNCTION_DECL, get_identifier (name), type);
482 DECL_EXTERNAL (decl) = 1;
483 TREE_PUBLIC (decl) = 1;
484 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
485 pushdecl (decl);
486 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
487 DECL_FUNCTION_CODE (decl) = val;
488 set_call_expr_flags (decl, flags);
490 set_builtin_decl (val, decl, true);
495 /* Initialize the builtins. */
496 void
497 initialize_builtins (void)
499 tree double_ftype_double, double_ftype_double_double;
500 tree float_ftype_float_float;
501 tree boolean_ftype_boolean_boolean;
502 int i;
504 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
506 tree klass_id = get_identifier (java_builtins[i].class_name.s);
507 tree m = get_identifier (java_builtins[i].method_name.s);
509 java_builtins[i].class_name.t = klass_id;
510 java_builtins[i].method_name.t = m;
513 void_list_node = end_params_node;
515 float_ftype_float_float
516 = build_function_type_list (float_type_node,
517 float_type_node, float_type_node, NULL_TREE);
519 double_ftype_double
520 = build_function_type_list (double_type_node, double_type_node, NULL_TREE);
521 double_ftype_double_double
522 = build_function_type_list (double_type_node,
523 double_type_node, double_type_node, NULL_TREE);
525 define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
526 double_ftype_double_double, "fmod", ECF_CONST);
527 define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
528 float_ftype_float_float, "fmodf", ECF_CONST);
530 define_builtin (BUILT_IN_ACOS, "__builtin_acos",
531 double_ftype_double, "_ZN4java4lang4Math4acosEJdd",
532 ECF_CONST);
533 define_builtin (BUILT_IN_ASIN, "__builtin_asin",
534 double_ftype_double, "_ZN4java4lang4Math4asinEJdd",
535 ECF_CONST);
536 define_builtin (BUILT_IN_ATAN, "__builtin_atan",
537 double_ftype_double, "_ZN4java4lang4Math4atanEJdd",
538 ECF_CONST);
539 define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
540 double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd",
541 ECF_CONST);
542 define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
543 double_ftype_double, "_ZN4java4lang4Math4ceilEJdd",
544 ECF_CONST);
545 define_builtin (BUILT_IN_COS, "__builtin_cos",
546 double_ftype_double, "_ZN4java4lang4Math3cosEJdd",
547 ECF_CONST);
548 define_builtin (BUILT_IN_EXP, "__builtin_exp",
549 double_ftype_double, "_ZN4java4lang4Math3expEJdd",
550 ECF_CONST);
551 define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
552 double_ftype_double, "_ZN4java4lang4Math5floorEJdd",
553 ECF_CONST);
554 define_builtin (BUILT_IN_LOG, "__builtin_log",
555 double_ftype_double, "_ZN4java4lang4Math3logEJdd",
556 ECF_CONST);
557 define_builtin (BUILT_IN_POW, "__builtin_pow",
558 double_ftype_double_double, "_ZN4java4lang4Math3powEJddd",
559 ECF_CONST);
560 define_builtin (BUILT_IN_SIN, "__builtin_sin",
561 double_ftype_double, "_ZN4java4lang4Math3sinEJdd",
562 ECF_CONST);
563 define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
564 double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd",
565 ECF_CONST);
566 define_builtin (BUILT_IN_TAN, "__builtin_tan",
567 double_ftype_double, "_ZN4java4lang4Math3tanEJdd",
568 ECF_CONST);
570 boolean_ftype_boolean_boolean
571 = build_function_type_list (boolean_type_node,
572 boolean_type_node, boolean_type_node,
573 NULL_TREE);
574 define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
575 boolean_ftype_boolean_boolean,
576 "__builtin_expect",
577 ECF_CONST | ECF_NOTHROW);
578 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4,
579 "__sync_bool_compare_and_swap_4",
580 build_function_type_list (boolean_type_node,
581 int_type_node,
582 build_pointer_type (int_type_node),
583 int_type_node, NULL_TREE),
584 "__sync_bool_compare_and_swap_4", ECF_NOTHROW | ECF_LEAF);
585 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8,
586 "__sync_bool_compare_and_swap_8",
587 build_function_type_list (boolean_type_node,
588 long_type_node,
589 build_pointer_type (long_type_node),
590 int_type_node, NULL_TREE),
591 "__sync_bool_compare_and_swap_8", ECF_NOTHROW | ECF_LEAF);
592 define_builtin (BUILT_IN_SYNC_SYNCHRONIZE, "__sync_synchronize",
593 build_function_type_list (void_type_node, NULL_TREE),
594 "__sync_synchronize", ECF_NOTHROW | ECF_LEAF);
596 define_builtin (BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
597 build_function_type_list (ptr_type_node, int_type_node, NULL_TREE),
598 "__builtin_return_address", ECF_NOTHROW | ECF_LEAF);
599 define_builtin (BUILT_IN_TRAP, "__builtin_trap",
600 build_function_type_list (void_type_node, NULL_TREE),
601 "__builtin_trap", ECF_NOTHROW | ECF_LEAF | ECF_NORETURN);
602 build_common_builtin_nodes ();
605 /* If the call matches a builtin, return the
606 appropriate builtin expression instead. */
607 tree
608 check_for_builtin (tree method, tree call)
610 if (optimize && TREE_CODE (call) == CALL_EXPR)
612 int i;
613 tree method_class = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
614 tree method_name = DECL_NAME (method);
615 tree method_return_type = TREE_TYPE (TREE_TYPE (method));
617 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
619 if (method_class == java_builtins[i].class_name.t
620 && method_name == java_builtins[i].method_name.t)
622 tree fn;
624 if (java_builtins[i].creator != NULL)
626 tree result
627 = (*java_builtins[i].creator) (method_return_type, call);
628 return result == NULL_TREE ? call : result;
631 /* Builtin functions emit a direct call which is incompatible
632 with the BC-ABI. */
633 if (flag_indirect_dispatch)
634 return call;
635 fn = builtin_decl_explicit (java_builtins[i].builtin_code);
636 if (fn == NULL_TREE)
637 return call;
638 return java_build_function_call_expr (fn, call);
642 return call;
645 #include "gt-java-builtins.h"