The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we help you to solve your academic and programming questions fast.
In eduladder you can Ask,Answer,Listen,Earn and Download Questions and Question papers.
Watch related videos of your favorite subject.
Connect with students from different parts of the world.
Apply or Post Jobs, Courses ,Internships and Volunteering opportunity. For FREE
See Our team
Wondering how we keep quality?
Got unsolved questions? Ask Questions

UNIX-SYSTEMS-PROGRAMMING-AND-COMPILER-DESIGN-LABORATORY-10CSL68--->View question


Asked On2017-12-19 15:49:23 by:leo

Taged users:
BrianSanket-Khatal

Likes:
Be first to like this question

Dislikes:
Be first to dislike this question
Talk about this  Like  Dislike
View all qusetions
Answers
                      
Optimization
Optimization is a program transformation technique, which tries to improve the code by making it consume less resources (i.e. CPU, Memory) and deliver high speed.
In optimization, high-level general programming constructs are replaced by very efficient low-level programming codes.
A code optimizing process must follow the three rules given below:
The output code must not, in any way, change the meaning of the program.
Optimization should increase the speed of the program and if possible, the program should demand less number of resources.
Optimization should itself be fast and should not delay the overall compiling process.
Efforts for an optimized code can be made at various levels of compiling the process.
At the beginning, users can change/rearrange the code or use better algorithms to write the code.
After generating intermediate code, the compiler can modify the intermediate code by address calculations and improving loops.
While producing the target machine code, the compiler can make use of memory hierarchy and CPU registers.
Optimization can be categorized broadly into two types:
Machine Independent and Machine Dependent.


Function Preserving                                      Loop Optimization
• Common subexpression Elimination         1. Code motion
• Constant Folding                                        2. Strength Reduction
• Copy Propagation                                       3. Frequency Reduction
• Dead code Elimination                                4. Loop distribution
Loop Optimization
We are going to perform optimization on loops.
Code Motion
It specifies on a condition if we perform some operations to be carried out and then compare for a condition.
Instead of that perform the calculation outside the loop and assign a value in the calculation.

Code motion (also called code hoisting) unifies sequences of code common to one or more basic blocks to reduce code size and potentially avoid expensive re-evaluation.
The most common form of code motion is loop-invariant code motion that moves statements that evaluate to the same value every iteration of the loop to somewhere outside the loop.
What statements inside the following TAC code can be moved outside the loop body?


We have an intuition of what makes a loop in a flow graph, but here is a more formal definition. A loop is a set of basic blocks which satisfies two conditions:
All are strongly connected, i.e. there is a path between any two blocks.
The set has a unique entry point, i.e. every path from outside the loop that reaches any block inside the loop enters through a single node. A block n dominates m if all paths from the starting block to m must travel through n. Every block dominates itself.
For loop L, moving invariant statement s in block B which defines variable v outside the loop is a safe optimization if:
B dominates all exits from L
No other statement assigns a value to v
All uses of v inside L are from the definition in s.
Loop invariant code can be moved to just above the entry point to the loop.


Answerd on:2018-06-06 Answerd By:aksingh1818

Likes:
|aksingh1818

Dislikes:
Be first to dislike this answer
Talk about this  Like  Dislike

Stay home and watch eduladder premium videos for free In at this qurentine.


You might like this video:Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here



Lets together make the web is a better place

We made eduladder by keeping the ideology of building a supermarket of all the educational material available under one roof. We are doing it with the help of individual contributors like you, interns and employees. So the resources you are looking for can be easily available and accessible also with the freedom of remix reuse and reshare our content under the terms of creative commons license with attribution required close.

You can also contribute to our vision of "Helping student to pass any exams" with these.
Answer a question: You can answer the questions not yet answered in eduladder.How to answer a question
Career: Work or do your internship with us.Work with us
Create a video: You can teach anything and everything each video should be less than five minutes should cover the idea less than five min.How to upload a video on eduladder