public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-09 8:07 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-09 8:07 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a6a700e793d986d673786c67a0bc5f2a51a4c9fc
commit a6a700e793d986d673786c67a0bc5f2a51a4c9fc
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 01:35:27 2023 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 7581640ad31..cee34a74245 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1805,6 +1805,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7ef82a613eb..a9a6e8c23b1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -634,8 +634,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}not-always@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17170,6 +17170,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-23 20:13 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-23 20:13 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:df9c89700f234305be581cc6613c95c442f4547a
commit df9c89700f234305be581cc6613c95c442f4547a
Author: Alexandre Oliva <oliva@adacore.com>
Date: Fri Jun 23 17:10:11 2023 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 0170aafa597..fe40fcd504b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1827,6 +1827,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 17030ca2b8f..23528b4cfaa 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -637,8 +637,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}no-xthrow@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17312,6 +17312,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 38b991879e7..ac4a329ebad 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1120,6 +1120,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-09 6:17 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-09 6:17 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2624c1e15a909e3cf422cec8ad9c8472f6f48f85
commit 2624c1e15a909e3cf422cec8ad9c8472f6f48f85
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 01:35:27 2023 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 7581640ad31..cee34a74245 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1805,6 +1805,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7ef82a613eb..a9a6e8c23b1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -634,8 +634,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}not-always@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17170,6 +17170,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-08 10:59 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-08 10:59 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3334b477965df23c819f92118bdfd157d2832fbb
commit 3334b477965df23c819f92118bdfd157d2832fbb
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 574299edace..feea4920c9d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1805,6 +1805,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3d9c5f753a4..2703a914dca 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -635,8 +635,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}not-always@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17263,6 +17263,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-08 10:43 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-08 10:43 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e6c234f7f21c6ecd7096fb743d8c3589c8746cf0
commit e6c234f7f21c6ecd7096fb743d8c3589c8746cf0
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 01:35:27 2023 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 574299edace..feea4920c9d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1805,6 +1805,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3d9c5f753a4..2703a914dca 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -635,8 +635,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}not-always@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17263,6 +17263,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-08 9:17 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-08 9:17 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3334b477965df23c819f92118bdfd157d2832fbb
commit 3334b477965df23c819f92118bdfd157d2832fbb
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 574299edace..feea4920c9d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1805,6 +1805,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3d9c5f753a4..2703a914dca 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -635,8 +635,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}not-always@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17263,6 +17263,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2023-06-08 4:48 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2023-06-08 4:48 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b1ea86d1e483d25349760afd201278c4888c40ca
commit b1ea86d1e483d25349760afd201278c4888c40ca
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 8 +++++--
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 574299edace..feea4920c9d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1805,6 +1805,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3d9c5f753a4..2703a914dca 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -635,8 +635,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]}
-fharden-compares -fharden-conditional-branches
--fharden-control-flow-redundancy -fhardcfr-check-exceptions
--fhardcfr-check-returning-calls
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf
+-fhardcfr-check-exceptions -fhardcfr-check-returning-calls
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}not-always@r{|}nothrow@r{|}never@r{]}
-fstack-protector -fstack-protector-all -fstack-protector-strong
-fstack-protector-explicit -fstack-check
@@ -17263,6 +17263,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@opindex fhardcfr-skip-leaf
+@item -fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
@item -fhardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2022-10-25 2:52 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2022-10-25 2:52 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c6c1bed45898dcaa8b4676fc1e0a79ee4bde5421
commit c6c1bed45898dcaa8b4676fc1e0a79ee4bde5421
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 7 +++++-
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index e57646ce125..1f929428bc0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1798,6 +1798,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 24ff8e36721..427006608af 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -627,7 +627,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check @gol
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]} @gol
-fharden-compares -fharden-conditional-branches @gol
--fharden-control-flow-redundancy -fhardcfr-check-exceptions @gol
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf @gol
+-fhardcfr-check-exceptions @gol
-fhardcfr-check-returning-calls @gol
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}nothrow@r{|}never@r{]} @gol
-fstack-protector -fstack-protector-all -fstack-protector-strong @gol
@@ -16664,6 +16665,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@item -fhardcfr-skip-leaf
+@opindex fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@item -fhardcfr-check-exceptions
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3e6fe2db479..3998fd0d293 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2022-10-20 22:32 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2022-10-20 22:32 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:146acff55ad3d82128d95b1fc481ca2debe75550
commit 146acff55ad3d82128d95b1fc481ca2debe75550
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Introduce -fhardcfr-skip-leaf to avoid control flow redundancy
instrumentation of leaf functions, where the benefit is far more
limited.
for gcc/ChangeLog
* common.opt (fhardcfr-skip-leaf): New.
* doc/invoke.texi: Document it.
* gimple-harden-control-flow.cc
(pass_harden_control_flow_redundancy::execute): Honor it.
for gcc/testsuite/ChangeLog
* c-c++-common/torture/harden-cfr-skip-leaf.c: New.
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 7 +++++-
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index e57646ce125..1f929428bc0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1798,6 +1798,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 24ff8e36721..427006608af 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -627,7 +627,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check @gol
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]} @gol
-fharden-compares -fharden-conditional-branches @gol
--fharden-control-flow-redundancy -fhardcfr-check-exceptions @gol
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf @gol
+-fhardcfr-check-exceptions @gol
-fhardcfr-check-returning-calls @gol
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}nothrow@r{|}never@r{]} @gol
-fstack-protector -fstack-protector-all -fstack-protector-strong @gol
@@ -16664,6 +16665,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@item -fhardcfr-skip-leaf
+@opindex fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@item -fhardcfr-check-exceptions
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 862cdd45eaf..dfebb8296ed 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1114,6 +1114,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2022-10-20 5:46 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2022-10-20 5:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:eafdb61837ec1cd30832a684c13e928f165ab204
commit eafdb61837ec1cd30832a684c13e928f165ab204
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 7 +++++-
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index e57646ce125..1f929428bc0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1798,6 +1798,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 24ff8e36721..427006608af 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -627,7 +627,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check @gol
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]} @gol
-fharden-compares -fharden-conditional-branches @gol
--fharden-control-flow-redundancy -fhardcfr-check-exceptions @gol
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf @gol
+-fhardcfr-check-exceptions @gol
-fhardcfr-check-returning-calls @gol
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}nothrow@r{|}never@r{]} @gol
-fstack-protector -fstack-protector-all -fstack-protector-strong @gol
@@ -16664,6 +16665,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@item -fhardcfr-skip-leaf
+@opindex fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@item -fhardcfr-check-exceptions
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 4d40fc98779..e07c237cf8c 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1121,6 +1121,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions
@ 2022-10-20 4:09 Alexandre Oliva
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Oliva @ 2022-10-20 4:09 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3559895d311ffa663a25fe467eb2deaf3ee94ff4
commit 3559895d311ffa663a25fe467eb2deaf3ee94ff4
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 19 20:36:30 2022 -0300
hardcfr: optionally disable in leaf functions
Diff:
---
gcc/common.opt | 4 ++++
gcc/doc/invoke.texi | 7 +++++-
gcc/gimple-harden-control-flow.cc | 27 ++++++++++++++++++++++
.../c-c++-common/torture/harden-cfr-skip-leaf.c | 10 ++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index e57646ce125..1f929428bc0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1798,6 +1798,10 @@ fharden-control-flow-redundancy
Common Var(flag_harden_control_flow_redundancy) Optimization
Harden control flow by recording and checking execution paths.
+fhardcfr-skip-leaf
+Common Var(flag_harden_control_flow_redundancy_skip_leaf) Optimization
+Disable CFR in leaf functions.
+
fhardcfr-check-returning-calls
Common Var(flag_harden_control_flow_redundancy_check_returning_calls) Init(-1) Optimization
Check CFR execution paths also before calls followed by returns of their results.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 24ff8e36721..427006608af 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -627,7 +627,8 @@ Objective-C and Objective-C++ Dialects}.
-fsanitize-undefined-trap-on-error -fbounds-check @gol
-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{|}check@r{]} @gol
-fharden-compares -fharden-conditional-branches @gol
--fharden-control-flow-redundancy -fhardcfr-check-exceptions @gol
+-fharden-control-flow-redundancy -fhardcfr-skip-leaf @gol
+-fhardcfr-check-exceptions @gol
-fhardcfr-check-returning-calls @gol
-fhardcfr-check-noreturn-calls=@r{[}always@r{|}nothrow@r{|}never@r{]} @gol
-fstack-protector -fstack-protector-all -fstack-protector-strong @gol
@@ -16664,6 +16665,10 @@ would also have verification issued before the call, but these
possibilities are merely theoretical, as these conditions can only be
met when using custom compiler plugins.
+@item -fhardcfr-skip-leaf
+@opindex fhardcfr-skip-leaf
+Disable @option{-fharden-control-flow-redundancy} in leaf functions.
+
@item -fhardcfr-check-exceptions
@opindex fhardcfr-check-exceptions
@opindex fno-hardcfr-check-exceptions
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 4d40fc98779..e07c237cf8c 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1121,6 +1121,33 @@ pass_harden_control_flow_redundancy::execute (function *fun)
basic_block bb;
basic_block bb_eh_cleanup = NULL;
+ if (flag_harden_control_flow_redundancy_skip_leaf)
+ {
+ bool found_calls_p = false;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ for (gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ !gsi_end_p (gsi); gsi_prev (&gsi))
+ if (is_a <gcall *> (gsi_stmt (gsi)))
+ {
+ found_calls_p = true;
+ break;
+ }
+ if (found_calls_p)
+ break;
+ }
+
+ if (!found_calls_p)
+ {
+ if (dump_file)
+ fprintf (dump_file,
+ "Disabling CFR for leaf function, as requested\n");
+
+ return 0;
+ }
+ }
+
if (check_at_escaping_exceptions)
{
int lp_eh_cleanup = -1;
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
new file mode 100644
index 00000000000..85ecaa04d04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-skip-leaf.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-skip-leaf -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Test skipping instrumentation of leaf functions. */
+
+#include "harden-cfr.c"
+
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
+/* Only main isn't leaf. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-06-23 20:13 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 8:07 [gcc(refs/users/aoliva/heads/testme)] hardcfr: optionally disable in leaf functions Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2023-06-23 20:13 Alexandre Oliva
2023-06-09 6:17 Alexandre Oliva
2023-06-08 10:59 Alexandre Oliva
2023-06-08 10:43 Alexandre Oliva
2023-06-08 9:17 Alexandre Oliva
2023-06-08 4:48 Alexandre Oliva
2022-10-25 2:52 Alexandre Oliva
2022-10-20 22:32 Alexandre Oliva
2022-10-20 5:46 Alexandre Oliva
2022-10-20 4:09 Alexandre Oliva
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).