]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/loop.texi
Update copyright years.
[thirdparty/gcc.git] / gcc / doc / loop.texi
CommitLineData
83ffe9cd 1@c Copyright (C) 2006-2023 Free Software Foundation, Inc.
d77de738
ML
2@c Free Software Foundation, Inc.
3@c This is part of the GCC manual.
4@c For copying conditions, see the file gcc.texi.
5
6@c ---------------------------------------------------------------------
7@c Loop Representation
8@c ---------------------------------------------------------------------
9
10@node Loop Analysis and Representation
11@chapter Analysis and Representation of Loops
12
13GCC provides extensive infrastructure for work with natural loops, i.e.,
14strongly connected components of CFG with only one entry block. This
15chapter describes representation of loops in GCC, both on GIMPLE and in
16RTL, as well as the interfaces to loop-related analyses (induction
17variable analysis and number of iterations analysis).
18
19@menu
20* Loop representation:: Representation and analysis of loops.
21* Loop querying:: Getting information about loops.
22* Loop manipulation:: Loop manipulation functions.
23* LCSSA:: Loop-closed SSA form.
24* Scalar evolutions:: Induction variables on GIMPLE.
25* loop-iv:: Induction variables on RTL.
26* Number of iterations:: Number of iterations analysis.
27* Dependency analysis:: Data dependency analysis.
28@end menu
29
30@node Loop representation
31@section Loop representation
32@cindex Loop representation
33@cindex Loop analysis
34
35This chapter describes the representation of loops in GCC, and functions
36that can be used to build, modify and analyze this representation. Most
37of the interfaces and data structures are declared in @file{cfgloop.h}.
38Loop structures are analyzed and this information disposed or updated
39at the discretion of individual passes. Still most of the generic
40CFG manipulation routines are aware of loop structures and try to
41keep them up-to-date. By this means an increasing part of the
42compilation pipeline is setup to maintain loop structure across
43passes to allow attaching meta information to individual loops
44for consumption by later passes.
45
46In general, a natural loop has one entry block (header) and possibly
47several back edges (latches) leading to the header from the inside of
48the loop. Loops with several latches may appear if several loops share
49a single header, or if there is a branching in the middle of the loop.
50The representation of loops in GCC however allows only loops with a
51single latch. During loop analysis, headers of such loops are split and
52forwarder blocks are created in order to disambiguate their structures.
53Heuristic based on profile information and structure of the induction
54variables in the loops is used to determine whether the latches
55correspond to sub-loops or to control flow in a single loop. This means
56that the analysis sometimes changes the CFG, and if you run it in the
57middle of an optimization pass, you must be able to deal with the new
58blocks. You may avoid CFG changes by passing
59@code{LOOPS_MAY_HAVE_MULTIPLE_LATCHES} flag to the loop discovery,
60note however that most other loop manipulation functions will not work
61correctly for loops with multiple latch edges (the functions that only
62query membership of blocks to loops and subloop relationships, or
63enumerate and test loop exits, can be expected to work).
64
65Body of the loop is the set of blocks that are dominated by its header,
66and reachable from its latch against the direction of edges in CFG@. The
67loops are organized in a containment hierarchy (tree) such that all the
68loops immediately contained inside loop L are the children of L in the
69tree. This tree is represented by the @code{struct loops} structure.
70The root of this tree is a fake loop that contains all blocks in the
71function. Each of the loops is represented in a @code{struct loop}
72structure. Each loop is assigned an index (@code{num} field of the
73@code{struct loop} structure), and the pointer to the loop is stored in
74the corresponding field of the @code{larray} vector in the loops
75structure. The indices do not have to be continuous, there may be
76empty (@code{NULL}) entries in the @code{larray} created by deleting
77loops. Also, there is no guarantee on the relative order of a loop
78and its subloops in the numbering. The index of a loop never changes.
79
80The entries of the @code{larray} field should not be accessed directly.
81The function @code{get_loop} returns the loop description for a loop with
82the given index. @code{number_of_loops} function returns number of loops
83in the function. To traverse all loops, use a range-based for loop with
84class @code{loops_list} instance. The @code{flags} argument passed to the
85constructor function of class @code{loops_list} is used to determine the
86direction of traversal and the set of loops visited. Each loop is
87guaranteed to be visited exactly once, regardless of the changes to the
88loop tree, and the loops may be removed during the traversal. The newly
89created loops are never traversed, if they need to be visited, this must
90be done separately after their creation.
91
92Each basic block contains the reference to the innermost loop it belongs
93to (@code{loop_father}). For this reason, it is only possible to have
94one @code{struct loops} structure initialized at the same time for each
95CFG@. The global variable @code{current_loops} contains the
96@code{struct loops} structure. Many of the loop manipulation functions
97assume that dominance information is up-to-date.
98
99The loops are analyzed through @code{loop_optimizer_init} function. The
100argument of this function is a set of flags represented in an integer
101bitmask. These flags specify what other properties of the loop
102structures should be calculated/enforced and preserved later:
103
104@itemize
105@item @code{LOOPS_MAY_HAVE_MULTIPLE_LATCHES}: If this flag is set, no
106changes to CFG will be performed in the loop analysis, in particular,
107loops with multiple latch edges will not be disambiguated. If a loop
108has multiple latches, its latch block is set to NULL@. Most of
109the loop manipulation functions will not work for loops in this shape.
110No other flags that require CFG changes can be passed to
111loop_optimizer_init.
112@item @code{LOOPS_HAVE_PREHEADERS}: Forwarder blocks are created in such
113a way that each loop has only one entry edge, and additionally, the
114source block of this entry edge has only one successor. This creates a
115natural place where the code can be moved out of the loop, and ensures
116that the entry edge of the loop leads from its immediate super-loop.
117@item @code{LOOPS_HAVE_SIMPLE_LATCHES}: Forwarder blocks are created to
118force the latch block of each loop to have only one successor. This
119ensures that the latch of the loop does not belong to any of its
120sub-loops, and makes manipulation with the loops significantly easier.
121Most of the loop manipulation functions assume that the loops are in
122this shape. Note that with this flag, the ``normal'' loop without any
123control flow inside and with one exit consists of two basic blocks.
124@item @code{LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS}: Basic blocks and
125edges in the strongly connected components that are not natural loops
126(have more than one entry block) are marked with
127@code{BB_IRREDUCIBLE_LOOP} and @code{EDGE_IRREDUCIBLE_LOOP} flags. The
128flag is not set for blocks and edges that belong to natural loops that
129are in such an irreducible region (but it is set for the entry and exit
130edges of such a loop, if they lead to/from this region).
131@item @code{LOOPS_HAVE_RECORDED_EXITS}: The lists of exits are recorded
132and updated for each loop. This makes some functions (e.g.,
133@code{get_loop_exit_edges}) more efficient. Some functions (e.g.,
134@code{single_exit}) can be used only if the lists of exits are
135recorded.
136@end itemize
137
138These properties may also be computed/enforced later, using functions
139@code{create_preheaders}, @code{force_single_succ_latches},
140@code{mark_irreducible_loops} and @code{record_loop_exits}.
141The properties can be queried using @code{loops_state_satisfies_p}.
142
143The memory occupied by the loops structures should be freed with
144@code{loop_optimizer_finalize} function. When loop structures are
145setup to be preserved across passes this function reduces the
146information to be kept up-to-date to a minimum (only
147@code{LOOPS_MAY_HAVE_MULTIPLE_LATCHES} set).
148
149The CFG manipulation functions in general do not update loop structures.
150Specialized versions that additionally do so are provided for the most
151common tasks. On GIMPLE, @code{cleanup_tree_cfg_loop} function can be
152used to cleanup CFG while updating the loops structures if
153@code{current_loops} is set.
154
155At the moment loop structure is preserved from the start of GIMPLE
156loop optimizations until the end of RTL loop optimizations. During
157this time a loop can be tracked by its @code{struct loop} and number.
158
159@node Loop querying
160@section Loop querying
161@cindex Loop querying
162
163The functions to query the information about loops are declared in
164@file{cfgloop.h}. Some of the information can be taken directly from
165the structures. @code{loop_father} field of each basic block contains
166the innermost loop to that the block belongs. The most useful fields of
167loop structure (that are kept up-to-date at all times) are:
168
169@itemize
170@item @code{header}, @code{latch}: Header and latch basic blocks of the
171loop.
172@item @code{num_nodes}: Number of basic blocks in the loop (including
173the basic blocks of the sub-loops).
174@item @code{outer}, @code{inner}, @code{next}: The super-loop, the first
175sub-loop, and the sibling of the loop in the loops tree.
176@end itemize
177
178There are other fields in the loop structures, many of them used only by
179some of the passes, or not updated during CFG changes; in general, they
180should not be accessed directly.
181
182The most important functions to query loop structures are:
183
184@itemize
185@item @code{loop_depth}: The depth of the loop in the loops tree, i.e., the
186number of super-loops of the loop.
187@item @code{flow_loops_dump}: Dumps the information about loops to a
188file.
189@item @code{verify_loop_structure}: Checks consistency of the loop
190structures.
191@item @code{loop_latch_edge}: Returns the latch edge of a loop.
192@item @code{loop_preheader_edge}: If loops have preheaders, returns
193the preheader edge of a loop.
194@item @code{flow_loop_nested_p}: Tests whether loop is a sub-loop of
195another loop.
196@item @code{flow_bb_inside_loop_p}: Tests whether a basic block belongs
197to a loop (including its sub-loops).
198@item @code{find_common_loop}: Finds the common super-loop of two loops.
199@item @code{superloop_at_depth}: Returns the super-loop of a loop with
200the given depth.
201@item @code{tree_num_loop_insns}, @code{num_loop_insns}: Estimates the
202number of insns in the loop, on GIMPLE and on RTL.
203@item @code{loop_exit_edge_p}: Tests whether edge is an exit from a
204loop.
205@item @code{mark_loop_exit_edges}: Marks all exit edges of all loops
206with @code{EDGE_LOOP_EXIT} flag.
207@item @code{get_loop_body}, @code{get_loop_body_in_dom_order},
208@code{get_loop_body_in_bfs_order}: Enumerates the basic blocks in the
209loop in depth-first search order in reversed CFG, ordered by dominance
210relation, and breath-first search order, respectively.
211@item @code{single_exit}: Returns the single exit edge of the loop, or
212@code{NULL} if the loop has more than one exit. You can only use this
213function if @code{LOOPS_HAVE_RECORDED_EXITS} is used.
214@item @code{get_loop_exit_edges}: Enumerates the exit edges of a loop.
215@item @code{just_once_each_iteration_p}: Returns true if the basic block
216is executed exactly once during each iteration of a loop (that is, it
217does not belong to a sub-loop, and it dominates the latch of the loop).
218@end itemize
219
220@node Loop manipulation
221@section Loop manipulation
222@cindex Loop manipulation
223
224The loops tree can be manipulated using the following functions:
225
226@itemize
227@item @code{flow_loop_tree_node_add}: Adds a node to the tree.
228@item @code{flow_loop_tree_node_remove}: Removes a node from the tree.
229@item @code{add_bb_to_loop}: Adds a basic block to a loop.
230@item @code{remove_bb_from_loops}: Removes a basic block from loops.
231@end itemize
232
233Most low-level CFG functions update loops automatically. The following
234functions handle some more complicated cases of CFG manipulations:
235
236@itemize
237@item @code{remove_path}: Removes an edge and all blocks it dominates.
238@item @code{split_loop_exit_edge}: Splits exit edge of the loop,
239ensuring that PHI node arguments remain in the loop (this ensures that
240loop-closed SSA form is preserved). Only useful on GIMPLE.
241@end itemize
242
243Finally, there are some higher-level loop transformations implemented.
244While some of them are written so that they should work on non-innermost
245loops, they are mostly untested in that case, and at the moment, they
246are only reliable for the innermost loops:
247
248@itemize
249@item @code{create_iv}: Creates a new induction variable. Only works on
250GIMPLE@. @code{standard_iv_increment_position} can be used to find a
251suitable place for the iv increment.
252@item @code{duplicate_loop_body_to_header_edge},
253@code{tree_duplicate_loop_body_to_header_edge}: These functions (on RTL and
254on GIMPLE) duplicate the body of the loop prescribed number of times on
255one of the edges entering loop header, thus performing either loop
256unrolling or loop peeling. @code{can_duplicate_loop_p}
257(@code{can_unroll_loop_p} on GIMPLE) must be true for the duplicated
258loop.
259@item @code{loop_version}: This function creates a copy of a loop, and
260a branch before them that selects one of them depending on the
261prescribed condition. This is useful for optimizations that need to
262verify some assumptions in runtime (one of the copies of the loop is
263usually left unchanged, while the other one is transformed in some way).
264@item @code{tree_unroll_loop}: Unrolls the loop, including peeling the
265extra iterations to make the number of iterations divisible by unroll
266factor, updating the exit condition, and removing the exits that now
267cannot be taken. Works only on GIMPLE.
268@end itemize
269
270@node LCSSA
271@section Loop-closed SSA form
272@cindex LCSSA
273@cindex Loop-closed SSA form
274
275Throughout the loop optimizations on tree level, one extra condition is
276enforced on the SSA form: No SSA name is used outside of the loop in
277that it is defined. The SSA form satisfying this condition is called
278``loop-closed SSA form'' -- LCSSA@. To enforce LCSSA, PHI nodes must be
279created at the exits of the loops for the SSA names that are used
280outside of them. Only the real operands (not virtual SSA names) are
281held in LCSSA, in order to save memory.
282
283There are various benefits of LCSSA:
284
285@itemize
286@item Many optimizations (value range analysis, final value
287replacement) are interested in the values that are defined in the loop
288and used outside of it, i.e., exactly those for that we create new PHI
289nodes.
290@item In induction variable analysis, it is not necessary to specify the
291loop in that the analysis should be performed -- the scalar evolution
292analysis always returns the results with respect to the loop in that the
293SSA name is defined.
294@item It makes updating of SSA form during loop transformations simpler.
295Without LCSSA, operations like loop unrolling may force creation of PHI
296nodes arbitrarily far from the loop, while in LCSSA, the SSA form can be
297updated locally. However, since we only keep real operands in LCSSA, we
298cannot use this advantage (we could have local updating of real
299operands, but it is not much more efficient than to use generic SSA form
300updating for it as well; the amount of changes to SSA is the same).
301@end itemize
302
303However, it also means LCSSA must be updated. This is usually
304straightforward, unless you create a new value in loop and use it
305outside, or unless you manipulate loop exit edges (functions are
306provided to make these manipulations simple).
307@code{rewrite_into_loop_closed_ssa} is used to rewrite SSA form to
308LCSSA, and @code{verify_loop_closed_ssa} to check that the invariant of
309LCSSA is preserved.
310
311@node Scalar evolutions
312@section Scalar evolutions
313@cindex Scalar evolutions
314@cindex IV analysis on GIMPLE
315
316Scalar evolutions (SCEV) are used to represent results of induction
317variable analysis on GIMPLE@. They enable us to represent variables with
318complicated behavior in a simple and consistent way (we only use it to
319express values of polynomial induction variables, but it is possible to
320extend it). The interfaces to SCEV analysis are declared in
321@file{tree-scalar-evolution.h}. To use scalar evolutions analysis,
322@code{scev_initialize} must be used. To stop using SCEV,
323@code{scev_finalize} should be used. SCEV analysis caches results in
324order to save time and memory. This cache however is made invalid by
325most of the loop transformations, including removal of code. If such a
326transformation is performed, @code{scev_reset} must be called to clean
327the caches.
328
329Given an SSA name, its behavior in loops can be analyzed using the
330@code{analyze_scalar_evolution} function. The returned SCEV however
331does not have to be fully analyzed and it may contain references to
332other SSA names defined in the loop. To resolve these (potentially
333recursive) references, @code{instantiate_parameters} or
334@code{resolve_mixers} functions must be used.
335@code{instantiate_parameters} is useful when you use the results of SCEV
336only for some analysis, and when you work with whole nest of loops at
337once. It will try replacing all SSA names by their SCEV in all loops,
338including the super-loops of the current loop, thus providing a complete
339information about the behavior of the variable in the loop nest.
340@code{resolve_mixers} is useful if you work with only one loop at a
341time, and if you possibly need to create code based on the value of the
342induction variable. It will only resolve the SSA names defined in the
343current loop, leaving the SSA names defined outside unchanged, even if
344their evolution in the outer loops is known.
345
346The SCEV is a normal tree expression, except for the fact that it may
347contain several special tree nodes. One of them is
348@code{SCEV_NOT_KNOWN}, used for SSA names whose value cannot be
349expressed. The other one is @code{POLYNOMIAL_CHREC}. Polynomial chrec
350has three arguments -- base, step and loop (both base and step may
351contain further polynomial chrecs). Type of the expression and of base
352and step must be the same. A variable has evolution
353@code{POLYNOMIAL_CHREC(base, step, loop)} if it is (in the specified
354loop) equivalent to @code{x_1} in the following example
355
356@smallexample
357while (@dots{})
358 @{
359 x_1 = phi (base, x_2);
360 x_2 = x_1 + step;
361 @}
362@end smallexample
363
364Note that this includes the language restrictions on the operations.
365For example, if we compile C code and @code{x} has signed type, then the
366overflow in addition would cause undefined behavior, and we may assume
367that this does not happen. Hence, the value with this SCEV cannot
368overflow (which restricts the number of iterations of such a loop).
369
370In many cases, one wants to restrict the attention just to affine
371induction variables. In this case, the extra expressive power of SCEV
372is not useful, and may complicate the optimizations. In this case,
373@code{simple_iv} function may be used to analyze a value -- the result
374is a loop-invariant base and step.
375
376@node loop-iv
377@section IV analysis on RTL
378@cindex IV analysis on RTL
379
380The induction variable on RTL is simple and only allows analysis of
381affine induction variables, and only in one loop at once. The interface
382is declared in @file{cfgloop.h}. Before analyzing induction variables
383in a loop L, @code{iv_analysis_loop_init} function must be called on L.
384After the analysis (possibly calling @code{iv_analysis_loop_init} for
385several loops) is finished, @code{iv_analysis_done} should be called.
386The following functions can be used to access the results of the
387analysis:
388
389@itemize
390@item @code{iv_analyze}: Analyzes a single register used in the given
391insn. If no use of the register in this insn is found, the following
392insns are scanned, so that this function can be called on the insn
393returned by get_condition.
394@item @code{iv_analyze_result}: Analyzes result of the assignment in the
395given insn.
396@item @code{iv_analyze_expr}: Analyzes a more complicated expression.
397All its operands are analyzed by @code{iv_analyze}, and hence they must
398be used in the specified insn or one of the following insns.
399@end itemize
400
401The description of the induction variable is provided in @code{struct
402rtx_iv}. In order to handle subregs, the representation is a bit
403complicated; if the value of the @code{extend} field is not
404@code{UNKNOWN}, the value of the induction variable in the i-th
405iteration is
406
407@smallexample
408delta + mult * extend_@{extend_mode@} (subreg_@{mode@} (base + i * step)),
409@end smallexample
410
411with the following exception: if @code{first_special} is true, then the
412value in the first iteration (when @code{i} is zero) is @code{delta +
413mult * base}. However, if @code{extend} is equal to @code{UNKNOWN},
414then @code{first_special} must be false, @code{delta} 0, @code{mult} 1
415and the value in the i-th iteration is
416
417@smallexample
418subreg_@{mode@} (base + i * step)
419@end smallexample
420
421The function @code{get_iv_value} can be used to perform these
422calculations.
423
424@node Number of iterations
425@section Number of iterations analysis
426@cindex Number of iterations analysis
427
428Both on GIMPLE and on RTL, there are functions available to determine
429the number of iterations of a loop, with a similar interface. The
430number of iterations of a loop in GCC is defined as the number of
431executions of the loop latch. In many cases, it is not possible to
432determine the number of iterations unconditionally -- the determined
433number is correct only if some assumptions are satisfied. The analysis
434tries to verify these conditions using the information contained in the
435program; if it fails, the conditions are returned together with the
436result. The following information and conditions are provided by the
437analysis:
438
439@itemize
440@item @code{assumptions}: If this condition is false, the rest of
441the information is invalid.
442@item @code{noloop_assumptions} on RTL, @code{may_be_zero} on GIMPLE: If
443this condition is true, the loop exits in the first iteration.
444@item @code{infinite}: If this condition is true, the loop is infinite.
445This condition is only available on RTL@. On GIMPLE, conditions for
446finiteness of the loop are included in @code{assumptions}.
447@item @code{niter_expr} on RTL, @code{niter} on GIMPLE: The expression
448that gives number of iterations. The number of iterations is defined as
449the number of executions of the loop latch.
450@end itemize
451
452Both on GIMPLE and on RTL, it necessary for the induction variable
453analysis framework to be initialized (SCEV on GIMPLE, loop-iv on RTL).
454On GIMPLE, the results are stored to @code{struct tree_niter_desc}
455structure. Number of iterations before the loop is exited through a
456given exit can be determined using @code{number_of_iterations_exit}
457function. On RTL, the results are returned in @code{struct niter_desc}
458structure. The corresponding function is named
459@code{check_simple_exit}. There are also functions that pass through
460all the exits of a loop and try to find one with easy to determine
461number of iterations -- @code{find_loop_niter} on GIMPLE and
462@code{find_simple_exit} on RTL@. Finally, there are functions that
463provide the same information, but additionally cache it, so that
464repeated calls to number of iterations are not so costly --
465@code{number_of_latch_executions} on GIMPLE and @code{get_simple_loop_desc}
466on RTL.
467
468Note that some of these functions may behave slightly differently than
469others -- some of them return only the expression for the number of
470iterations, and fail if there are some assumptions. The function
471@code{number_of_latch_executions} works only for single-exit loops.
472The function @code{number_of_cond_exit_executions} can be used to
473determine number of executions of the exit condition of a single-exit
474loop (i.e., the @code{number_of_latch_executions} increased by one).
475
476On GIMPLE, below constraint flags affect semantics of some APIs of number
477of iterations analyzer:
478
479@itemize
480@item @code{LOOP_C_INFINITE}: If this constraint flag is set, the loop
481is known to be infinite. APIs like @code{number_of_iterations_exit} can
482return false directly without doing any analysis.
483@item @code{LOOP_C_FINITE}: If this constraint flag is set, the loop is
484known to be finite, in other words, loop's number of iterations can be
485computed with @code{assumptions} be true.
486@end itemize
487
488Generally, the constraint flags are set/cleared by consumers which are
489loop optimizers. It's also the consumers' responsibility to set/clear
490constraints correctly. Failing to do that might result in hard to track
491down bugs in scev/niter consumers. One typical use case is vectorizer:
492it drives number of iterations analyzer by setting @code{LOOP_C_FINITE}
493and vectorizes possibly infinite loop by versioning loop with analysis
494result. In return, constraints set by consumers can also help number of
495iterations analyzer in following optimizers. For example, @code{niter}
496of a loop versioned under @code{assumptions} is valid unconditionally.
497
498Other constraints may be added in the future, for example, a constraint
499indicating that loops' latch must roll thus @code{may_be_zero} would be
500false unconditionally.
501
502@node Dependency analysis
503@section Data Dependency Analysis
504@cindex Data Dependency Analysis
505
506The code for the data dependence analysis can be found in
507@file{tree-data-ref.cc} and its interface and data structures are
508described in @file{tree-data-ref.h}. The function that computes the
509data dependences for all the array and pointer references for a given
510loop is @code{compute_data_dependences_for_loop}. This function is
511currently used by the linear loop transform and the vectorization
512passes. Before calling this function, one has to allocate two vectors:
513a first vector will contain the set of data references that are
514contained in the analyzed loop body, and the second vector will contain
515the dependence relations between the data references. Thus if the
516vector of data references is of size @code{n}, the vector containing the
517dependence relations will contain @code{n*n} elements. However if the
518analyzed loop contains side effects, such as calls that potentially can
519interfere with the data references in the current analyzed loop, the
520analysis stops while scanning the loop body for data references, and
521inserts a single @code{chrec_dont_know} in the dependence relation
522array.
523
524The data references are discovered in a particular order during the
525scanning of the loop body: the loop body is analyzed in execution order,
526and the data references of each statement are pushed at the end of the
527data reference array. Two data references syntactically occur in the
528program in the same order as in the array of data references. This
529syntactic order is important in some classical data dependence tests,
530and mapping this order to the elements of this array avoids costly
531queries to the loop body representation.
532
533Three types of data references are currently handled: ARRAY_REF,
534INDIRECT_REF and COMPONENT_REF@. The data structure for the data reference
535is @code{data_reference}, where @code{data_reference_p} is a name of a
536pointer to the data reference structure. The structure contains the
537following elements:
538
539@itemize
540@item @code{base_object_info}: Provides information about the base object
541of the data reference and its access functions. These access functions
542represent the evolution of the data reference in the loop relative to
543its base, in keeping with the classical meaning of the data reference
544access function for the support of arrays. For example, for a reference
545@code{a.b[i][j]}, the base object is @code{a.b} and the access functions,
546one for each array subscript, are:
547@code{@{i_init, + i_step@}_1, @{j_init, +, j_step@}_2}.
548
549@item @code{first_location_in_loop}: Provides information about the first
550location accessed by the data reference in the loop and about the access
551function used to represent evolution relative to this location. This data
552is used to support pointers, and is not used for arrays (for which we
553have base objects). Pointer accesses are represented as a one-dimensional
554access that starts from the first location accessed in the loop. For
555example:
556
557@smallexample
558 for1 i
559 for2 j
560 *((int *)p + i + j) = a[i][j];
561@end smallexample
562
563The access function of the pointer access is @code{@{0, + 4B@}_for2}
564relative to @code{p + i}. The access functions of the array are
565@code{@{i_init, + i_step@}_for1} and @code{@{j_init, +, j_step@}_for2}
566relative to @code{a}.
567
568Usually, the object the pointer refers to is either unknown, or we cannot
569prove that the access is confined to the boundaries of a certain object.
570
571Two data references can be compared only if at least one of these two
572representations has all its fields filled for both data references.
573
574The current strategy for data dependence tests is as follows:
575If both @code{a} and @code{b} are represented as arrays, compare
576@code{a.base_object} and @code{b.base_object};
577if they are equal, apply dependence tests (use access functions based on
578base_objects).
579Else if both @code{a} and @code{b} are represented as pointers, compare
580@code{a.first_location} and @code{b.first_location};
581if they are equal, apply dependence tests (use access functions based on
582first location).
583However, if @code{a} and @code{b} are represented differently, only try
584to prove that the bases are definitely different.
585
586@item Aliasing information.
587@item Alignment information.
588@end itemize
589
590The structure describing the relation between two data references is
591@code{data_dependence_relation} and the shorter name for a pointer to
592such a structure is @code{ddr_p}. This structure contains:
593
594@itemize
595@item a pointer to each data reference,
596@item a tree node @code{are_dependent} that is set to @code{chrec_known}
597if the analysis has proved that there is no dependence between these two
598data references, @code{chrec_dont_know} if the analysis was not able to
599determine any useful result and potentially there could exist a
600dependence between these data references, and @code{are_dependent} is
601set to @code{NULL_TREE} if there exist a dependence relation between the
602data references, and the description of this dependence relation is
603given in the @code{subscripts}, @code{dir_vects}, and @code{dist_vects}
604arrays,
605@item a boolean that determines whether the dependence relation can be
606represented by a classical distance vector,
607@item an array @code{subscripts} that contains a description of each
608subscript of the data references. Given two array accesses a
609subscript is the tuple composed of the access functions for a given
610dimension. For example, given @code{A[f1][f2][f3]} and
611@code{B[g1][g2][g3]}, there are three subscripts: @code{(f1, g1), (f2,
612g2), (f3, g3)}.
613@item two arrays @code{dir_vects} and @code{dist_vects} that contain
614classical representations of the data dependences under the form of
615direction and distance dependence vectors,
616@item an array of loops @code{loop_nest} that contains the loops to
617which the distance and direction vectors refer to.
618@end itemize
619
620Several functions for pretty printing the information extracted by the
621data dependence analysis are available: @code{dump_ddrs} prints with a
622maximum verbosity the details of a data dependence relations array,
623@code{dump_dist_dir_vectors} prints only the classical distance and
624direction vectors for a data dependence relations array, and
625@code{dump_data_references} prints the details of the data references
626contained in a data reference array.