gccint: Function Entry
1
1 18.9.11 Function Entry and Exit
1 -------------------------------
1
1 This section describes the macros that output function entry
1 ("prologue") and exit ("epilogue") code.
1
1 -- Target Hook: void TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY (FILE
1 *FILE, unsigned HOST_WIDE_INT PATCH_AREA_SIZE, bool RECORD_P)
1 Generate a patchable area at the function start, consisting of
1 PATCH_AREA_SIZE NOP instructions. If the target supports named
1 sections and if RECORD_P is true, insert a pointer to the current
1 location in the table of patchable functions. The default
1 implementation of the hook places the table of pointers in the
1 special section named '__patchable_function_entries'.
1
1 -- Target Hook: void TARGET_ASM_FUNCTION_PROLOGUE (FILE *FILE)
1 If defined, a function that outputs the assembler code for entry to
1 a function. The prologue is responsible for setting up the stack
1 frame, initializing the frame pointer register, saving registers
1 that must be saved, and allocating SIZE additional bytes of storage
1 for the local variables. FILE is a stdio stream to which the
1 assembler code should be output.
1
1 The label for the beginning of the function need not be output by
1 this macro. That has already been done when the macro is run.
1
1 To determine which registers to save, the macro can refer to the
1 array 'regs_ever_live': element R is nonzero if hard register R is
1 used anywhere within the function. This implies the function
1 prologue should save register R, provided it is not one of the
1 call-used registers. ('TARGET_ASM_FUNCTION_EPILOGUE' must likewise
1 use 'regs_ever_live'.)
1
1 On machines that have "register windows", the function entry code
1 does not save on the stack the registers that are in the windows,
1 even if they are supposed to be preserved by function calls;
1 instead it takes appropriate steps to "push" the register stack, if
1 any non-call-used registers are used in the function.
1
1 On machines where functions may or may not have frame-pointers, the
1 function entry code must vary accordingly; it must set up the frame
1 pointer if one is wanted, and not otherwise. To determine whether
1 a frame pointer is in wanted, the macro can refer to the variable
1 'frame_pointer_needed'. The variable's value will be 1 at run time
1 in a function that needs a frame pointer. ⇒Elimination.
1
1 The function entry code is responsible for allocating any stack
1 space required for the function. This stack space consists of the
1 regions listed below. In most cases, these regions are allocated
1 in the order listed, with the last listed region closest to the top
1 of the stack (the lowest address if 'STACK_GROWS_DOWNWARD' is
1 defined, and the highest address if it is not defined). You can
1 use a different order for a machine if doing so is more convenient
1 or required for compatibility reasons. Except in cases where
1 required by standard or by a debugger, there is no reason why the
1 stack layout used by GCC need agree with that used by other
1 compilers for a machine.
1
1 -- Target Hook: void TARGET_ASM_FUNCTION_END_PROLOGUE (FILE *FILE)
1 If defined, a function that outputs assembler code at the end of a
1 prologue. This should be used when the function prologue is being
1 emitted as RTL, and you have some extra assembler that needs to be
1 emitted. ⇒prologue instruction pattern.
1
1 -- Target Hook: void TARGET_ASM_FUNCTION_BEGIN_EPILOGUE (FILE *FILE)
1 If defined, a function that outputs assembler code at the start of
1 an epilogue. This should be used when the function epilogue is
1 being emitted as RTL, and you have some extra assembler that needs
1 to be emitted. ⇒epilogue instruction pattern.
1
1 -- Target Hook: void TARGET_ASM_FUNCTION_EPILOGUE (FILE *FILE)
1 If defined, a function that outputs the assembler code for exit
1 from a function. The epilogue is responsible for restoring the
1 saved registers and stack pointer to their values when the function
1 was called, and returning control to the caller. This macro takes
1 the same argument as the macro 'TARGET_ASM_FUNCTION_PROLOGUE', and
1 the registers to restore are determined from 'regs_ever_live' and
1 'CALL_USED_REGISTERS' in the same way.
1
1 On some machines, there is a single instruction that does all the
1 work of returning from the function. On these machines, give that
1 instruction the name 'return' and do not define the macro
1 'TARGET_ASM_FUNCTION_EPILOGUE' at all.
1
1 Do not define a pattern named 'return' if you want the
1 'TARGET_ASM_FUNCTION_EPILOGUE' to be used. If you want the target
1 switches to control whether return instructions or epilogues are
1 used, define a 'return' pattern with a validity condition that
1 tests the target switches appropriately. If the 'return' pattern's
1 validity condition is false, epilogues will be used.
1
1 On machines where functions may or may not have frame-pointers, the
1 function exit code must vary accordingly. Sometimes the code for
1 these two cases is completely different. To determine whether a
1 frame pointer is wanted, the macro can refer to the variable
1 'frame_pointer_needed'. The variable's value will be 1 when
1 compiling a function that needs a frame pointer.
1
1 Normally, 'TARGET_ASM_FUNCTION_PROLOGUE' and
1 'TARGET_ASM_FUNCTION_EPILOGUE' must treat leaf functions specially.
1 The C variable 'current_function_is_leaf' is nonzero for such a
1 function. ⇒Leaf Functions.
1
1 On some machines, some functions pop their arguments on exit while
1 others leave that for the caller to do. For example, the 68020
1 when given '-mrtd' pops arguments in functions that take a fixed
1 number of arguments.
1
1 Your definition of the macro 'RETURN_POPS_ARGS' decides which
1 functions pop their own arguments. 'TARGET_ASM_FUNCTION_EPILOGUE'
1 needs to know what was decided. The number of bytes of the current
1 function's arguments that this function should pop is available in
1 'crtl->args.pops_args'. ⇒Scalar Return.
1
1 * A region of 'crtl->args.pretend_args_size' bytes of uninitialized
1 space just underneath the first argument arriving on the stack.
1 (This may not be at the very start of the allocated stack region if
1 the calling sequence has pushed anything else since pushing the
1 stack arguments. But usually, on such machines, nothing else has
1 been pushed yet, because the function prologue itself does all the
1 pushing.) This region is used on machines where an argument may be
1 passed partly in registers and partly in memory, and, in some cases
1 to support the features in '<stdarg.h>'.
1
1 * An area of memory used to save certain registers used by the
1 function. The size of this area, which may also include space for
1 such things as the return address and pointers to previous stack
1 frames, is machine-specific and usually depends on which registers
1 have been used in the function. Machines with register windows
1 often do not require a save area.
1
1 * A region of at least SIZE bytes, possibly rounded up to an
1 allocation boundary, to contain the local variables of the
1 function. On some machines, this region and the save area may
1 occur in the opposite order, with the save area closer to the top
1 of the stack.
1
1 * Optionally, when 'ACCUMULATE_OUTGOING_ARGS' is defined, a region of
1 'crtl->outgoing_args_size' bytes to be used for outgoing argument
1 lists of the function. ⇒Stack Arguments.
1
1 -- Macro: EXIT_IGNORE_STACK
1 Define this macro as a C expression that is nonzero if the return
1 instruction or the function epilogue ignores the value of the stack
1 pointer; in other words, if it is safe to delete an instruction to
1 adjust the stack pointer before a return from the function. The
1 default is 0.
1
1 Note that this macro's value is relevant only for functions for
1 which frame pointers are maintained. It is never safe to delete a
1 final stack adjustment in a function that has no frame pointer, and
1 the compiler knows this regardless of 'EXIT_IGNORE_STACK'.
1
1 -- Macro: EPILOGUE_USES (REGNO)
1 Define this macro as a C expression that is nonzero for registers
1 that are used by the epilogue or the 'return' pattern. The stack
1 and frame pointer registers are already assumed to be used as
1 needed.
1
1 -- Macro: EH_USES (REGNO)
1 Define this macro as a C expression that is nonzero for registers
1 that are used by the exception handling mechanism, and so should be
1 considered live on entry to an exception edge.
1
1 -- Target Hook: void TARGET_ASM_OUTPUT_MI_THUNK (FILE *FILE, tree
1 THUNK_FNDECL, HOST_WIDE_INT DELTA, HOST_WIDE_INT VCALL_OFFSET,
1 tree FUNCTION)
1 A function that outputs the assembler code for a thunk function,
1 used to implement C++ virtual function calls with multiple
1 inheritance. The thunk acts as a wrapper around a virtual
1 function, adjusting the implicit object parameter before handing
1 control off to the real function.
1
1 First, emit code to add the integer DELTA to the location that
1 contains the incoming first argument. Assume that this argument
1 contains a pointer, and is the one used to pass the 'this' pointer
1 in C++. This is the incoming argument _before_ the function
1 prologue, e.g. '%o0' on a sparc. The addition must preserve the
1 values of all other incoming arguments.
1
1 Then, if VCALL_OFFSET is nonzero, an additional adjustment should
1 be made after adding 'delta'. In particular, if P is the adjusted
1 pointer, the following adjustment should be made:
1
1 p += (*((ptrdiff_t **)p))[vcall_offset/sizeof(ptrdiff_t)]
1
1 After the additions, emit code to jump to FUNCTION, which is a
1 'FUNCTION_DECL'. This is a direct pure jump, not a call, and does
1 not touch the return address. Hence returning from FUNCTION will
1 return to whoever called the current 'thunk'.
1
1 The effect must be as if FUNCTION had been called directly with the
1 adjusted first argument. This macro is responsible for emitting
1 all of the code for a thunk function;
1 'TARGET_ASM_FUNCTION_PROLOGUE' and 'TARGET_ASM_FUNCTION_EPILOGUE'
1 are not invoked.
1
1 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
1 been extracted from it.) It might possibly be useful on some
1 targets, but probably not.
1
1 If you do not define this macro, the target-independent code in the
1 C++ front end will generate a less efficient heavyweight thunk that
1 calls FUNCTION instead of jumping to it. The generic approach does
1 not support varargs.
1
1 -- Target Hook: bool TARGET_ASM_CAN_OUTPUT_MI_THUNK (const_tree
1 THUNK_FNDECL, HOST_WIDE_INT DELTA, HOST_WIDE_INT VCALL_OFFSET,
1 const_tree FUNCTION)
1 A function that returns true if TARGET_ASM_OUTPUT_MI_THUNK would be
1 able to output the assembler code for the thunk function specified
1 by the arguments it is passed, and false otherwise. In the latter
1 case, the generic approach will be used by the C++ front end, with
1 the limitations previously exposed.
1