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

Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in CSyed Mustafa
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In JavaMD SALEEM QAISAR
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine DiagramNiloy Rocker
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Gaditek
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEMMansi Tyagi
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
8085 branching instruction
8085 branching instruction8085 branching instruction
8085 branching instructionprashant1271
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C ProgrammingHimanshu Negi
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 

What's hot (20)

Java packages
Java packagesJava packages
Java packages
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In Java
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Recursion
RecursionRecursion
Recursion
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine Diagram
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
8085 branching instruction
8085 branching instruction8085 branching instruction
8085 branching instruction
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Looping statement
Looping statementLooping statement
Looping statement
 
Memory mapping
Memory mappingMemory mapping
Memory mapping
 
Loops in C
Loops in CLoops in C
Loops in C
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 

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

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Recently uploaded (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

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