On Tue, Jun 3, 2025 at 6:06 AM H.J. Lu <hjl.to...@gmail.com> wrote: > > On Mon, Jun 2, 2025 at 4:45 PM Richard Sandiford > <richard.sandif...@arm.com> wrote: > > > > "H.J. Lu" <hjl.to...@gmail.com> writes: > > > On Mon, Jun 2, 2025 at 4:07 PM Richard Sandiford > > > <richard.sandif...@arm.com> wrote: > > >> > > >> "H.J. Lu" <hjl.to...@gmail.com> writes: > > >> > Since not all CALL instructions in RTL passes have a REG_CALL_DECL > > >> > note, > > >> > update get_call_fndecl to also check function symbol for function > > >> > declaration so that it can be used on CALL instructions like > > >> > > > >> > (call_insn 39 38 61 7 (set (reg:SI 0 ax) > > >> > (call (mem:QI (symbol_ref:DI ("foo") [flags 0x3] > > >> > <function_decl 0x7fffe96da900 foo>) [0 foo S1 A8]) > > >> > (const_int 0 [0]))) "pr92080-15.c":24:9 1480 {*call_value} > > >> > (expr_list:REG_DEAD (reg:SI 5 di) > > >> > (expr_list:REG_DEAD (reg:SI 4 si) > > >> > (expr_list:REG_EH_REGION (const_int 0 [0]) > > >> > (nil)))) > > >> > (expr_list:SI (use (reg:SI 5 di)) > > >> > (expr_list:SI (use (reg:SI 4 si)) > > >> > (nil)))) > > >> > > > >> > PR other/120494 > > >> > * rtlanal.cc (get_call_fndecl): Also check function symbol to > > >> > get function declaration. > > >> > > >> What's your use case for this? I think we should instead move to making > > >> the notes more generally available, since looking at the call rtx won't > > >> work for targets that need indirect calls (e.g. for -mlong-calls). > > > > > > I am working on a pass which needs to check if CALL insn is a recursive > > > call. > > > > I assume false negatives are allowed? That is, "false" means "might be > > recursive, might not"? > > > > > Currently I have > > > > > > * Get the declaration of the function called by INSN. If INDIRECT_P > > > is true, also get indirect declaration. */ > > > > > > static tree > > > get_call_fndecl_from_rtx (const rtx_insn *insn, bool indirect_p = false) > > > { > > > rtx note = find_reg_note (insn, REG_CALL_DECL, NULL_RTX); > > > if (note) > > > { > > > rtx datum = XEXP (note, 0); > > > if (datum) > > > return SYMBOL_REF_DECL (datum); > > > } > > > rtx call = get_call_rtx_from (insn); > > > rtx fnaddr = XEXP (call, 0); > > > rtx addr = XEXP (fnaddr, 0); > > > if (GET_CODE (addr) == SYMBOL_REF) > > > { > > > tree fndecl = SYMBOL_REF_DECL (addr); > > > if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL) > > > return fndecl; > > > } > > > return indirect_p ? MEM_EXPR (fnaddr) : nullptr; > > > } > > > > > > if (CALL_P (insn)) > > > { > > > tree fndecl = get_call_fndecl_from_rtx (insn); > > > if (fndecl == current_function_decl > > > && decl_binds_to_current_def_p (fndecl)) > > > { > > > recursive_call_p = true; > > > break; > > > } > > > } > > > > > > If get_call_fndecl works without a REG_CALL_DECL note, I can use it > > > instead of writing my own. > > > > I think we should consider removing the flag_ipa_ra guards around > > the code that adds REG_CALL_DECLs. > > > > Like this? > > Always add REG_CALL_DECL note for CALL so that get_call_fndecl works > without -fipa-ra. > > PR other/120494 > * calls.cc (expand_call): Always add REG_CALL_DECL note. > (emit_library_call_value_1): Likewise. > > Thanks. > > > -- > H.J.
I found another way to check recursive function. I don't need this patch for my pass. -- H.J.