Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Basic block
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Creation algorithm== The [[algorithm]] for generating basic blocks from a listing of code is simple: the analyser scans over the code, marking ''block boundaries'', which are instructions that may either begin or end a block because they either transfer control or accept control from another point. Then, the listing is simply "cut" at each of these points, and basic blocks remain. Note that this method does not always generate ''maximal'' basic blocks, by the formal definition, but they are usually sufficient (maximal basic blocks are basic blocks that cannot be extended by including adjacent blocks without violating the definition of a basic block<ref>Modern Compiler Design by Dick Grune, Henri E. Bal, Ceriel J. H. Jacobs, and Koen G. Langendoen, p. 320.</ref>). '''Input''': A sequence of instructions (mostly [[three-address code]]).<ref>Compiler Principles, Techniques and Tools, Aho Sethi Ullman.</ref> <br/> '''Output''': A list of basic blocks with each three-address instruction in exactly one block. # Identify the leaders in the code. Leaders are instructions that come under any of the following 3 categories: ## It is the first instruction. The first instruction is a leader. ## The target of a conditional or an unconditional goto/jump instruction is a leader. ## The instruction that immediately follows a conditional or an unconditional goto/jump instruction is a leader. # Starting from a leader, the set of all following instructions until and not including the next leader is the basic block corresponding to the starting leader. Thus every basic block has a leader. Instructions that end a basic block include the following: * unconditional and conditional [[branch (computer science)|branches]], both direct and indirect; * [[return statement|returns]] to a calling procedure; * instructions that may throw an [[exception handling|exception]]; * function calls can be at the end of a basic block if they can not return, such as functions that throw exceptions or special calls like [[C (programming language)|C]]'s [[Longjmp|<code>longjmp</code>]] and <code>exit</code>. Instructions that begin a new basic block include the following: * procedure and function entry points; * targets of jumps or branches; * "fall-through" instructions following some conditional branches; * instructions following ones that throw exceptions; * exception handlers. Note that, because control can never pass through the end of a basic block, some instructions may have to be modified to find the basic blocks. In particular, fall-through conditional branches must be changed to two-way branches, and function calls throwing exceptions must have unconditional jumps added after them. Doing these may require adding labels to the beginning of other blocks.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)