GCC Middle and Back End API Reference
cfgloop.h
Go to the documentation of this file.
1/* Natural loop functions
2 Copyright (C) 1987-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_CFGLOOP_H
21#define GCC_CFGLOOP_H
22
23#include "cfgloopmanip.h"
24
25/* Structure to hold decision about unrolling/peeling. */
33
34struct GTY (()) lpt_decision {
36 unsigned times;
37};
38
39/* The type of extend applied to an IV. */
46
49
50/* The structure describing a bound on number of iterations of a loop. */
51
52class GTY ((chain_next ("%h.next"))) nb_iter_bound {
53public:
54 /* The statement STMT is executed at most ... */
56
57 /* ... BOUND + 1 times (BOUND must be an unsigned constant).
58 The + 1 is added for the following reasons:
59
60 a) 0 would otherwise be unused, while we would need to care more about
61 overflows (as MAX + 1 is sometimes produced as the estimate on number
62 of executions of STMT).
63 b) it is consistent with the result of number_of_iterations_exit. */
65
66 /* True if, after executing the statement BOUND + 1 times, we will
67 leave the loop; that is, all the statements after it are executed at most
68 BOUND times. */
69 bool is_exit;
70
71 /* The next bound in the list. */
73};
74
75/* Description of the loop exit. */
76
78 /* The exit edge. */
80
81 /* Previous and next exit in the list of the exits of the loop. */
82 struct loop_exit *prev;
83 struct loop_exit *next;
84
85 /* Next element in the list of loops from that E exits. */
87};
88
89struct loop_exit_hasher : ggc_ptr_hash<loop_exit>
90{
92
93 static hashval_t hash (loop_exit *);
94 static bool equal (loop_exit *, edge);
95 static void remove (loop_exit *);
96};
97
98typedef class loop *loop_p;
99
100/* An integer estimation of the number of iterations. Estimate_state
101 describes what is the state of the estimation. */
103{
104 /* Estimate was not computed yet. */
106 /* Estimate is ready. */
110
111/* The structure describing non-overflow control induction variable for
112 loop's exit edge. */
113struct GTY ((chain_next ("%h.next"))) control_iv {
117};
118
119/* Structure to hold information for each natural loop. */
120class GTY ((chain_next ("%h.next"))) loop {
121public:
122 /* Index into loops array. Note indices will never be reused after loop
123 is destroyed. */
124 int num;
125
126 /* Number of loop insns. */
127 unsigned ninsns;
128
129 /* Basic block of loop header. */
131
132 /* Basic block of loop latch. */
134
135 /* For loop unrolling/peeling decision. */
137
138 /* Average number of executed insns per iteration. */
139 unsigned av_ninsns;
140
141 /* Number of blocks contained within the loop. */
142 unsigned num_nodes;
143
144 /* Superloops of the loop, starting with the outermost loop. */
146
147 /* The first inner (child) loop or NULL if innermost loop. */
148 class loop *inner;
149
150 /* Link to the next (sibling) loop. */
151 class loop *next;
152
153 /* Auxiliary info specific to a pass. */
154 void *GTY ((skip (""))) aux;
155
156 /* The number of times the latch of the loop is executed. This can be an
157 INTEGER_CST, or a symbolic expression representing the number of
158 iterations like "N - 1", or a COND_EXPR containing the runtime
159 conditions under which the number of iterations is non zero.
160
161 Don't access this field directly: number_of_latch_executions
162 computes and caches the computed information in this field. */
163 tree nb_iterations;
164
165 /* An integer guaranteed to be greater or equal to nb_iterations. Only
166 valid if any_upper_bound is true. */
167 bound_wide_int nb_iterations_upper_bound;
168
169 bound_wide_int nb_iterations_likely_upper_bound;
170
171 /* An integer giving an estimate on nb_iterations. Unlike
172 nb_iterations_upper_bound, there is no guarantee that it is at least
173 nb_iterations. */
174 bound_wide_int nb_iterations_estimate;
175
176 /* If > 0, an integer, where the user asserted that for any
177 I in [ 0, nb_iterations ) and for any J in
178 [ I, min ( I + safelen, nb_iterations ) ), the Ith and Jth iterations
179 of the loop can be safely evaluated concurrently. */
180 int safelen;
181
182 /* Preferred vectorization factor for the loop if non-zero. */
183 int simdlen;
184
185 /* Constraints are generally set by consumers and affect certain
186 semantics of niter analyzer APIs. Currently the APIs affected are
187 number_of_iterations_exit* functions and their callers. One typical
188 use case of constraints is to vectorize possibly infinite loop:
189
190 1) Compute niter->assumptions by calling niter analyzer API and
191 record it as possible condition for loop versioning.
192 2) Clear buffered result of niter/scev analyzer.
193 3) Set constraint LOOP_C_FINITE assuming the loop is finite.
194 4) Analyze data references. Since data reference analysis depends
195 on niter/scev analyzer, the point is that niter/scev analysis
196 is done under circumstance of LOOP_C_FINITE constraint.
197 5) Version the loop with niter->assumptions computed in step 1).
198 6) Vectorize the versioned loop in which niter->assumptions is
199 checked to be true.
200 7) Update constraints in versioned loops so that niter analyzer
201 in following passes can use it.
202
203 Note consumers are usually the loop optimizers and it is consumers'
204 responsibility to set/clear constraints correctly. Failing to do
205 that might result in hard to track down bugs in niter/scev consumers. */
206 unsigned constraints;
207
208 /* An integer estimation of the number of iterations. Estimate_state
209 describes what is the state of the estimation. */
210 ENUM_BITFIELD(loop_estimation) estimate_state : 8;
211
212 unsigned any_upper_bound : 1;
213 unsigned any_estimate : 1;
214 unsigned any_likely_upper_bound : 1;
215
216 /* True if the loop can be parallel. */
217 unsigned can_be_parallel : 1;
218
219 /* True if -Waggressive-loop-optimizations warned about this loop
220 already. */
221 unsigned warned_aggressive_loop_optimizations : 1;
222
223 /* True if this loop should never be vectorized. */
224 unsigned dont_vectorize : 1;
225
226 /* True if we should try harder to vectorize this loop. */
227 unsigned force_vectorize : 1;
228
229 /* True if the loop is part of an oacc kernels region. */
230 unsigned in_oacc_kernels_region : 1;
231
232 /* True if the loop is known to be finite. This is a localized
233 flag_finite_loops or similar pragmas state. */
234 unsigned finite_p : 1;
235
236 /* The number of times to unroll the loop. 0 means no information given,
237 just do what we always do. A value of 1 means do not unroll the loop.
238 A value of USHRT_MAX means unroll with no specific unrolling factor.
239 Other values means unroll with the given unrolling factor. */
240 unsigned short unroll;
241
242 /* If this loop was inlined the main clique of the callee which does
243 not need remapping when copying the loop body. */
244 unsigned short owned_clique;
245
246 /* For SIMD loops, this is a unique identifier of the loop, referenced
247 by IFN_GOMP_SIMD_VF, IFN_GOMP_SIMD_LANE and IFN_GOMP_SIMD_LAST_LANE
248 builtins. */
249 tree simduid;
250
251 /* In loop optimization, it's common to generate loops from the original
252 loop. This field records the index of the original loop which can be
253 used to track the original loop from newly generated loops. This can
254 be done by calling function get_loop (cfun, orig_loop_num). Note the
255 original loop could be destroyed for various reasons thus no longer
256 exists, as a result, function call to get_loop returns NULL pointer.
257 In this case, this field should not be used and needs to be cleared
258 whenever possible. */
259 int orig_loop_num;
260
261 /* Upper bound on number of iterations of a loop. */
263
264 /* Non-overflow control ivs of a loop. */
265 struct control_iv *control_ivs;
266
267 /* Head of the cyclic list of the exits of the loop. */
269
270 /* Number of iteration analysis data for RTL. */
272
273 /* For sanity checking during loop fixup we record here the former
274 loop header for loops marked for removal. Note that this prevents
275 the basic-block from being collected but its index can still be
276 reused. */
277 basic_block former_header;
278};
279
280/* Set if the loop is known to be infinite. */
281#define LOOP_C_INFINITE (1 << 0)
282/* Set if the loop is known to be finite without any assumptions. */
283#define LOOP_C_FINITE (1 << 1)
284
285/* Set C to the LOOP constraint. */
286inline void
287loop_constraint_set (class loop *loop, unsigned c)
288{
289 loop->constraints |= c;
290}
291
292/* Clear C from the LOOP constraint. */
293inline void
294loop_constraint_clear (class loop *loop, unsigned c)
295{
296 loop->constraints &= ~c;
297}
298
299/* Check if C is set in the LOOP constraint. */
300inline bool
301loop_constraint_set_p (class loop *loop, unsigned c)
302{
303 return (loop->constraints & c) == c;
304}
305
306/* Flags for state of loop structure. */
307enum
308{
318
319#define LOOPS_NORMAL (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES \
320 | LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)
321#define AVOID_CFG_MODIFICATIONS (LOOPS_MAY_HAVE_MULTIPLE_LATCHES)
322
323/* Structure to hold CFG information about natural loops within a function. */
324struct GTY (()) loops {
325 /* State of loops. */
326 int state;
327
328 /* Array of the loops. */
330
331 /* Maps edges to the list of their descriptions as loop exits. Edges
332 whose sources or destinations have loop_father == NULL (which may
333 happen during the cfg manipulations) should not appear in EXITS. */
335
336 /* Pointer to root of loop hierarchy tree. */
337 class loop *tree_root;
338};
339
340/* Loop recognition. */
342void init_loops_structure (struct function *, struct loops *, unsigned);
347 void (*)(const class loop *, FILE *, int), int);
349 void (*)(const class loop *, FILE *, int), int);
350class loop *alloc_loop (void);
354bool mark_irreducible_loops (void);
356void record_loop_exits (void);
357void rescan_loop_exit (edge, bool, bool);
359
360/* Loop data structure manipulation/querying. */
362 class loop * = NULL);
367class loop *superloop_at_depth (class loop *, unsigned);
375extern void mark_loop_exit_edges (void);
377
378/* Loops & cfg manipulation. */
381 unsigned);
385 int (*) (const void *, const void *));
387 int (*) (const void *, const void *, void *));
388
393
396
399
402
403
404extern void verify_loop_structure (void);
405
406/* Loop analysis. */
409 bool *read_profile_p = NULL);
411 sreal *ret,
412 bool *reliable = NULL);
416
418void print_loop_info (FILE *file, const class loop *loop, const char *);
419
420/* Induction variable analysis. */
421
422/* The description of induction variable. The things are a bit complicated
423 due to need to handle subregs and extends. The value of the object described
424 by it can be obtained as follows (all computations are done in extend_mode):
425
426 Value in i-th iteration is
427 delta + mult * extend_{extend_mode} (subreg_{mode} (base + i * step)).
428
429 If first_special is true, the value in the first iteration is
430 delta + mult * base
431
432 If extend = UNKNOWN, first_special must be false, delta 0, mult 1 and value is
433 subreg_{mode} (base + i * step)
434
435 The get_iv_value function can be used to obtain these expressions.
436
437 ??? Add a third mode field that would specify the mode in that inner
438 computation is done, which would enable it to be different from the
439 outer one? */
440
442{
443public:
444 /* Its base and step (mode of base and step is supposed to be extend_mode,
445 see the description above). */
446 rtx base, step;
447
448 /* The type of extend applied to it (IV_SIGN_EXTEND, IV_ZERO_EXTEND,
449 or IV_UNKNOWN_EXTEND). */
451
452 /* Operations applied in the extended mode. */
454
455 /* The mode it is extended to. */
457
458 /* The mode the variable iterates in. */
460
461 /* Whether the first iteration needs to be handled specially. */
462 unsigned first_special : 1;
463};
464
465/* The description of an exit from the loop and of the number of iterations
466 till we take the exit. */
467
469{
470public:
471 /* The edge out of the loop. */
473
474 /* The other edge leading from the condition. */
476
477 /* True if we are able to say anything about number of iterations of the
478 loop. */
480
481 /* True if the loop iterates the constant number of times. */
483
484 /* Number of iterations if constant. */
486
487 /* Assumptions under that the rest of the information is valid. */
489
490 /* Assumptions under that the loop ends before reaching the latch,
491 even if value of niter_expr says otherwise. */
493
494 /* Condition under that the loop is infinite. */
496
497 /* Whether the comparison is signed. */
499
500 /* The mode in that niter_expr should be computed. */
502
503 /* The number of iterations of the loop. */
505};
506
507extern void iv_analysis_loop_init (class loop *);
508extern bool iv_analyze (rtx_insn *, scalar_int_mode, rtx, class rtx_iv *);
509extern bool iv_analyze_result (rtx_insn *, rtx, class rtx_iv *);
511 class rtx_iv *);
512extern rtx get_iv_value (class rtx_iv *, rtx);
513extern bool biv_p (rtx_insn *, scalar_int_mode, rtx);
514extern void iv_analysis_done (void);
515
516extern class niter_desc *get_simple_loop_desc (class loop *loop);
517extern void free_simple_loop_desc (class loop *loop);
518
519inline class niter_desc *
521{
522 return loop->simple_loop_desc;
523}
524
525/* Accessors for the loop structures. */
526
527/* Returns the loop with index NUM from FNs loop tree. */
528
529inline class loop *
530get_loop (struct function *fn, unsigned num)
531{
532 return (*loops_for_fn (fn)->larray)[num];
533}
534
535/* Returns the number of superloops of LOOP. */
536
537inline unsigned
538loop_depth (const class loop *loop)
539{
541}
542
543/* Returns the immediate superloop of LOOP, or NULL if LOOP is the outermost
544 loop. */
545
546inline class loop *
547loop_outer (const class loop *loop)
548{
549 unsigned n = vec_safe_length (loop->superloops);
550
551 if (n == 0)
552 return NULL;
553
554 return (*loop->superloops)[n - 1];
555}
556
557/* Returns true if LOOP has at least one exit edge. */
558
559inline bool
561{
562 return loop->exits->next->e != NULL;
563}
564
565/* Returns the list of loops in FN. */
566
567inline vec<loop_p, va_gc> *
568get_loops (struct function *fn)
569{
570 struct loops *loops = loops_for_fn (fn);
571 if (!loops)
572 return NULL;
573
574 return loops->larray;
575}
576
577/* Returns the number of loops in FN (including the removed
578 ones and the fake loop that forms the root of the loop tree). */
579
580inline unsigned
582{
583 struct loops *loops = loops_for_fn (fn);
584 if (!loops)
585 return 0;
586
587 return vec_safe_length (loops->larray);
588}
589
590/* Returns true if state of the loops satisfies all properties
591 described by FLAGS. */
592
593inline bool
595{
596 return (loops_for_fn (fn)->state & flags) == flags;
597}
598
599inline bool
601{
602 return loops_state_satisfies_p (cfun, flags);
603}
604
605/* Sets FLAGS to the loops state. */
606
607inline void
608loops_state_set (function *fn, unsigned flags)
609{
610 loops_for_fn (fn)->state |= flags;
611}
612
613inline void
614loops_state_set (unsigned flags)
615{
616 loops_state_set (cfun, flags);
617}
618
619/* Clears FLAGS from the loops state. */
620
621inline void
622loops_state_clear (function *fn, unsigned flags)
623{
624 loops_for_fn (fn)->state &= ~flags;
625}
626
627inline void
628loops_state_clear (unsigned flags)
629{
630 if (!current_loops)
631 return;
632 loops_state_clear (cfun, flags);
633}
634
635/* Check loop structure invariants, if internal consistency checks are
636 enabled. */
637
638inline void
640{
641 /* VERIFY_LOOP_STRUCTURE essentially asserts that no loops need fixups.
642
643 The loop optimizers should never make changes to the CFG which
644 require loop fixups. But the low level CFG manipulation code may
645 set the flag conservatively.
646
647 Go ahead and clear the flag here. That avoids the assert inside
648 VERIFY_LOOP_STRUCTURE, and if there is an inconsistency in the loop
649 structures VERIFY_LOOP_STRUCTURE will detect it.
650
651 This also avoid the compile time cost of excessive fixups. */
653 if (flag_checking)
655}
656
657/* Loop iterators. */
658
659/* Flags for loop iteration. */
660
662{
663 LI_INCLUDE_ROOT = 1, /* Include the fake root of the loop tree. */
664 LI_FROM_INNERMOST = 2, /* Iterate over the loops in the reverse order,
665 starting from innermost ones. */
666 LI_ONLY_INNERMOST = 4 /* Iterate only over innermost loops. */
668
669/* Provide the functionality of std::as_const to support range-based for
670 to use const iterator. (We can't use std::as_const itself because it's
671 a C++17 feature.) */
672template <typename T>
673constexpr const T &
675{
676 return t;
677}
678
679/* A list for visiting loops, which contains the loop numbers instead of
680 the loop pointers. If the loop ROOT is offered (non-null), the visiting
681 will start from it, otherwise it would start from the tree_root of
682 loops_for_fn (FN) instead. The scope is restricted in function FN and
683 the visiting order is specified by FLAGS. */
684
686{
687public:
688 loops_list (function *fn, unsigned flags, class loop *root = nullptr);
689
690 template <typename T> class Iter
691 {
692 public:
693 Iter (const loops_list &l, unsigned idx) : list (l), curr_idx (idx)
694 {
695 fill_curr_loop ();
696 }
697
698 T operator* () const { return curr_loop; }
699
700 Iter &
701 operator++ ()
702 {
703 if (curr_idx < list.to_visit.length ())
704 {
705 /* Bump the index and fill a new one. */
706 curr_idx++;
707 fill_curr_loop ();
708 }
709 else
711
712 return *this;
713 }
714
715 bool
716 operator!= (const Iter &rhs) const
717 {
718 return this->curr_idx != rhs.curr_idx;
719 }
720
721 private:
722 /* Fill the current loop starting from the current index. */
723 void fill_curr_loop ();
724
725 /* Reference to the loop list to visit. */
727
728 /* The current index in the list to visit. */
729 unsigned curr_idx;
730
731 /* The loop implied by the current index. */
733 };
734
737
740 {
741 return iterator (*this, 0);
742 }
743
744 iterator
746 {
747 return iterator (*this, to_visit.length ());
748 }
749
750 const_iterator
751 begin () const
752 {
753 return const_iterator (*this, 0);
754 }
755
756 const_iterator
757 end () const
758 {
759 return const_iterator (*this, to_visit.length ());
760 }
761
762private:
763 /* Walk loop tree starting from ROOT as the visiting order specified
764 by FLAGS. */
765 void walk_loop_tree (class loop *root, unsigned flags);
766
767 /* The function we are visiting. */
769
770 /* The list of loops to visit. */
772};
773
774/* Starting from current index CURR_IDX (inclusive), find one index
775 which stands for one valid loop and fill the found loop as CURR_LOOP,
776 if we can't find one, set CURR_LOOP as null. */
777
778template <typename T>
779inline void
781{
782 int anum;
783
784 while (this->list.to_visit.iterate (this->curr_idx, &anum))
785 {
786 class loop *loop = get_loop (this->list.fn, anum);
787 if (loop)
788 {
789 curr_loop = loop;
790 return;
791 }
792 this->curr_idx++;
793 }
794
795 curr_loop = nullptr;
796}
797
798/* Set up the loops list to visit according to the specified
799 function scope FN and iterating order FLAGS. If ROOT is
800 not null, the visiting would start from it, otherwise it
801 will start from tree_root of loops_for_fn (FN). */
802
803inline loops_list::loops_list (function *fn, unsigned flags, class loop *root)
804{
805 struct loops *loops = loops_for_fn (fn);
806 gcc_assert (!root || loops);
807
808 /* Check mutually exclusive flags should not co-exist. */
811
812 this->fn = fn;
813 if (!loops)
814 return;
815
816 class loop *tree_root = root ? root : loops->tree_root;
817
818 this->to_visit.reserve_exact (number_of_loops (fn));
819
820 /* When root is tree_root of loops_for_fn (fn) and the visiting
821 order is LI_ONLY_INNERMOST, we would like to use linear
822 search here since it has a more stable bound than the
823 walk_loop_tree. */
824 if (flags & LI_ONLY_INNERMOST && tree_root == loops->tree_root)
825 {
826 gcc_assert (tree_root->num == 0);
827 if (tree_root->inner == NULL)
828 {
829 if (flags & LI_INCLUDE_ROOT)
830 this->to_visit.quick_push (0);
831
832 return;
833 }
834
835 class loop *aloop;
836 unsigned int i;
837 for (i = 1; vec_safe_iterate (loops->larray, i, &aloop); i++)
838 if (aloop != NULL && aloop->inner == NULL)
839 this->to_visit.quick_push (aloop->num);
840 }
841 else
842 walk_loop_tree (tree_root, flags);
843}
844
845/* The properties of the target. */
847 /* Number of available registers. */
849
850 /* Number of available registers that are call-clobbered. */
852
853 /* Number of registers reserved for temporary expressions. */
855
856 /* The cost for register when there still is some reserve, but we are
857 approaching the number of available registers. */
858 unsigned x_target_reg_cost[2];
859
860 /* The cost for register when we need to spill. */
861 unsigned x_target_spill_cost[2];
862};
863
865#if SWITCHABLE_TARGET
867#else
868#define this_target_cfgloop (&default_target_cfgloop)
869#endif
870
871#define target_avail_regs \
872 (this_target_cfgloop->x_target_avail_regs)
873#define target_clobbered_regs \
874 (this_target_cfgloop->x_target_clobbered_regs)
875#define target_res_regs \
876 (this_target_cfgloop->x_target_res_regs)
877#define target_reg_cost \
878 (this_target_cfgloop->x_target_reg_cost)
879#define target_spill_cost \
880 (this_target_cfgloop->x_target_spill_cost)
881
882/* Register pressure estimation for induction variable optimizations & loop
883 invariant motion. */
884extern unsigned estimate_reg_pressure_cost (unsigned, unsigned, bool, bool);
885extern void init_set_costs (void);
886
887/* Loop optimizer initialization. */
888extern void loop_optimizer_init (unsigned);
889extern void loop_optimizer_finalize (function *, bool = false);
890inline void
895
896/* Optimization passes. */
897enum
898{
899 UAP_UNROLL = 1, /* Enables unrolling of loops if it seems profitable. */
900 UAP_UNROLL_ALL = 2 /* Enables unrolling of all loops. */
902
903extern void doloop_optimize_loops (void);
904extern void move_loop_invariants (void);
906
907/* Returns the outermost loop of the loop nest that contains LOOP.*/
908inline class loop *
910{
911 unsigned n = vec_safe_length (loop->superloops);
912
913 if (n <= 1)
914 return loop;
915
916 return (*loop->superloops)[1];
917}
918
919extern void record_niter_bound (class loop *, const widest_int &, bool, bool);
921extern HOST_WIDE_INT get_max_loop_iterations_int (const class loop *);
924extern bool get_max_loop_iterations (const class loop *loop, widest_int *nit);
927extern edge single_dom_exit (class loop *);
928extern profile_count loop_count_in (const class loop *loop);
929
930/* Converts VAL to widest_int. */
931
932inline widest_int
934{
935 HOST_WIDE_INT a[2];
936
937 a[0] = (unsigned HOST_WIDE_INT) val;
938 /* If HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_WIDEST_INT, avoid shifting by
939 the size of type. */
940 val >>= HOST_BITS_PER_WIDE_INT - 1;
941 val >>= 1;
942 a[1] = (unsigned HOST_WIDE_INT) val;
943
944 return widest_int::from_array (a, 2);
945}
946#endif /* GCC_CFGLOOP_H */
bool bb_loop_header_p(basic_block header)
Definition cfgloop.cc:381
basic_block * get_loop_body(const class loop *loop)
Definition cfgloop.cc:881
int flow_loop_nodes_find(basic_block header, class loop *loop)
Definition cfgloop.cc:225
bool loop_exit_edge_p(const class loop *loop, const_edge e)
Definition cfgloop.cc:1784
bool flow_bb_inside_loop_p(const class loop *loop, const_basic_block bb)
Definition cfgloop.cc:840
bool loop_exits_from_bb_p(class loop *loop, basic_block bb)
Definition cfgloop.cc:1826
edge single_exit(const class loop *loop)
Definition cfgloop.cc:1795
void flow_loop_tree_node_add(class loop *father, class loop *loop, class loop *after)
Definition cfgloop.cc:298
void remove_bb_from_loops(basic_block bb)
Definition cfgloop.cc:1281
HOST_WIDE_INT get_estimated_loop_iterations_int(class loop *loop)
Definition cfgloop.cc:1951
void cancel_loop_tree(class loop *loop)
Definition cfgloop.cc:1367
void add_bb_to_loop(basic_block bb, class loop *loop)
Definition cfgloop.cc:1256
void delete_loop(class loop *loop)
Definition cfgloop.cc:1333
bool flow_loop_nested_p(const class loop *outer, const class loop *loop)
Definition cfgloop.cc:65
HOST_WIDE_INT get_max_loop_iterations_int(const class loop *loop)
Definition cfgloop.cc:2049
void flow_loop_free(class loop *loop)
Definition cfgloop.cc:177
void flow_loops_dump(FILE *file, void(*loop_dump_aux)(const class loop *, FILE *, int), int verbose)
Definition cfgloop.cc:158
void record_loop_exits(void)
Definition cfgloop.cc:1126
class loop * superloop_at_depth(class loop *loop, unsigned depth)
Definition cfgloop.cc:77
bool get_max_loop_iterations(const class loop *loop, widest_int *nit)
Definition cfgloop.cc:2035
void release_recorded_exits(function *fn)
Definition cfgloop.cc:1185
void mark_loop_for_removal(loop_p loop)
Definition cfgloop.cc:2109
bool get_estimated_loop_iterations(class loop *loop, widest_int *nit)
Definition cfgloop.cc:2009
void disambiguate_loops_with_multiple_latches(void)
Definition cfgloop.cc:829
void flow_loop_dump(const class loop *loop, FILE *file, void(*loop_dump_aux)(const class loop *, FILE *, int), int verbose)
Definition cfgloop.cc:111
basic_block * get_loop_body_in_bfs_order(const class loop *loop)
Definition cfgloop.cc:989
HOST_WIDE_INT get_likely_max_loop_iterations_int(class loop *loop)
Definition cfgloop.cc:2083
auto_vec< edge > get_loop_exit_edges(const class loop *loop, basic_block *body)
Definition cfgloop.cc:1196
edge loop_latch_edge(const class loop *loop)
Definition cfgloop.cc:1753
void rescan_loop_exit(edge e, bool new_edge, bool removed)
Definition cfgloop.cc:1072
struct loops * flow_loops_find(struct loops *loops)
Definition cfgloop.cc:416
edge loop_preheader_edge(const class loop *loop)
Definition cfgloop.cc:1760
bool get_likely_max_loop_iterations(class loop *loop, widest_int *nit)
Definition cfgloop.cc:2069
void init_loops_structure(struct function *fn, struct loops *loops, unsigned num_loops)
Definition cfgloop.cc:358
DEBUG_FUNCTION void verify_loop_structure(void)
Definition cfgloop.cc:1392
bool loop_exits_to_bb_p(class loop *loop, basic_block bb)
Definition cfgloop.cc:1811
basic_block * get_loop_body_in_custom_order(const class loop *loop, int(*bb_comparator)(const void *, const void *))
Definition cfgloop.cc:963
void flow_loops_free(struct loops *loops)
Definition cfgloop.cc:201
unsigned num_loop_branches(const class loop *loop)
Definition cfgloop.cc:1237
void flow_loop_tree_node_remove(class loop *loop)
Definition cfgloop.cc:318
dump_user_location_t get_loop_location(class loop *loop)
Definition cfgloop.cc:1841
void sort_sibling_loops(function *fn)
Definition cfgloop.cc:544
class loop * find_common_loop(class loop *loop_s, class loop *loop_d)
Definition cfgloop.cc:1307
basic_block * get_loop_body_in_dom_order(const class loop *loop)
Definition cfgloop.cc:941
int bb_loop_depth(const_basic_block bb)
Definition cfgloop.cc:2101
void record_niter_bound(class loop *loop, const widest_int &i_bound, bool realistic, bool upper)
Definition cfgloop.cc:1895
class loop * alloc_loop(void)
Definition cfgloop.cc:340
unsigned get_loop_body_with_size(const class loop *loop, basic_block *body, unsigned max_size)
Definition cfgloop.cc:869
void flow_loops_free(struct loops *)
Definition cfgloop.cc:201
edge single_likely_exit(class loop *loop, const vec< edge > &)
Definition cfgloopanal.cc:564
iv_extend_code
Definition cfgloop.h:41
@ IV_SIGN_EXTEND
Definition cfgloop.h:42
@ IV_UNKNOWN_EXTEND
Definition cfgloop.h:44
@ IV_ZERO_EXTEND
Definition cfgloop.h:43
bool biv_p(rtx_insn *, scalar_int_mode, rtx)
Definition loop-iv.cc:1239
void iv_analysis_done(void)
Definition loop-iv.cc:1298
void add_bb_to_loop(basic_block, class loop *)
Definition cfgloop.cc:1256
struct target_cfgloop default_target_cfgloop
Definition cfgloopanal.cc:37
void record_niter_bound(class loop *, const widest_int &, bool, bool)
Definition cfgloop.cc:1895
void cancel_loop_tree(class loop *)
Definition cfgloop.cc:1367
void mark_loop_exit_edges(void)
Definition cfgloopanal.cc:536
edge loop_preheader_edge(const class loop *)
Definition cfgloop.cc:1760
void doloop_optimize_loops(void)
Definition loop-doloop.cc:790
bool loop_constraint_set_p(class loop *loop, unsigned c)
Definition cfgloop.h:301
void checking_verify_loop_structure(void)
Definition cfgloop.h:639
void release_recorded_exits(function *)
Definition cfgloop.cc:1185
void loop_optimizer_init(unsigned)
Definition loop-init.cc:86
void flow_loop_dump(const class loop *, FILE *, void(*)(const class loop *, FILE *, int), int)
Definition cfgloop.cc:111
gcov_type expected_loop_iterations_unbounded(const class loop *, bool *read_profile_p=NULL)
Definition cfgloopanal.cc:382
void verify_loop_structure(void)
Definition cfgloop.cc:1392
class loop * find_common_loop(class loop *, class loop *)
Definition cfgloop.cc:1307
void loop_constraint_set(class loop *loop, unsigned c)
Definition cfgloop.h:287
HOST_WIDE_INT get_estimated_loop_iterations_int(class loop *)
Definition cfgloop.cc:1951
edge single_exit(const class loop *)
Definition cfgloop.cc:1795
class loop * loop_outer(const class loop *loop)
Definition cfgloop.h:547
basic_block * get_loop_body(const class loop *)
Definition cfgloop.cc:881
bool iv_analyze_result(rtx_insn *, rtx, class rtx_iv *)
Definition loop-iv.cc:1221
loop_estimation
Definition cfgloop.h:103
@ EST_LAST
Definition cfgloop.h:108
@ EST_AVAILABLE
Definition cfgloop.h:107
@ EST_NOT_COMPUTED
Definition cfgloop.h:105
generic_wide_int< fixed_wide_int_storage< WIDE_INT_MAX_INL_PRECISION > > bound_wide_int
Definition cfgloop.h:48
auto_vec< edge > get_loop_exit_edges(const class loop *, basic_block *=NULL)
Definition cfgloop.cc:1196
@ UAP_UNROLL_ALL
Definition cfgloop.h:900
@ UAP_UNROLL
Definition cfgloop.h:899
profile_count loop_count_in(const class loop *loop)
Definition cfgloopanal.cc:239
class loop * get_loop(struct function *fn, unsigned num)
Definition cfgloop.h:530
basic_block * get_loop_body_in_custom_order(const class loop *, int(*)(const void *, const void *))
Definition cfgloop.cc:963
bool flow_bb_inside_loop_p(const class loop *, const_basic_block)
Definition cfgloop.cc:840
bool iv_analyze_expr(rtx_insn *, scalar_int_mode, rtx, class rtx_iv *)
Definition loop-iv.cc:959
void print_loop_info(FILE *file, const class loop *loop, const char *)
Definition tree-cfg.cc:8616
unsigned get_loop_body_with_size(const class loop *, basic_block *, unsigned)
Definition cfgloop.cc:869
void record_loop_exits(void)
Definition cfgloop.cc:1126
edge single_dom_exit(class loop *)
Definition tree-ssa-loop-ivopts.cc:747
unsigned estimate_reg_pressure_cost(unsigned, unsigned, bool, bool)
Definition cfgloopanal.cc:495
bool get_max_loop_iterations(const class loop *loop, widest_int *nit)
Definition cfgloop.cc:2035
edge loop_latch_edge(const class loop *)
Definition cfgloop.cc:1753
void flow_loops_dump(FILE *, void(*)(const class loop *, FILE *, int), int)
Definition cfgloop.cc:158
unsigned loop_depth(const class loop *loop)
Definition cfgloop.h:538
void loop_constraint_clear(class loop *loop, unsigned c)
Definition cfgloop.h:294
void init_loops_structure(struct function *, struct loops *, unsigned)
Definition cfgloop.cc:358
bool loop_exits_to_bb_p(class loop *, basic_block)
Definition cfgloop.cc:1811
void rescan_loop_exit(edge, bool, bool)
Definition cfgloop.cc:1072
bool get_estimated_loop_iterations(class loop *loop, widest_int *nit)
Definition cfgloop.cc:2009
bool expected_loop_iterations_by_profile(const class loop *loop, sreal *ret, bool *reliable=NULL)
Definition cfgloopanal.cc:277
void move_loop_invariants(void)
Definition loop-invariant.cc:2276
void disambiguate_loops_with_multiple_latches(void)
Definition cfgloop.cc:829
rtx get_iv_value(class rtx_iv *, rtx)
Definition loop-iv.cc:1263
bool just_once_each_iteration_p(const class loop *, const_basic_block)
Definition cfgloopanal.cc:45
void iv_analysis_loop_init(class loop *)
Definition loop-iv.cc:270
basic_block * get_loop_body_in_bfs_order(const class loop *)
Definition cfgloop.cc:989
rtx doloop_condition_get(rtx_insn *)
Definition loop-doloop.cc:73
bool loop_exits_from_bb_p(class loop *, basic_block)
Definition cfgloop.cc:1826
unsigned get_loop_level(const class loop *)
Definition cfgloopanal.cc:417
unsigned expected_loop_iterations(class loop *)
Definition cfgloopanal.cc:408
void loop_optimizer_finalize()
Definition cfgloop.h:891
int flow_loop_nodes_find(basic_block, class loop *)
Definition cfgloop.cc:225
bool mark_irreducible_loops(void)
Definition cfgloopanal.cc:75
void remove_bb_from_loops(basic_block)
Definition cfgloop.cc:1281
constexpr const T & as_const(T &t)
Definition cfgloop.h:674
vec< loop_p, va_gc > * get_loops(struct function *fn)
Definition cfgloop.h:568
class loop * loop_p
Definition cfgloop.h:98
struct loops * flow_loops_find(struct loops *)
Definition cfgloop.cc:416
void init_set_costs(void)
Definition cfgloopanal.cc:434
HOST_WIDE_INT get_likely_max_loop_iterations_int(class loop *)
Definition cfgloop.cc:2083
bool maybe_flat_loop_profile(const class loop *)
Definition cfgloopanal.cc:330
bool loop_has_exit_edges(const class loop *loop)
Definition cfgloop.h:560
int bb_loop_depth(const_basic_block)
Definition cfgloop.cc:2101
bool get_likely_max_loop_iterations(class loop *loop, widest_int *nit)
Definition cfgloop.cc:2069
void free_simple_loop_desc(class loop *loop)
Definition loop-iv.cc:3025
void loops_state_clear(function *fn, unsigned flags)
Definition cfgloop.h:622
int num_loop_insns(const class loop *)
Definition cfgloopanal.cc:177
bool loops_state_satisfies_p(function *fn, unsigned flags)
Definition cfgloop.h:594
lpt_dec
Definition cfgloop.h:27
@ LPT_NONE
Definition cfgloop.h:28
@ LPT_UNROLL_STUPID
Definition cfgloop.h:31
@ LPT_UNROLL_CONSTANT
Definition cfgloop.h:29
@ LPT_UNROLL_RUNTIME
Definition cfgloop.h:30
void delete_loop(class loop *)
Definition cfgloop.cc:1333
HOST_WIDE_INT get_max_loop_iterations_int(const class loop *)
Definition cfgloop.cc:2049
basic_block * get_loop_body_in_dom_order(const class loop *)
Definition cfgloop.cc:941
class niter_desc * simple_loop_desc(class loop *loop)
Definition cfgloop.h:520
void flow_loop_tree_node_remove(class loop *)
Definition cfgloop.cc:318
auto_vec< basic_block > get_loop_hot_path(const class loop *loop)
Definition cfgloopanal.cc:595
li_flags
Definition cfgloop.h:662
@ LI_FROM_INNERMOST
Definition cfgloop.h:664
@ LI_ONLY_INNERMOST
Definition cfgloop.h:666
@ LI_INCLUDE_ROOT
Definition cfgloop.h:663
@ LOOPS_HAVE_PREHEADERS
Definition cfgloop.h:309
@ LOOPS_HAVE_RECORDED_EXITS
Definition cfgloop.h:312
@ LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS
Definition cfgloop.h:311
@ LOOPS_HAVE_FALLTHRU_PREHEADERS
Definition cfgloop.h:316
@ LOOPS_HAVE_SIMPLE_LATCHES
Definition cfgloop.h:310
@ LOOPS_NEED_FIXUP
Definition cfgloop.h:315
@ LOOP_CLOSED_SSA
Definition cfgloop.h:314
@ LOOPS_MAY_HAVE_MULTIPLE_LATCHES
Definition cfgloop.h:313
unsigned num_loop_branches(const class loop *)
Definition cfgloop.cc:1237
#define this_target_cfgloop
Definition cfgloop.h:868
widest_int gcov_type_to_wide_int(gcov_type val)
Definition cfgloop.h:933
void flow_loop_tree_node_add(class loop *, class loop *, class loop *=NULL)
Definition cfgloop.cc:298
class loop * superloop_at_depth(class loop *, unsigned)
Definition cfgloop.cc:77
void sort_sibling_loops(function *)
Definition cfgloop.cc:544
class loop * loop_outermost(class loop *loop)
Definition cfgloop.h:909
unsigned fix_loop_structure(bitmap changed_bbs)
Definition loop-init.cc:200
void loops_state_set(function *fn, unsigned flags)
Definition cfgloop.h:608
dump_user_location_t get_loop_location(class loop *loop)
Definition cfgloop.cc:1841
bool bb_loop_header_p(basic_block)
Definition cfgloop.cc:381
void mark_loop_for_removal(loop_p)
Definition cfgloop.cc:2109
bool loop_exit_edge_p(const class loop *, const_edge)
Definition cfgloop.cc:1784
class niter_desc * get_simple_loop_desc(class loop *loop)
Definition loop-iv.cc:3006
class loop * alloc_loop(void)
Definition cfgloop.cc:340
int average_num_loop_insns(const class loop *)
Definition cfgloopanal.cc:201
bool iv_analyze(rtx_insn *, scalar_int_mode, rtx, class rtx_iv *)
Definition loop-iv.cc:1196
void flow_loop_free(class loop *)
Definition cfgloop.cc:177
bool flow_loop_nested_p(const class loop *, const class loop *)
Definition cfgloop.cc:65
unsigned number_of_loops(struct function *fn)
Definition cfgloop.h:581
Definition vec.h:1656
Definition dumpfile.h:340
Definition hash-table.h:375
Definition cfgloop.h:120
int simdlen
Definition cfgloop.h:183
bound_wide_int nb_iterations_estimate
Definition cfgloop.h:174
class loop * next
Definition cfgloop.h:151
class loop * inner
Definition cfgloop.h:148
unsigned any_likely_upper_bound
Definition cfgloop.h:214
enum loop_estimation estimate_state
Definition cfgloop.h:210
unsigned any_upper_bound
Definition cfgloop.h:212
vec< loop_p, va_gc > * superloops
Definition cfgloop.h:145
int num
Definition cfgloop.h:124
struct control_iv * control_ivs
Definition cfgloop.h:265
unsigned constraints
Definition cfgloop.h:206
class niter_desc * simple_loop_desc
Definition cfgloop.h:271
unsigned av_ninsns
Definition cfgloop.h:139
unsigned any_estimate
Definition cfgloop.h:213
unsigned warned_aggressive_loop_optimizations
Definition cfgloop.h:221
unsigned dont_vectorize
Definition cfgloop.h:224
unsigned can_be_parallel
Definition cfgloop.h:217
unsigned force_vectorize
Definition cfgloop.h:227
basic_block latch
Definition cfgloop.h:133
int safelen
Definition cfgloop.h:180
basic_block former_header
Definition cfgloop.h:277
bound_wide_int nb_iterations_likely_upper_bound
Definition cfgloop.h:169
void * aux
Definition cfgloop.h:154
int orig_loop_num
Definition cfgloop.h:259
tree simduid
Definition cfgloop.h:249
unsigned ninsns
Definition cfgloop.h:127
unsigned short unroll
Definition cfgloop.h:240
unsigned num_nodes
Definition cfgloop.h:142
unsigned short owned_clique
Definition cfgloop.h:244
struct loop_exit * exits
Definition cfgloop.h:268
tree nb_iterations
Definition cfgloop.h:163
unsigned finite_p
Definition cfgloop.h:234
class nb_iter_bound * bounds
Definition cfgloop.h:262
bound_wide_int nb_iterations_upper_bound
Definition cfgloop.h:167
basic_block header
Definition cfgloop.h:130
unsigned in_oacc_kernels_region
Definition cfgloop.h:230
Definition cfgloop.h:691
Iter & operator++()
Definition cfgloop.h:701
unsigned curr_idx
Definition cfgloop.h:729
class loop * curr_loop
Definition cfgloop.h:732
bool operator!=(const Iter &rhs) const
Definition cfgloop.h:716
void fill_curr_loop()
Definition cfgloop.h:780
Iter(const loops_list &l, unsigned idx)
Definition cfgloop.h:693
const loops_list & list
Definition cfgloop.h:726
T operator*() const
Definition cfgloop.h:698
Definition cfgloop.h:686
Iter< const class loop * > const_iterator
Definition cfgloop.h:736
function * fn
Definition cfgloop.h:768
const_iterator begin() const
Definition cfgloop.h:751
auto_vec< int, 16 > to_visit
Definition cfgloop.h:771
const_iterator end() const
Definition cfgloop.h:757
void walk_loop_tree(class loop *root, unsigned flags)
Definition cfgloop.cc:2127
Iter< class loop * > iterator
Definition cfgloop.h:735
iterator end()
Definition cfgloop.h:745
iterator begin()
Definition cfgloop.h:739
loops_list(function *fn, unsigned flags, class loop *root=nullptr)
Definition cfgloop.h:803
Definition cfgloop.h:52
class nb_iter_bound * next
Definition cfgloop.h:72
bound_wide_int bound
Definition cfgloop.h:64
gimple * stmt
Definition cfgloop.h:55
bool is_exit
Definition cfgloop.h:69
Definition cfgloop.h:469
bool const_iter
Definition cfgloop.h:482
rtx assumptions
Definition cfgloop.h:488
edge in_edge
Definition cfgloop.h:475
rtx niter_expr
Definition cfgloop.h:504
rtx noloop_assumptions
Definition cfgloop.h:492
rtx infinite
Definition cfgloop.h:495
bool simple_p
Definition cfgloop.h:479
bool signed_p
Definition cfgloop.h:498
scalar_int_mode mode
Definition cfgloop.h:501
uint64_t niter
Definition cfgloop.h:485
edge out_edge
Definition cfgloop.h:472
Definition cfgloop.h:442
rtx mult
Definition cfgloop.h:453
enum iv_extend_code extend
Definition cfgloop.h:450
rtx base
Definition cfgloop.h:446
rtx step
Definition cfgloop.h:446
scalar_int_mode mode
Definition cfgloop.h:459
scalar_int_mode extend_mode
Definition cfgloop.h:456
unsigned first_special
Definition cfgloop.h:462
rtx delta
Definition cfgloop.h:453
Definition machmode.h:427
Definition sreal.h:41
class edge_def * edge
Definition coretypes.h:342
const class edge_def * const_edge
Definition coretypes.h:343
#define GTY(x)
Definition coretypes.h:41
class bitmap_head * bitmap
Definition coretypes.h:51
int64_t gcov_type
Definition coretypes.h:46
union tree_node * tree
Definition coretypes.h:97
bool operator!=(const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:132
struct loops * loops_for_fn(struct function *fn)
Definition function.h:511
#define current_loops
Definition function.h:539
#define cfun
Definition function.h:475
size_t mult
Definition ggc-page.cc:232
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
#define HOST_BITS_PER_WIDE_INT
Definition hwint.h:53
static class loop * curr_loop
Definition loop-invariant.cc:146
i
Definition poly-int.h:772
Ca & a
Definition poly-int.h:766
Definition basic-block.h:117
Definition tree-ssa-loop-niter.cc:64
Definition cfgloop.h:113
tree base
Definition cfgloop.h:114
tree step
Definition cfgloop.h:115
struct control_iv * next
Definition cfgloop.h:116
Definition tree-inline.h:186
Definition function.h:249
Definition hash-traits.h:321
Definition gimple.h:225
Definition cfgloop.h:90
static hashval_t hash(loop_exit *)
Definition cfgloop.cc:1027
static bool equal(loop_exit *, edge)
Definition cfgloop.cc:1035
edge compare_type
Definition cfgloop.h:91
static void remove(loop_exit *)
Definition cfgloop.cc:1043
Definition cfgloop.h:77
struct loop_exit * prev
Definition cfgloop.h:82
struct loop_exit * next_e
Definition cfgloop.h:86
struct loop_exit * next
Definition cfgloop.h:83
edge e
Definition cfgloop.h:79
Definition cfgloop.h:324
hash_table< loop_exit_hasher > * exits
Definition cfgloop.h:334
class loop * tree_root
Definition cfgloop.h:337
int state
Definition cfgloop.h:326
vec< loop_p, va_gc > * larray
Definition cfgloop.h:329
Definition cfgloop.h:34
unsigned times
Definition cfgloop.h:36
enum lpt_dec decision
Definition cfgloop.h:35
Definition profile-count.h:750
Definition rtl.h:311
Definition rtl.h:545
Definition genautomata.cc:669
Definition cfgloop.h:846
unsigned x_target_avail_regs
Definition cfgloop.h:848
unsigned x_target_reg_cost[2]
Definition cfgloop.h:858
unsigned x_target_res_regs
Definition cfgloop.h:854
unsigned x_target_clobbered_regs
Definition cfgloop.h:851
unsigned x_target_spill_cost[2]
Definition cfgloop.h:861
Definition vec.h:450
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:821
static vec< constraint_t > constraints
Definition tree-ssa-structalias.cc:548
bool vec_safe_iterate(const vec< T, A, vl_embed > *v, unsigned ix, T **ptr)
Definition vec.h:803
unsigned vec_safe_length(const vec< T, A, vl_embed > *v)
Definition vec.h:685