Courses

# Introduction to Code Optimization Computer Science Engineering (CSE) Notes | EduRev

## Computer Science Engineering (CSE) : Introduction to Code Optimization Computer Science Engineering (CSE) Notes | EduRev

The document Introduction to Code Optimization Computer Science Engineering (CSE) Notes | EduRev 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)

1.  INTRODUCTION

• The code produced by the straight forward compiling algorithms can often be made to run faster or take less space, or both. This improvement is achieved by program transformations that are traditionally called optimizations. Compilers that apply code-improving transformations are called optimizing compilers.
• Optimizations are classified into two categories. They are
• Machine independent optimizations:
• Machine dependant optimizations:

1.1 Machine independent optimizations:
Machine independent optimizations are program transformations that improve the target code without taking into consideration any properties of the target machine.

1.2 Machine dependant optimizations:
Machine dependant optimizations are based on register allocation and utilization of special machine- instruction sequences.

1.3 The criteria for code improvement transformations:

• Simply stated, the best program transformations are those that yield the most benefit for the least effort.
• The transformation must preserve the meaning of programs. That is, the optimization must not change the output produced by a program for a given input, or cause an error such as division by zero, that was not present in the original source program. At all times we take the “safe” approach of missing an opportunity to apply a transformation rather than risk changing what the program does.
• A transformation must, on the average, speed up programs by a measurable amount. We are also interested in reducing the size of the compiled code although the size of the code has less importance than it once had. Not every transformation succeeds in improving every program, occasionally an “optimization” may slow down a program slightly.
• The transformation must be worth the effort. It does not make sense for a compiler writer  to expend the intellectual effort to implement a code improving transformation and to have the compiler expend the additional time compiling source programs if this effort is not repaid when the target programs are executed. “Peephole” transformations of this kind are simple enough and beneficial enough to be included in any compiler.

•  Flow analysis is a fundamental prerequisite for many important types of code improvement. · Generally control flow analysis precedes data flow analysis.
•  Control flow analysis (CFA) represents flow of control usually in form of graphs, CFA constructs such as
• A transformation of a program is called local if it can be performed by looking only at the statements in a basic block; otherwise, it is called global.
•  Many transformations can be performed at both the local and global levels. Local transformations are usually performed first.

Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!

## Compiler Design

16 videos|44 docs|29 tests

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

;