0% found this document useful (0 votes)
7 views7 pages

Understanding Basic Blocks in Compilers

The document discusses basic blocks in compiler design. It defines what a basic block is and provides an example of partitioning code into basic blocks. It also shows the three address code and corresponding basic blocks for a dot product example.

Uploaded by

rajch14587
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Understanding Basic Blocks in Compilers

The document discusses basic blocks in compiler design. It defines what a basic block is and provides an example of partitioning code into basic blocks. It also shows the three address code and corresponding basic blocks for a dot product example.

Uploaded by

rajch14587
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

12/10/22, 10:08 AM Basic Block - javatpoint

Home Compiler Data Structure C C++ C# Java SQL HTML CSS JavaScript

Bengaluru to New Delhi

from Rs6,650 Info


*

[Link] 1/7
12/10/22, 10:08 AM Basic Block - javatpoint

Basic Block
Basic block contains a sequence of statement. The flow of control enters at the beginning of the
statement and leave at the end without any halt (except may be the last instruction of the block).

The following sequence of three address statements forms a basic block:

t1:= x * x
t2:= x * y
t3:= 2 * t2
t4:= t1 + t3
t5:= y * y
t6:= t4 + t5

Basic block construction:


Algorithm: Partition into basic blocks

Input: It contains the sequence of three address statements

Output: it contains a list of basic blocks with each three address statement in exactly one block

Method: First identify the leader in the code. The rules for finding leaders are as follows:

The first statement is a leader.

Statement L is a leader if there is an conditional or unconditional goto statement like: if....goto


L or goto L

Instruction L is a leader if it immediately follows a goto or conditional goto statement like: if


goto B or goto B

[Link] 2/7
12/10/22, 10:08 AM Basic Block - javatpoint

For each leader, its basic block consists of the leader and all statement up to. It doesn't include the
next leader or end of the program.

Consider the following source code for dot product of two vectors a and b of length 10:

begin
prod :=0;
i:=1;
do begin
prod :=prod+ a[i] * b[i];
i :=i+1;
end
while i <= 10
end

The three address code for the above source program is given below:

B1

(1) prod := 0
(2) i := 1

B2

(3) t1 := 4* i
(4) t2 := a[t1]
(5) t3 := 4* i
(6) t4 := b[t3]
(7) t5 := t2*t4
(8) t6 := prod+t5
(9) prod := t6
(10) t7 := i+1
(11) i := t7
(12) if i<=10 goto (3)

Basic block B1 contains the statement (1) to (2)

[Link] 3/7
12/10/22, 10:08 AM Basic Block - javatpoint

Basic block B2 contains the statement (3) to (12)

← Prev Next →

With Love For Adam


& Cartier - Watch…
Zee Zest

Youtube For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to feedback@[Link]

Help Others, Please Share

[Link] 4/7
12/10/22, 10:08 AM Basic Block - javatpoint

Learn Latest Tutorials

Splunk tutorial SPSS tutorial Swagger T-SQL tutorial


tutorial
Splunk SPSS Transact-SQL
Swagger

Tumblr tutorial React tutorial Regex tutorial Reinforcement


learning tutorial
Tumblr ReactJS Regex
Reinforcement
Learning

R Programming RxJS tutorial React Native Python Design


tutorial tutorial Patterns
RxJS
R Programming React Native Python Design
Patterns

Python Pillow Python Turtle Keras tutorial


tutorial tutorial
Keras
Python Pillow Python Turtle

Preparation

Aptitude Logical Verbal Ability Interview


Reasoning Questions
Aptitude Verbal Ability
Reasoning Interview Questions
[Link] 5/7
12/10/22, 10:08 AM Basic Block - javatpoint

Company
Interview
Questions
Company Questions

Trending Technologies

Artificial AWS Tutorial Selenium Cloud


Intelligence tutorial Computing
AWS
Tutorial tutorial
Selenium
Artificial Cloud Computing
Intelligence

Hadoop tutorial ReactJS Data Science Angular 7


Tutorial Tutorial Tutorial
Hadoop
ReactJS Data Science Angular 7

Blockchain Git Tutorial Machine DevOps


Tutorial Learning Tutorial Tutorial
Git
Blockchain Machine Learning DevOps

[Link] / MCA

DBMS tutorial Data Structures DAA tutorial Operating


tutorial System tutorial
DBMS DAA
Data Structures Operating System

Computer Compiler Computer Discrete


Network tutorial Design tutorial Organization and Mathematics
Architecture Tutorial
Computer Discrete
Organization Mathematics
[Link] 6/7
12/10/22, 10:08 AM Basic Block - javatpoint

Computer Network Compiler Design

Ethical Hacking Computer Software html tutorial


Tutorial Graphics Tutorial Engineering
Web Technology
Tutorial
Ethical Hacking Computer Graphics
Software
Engineering

Cyber Security Automata C Language C++ tutorial


tutorial Tutorial tutorial
C++
Cyber Security Automata C Programming

Java tutorial .Net Python tutorial List of


Framework Programs
Java Python
tutorial
Programs
.Net

Control Data Mining Data


Systems tutorial Tutorial Warehouse
Tutorial
Control System Data Mining
Data Warehouse

Sponsored

Kolhapur - City of Wrestlers - Watch


Full Episode
Zee Zest

[Link] 7/7

Common questions

Powered by AI

Memory allocation and management in object-oriented languages is handled through concepts such as heap memory allocation, and automatic garbage collection. These languages often provide abstractions for dynamic memory management, enabling complex data structures like objects to be handled efficiently. While the document does not delve deeply into OOP-specific memory management, it provides foundational understanding through general concepts applicable across many programming languages .

Three address statements form the basis for constructing basic blocks, as they represent the code in a more refined and manageable format suitable for compiler optimizations. Each statement in the sequence generally involves three operations: two operand retrievals and one operation execution, typically resulting in a temporary variable. The simplified form is easy to analyze for dependencies and flow control, making it foundational to forming basic blocks for further optimization processes .

A basic block is a sequence of consecutive statements in a program where control enters at the beginning and leaves at the end without any possibility of branching, except possibly at the end of the block. The entire block executes sequentially once entered. This structure is important because it provides a framework for optimizations within compilers .

Resources for learning data structures include tutorials and documentation on various programming languages like C, C++, Java, and Python, available on platforms such as javatpoint. These resources often provide a comprehensive guide covering the basics to advanced topics, including specific algorithms and data structures like arrays, linked lists, stacks, and queues .

The three address code representation allows for a straightforward linear sequence of instructions, making it easier to analyze and modify during compiler optimizations. By breaking down complex expressions into simpler ones, it permits detailed tracking of variable changes and dependencies, fostering optimizations like constant folding, strength reduction, and moving invariant code. This granular approach facilitates precise locality of transformations within basic blocks .

A simple arithmetic operation like (a + b) * (c - d) is transformed into a series of three address statements such as: t1 = a + b, t2 = c - d, and t3 = t1 * t2. Each statement involves up to three operands and can be represented as a node within a basic block. These instructions provide clear points of operation and result storage, facilitating optimization by allowing the compiler to easily track dependencies and results of these operations within a basic block .

Leaders play a critical role in partitioning code into basic blocks as they determine where a new basic block begins. The rules for identifying leaders include marking the first statement as a leader, any statement that is a target of a goto statement, and any statement immediately following a goto or conditional goto. Once leaders are identified, each leader starts a new basic block which includes all subsequent statements until the next leader or the end of the program. This partitioning helps in optimizing the code during compilation .

A loop structure is translated into basic blocks by identifying leaders and partitioning the loop into a series of blocks, starting from the loop initialization through to the exit condition. The loop's conditional statements play a role by defining the points where control may branch back to the start of the loop or exit, thus creating a flow between blocks. This is evident where a conditional check leads to a goto statement, identifying leaders, and forming boundaries for each basic block .

The control flow properties of a basic block are pivotal in compiler optimizations because they allow for the assumption that if a basic block is entered, all its statements will execute sequentially. This assumption simplifies the analysis of control flow, making data flow analysis, dependency resolution, and transformations such as dead code elimination or loop unrolling more straightforward. Optimizations can be localized within these blocks as they ensure no interference from jumps or branches, maximizing the efficiency of compiled code .

Identifying the initial leader is crucial because it marks the entry point of a basic block, setting the boundaries for code optimizations within that block. This identification impacts subsequent code execution by defining the scope where certain assumptions about control flow can be safely made, such as predictability and non-interference from outside code. Proper leader identification ensures that optimizations preserve the logical correctness and performance enhancements across the compiled program .

You might also like