This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Local noreturn discovery
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 1 Jun 2010 23:57:23 +0200
- Subject: Local noreturn discovery
Hi,
this patch adds the noreturn discovery to local_pure_const. For IPA noreturn
discovery we will need to add logic deciding on when function become noreturn
based on noreturn callees, I will look into this incrementally.
Bootstrapped/regtested x86_64-linux and comitted.
* ipa-pure-const.c (local_pure_const): Do NORETURN discovery.
* testsuite/gcc.dg/noreturn-8.c: New testcase.
Index: ipa-pure-const.c
===================================================================
--- ipa-pure-const.c (revision 160109)
+++ ipa-pure-const.c (working copy)
@@ -1362,6 +1362,27 @@ local_pure_const (void)
&& !warn_suggest_attribute_pure
&& skip)
return 0;
+
+ /* First do NORETURN discovery. */
+ if (!skip && !TREE_THIS_VOLATILE (current_function_decl)
+ && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0)
+ {
+ if (warn_missing_noreturn
+ && !lang_hooks.missing_noreturn_ok_p (cfun->decl))
+ warning_at (DECL_SOURCE_LOCATION (cfun->decl), OPT_Wmissing_noreturn,
+ "function might be possible candidate "
+ "for attribute %<noreturn%>");
+ if (dump_file)
+ fprintf (dump_file, "Function found to be noreturn: %s\n",
+ lang_hooks.decl_printable_name (current_function_decl, 2));
+
+ /* Update declaration and reduce profile to executed once. */
+ TREE_THIS_VOLATILE (current_function_decl) = 1;
+ if (node->frequency > NODE_FREQUENCY_EXECUTED_ONCE)
+ node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
+
+ changed = true;
+ }
l = analyze_function (node, false);
switch (l->pure_const_state)
Index: testsuite/gcc.dg/noreturn-8.c
===================================================================
--- testsuite/gcc.dg/noreturn-8.c (revision 0)
+++ testsuite/gcc.dg/noreturn-8.c (revision 0)
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+void exit (int);
+void noreturn_autodetection_failed ();
+__attribute__ ((noinline))
+detect_noreturn ()
+{
+ exit (0);
+}
+int
+main (void)
+{
+ detect_noreturn ();
+ noreturn_autodetection_failed ();
+ return 0;
+}