Basic Blocks and Flow Graphs
-
Upload
jenny-galino -
Category
Software
-
view
129 -
download
0
Transcript of Basic Blocks and Flow Graphs
![Page 1: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/1.jpg)
BASIC BLOCKS AND FLOW GRAPHSJGALINO
![Page 2: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/2.jpg)
Construction of the
Representation
1. Partition the intermediate code into basic blocks
2. The basic blocks become the nodes of a flow graph
and the edges indicate the flow (which blocks
follow which)
![Page 3: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/3.jpg)
Basic Blocks*a piece of straight line code i.e. there are no jumps in or out of the middle of a block
1. the flow of control can only enter the basic
block through the first instruction
2. control will leave the block without halting or
branching, except possibly, at the last
instruction in the block
![Page 4: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/4.jpg)
Constructing Basic Blocks
1) Determine a set of leaders, the first
instruction of blocks2) A basic block consists of
a leader and all the following instructions until the next leader
![Page 5: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/5.jpg)
Constructing Basic Blocks
Determine a set of leaders
1) The first instruction is a leader
2) Instruction L is a leader if there is an instruction a or
a3) Instruction L is a leader if it
immediately follows an instruction
a or a
if … goto Lgoto
L
if … goto B
goto B
goto B
![Page 6: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/6.jpg)
Flow Graph
Once an intermediate-code program is partitioned into basic blocks, we represent
the flow of control between them by a flow graph.
![Page 7: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/7.jpg)
Constructing the Flow
GraphThere is an edge from block B to block C iff it is possible
for the first instruction in block C to immediately
follow the last instruction in block B
1. There is a conditional or unconditional jump from the end of B to the beginning of C
![Page 8: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/8.jpg)
Constructing the Flow
GraphThere is an edge from block B to block C iff it is possible
for the first instruction in block C to immediately
follow the last instruction in block B
2. C immediately follows B in the original order of the three-address instructions, and B does not end in an unconditional jump
![Page 9: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/9.jpg)
Constructing the Flow
GraphOften we add two nodes, called the entry and exit.
1. There is an edge from the entry to the first executable node.
![Page 10: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/10.jpg)
Constructing the Flow
GraphOften we add two nodes, called the entry and exit.
2. There is an edge to the exit from any basic block that contains an instruction that could bet eh last executed instruction of the program
![Page 11: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/11.jpg)
goto B
![Page 12: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/12.jpg)
goto B
![Page 13: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/13.jpg)
Loops
We say that a set of nodes L in a flow graph is a loop if
1. There is a node in L called the loop entry with the property that no other node in L has a predecessor outside L. That is , every path from the entry of the entire flow graph to any node in L goes through the loop entry.
![Page 14: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/14.jpg)
Loops
We say that a set of nodes L in a flow graph is a loop if
2. Every node in L has a nonempty path, completely within L, to the entry of L.
![Page 15: Basic Blocks and Flow Graphs](https://reader033.fdocuments.us/reader033/viewer/2022051501/5887aa3e1a28aba2088b6659/html5/thumbnails/15.jpg)
Fin