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