From: Xinliang David Li <davidxl@google.com>
To: Harshit Chopra <harshit@google.com>
Cc: reply@codereview.appspotmail.com, gcc-patches@gcc.gnu.org
Subject: Re: [google] Minor cleanup and test fixes for -mpatch-functions-for-instrumentation. (issue5877043)
Date: Mon, 26 Mar 2012 16:50:00 -0000 [thread overview]
Message-ID: <CAAkRFZJPXb-Lh6vJjUe_i8ZC0Grs5Hy-n3jj+0WNWQW9A-Y0iA@mail.gmail.com> (raw)
In-Reply-To: <20120321214558.5543B4314A@hchopra.mtv.corp.google.com>
Ok for google branches (main and 4_7).
thanks,
David
On Wed, Mar 21, 2012 at 2:45 PM, Harshit Chopra <harshit@google.com> wrote:
> 2012-03-21 Harshit Chopra <harshit@google.com>
>
> Minor changes:
> i386.c: made check_should_patch_current_function C90 compatible.
> i386.md: Added '\t' to bytes generated by
> ix86_output_function_nops_prologue_epilogue for proper formatting
> of assembly.
> patch-functions-*.c: Fixed verification in tests. Added a test to verify
> nop-bytes generated for sibling calls and another test
> to verify a binary with nop-bytes runs properly.
>
> * gcc/config/i386/i386.c (check_should_patch_current_function):
> * gcc/config/i386/i386.md:
> * gcc/testsuite/gcc.target/i386/patch-functions-1.c (void foo):
> (int main):
> * gcc/testsuite/gcc.target/i386/patch-functions-2.c:
> * gcc/testsuite/gcc.target/i386/patch-functions-3.c:
> * gcc/testsuite/gcc.target/i386/patch-functions-4.c:
> * gcc/testsuite/gcc.target/i386/patch-functions-5.c:
> * gcc/testsuite/gcc.target/i386/patch-functions-6.c:
> * gcc/testsuite/gcc.target/i386/patch-functions-7.c:
> * gcc/testsuite/gcc.target/i386/patch-functions-8.c (int foo):
> (int bar):
> * gcc/testsuite/gcc.target/i386/patch-functions-sibling-call.c:
>
> Testing method:
> make check-gcc RUNTESTFLAGS="i386.exp=patch-functions* --target_board=\"unix{-m32,}\""
>
> Patch to be applied to google/main.
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 08bd5f0..be1f7a4 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -10981,6 +10981,7 @@ check_should_patch_current_function (void)
> const char* func_name = NULL;
> struct loops loops;
> int num_loops = 0;
> + int min_functions_instructions;
>
> /* Patch the function if it has at least a loop. */
> if (!patch_functions_ignore_loops)
> @@ -11007,7 +11008,7 @@ check_should_patch_current_function (void)
> strcmp("main", func_name) == 0)
> return true;
>
> - int min_functions_instructions =
> + min_functions_instructions =
> PARAM_VALUE (PARAM_FUNCTION_PATCH_MIN_INSTRUCTIONS);
> if (min_functions_instructions > 0)
> {
> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
> index 08353ff..38a04ae 100644
> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -11688,7 +11688,7 @@
> /* Emit 10 nop bytes after ret. */
> if (ix86_output_function_nops_prologue_epilogue (asm_out_file,
> FUNCTION_PATCH_EPILOGUE_SECTION,
> - "ret",
> + "\tret",
> 10))
> return "";
> }
> @@ -11712,7 +11712,7 @@
> /* Emit 9 nop bytes after rep;ret. */
> if (ix86_output_function_nops_prologue_epilogue (asm_out_file,
> FUNCTION_PATCH_EPILOGUE_SECTION,
> - "rep\;ret",
> + "\trep\;ret",
> 9))
> return "";
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-1.c b/gcc/testsuite/gcc.target/i386/patch-functions-1.c
> index 308e8c3..aa1f424 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-1.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-1.c
> @@ -1,5 +1,5 @@
> /* Verify -mpatch-functions-for-instrumentation works. */
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation" } */
>
> @@ -8,13 +8,16 @@
> /* Check nop-bytes at end. */
> /* { dg-final { scan-assembler "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -void foo() {
> +__attribute__ ((noinline))
> +void foo()
> +{
> /* Dummy loop. */
> int x = 0;
> while (++x);
> }
>
> -int main() {
> +int main()
> +{
> foo();
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-2.c b/gcc/testsuite/gcc.target/i386/patch-functions-2.c
> index 6baad32..78de867 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-2.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-2.c
> @@ -1,4 +1,4 @@
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation -mno-patch-functions-main-always" } */
>
> @@ -8,11 +8,14 @@
> /* { dg-final { scan-assembler-not ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> /* { dg-final { scan-assembler-not "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -void foo() {
> +__attribute__ ((noinline))
> +void foo()
> +{
> int x = 0;
> }
>
> -int main() {
> +int main()
> +{
> foo();
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-3.c b/gcc/testsuite/gcc.target/i386/patch-functions-3.c
> index 49b57a8..9e8eb52 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-3.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-3.c
> @@ -1,4 +1,4 @@
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation --param function-patch-min-instructions=0" } */
>
> @@ -8,11 +8,14 @@
> /* { dg-final { scan-assembler ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> /* { dg-final { scan-assembler "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -void foo() {
> +__attribute__ ((noinline))
> +void foo()
> +{
> int x = 0;
> }
>
> -int main() {
> +int main()
> +{
> foo();
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-4.c b/gcc/testsuite/gcc.target/i386/patch-functions-4.c
> index 5fcbd0f..7a031d7 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-4.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-4.c
> @@ -1,4 +1,4 @@
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation -mpatch-functions-ignore-loops -mno-patch-functions-main-always" } */
>
> @@ -8,12 +8,15 @@
> /* { dg-final { scan-assembler-not ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> /* { dg-final { scan-assembler-not "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -void foo() {
> +__attribute__ ((noinline))
> +void foo()
> +{
> int x = 0;
> while (++x);
> }
>
> -int main() {
> +int main()
> +{
> foo();
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-5.c b/gcc/testsuite/gcc.target/i386/patch-functions-5.c
> index 1f9cccf..cd6a014 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-5.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-5.c
> @@ -1,4 +1,4 @@
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation -mpatch-functions-ignore-loops --param function-patch-min-instructions=0" } */
>
> @@ -8,12 +8,15 @@
> /* { dg-final { scan-assembler ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> /* { dg-final { scan-assembler "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -void foo() {
> +__attribute__ ((noinline))
> +void foo()
> +{
> int x = 0;
> while (++x);
> }
>
> -int main() {
> +int main()
> +{
> foo();
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-6.c b/gcc/testsuite/gcc.target/i386/patch-functions-6.c
> index 5bf844f..c1d6446 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-6.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-6.c
> @@ -1,4 +1,4 @@
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation" } */
>
> @@ -8,7 +8,8 @@
> /* { dg-final { scan-assembler ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> /* { dg-final { scan-assembler "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -int main(int argc, char **argv) {
> +int main()
> +{
> int x = 0;
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-7.c b/gcc/testsuite/gcc.target/i386/patch-functions-7.c
> index e2c50a0..f625298 100644
> --- a/gcc/testsuite/gcc.target/i386/patch-functions-7.c
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-7.c
> @@ -1,4 +1,4 @@
> -/* { dg-do run } */
> +/* { dg-do compile } */
> /* { dg-require-effective-target lp64 } */
> /* { dg-options "-mpatch-functions-for-instrumentation -mno-patch-functions-main-always" } */
>
> @@ -8,7 +8,8 @@
> /* { dg-final { scan-assembler-not ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> /* { dg-final { scan-assembler-not "ret(.*).byte\t0x90(.*).byte\t0x90" } } */
>
> -int main(int argc, char **argv) {
> +int main()
> +{
> int x = 0;
> return 0;
> }
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-8.c b/gcc/testsuite/gcc.target/i386/patch-functions-8.c
> new file mode 100644
> index 0000000..436379c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-8.c
> @@ -0,0 +1,29 @@
> +/* Verify -mpatch-functions-for-instrumentation works. */
> +/* { dg-do run } */
> +/* { dg-require-effective-target lp64 } */
> +
> +/* -O2 forces a sibling call for foo from bar. */
> +/* { dg-options "-O2 -mpatch-functions-for-instrumentation --param function-patch-min-instructions=0" } */
> +
> +__attribute__ ((noinline))
> +int foo()
> +{
> + /* Dummy loop. */
> + int x = 10;
> + int y = 100;
> + while (--x)
> + ++y;
> + return y;
> +}
> +
> +__attribute__ ((noinline))
> +int bar()
> +{
> + return foo();
> +}
> +
> +int main()
> +{
> + bar();
> + return 0;
> +}
> diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-sibling-call.c b/gcc/testsuite/gcc.target/i386/patch-functions-sibling-call.c
> new file mode 100644
> index 0000000..847a95c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/patch-functions-sibling-call.c
> @@ -0,0 +1,26 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target lp64 } */
> +/* -O2 forces a sibling call. */
> +/* { dg-options "-O2 -mpatch-functions-for-instrumentation" } */
> +
> +/* { dg-final { scan-assembler ".byte\t0xeb,0x09(.*).byte\t0x90" } } */
> +
> +/* Checks correct nop-bytes are generated just before a sibling call. */
> +/* { dg-final { scan-assembler ".byte\t0xeb,0x09(.*).byte\t0x90(.*)jmp" } } */
> +
> +/* Not instrumented as function has no loop and is small. */
> +__attribute__ ((noinline))
> +int foo(int n)
> +{
> + int x = 0;
> + return n + 10;
> +}
> +
> +__attribute__ ((noinline))
> +int bar(int n)
> +{
> + /* Dummy loop. */
> + while (--n)
> + n = n * 2;
> + return foo(n);
> +}
>
> --
> This patch is available for review at http://codereview.appspot.com/5877043
prev parent reply other threads:[~2012-03-26 16:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-21 21:46 Harshit Chopra
2012-03-26 16:50 ` Xinliang David Li [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAkRFZJPXb-Lh6vJjUe_i8ZC0Grs5Hy-n3jj+0WNWQW9A-Y0iA@mail.gmail.com \
--to=davidxl@google.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=harshit@google.com \
--cc=reply@codereview.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).