1 /* Callgraph based analysis of static variables.
2 Copyright (C) 2004-2014 Free Software Foundation, Inc.
3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This file marks functions as being either const (TREE_READONLY) or
22 pure (DECL_PURE_P). It can also set a variant of these that
23 are allowed to loop indefinitely (DECL_LOOPING_CONST_PURE_P).
25 This must be run after inlining decisions have been made since
26 otherwise, the local sets will not contain information that is
27 consistent with post inlined state. The global sets are not prone
28 to this problem since they are by definition transitive. */
30 /* The code in this module is called by the ipa pass manager. It
31 should be one of the later passes since it's information is used by
32 the rest of the compilation. */
36 #include "coretypes.h"
39 #include "print-tree.h"
46 #include "hard-reg-set.h"
49 #include "dominance.h"
52 #include "basic-block.h"
53 #include "tree-ssa-alias.h"
54 #include "internal-fn.h"
56 #include "gimple-expr.h"
59 #include "gimple-iterator.h"
60 #include "gimple-walk.h"
62 #include "tree-ssa-loop-niter.h"
63 #include "tree-inline.h"
64 #include "tree-pass.h"
65 #include "langhooks.h"
67 #include "plugin-api.h"
70 #include "ipa-utils.h"
72 #include "diagnostic.h"
73 #include "gimple-pretty-print.h"
74 #include "langhooks.h"
76 #include "lto-streamer.h"
77 #include "data-streamer.h"
78 #include "tree-streamer.h"
80 #include "tree-scalar-evolution.h"
84 /* Lattice values for const and pure functions. Everything starts out
85 being const, then may drop to pure and then neither depending on
87 enum pure_const_state_e
94 const char *pure_const_names
[3] = {"const", "pure", "neither"};
96 /* Holder for the const_state. There is one of these per function
101 enum pure_const_state_e pure_const_state
;
102 /* What user set here; we can be always sure about this. */
103 enum pure_const_state_e state_previously_known
;
104 bool looping_previously_known
;
106 /* True if the function could possibly infinite loop. There are a
107 lot of ways that this could be determined. We are pretty
108 conservative here. While it is possible to cse pure and const
109 calls, it is not legal to have dce get rid of the call if there
110 is a possibility that the call could infinite loop since this is
111 a behavioral change. */
117 /* State used when we know nothing about function. */
118 static struct funct_state_d varying_state
119 = { IPA_NEITHER
, IPA_NEITHER
, true, true, true };
122 typedef struct funct_state_d
* funct_state
;
124 /* The storage of the funct_state is abstracted because there is the
125 possibility that it may be desirable to move this to the cgraph
128 /* Array, indexed by cgraph node uid, of function states. */
130 static vec
<funct_state
> funct_state_vec
;
132 static bool gate_pure_const (void);
136 const pass_data pass_data_ipa_pure_const
=
139 "pure-const", /* name */
140 OPTGROUP_NONE
, /* optinfo_flags */
141 TV_IPA_PURE_CONST
, /* tv_id */
142 0, /* properties_required */
143 0, /* properties_provided */
144 0, /* properties_destroyed */
145 0, /* todo_flags_start */
146 0, /* todo_flags_finish */
149 class pass_ipa_pure_const
: public ipa_opt_pass_d
152 pass_ipa_pure_const(gcc::context
*ctxt
);
154 /* opt_pass methods: */
155 bool gate (function
*) { return gate_pure_const (); }
156 unsigned int execute (function
*fun
);
158 void register_hooks (void);
163 /* Holders of ipa cgraph hooks: */
164 struct cgraph_node_hook_list
*function_insertion_hook_holder
;
165 struct cgraph_2node_hook_list
*node_duplication_hook_holder
;
166 struct cgraph_node_hook_list
*node_removal_hook_holder
;
168 }; // class pass_ipa_pure_const
172 /* Try to guess if function body will always be visible to compiler
173 when compiling the call and whether compiler will be able
174 to propagate the information by itself. */
177 function_always_visible_to_compiler_p (tree decl
)
179 return (!TREE_PUBLIC (decl
) || DECL_DECLARED_INLINE_P (decl
));
182 /* Emit suggestion about attribute ATTRIB_NAME for DECL. KNOWN_FINITE
183 is true if the function is known to be finite. The diagnostic is
184 controlled by OPTION. WARNED_ABOUT is a hash_set<tree> unique for
185 OPTION, this function may initialize it and it is always returned
188 static hash_set
<tree
> *
189 suggest_attribute (int option
, tree decl
, bool known_finite
,
190 hash_set
<tree
> *warned_about
,
191 const char * attrib_name
)
193 if (!option_enabled (option
, &global_options
))
195 if (TREE_THIS_VOLATILE (decl
)
196 || (known_finite
&& function_always_visible_to_compiler_p (decl
)))
200 warned_about
= new hash_set
<tree
>;
201 if (warned_about
->contains (decl
))
203 warned_about
->add (decl
);
204 warning_at (DECL_SOURCE_LOCATION (decl
),
207 ? _("function might be candidate for attribute %<%s%>")
208 : _("function might be candidate for attribute %<%s%>"
209 " if it is known to return normally"), attrib_name
);
213 /* Emit suggestion about __attribute_((pure)) for DECL. KNOWN_FINITE
214 is true if the function is known to be finite. */
217 warn_function_pure (tree decl
, bool known_finite
)
219 static hash_set
<tree
> *warned_about
;
222 = suggest_attribute (OPT_Wsuggest_attribute_pure
, decl
,
223 known_finite
, warned_about
, "pure");
226 /* Emit suggestion about __attribute_((const)) for DECL. KNOWN_FINITE
227 is true if the function is known to be finite. */
230 warn_function_const (tree decl
, bool known_finite
)
232 static hash_set
<tree
> *warned_about
;
234 = suggest_attribute (OPT_Wsuggest_attribute_const
, decl
,
235 known_finite
, warned_about
, "const");
239 warn_function_noreturn (tree decl
)
241 static hash_set
<tree
> *warned_about
;
242 if (!lang_hooks
.missing_noreturn_ok_p (decl
)
243 && targetm
.warn_func_return (decl
))
245 = suggest_attribute (OPT_Wsuggest_attribute_noreturn
, decl
,
246 true, warned_about
, "noreturn");
249 /* Return true if we have a function state for NODE. */
252 has_function_state (struct cgraph_node
*node
)
254 if (!funct_state_vec
.exists ()
255 || funct_state_vec
.length () <= (unsigned int)node
->uid
)
257 return funct_state_vec
[node
->uid
] != NULL
;
260 /* Return the function state from NODE. */
262 static inline funct_state
263 get_function_state (struct cgraph_node
*node
)
265 if (!funct_state_vec
.exists ()
266 || funct_state_vec
.length () <= (unsigned int)node
->uid
267 || !funct_state_vec
[node
->uid
])
268 /* We might want to put correct previously_known state into varying. */
269 return &varying_state
;
270 return funct_state_vec
[node
->uid
];
273 /* Set the function state S for NODE. */
276 set_function_state (struct cgraph_node
*node
, funct_state s
)
278 if (!funct_state_vec
.exists ()
279 || funct_state_vec
.length () <= (unsigned int)node
->uid
)
280 funct_state_vec
.safe_grow_cleared (node
->uid
+ 1);
281 funct_state_vec
[node
->uid
] = s
;
284 /* Check to see if the use (or definition when CHECKING_WRITE is true)
285 variable T is legal in a function that is either pure or const. */
288 check_decl (funct_state local
,
289 tree t
, bool checking_write
, bool ipa
)
291 /* Do not want to do anything with volatile except mark any
292 function that uses one to be not const or pure. */
293 if (TREE_THIS_VOLATILE (t
))
295 local
->pure_const_state
= IPA_NEITHER
;
297 fprintf (dump_file
, " Volatile operand is not const/pure");
301 /* Do not care about a local automatic that is not static. */
302 if (!TREE_STATIC (t
) && !DECL_EXTERNAL (t
))
305 /* If the variable has the "used" attribute, treat it as if it had a
306 been touched by the devil. */
307 if (DECL_PRESERVE_P (t
))
309 local
->pure_const_state
= IPA_NEITHER
;
311 fprintf (dump_file
, " Used static/global variable is not const/pure\n");
315 /* In IPA mode we are not interested in checking actual loads and stores;
316 they will be processed at propagation time using ipa_ref. */
320 /* Since we have dealt with the locals and params cases above, if we
321 are CHECKING_WRITE, this cannot be a pure or constant
325 local
->pure_const_state
= IPA_NEITHER
;
327 fprintf (dump_file
, " static/global memory write is not const/pure\n");
331 if (DECL_EXTERNAL (t
) || TREE_PUBLIC (t
))
333 /* Readonly reads are safe. */
334 if (TREE_READONLY (t
) && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (t
)))
335 return; /* Read of a constant, do not change the function state. */
339 fprintf (dump_file
, " global memory read is not const\n");
340 /* Just a regular read. */
341 if (local
->pure_const_state
== IPA_CONST
)
342 local
->pure_const_state
= IPA_PURE
;
347 /* Compilation level statics can be read if they are readonly
349 if (TREE_READONLY (t
))
353 fprintf (dump_file
, " static memory read is not const\n");
354 /* Just a regular read. */
355 if (local
->pure_const_state
== IPA_CONST
)
356 local
->pure_const_state
= IPA_PURE
;
361 /* Check to see if the use (or definition when CHECKING_WRITE is true)
362 variable T is legal in a function that is either pure or const. */
365 check_op (funct_state local
, tree t
, bool checking_write
)
367 t
= get_base_address (t
);
368 if (t
&& TREE_THIS_VOLATILE (t
))
370 local
->pure_const_state
= IPA_NEITHER
;
372 fprintf (dump_file
, " Volatile indirect ref is not const/pure\n");
376 && (INDIRECT_REF_P (t
) || TREE_CODE (t
) == MEM_REF
)
377 && TREE_CODE (TREE_OPERAND (t
, 0)) == SSA_NAME
378 && !ptr_deref_may_alias_global_p (TREE_OPERAND (t
, 0)))
381 fprintf (dump_file
, " Indirect ref to local memory is OK\n");
384 else if (checking_write
)
386 local
->pure_const_state
= IPA_NEITHER
;
388 fprintf (dump_file
, " Indirect ref write is not const/pure\n");
394 fprintf (dump_file
, " Indirect ref read is not const\n");
395 if (local
->pure_const_state
== IPA_CONST
)
396 local
->pure_const_state
= IPA_PURE
;
400 /* compute state based on ECF FLAGS and store to STATE and LOOPING. */
403 state_from_flags (enum pure_const_state_e
*state
, bool *looping
,
404 int flags
, bool cannot_lead_to_return
)
407 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
410 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
411 fprintf (dump_file
, " looping");
413 if (flags
& ECF_CONST
)
416 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
417 fprintf (dump_file
, " const\n");
419 else if (flags
& ECF_PURE
)
422 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
423 fprintf (dump_file
, " pure\n");
425 else if (cannot_lead_to_return
)
429 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
430 fprintf (dump_file
, " ignoring side effects->pure looping\n");
434 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
435 fprintf (dump_file
, " neither\n");
436 *state
= IPA_NEITHER
;
441 /* Merge STATE and STATE2 and LOOPING and LOOPING2 and store
442 into STATE and LOOPING better of the two variants.
443 Be sure to merge looping correctly. IPA_NEITHER functions
444 have looping 0 even if they don't have to return. */
447 better_state (enum pure_const_state_e
*state
, bool *looping
,
448 enum pure_const_state_e state2
, bool looping2
)
452 if (*state
== IPA_NEITHER
)
455 *looping
= MIN (*looping
, looping2
);
458 else if (state2
!= IPA_NEITHER
)
459 *looping
= MIN (*looping
, looping2
);
462 /* Merge STATE and STATE2 and LOOPING and LOOPING2 and store
463 into STATE and LOOPING worse of the two variants. */
466 worse_state (enum pure_const_state_e
*state
, bool *looping
,
467 enum pure_const_state_e state2
, bool looping2
)
469 *state
= MAX (*state
, state2
);
470 *looping
= MAX (*looping
, looping2
);
473 /* Recognize special cases of builtins that are by themselves not pure or const
474 but function using them is. */
476 special_builtin_state (enum pure_const_state_e
*state
, bool *looping
,
479 if (DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
480 switch (DECL_FUNCTION_CODE (callee
))
482 case BUILT_IN_RETURN
:
483 case BUILT_IN_UNREACHABLE
:
484 case BUILT_IN_ALLOCA
:
485 case BUILT_IN_ALLOCA_WITH_ALIGN
:
486 case BUILT_IN_STACK_SAVE
:
487 case BUILT_IN_STACK_RESTORE
:
488 case BUILT_IN_EH_POINTER
:
489 case BUILT_IN_EH_FILTER
:
490 case BUILT_IN_UNWIND_RESUME
:
491 case BUILT_IN_CXA_END_CLEANUP
:
492 case BUILT_IN_EH_COPY_VALUES
:
493 case BUILT_IN_FRAME_ADDRESS
:
495 case BUILT_IN_APPLY_ARGS
:
499 case BUILT_IN_PREFETCH
:
509 /* Check the parameters of a function call to CALL_EXPR to see if
510 there are any references in the parameters that are not allowed for
511 pure or const functions. Also check to see if this is either an
512 indirect call, a call outside the compilation unit, or has special
513 attributes that may also effect the purity. The CALL_EXPR node for
514 the entire call expression. */
517 check_call (funct_state local
, gimple call
, bool ipa
)
519 int flags
= gimple_call_flags (call
);
520 tree callee_t
= gimple_call_fndecl (call
);
521 bool possibly_throws
= stmt_could_throw_p (call
);
522 bool possibly_throws_externally
= (possibly_throws
523 && stmt_can_throw_external (call
));
528 for (i
= 0; i
< gimple_num_ops (call
); i
++)
529 if (gimple_op (call
, i
)
530 && tree_could_throw_p (gimple_op (call
, i
)))
532 if (possibly_throws
&& cfun
->can_throw_non_call_exceptions
)
535 fprintf (dump_file
, " operand can throw; looping\n");
536 local
->looping
= true;
538 if (possibly_throws_externally
)
541 fprintf (dump_file
, " operand can throw externally\n");
542 local
->can_throw
= true;
547 /* The const and pure flags are set by a variety of places in the
548 compiler (including here). If someone has already set the flags
549 for the callee, (such as for some of the builtins) we will use
550 them, otherwise we will compute our own information.
552 Const and pure functions have less clobber effects than other
553 functions so we process these first. Otherwise if it is a call
554 outside the compilation unit or an indirect call we punt. This
555 leaves local calls which will be processed by following the call
559 enum pure_const_state_e call_state
;
562 if (special_builtin_state (&call_state
, &call_looping
, callee_t
))
564 worse_state (&local
->pure_const_state
, &local
->looping
,
565 call_state
, call_looping
);
568 /* When bad things happen to bad functions, they cannot be const
570 if (setjmp_call_p (callee_t
))
573 fprintf (dump_file
, " setjmp is not const/pure\n");
574 local
->looping
= true;
575 local
->pure_const_state
= IPA_NEITHER
;
578 if (DECL_BUILT_IN_CLASS (callee_t
) == BUILT_IN_NORMAL
)
579 switch (DECL_FUNCTION_CODE (callee_t
))
581 case BUILT_IN_LONGJMP
:
582 case BUILT_IN_NONLOCAL_GOTO
:
584 fprintf (dump_file
, " longjmp and nonlocal goto is not const/pure\n");
585 local
->pure_const_state
= IPA_NEITHER
;
586 local
->looping
= true;
593 /* When not in IPA mode, we can still handle self recursion. */
595 && recursive_call_p (current_function_decl
, callee_t
))
598 fprintf (dump_file
, " Recursive call can loop.\n");
599 local
->looping
= true;
601 /* Either callee is unknown or we are doing local analysis.
602 Look to see if there are any bits available for the callee (such as by
603 declaration or because it is builtin) and process solely on the basis of
607 enum pure_const_state_e call_state
;
609 if (possibly_throws
&& cfun
->can_throw_non_call_exceptions
)
612 fprintf (dump_file
, " can throw; looping\n");
613 local
->looping
= true;
615 if (possibly_throws_externally
)
619 fprintf (dump_file
, " can throw externally to lp %i\n",
620 lookup_stmt_eh_lp (call
));
622 fprintf (dump_file
, " callee:%s\n",
623 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (callee_t
)));
625 local
->can_throw
= true;
627 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
628 fprintf (dump_file
, " checking flags for call:");
629 state_from_flags (&call_state
, &call_looping
, flags
,
630 ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
631 == (ECF_NORETURN
| ECF_NOTHROW
))
632 || (!flag_exceptions
&& (flags
& ECF_NORETURN
)));
633 worse_state (&local
->pure_const_state
, &local
->looping
,
634 call_state
, call_looping
);
636 /* Direct functions calls are handled by IPA propagation. */
639 /* Wrapper around check_decl for loads in local more. */
642 check_load (gimple
, tree op
, tree
, void *data
)
645 check_decl ((funct_state
)data
, op
, false, false);
647 check_op ((funct_state
)data
, op
, false);
651 /* Wrapper around check_decl for stores in local more. */
654 check_store (gimple
, tree op
, tree
, void *data
)
657 check_decl ((funct_state
)data
, op
, true, false);
659 check_op ((funct_state
)data
, op
, true);
663 /* Wrapper around check_decl for loads in ipa mode. */
666 check_ipa_load (gimple
, tree op
, tree
, void *data
)
669 check_decl ((funct_state
)data
, op
, false, true);
671 check_op ((funct_state
)data
, op
, false);
675 /* Wrapper around check_decl for stores in ipa mode. */
678 check_ipa_store (gimple
, tree op
, tree
, void *data
)
681 check_decl ((funct_state
)data
, op
, true, true);
683 check_op ((funct_state
)data
, op
, true);
687 /* Look into pointer pointed to by GSIP and figure out what interesting side
690 check_stmt (gimple_stmt_iterator
*gsip
, funct_state local
, bool ipa
)
692 gimple stmt
= gsi_stmt (*gsip
);
694 if (is_gimple_debug (stmt
))
699 fprintf (dump_file
, " scanning: ");
700 print_gimple_stmt (dump_file
, stmt
, 0, 0);
703 if (gimple_has_volatile_ops (stmt
)
704 && !gimple_clobber_p (stmt
))
706 local
->pure_const_state
= IPA_NEITHER
;
708 fprintf (dump_file
, " Volatile stmt is not const/pure\n");
711 /* Look for loads and stores. */
712 walk_stmt_load_store_ops (stmt
, local
,
713 ipa
? check_ipa_load
: check_load
,
714 ipa
? check_ipa_store
: check_store
);
716 if (gimple_code (stmt
) != GIMPLE_CALL
717 && stmt_could_throw_p (stmt
))
719 if (cfun
->can_throw_non_call_exceptions
)
722 fprintf (dump_file
, " can throw; looping\n");
723 local
->looping
= true;
725 if (stmt_can_throw_external (stmt
))
728 fprintf (dump_file
, " can throw externally\n");
729 local
->can_throw
= true;
733 fprintf (dump_file
, " can throw\n");
735 switch (gimple_code (stmt
))
738 check_call (local
, stmt
, ipa
);
741 if (DECL_NONLOCAL (gimple_label_label (stmt
)))
742 /* Target of long jump. */
745 fprintf (dump_file
, " nonlocal label is not const/pure\n");
746 local
->pure_const_state
= IPA_NEITHER
;
750 if (gimple_asm_clobbers_memory_p (stmt
))
753 fprintf (dump_file
, " memory asm clobber is not const/pure\n");
754 /* Abandon all hope, ye who enter here. */
755 local
->pure_const_state
= IPA_NEITHER
;
757 if (gimple_asm_volatile_p (stmt
))
760 fprintf (dump_file
, " volatile is not const/pure\n");
761 /* Abandon all hope, ye who enter here. */
762 local
->pure_const_state
= IPA_NEITHER
;
763 local
->looping
= true;
772 /* This is the main routine for finding the reference patterns for
773 global variables within a function FN. */
776 analyze_function (struct cgraph_node
*fn
, bool ipa
)
778 tree decl
= fn
->decl
;
780 basic_block this_block
;
782 l
= XCNEW (struct funct_state_d
);
783 l
->pure_const_state
= IPA_CONST
;
784 l
->state_previously_known
= IPA_NEITHER
;
785 l
->looping_previously_known
= true;
787 l
->can_throw
= false;
788 state_from_flags (&l
->state_previously_known
, &l
->looping_previously_known
,
789 flags_from_decl_or_type (fn
->decl
),
790 fn
->cannot_return_p ());
792 if (fn
->thunk
.thunk_p
|| fn
->alias
)
794 /* Thunk gets propagated through, so nothing interesting happens. */
801 fprintf (dump_file
, "\n\n local analysis of %s\n ",
805 push_cfun (DECL_STRUCT_FUNCTION (decl
));
807 FOR_EACH_BB_FN (this_block
, cfun
)
809 gimple_stmt_iterator gsi
;
810 struct walk_stmt_info wi
;
812 memset (&wi
, 0, sizeof (wi
));
813 for (gsi
= gsi_start_bb (this_block
);
817 check_stmt (&gsi
, l
, ipa
);
818 if (l
->pure_const_state
== IPA_NEITHER
&& l
->looping
&& l
->can_throw
)
824 if (l
->pure_const_state
!= IPA_NEITHER
)
826 /* Const functions cannot have back edges (an
827 indication of possible infinite loop side
829 if (mark_dfs_back_edges ())
831 /* Preheaders are needed for SCEV to work.
832 Simple latches and recorded exits improve chances that loop will
833 proved to be finite in testcases such as in loop-15.c
835 loop_optimizer_init (LOOPS_HAVE_PREHEADERS
836 | LOOPS_HAVE_SIMPLE_LATCHES
837 | LOOPS_HAVE_RECORDED_EXITS
);
838 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
839 flow_loops_dump (dump_file
, NULL
, 0);
840 if (mark_irreducible_loops ())
843 fprintf (dump_file
, " has irreducible loops\n");
850 FOR_EACH_LOOP (loop
, 0)
851 if (!finite_loop_p (loop
))
854 fprintf (dump_file
, " can not prove finiteness of "
855 "loop %i\n", loop
->num
);
861 loop_optimizer_finalize ();
865 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
866 fprintf (dump_file
, " checking previously known:");
868 better_state (&l
->pure_const_state
, &l
->looping
,
869 l
->state_previously_known
,
870 l
->looping_previously_known
);
871 if (TREE_NOTHROW (decl
))
872 l
->can_throw
= false;
878 fprintf (dump_file
, "Function is locally looping.\n");
880 fprintf (dump_file
, "Function is locally throwing.\n");
881 if (l
->pure_const_state
== IPA_CONST
)
882 fprintf (dump_file
, "Function is locally const.\n");
883 if (l
->pure_const_state
== IPA_PURE
)
884 fprintf (dump_file
, "Function is locally pure.\n");
889 /* Called when new function is inserted to callgraph late. */
891 add_new_function (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
893 if (node
->get_availability () < AVAIL_INTERPOSABLE
)
895 /* There are some shared nodes, in particular the initializers on
896 static declarations. We do not need to scan them more than once
897 since all we would be interested in are the addressof
899 if (node
->get_availability () > AVAIL_INTERPOSABLE
)
900 set_function_state (node
, analyze_function (node
, true));
903 /* Called when new clone is inserted to callgraph late. */
906 duplicate_node_data (struct cgraph_node
*src
, struct cgraph_node
*dst
,
907 void *data ATTRIBUTE_UNUSED
)
909 if (has_function_state (src
))
911 funct_state l
= XNEW (struct funct_state_d
);
912 gcc_assert (!has_function_state (dst
));
913 memcpy (l
, get_function_state (src
), sizeof (*l
));
914 set_function_state (dst
, l
);
918 /* Called when new clone is inserted to callgraph late. */
921 remove_node_data (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
923 if (has_function_state (node
))
925 funct_state l
= get_function_state (node
);
926 if (l
!= &varying_state
)
928 set_function_state (node
, NULL
);
934 pass_ipa_pure_const::
935 register_hooks (void)
942 node_removal_hook_holder
=
943 symtab
->add_cgraph_removal_hook (&remove_node_data
, NULL
);
944 node_duplication_hook_holder
=
945 symtab
->add_cgraph_duplication_hook (&duplicate_node_data
, NULL
);
946 function_insertion_hook_holder
=
947 symtab
->add_cgraph_insertion_hook (&add_new_function
, NULL
);
951 /* Analyze each function in the cgraph to see if it is locally PURE or
955 pure_const_generate_summary (void)
957 struct cgraph_node
*node
;
959 pass_ipa_pure_const
*pass
= static_cast <pass_ipa_pure_const
*> (current_pass
);
960 pass
->register_hooks ();
962 /* Process all of the functions.
964 We process AVAIL_INTERPOSABLE functions. We can not use the results
965 by default, but the info can be used at LTO with -fwhole-program or
966 when function got cloned and the clone is AVAILABLE. */
968 FOR_EACH_DEFINED_FUNCTION (node
)
969 if (node
->get_availability () >= AVAIL_INTERPOSABLE
)
970 set_function_state (node
, analyze_function (node
, true));
974 /* Serialize the ipa info for lto. */
977 pure_const_write_summary (void)
979 struct cgraph_node
*node
;
980 struct lto_simple_output_block
*ob
981 = lto_create_simple_output_block (LTO_section_ipa_pure_const
);
982 unsigned int count
= 0;
983 lto_symtab_encoder_iterator lsei
;
984 lto_symtab_encoder_t encoder
;
986 encoder
= lto_get_out_decl_state ()->symtab_node_encoder
;
988 for (lsei
= lsei_start_function_in_partition (encoder
); !lsei_end_p (lsei
);
989 lsei_next_function_in_partition (&lsei
))
991 node
= lsei_cgraph_node (lsei
);
992 if (node
->definition
&& has_function_state (node
))
996 streamer_write_uhwi_stream (ob
->main_stream
, count
);
998 /* Process all of the functions. */
999 for (lsei
= lsei_start_function_in_partition (encoder
); !lsei_end_p (lsei
);
1000 lsei_next_function_in_partition (&lsei
))
1002 node
= lsei_cgraph_node (lsei
);
1003 if (node
->definition
&& has_function_state (node
))
1005 struct bitpack_d bp
;
1008 lto_symtab_encoder_t encoder
;
1010 fs
= get_function_state (node
);
1012 encoder
= ob
->decl_state
->symtab_node_encoder
;
1013 node_ref
= lto_symtab_encoder_encode (encoder
, node
);
1014 streamer_write_uhwi_stream (ob
->main_stream
, node_ref
);
1016 /* Note that flags will need to be read in the opposite
1017 order as we are pushing the bitflags into FLAGS. */
1018 bp
= bitpack_create (ob
->main_stream
);
1019 bp_pack_value (&bp
, fs
->pure_const_state
, 2);
1020 bp_pack_value (&bp
, fs
->state_previously_known
, 2);
1021 bp_pack_value (&bp
, fs
->looping_previously_known
, 1);
1022 bp_pack_value (&bp
, fs
->looping
, 1);
1023 bp_pack_value (&bp
, fs
->can_throw
, 1);
1024 streamer_write_bitpack (&bp
);
1028 lto_destroy_simple_output_block (ob
);
1032 /* Deserialize the ipa info for lto. */
1035 pure_const_read_summary (void)
1037 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1038 struct lto_file_decl_data
*file_data
;
1041 pass_ipa_pure_const
*pass
= static_cast <pass_ipa_pure_const
*> (current_pass
);
1042 pass
->register_hooks ();
1044 while ((file_data
= file_data_vec
[j
++]))
1048 struct lto_input_block
*ib
1049 = lto_create_simple_input_block (file_data
,
1050 LTO_section_ipa_pure_const
,
1055 unsigned int count
= streamer_read_uhwi (ib
);
1057 for (i
= 0; i
< count
; i
++)
1060 struct cgraph_node
*node
;
1061 struct bitpack_d bp
;
1063 lto_symtab_encoder_t encoder
;
1065 fs
= XCNEW (struct funct_state_d
);
1066 index
= streamer_read_uhwi (ib
);
1067 encoder
= file_data
->symtab_node_encoder
;
1068 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
,
1070 set_function_state (node
, fs
);
1072 /* Note that the flags must be read in the opposite
1073 order in which they were written (the bitflags were
1074 pushed into FLAGS). */
1075 bp
= streamer_read_bitpack (ib
);
1076 fs
->pure_const_state
1077 = (enum pure_const_state_e
) bp_unpack_value (&bp
, 2);
1078 fs
->state_previously_known
1079 = (enum pure_const_state_e
) bp_unpack_value (&bp
, 2);
1080 fs
->looping_previously_known
= bp_unpack_value (&bp
, 1);
1081 fs
->looping
= bp_unpack_value (&bp
, 1);
1082 fs
->can_throw
= bp_unpack_value (&bp
, 1);
1085 int flags
= flags_from_decl_or_type (node
->decl
);
1086 fprintf (dump_file
, "Read info for %s/%i ",
1089 if (flags
& ECF_CONST
)
1090 fprintf (dump_file
, " const");
1091 if (flags
& ECF_PURE
)
1092 fprintf (dump_file
, " pure");
1093 if (flags
& ECF_NOTHROW
)
1094 fprintf (dump_file
, " nothrow");
1095 fprintf (dump_file
, "\n pure const state: %s\n",
1096 pure_const_names
[fs
->pure_const_state
]);
1097 fprintf (dump_file
, " previously known state: %s\n",
1098 pure_const_names
[fs
->looping_previously_known
]);
1100 fprintf (dump_file
," function is locally looping\n");
1101 if (fs
->looping_previously_known
)
1102 fprintf (dump_file
," function is previously known looping\n");
1104 fprintf (dump_file
," function is locally throwing\n");
1108 lto_destroy_simple_input_block (file_data
,
1109 LTO_section_ipa_pure_const
,
1117 ignore_edge (struct cgraph_edge
*e
)
1119 return (!e
->can_throw_external
);
1122 /* Return true if NODE is self recursive function.
1123 Indirectly recursive functions appears as non-trivial strongly
1124 connected components, so we need to care about self recursion
1128 self_recursive_p (struct cgraph_node
*node
)
1130 struct cgraph_edge
*e
;
1131 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1132 if (e
->callee
->function_symbol () == node
)
1137 /* Produce transitive closure over the callgraph and compute pure/const
1141 propagate_pure_const (void)
1143 struct cgraph_node
*node
;
1144 struct cgraph_node
*w
;
1145 struct cgraph_node
**order
=
1146 XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
1149 struct ipa_dfs_info
* w_info
;
1151 order_pos
= ipa_reduced_postorder (order
, true, false, NULL
);
1154 cgraph_node::dump_cgraph (dump_file
);
1155 ipa_print_order (dump_file
, "reduced", order
, order_pos
);
1158 /* Propagate the local information through the call graph to produce
1159 the global information. All the nodes within a cycle will have
1160 the same info so we collapse cycles first. Then we can do the
1161 propagation in one pass from the leaves to the roots. */
1162 for (i
= 0; i
< order_pos
; i
++ )
1164 enum pure_const_state_e pure_const_state
= IPA_CONST
;
1165 bool looping
= false;
1172 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1173 fprintf (dump_file
, "Starting cycle\n");
1175 /* Find the worst state for any node in the cycle. */
1177 while (w
&& pure_const_state
!= IPA_NEITHER
)
1179 struct cgraph_edge
*e
;
1180 struct cgraph_edge
*ie
;
1182 struct ipa_ref
*ref
= NULL
;
1184 funct_state w_l
= get_function_state (w
);
1185 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1186 fprintf (dump_file
, " Visiting %s/%i state:%s looping %i\n",
1189 pure_const_names
[w_l
->pure_const_state
],
1192 /* First merge in function body properties. */
1193 worse_state (&pure_const_state
, &looping
,
1194 w_l
->pure_const_state
, w_l
->looping
);
1195 if (pure_const_state
== IPA_NEITHER
)
1198 /* For overwritable nodes we can not assume anything. */
1199 if (w
->get_availability () == AVAIL_INTERPOSABLE
)
1201 worse_state (&pure_const_state
, &looping
,
1202 w_l
->state_previously_known
,
1203 w_l
->looping_previously_known
);
1204 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1207 " Overwritable. state %s looping %i\n",
1208 pure_const_names
[w_l
->state_previously_known
],
1209 w_l
->looping_previously_known
);
1216 /* We consider recursive cycles as possibly infinite.
1217 This might be relaxed since infinite recursion leads to stack
1222 /* Now walk the edges and merge in callee properties. */
1223 for (e
= w
->callees
; e
; e
= e
->next_callee
)
1225 enum availability avail
;
1226 struct cgraph_node
*y
= e
->callee
->function_symbol (&avail
);
1227 enum pure_const_state_e edge_state
= IPA_CONST
;
1228 bool edge_looping
= false;
1230 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1237 if (avail
> AVAIL_INTERPOSABLE
)
1239 funct_state y_l
= get_function_state (y
);
1240 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1243 " state:%s looping:%i\n",
1244 pure_const_names
[y_l
->pure_const_state
],
1247 if (y_l
->pure_const_state
> IPA_PURE
1248 && e
->cannot_lead_to_return_p ())
1250 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1252 " Ignoring side effects"
1253 " -> pure, looping\n");
1254 edge_state
= IPA_PURE
;
1255 edge_looping
= true;
1259 edge_state
= y_l
->pure_const_state
;
1260 edge_looping
= y_l
->looping
;
1263 else if (special_builtin_state (&edge_state
, &edge_looping
,
1267 state_from_flags (&edge_state
, &edge_looping
,
1268 flags_from_decl_or_type (y
->decl
),
1269 e
->cannot_lead_to_return_p ());
1271 /* Merge the results with what we already know. */
1272 better_state (&edge_state
, &edge_looping
,
1273 w_l
->state_previously_known
,
1274 w_l
->looping_previously_known
);
1275 worse_state (&pure_const_state
, &looping
,
1276 edge_state
, edge_looping
);
1277 if (pure_const_state
== IPA_NEITHER
)
1280 if (pure_const_state
== IPA_NEITHER
)
1283 /* Now process the indirect call. */
1284 for (ie
= w
->indirect_calls
; ie
; ie
= ie
->next_callee
)
1286 enum pure_const_state_e edge_state
= IPA_CONST
;
1287 bool edge_looping
= false;
1289 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1290 fprintf (dump_file
, " Indirect call");
1291 state_from_flags (&edge_state
, &edge_looping
,
1292 ie
->indirect_info
->ecf_flags
,
1293 ie
->cannot_lead_to_return_p ());
1294 /* Merge the results with what we already know. */
1295 better_state (&edge_state
, &edge_looping
,
1296 w_l
->state_previously_known
,
1297 w_l
->looping_previously_known
);
1298 worse_state (&pure_const_state
, &looping
,
1299 edge_state
, edge_looping
);
1300 if (pure_const_state
== IPA_NEITHER
)
1303 if (pure_const_state
== IPA_NEITHER
)
1306 /* And finally all loads and stores. */
1307 for (i
= 0; w
->iterate_reference (i
, ref
); i
++)
1309 enum pure_const_state_e ref_state
= IPA_CONST
;
1310 bool ref_looping
= false;
1314 /* readonly reads are safe. */
1315 if (TREE_READONLY (ref
->referred
->decl
))
1317 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1318 fprintf (dump_file
, " nonreadonly global var read\n");
1319 ref_state
= IPA_PURE
;
1322 if (ref
->cannot_lead_to_return ())
1324 ref_state
= IPA_NEITHER
;
1325 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1326 fprintf (dump_file
, " global var write\n");
1333 better_state (&ref_state
, &ref_looping
,
1334 w_l
->state_previously_known
,
1335 w_l
->looping_previously_known
);
1336 worse_state (&pure_const_state
, &looping
,
1337 ref_state
, ref_looping
);
1338 if (pure_const_state
== IPA_NEITHER
)
1341 w_info
= (struct ipa_dfs_info
*) w
->aux
;
1342 w
= w_info
->next_cycle
;
1344 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1345 fprintf (dump_file
, "Result %s looping %i\n",
1346 pure_const_names
[pure_const_state
],
1349 /* Copy back the region's pure_const_state which is shared by
1350 all nodes in the region. */
1354 funct_state w_l
= get_function_state (w
);
1355 enum pure_const_state_e this_state
= pure_const_state
;
1356 bool this_looping
= looping
;
1358 if (w_l
->state_previously_known
!= IPA_NEITHER
1359 && this_state
> w_l
->state_previously_known
)
1361 this_state
= w_l
->state_previously_known
;
1362 this_looping
|= w_l
->looping_previously_known
;
1364 if (!this_looping
&& self_recursive_p (w
))
1365 this_looping
= true;
1366 if (!w_l
->looping_previously_known
)
1367 this_looping
= false;
1369 /* All nodes within a cycle share the same info. */
1370 w_l
->pure_const_state
= this_state
;
1371 w_l
->looping
= this_looping
;
1373 /* Inline clones share declaration with their offline copies;
1374 do not modify their declarations since the offline copy may
1376 if (!w
->global
.inlined_to
)
1380 if (!TREE_READONLY (w
->decl
))
1382 warn_function_const (w
->decl
, !this_looping
);
1384 fprintf (dump_file
, "Function found to be %sconst: %s\n",
1385 this_looping
? "looping " : "",
1388 w
->set_const_flag (true, this_looping
);
1392 if (!DECL_PURE_P (w
->decl
))
1394 warn_function_pure (w
->decl
, !this_looping
);
1396 fprintf (dump_file
, "Function found to be %spure: %s\n",
1397 this_looping
? "looping " : "",
1400 w
->set_pure_flag (true, this_looping
);
1406 w_info
= (struct ipa_dfs_info
*) w
->aux
;
1407 w
= w_info
->next_cycle
;
1411 ipa_free_postorder_info ();
1415 /* Produce transitive closure over the callgraph and compute nothrow
1419 propagate_nothrow (void)
1421 struct cgraph_node
*node
;
1422 struct cgraph_node
*w
;
1423 struct cgraph_node
**order
=
1424 XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
1427 struct ipa_dfs_info
* w_info
;
1429 order_pos
= ipa_reduced_postorder (order
, true, false, ignore_edge
);
1432 cgraph_node::dump_cgraph (dump_file
);
1433 ipa_print_order (dump_file
, "reduced for nothrow", order
, order_pos
);
1436 /* Propagate the local information through the call graph to produce
1437 the global information. All the nodes within a cycle will have
1438 the same info so we collapse cycles first. Then we can do the
1439 propagation in one pass from the leaves to the roots. */
1440 for (i
= 0; i
< order_pos
; i
++ )
1442 bool can_throw
= false;
1448 /* Find the worst state for any node in the cycle. */
1452 struct cgraph_edge
*e
, *ie
;
1453 funct_state w_l
= get_function_state (w
);
1456 || w
->get_availability () == AVAIL_INTERPOSABLE
)
1462 for (e
= w
->callees
; e
; e
= e
->next_callee
)
1464 enum availability avail
;
1465 struct cgraph_node
*y
= e
->callee
->function_symbol (&avail
);
1467 if (avail
> AVAIL_INTERPOSABLE
)
1469 funct_state y_l
= get_function_state (y
);
1473 if (y_l
->can_throw
&& !TREE_NOTHROW (w
->decl
)
1474 && e
->can_throw_external
)
1477 else if (e
->can_throw_external
&& !TREE_NOTHROW (y
->decl
))
1480 for (ie
= node
->indirect_calls
; ie
; ie
= ie
->next_callee
)
1481 if (ie
->can_throw_external
)
1486 w_info
= (struct ipa_dfs_info
*) w
->aux
;
1487 w
= w_info
->next_cycle
;
1490 /* Copy back the region's pure_const_state which is shared by
1491 all nodes in the region. */
1495 funct_state w_l
= get_function_state (w
);
1496 if (!can_throw
&& !TREE_NOTHROW (w
->decl
))
1498 /* Inline clones share declaration with their offline copies;
1499 do not modify their declarations since the offline copy may
1501 if (!w
->global
.inlined_to
)
1503 w
->set_nothrow_flag (true);
1505 fprintf (dump_file
, "Function found to be nothrow: %s\n",
1509 else if (can_throw
&& !TREE_NOTHROW (w
->decl
))
1510 w_l
->can_throw
= true;
1511 w_info
= (struct ipa_dfs_info
*) w
->aux
;
1512 w
= w_info
->next_cycle
;
1516 ipa_free_postorder_info ();
1521 /* Produce the global information by preforming a transitive closure
1522 on the local information that was produced by generate_summary. */
1525 pass_ipa_pure_const::
1526 execute (function
*)
1528 struct cgraph_node
*node
;
1530 symtab
->remove_cgraph_insertion_hook (function_insertion_hook_holder
);
1531 symtab
->remove_cgraph_duplication_hook (node_duplication_hook_holder
);
1532 symtab
->remove_cgraph_removal_hook (node_removal_hook_holder
);
1534 /* Nothrow makes more function to not lead to return and improve
1536 propagate_nothrow ();
1537 propagate_pure_const ();
1540 FOR_EACH_FUNCTION (node
)
1541 if (has_function_state (node
))
1542 free (get_function_state (node
));
1543 funct_state_vec
.release ();
1548 gate_pure_const (void)
1550 return (flag_ipa_pure_const
1551 /* Don't bother doing anything if the program has errors. */
1555 pass_ipa_pure_const::pass_ipa_pure_const(gcc::context
*ctxt
)
1556 : ipa_opt_pass_d(pass_data_ipa_pure_const
, ctxt
,
1557 pure_const_generate_summary
, /* generate_summary */
1558 pure_const_write_summary
, /* write_summary */
1559 pure_const_read_summary
, /* read_summary */
1560 NULL
, /* write_optimization_summary */
1561 NULL
, /* read_optimization_summary */
1562 NULL
, /* stmt_fixup */
1563 0, /* function_transform_todo_flags_start */
1564 NULL
, /* function_transform */
1565 NULL
), /* variable_transform */
1567 function_insertion_hook_holder(NULL
),
1568 node_duplication_hook_holder(NULL
),
1569 node_removal_hook_holder(NULL
)
1574 make_pass_ipa_pure_const (gcc::context
*ctxt
)
1576 return new pass_ipa_pure_const (ctxt
);
1579 /* Return true if function should be skipped for local pure const analysis. */
1582 skip_function_for_local_pure_const (struct cgraph_node
*node
)
1584 /* Because we do not schedule pass_fixup_cfg over whole program after early optimizations
1585 we must not promote functions that are called by already processed functions. */
1587 if (function_called_by_processed_nodes_p ())
1590 fprintf (dump_file
, "Function called in recursive cycle; ignoring\n");
1593 if (node
->get_availability () <= AVAIL_INTERPOSABLE
)
1596 fprintf (dump_file
, "Function is not available or overwritable; not analyzing.\n");
1602 /* Simple local pass for pure const discovery reusing the analysis from
1603 ipa_pure_const. This pass is effective when executed together with
1604 other optimization passes in early optimization pass queue. */
1608 const pass_data pass_data_local_pure_const
=
1610 GIMPLE_PASS
, /* type */
1611 "local-pure-const", /* name */
1612 OPTGROUP_NONE
, /* optinfo_flags */
1613 TV_IPA_PURE_CONST
, /* tv_id */
1614 0, /* properties_required */
1615 0, /* properties_provided */
1616 0, /* properties_destroyed */
1617 0, /* todo_flags_start */
1618 0, /* todo_flags_finish */
1621 class pass_local_pure_const
: public gimple_opt_pass
1624 pass_local_pure_const (gcc::context
*ctxt
)
1625 : gimple_opt_pass (pass_data_local_pure_const
, ctxt
)
1628 /* opt_pass methods: */
1629 opt_pass
* clone () { return new pass_local_pure_const (m_ctxt
); }
1630 virtual bool gate (function
*) { return gate_pure_const (); }
1631 virtual unsigned int execute (function
*);
1633 }; // class pass_local_pure_const
1636 pass_local_pure_const::execute (function
*fun
)
1638 bool changed
= false;
1641 struct cgraph_node
*node
;
1643 node
= cgraph_node::get (current_function_decl
);
1644 skip
= skip_function_for_local_pure_const (node
);
1645 if (!warn_suggest_attribute_const
1646 && !warn_suggest_attribute_pure
1650 l
= analyze_function (node
, false);
1652 /* Do NORETURN discovery. */
1653 if (!skip
&& !TREE_THIS_VOLATILE (current_function_decl
)
1654 && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (fun
)->preds
) == 0)
1656 warn_function_noreturn (fun
->decl
);
1658 fprintf (dump_file
, "Function found to be noreturn: %s\n",
1659 current_function_name ());
1661 /* Update declaration and reduce profile to executed once. */
1662 TREE_THIS_VOLATILE (current_function_decl
) = 1;
1663 if (node
->frequency
> NODE_FREQUENCY_EXECUTED_ONCE
)
1664 node
->frequency
= NODE_FREQUENCY_EXECUTED_ONCE
;
1669 switch (l
->pure_const_state
)
1672 if (!TREE_READONLY (current_function_decl
))
1674 warn_function_const (current_function_decl
, !l
->looping
);
1677 node
->set_const_flag (true, l
->looping
);
1681 fprintf (dump_file
, "Function found to be %sconst: %s\n",
1682 l
->looping
? "looping " : "",
1683 current_function_name ());
1685 else if (DECL_LOOPING_CONST_OR_PURE_P (current_function_decl
)
1690 node
->set_const_flag (true, false);
1694 fprintf (dump_file
, "Function found to be non-looping: %s\n",
1695 current_function_name ());
1700 if (!DECL_PURE_P (current_function_decl
))
1704 node
->set_pure_flag (true, l
->looping
);
1707 warn_function_pure (current_function_decl
, !l
->looping
);
1709 fprintf (dump_file
, "Function found to be %spure: %s\n",
1710 l
->looping
? "looping " : "",
1711 current_function_name ());
1713 else if (DECL_LOOPING_CONST_OR_PURE_P (current_function_decl
)
1718 node
->set_pure_flag (true, false);
1722 fprintf (dump_file
, "Function found to be non-looping: %s\n",
1723 current_function_name ());
1730 if (!l
->can_throw
&& !TREE_NOTHROW (current_function_decl
))
1732 node
->set_nothrow_flag (true);
1735 fprintf (dump_file
, "Function found to be nothrow: %s\n",
1736 current_function_name ());
1740 return execute_fixup_cfg ();
1748 make_pass_local_pure_const (gcc::context
*ctxt
)
1750 return new pass_local_pure_const (ctxt
);
1753 /* Emit noreturn warnings. */
1757 const pass_data pass_data_warn_function_noreturn
=
1759 GIMPLE_PASS
, /* type */
1760 "*warn_function_noreturn", /* name */
1761 OPTGROUP_NONE
, /* optinfo_flags */
1762 TV_NONE
, /* tv_id */
1763 PROP_cfg
, /* properties_required */
1764 0, /* properties_provided */
1765 0, /* properties_destroyed */
1766 0, /* todo_flags_start */
1767 0, /* todo_flags_finish */
1770 class pass_warn_function_noreturn
: public gimple_opt_pass
1773 pass_warn_function_noreturn (gcc::context
*ctxt
)
1774 : gimple_opt_pass (pass_data_warn_function_noreturn
, ctxt
)
1777 /* opt_pass methods: */
1778 virtual bool gate (function
*) { return warn_suggest_attribute_noreturn
; }
1779 virtual unsigned int execute (function
*fun
)
1781 if (!TREE_THIS_VOLATILE (current_function_decl
)
1782 && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (fun
)->preds
) == 0)
1783 warn_function_noreturn (current_function_decl
);
1787 }; // class pass_warn_function_noreturn
1792 make_pass_warn_function_noreturn (gcc::context
*ctxt
)
1794 return new pass_warn_function_noreturn (ctxt
);