]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gccint/control-flow-graph.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / control-flow-graph.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:: CFG, Control Flow Graph, basic-block.h
7
8 .. _control-flow:
9
10 Control Flow Graph
11 ------------------
12
13 A control flow graph (CFG) is a data structure built on top of the
14 intermediate code representation (the RTL or ``GIMPLE`` instruction
15 stream) abstracting the control flow behavior of a function that is
16 being compiled. The CFG is a directed graph where the vertices
17 represent basic blocks and edges represent possible transfer of
18 control flow from one basic block to another. The data structures
19 used to represent the control flow graph are defined in
20 :samp:`basic-block.h`.
21
22 In GCC, the representation of control flow is maintained throughout
23 the compilation process, from constructing the CFG early in
24 ``pass_build_cfg`` to ``pass_free_cfg`` (see :samp:`passes.def`).
25 The CFG takes various different modes and may undergo extensive
26 manipulations, but the graph is always valid between its construction
27 and its release. This way, transfer of information such as data flow,
28 a measured profile, or the loop tree, can be propagated through the
29 passes pipeline, and even from ``GIMPLE`` to ``RTL``.
30
31 Often the CFG may be better viewed as integral part of instruction
32 chain, than structure built on the top of it. Updating the compiler's
33 intermediate representation for instructions cannot be easily done
34 without proper maintenance of the CFG simultaneously.
35
36 .. toctree::
37 :maxdepth: 2
38
39 control-flow-graph/basic-blocks
40 control-flow-graph/edges
41 control-flow-graph/profile-information
42 control-flow-graph/maintaining-the-cfg
43 control-flow-graph/liveness-information