SlideShare a Scribd company logo
1 of 16
Compiler Optimization
Speaker :呂宗螢
Adviser :梁文耀 老師
Date : 2006/10/11
Embedded and Parallel Systems Lab2
The Structure of Recent
Front end per
language
High-level
optimizations
Global optimizer
Code generator
Intermediate
representation
Dependencies Function
Language Dependent machine
independent
Transform language to
common intermediate form
Largely machine independent For example, procedure
inlineing (also called
procedure intergration)
Small language dependencies
machine dependencies slight
(e.g., register count/types)
Including global and local
optimizations + register
allocation
Highly machine dependent
Language independent
Detailed instruction selection
and machine-dependent
optimizations
May include or be followed
by assembler
Embedded and Parallel Systems Lab3
Major types of optimizations
Embedded and Parallel Systems Lab4
Procedure integration
 Replace procedure call by procedure body
Int a;
void up(){
a=a+1;
}
Void main(){
a=10;
up();
b=a+5;
}
Int a;
Void main(){
a=10;
a=a+1;
b=a+5;
}
Embedded and Parallel Systems Lab5
Common subexpression elimination
 Replace two instances of same
computation by single copy
a = b * c + g;
d = b * c * d;
tmp = b * c;
a = tmp + g;
d = tmp * d;
Embedded and Parallel Systems Lab6
Constant propagation
 Replace all instances of a variable that is
assigned a constant with the constant
int x = 14;
int y = 7 - x / 2;
return y * (28 / x + 2);
int x = 14;
int y = 7 - 14 / 2;
return y * (28 / 14 +
2);
int x = 14;
int y = 0;
return y * 4;
Embedded and Parallel Systems Lab7
Stack height reduction
 Rearrange expression tree to minimize resources needed for
expression evaluation
ADD R6,R2,R3
ADD R7,R6,R4
ADD R8,R7,R5
ADD R6,R2,R3
ADD R7,R4,R5
ADD R8,R7,R6
I1
I2
I3
I1 I2
I3
R8=((R2+R3)+R4)+R5 R8=(R2+R3)+(R4+R5)
Embedded and Parallel Systems Lab8
Copy propagation
 Replace all instances of a variable A that
has been assigned X (i.e., A = X) with X
y = x ;
z = 3 + y;
z = 3 + x
Embedded and Parallel Systems Lab9
Code motion
 Remove code from a loop that computes
same value each iteration of the loop
 Loop-invariant code
while (j < maximum - 1) {
x=1;
j = j + 4 * a;
}
int maxval = maximum - 1;
int calcval = 4 * a;
x=1;
while (j < maxval) {
j = j + calcval;
}
Embedded and Parallel Systems Lab10
Induction variable elimination
 Simplify / eliminate array addressing
calculations within loops
Int i=0;
while( i<10){
i=i+1;
p = 4*i ;
do some things;
}
Int p=0;
while( p<40){
p=p+4;
do some things;
}
Embedded and Parallel Systems Lab11
Strength reduction
 Such as , replace multiply by constant
with adds and shifts
for (i=0 ; i<n ; i++){
z = i * x;
do some things;
}
for (i=0 ; i<n ; i++){
z = z + x;
do some things;
}
Embedded and Parallel Systems Lab12
Branch offset optimization
 Choose the shortest branch displacement
that reaches target
if( a ){
statement 1
}
else {
goto L1;
}
statement 2
L1:
statement 3
if( !a ){
goto L1;
}
statement 1
statement 2
L1:
statement 3
Embedded and Parallel Systems Lab13
dead (unreachable) code elimination
 Remove instructions that will not affect the
behavior of the program.
Int func( int a){
int b, c;
b=a*2;
c=a*3;
return b;
}
Int func( int a){
int b, c;
b=a*2;
return b;
}
Embedded and Parallel Systems Lab14
Boolean Expression
If( a=0 || b=0 || c=0) {
statement 1;
}
If( a=0) {
statement 1;
}else if( b=0){
statement 1;
}else if( c=0){
statement 1;
}
Embedded and Parallel Systems Lab15
Loop unrolling
int i;
for (i = 0; i < 5; i++){
function(i);
}
function(0);
function(1);
function(2);
function(3);
function(4);
 Duplicates the body of the loop multiple times, in order to decrease
the number of times the loop condition is tested and the number of
jumps, which hurt performance by impairing the instruction pipeline
Embedded and Parallel Systems Lab16
 Thanks

More Related Content

What's hot (20)

Object Oriented Programming Languages
Object Oriented Programming LanguagesObject Oriented Programming Languages
Object Oriented Programming Languages
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
stack & queue
stack & queuestack & queue
stack & queue
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
 
OOP java
OOP javaOOP java
OOP java
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
class and objects
class and objectsclass and objects
class and objects
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 

Viewers also liked (18)

Engranajes fotos
Engranajes fotosEngranajes fotos
Engranajes fotos
 
Fiqih icha
Fiqih ichaFiqih icha
Fiqih icha
 
Tik allisya smpit rpi
Tik allisya smpit rpiTik allisya smpit rpi
Tik allisya smpit rpi
 
Creative & Digital Business Briefing - October 2016
Creative & Digital Business Briefing - October 2016Creative & Digital Business Briefing - October 2016
Creative & Digital Business Briefing - October 2016
 
Creative & Digital Business Briefing - November 2016
Creative & Digital Business Briefing - November 2016Creative & Digital Business Briefing - November 2016
Creative & Digital Business Briefing - November 2016
 
tentang menu toolbar pada microsoft word
tentang menu toolbar pada microsoft wordtentang menu toolbar pada microsoft word
tentang menu toolbar pada microsoft word
 
Programme on Ms Excel For Managerial Computing
Programme on Ms Excel For Managerial ComputingProgramme on Ms Excel For Managerial Computing
Programme on Ms Excel For Managerial Computing
 
An Opinion Without Support Is Not An Appraisal
An Opinion Without Support Is Not An AppraisalAn Opinion Without Support Is Not An Appraisal
An Opinion Without Support Is Not An Appraisal
 
Digital business briefing January 2015
Digital business briefing January 2015Digital business briefing January 2015
Digital business briefing January 2015
 
Health supervision policy for the workplace
Health supervision policy for the workplaceHealth supervision policy for the workplace
Health supervision policy for the workplace
 
Ramya mmwt
Ramya mmwtRamya mmwt
Ramya mmwt
 
English research report
English research reportEnglish research report
English research report
 
Three Post - Media Production Capabilities
Three Post - Media Production CapabilitiesThree Post - Media Production Capabilities
Three Post - Media Production Capabilities
 
Hukum newton gravitasi
Hukum newton gravitasiHukum newton gravitasi
Hukum newton gravitasi
 
Psy 1
Psy 1Psy 1
Psy 1
 
Fit notes and work
Fit notes and workFit notes and work
Fit notes and work
 
Epc slides (part1)
Epc slides (part1)Epc slides (part1)
Epc slides (part1)
 
Life insurance after retirement
Life insurance after retirementLife insurance after retirement
Life insurance after retirement
 

Similar to Compiler optimization

Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languagesAnkit Pandey
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCAFxX
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++msharshitha03s
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Jorisimec.archive
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12Andrew Dunstan
 
control statements
control statementscontrol statements
control statementsAzeem Sultan
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++NUST Stuff
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Hermann Hueck
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)SURBHI SAROHA
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython ScriptingAlithya
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set ArchitectureDilum Bandara
 

Similar to Compiler optimization (20)

Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12
 
control statements
control statementscontrol statements
control statements
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Matopt
MatoptMatopt
Matopt
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
Code Tuning
Code TuningCode Tuning
Code Tuning
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
LLVM
LLVMLLVM
LLVM
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython Scripting
 
Thinking in Functions
Thinking in FunctionsThinking in Functions
Thinking in Functions
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
 

More from ZongYing Lyu

Performance improvement techniques for software distributed shared memory
Performance improvement techniques for software distributed shared memoryPerformance improvement techniques for software distributed shared memory
Performance improvement techniques for software distributed shared memoryZongYing Lyu
 
Architecture of the oasis mobile shared virtual memory system
Architecture of the oasis mobile shared virtual memory systemArchitecture of the oasis mobile shared virtual memory system
Architecture of the oasis mobile shared virtual memory systemZongYing Lyu
 
A deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorA deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorZongYing Lyu
 
Libckpt transparent checkpointing under unix
Libckpt transparent checkpointing under unixLibckpt transparent checkpointing under unix
Libckpt transparent checkpointing under unixZongYing Lyu
 
Device Driver - Chapter 6字元驅動程式的進階作業
Device Driver - Chapter 6字元驅動程式的進階作業Device Driver - Chapter 6字元驅動程式的進階作業
Device Driver - Chapter 6字元驅動程式的進階作業ZongYing Lyu
 
Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式ZongYing Lyu
 
Web coding principle
Web coding principleWeb coding principle
Web coding principleZongYing Lyu
 
提高 Code 品質心得
提高 Code 品質心得提高 Code 品質心得
提高 Code 品質心得ZongYing Lyu
 
Consistency protocols
Consistency protocolsConsistency protocols
Consistency protocolsZongYing Lyu
 
MPI use c language
MPI use c languageMPI use c language
MPI use c languageZongYing Lyu
 
Parallel program design
Parallel program designParallel program design
Parallel program designZongYing Lyu
 

More from ZongYing Lyu (16)

Vue.js
Vue.jsVue.js
Vue.js
 
Performance improvement techniques for software distributed shared memory
Performance improvement techniques for software distributed shared memoryPerformance improvement techniques for software distributed shared memory
Performance improvement techniques for software distributed shared memory
 
Architecture of the oasis mobile shared virtual memory system
Architecture of the oasis mobile shared virtual memory systemArchitecture of the oasis mobile shared virtual memory system
Architecture of the oasis mobile shared virtual memory system
 
A deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorA deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processor
 
Libckpt transparent checkpointing under unix
Libckpt transparent checkpointing under unixLibckpt transparent checkpointing under unix
Libckpt transparent checkpointing under unix
 
Device Driver - Chapter 6字元驅動程式的進階作業
Device Driver - Chapter 6字元驅動程式的進階作業Device Driver - Chapter 6字元驅動程式的進階作業
Device Driver - Chapter 6字元驅動程式的進階作業
 
Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式
 
Web coding principle
Web coding principleWeb coding principle
Web coding principle
 
提高 Code 品質心得
提高 Code 品質心得提高 Code 品質心得
提高 Code 品質心得
 
SCRUM
SCRUMSCRUM
SCRUM
 
Consistency protocols
Consistency protocolsConsistency protocols
Consistency protocols
 
MPI use c language
MPI use c languageMPI use c language
MPI use c language
 
Cvs
CvsCvs
Cvs
 
Parallel program design
Parallel program designParallel program design
Parallel program design
 
MPI
MPIMPI
MPI
 
OpenMP
OpenMPOpenMP
OpenMP
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Compiler optimization

  • 1. Compiler Optimization Speaker :呂宗螢 Adviser :梁文耀 老師 Date : 2006/10/11
  • 2. Embedded and Parallel Systems Lab2 The Structure of Recent Front end per language High-level optimizations Global optimizer Code generator Intermediate representation Dependencies Function Language Dependent machine independent Transform language to common intermediate form Largely machine independent For example, procedure inlineing (also called procedure intergration) Small language dependencies machine dependencies slight (e.g., register count/types) Including global and local optimizations + register allocation Highly machine dependent Language independent Detailed instruction selection and machine-dependent optimizations May include or be followed by assembler
  • 3. Embedded and Parallel Systems Lab3 Major types of optimizations
  • 4. Embedded and Parallel Systems Lab4 Procedure integration  Replace procedure call by procedure body Int a; void up(){ a=a+1; } Void main(){ a=10; up(); b=a+5; } Int a; Void main(){ a=10; a=a+1; b=a+5; }
  • 5. Embedded and Parallel Systems Lab5 Common subexpression elimination  Replace two instances of same computation by single copy a = b * c + g; d = b * c * d; tmp = b * c; a = tmp + g; d = tmp * d;
  • 6. Embedded and Parallel Systems Lab6 Constant propagation  Replace all instances of a variable that is assigned a constant with the constant int x = 14; int y = 7 - x / 2; return y * (28 / x + 2); int x = 14; int y = 7 - 14 / 2; return y * (28 / 14 + 2); int x = 14; int y = 0; return y * 4;
  • 7. Embedded and Parallel Systems Lab7 Stack height reduction  Rearrange expression tree to minimize resources needed for expression evaluation ADD R6,R2,R3 ADD R7,R6,R4 ADD R8,R7,R5 ADD R6,R2,R3 ADD R7,R4,R5 ADD R8,R7,R6 I1 I2 I3 I1 I2 I3 R8=((R2+R3)+R4)+R5 R8=(R2+R3)+(R4+R5)
  • 8. Embedded and Parallel Systems Lab8 Copy propagation  Replace all instances of a variable A that has been assigned X (i.e., A = X) with X y = x ; z = 3 + y; z = 3 + x
  • 9. Embedded and Parallel Systems Lab9 Code motion  Remove code from a loop that computes same value each iteration of the loop  Loop-invariant code while (j < maximum - 1) { x=1; j = j + 4 * a; } int maxval = maximum - 1; int calcval = 4 * a; x=1; while (j < maxval) { j = j + calcval; }
  • 10. Embedded and Parallel Systems Lab10 Induction variable elimination  Simplify / eliminate array addressing calculations within loops Int i=0; while( i<10){ i=i+1; p = 4*i ; do some things; } Int p=0; while( p<40){ p=p+4; do some things; }
  • 11. Embedded and Parallel Systems Lab11 Strength reduction  Such as , replace multiply by constant with adds and shifts for (i=0 ; i<n ; i++){ z = i * x; do some things; } for (i=0 ; i<n ; i++){ z = z + x; do some things; }
  • 12. Embedded and Parallel Systems Lab12 Branch offset optimization  Choose the shortest branch displacement that reaches target if( a ){ statement 1 } else { goto L1; } statement 2 L1: statement 3 if( !a ){ goto L1; } statement 1 statement 2 L1: statement 3
  • 13. Embedded and Parallel Systems Lab13 dead (unreachable) code elimination  Remove instructions that will not affect the behavior of the program. Int func( int a){ int b, c; b=a*2; c=a*3; return b; } Int func( int a){ int b, c; b=a*2; return b; }
  • 14. Embedded and Parallel Systems Lab14 Boolean Expression If( a=0 || b=0 || c=0) { statement 1; } If( a=0) { statement 1; }else if( b=0){ statement 1; }else if( c=0){ statement 1; }
  • 15. Embedded and Parallel Systems Lab15 Loop unrolling int i; for (i = 0; i < 5; i++){ function(i); } function(0); function(1); function(2); function(3); function(4);  Duplicates the body of the loop multiple times, in order to decrease the number of times the loop condition is tested and the number of jumps, which hurt performance by impairing the instruction pipeline
  • 16. Embedded and Parallel Systems Lab16  Thanks