1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 1987, 1991 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC 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 2, or (at your option)
11 GNU CC 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.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* The default branch cost is 1. */
32 /* Macros to access the slots of a QUEUED rtx.
33 Here rather than in rtl.h because only the expansion pass
34 should ever encounter a QUEUED. */
36 /* The variable for which an increment is queued. */
37 #define QUEUED_VAR(P) XEXP (P, 0)
38 /* If the increment has been emitted, this is the insn
39 that does the increment. It is zero before the increment is emitted. */
40 #define QUEUED_INSN(P) XEXP (P, 1)
41 /* If a pre-increment copy has been generated, this is the copy
42 (it is a temporary reg). Zero if no copy made yet. */
43 #define QUEUED_COPY(P) XEXP (P, 2)
44 /* This is the body to use for the insn to do the increment.
45 It is used to emit the increment. */
46 #define QUEUED_BODY(P) XEXP (P, 3)
47 /* Next QUEUED in the queue. */
48 #define QUEUED_NEXT(P) XEXP (P, 4)
50 /* This is the 4th arg to `expand_expr'.
51 EXPAND_SUM means it is ok to return a PLUS rtx or MULT rtx.
52 EXPAND_INITIALIZER is similar but also record any labels on forced_labels.
53 EXPAND_CONST_ADDRESS means it is ok to return a MEM whose address
54 is a constant that is not a legitimate address. */
55 enum expand_modifier
{EXPAND_NORMAL
, EXPAND_SUM
,
56 EXPAND_CONST_ADDRESS
, EXPAND_INITIALIZER
};
58 /* List of labels that must never be deleted. */
59 extern rtx forced_labels
;
61 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
62 So we can mark them all live at the end of the function, if stupid. */
63 extern rtx save_expr_regs
;
65 extern int current_function_calls_alloca
;
66 extern int current_function_outgoing_args_size
;
68 /* This is the offset from the arg pointer to the place where the first
69 anonymous arg can be found, if there is one. */
70 extern rtx current_function_arg_offset_rtx
;
72 /* This is nonzero if the current function uses the constant pool. */
73 extern int current_function_uses_const_pool
;
75 /* This is nonzero if the current function uses pic_offset_table_rtx. */
76 extern int current_function_uses_pic_offset_table
;
78 /* The arg pointer hard register, or the pseudo into which it was copied. */
79 extern rtx current_function_internal_arg_pointer
;
81 /* Nonzero means stack pops must not be deferred, and deferred stack
82 pops must not be output. It is nonzero inside a function call,
83 inside a conditional expression, inside a statement expression,
84 and in other cases as well. */
85 extern int inhibit_defer_pop
;
87 /* Number of function calls seen so far in current function. */
89 extern int function_call_count
;
91 /* RTX for stack slot that holds the current handler for nonlocal gotos.
92 Zero when function does not have nonlocal labels. */
94 extern rtx nonlocal_goto_handler_slot
;
96 /* RTX for stack slot that holds the stack pointer value to restore
98 Zero when function does not have nonlocal labels. */
100 extern rtx nonlocal_goto_stack_level
;
102 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
103 (labels to which there can be nonlocal gotos from nested functions)
106 #ifdef TREE_CODE /* Don't lose if tree.h not included. */
107 extern tree nonlocal_labels
;
110 #define NO_DEFER_POP (inhibit_defer_pop += 1)
111 #define OK_DEFER_POP (inhibit_defer_pop -= 1)
113 /* Number of units that we should eventually pop off the stack.
114 These are the arguments to function calls that have already returned. */
115 extern int pending_stack_adjust
;
117 /* A list of all cleanups which belong to the arguments of
118 function calls being expanded by expand_call. */
119 #ifdef TREE_CODE /* Don't lose if tree.h not included. */
120 extern tree cleanups_this_call
;
123 #ifdef TREE_CODE /* Don't lose if tree.h not included. */
124 /* Structure to record the size of a sequence of arguments
125 as the sum of a tree-expression and a constant. */
134 /* Add the value of the tree INC to the `struct args_size' TO. */
136 #define ADD_PARM_SIZE(TO, INC) \
137 { tree inc = (INC); \
138 if (TREE_CODE (inc) == INTEGER_CST) \
139 (TO).constant += TREE_INT_CST_LOW (inc); \
140 else if ((TO).var == 0) \
143 (TO).var = size_binop (PLUS_EXPR, (TO).var, inc); }
145 #define SUB_PARM_SIZE(TO, DEC) \
146 { tree dec = (DEC); \
147 if (TREE_CODE (dec) == INTEGER_CST) \
148 (TO).constant -= TREE_INT_CST_LOW (dec); \
149 else if ((TO).var == 0) \
150 (TO).var = size_binop (MINUS_EXPR, integer_zero_node, dec); \
152 (TO).var = size_binop (MINUS_EXPR, (TO).var, dec); }
154 /* Convert the implicit sum in a `struct args_size' into an rtx. */
155 #define ARGS_SIZE_RTX(SIZE) \
156 ((SIZE).var == 0 ? gen_rtx (CONST_INT, VOIDmode, (SIZE).constant) \
157 : expand_expr (size_binop (PLUS_EXPR, (SIZE).var, \
158 size_int ((SIZE).constant)), \
161 /* Convert the implicit sum in a `struct args_size' into a tree. */
162 #define ARGS_SIZE_TREE(SIZE) \
163 ((SIZE).var == 0 ? size_int ((SIZE).constant) \
164 : size_binop (PLUS_EXPR, (SIZE).var, size_int ((SIZE).constant)))
166 /* Supply a default definition for FUNCTION_ARG_PADDING:
167 usually pad upward, but pad short, non-BLKmode args downward on
168 big-endian machines. */
170 enum direction
{none
, upward
, downward
}; /* Value has this type. */
172 #ifndef FUNCTION_ARG_PADDING
174 #define FUNCTION_ARG_PADDING(MODE, TYPE) \
175 (((MODE) == BLKmode \
176 ? ((TYPE) && TREE_CODE (TYPE_SIZE (TYPE)) == INTEGER_CST \
177 && int_size_in_bytes (TYPE) < PARM_BOUNDARY / BITS_PER_UNIT) \
178 : GET_MODE_BITSIZE (MODE) < PARM_BOUNDARY) \
181 #define FUNCTION_ARG_PADDING(MODE, TYPE) upward
185 /* Supply a default definition for FUNCTION_ARG_BOUNDARY. Normally, we let
186 FUNCTION_ARG_PADDING, which also pads the length, handle any needed
189 #ifndef FUNCTION_ARG_BOUNDARY
190 #define FUNCTION_ARG_BOUNDARY(MODE, TYPE) PARM_BOUNDARY
193 /* Nonzero if we do not know how to pass TYPE solely in registers.
194 We cannot do so in the following cases:
196 - if the type has variable size
197 - if the type is marked as addressable (it is required to be constructed
199 - if the padding and mode of the type is such that a copy into a register
200 would put it into the wrong part of the register
201 - when STRICT_ALIGNMENT and the type is BLKmode and is is not
202 aligned to a boundary corresponding to what can be loaded into a
205 #define MUST_PASS_IN_STACK_BAD_ALIGN(MODE,TYPE) \
206 (STRICT_ALIGNMENT && MODE == BLKmode \
207 && TYPE_ALIGN (TYPE) < (BIGGEST_ALIGNMENT < BITS_PER_WORD \
208 ? BIGGEST_ALIGNMENT : BITS_PER_WORD))
210 /* Which padding can't be supported depends on the byte endianness. */
212 /* A value in a register is implicitly padded at the most significant end.
213 On a big-endian machine, that is the lower end in memory.
214 So a value padded in memory at the upper end can't go in a register.
215 For a little-endian machine, the reverse is true. */
218 #define MUST_PASS_IN_STACK_BAD_PADDING upward
220 #define MUST_PASS_IN_STACK_BAD_PADDING downward
223 #define MUST_PASS_IN_STACK(MODE,TYPE) \
225 && (TREE_CODE (TYPE_SIZE (TYPE)) != INTEGER_CST \
226 || TREE_ADDRESSABLE (TYPE) \
227 || ((MODE) == BLKmode \
228 && (FUNCTION_ARG_PADDING (MODE, TYPE) \
229 == MUST_PASS_IN_STACK_BAD_PADDING)) \
230 || MUST_PASS_IN_STACK_BAD_ALIGN (MODE, TYPE)))
232 /* Nonzero if type TYPE should be returned in memory
233 (even though its mode is not BLKmode).
234 Most machines can use the following default definition. */
236 #ifndef RETURN_IN_MEMORY
237 #define RETURN_IN_MEMORY(TYPE) 0
240 /* Optabs are tables saying how to generate insn bodies
241 for various machine modes and numbers of operands.
242 Each optab applies to one operation.
243 For example, add_optab applies to addition.
245 The insn_code slot is the enum insn_code that says how to
246 generate an insn for this operation on a particular machine mode.
247 It is CODE_FOR_nothing if there is no such insn on the target machine.
249 The `lib_call' slot is the name of the library function that
250 can be used to perform the operation.
252 A few optabs, such as move_optab and cmp_optab, are used
255 /* Everything that uses expr.h needs to define enum insn_code
256 but we don't list it in the Makefile dependencies just for that. */
257 #include "insn-codes.h"
263 enum insn_code insn_code
;
265 } handlers
[NUM_MACHINE_MODES
];
268 /* Given an enum insn_code, access the function to construct
269 the body of that kind of insn. */
270 #ifdef FUNCTION_CONVERSION_BUG
271 /* Some compilers fail to convert a function properly to a
272 pointer-to-function when used as an argument.
273 So produce the pointer-to-function directly.
274 Luckily, these compilers seem to work properly when you
275 call the pointer-to-function. */
276 #define GEN_FCN(CODE) (insn_gen_function[(int) (CODE)])
278 #define GEN_FCN(CODE) (*insn_gen_function[(int) (CODE)])
281 extern rtx (*const insn_gen_function
[]) ();
283 extern optab add_optab
;
284 extern optab sub_optab
;
285 extern optab smul_optab
; /* Signed and floating-point multiply */
286 extern optab smul_widen_optab
; /* Signed multiply with result
287 one machine mode wider than args */
288 extern optab umul_widen_optab
;
289 extern optab sdiv_optab
; /* Signed divide */
290 extern optab sdivmod_optab
; /* Signed divide-and-remainder in one */
291 extern optab udiv_optab
;
292 extern optab udivmod_optab
;
293 extern optab smod_optab
; /* Signed remainder */
294 extern optab umod_optab
;
295 extern optab flodiv_optab
; /* Optab for floating divide. */
296 extern optab ftrunc_optab
; /* Convert float to integer in float fmt */
297 extern optab and_optab
; /* Logical and */
298 extern optab ior_optab
; /* Logical or */
299 extern optab xor_optab
; /* Logical xor */
300 extern optab ashl_optab
; /* Arithmetic shift left */
301 extern optab ashr_optab
; /* Arithmetic shift right */
302 extern optab lshl_optab
; /* Logical shift left */
303 extern optab lshr_optab
; /* Logical shift right */
304 extern optab rotl_optab
; /* Rotate left */
305 extern optab rotr_optab
; /* Rotate right */
306 extern optab smin_optab
; /* Signed and floating-point minimum value */
307 extern optab smax_optab
; /* Signed and floating-point maximum value */
308 extern optab umin_optab
; /* Unsigned minimum value */
309 extern optab umax_optab
; /* Unsigned maximum value */
311 extern optab mov_optab
; /* Move instruction. */
312 extern optab movstrict_optab
; /* Move, preserving high part of register. */
314 extern optab cmp_optab
; /* Compare insn; two operands. */
315 extern optab tst_optab
; /* tst insn; compare one operand against 0 */
317 /* Unary operations */
318 extern optab neg_optab
; /* Negation */
319 extern optab abs_optab
; /* Abs value */
320 extern optab one_cmpl_optab
; /* Bitwise not */
321 extern optab ffs_optab
; /* Find first bit set */
322 extern optab sqrt_optab
; /* Square root */
323 extern optab strlen_optab
; /* String length */
325 /* Passed to expand_binop and expand_unop to say which options to try to use
326 if the requested operation can't be open-coded on the requisite mode.
327 Either OPTAB_LIB or OPTAB_LIB_WIDEN says try using a library call.
328 Either OPTAB_WIDEN or OPTAB_LIB_WIDEN says try using a wider mode.
329 OPTAB_MUST_WIDEN says try widening and don't try anything else. */
340 /* SYMBOL_REF rtx's for the library functions that are called
341 implicitly and not via optabs. */
343 extern rtx extendsfdf2_libfunc
;
344 extern rtx truncdfsf2_libfunc
;
345 extern rtx memcpy_libfunc
;
346 extern rtx bcopy_libfunc
;
347 extern rtx memcmp_libfunc
;
348 extern rtx bcmp_libfunc
;
349 extern rtx memset_libfunc
;
350 extern rtx bzero_libfunc
;
351 extern rtx eqsf2_libfunc
;
352 extern rtx nesf2_libfunc
;
353 extern rtx gtsf2_libfunc
;
354 extern rtx gesf2_libfunc
;
355 extern rtx ltsf2_libfunc
;
356 extern rtx lesf2_libfunc
;
357 extern rtx eqdf2_libfunc
;
358 extern rtx nedf2_libfunc
;
359 extern rtx gtdf2_libfunc
;
360 extern rtx gedf2_libfunc
;
361 extern rtx ltdf2_libfunc
;
362 extern rtx ledf2_libfunc
;
363 extern rtx floatdisf_libfunc
;
364 extern rtx floatsisf_libfunc
;
365 extern rtx floatdidf_libfunc
;
366 extern rtx floatsidf_libfunc
;
367 extern rtx fixsfsi_libfunc
;
368 extern rtx fixsfdi_libfunc
;
369 extern rtx fixdfsi_libfunc
;
370 extern rtx fixdfdi_libfunc
;
371 extern rtx fixunssfsi_libfunc
;
372 extern rtx fixunssfdi_libfunc
;
373 extern rtx fixunsdfsi_libfunc
;
374 extern rtx fixunsdfdi_libfunc
;
376 typedef rtx (*rtxfun
) ();
378 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
379 gives the gen_function to make a branch to test that condition. */
381 extern rtxfun bcc_gen_fctn
[NUM_RTX_CODE
];
383 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
384 gives the insn code to make a store-condition insn
385 to test that condition. */
387 extern enum insn_code setcc_gen_code
[NUM_RTX_CODE
];
389 /* Expand a binary operation given optab and rtx operands. */
390 extern rtx
expand_binop ();
392 /* Expand a binary operation with both signed and unsigned forms. */
393 extern rtx
sign_expand_binop ();
395 /* Expand a unary arithmetic operation given optab rtx operand. */
396 extern rtx
expand_unop ();
398 /* Arguments MODE, RTX: return an rtx for the negation of that value.
400 extern rtx
negate_rtx ();
402 /* Expand a logical AND operation. */
403 extern rtx
expand_and ();
405 /* Emit a store-flag operation. */
406 extern rtx
emit_store_flag ();
408 /* Return the CODE_LABEL rtx for a LABEL_DECL, creating it if necessary. */
409 extern rtx
label_rtx ();
411 /* Given a JUMP_INSN, return a description of the test being made. */
412 extern rtx
get_condition ();
414 /* Return the INSN_CODE to use for an extend operation. */
415 extern enum insn_code
can_extend_p ();
417 /* Initialize the tables that control conversion between fixed and
419 extern void init_fixtab ();
420 extern void init_floattab ();
422 /* Generate code for a FIX_EXPR. */
423 extern void expand_fix ();
425 /* Generate code for a FLOAT_EXPR. */
426 extern void expand_float ();
428 /* Create but don't emit one rtl instruction to add one rtx into another.
429 Modes must match; operands must meet the operation's predicates.
430 Likewise for subtraction and for just copying.
431 These do not call protect_from_queue; caller must do so. */
432 extern rtx
gen_add2_insn ();
433 extern rtx
gen_sub2_insn ();
434 extern rtx
gen_move_insn ();
436 /* Emit one rtl instruction to store zero in specified rtx. */
437 extern void emit_clr_insn ();
439 /* Emit one rtl insn to store 1 in specified rtx assuming it contains 0. */
440 extern void emit_0_to_1_insn ();
442 /* Emit one rtl insn to compare two rtx's. */
443 extern void emit_cmp_insn ();
445 /* Generate rtl to compare two rtx's, will call emit_cmp_insn. */
446 extern rtx
compare_from_rtx ();
448 /* Emit some rtl insns to move data between rtx's, converting machine modes.
449 Both modes must be floating or both fixed. */
450 extern void convert_move ();
452 /* Convert an rtx to specified machine mode and return the result. */
453 extern rtx
convert_to_mode ();
455 /* Emit code to push some arguments and call a library routine,
456 storing the value in a specified place. Calling sequence is
458 extern void emit_library_call ();
460 /* Given an rtx that may include add and multiply operations,
461 generate them as insns and return a pseudo-reg containing the value.
462 Useful after calling expand_expr with 1 as sum_ok. */
463 extern rtx
force_operand ();
465 /* Return an rtx for the size in bytes of the value of an expr. */
466 extern rtx
expr_size ();
468 /* Return an rtx for the sum of an rtx and an integer. */
469 extern rtx
plus_constant ();
471 extern rtx
lookup_static_chain ();
473 /* Return an rtx like arg but sans any constant terms.
474 Returns the original rtx if it has no constant terms.
475 The constant terms are added and stored via a second arg. */
476 extern rtx
eliminate_constant_term ();
478 /* Convert arg to a valid memory address for specified machine mode,
479 by emitting insns to perform arithmetic if nec. */
480 extern rtx
memory_address ();
482 /* Like `memory_address' but pretent `flag_force_addr' is 0. */
483 extern rtx
memory_address_noforce ();
485 /* Return a memory reference like MEMREF, but with its mode changed
486 to MODE and its address changed to ADDR.
487 (VOIDmode means don't change the mode.
488 NULL for ADDR means don't change the address.) */
489 extern rtx
change_address ();
491 /* Return a memory reference like MEMREF, but which is known to have a
494 extern rtx
validize_mem ();
496 /* Convert a stack slot address ADDR valid in function FNDECL
497 into an address valid in this function (using a static chain). */
498 extern rtx
fix_lexical_addr ();
500 /* Return the address of the trampoline for entering nested fn FUNCTION. */
501 extern rtx
trampoline_address ();
503 /* Assemble the static constant template for function entry trampolines. */
504 extern rtx
assemble_trampoline_template ();
506 /* Return 1 if two rtx's are equivalent in structure and elements. */
507 extern int rtx_equal_p ();
509 /* Given rtx, return new rtx whose address won't be affected by
510 any side effects. It has been copied to a new temporary reg. */
511 extern rtx
stabilize ();
513 /* Given an rtx, copy all regs it refers to into new temps
514 and return a modified copy that refers to the new temps. */
515 extern rtx
copy_all_regs ();
517 /* Copy given rtx to a new temp reg and return that. */
518 extern rtx
copy_to_reg ();
520 /* Like copy_to_reg but always make the reg Pmode. */
521 extern rtx
copy_addr_to_reg ();
523 /* Like copy_to_reg but always make the reg the specified mode MODE. */
524 extern rtx
copy_to_mode_reg ();
526 /* Copy given rtx to given temp reg and return that. */
527 extern rtx
copy_to_suggested_reg ();
529 /* Copy a value to a register if it isn't already a register.
530 Args are mode (in case value is a constant) and the value. */
531 extern rtx
force_reg ();
533 /* Return given rtx, copied into a new temp reg if it was in memory. */
534 extern rtx
force_not_mem ();
536 /* Remove some bytes from the stack. An rtx says how many. */
537 extern void adjust_stack ();
539 /* Add some bytes to the stack. An rtx says how many. */
540 extern void anti_adjust_stack ();
542 /* This enum is used for the following two functions. */
543 enum save_level
{SAVE_BLOCK
, SAVE_FUNCTION
, SAVE_NONLOCAL
};
545 /* Save the stack pointer at the specified level. */
546 extern void emit_stack_save ();
548 /* Restore the stack pointer from a save area of the specified level. */
549 extern void emit_stack_restore ();
551 /* Allocate some space on the stack dynamically and return its address. An rtx
552 says how many bytes. */
553 extern rtx
allocate_dynamic_stack_space ();
555 /* Emit code to copy function value to a new temp reg and return that reg. */
556 extern rtx
function_value ();
558 /* Return an rtx that refers to the value returned by a function
559 in its original home. This becomes invalid if any more code is emitted. */
560 extern rtx
hard_function_value ();
562 /* Return an rtx that refers to the value returned by a library call
563 in its original home. This becomes invalid if any more code is emitted. */
564 extern rtx
hard_libcall_value ();
566 /* Emit code to copy function value to a specified place. */
567 extern void copy_function_value ();
569 /* Given an rtx, return an rtx for a value rounded up to a multiple
570 of STACK_BOUNDARY / BITS_PER_UNIT. */
571 extern rtx
round_push ();
573 /* Push a block of length SIZE (perhaps variable)
574 and return an rtx to address the beginning of the block. */
575 extern rtx
push_block ();
577 /* Generate code for computing expression EXP,
578 and storing the value into TARGET.
579 If SUGGEST_REG is nonzero, copy the value through a register
580 and return that register, if that is possible. */
581 extern rtx
store_expr ();
583 extern rtx
prepare_call_address ();
584 extern rtx
expand_call ();
585 extern void emit_call_1 ();
587 extern void emit_block_move ();
588 extern void emit_push_insn ();
589 extern void use_regs ();
590 extern void move_block_to_reg ();
592 extern rtx
store_bit_field ();
593 extern rtx
extract_bit_field ();
594 extern rtx
expand_shift ();
595 extern rtx
expand_mult ();
596 extern rtx
expand_divmod ();
597 extern rtx
expand_mult_add ();
598 extern rtx
expand_stmt_expr ();
599 extern rtx
emit_no_conflict_block ();
600 extern void emit_libcall_block ();
602 extern void jumpifnot ();
603 extern void jumpif ();
604 extern void do_jump ();
606 extern rtx
assemble_static_space ();
608 extern void locate_and_pad_parm ();
610 extern rtx
expand_inline_function ();
612 /* Hook called by expand_expr for language-specific tree codes.
613 It is up to the language front end to install a hook
614 if it has any such codes that expand_expr needs to know about. */
615 extern rtx (*lang_expand_expr
) ();