Optimization of Basic Blocks | Compiler Design - Computer Science Engineering (CSE) PDF Download

3.  OPTIMIZATION OF BASIC BLOCKS

Optimization of Basic Blocks | Compiler Design - Computer Science Engineering (CSE)
 

There are two types of basic block optimizations.
They are :
Structure -Preserving Transformations
Algebraic Transformations

 

.1 Structure- Preserving Transformations:

The primary Structure-Preserving Transformation on basic blocks are: � Common sub-expression elimination  

  • Dead code elimination 
  • Renaming of temporary variables 
  • Interchange of two independent adjacent statements.  

3.2 Common sub-expression elimination: 

Common sub expressions need not be computed over and over again. Instead they can be computed once and kept in store from where it’s referenced when encountered again – of course providing the variable values in the expression still remain constant.
 

Example:
a: =b+c
b: =a-d
c: =b+c
d: =a-d 

The 2nd and 4th statements compute the same expression: b+c and a-d

Basic block can be transformed to
a: =b+c
b: =a-d
c: =a
d: =b 
 

3.3 Dead code elimination: 

It’s possible that a large amount of dead (useless) code may exist in the program. This might be especially caused when introducing variables and procedures as part of construction or error -correction of a program – once declared and defined, one forgets to remove them in case they serve no purpose. Eliminating these will definitely optimize the code. 3.4 Renaming of temporary variables: 

  •  A statement t:=b+c where t is a temporary name can be changed to u:=b+c where u is another temporary name, and change all uses of t to u.  
     
  •   In this we can transform a basic block to its equivalent block called normal-form block. 
     

3.5 Interchange of two independent adjacent statements:

Two statements
t1:=b+c

t2:=x+y

can be interchanged or reordered in its computation in the basic block when value of t1 does not affect the value of t2.
 

3.6 Algebraic Transformations:

  • Algebraic identities represent another important class of optimizations on basic blocks. This includes simplifying expressions or replacing expensive operation by cheaper ones i.e. reduction in strength.  
     
  •   Another class of related optimizations is constant folding. Here we evaluate constant expressions at compile time and replace the constant expressions by their values. Thus the expression 2*3.14 would be replaced by 6.28.  
     
  •  The relational operators <=, >=, <, >, + and = sometimes generate unexpected common sub expressions.  
     
  •  Associative laws may also be applied to expose common sub expressions. For example, if the source code has the assignments  

a :=b+c e :=c+d+b

the following intermediate code may be generated:

a :=b+c t :=c+d

e :=t+b

  • The  compiler writer  should  examine  the  language carefully to  determine  what rearrangements of  computations  are  permitted;  since computer arithmetic  does  not always obey the algebraic identities of mathematics. Thus, a compiler may evaluate x*y-x*z as x*(y-z) but it may not evaluate a+(b-c) as (a+b)-c.



 

 

The document Optimization of Basic Blocks | Compiler Design - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Optimization of Basic Blocks - Compiler Design - Computer Science Engineering (CSE)

1. What is the concept of optimization of basic blocks in computer science engineering?
Ans. Optimization of basic blocks in computer science engineering refers to the process of improving the efficiency and performance of a program by analyzing and modifying the individual blocks of code. These blocks, known as basic blocks, are sequences of instructions that have a single entry point and a single exit point. By optimizing these basic blocks, the overall execution time of the program can be reduced, resulting in faster and more efficient code.
2. How can optimization of basic blocks benefit computer science engineering?
Ans. Optimization of basic blocks can benefit computer science engineering in several ways. Firstly, it can improve the overall performance of a program by reducing its execution time. This can result in faster and more responsive software, which is especially important in applications that require real-time processing. Additionally, optimization of basic blocks can help in reducing the memory footprint of a program, making it more efficient in terms of resource usage. Overall, optimization of basic blocks plays a crucial role in improving the efficiency and effectiveness of software systems.
3. What techniques are commonly used for optimizing basic blocks in computer science engineering?
Ans. There are several techniques commonly used for optimizing basic blocks in computer science engineering. Some of these techniques include: 1. Constant folding: This technique involves evaluating constant expressions at compile-time rather than runtime, reducing the number of instructions needed for execution. 2. Common subexpression elimination: This technique identifies and eliminates redundant computations by reusing the results of previously computed expressions. 3. Loop unrolling: Loop unrolling aims to reduce the overhead of loop control by duplicating loop bodies, allowing for better utilization of CPU resources and potentially improving performance. 4. Instruction scheduling: This technique reorders instructions within a basic block to reduce stalls and improve instruction-level parallelism. 5. Dead code elimination: This technique identifies and removes code that does not affect the program's output, reducing the overall execution time.
4. How does optimization of basic blocks impact the performance of a computer program?
Ans. Optimization of basic blocks can have a significant impact on the performance of a computer program. By analyzing and modifying the individual blocks of code, the execution time of the program can be reduced. This reduction in execution time leads to faster program execution, resulting in improved performance. Additionally, optimization of basic blocks can also help in reducing the memory usage of a program, improving its overall efficiency in terms of resource utilization. Overall, optimization of basic blocks plays a crucial role in enhancing the performance of computer programs.
5. Are there any limitations or trade-offs associated with the optimization of basic blocks in computer science engineering?
Ans. Yes, there are limitations and trade-offs associated with the optimization of basic blocks. Some optimizations may increase the code size, which can negatively impact the memory usage of the program. Additionally, certain aggressive optimizations may introduce new bugs or alter the behavior of the program, leading to unexpected results. It is important to carefully evaluate the potential benefits and drawbacks of each optimization technique before applying it to a program. Furthermore, the effectiveness of optimizations may vary depending on the specific program and its underlying architecture, so it is crucial to consider the trade-offs involved in order to achieve the desired balance between performance and other factors.
26 videos|66 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

practice quizzes

,

past year papers

,

pdf

,

Optimization of Basic Blocks | Compiler Design - Computer Science Engineering (CSE)

,

Optimization of Basic Blocks | Compiler Design - Computer Science Engineering (CSE)

,

Optimization of Basic Blocks | Compiler Design - Computer Science Engineering (CSE)

,

study material

,

Free

,

Important questions

,

mock tests for examination

,

MCQs

,

Sample Paper

,

Semester Notes

,

video lectures

,

shortcuts and tricks

,

Viva Questions

,

ppt

,

Summary

,

Objective type Questions

,

Previous Year Questions with Solutions

,

Exam

,

Extra Questions

;