Control-Flow Analysis
COP-5621, Spring 2024
Table of Contents
Review
Questions about the last class?
Questions about project setup
Homework discussion
What is a Control-Flow Graph (CFG)?
Why Would We Need a CFG?
Elements of a CFG
Examples
Conditional statements
Loops
An algorithm for CFG construction
- Create entry and exit nodes (used for optimization later)
- Collect the leaders of the basic blocks, i.e., each line that starts a basic block, and creating a new node for each
- create edges between basic blocks, looking at each basic block's ending goto/ifgoto and create an edge to the target leader
How do we know when something is a leader, i.e., the first line of a basic block?
- First line of the program
- Target of a goto/ifgoto
- Line after a goto/ifgoto