TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Machine Independent

Machine Independent with introduction, Phases, Passes, Bootstrapping, Optimization of DFA, Finite State machine, Formal Grammar, BNF Notation, YACC, Derivation, Parse Tree, Ambiguity, Syntax directed Translation, slr 1 parsing etc.

<< Back to MACHINE

Machine-Independent Optimization

  • Machine independent optimization attempts to improve the intermediate code to get a better target code. The part of the code which is transformed here does not involve any absolute memory location or any CPU registers.
  • The process of intermediate code generation introduces much inefficiency like: using variable instead of constants, extra copies of variable, repeated evaluation of expression. Through the code optimization, you can remove such efficiencies and improves code.
  • It can change the structure of program sometimes of beyond recognition like: unrolls loops, inline functions, eliminates some variables that are programmer defined.

Code Optimization can perform in the following different ways:

(1) Compile Time Evaluation:

(a) z = 5*(45.0/5.0)*r
     Perform 5*(45.0/5.0)*r at compile time.

(b) x = 5.7
     y = x/3.6
    Evaluate x/3.6 as 5.7/3.6 at compile time.

(2) Variable Propagation:

Before Optimization the code is:

c = a * b                                              
x = a                                                 
till                                                          
d = x * b + 4 

After Optimization the code is:

c = a * b  
x = a
till
	d = a * b + 4

Here, after variable propagation a*b and x*b identified as common sub expression.

(3) Dead code elimination:

Before elimination the code is:

c = a * b                                                
x = b                                               
till                                                        
d = a * b + 4  

After elimination the code is:

c = a * b
till
d = a * b + 4

Here, x= b is a dead state because it will never subsequently used in the program. So, we can eliminate this state.

(4) Code Motion:

  • It reduces the evaluation frequency of expression.
  • It brings loop invariant statements out of the loop.
do
{
   item = 10;
   value = value + item; 
} while(value<100);
 
 
//This code can be further optimized as

item = 10;
do
{
   value = value + item; 
} while(value<100);

(5) Induction Variable and Strength Reduction:

  • Strength reduction is used to replace the high strength operator by the low strength.
  • An induction variable is used in loop for the following kind of assignment like i = i + constant.

Before reduction the code is:

i = 1;                                                  
while(i<10)                                              
{                                                      
    y = i * 4; 
}

After Reduction the code is:

i = 1
t = 4
{ 
   while( t<40) 
  y = t; 
  t = t + 4;
}

Next TopicLoop optimization




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf