Prerequisite – Compiler Design | Code Optimization
Frequency reduction is a type in loop optimization process which is machine independent. In frequency reduction code inside a loop is optimized to improve the running time of program. Frequency reduction is used to decrease the amount of code in a loop. A statement or expression, which can be moved outside the loop body without affecting the semantics of the program, is moved outside the loop. Frequency Reduction is also called Code Motion.
Objective of Frequency Reduction:
The objective of frequency reduction is:
- To reduce the evaluation frequency of expression.
- To bring loop invariant statements out of the loop.
Below is the example of Frequency Reduction:
17 17 17 17 17
Program 2 is more efficient than Program 1 as in Program 1 the value of c is calculated each time the while loop is executed. Hence the value of c is calculated outside the loop only once and it reduces the amount of code in the loop.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Need for Intermediate Code and Code Optimization
- Code Optimization in Compiler Design
- Loop Optimization Techniques | Set 2
- Peephole Optimization in Compiler Design
- Loop Optimization in Compiler Design
- Lex program to count the frequency of the given word in a file
- Three address code in Compiler
- Issues in the design of a code generator
- DFA in LEX code which accepts strings ending with 11
- Intermediate Code Generation in Compiler Design
- Introduction of Object Code in Compiler Design
- Lex code to count total number of tokens
- Compiler Design | Detection of a Loop in Three Address Code
- Lex code to replace a word with another word in a file
- DFA in LEX code which accepts Odd number of 0’s and even number of 1’s
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.