SlideShare uma empresa Scribd logo
1 de 15
Code Generation Part III Chapter 8 (1 st  ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009
Classic Examples of Local and Global Code Optimizations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Local: Constant Folding ,[object Object],[object Object],[object Object],[object Object],r7 = 4 + 1 r5 = 2 * r4 r6 = r5 * 2 src1(X) =  4 src2(X) =  1
Local: Constant Combining ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r7 = 5 r5 = 2 * r4 r6 = r5 * 2 r6 = r4 * 4
Local: Strength Reduction ,[object Object],[object Object],[object Object],[object Object],[object Object],r7 = 5 r5 = 2 * r4 r6 = r4 * 4 r6 = r4 << 2 r5 = r4 + r4
Local: Constant Propagation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r1 = 5 r2 = _x r3 = 7 r4 = r4 + r1 r1 = r1 + r2 r1 = r1 + 1 r3 = 12 r8 = r1 - r2 r9 = r3 + r5 r3 = r2 + 1 r7 = r3 - r1 M[r7] = 0 r4 = r4 + 5 r1 = 5 + _x r8 = 5 + _x + 1 - _x r9 = 12 + r5 r3 = _x + 1 r1 = 5 + _x + 1 r7 = _x + 1 - 5 - _x - 1
Local: Common Subexpression Elimination (CSE) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r1 = r2 + r3 r4 = r4 + 1 r1 = 6 r6 = r2 + r3 r2 = r1 - 1 r5 = r4 + 1 r7 = r2 + r3 r5 = r1 - 1 r5 = r2
Local: Backward Copy Propagation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r1 = r8 + r9 r2 = r9 + r1 r4 = r2 r6 = r2 + 1 r9 = r1 r7 = r6 r5 = r7 + 1 r4 = 0 r8 = r2 + r7 r7 = r2 + 1 r6  not live remove  r7 = r6
Global: Dead Code Elimination ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r4 = r4 + 1 r7 = r1 * r4 r3 = r3 + 1 r2 = 0 r3 = r2 + r1 M[r1] = r3 r1 = 3 r2 = 10 r7  not live
Global: Constant Propagation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r5 = 2 r7 = r1 * r5 r3 = r3 + r5 r2 = 0 r3 = r2 + r1 r6 = r7 * r4 M[r1] = r3 r1 = 4 r2 = 10 r7 = 8 r3 = r3 + 2 M[4] = r3 r3 = r2 + 4 r6 = 8 * r4
Global: Forward Copy Propagation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r1 = r2 r3 = r4 r6 = r3 + 1 r2 = 0 r5 = r2 + r3 r6 = r4 + 1 r5 = r2 + r4
Global: Common Subexpression Elimination (CSE) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r3 = r4 / r7 r2 = r2 + 1 r3 = r3 + 1 r1 = r3 * 7 r5 = r2 * r6 r8 = r4 / r7 r9 = r3 * 7 r1 = r2 * r6 r8 = r10 r10 = r3
Global: Code Motion ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],r4 = M[r5] r7 = r4 * 3 r8 = r2 + 1 r7 = r8 * r4 r3 = r2 + 1 r1 = r1 + r7 M[r1] = r3 r1 = 0 preheader header r4 = M[r5]
Global: Loop Strength Reduction i := 0 t1 := n-2 t2 := 4*i A[t2] := 0 i := i+1 if i < t1 goto B2 B1: B2: B3: i := 0 t1 := n-2 t2 := 4*i A[t2] := 0 i := i+1 t2 := t2+4 if i < t1 goto B2 B1: B2: B3: Replace expensive computations with  induction variables
Global: Induction Variable Elimination i := 0 t1 := n-2 t2 := 4*i A[t2] := 0 i := i+1 t2 := t2+4 if i<t1 goto B2 B1: B2: B3: t1 := 4*n t1 := t1-8 t2 := 4*i A[t2] := 0 t2 := t2+4 if t2<t1 goto B2 B1: B2: B3: Replace induction variable in expressions with another

Mais conteúdo relacionado

Mais procurados

Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
bolovv
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
bolovv
 

Mais procurados (20)

Software Construction Assignment Help
Software Construction Assignment HelpSoftware Construction Assignment Help
Software Construction Assignment Help
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 
Three address code generation
Three address code generationThree address code generation
Three address code generation
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Ch2
Ch2Ch2
Ch2
 
COMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTIONCOMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTION
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Three Address code
Three Address code Three Address code
Three Address code
 
Assignment statements
Assignment statementsAssignment statements
Assignment statements
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
Intermediate code
Intermediate codeIntermediate code
Intermediate code
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 

Semelhante a Ch9c

Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Silvio Cesare
 
Fractional Calculus A Commutative Method on Real Analytic Functions
Fractional Calculus A Commutative Method on Real Analytic FunctionsFractional Calculus A Commutative Method on Real Analytic Functions
Fractional Calculus A Commutative Method on Real Analytic Functions
Matt Parker
 
CA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptx
CA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptxCA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptx
CA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptx
trupeace
 

Semelhante a Ch9c (20)

R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
 
COMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptCOMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.ppt
 
COMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxCOMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptx
 
Fractional Calculus A Commutative Method on Real Analytic Functions
Fractional Calculus A Commutative Method on Real Analytic FunctionsFractional Calculus A Commutative Method on Real Analytic Functions
Fractional Calculus A Commutative Method on Real Analytic Functions
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
 
CA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptx
CA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptxCA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptx
CA-Lec4-RISCV-Instructions-1aaaaaaaaaa.pptx
 
Transformations computer graphics
Transformations computer graphics Transformations computer graphics
Transformations computer graphics
 
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler OptimizationsPragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
 
1519 differentiation-integration-02
1519 differentiation-integration-021519 differentiation-integration-02
1519 differentiation-integration-02
 
Vectorization in ATLAS
Vectorization in ATLASVectorization in ATLAS
Vectorization in ATLAS
 
ITS World Congress :: Vienna, Oct 2012
ITS World Congress :: Vienna, Oct 2012ITS World Congress :: Vienna, Oct 2012
ITS World Congress :: Vienna, Oct 2012
 
Maximizing Submodular Function over the Integer Lattice
Maximizing Submodular Function over the Integer LatticeMaximizing Submodular Function over the Integer Lattice
Maximizing Submodular Function over the Integer Lattice
 
IVR - Chapter 1 - Introduction
IVR - Chapter 1 - IntroductionIVR - Chapter 1 - Introduction
IVR - Chapter 1 - Introduction
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and Decoder
 
boyd 3.1
boyd 3.1boyd 3.1
boyd 3.1
 
Great Pyramid of Giza and Golden Section Transform Preview
Great Pyramid of Giza and Golden Section Transform PreviewGreat Pyramid of Giza and Golden Section Transform Preview
Great Pyramid of Giza and Golden Section Transform Preview
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well
 
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
 

Mais de kinnarshah8888 (12)

Yuva Msp All
Yuva Msp AllYuva Msp All
Yuva Msp All
 
Yuva Msp Intro
Yuva Msp IntroYuva Msp Intro
Yuva Msp Intro
 
Ch6
Ch6Ch6
Ch6
 
Ch5a
Ch5aCh5a
Ch5a
 
Ch10
Ch10Ch10
Ch10
 
Ch7
Ch7Ch7
Ch7
 
Ch3
Ch3Ch3
Ch3
 
Ch4b
Ch4bCh4b
Ch4b
 
Ch4a
Ch4aCh4a
Ch4a
 
Ch5b
Ch5bCh5b
Ch5b
 
Ch4c
Ch4cCh4c
Ch4c
 
Ch1
Ch1Ch1
Ch1
 

Último

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Último (20)

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 

Ch9c

  • 1. Code Generation Part III Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Global: Loop Strength Reduction i := 0 t1 := n-2 t2 := 4*i A[t2] := 0 i := i+1 if i < t1 goto B2 B1: B2: B3: i := 0 t1 := n-2 t2 := 4*i A[t2] := 0 i := i+1 t2 := t2+4 if i < t1 goto B2 B1: B2: B3: Replace expensive computations with induction variables
  • 15. Global: Induction Variable Elimination i := 0 t1 := n-2 t2 := 4*i A[t2] := 0 i := i+1 t2 := t2+4 if i<t1 goto B2 B1: B2: B3: t1 := 4*n t1 := t1-8 t2 := 4*i A[t2] := 0 t2 := t2+4 if t2<t1 goto B2 B1: B2: B3: Replace induction variable in expressions with another