From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ralf Guetlein To: gcc-help@gcc.gnu.org Cc: pmw@uk.research.att.com Subject: Re: Functions using attribute `noreturn'... Date: Wed, 02 Feb 2000 11:56:00 -0000 Message-id: <38988C3C.636FCE9D@aranea.de> X-SW-Source: 2000-02/msg00009.html Paul wrote >I'm currently in the process of porting GCC and am trying to optimise my code >for function prologues and epilogues. May we know what target you are working on? >To minimise the amount of code output, I would like to check to see if the >current function is declared with the __noreturn__ attribute. If it is, then >I don't need to do output any of the function return code or save/restore any >registers that otherwise would be. Not exactly... __attribute__((noreturn)) has 2 effects: 1) It allows the compiler to issue a warning if a 'noreturn' function returns (the code is apparently erroneous) 2) If a function calls a function with attribute `noreturn' in the main path, the compiler knows that the caller doesn't return either. BUT: The attribute `noreturn' is not involved in code generation directly. Instead, the compiler is able to recognize if there is a return path or not, independently of the `noreturn' attribute (E.g. if there is an endless loop). You have to deal with that in your function_epilogue() in the target support file (target.c). Find out if the last non-note insn of the current function is a BARRIER (that means no path leads to the epilogue). If this is the case, you don't need to emit an epilogue. Your code in function_epilogue() may look like this (see h8300.c or m68k.c): /* If the last insn was a BARRIER, we don't have to write any code. */ if (GET_CODE (insn) == NOTE) insn = prev_nonnote_insn (insn); if (insn && GET_CODE (insn) == BARRIER) return; >Is there any way I can find out whether the current function has been declared >with this attribute? (Similarly, for other attributes, such as interrupt). This >would be in the C support code, not in the machine description (.md) file. Is >there a GCC support routine I can call, or is it more involved? You have to distinguish: For your `noreturn' problem see the code snippet above. To recognize attributes, you may use code like the following (also taken from h8300.c): /* Return nonzero if FUNC is an interrupt function as specified by the "interrupt" attribute. */ static int h8300_interrupt_function_p (func) tree func; { tree a; if (TREE_CODE (func) != FUNCTION_DECL) return 0; a = lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES (func)); return a != NULL_TREE; } Enjoy, Ralf From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ralf Guetlein To: gcc-help@gcc.gnu.org Cc: pmw@uk.research.att.com Subject: Re: Functions using attribute `noreturn'... Date: Sat, 01 Apr 2000 00:00:00 -0000 Message-ID: <38988C3C.636FCE9D@aranea.de> X-SW-Source: 2000-q1/msg00203.html Message-ID: <20000401000000.m62G7QKyP3YGbXGf4COK3V-1OX3oj_pzj7nxsmWBq5c@z> Paul wrote >I'm currently in the process of porting GCC and am trying to optimise my code >for function prologues and epilogues. May we know what target you are working on? >To minimise the amount of code output, I would like to check to see if the >current function is declared with the __noreturn__ attribute. If it is, then >I don't need to do output any of the function return code or save/restore any >registers that otherwise would be. Not exactly... __attribute__((noreturn)) has 2 effects: 1) It allows the compiler to issue a warning if a 'noreturn' function returns (the code is apparently erroneous) 2) If a function calls a function with attribute `noreturn' in the main path, the compiler knows that the caller doesn't return either. BUT: The attribute `noreturn' is not involved in code generation directly. Instead, the compiler is able to recognize if there is a return path or not, independently of the `noreturn' attribute (E.g. if there is an endless loop). You have to deal with that in your function_epilogue() in the target support file (target.c). Find out if the last non-note insn of the current function is a BARRIER (that means no path leads to the epilogue). If this is the case, you don't need to emit an epilogue. Your code in function_epilogue() may look like this (see h8300.c or m68k.c): /* If the last insn was a BARRIER, we don't have to write any code. */ if (GET_CODE (insn) == NOTE) insn = prev_nonnote_insn (insn); if (insn && GET_CODE (insn) == BARRIER) return; >Is there any way I can find out whether the current function has been declared >with this attribute? (Similarly, for other attributes, such as interrupt). This >would be in the C support code, not in the machine description (.md) file. Is >there a GCC support routine I can call, or is it more involved? You have to distinguish: For your `noreturn' problem see the code snippet above. To recognize attributes, you may use code like the following (also taken from h8300.c): /* Return nonzero if FUNC is an interrupt function as specified by the "interrupt" attribute. */ static int h8300_interrupt_function_p (func) tree func; { tree a; if (TREE_CODE (func) != FUNCTION_DECL) return 0; a = lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES (func)); return a != NULL_TREE; } Enjoy, Ralf