Re: Avoid global optimize flag checks in LTO

2017-07-07 Thread Jan Hubicka
> On 7 July 2017 15:31:55 CEST, Jan Hubicka  wrote:
> >Hi,
> >this patch fixes some places where we check global optimize flag rather
> >than
> >doing it per-function. This makes optimization attribute work closer to
> >what one gets when passing the same flag at command line.
> >This requires to run IPA passes even with !optimize, but having fast
> >way through
> >which does mostly nothing except when it sees functions with optimize
> >attributes
> >set.
> 
> Sounds gross.

Yep, supporting units compiled with different optimization flags is not
prettiest. But with LTO they are sad reality.
> >
> >Bootstrapped/regtested x86_64-linux, comitted.
> > 
> 
> >Index: ipa-visibility.c
> >===
> >--- ipa-visibility.c (revision 250021)
> >+++ ipa-visibility.c (working copy)
> >@@ -622,9 +622,12 @@ function_and_variable_visibility (bool w
> >   int flags = flags_from_decl_or_type (node->decl);
> > 
> >  /* Optimize away PURE and CONST constructors and destructors.  */
> >-  if (optimize
> >+  if (node->analyzed
> >+  && (DECL_STATIC_CONSTRUCTOR (node->decl)
> >+  || DECL_STATIC_CONSTRUCTOR (node->decl))
> 
> Typo DECL_STATIC_DESTRUCTOR

Oops, thanks! I will fix it shortly.

Honza
> 
> thanks,


Re: Avoid global optimize flag checks in LTO

2017-07-07 Thread Bernhard Reutner-Fischer
On 7 July 2017 15:31:55 CEST, Jan Hubicka  wrote:
>Hi,
>this patch fixes some places where we check global optimize flag rather
>than
>doing it per-function. This makes optimization attribute work closer to
>what one gets when passing the same flag at command line.
>This requires to run IPA passes even with !optimize, but having fast
>way through
>which does mostly nothing except when it sees functions with optimize
>attributes
>set.

Sounds gross.
>
>Bootstrapped/regtested x86_64-linux, comitted.
>   

>Index: ipa-visibility.c
>===
>--- ipa-visibility.c   (revision 250021)
>+++ ipa-visibility.c   (working copy)
>@@ -622,9 +622,12 @@ function_and_variable_visibility (bool w
>   int flags = flags_from_decl_or_type (node->decl);
> 
>  /* Optimize away PURE and CONST constructors and destructors.  */
>-  if (optimize
>+  if (node->analyzed
>+&& (DECL_STATIC_CONSTRUCTOR (node->decl)
>+|| DECL_STATIC_CONSTRUCTOR (node->decl))

Typo DECL_STATIC_DESTRUCTOR

thanks,


Avoid global optimize flag checks in LTO

2017-07-07 Thread Jan Hubicka
Hi,
this patch fixes some places where we check global optimize flag rather than
doing it per-function. This makes optimization attribute work closer to
what one gets when passing the same flag at command line.
This requires to run IPA passes even with !optimize, but having fast way through
which does mostly nothing except when it sees functions with optimize attributes
set.

Bootstrapped/regtested x86_64-linux, comitted.

* ipa-comdats.c: Remove optimize check from gate.
* ipa-fnsummary.c (ipa_fn_summary_generate): do not generate summary
for functions not optimized.
(ipa_fn_summary_read): Skip optimize check.
(ipa_fn_summary_write): Likewise.
* ipa-inline-analysis.c (do_estimate_growth_1): Check that caller
is optimized.
* ipa-inline.c (can_inline_edge_p): Not optimized functions are
uninlinable.
(can_inline_edge_p): Check flag_pcc_struct_return for match.
(check_callers): Give up on caller which is not optimized.
(inline_small_functions): Likewise.
(ipa_inline): Do not give up when not optimizing.
* ipa-visbility.c (function_and_variable_visibility): Do not optimize
away unoptimizes cdtors.
(whole_program_function_and_variable_visibility): Do
ipa_discover_readonly_nonaddressable_vars in LTO mode.
* ipa.c (process_references): Do not check optimize.
(symbol_table::remove_unreachable_nodes): Update optimize check.
(set_writeonly_bit): Update optimize check.
(pass_ipa_cdtor_merge::gate): Do not check optimize.
(pass_ipa_single_use::gate): Remove.
Index: ipa-comdats.c
===
--- ipa-comdats.c   (revision 250021)
+++ ipa-comdats.c   (working copy)
@@ -416,7 +416,7 @@ public:
 bool
 pass_ipa_comdats::gate (function *)
 {
-  return HAVE_COMDAT_GROUP && optimize;
+  return HAVE_COMDAT_GROUP;
 }
 
 } // anon namespace
Index: ipa-fnsummary.c
===
--- ipa-fnsummary.c (revision 250021)
+++ ipa-fnsummary.c (working copy)
@@ -3174,22 +3174,20 @@ ipa_fn_summary_generate (void)
 
   FOR_EACH_DEFINED_FUNCTION (node)
 if (DECL_STRUCT_FUNCTION (node->decl))
-  node->local.versionable = tree_versionable_function_p (node->decl);
-
-  /* When not optimizing, do not bother to analyze.  Inlining is still done
- because edge redirection needs to happen there.  */
-  if (!optimize && !flag_generate_lto && !flag_generate_offload && !flag_wpa)
-return;
+  node->local.versionable = 
+   (opt_for_fn (node->decl, optimize)
+   && tree_versionable_function_p (node->decl));
 
   ipa_fn_summary_alloc ();
 
   ipa_fn_summaries->enable_insertion_hook ();
 
   ipa_register_cgraph_hooks ();
-  ipa_free_fn_summary ();
 
   FOR_EACH_DEFINED_FUNCTION (node)
-if (!node->alias)
+if (!node->alias
+   && (flag_generate_lto || flag_generate_offload|| flag_wpa
+   || opt_for_fn (node->decl, optimize)))
   inline_analyze_function (node);
 }
 
@@ -3342,12 +3340,9 @@ ipa_fn_summary_read (void)
fatal_error (input_location,
 "ipa inline summary is missing in input file");
 }
-  if (optimize)
-{
-  ipa_register_cgraph_hooks ();
-  if (!flag_ipa_cp)
-   ipa_prop_read_jump_functions ();
-}
+  ipa_register_cgraph_hooks ();
+  if (!flag_ipa_cp)
+ipa_prop_read_jump_functions ();
 
   gcc_assert (ipa_fn_summaries);
   ipa_fn_summaries->enable_insertion_hook ();
@@ -3462,7 +3457,7 @@ ipa_fn_summary_write (void)
   produce_asm (ob, NULL);
   destroy_output_block (ob);
 
-  if (optimize && !flag_ipa_cp)
+  if (!flag_ipa_cp)
 ipa_prop_write_jump_functions ();
 }
 
Index: ipa-inline-analysis.c
===
--- ipa-inline-analysis.c   (revision 250021)
+++ ipa-inline-analysis.c   (working copy)
@@ -326,7 +326,8 @@ do_estimate_growth_1 (struct cgraph_node
 {
   gcc_checking_assert (e->inline_failed);
 
-  if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
+  if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR
+ || !opt_for_fn (e->caller->decl, optimize))
{
  d->uninlinable = true;
   continue;
Index: ipa-inline.c
===
--- ipa-inline.c(revision 250021)
+++ ipa-inline.c(working copy)
@@ -322,6 +322,11 @@ can_inline_edge_p (struct cgraph_edge *e
   e->inline_failed = CIF_BODY_NOT_AVAILABLE;
   inlinable = false;
 }
+  if (!early && !opt_for_fn (callee->decl, optimize))
+{
+  e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
+  inlinable = false;
+}
   else if (callee->calls_comdat_local)
 {
   e->inline_failed = CIF_USES_COMDAT_LOCAL;
@@ -402,6 +407,7 @@ can_inline_edge_p (struct