public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH v3] gcc/config/tilegx/tilegx.c (tilegx_function_profiler): Save r10 to stack before call mcount
@ 2016-10-23 18:11 Bernd Edlinger
  2016-10-24 15:28 ` Jeff Law
  0 siblings, 1 reply; 8+ messages in thread
From: Bernd Edlinger @ 2016-10-23 18:11 UTC (permalink / raw)
  To: Chris Metcalf, Chen Gang, Jeff Law
  Cc: gcc-patches, Richard Henderson, Mike Stump, Walter Lee,
	peter.maydell, Chen Gang

Hi,

I don't know much about tilegx, but
I think the patch should work as is.

This is because the
Save r10 code is a bundle

  {
  addi sp, sp, -8
  st sp, r10
  }

which stores r10 at [sp] and subtracts 8 from sp.

The restore r10 code is actually two bundles:

  addi sp, sp, 8
  ld r10, sp

This just adds 8 to sp, and loads r10 from there.

I don't know how __mcount is implemented, it must
be some asm code, almost all functions save the
lr at [sp] when invoked, but I don't know if __mcount
does that at all, if it doesn't do that, then the
adjusting of sp might be unnecessary.

The only thing that might be a problem is that
the stack is always adjusted in multiples of 16
on the tilegx platform, see tilegx.h:

#define STACK_BOUNDARY 128

That is counted in bits, and means 16 bytes.
But your patch adjusts the stack only by 8.

Furthermore, I don't see how the stack unwinding will work
with this stack adjustment when no .cfi directives
are emitted, but that is probably not a big problem.

You might see a difference, when single-stepping
over the function entry.

Maybe a test case would be good as well.


Bernd.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH v3] gcc/config/tilegx/tilegx.c (tilegx_function_profiler): Save r10 to stack before call mcount
@ 2016-06-04 13:26 chengang
  2016-10-06 13:45 ` Chen Gang
  0 siblings, 1 reply; 8+ messages in thread
From: chengang @ 2016-06-04 13:26 UTC (permalink / raw)
  To: law; +Cc: rth, mikestump, gcc-patches, cmetcalf, walt, peter.maydell, Chen Gang

From: Chen Gang <gang.chen.5i5j@gmail.com>

r10 may also be as parameter stack pointer for the nested function, so
need save it before call mcount.

Also clean up code: use '!' instead of "== 0" for checking
static_chain_decl and compute_total_frame_size.

2016-06-04  Chen Gang  <gang.chen.5i5j@gmail.com>

	gcc/
	PR target/71331
	* config/tilegx/tilegx.c (tilegx_function_profiler): Save r10
	to stack before call mcount.
	(tilegx_can_use_return_insn_p): Clean up code.
---
 gcc/config/tilegx/tilegx.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/config/tilegx/tilegx.c b/gcc/config/tilegx/tilegx.c
index 06c832c..55161bb 100644
--- a/gcc/config/tilegx/tilegx.c
+++ b/gcc/config/tilegx/tilegx.c
@@ -3880,8 +3880,8 @@ bool
 tilegx_can_use_return_insn_p (void)
 {
   return (reload_completed
-	  && cfun->static_chain_decl == 0
-	  && compute_total_frame_size () == 0
+	  && !cfun->static_chain_decl
+	  && !compute_total_frame_size ()
 	  && tilegx_current_function_is_leaf ()
 	  && !crtl->profile && !df_regs_ever_live_p (TILEGX_LINK_REGNUM));
 }
@@ -5507,6 +5507,15 @@ tilegx_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
       fprintf (file, "\t}\n");
     }
 
+  if (cfun->static_chain_decl)
+    {
+      fprintf (file,
+	       "\t{\n"
+	       "\taddi\tsp, sp, -8\n"
+	       "\tst\tsp, r10\n"
+	       "\t}\n");
+    }
+
   if (flag_pic)
     {
       fprintf (file,
@@ -5524,6 +5533,13 @@ tilegx_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
 	       "\t}\n", MCOUNT_NAME);
     }
 
+  if (cfun->static_chain_decl)
+    {
+      fprintf (file,
+	       "\taddi\tsp, sp, 8\n"
+	       "\tld\tr10, sp\n");
+    }
+
   tilegx_in_bundle = false;
 }
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-10-29  4:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-23 18:11 [PATCH v3] gcc/config/tilegx/tilegx.c (tilegx_function_profiler): Save r10 to stack before call mcount Bernd Edlinger
2016-10-24 15:28 ` Jeff Law
2016-10-29  4:26   ` Chen Gang
  -- strict thread matches above, loose matches on Subject: below --
2016-06-04 13:26 chengang
2016-10-06 13:45 ` Chen Gang
2016-10-19 22:42   ` Jeff Law
2016-10-21 22:16     ` Chen Gang
2016-10-22 22:59       ` Chris Metcalf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).