Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Code Optimization in Compiler Design

Code optimization is a program modification strategy that endeavours to enhance the intermediate code, so a program utilises the least potential memory, minimises its CPU time and offers high speed.

Code Optimization in compiler

Table of Contents

Reasons for Optimizing the Code

  • Code optimization is essential to enhance the execution and efficiency of a source code.
  • It is mandatory to deliver efficient target code by lowering the number of instructions in a program.

When to Optimize?

Code optimization is an important step that is usually performed at the last stage of development.

Role of Code Optimization

  • It is the fifth stage of a compiler, and it allows you to choose whether or not to optimize your code, making it really optional.
  • It aids in reducing the storage space and increases compilation speed.
  • It takes source code as input and attempts to produce optimal code.
  • Functioning the optimization is tedious; it is preferable to employ a code optimizer to accomplish the assignment.

Different Types of Optimization

Optimization is classified broadly into two types:

  • Machine-Independent
  • Machine-Dependent

Video on Code Optimization

Machine-Independent Optimization

It positively affects the efficiency of intermediate code by transforming a part of code that does not employ hardware parts. It usually optimises code by eliminating tediums and removing unneeded code.

do

{

item = 10;

amount= amount + item;

} while(amount<100);

This code implicates the replicated assignment of the identifier item if we put it this way:

item = 10;

do

{

amount= amount + item;

} while(amount<100);

Machine-Independent Optimization Techniques:

  • Compile Time Evaluation
  • Common Subexpression Elimination
  • Variable Propagation
  • Dead Code Elimination
  • Code Movement
  • Strength Reduction

Code Optimization

Machine-Dependent Optimization

After the target code has been constructed and transformed according to the target machine architecture, machine-dependent optimization is performed. It makes use of CPU registers and may utilise absolute rather than relative memory addresses. Machine-dependent optimizers work hard to maximise the perks of the memory hierarchy.

Keep learning and stay tuned to get the latest updates on the GATE Exam along with GATE MCQsGATE Eligibility CriteriaGATE Syllabus for CSE (Computer Science Engineering)GATE Notes for CSEGATE CSE Question Paper, and more.

Also Explore,