2013-05-30 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / java / builtins.c
blobf971a6fb25e4a7fc1ac1b083981bdb2ed2fba326
1 /* Built-in and inline functions for gcj
2 Copyright (C) 2001-2013 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 "ggc.h"
35 #include "flags.h"
36 #include "langhooks.h"
37 #include "java-tree.h"
39 /* FIXME: All these headers are necessary for sync_compare_and_swap.
40 Front ends should never have to look at that. */
41 #include "rtl.h"
42 #include "insn-codes.h"
43 #include "expr.h"
44 #include "optabs.h"
46 static tree max_builtin (tree, tree);
47 static tree min_builtin (tree, tree);
48 static tree abs_builtin (tree, tree);
49 static tree convert_real (tree, tree);
51 static tree java_build_function_call_expr (tree, tree);
53 static tree putObject_builtin (tree, tree);
54 static tree compareAndSwapInt_builtin (tree, tree);
55 static tree compareAndSwapLong_builtin (tree, tree);
56 static tree compareAndSwapObject_builtin (tree, tree);
57 static tree putVolatile_builtin (tree, tree);
58 static tree getVolatile_builtin (tree, tree);
59 static tree VMSupportsCS8_builtin (tree, tree);
62 /* Functions of this type are used to inline a given call. Such a
63 function should either return an expression, if the call is to be
64 inlined, or NULL_TREE if a real call should be emitted. Arguments
65 are method return type and the original CALL_EXPR containing the
66 arguments to the call. */
67 typedef tree builtin_creator_function (tree, tree);
69 /* Hold a char*, before initialization, or a tree, after
70 initialization. */
71 union GTY(()) string_or_tree {
72 const char * GTY ((tag ("0"))) s;
73 tree GTY ((tag ("1"))) t;
76 /* Used to hold a single builtin record. */
77 struct GTY(()) builtin_record {
78 union string_or_tree GTY ((desc ("1"))) class_name;
79 union string_or_tree GTY ((desc ("1"))) method_name;
80 builtin_creator_function * GTY((skip)) creator;
81 enum built_in_function builtin_code;
84 static GTY(()) struct builtin_record java_builtins[] =
86 { { "java.lang.Math" }, { "min" }, min_builtin, (enum built_in_function) 0 },
87 { { "java.lang.Math" }, { "max" }, max_builtin, (enum built_in_function) 0 },
88 { { "java.lang.Math" }, { "abs" }, abs_builtin, (enum built_in_function) 0 },
89 { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
90 { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
91 { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
92 { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
93 { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
94 { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
95 { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
96 { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
97 { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
98 { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
99 { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
100 { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT },
101 { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN },
102 { { "java.lang.Float" }, { "intBitsToFloat" }, convert_real,
103 (enum built_in_function) 0 },
104 { { "java.lang.Double" }, { "longBitsToDouble" }, convert_real,
105 (enum built_in_function) 0 },
106 { { "java.lang.Float" }, { "floatToRawIntBits" }, convert_real,
107 (enum built_in_function) 0 },
108 { { "java.lang.Double" }, { "doubleToRawLongBits" }, convert_real,
109 (enum built_in_function) 0 },
110 { { "sun.misc.Unsafe" }, { "putInt" }, putObject_builtin,
111 (enum built_in_function) 0},
112 { { "sun.misc.Unsafe" }, { "putLong" }, putObject_builtin,
113 (enum built_in_function) 0},
114 { { "sun.misc.Unsafe" }, { "putObject" }, putObject_builtin,
115 (enum built_in_function) 0},
116 { { "sun.misc.Unsafe" }, { "compareAndSwapInt" },
117 compareAndSwapInt_builtin, (enum built_in_function) 0},
118 { { "sun.misc.Unsafe" }, { "compareAndSwapLong" },
119 compareAndSwapLong_builtin, (enum built_in_function) 0},
120 { { "sun.misc.Unsafe" }, { "compareAndSwapObject" },
121 compareAndSwapObject_builtin, (enum built_in_function) 0},
122 { { "sun.misc.Unsafe" }, { "putOrderedInt" }, putVolatile_builtin,
123 (enum built_in_function) 0},
124 { { "sun.misc.Unsafe" }, { "putOrderedLong" }, putVolatile_builtin,
125 (enum built_in_function) 0},
126 { { "sun.misc.Unsafe" }, { "putOrderedObject" }, putVolatile_builtin,
127 (enum built_in_function) 0},
128 { { "sun.misc.Unsafe" }, { "putIntVolatile" }, putVolatile_builtin,
129 (enum built_in_function) 0},
130 { { "sun.misc.Unsafe" }, { "putLongVolatile" }, putVolatile_builtin,
131 (enum built_in_function) 0},
132 { { "sun.misc.Unsafe" }, { "putObjectVolatile" }, putVolatile_builtin,
133 (enum built_in_function) 0},
134 { { "sun.misc.Unsafe" }, { "getObjectVolatile" }, getVolatile_builtin,
135 (enum built_in_function) 0},
136 { { "sun.misc.Unsafe" }, { "getIntVolatile" }, getVolatile_builtin,
137 (enum built_in_function) 0},
138 { { "sun.misc.Unsafe" }, { "getLongVolatile" }, getVolatile_builtin, (enum built_in_function) 0},
139 { { "sun.misc.Unsafe" }, { "getLong" }, getVolatile_builtin,
140 (enum built_in_function) 0},
141 { { "java.util.concurrent.atomic.AtomicLong" }, { "VMSupportsCS8" },
142 VMSupportsCS8_builtin, (enum built_in_function) 0},
143 { { NULL }, { NULL }, NULL, END_BUILTINS }
147 /* Internal functions which implement various builtin conversions. */
149 static tree
150 max_builtin (tree method_return_type, tree orig_call)
152 /* MAX_EXPR does not handle -0.0 in the Java style. */
153 if (TREE_CODE (method_return_type) == REAL_TYPE)
154 return NULL_TREE;
155 return fold_build2 (MAX_EXPR, method_return_type,
156 CALL_EXPR_ARG (orig_call, 0),
157 CALL_EXPR_ARG (orig_call, 1));
160 static tree
161 min_builtin (tree method_return_type, tree orig_call)
163 /* MIN_EXPR does not handle -0.0 in the Java style. */
164 if (TREE_CODE (method_return_type) == REAL_TYPE)
165 return NULL_TREE;
166 return fold_build2 (MIN_EXPR, method_return_type,
167 CALL_EXPR_ARG (orig_call, 0),
168 CALL_EXPR_ARG (orig_call, 1));
171 static tree
172 abs_builtin (tree method_return_type, tree orig_call)
174 return fold_build1 (ABS_EXPR, method_return_type,
175 CALL_EXPR_ARG (orig_call, 0));
178 /* Construct a new call to FN using the arguments from ORIG_CALL. */
180 static tree
181 java_build_function_call_expr (tree fn, tree orig_call)
183 int nargs = call_expr_nargs (orig_call);
184 switch (nargs)
186 /* Although we could handle the 0-3 argument cases using the general
187 logic in the default case, splitting them out permits folding to
188 be performed without constructing a temporary CALL_EXPR. */
189 case 0:
190 return build_call_expr (fn, 0);
191 case 1:
192 return build_call_expr (fn, 1, CALL_EXPR_ARG (orig_call, 0));
193 case 2:
194 return build_call_expr (fn, 2,
195 CALL_EXPR_ARG (orig_call, 0),
196 CALL_EXPR_ARG (orig_call, 1));
197 case 3:
198 return build_call_expr (fn, 3,
199 CALL_EXPR_ARG (orig_call, 0),
200 CALL_EXPR_ARG (orig_call, 1),
201 CALL_EXPR_ARG (orig_call, 2));
202 default:
204 tree fntype = TREE_TYPE (fn);
205 fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn);
206 return fold (build_call_array (TREE_TYPE (fntype),
207 fn, nargs, CALL_EXPR_ARGP (orig_call)));
212 static tree
213 convert_real (tree method_return_type, tree orig_call)
215 return build1 (VIEW_CONVERT_EXPR, method_return_type,
216 CALL_EXPR_ARG (orig_call, 0));
221 /* Provide builtin support for atomic operations. These are
222 documented at length in libjava/sun/misc/Unsafe.java. */
224 /* FIXME. There are still a few things wrong with this logic. In
225 particular, atomic writes of multi-word integers are not truly
226 atomic: this requires more work.
228 In general, double-word compare-and-swap cannot portably be
229 implemented, so we need some kind of fallback for 32-bit machines.
234 /* Macros to unmarshal arguments from a CALL_EXPR into a few
235 variables. We also convert the offset arg from a long to an
236 integer that is the same size as a pointer. */
238 #define UNMARSHAL3(METHOD_CALL) \
239 tree this_arg, obj_arg, offset_arg; \
240 do \
242 tree orig_method_call = METHOD_CALL; \
243 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
244 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
245 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
246 CALL_EXPR_ARG (orig_method_call, 2)); \
248 while (0)
250 #define UNMARSHAL4(METHOD_CALL) \
251 tree value_type, this_arg, obj_arg, offset_arg, value_arg; \
252 do \
254 tree orig_method_call = METHOD_CALL; \
255 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
256 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
257 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
258 CALL_EXPR_ARG (orig_method_call, 2)); \
259 value_arg = CALL_EXPR_ARG (orig_method_call, 3); \
260 value_type = TREE_TYPE (value_arg); \
262 while (0)
264 #define UNMARSHAL5(METHOD_CALL) \
265 tree value_type, this_arg, obj_arg, offset_arg, expected_arg, value_arg; \
266 do \
268 tree orig_method_call = METHOD_CALL; \
269 this_arg = CALL_EXPR_ARG (orig_method_call, 0); \
270 obj_arg = CALL_EXPR_ARG (orig_method_call, 1); \
271 offset_arg = fold_convert (java_type_for_size (POINTER_SIZE, 0), \
272 CALL_EXPR_ARG (orig_method_call, 2)); \
273 expected_arg = CALL_EXPR_ARG (orig_method_call, 3); \
274 value_arg = CALL_EXPR_ARG (orig_method_call, 4); \
275 value_type = TREE_TYPE (value_arg); \
277 while (0)
279 /* Add an address to an offset, forming a sum. */
281 static tree
282 build_addr_sum (tree type, tree addr, tree offset)
284 tree ptr_type = build_pointer_type (type);
285 return fold_build_pointer_plus (fold_convert (ptr_type, addr), offset);
288 /* Make sure that this-arg is non-NULL. This is a security check. */
290 static tree
291 build_check_this (tree stmt, tree this_arg)
293 return build2 (COMPOUND_EXPR, TREE_TYPE (stmt),
294 java_check_reference (this_arg, 1), stmt);
297 /* Now the builtins. These correspond to the primitive functions in
298 libjava/sun/misc/natUnsafe.cc. */
300 static tree
301 putObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
302 tree orig_call)
304 tree addr, stmt;
305 UNMARSHAL4 (orig_call);
307 addr = build_addr_sum (value_type, obj_arg, offset_arg);
308 stmt = fold_build2 (MODIFY_EXPR, value_type,
309 build_java_indirect_ref (value_type, addr,
310 flag_check_references),
311 value_arg);
313 return build_check_this (stmt, this_arg);
316 static tree
317 compareAndSwapInt_builtin (tree method_return_type ATTRIBUTE_UNUSED,
318 tree orig_call)
320 enum machine_mode mode = TYPE_MODE (int_type_node);
321 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
323 tree addr, stmt;
324 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
325 UNMARSHAL5 (orig_call);
326 (void) value_type; /* Avoid set but not used warning. */
328 addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
329 stmt = build_call_expr (builtin_decl_explicit (fncode),
330 3, addr, expected_arg, value_arg);
332 return build_check_this (stmt, this_arg);
334 return NULL_TREE;
337 static tree
338 compareAndSwapLong_builtin (tree method_return_type ATTRIBUTE_UNUSED,
339 tree orig_call)
341 enum machine_mode mode = TYPE_MODE (long_type_node);
342 /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
343 Some machines such as ARM have atomic libfuncs but not the multi-word
344 versions. */
345 if (can_compare_and_swap_p (mode,
346 (flag_use_atomic_builtins
347 && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
349 tree addr, stmt;
350 enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
351 UNMARSHAL5 (orig_call);
352 (void) value_type; /* Avoid set but not used warning. */
354 addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
355 stmt = build_call_expr (builtin_decl_explicit (fncode),
356 3, addr, expected_arg, value_arg);
358 return build_check_this (stmt, this_arg);
360 return NULL_TREE;
362 static tree
363 compareAndSwapObject_builtin (tree method_return_type ATTRIBUTE_UNUSED,
364 tree orig_call)
366 enum machine_mode mode = TYPE_MODE (ptr_type_node);
367 if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
369 tree addr, stmt;
370 enum built_in_function builtin;
372 UNMARSHAL5 (orig_call);
373 builtin = (POINTER_SIZE == 32
374 ? BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4
375 : BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8);
377 addr = build_addr_sum (value_type, obj_arg, offset_arg);
378 stmt = build_call_expr (builtin_decl_explicit (builtin),
379 3, addr, expected_arg, value_arg);
381 return build_check_this (stmt, this_arg);
383 return NULL_TREE;
386 static tree
387 putVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
388 tree orig_call)
390 tree addr, stmt, modify_stmt;
391 UNMARSHAL4 (orig_call);
393 addr = build_addr_sum (value_type, obj_arg, offset_arg);
394 addr
395 = fold_convert (build_pointer_type (build_type_variant (value_type, 0, 1)),
396 addr);
398 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
399 modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
400 build_java_indirect_ref (value_type, addr,
401 flag_check_references),
402 value_arg);
403 stmt = build2 (COMPOUND_EXPR, TREE_TYPE (modify_stmt),
404 stmt, modify_stmt);
406 return build_check_this (stmt, this_arg);
409 static tree
410 getVolatile_builtin (tree method_return_type ATTRIBUTE_UNUSED,
411 tree orig_call)
413 tree addr, stmt, modify_stmt, tmp;
414 UNMARSHAL3 (orig_call);
415 (void) this_arg; /* Avoid set but not used warning. */
417 addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
418 addr
419 = fold_convert (build_pointer_type (build_type_variant
420 (method_return_type, 0, 1)), addr);
422 stmt = build_call_expr (builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE), 0);
423 tmp = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL, method_return_type);
424 DECL_IGNORED_P (tmp) = 1;
425 DECL_ARTIFICIAL (tmp) = 1;
426 pushdecl (tmp);
428 modify_stmt = fold_build2 (MODIFY_EXPR, method_return_type,
429 tmp,
430 build_java_indirect_ref (method_return_type, addr,
431 flag_check_references));
433 stmt = build2 (COMPOUND_EXPR, void_type_node, modify_stmt, stmt);
434 stmt = build2 (COMPOUND_EXPR, method_return_type, stmt, tmp);
436 return stmt;
439 static tree
440 VMSupportsCS8_builtin (tree method_return_type,
441 tree orig_call ATTRIBUTE_UNUSED)
443 enum machine_mode mode = TYPE_MODE (long_type_node);
444 gcc_assert (method_return_type == boolean_type_node);
445 if (can_compare_and_swap_p (mode, false))
446 return boolean_true_node;
447 else
448 return boolean_false_node;
453 /* Define a single builtin. */
454 static void
455 define_builtin (enum built_in_function val,
456 const char *name,
457 tree type,
458 const char *libname,
459 int flags)
461 tree decl;
463 decl = build_decl (BUILTINS_LOCATION,
464 FUNCTION_DECL, get_identifier (name), type);
465 DECL_EXTERNAL (decl) = 1;
466 TREE_PUBLIC (decl) = 1;
467 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
468 pushdecl (decl);
469 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
470 DECL_FUNCTION_CODE (decl) = val;
471 set_call_expr_flags (decl, flags);
473 set_builtin_decl (val, decl, true);
478 /* Initialize the builtins. */
479 void
480 initialize_builtins (void)
482 tree double_ftype_double, double_ftype_double_double;
483 tree float_ftype_float_float;
484 tree boolean_ftype_boolean_boolean;
485 int i;
487 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
489 tree klass_id = get_identifier (java_builtins[i].class_name.s);
490 tree m = get_identifier (java_builtins[i].method_name.s);
492 java_builtins[i].class_name.t = klass_id;
493 java_builtins[i].method_name.t = m;
496 void_list_node = end_params_node;
498 float_ftype_float_float
499 = build_function_type_list (float_type_node,
500 float_type_node, float_type_node, NULL_TREE);
502 double_ftype_double
503 = build_function_type_list (double_type_node, double_type_node, NULL_TREE);
504 double_ftype_double_double
505 = build_function_type_list (double_type_node,
506 double_type_node, double_type_node, NULL_TREE);
508 define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
509 double_ftype_double_double, "fmod", ECF_CONST);
510 define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
511 float_ftype_float_float, "fmodf", ECF_CONST);
513 define_builtin (BUILT_IN_ACOS, "__builtin_acos",
514 double_ftype_double, "_ZN4java4lang4Math4acosEJdd",
515 ECF_CONST);
516 define_builtin (BUILT_IN_ASIN, "__builtin_asin",
517 double_ftype_double, "_ZN4java4lang4Math4asinEJdd",
518 ECF_CONST);
519 define_builtin (BUILT_IN_ATAN, "__builtin_atan",
520 double_ftype_double, "_ZN4java4lang4Math4atanEJdd",
521 ECF_CONST);
522 define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
523 double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd",
524 ECF_CONST);
525 define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
526 double_ftype_double, "_ZN4java4lang4Math4ceilEJdd",
527 ECF_CONST);
528 define_builtin (BUILT_IN_COS, "__builtin_cos",
529 double_ftype_double, "_ZN4java4lang4Math3cosEJdd",
530 ECF_CONST);
531 define_builtin (BUILT_IN_EXP, "__builtin_exp",
532 double_ftype_double, "_ZN4java4lang4Math3expEJdd",
533 ECF_CONST);
534 define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
535 double_ftype_double, "_ZN4java4lang4Math5floorEJdd",
536 ECF_CONST);
537 define_builtin (BUILT_IN_LOG, "__builtin_log",
538 double_ftype_double, "_ZN4java4lang4Math3logEJdd",
539 ECF_CONST);
540 define_builtin (BUILT_IN_POW, "__builtin_pow",
541 double_ftype_double_double, "_ZN4java4lang4Math3powEJddd",
542 ECF_CONST);
543 define_builtin (BUILT_IN_SIN, "__builtin_sin",
544 double_ftype_double, "_ZN4java4lang4Math3sinEJdd",
545 ECF_CONST);
546 define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
547 double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd",
548 ECF_CONST);
549 define_builtin (BUILT_IN_TAN, "__builtin_tan",
550 double_ftype_double, "_ZN4java4lang4Math3tanEJdd",
551 ECF_CONST);
553 boolean_ftype_boolean_boolean
554 = build_function_type_list (boolean_type_node,
555 boolean_type_node, boolean_type_node,
556 NULL_TREE);
557 define_builtin (BUILT_IN_EXPECT, "__builtin_expect",
558 boolean_ftype_boolean_boolean,
559 "__builtin_expect",
560 ECF_CONST | ECF_NOTHROW);
561 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4,
562 "__sync_bool_compare_and_swap_4",
563 build_function_type_list (boolean_type_node,
564 int_type_node,
565 build_pointer_type (int_type_node),
566 int_type_node, NULL_TREE),
567 "__sync_bool_compare_and_swap_4", ECF_NOTHROW | ECF_LEAF);
568 define_builtin (BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8,
569 "__sync_bool_compare_and_swap_8",
570 build_function_type_list (boolean_type_node,
571 long_type_node,
572 build_pointer_type (long_type_node),
573 int_type_node, NULL_TREE),
574 "__sync_bool_compare_and_swap_8", ECF_NOTHROW | ECF_LEAF);
575 define_builtin (BUILT_IN_SYNC_SYNCHRONIZE, "__sync_synchronize",
576 build_function_type_list (void_type_node, NULL_TREE),
577 "__sync_synchronize", ECF_NOTHROW | ECF_LEAF);
579 define_builtin (BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
580 build_function_type_list (ptr_type_node, int_type_node, NULL_TREE),
581 "__builtin_return_address", ECF_NOTHROW | ECF_LEAF);
583 build_common_builtin_nodes ();
586 /* If the call matches a builtin, return the
587 appropriate builtin expression instead. */
588 tree
589 check_for_builtin (tree method, tree call)
591 if (optimize && TREE_CODE (call) == CALL_EXPR)
593 int i;
594 tree method_class = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
595 tree method_name = DECL_NAME (method);
596 tree method_return_type = TREE_TYPE (TREE_TYPE (method));
598 for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
600 if (method_class == java_builtins[i].class_name.t
601 && method_name == java_builtins[i].method_name.t)
603 tree fn;
605 if (java_builtins[i].creator != NULL)
607 tree result
608 = (*java_builtins[i].creator) (method_return_type, call);
609 return result == NULL_TREE ? call : result;
612 /* Builtin functions emit a direct call which is incompatible
613 with the BC-ABI. */
614 if (flag_indirect_dispatch)
615 return call;
616 fn = builtin_decl_explicit (java_builtins[i].builtin_code);
617 if (fn == NULL_TREE)
618 return call;
619 return java_build_function_call_expr (fn, call);
623 return call;
626 #include "gt-java-builtins.h"