Move get_call_rtx_from to final.c and call call_from_call_insn.

PR other/120493
* final.cc (call_from_call_insn): Change the argument type to
const rtx_call_insn *.
(get_call_rtx_from): New.
* rtl.h (is_a_helper <const rtx_call_insn *>::test): New.
(get_call_rtx_from): Moved to the final.cc section.
* rtlanal.cc (get_call_rtx_from): Removed.

Tested on x86-64.

-- 
H.J.
From 5f68d5644870e3984343240b26918ee97e3e6f17 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.to...@gmail.com>
Date: Sun, 1 Jun 2025 09:29:48 +0800
Subject: [PATCH] Move get_call_rtx_from to final.c

Move get_call_rtx_from to final.c and call call_from_call_insn.

	PR other/120493
	* final.cc (call_from_call_insn): Change the argument type to
	const rtx_call_insn *.
	(get_call_rtx_from): New.
	* rtl.h (is_a_helper <const rtx_call_insn *>::test): New.
	(get_call_rtx_from): Moved to the final.cc section.
	* rtlanal.cc (get_call_rtx_from): Removed.

Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
---
 gcc/final.cc   | 11 ++++++++++-
 gcc/rtl.h      | 10 +++++++++-
 gcc/rtlanal.cc | 15 ---------------
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/gcc/final.cc b/gcc/final.cc
index 12c6eb0ac09..a4dbab72914 100644
--- a/gcc/final.cc
+++ b/gcc/final.cc
@@ -2072,7 +2072,7 @@ output_alternate_entry_point (FILE *file, rtx_insn *insn)
 
 /* Given a CALL_INSN, find and return the nested CALL. */
 static rtx
-call_from_call_insn (rtx_call_insn *insn)
+call_from_call_insn (const rtx_call_insn *insn)
 {
   rtx x;
   gcc_assert (CALL_P (insn));
@@ -2098,6 +2098,15 @@ call_from_call_insn (rtx_call_insn *insn)
   return x;
 }
 
+/* Return the CALL in X if there is one.  */
+
+rtx
+get_call_rtx_from (const rtx_insn *insn)
+{
+  const rtx_call_insn *call_insn = as_a<const rtx_call_insn *> (insn);
+  return call_from_call_insn (call_insn);
+}
+
 /* Print a comment into the asm showing FILENAME, LINENUM, and the
    corresponding source line, if available.  */
 
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 7049ed775e8..8a740219c2a 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -957,6 +957,14 @@ is_a_helper <rtx_call_insn *>::test (rtx_insn *insn)
   return CALL_P (insn);
 }
 
+template <>
+template <>
+inline bool
+is_a_helper <const rtx_call_insn *>::test (const rtx_insn *insn)
+{
+  return CALL_P (insn);
+}
+
 template <>
 template <>
 inline bool
@@ -3682,7 +3690,6 @@ extern bool nonzero_address_p (const_rtx);
 extern bool rtx_unstable_p (const_rtx);
 extern bool rtx_varies_p (const_rtx, bool);
 extern bool rtx_addr_varies_p (const_rtx, bool);
-extern rtx get_call_rtx_from (const rtx_insn *);
 extern tree get_call_fndecl (const rtx_insn *);
 extern HOST_WIDE_INT get_integer_term (const_rtx);
 extern rtx get_related_value (const_rtx);
@@ -4572,6 +4579,7 @@ extern void simplify_using_condition (rtx, rtx *, bitmap);
 extern void compute_alignments (void);
 extern void update_alignments (vec<rtx> &);
 extern int asm_str_count (const char *templ);
+extern rtx get_call_rtx_from (const rtx_insn *);
 
 struct rtl_hooks
 {
diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index 900f53e252a..239d6691c4c 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -813,21 +813,6 @@ rtx_addr_varies_p (const_rtx x, bool for_alias)
   return false;
 }
 
-/* Return the CALL in X if there is one.  */
-
-rtx
-get_call_rtx_from (const rtx_insn *insn)
-{
-  rtx x = PATTERN (insn);
-  if (GET_CODE (x) == PARALLEL)
-    x = XVECEXP (x, 0, 0);
-  if (GET_CODE (x) == SET)
-    x = SET_SRC (x);
-  if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
-    return x;
-  return NULL_RTX;
-}
-
 /* Get the declaration of the function called by INSN.  */
 
 tree
-- 
2.49.0

Reply via email to