diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-01-07 14:27:49 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-01-08 04:51:57 -0800 |
commit | 1b885264a48dcd71b7aeb26c0abeb91246724897 (patch) | |
tree | 312f19cb7205606a2260efd56bfd81ec7c1fb59f | |
parent | 8f1cb70d7ca6a8da7f6bc7f43fb5e758c0ce88b5 (diff) | |
download | gcc-1b885264a48dcd71b7aeb26c0abeb91246724897.zip gcc-1b885264a48dcd71b7aeb26c0abeb91246724897.tar.gz gcc-1b885264a48dcd71b7aeb26c0abeb91246724897.tar.bz2 |
x86-64: Use R10 for profiling large model
R10 is caller-saved. Although it can be used as a static chain register,
it is preserved when calling mcount for nested functions. Use R10 as a
scratch register to call mcount in large model.
gcc/
PR target/98482
* config/i386/i386.c (x86_function_profiler): Use R10 to call
mcount in large model. Sorry for large model with PIC.
gcc/testsuite/
PR target/98482
* gcc.target/i386/pr98482-1.c: New test.
* gcc.target/i386/pr98482-1.c: Likewise.
-rw-r--r-- | gcc/config/i386/i386.c | 26 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr98482-1.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr98482-2.c | 9 |
3 files changed, 42 insertions, 2 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index fad50e7..d306846 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -20794,8 +20794,30 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno); #endif - if (!TARGET_PECOFF && flag_pic) - fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name); + if (!TARGET_PECOFF) + { + switch (ix86_cmodel) + { + case CM_LARGE: + /* NB: R10 is caller-saved. Although it can be used as a + static chain register, it is preserved when calling + mcount for nested functions. */ + fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n", + mcount_name); + break; + case CM_LARGE_PIC: + sorry ("profiling %<-mcmodel=large%> with PIC is not supported"); + break; + case CM_SMALL_PIC: + case CM_MEDIUM_PIC: + fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", + mcount_name); + break; + default: + x86_print_call_or_nop (file, mcount_name); + break; + } + } else x86_print_call_or_nop (file, mcount_name); } diff --git a/gcc/testsuite/gcc.target/i386/pr98482-1.c b/gcc/testsuite/gcc.target/i386/pr98482-1.c new file mode 100644 index 0000000..72d5ccb --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98482-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */ +/* { dg-require-effective-target mfentry } */ +/* { dg-options "-fprofile -mfentry -O2 -mcmodel=large" } */ +/* { dg-final { scan-assembler "movabsq\t\\\$__fentry__, %r10\n\tcall\t\\*%r10" } } */ + +void +func (void) +{ +} diff --git a/gcc/testsuite/gcc.target/i386/pr98482-2.c b/gcc/testsuite/gcc.target/i386/pr98482-2.c new file mode 100644 index 0000000..aed3ca4 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98482-2.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */ +/* { dg-require-effective-target mfentry } */ +/* { dg-require-effective-target fpic } */ +/* { dg-options "-fpic -fprofile -mfentry -O2 -mcmodel=large" } */ + +void +func (void) +{ +} /* { dg-message "sorry, unimplemented: profiling '-mcmodel=large' with PIC is not supported" } */ |