]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gccint/analysis-and-representation-of-loops/loop-manipulation.rst
7546e439f8cd2de744ec621a08049c2188d93a46
[thirdparty/gcc.git] / gcc / doc / gccint / analysis-and-representation-of-loops / loop-manipulation.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: Loop manipulation
7
8 .. _loop-manipulation:
9
10 Loop manipulation
11 *****************
12
13 The loops tree can be manipulated using the following functions:
14
15 * ``flow_loop_tree_node_add`` : Adds a node to the tree.
16
17 * ``flow_loop_tree_node_remove`` : Removes a node from the tree.
18
19 * ``add_bb_to_loop`` : Adds a basic block to a loop.
20
21 * ``remove_bb_from_loops`` : Removes a basic block from loops.
22
23 Most low-level CFG functions update loops automatically. The following
24 functions handle some more complicated cases of CFG manipulations:
25
26 * ``remove_path`` : Removes an edge and all blocks it dominates.
27
28 * ``split_loop_exit_edge`` : Splits exit edge of the loop,
29 ensuring that PHI node arguments remain in the loop (this ensures that
30 loop-closed SSA form is preserved). Only useful on GIMPLE.
31
32 Finally, there are some higher-level loop transformations implemented.
33 While some of them are written so that they should work on non-innermost
34 loops, they are mostly untested in that case, and at the moment, they
35 are only reliable for the innermost loops:
36
37 * ``create_iv`` : Creates a new induction variable. Only works on
38 GIMPLE. ``standard_iv_increment_position`` can be used to find a
39 suitable place for the iv increment.
40
41 * ``duplicate_loop_body_to_header_edge``,
42 ``tree_duplicate_loop_body_to_header_edge`` : These functions (on RTL and
43 on GIMPLE) duplicate the body of the loop prescribed number of times on
44 one of the edges entering loop header, thus performing either loop
45 unrolling or loop peeling. ``can_duplicate_loop_p``
46 (``can_unroll_loop_p`` on GIMPLE) must be true for the duplicated
47 loop.
48
49 * ``loop_version`` : This function creates a copy of a loop, and
50 a branch before them that selects one of them depending on the
51 prescribed condition. This is useful for optimizations that need to
52 verify some assumptions in runtime (one of the copies of the loop is
53 usually left unchanged, while the other one is transformed in some way).
54
55 * ``tree_unroll_loop`` : Unrolls the loop, including peeling the
56 extra iterations to make the number of iterations divisible by unroll
57 factor, updating the exit condition, and removing the exits that now
58 cannot be taken. Works only on GIMPLE.